cpu/stm32_common/flashpage: force waiting for pending operations
Moving the while loop in a separate function ensures no ordering
optimizations is applied silently by gcc.
This commit fixes the flashpage not working on iotlab-m3.
This commit is contained in:
parent
c73ec5c00f
commit
f7b61b6ac1
@ -65,6 +65,12 @@ static void _unlock_flash(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _wait_for_pending_operations(void)
|
||||||
|
{
|
||||||
|
DEBUG("[flashpage] waiting for any pending operation to finish\n");
|
||||||
|
while (FLASH->SR & FLASH_SR_BSY) {}
|
||||||
|
}
|
||||||
|
|
||||||
static void _erase_page(void *page_addr)
|
static void _erase_page(void *page_addr)
|
||||||
{
|
{
|
||||||
#if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1)
|
#if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1)
|
||||||
@ -81,8 +87,8 @@ static void _erase_page(void *page_addr)
|
|||||||
_unlock_flash();
|
_unlock_flash();
|
||||||
|
|
||||||
/* make sure no flash operation is ongoing */
|
/* make sure no flash operation is ongoing */
|
||||||
DEBUG("[flashpage] erase: waiting for any operation to finish\n");
|
_wait_for_pending_operations();
|
||||||
while (FLASH->SR & FLASH_SR_BSY) {}
|
|
||||||
/* set page erase bit and program page address */
|
/* set page erase bit and program page address */
|
||||||
DEBUG("[flashpage] erase: setting the erase bit\n");
|
DEBUG("[flashpage] erase: setting the erase bit\n");
|
||||||
CNTRL_REG |= FLASH_CR_PER;
|
CNTRL_REG |= FLASH_CR_PER;
|
||||||
@ -97,8 +103,9 @@ static void _erase_page(void *page_addr)
|
|||||||
DEBUG("[flashpage] erase: trigger the page erase\n");
|
DEBUG("[flashpage] erase: trigger the page erase\n");
|
||||||
CNTRL_REG |= FLASH_CR_STRT;
|
CNTRL_REG |= FLASH_CR_STRT;
|
||||||
#endif
|
#endif
|
||||||
DEBUG("[flashpage] erase: wait as long as device is busy\n");
|
/* wait as long as device is busy */
|
||||||
while (FLASH->SR & FLASH_SR_BSY) {}
|
_wait_for_pending_operations();
|
||||||
|
|
||||||
/* reset PER bit */
|
/* reset PER bit */
|
||||||
DEBUG("[flashpage] erase: resetting the page erase bit\n");
|
DEBUG("[flashpage] erase: resetting the page erase bit\n");
|
||||||
CNTRL_REG &= ~(FLASH_CR_PER);
|
CNTRL_REG &= ~(FLASH_CR_PER);
|
||||||
@ -151,7 +158,8 @@ void flashpage_write_raw(void *target_addr, const void *data, size_t len)
|
|||||||
for (size_t i = 0; i < (len / FLASHPAGE_DIV); i++) {
|
for (size_t i = 0; i < (len / FLASHPAGE_DIV); i++) {
|
||||||
DEBUG("[flashpage_raw] writing %c to %p\n", (char)data_addr[i], dst);
|
DEBUG("[flashpage_raw] writing %c to %p\n", (char)data_addr[i], dst);
|
||||||
*dst++ = data_addr[i];
|
*dst++ = data_addr[i];
|
||||||
while (FLASH->SR & FLASH_SR_BSY) {}
|
/* wait as long as device is busy */
|
||||||
|
_wait_for_pending_operations();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear program bit again */
|
/* clear program bit again */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user