Bayley Wang
/
flash_configuration
flash based config testing
FlashWriter/FlashWriter.h@3:82c00c8e2cb4, 2017-03-07 (annotated)
- Committer:
- bwang
- Date:
- Tue Mar 07 08:06:39 2017 +0000
- Revision:
- 3:82c00c8e2cb4
- Parent:
- 0:941e150e78b6
lot's more commands
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 0:941e150e78b6 | 1 | #ifndef __FLASHWRITER_H |
bwang | 0:941e150e78b6 | 2 | #define __FLASHWRITER_H |
bwang | 0:941e150e78b6 | 3 | |
bwang | 0:941e150e78b6 | 4 | #include "stm32f4xx_flash.h" |
bwang | 0:941e150e78b6 | 5 | |
bwang | 0:941e150e78b6 | 6 | /* Base address of the Flash sectors */ |
bwang | 0:941e150e78b6 | 7 | #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */ |
bwang | 0:941e150e78b6 | 8 | #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */ |
bwang | 0:941e150e78b6 | 9 | #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */ |
bwang | 0:941e150e78b6 | 10 | #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */ |
bwang | 0:941e150e78b6 | 11 | #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */ |
bwang | 0:941e150e78b6 | 12 | #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */ |
bwang | 0:941e150e78b6 | 13 | #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */ |
bwang | 0:941e150e78b6 | 14 | #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */ |
bwang | 0:941e150e78b6 | 15 | |
bwang | 0:941e150e78b6 | 16 | static uint32_t __SECTOR_ADDRS[] = {ADDR_FLASH_SECTOR_0, ADDR_FLASH_SECTOR_1, ADDR_FLASH_SECTOR_2, ADDR_FLASH_SECTOR_3, |
bwang | 0:941e150e78b6 | 17 | ADDR_FLASH_SECTOR_4, ADDR_FLASH_SECTOR_5, ADDR_FLASH_SECTOR_6, ADDR_FLASH_SECTOR_7}; |
bwang | 0:941e150e78b6 | 18 | static uint32_t __SECTORS[] = {FLASH_Sector_0, FLASH_Sector_1, FLASH_Sector_2, FLASH_Sector_3, |
bwang | 0:941e150e78b6 | 19 | FLASH_Sector_4, FLASH_Sector_6, FLASH_Sector_6, FLASH_Sector_7}; |
bwang | 0:941e150e78b6 | 20 | class FlashWriter { |
bwang | 0:941e150e78b6 | 21 | public: |
bwang | 0:941e150e78b6 | 22 | FlashWriter(int sector); |
bwang | 0:941e150e78b6 | 23 | void open(); |
bwang | 0:941e150e78b6 | 24 | bool ready(); |
bwang | 0:941e150e78b6 | 25 | void write(uint32_t index, int x); |
bwang | 0:941e150e78b6 | 26 | void write(uint32_t index, unsigned int x); |
bwang | 0:941e150e78b6 | 27 | void write(uint32_t index, float x); |
bwang | 0:941e150e78b6 | 28 | void close(); |
bwang | 0:941e150e78b6 | 29 | private: |
bwang | 0:941e150e78b6 | 30 | uint32_t __base; |
bwang | 0:941e150e78b6 | 31 | uint32_t __sector; |
bwang | 0:941e150e78b6 | 32 | bool __ready; |
bwang | 0:941e150e78b6 | 33 | }; |
bwang | 0:941e150e78b6 | 34 | |
bwang | 0:941e150e78b6 | 35 | int flashReadInt(uint32_t sector, uint32_t index); |
bwang | 0:941e150e78b6 | 36 | uint32_t flashReadUint(uint32_t sector, uint32_t index); |
bwang | 0:941e150e78b6 | 37 | float flashReadFloat(uint32_t sector, uint32_t index); |
bwang | 0:941e150e78b6 | 38 | |
bwang | 0:941e150e78b6 | 39 | #endif |