STM32CubeF4
STM32CubeF4 copied to clipboard
Implicit downcast from uint16_t to uint8_t
Describe the set-up
- Enabled
-Wconversion
in gcc.
Describe the bug
The compiler warns about an implicit downcast from uint16_t
to uint8_t
in LL_ADC_REG_ReadConversionData8()
and LL_ADC_REG_ReadConversionData6()
.
https://github.com/STMicroelectronics/STM32CubeF4/blob/3d6be4bd406f275728e0a321cc371c62a3100533/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_adc.h#L4016-L4019
https://github.com/STMicroelectronics/STM32CubeF4/blob/3d6be4bd406f275728e0a321cc371c62a3100533/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_adc.h#L4031-L4034
How To Reproduce
Compile a file which includes stm32f4xx_ll_adc.h
with -Wconversion
in gcc.
Additional context
A cast is already included for the return value within the named functions.
I propose to change the cast from uint16_t
to uint8_t
.
Hi @daniel-starke,
First, thank you for this report. Actually, the point you have mentioned has been raised within another issue. It has been fixed internally and the fix will be available in the frame of a next release.
The fix is as follow:
__STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData8(ADC_TypeDef *ADCx)
{
- return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
+ return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
}
__STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData6(ADC_TypeDef *ADCx)
{
- return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
+ return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
}
With regards,
ST Internal Reference: 118485
Fixed in commit d5af56388ff037735ac99de39abf2b46f9921aa3