stm32l0/l1: flash: support half page flashing
Tested on L1 and L0 using the "dapboot" project, see https://github.com/devanlai/dapboot/pull/27 for L1 and https://github.com/devanlai/dapboot/pull/30 for L0
This commit is contained in:
@@ -97,6 +97,36 @@ void flash_unlock_acr(void)
|
||||
FLASH_PDKEYR = FLASH_PDKEYR_PDKEY2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase a page in ram.
|
||||
* @param page_address must be first word in page for L1, any address in page for L0
|
||||
*/
|
||||
void flash_erase_page(uint32_t page_address)
|
||||
{
|
||||
FLASH_PECR |= FLASH_PECR_ERASE | FLASH_PECR_PROG;
|
||||
MMIO32(page_address) = 0;
|
||||
while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY);
|
||||
FLASH_PECR &= ~(FLASH_PECR_ERASE | FLASH_PECR_PROG);
|
||||
}
|
||||
|
||||
/* Must be run from RAM (per ref manual), and because it's in ram, more
|
||||
* than 64MB away from flash address space, must be a long_call. */
|
||||
__attribute__ ((long_call, section (".ramtext")))
|
||||
void flash_program_half_page(uint32_t *dst, void *buf)
|
||||
{
|
||||
uint32_t *src = buf;
|
||||
|
||||
/* Enable half page writes to program memory */
|
||||
FLASH_PECR |= FLASH_PECR_FPRG | FLASH_PECR_PROG;
|
||||
while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY);
|
||||
for (int i = 0; i < FLASH_HALF_PAGE_SIZE; i++) {
|
||||
*dst++ = *src++;
|
||||
}
|
||||
while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY);
|
||||
FLASH_PECR &= ~(FLASH_PECR_FPRG | FLASH_PECR_PROG);
|
||||
}
|
||||
|
||||
|
||||
/** @brief Write a word to eeprom
|
||||
*
|
||||
* @param address assumed to be in the eeprom space, no checking
|
||||
|
||||
Reference in New Issue
Block a user