drv_flash.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef __DRV_FLASH_H
  2. #define __DRV_FLASH_H
  3. #ifdef __cplusplus
  4. extern 'C'
  5. {
  6. #endif
  7. #ifdef __DRV_FLASH_H_GLOBAL
  8. #define __DRV_FLASH_H_EXTERN
  9. #else
  10. #define __DRV_FLASH_H_EXTERN extern
  11. #endif
  12. /************************************************************************************************
  13. * Version *
  14. ************************************************************************************************/
  15. /************************************************************************************************
  16. * How to use *
  17. ************************************************************************************************/
  18. /************************************************************************************************
  19. * Enable config *
  20. ************************************************************************************************/
  21. /************************************************************************************************
  22. * Includes *
  23. ************************************************************************************************/
  24. #include "stm32f4xx_flash.h"
  25. /************************************************************************************************
  26. * Defines *
  27. ************************************************************************************************/
  28. #define FMC_PAGE_SIZE ((uint16_t)0x800)
  29. #define FMC_PAGE_SIZE_U16 ((uint16_t)0x400)
  30. #define FMC_FLASH_BASE ((uint32_t)0x08000000)
  31. #define FMC_PAGE_SIZE_16K ((uint32_t)0x4000)
  32. #define FMC_PAGE_SIZE_32K ((uint32_t)0x8000)
  33. #define FMC_PAGE_SIZE_64K ((uint32_t)0x10000)
  34. #define FMC_PAGE_SIZE_128K ((uint32_t)0x20000)
  35. // FLASH 扇区的起始地址
  36. #define ADDR_FLASH_SECTOR_0 ((u32)0x08000000) // 扇区0起始地址, 16 Kbytes
  37. #define ADDR_FLASH_SECTOR_1 ((u32)0x08004000) // 扇区1起始地址, 16 Kbytes
  38. #define ADDR_FLASH_SECTOR_2 ((u32)0x08008000) // 扇区2起始地址, 16 Kbytes
  39. #define ADDR_FLASH_SECTOR_3 ((u32)0x0800C000) // 扇区3起始地址, 16 Kbytes
  40. #define ADDR_FLASH_SECTOR_4 ((u32)0x08010000) // 扇区4起始地址, 64 Kbytes
  41. #define ADDR_FLASH_SECTOR_5 ((u32)0x08020000) // 扇区5起始地址, 128 Kbytes
  42. #define ADDR_FLASH_SECTOR_6 ((u32)0x08040000) // 扇区6起始地址, 128 Kbytes
  43. #define ADDR_FLASH_SECTOR_7 ((u32)0x08060000) // 扇区7起始地址, 128 Kbytes
  44. #define ADDR_FLASH_SECTOR_8 ((u32)0x08080000) // 扇区8起始地址, 128 Kbytes
  45. #define ADDR_FLASH_SECTOR_9 ((u32)0x080A0000) // 扇区9起始地址, 128 Kbytes
  46. #define ADDR_FLASH_SECTOR_10 ((u32)0x080C0000) // 扇区10起始地址,128 Kbytes
  47. #define ADDR_FLASH_SECTOR_11 ((u32)0x080E0000) // 扇区11起始地址,128 Kbytes
  48. #define ADDR_FLASH_SECTOR_END ((u32)0x080FFFFF)
  49. /************************************************************************************************
  50. * Defines *
  51. ************************************************************************************************/
  52. void fmc_clear_flag_star(void);
  53. void fmc_clear_flag_end(void);
  54. uint8_t fmc_read_byte(uint32_t read_addr);
  55. uint16_t fmc_read_half_word(uint32_t read_addr);
  56. uint8_t fmc_read_n_half_word(uint32_t read_addr, uint16_t * buff, uint16_t count);
  57. uint8_t fmc_read_one_page(uint32_t read_addr, uint16_t * buff);
  58. uint8_t fmc_erase_pages(uint32_t erase_addr, uint16_t len);
  59. uint8_t fmc_write_n_half_word(uint32_t write_addr, uint16_t * buff, uint16_t len);
  60. uint16_t firmware_crc16_ccitt_false(uint16_t init_value, uint8_t * pbuff, uint32_t len);
  61. #ifdef __cplusplus
  62. };
  63. #endif
  64. #endif // __DRV_FLASH_H