cancel
Showing results for 
Search instead for 
Did you mean: 

Warning in HAL CRC since updating to F0 Cube v1.11.3

MattKefford
Associate III

The clear_bit macro in the CMSIS driver is causing a warning when used in the function HAL_CRC_DeInit:

0693W00000QKZgGQAX.png

1 ACCEPTED SOLUTION

Accepted Solutions

The CLEAR_BIT macro usually deals with 32-bit registers, but CRC_IDR is 8 bit. So even as  CRC_IDR_IDR is cast to uint8_t, operator ~ promotes it back to signed int.

The best solution IMHO is replace CLEAR_BIT to simple assignment:

hcrc->Instance->IDR = 0;

You can post a bug report on ST's github.

View solution in original post

6 REPLIES 6

No doubt the code has always had that "issue", but the default warning level has changed - so now you see the warning.

The thing in square brackets at the end is the option to disable this warning:

0693W00000QKZkwQAH.png 

Also, googling "Woverflow" will get you to documentation of exactly what that warning's all about.

It's generally better to copy & paste as text rather than an image

MattKefford
Associate III

Thanks for the reply Andrew!

I have had a look at my project settings and there's no option to turn -Woverflow on or off:

0693W00000QKZo5QAH.pngI could deselect -Wall in this settings window but I would like to know about warnings really. If it's something in my code that could cause a bug.

So it seems I would have to add the pre-processor instructions:

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Woverflow"

// ... offending code here ...

#pragma GCC diagnostic pop

But I can't add this as it's in the HAL code and will be overwritten/removed next time I generate the project with CubeMX.

Here's the text from the screenshot if any ST people need it:

../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_crc.c: In function 'HAL_CRC_DeInit':

../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h:198:41: warning: overflow in conversion from 'int' to 'uint8_t' {aka 'volatile unsigned char'} changes value from '(int)hcrc->Instance->IDR & -256' to '0' [-Woverflow]

 198 | #define CLEAR_BIT(REG, BIT)  ((REG) &= ~(BIT))

   |                     ^

../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_crc.c:205:3: note: in expansion of macro 'CLEAR_BIT'

 205 |  CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR);

   |  ^~~~~~~~~

There's perhaps a command line level option to allow more carte-blanche feed-thru to the compiler where the tools don't individually check-box all combinations of available settings?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

The CLEAR_BIT macro usually deals with 32-bit registers, but CRC_IDR is 8 bit. So even as  CRC_IDR_IDR is cast to uint8_t, operator ~ promotes it back to signed int.

The best solution IMHO is replace CLEAR_BIT to simple assignment:

hcrc->Instance->IDR = 0;

You can post a bug report on ST's github.

I will do that, thank you for the help

Hi Pavel, further to your suggestion there is actually a macro CLEAR_REG which does the same as you suggested and removes the warning 👍🏻

#define CLEAR_REG(REG)        ((REG) = (0x0))

 I also found a macro in the CRC header file which could be used too:

__HAL_CRC_SET_IDR(hcrc, 0);

So I will suggest both of these and let them pick.

Thanks again!