HAL_ChibiOS: added stm32_flash_keep_unlocked()

This commit is contained in:
Andrew Tridgell 2018-06-25 08:29:40 +10:00
parent 95f3eb5ab6
commit dd1bd43a2e
2 changed files with 19 additions and 1 deletions

View File

@ -114,7 +114,7 @@ static const uint32_t flash_memmap[STM32_FLASH_NPAGES] = { KB(32), KB(32), KB(32
// keep a cache of the page addresses
static uint32_t flash_pageaddr[STM32_FLASH_NPAGES];
static bool flash_pageaddr_initialised;
static bool flash_keep_unlocked;
#define FLASH_KEY1 0x45670123
#define FLASH_KEY2 0xCDEF89AB
@ -144,6 +144,9 @@ static void stm32_flash_wait_idle(void)
static void stm32_flash_unlock(void)
{
if (flash_keep_unlocked) {
return;
}
stm32_flash_wait_idle();
if (FLASH->CR & FLASH_CR_LOCK) {
@ -160,6 +163,9 @@ static void stm32_flash_unlock(void)
void stm32_flash_lock(void)
{
if (flash_keep_unlocked) {
return;
}
stm32_flash_wait_idle();
FLASH->CR |= FLASH_CR_LOCK;
@ -352,5 +358,16 @@ failed:
return -1;
}
void stm32_flash_keep_unlocked(bool set)
{
if (set && !flash_keep_unlocked) {
stm32_flash_unlock();
flash_keep_unlocked = true;
} else if (!set && flash_keep_unlocked) {
flash_keep_unlocked = false;
stm32_flash_lock();
}
}
#endif // HAL_NO_FLASH_SUPPORT

View File

@ -25,6 +25,7 @@ uint32_t stm32_flash_getpagesize(uint32_t page);
uint32_t stm32_flash_getnumpages(void);
bool stm32_flash_erasepage(uint32_t page);
int32_t stm32_flash_write(uint32_t addr, const void *buf, uint32_t count);
void stm32_flash_keep_unlocked(bool set);
#ifdef __cplusplus
}
#endif