1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #11355 from fjmolinas/pr_eeprom_wait_for_op

stm32_common/flash: move wait_for_pending_operation to flash_common
This commit is contained in:
Alexandre Abadie 2019-04-12 13:36:01 +02:00 committed by GitHub
commit 75671ac208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 11 deletions

View File

@ -15,6 +15,7 @@
* @brief Low-level eeprom driver implementation
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
* @author Oleg Artamonov <oleg@unwds.com>
*
* @}
*/
@ -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++;
}

View File

@ -14,6 +14,7 @@
* @brief Low-level flash lock/unlock implementation
*
* @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;
}
}
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);
}
}

View File

@ -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) || \