asdgas
Dependencies: mbed Eigen FastPWM
FlashWriter/FlashWriter.h@16:903b5a4433b4, 2019-09-02 (annotated)
- Committer:
- Lightvalve
- Date:
- Mon Sep 02 13:32:33 2019 +0000
- Revision:
- 16:903b5a4433b4
190902
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lightvalve | 16:903b5a4433b4 | 1 | #ifndef __FLASHWRITER_H |
Lightvalve | 16:903b5a4433b4 | 2 | #define __FLASHWRITER_H |
Lightvalve | 16:903b5a4433b4 | 3 | |
Lightvalve | 16:903b5a4433b4 | 4 | #include "stm32f4xx_flash.h" |
Lightvalve | 16:903b5a4433b4 | 5 | |
Lightvalve | 16:903b5a4433b4 | 6 | /* Base address of the Flash sectors */ |
Lightvalve | 16:903b5a4433b4 | 7 | #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */ |
Lightvalve | 16:903b5a4433b4 | 8 | #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */ |
Lightvalve | 16:903b5a4433b4 | 9 | #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */ |
Lightvalve | 16:903b5a4433b4 | 10 | #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */ |
Lightvalve | 16:903b5a4433b4 | 11 | #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */ |
Lightvalve | 16:903b5a4433b4 | 12 | #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */ |
Lightvalve | 16:903b5a4433b4 | 13 | #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */ |
Lightvalve | 16:903b5a4433b4 | 14 | #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */ |
Lightvalve | 16:903b5a4433b4 | 15 | |
Lightvalve | 16:903b5a4433b4 | 16 | static uint32_t __SECTOR_ADDRS[] = {ADDR_FLASH_SECTOR_0, ADDR_FLASH_SECTOR_1, ADDR_FLASH_SECTOR_2, ADDR_FLASH_SECTOR_3, |
Lightvalve | 16:903b5a4433b4 | 17 | ADDR_FLASH_SECTOR_4, ADDR_FLASH_SECTOR_5, ADDR_FLASH_SECTOR_6, ADDR_FLASH_SECTOR_7}; |
Lightvalve | 16:903b5a4433b4 | 18 | static uint32_t __SECTORS[] = {FLASH_Sector_0, FLASH_Sector_1, FLASH_Sector_2, FLASH_Sector_3, |
Lightvalve | 16:903b5a4433b4 | 19 | FLASH_Sector_4, FLASH_Sector_6, FLASH_Sector_6, FLASH_Sector_7}; |
Lightvalve | 16:903b5a4433b4 | 20 | class FlashWriter { |
Lightvalve | 16:903b5a4433b4 | 21 | public: |
Lightvalve | 16:903b5a4433b4 | 22 | FlashWriter(int sector); |
Lightvalve | 16:903b5a4433b4 | 23 | void open(); |
Lightvalve | 16:903b5a4433b4 | 24 | bool ready(); |
Lightvalve | 16:903b5a4433b4 | 25 | void write(uint32_t index, int x); |
Lightvalve | 16:903b5a4433b4 | 26 | void write(uint32_t index, unsigned int x); |
Lightvalve | 16:903b5a4433b4 | 27 | void write(uint32_t index, float x); |
Lightvalve | 16:903b5a4433b4 | 28 | void close(); |
Lightvalve | 16:903b5a4433b4 | 29 | private: |
Lightvalve | 16:903b5a4433b4 | 30 | uint32_t __base; |
Lightvalve | 16:903b5a4433b4 | 31 | uint32_t __sector; |
Lightvalve | 16:903b5a4433b4 | 32 | bool __ready; |
Lightvalve | 16:903b5a4433b4 | 33 | }; |
Lightvalve | 16:903b5a4433b4 | 34 | |
Lightvalve | 16:903b5a4433b4 | 35 | int flashReadInt(uint32_t sector, uint32_t index); |
Lightvalve | 16:903b5a4433b4 | 36 | uint32_t flashReadUint(uint32_t sector, uint32_t index); |
Lightvalve | 16:903b5a4433b4 | 37 | float flashReadFloat(uint32_t sector, uint32_t index); |
Lightvalve | 16:903b5a4433b4 | 38 | |
Lightvalve | 16:903b5a4433b4 | 39 | #endif |