AnsweredAssumed Answered

[stm32cubef7] Flash : no status flag clear after error

Question asked by hanna.regis on Apr 12, 2016
Latest reply on Apr 22, 2016 by Nesrine M
Hi,

I am using STM32F7xx HAL Drivers v1.0.4 (09-December-2015).

I found a bug in stm32f7xx_hal_flash.c : when I call HAL_FLASH_Program, and it returns an error (sector write protected for example), following calls to HAL_FLASH_Program return errors before any attempt to write.
It is because error flags in FLASH_SR are not cleared after save.

Here is a patch that fixes the bug in FLASH_WaitForLastOperation function :

diff --git a/HAL_Driver/Src/stm32f7xx_hal_flash.c b/HAL_Driver/Src/stm32f7xx_hal_flash.c
index 8ac6351..3de2461 100644
--- a/HAL_Driver/Src/stm32f7xx_hal_flash.c
+++ b/HAL_Driver/Src/stm32f7xx_hal_flash.c
@@ -646,6 +646,10 @@ HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
   {
     /*Save the error code*/
     FLASH_SetErrorCode();
+
+    /*Clear error flags*/
+    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR  | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR );
+
     return HAL_ERROR;
   }
 
--
1.9.5.msysgit.0

Outcomes