Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
FlashWriter.cpp
00001 #include "stm32f4xx_flash.h" 00002 #include "FlashWriter.h" 00003 00004 FlashWriter::FlashWriter(int sector) { 00005 if (sector > 7) sector = 7; 00006 __sector = sector; 00007 __base = __SECTOR_ADDRS[sector]; 00008 __ready = false; 00009 00010 FLASH_Unlock(); 00011 FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); 00012 FLASH_EraseSector(__SECTORS[sector], VoltageRange_3); 00013 } 00014 00015 bool FlashWriter::ready() { 00016 return __ready; 00017 } 00018 00019 void FlashWriter::open() { 00020 FLASH_Unlock(); 00021 FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); 00022 FLASH_EraseSector(__SECTORS[__sector], VoltageRange_3); 00023 __ready = true; 00024 } 00025 00026 void FlashWriter::write(uint32_t index, int x) { 00027 union {int a; uint32_t b;}; 00028 a = x; 00029 FLASH_ProgramWord(__base + 4 * index, b); 00030 } 00031 00032 void FlashWriter::write(uint32_t index, unsigned int x) { 00033 FLASH_ProgramWord(__base + 4 * index, x); 00034 } 00035 00036 void FlashWriter::write(uint32_t index, float x) { 00037 union {float a; uint32_t b;}; 00038 a = x; 00039 FLASH_ProgramWord(__base + 4 * index, b); 00040 } 00041 00042 void FlashWriter::close() { 00043 FLASH_Lock(); 00044 } 00045 00046 int flashReadInt(uint32_t sector, uint32_t index) { 00047 return *(int*) (__SECTOR_ADDRS[sector] + 4 * index); 00048 } 00049 00050 uint32_t flashReadUint(uint32_t sector, uint32_t index) { 00051 return *(uint32_t*) (__SECTOR_ADDRS[sector] + 4 * index); 00052 } 00053 00054 float flashReadFloat(uint32_t sector, uint32_t index) { 00055 return *(float*) (__SECTOR_ADDRS[sector] + 4 * index); 00056 }
Generated on Mon Aug 1 2022 09:51:13 by
1.7.2