diff --git a/cpu/stm32_common/periph/eeprom.c b/cpu/stm32_common/periph/eeprom.c index 962b543bab..6e3662c05f 100644 --- a/cpu/stm32_common/periph/eeprom.c +++ b/cpu/stm32_common/periph/eeprom.c @@ -15,6 +15,7 @@ * @brief Low-level eeprom driver implementation * * @author Alexandre Abadie + * @author Oleg Artamonov * * @} */ @@ -29,6 +30,7 @@ extern void _lock(void); extern void _unlock(void); +extern void _wait_for_pending_operations(void); #ifndef EEPROM_START_ADDR #error "periph/eeprom: EEPROM_START_ADDR is not defined" @@ -42,6 +44,7 @@ size_t eeprom_read(uint32_t pos, uint8_t *data, size_t len) DEBUG("Reading data from EEPROM at pos %" PRIu32 ": ", pos); for (size_t i = 0; i < len; i++) { + _wait_for_pending_operations(); *p++ = *(uint8_t *)(EEPROM_START_ADDR + pos++); DEBUG("0x%02X ", *p); } @@ -59,6 +62,7 @@ size_t eeprom_write(uint32_t pos, const uint8_t *data, size_t len) _unlock(); for (size_t i = 0; i < len; i++) { + _wait_for_pending_operations(); *(uint8_t *)(EEPROM_START_ADDR + pos++) = *p++; } diff --git a/cpu/stm32_common/periph/flash_common.c b/cpu/stm32_common/periph/flash_common.c index e254b99486..57b5c39efe 100644 --- a/cpu/stm32_common/periph/flash_common.c +++ b/cpu/stm32_common/periph/flash_common.c @@ -14,6 +14,7 @@ * @brief Low-level flash lock/unlock implementation * * @author Alexandre Abadie + * @author Oleg Artamonov * * @} */ @@ -56,3 +57,16 @@ void _lock(void) CNTRL_REG |= CNTRL_REG_LOCK; } } + +void _wait_for_pending_operations(void) +{ + if (FLASH->SR & FLASH_SR_BSY) { + DEBUG("[flash-common] waiting for any pending operation to finish\n"); + while (FLASH->SR & FLASH_SR_BSY) {} + } + + /* Clear 'end of operation' bit in status register */ + if (FLASH->SR & FLASH_SR_EOP) { + FLASH->SR &= ~(FLASH_SR_EOP); + } +} diff --git a/cpu/stm32_common/periph/flashpage.c b/cpu/stm32_common/periph/flashpage.c index f7b8296902..8e99c3c7dd 100644 --- a/cpu/stm32_common/periph/flashpage.c +++ b/cpu/stm32_common/periph/flashpage.c @@ -52,6 +52,7 @@ extern void _lock(void); extern void _unlock(void); +extern void _wait_for_pending_operations(void); static void _unlock_flash(void) { @@ -69,17 +70,6 @@ static void _unlock_flash(void) #endif } -static void _wait_for_pending_operations(void) -{ - DEBUG("[flashpage] waiting for any pending operation to finish\n"); - while (FLASH->SR & FLASH_SR_BSY) {} - - /* Clear 'end of operation' bit in status register */ - if (FLASH->SR & FLASH_SR_EOP) { - FLASH->SR &= ~(FLASH_SR_EOP); - } -} - static void _erase_page(void *page_addr) { #if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1) || \