cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030xx driver - Macro __HAL_FLASH_CLEAR_FLAG might be wrong

JLemi
Associate III

Related to the STM32G030xx HAL driver.

Many examples of the macro __HAL_FLASH_CLEAR_FLAG use multiple flag values ORed together. The comments on this macro seem to suggest that this is OK since the plural form is used on flagS ("Clear the FLASH pending flags", "__FLAG__ specifies the FLASH flags to clear"), although the comments also says that "This parameter can be one of the following values", suggesting that only a single value can be used.

In fact, only a single value can be used, as these two calls would do exactly the same thing:

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR);

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGAERR);

Since they would both expand to:

__HAL_FLASH_CLEAR_FLAG(0x00010005);

This is due to the fact that the FLASH_FLAG_xxxx macros are not representing a mask, but rather an identifier bit combined with a bit number. And you simply can't OR together bit numbers, it does not make sense.

The comments should remove the plural form on the word "flags", and maybe put emphasis on the fact that only a single flag can be used at a time.

I do not understand why so many examples found on the web and on this site use this macro with multiple values, as they are all wrong.

2 REPLIES 2
Simon.T
ST Employee

Hello @JLemi​ ,

First of all thanks for the discovering, I will raise an internal ticket to remove the plural form on the word "flags", in order to change it for the next firmware package revision.

However, I would like to know what example are you talking about. Is it official ST example ?

Best regards,

Simon

Piranha
Chief II

> why so many examples found on the web and on this site use this macro with multiple values

Because for most other STM32 series those defines are just a simple register flags and can be ORed together.