EEPROM emulation using Flash for STM32F103 with fix error on "FLASH_PageErase"
Fork of eeprom_flash by
Revision 2:16f5373f8b31, committed 2018-05-05
- Comitter:
- Leech
- Date:
- Sat May 05 19:06:35 2018 +0000
- Parent:
- 1:e593ae8ff81d
- Commit message:
- Fix error on FLASH_PageErase
Changed in this revision
eeprom_flash.cpp | Show annotated file Show diff for this revision Revisions of this file |
eeprom_flash.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/eeprom_flash.cpp Mon Aug 29 21:29:20 2016 +0000 +++ b/eeprom_flash.cpp Sat May 05 19:06:35 2018 +0000 @@ -26,6 +26,17 @@ CLEAR_BIT(FLASH->CR, FLASH_CR_PER); // Bug fix: bit PER has been set in Flash_PageErase(), must clear it here } +void FLASH_PageErase(uint32_t PageAddress) +{ + /* Proceed to erase the page */ + SET_BIT(FLASH->CR, FLASH_CR_PER); + while (FLASH->SR & FLASH_SR_BSY); + WRITE_REG(FLASH->AR, PageAddress); + SET_BIT(FLASH->CR, FLASH_CR_STRT); + while (FLASH->SR & FLASH_SR_BSY); + CLEAR_BIT(FLASH->CR, FLASH_CR_PER); +} + void disableEEPROMWriting() { HAL_FLASH_Lock(); }
--- a/eeprom_flash.h Mon Aug 29 21:29:20 2016 +0000 +++ b/eeprom_flash.h Sat May 05 19:06:35 2018 +0000 @@ -9,6 +9,8 @@ void enableEEPROMWriting(); // Unlock and keep PER cleared void disableEEPROMWriting(); // Lock +void FLASH_PageErase(uint32_t PageAddress); + // Write functions HAL_StatusTypeDef writeEEPROMHalfWord(uint32_t address, uint16_t data); HAL_StatusTypeDef writeEEPROMWord(uint32_t address, uint32_t data);