STMicroelectronics / stm32l0xx_hal_driver

Provides the STM32Cube MCU Component "hal_driver" of the STM32L0 series.
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

The macro __HAL_FLASH_CLEAR_FLAG does not work properly #11

Closed tomatsu closed 3 months ago

tomatsu commented 3 months ago

I am experiencing an error when I write data to EEPROM. I suspect that __HAL_FLASH_CLEAR_FLAG does not property clear FLASH->SR, and the macro should be defined as follows.

#define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) &= ~(__FLAG__))

I would appreciate if you could take a look at the code.

TOUNSTM commented 3 months ago

Hello @tomatsu,

Thank you for your contribution, the macro you provided: #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) &= ~(__FLAG__))

is intended to clear specific flags by performing a bitwise AND operation with the complement of the flag. This method is typically used for flags that are reset by writing 0. However, as per RM0394 Rev 4 page 102 the flags in the FLASH->SRregister are cleared by writing 1.

Therefore, the correct definition should be: #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__))

This aligns with our driver's implementation. As for the issue you raised, since it is not relevant, I will proceed to close it. Thank you for your comprehension.

With regards,