2022-07-06 07:56 AM
The clear_bit macro in the CMSIS driver is causing a warning when used in the function HAL_CRC_DeInit:
Solved! Go to Solution.
2022-07-06 09:36 AM
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.
2022-07-06 08:09 AM
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:
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
2022-07-06 08:39 AM
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:
I 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);
| ^~~~~~~~~
2022-07-06 08:56 AM
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?
2022-07-06 09:36 AM
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.
2022-07-06 09:52 AM
I will do that, thank you for the help
2022-08-15 05:03 AM
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!