chipflash.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef __CHIPFLASH_H
  2. #define __CHIPFLASH_H
  3. #include "stdint.h"
  4. #include "stm32h5xx.h"
  5. #include "stm32h523xx.h"
  6. //一个扇区8*1024bytes
  7. #define CPU_FLASH_SIZE (512 * 1024) // FLASH总容量(很奇怪,GD32的128KB后64KB可能跟STM32一样没有保障,稳定优先)
  8. #define BOOT_FLASH_SIZE (8 * 1024) // BOOTLOADER占用容量
  9. #define PAR_FLASH_SIZE (8 * 1024) // PAR占用容量
  10. #define PROGRAM_FLASH_SIZE (8 * 1024) // APP占用容量
  11. #define SECTOR_SIZE (8 * 1024) // 扇区大小 8*1024bytes
  12. #define CPU_FLASH_BASE_ADDR (uint32_t)(FLASH_BASE)
  13. #define BOOT_FLASH_END_ADDR (CPU_FLASH_BASE_ADDR + BOOT_FLASH_SIZE)
  14. #define PAR_FLASH_BASE_ADDR (BOOT_FLASH_END_ADDR)
  15. #define PAR_FLASH_END_ADDR (PAR_FLASH_BASE_ADDR + PAR_FLASH_SIZE)
  16. #define PROGRAM_FLASH_BASE_ADDR (PAR_FLASH_END_ADDR + 8 * 1024) // 跳过APP1
  17. #define PROGRAM_FLASH_END_ADDR (PROGRAM_FLASH_BASE_ADDR + PROGRAM_FLASH_SIZE)
  18. #define FLASH_IS_EQU 0 // 无需擦除
  19. #define FLASH_REQ_WRITE 1 // 不需要擦除直接写
  20. #define FLASH_REQ_ERASE 2 // 先擦除再写
  21. #define FLASH_PARAM_ERR 3 // 函数参数错误
  22. #define ChipUniqueID_HIGH 0x1FFFF7F0
  23. #define ChipUniqueID_MEDIUM 0x1FFFF7EC
  24. #define ChipUniqueID_LOW 0x1FFFF7E8
  25. #define CHIPFLASHSIZE 0x1FFFF7E0
  26. #define CHIPMCUID 0xE0042000
  27. #define WS_INFO_ADDR (PAR_FLASH_BASE_ADDR)
  28. #define WS_INFO_FLAG (uint32_t)0xA77A
  29. #pragma pack(push, 1)
  30. typedef struct
  31. {
  32. uint32_t _app_bin_size;
  33. uint16_t _compAddr; // 0x66
  34. uint16_t _hardVer; // 0x0001
  35. uint32_t _softVer;
  36. uint32_t _moduleID; // 预留0x00
  37. uint32_t _bootFlag; // 0x1234abcd
  38. uint16_t _crcCheck;
  39. } _WS_INFO;
  40. #pragma pack(pop)
  41. extern _WS_INFO ws_info;
  42. #pragma pack(push, 1)
  43. typedef struct
  44. {
  45. uint32_t ChipUniqueID[3];
  46. uint32_t ChipFlashSize;
  47. uint32_t ChipMCUID;
  48. } _CHIP_INFO;
  49. #pragma pack(pop)
  50. extern _CHIP_INFO chip_info;
  51. typedef struct
  52. {
  53. uint8_t (*Read_Flash)(uint32_t ulFlashAddr, uint8_t *pdata, uint32_t len);
  54. uint8_t (*Write_Flash)(uint32_t ulFlashAddr, uint8_t *pdata, uint32_t len);
  55. uint8_t (*Erase_Flash)(uint32_t ulFlashAddr, uint32_t u2FlashAddr);
  56. } __FLASH_OPS;
  57. extern __FLASH_OPS *flash_ops;
  58. // uint32_t bsp_get_sector(uint32_t Addr);
  59. // uint8_t bsp_read_cpu_flash(uint32_t ulFlashAddr, uint8_t* ucpDst, uint32_t ulSize);
  60. // uint8_t bsp_cmp_cpu_flash(uint32_t ulFlashAddr, uint8_t* ucpBuf, uint32_t ulSize);
  61. // uint8_t bsp_write_cpu_flash(uint32_t ulFlashAddr, uint8_t* ucpSrc, uint32_t ulSize);
  62. // uint8_t bsp_erase_cpu_flash(uint32_t ulFlashAddr, uint32_t u2FlashAddr);
  63. // void get_chip_info(void);
  64. #endif