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 00011 bool FlashWriter::ready() { 00012 return __ready; 00013 } 00014 00015 void FlashWriter::open() { 00016 FLASH_Unlock(); 00017 FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); 00018 FLASH_EraseSector(__SECTORS[__sector], VoltageRange_3); 00019 __ready = true; 00020 } 00021 00022 void FlashWriter::write(uint32_t index, int x) { 00023 union {int a; uint32_t b;}; 00024 a = x; 00025 FLASH_ProgramWord(__base + 4 * index, b); 00026 } 00027 00028 void FlashWriter::write(uint32_t index, unsigned int x) { 00029 FLASH_ProgramWord(__base + 4 * index, x); 00030 } 00031 00032 void FlashWriter::write(uint32_t index, float x) { 00033 union {float a; uint32_t b;}; 00034 a = x; 00035 FLASH_ProgramWord(__base + 4 * index, b); 00036 } 00037 00038 void FlashWriter::close() { 00039 FLASH_Lock(); 00040 __ready = false; 00041 } 00042 00043 int flashReadInt(uint32_t sector, uint32_t index) { 00044 return *(int*) (__SECTOR_ADDRS[sector] + 4 * index); 00045 } 00046 00047 uint32_t flashReadUint(uint32_t sector, uint32_t index) { 00048 return *(uint32_t*) (__SECTOR_ADDRS[sector] + 4 * index); 00049 } 00050 00051 float flashReadFloat(uint32_t sector, uint32_t index) { 00052 return *(float*) (__SECTOR_ADDRS[sector] + 4 * index); 00053 }
Generated on Tue Jul 12 2022 21:21:55 by
