From 29225397720299bc6528c48d94d37d600017304b Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 3 Sep 2022 11:04:14 +0200 Subject: [PATCH] stm32l0/stm32lx_nvm_busy_wait: Check for errors only after busy is released. While busy, EOP(end of operation) is not yet set. But check for communication errors. --- src/target/stm32l0.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/target/stm32l0.c b/src/target/stm32l0.c index bde8795..713bb2f 100644 --- a/src/target/stm32l0.c +++ b/src/target/stm32l0.c @@ -326,11 +326,10 @@ static bool stm32lx_nvm_busy_wait(target *t, uint32_t nvm) uint32_t sr; do { sr = target_mem_read32(t, STM32Lx_NVM_SR(nvm)); - if ((sr & STM32Lx_NVM_SR_ERR_M) || !(sr & STM32Lx_NVM_SR_EOP) || target_check_error(t)) + if (target_check_error(t)) /* Check for communication errors */ return false; } while (sr & STM32Lx_NVM_SR_BSY); - - return true; + return (!((sr & STM32Lx_NVM_SR_ERR_M) || !(sr & STM32Lx_NVM_SR_EOP))); } /** Erase a region of program flash using operations through the debug