mirror of https://github.com/ArduPilot/ardupilot
HAL_ChibiOS: added stm32_flash_keep_unlocked()
This commit is contained in:
parent
95f3eb5ab6
commit
dd1bd43a2e
|
@ -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
|
// keep a cache of the page addresses
|
||||||
static uint32_t flash_pageaddr[STM32_FLASH_NPAGES];
|
static uint32_t flash_pageaddr[STM32_FLASH_NPAGES];
|
||||||
static bool flash_pageaddr_initialised;
|
static bool flash_pageaddr_initialised;
|
||||||
|
static bool flash_keep_unlocked;
|
||||||
|
|
||||||
#define FLASH_KEY1 0x45670123
|
#define FLASH_KEY1 0x45670123
|
||||||
#define FLASH_KEY2 0xCDEF89AB
|
#define FLASH_KEY2 0xCDEF89AB
|
||||||
|
@ -144,6 +144,9 @@ static void stm32_flash_wait_idle(void)
|
||||||
|
|
||||||
static void stm32_flash_unlock(void)
|
static void stm32_flash_unlock(void)
|
||||||
{
|
{
|
||||||
|
if (flash_keep_unlocked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
stm32_flash_wait_idle();
|
stm32_flash_wait_idle();
|
||||||
|
|
||||||
if (FLASH->CR & FLASH_CR_LOCK) {
|
if (FLASH->CR & FLASH_CR_LOCK) {
|
||||||
|
@ -160,6 +163,9 @@ static void stm32_flash_unlock(void)
|
||||||
|
|
||||||
void stm32_flash_lock(void)
|
void stm32_flash_lock(void)
|
||||||
{
|
{
|
||||||
|
if (flash_keep_unlocked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
stm32_flash_wait_idle();
|
stm32_flash_wait_idle();
|
||||||
FLASH->CR |= FLASH_CR_LOCK;
|
FLASH->CR |= FLASH_CR_LOCK;
|
||||||
|
|
||||||
|
@ -352,5 +358,16 @@ failed:
|
||||||
return -1;
|
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
|
#endif // HAL_NO_FLASH_SUPPORT
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ uint32_t stm32_flash_getpagesize(uint32_t page);
|
||||||
uint32_t stm32_flash_getnumpages(void);
|
uint32_t stm32_flash_getnumpages(void);
|
||||||
bool stm32_flash_erasepage(uint32_t page);
|
bool stm32_flash_erasepage(uint32_t page);
|
||||||
int32_t stm32_flash_write(uint32_t addr, const void *buf, uint32_t count);
|
int32_t stm32_flash_write(uint32_t addr, const void *buf, uint32_t count);
|
||||||
|
void stm32_flash_keep_unlocked(bool set);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue