stm32_common/flash: move wait_for_pending_operation to flash_common
This commit is contained in:
parent
2f8e705679
commit
2c44cd4f70
@ -15,6 +15,7 @@
|
|||||||
* @brief Low-level eeprom driver implementation
|
* @brief Low-level eeprom driver implementation
|
||||||
*
|
*
|
||||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
|
* @author Oleg Artamonov <oleg@unwds.com>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@ -29,6 +30,7 @@
|
|||||||
|
|
||||||
extern void _lock(void);
|
extern void _lock(void);
|
||||||
extern void _unlock(void);
|
extern void _unlock(void);
|
||||||
|
extern void _wait_for_pending_operations(void);
|
||||||
|
|
||||||
#ifndef EEPROM_START_ADDR
|
#ifndef EEPROM_START_ADDR
|
||||||
#error "periph/eeprom: EEPROM_START_ADDR is not defined"
|
#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);
|
DEBUG("Reading data from EEPROM at pos %" PRIu32 ": ", pos);
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
_wait_for_pending_operations();
|
||||||
*p++ = *(uint8_t *)(EEPROM_START_ADDR + pos++);
|
*p++ = *(uint8_t *)(EEPROM_START_ADDR + pos++);
|
||||||
DEBUG("0x%02X ", *p);
|
DEBUG("0x%02X ", *p);
|
||||||
}
|
}
|
||||||
@ -59,6 +62,7 @@ size_t eeprom_write(uint32_t pos, const uint8_t *data, size_t len)
|
|||||||
_unlock();
|
_unlock();
|
||||||
|
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
_wait_for_pending_operations();
|
||||||
*(uint8_t *)(EEPROM_START_ADDR + pos++) = *p++;
|
*(uint8_t *)(EEPROM_START_ADDR + pos++) = *p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
* @brief Low-level flash lock/unlock implementation
|
* @brief Low-level flash lock/unlock implementation
|
||||||
*
|
*
|
||||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
|
* @author Oleg Artamonov <oleg@unwds.com>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@ -56,3 +57,16 @@ void _lock(void)
|
|||||||
CNTRL_REG |= CNTRL_REG_LOCK;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
extern void _lock(void);
|
extern void _lock(void);
|
||||||
extern void _unlock(void);
|
extern void _unlock(void);
|
||||||
|
extern void _wait_for_pending_operations(void);
|
||||||
|
|
||||||
static void _unlock_flash(void)
|
static void _unlock_flash(void)
|
||||||
{
|
{
|
||||||
@ -69,17 +70,6 @@ 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) {}
|
|
||||||
|
|
||||||
/* 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)
|
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) || \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user