Flash only unlocked when needed

This commit is contained in:
Andre Bernet
2014-04-11 11:18:58 +02:00
parent d442fa77e0
commit ac1dbf81f4
5 changed files with 25 additions and 2 deletions
@@ -144,6 +144,7 @@ void delay_01us(uint16_t nb);
// Flash Write driver
#define FLASH_PAGESIZE 256
void unlockFlash();
void lockFlash();
void writeFlash(uint32_t * address, uint32_t * buffer);
uint32_t isFirmwareStart(const void * buffer);
uint32_t isBootloaderStart(const void * buffer);
@@ -16,6 +16,12 @@ void unlockFlash()
FLASH->KEYR = 0xCDEF89AB;
}
void lockFlash()
{
while (!FLASH->SR & FLASH_SR_BSY);
FLASH->CR |= FLASH_CR_LOCK;
}
void waitFlashIdle()
{
while (FLASH->SR & FLASH_FLAG_BSY) {