flash writing code for 446re

Dependencies:   mbed

Committer:
bwang
Date:
Tue Feb 28 22:31:12 2017 +0000
Revision:
3:16b0692f3ed3
Parent:
2:11238235cb62
forgot an include

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bwang 2:11238235cb62 1 #ifndef __FLASHWRITER_H
bwang 2:11238235cb62 2 #define __FLASHWRITER_H
bwang 2:11238235cb62 3
bwang 3:16b0692f3ed3 4 #include "stm32f4xx_flash.h"
bwang 3:16b0692f3ed3 5
bwang 2:11238235cb62 6 /* Base address of the Flash sectors */
bwang 2:11238235cb62 7 #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
bwang 2:11238235cb62 8 #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
bwang 2:11238235cb62 9 #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
bwang 2:11238235cb62 10 #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
bwang 2:11238235cb62 11 #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
bwang 2:11238235cb62 12 #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
bwang 2:11238235cb62 13 #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
bwang 2:11238235cb62 14 #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
bwang 2:11238235cb62 15
bwang 2:11238235cb62 16 static uint32_t __SECTOR_ADDRS[] = {ADDR_FLASH_SECTOR_0, ADDR_FLASH_SECTOR_1, ADDR_FLASH_SECTOR_2, ADDR_FLASH_SECTOR_3,
bwang 2:11238235cb62 17 ADDR_FLASH_SECTOR_4, ADDR_FLASH_SECTOR_5, ADDR_FLASH_SECTOR_6, ADDR_FLASH_SECTOR_7};
bwang 2:11238235cb62 18 static uint32_t __SECTORS[] = {FLASH_Sector_0, FLASH_Sector_1, FLASH_Sector_2, FLASH_Sector_3,
bwang 2:11238235cb62 19 FLASH_Sector_4, FLASH_Sector_6, FLASH_Sector_6, FLASH_Sector_7};
bwang 2:11238235cb62 20 class FlashWriter {
bwang 2:11238235cb62 21 public:
bwang 2:11238235cb62 22 FlashWriter(int sector);
bwang 2:11238235cb62 23 void open();
bwang 2:11238235cb62 24 bool ready();
bwang 2:11238235cb62 25 void write(uint32_t index, int x);
bwang 2:11238235cb62 26 void write(uint32_t index, unsigned int x);
bwang 2:11238235cb62 27 void write(uint32_t index, float x);
bwang 2:11238235cb62 28 void close();
bwang 2:11238235cb62 29 private:
bwang 2:11238235cb62 30 uint32_t __base;
bwang 2:11238235cb62 31 uint32_t __sector;
bwang 2:11238235cb62 32 bool __ready;
bwang 2:11238235cb62 33 };
bwang 2:11238235cb62 34
bwang 2:11238235cb62 35 int flashReadInt(uint32_t sector, uint32_t index);
bwang 2:11238235cb62 36 uint32_t flashReadUint(uint32_t sector, uint32_t index);
bwang 2:11238235cb62 37 float flashReadFloat(uint32_t sector, uint32_t index);
bwang 2:11238235cb62 38
bwang 2:11238235cb62 39 #endif