mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-11 10:43:46 +08:00
d7dac0e5c2
date: 2024-06-11T01:36:39 master commit: f8cb04e4a8b032b72a909f68b808a50936184bee
34 lines
770 B
C
34 lines
770 B
C
bool flash_is_locked(void) {
|
|
return (FLASH->CR1 & FLASH_CR_LOCK);
|
|
}
|
|
|
|
void flash_unlock(void) {
|
|
FLASH->KEYR1 = 0x45670123;
|
|
FLASH->KEYR1 = 0xCDEF89AB;
|
|
}
|
|
|
|
bool flash_erase_sector(uint8_t sector, bool unlocked) {
|
|
// don't erase the bootloader(sector 0)
|
|
if (sector != 0 && sector < 8 && unlocked) {
|
|
FLASH->CR1 = (sector << 8) | FLASH_CR_SER;
|
|
FLASH->CR1 |= FLASH_CR_START;
|
|
while (FLASH->SR1 & FLASH_SR_QW);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void flash_write_word(void *prog_ptr, uint32_t data) {
|
|
uint32_t *pp = prog_ptr;
|
|
FLASH->CR1 |= FLASH_CR_PG;
|
|
*pp = data;
|
|
while (FLASH->SR1 & FLASH_SR_QW);
|
|
}
|
|
|
|
void flush_write_buffer(void) {
|
|
if (FLASH->SR1 & FLASH_SR_WBNE) {
|
|
FLASH->CR1 |= FLASH_CR_FW;
|
|
while (FLASH->SR1 & FLASH_CR_FW);
|
|
}
|
|
}
|