BaseCode for T-Motor_AK80

Dependencies:   mbed-dev-f303 FastPWM3

Committer:
benkatz
Date:
Wed Apr 05 20:54:16 2017 +0000
Revision:
23:2adf23ee0305
Added bayley's flash writer

Who changed what in which revision?

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