Skip to main content
This topic has been closed for replies.
Best answer by Pavel A.

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.

2 replies

Andrew Neil
Super User
July 6, 2022

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

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
MattKefford
Associate III
July 6, 2022

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);

   |  ^~~~~~~~~

Tesla DeLorean
Guru
July 6, 2022

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 VenmoUp vote any posts that you find helpful, it shows what's working..