2024-08-22 05:41 AM - last edited on 2024-08-26 02:19 AM by SofLit
In my project I use 4 adc, managed with the same code. With adc5, and two channels, I had a problem: I read two equal values, that is, the second was equal to first channel.
After several searches I discovered that, in the adc.c file created by cubemx, in the section relating to adc5,
the line -->sConfig.Channel = ADC_CHANNEL_2;<-- was missing
First channel configuration
/** Configure Regular Channel */
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc5, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel */
Second channel configuration
--> sConfig.Channel = ADC_CHANNEL_2; <<-- this was not there
sConfig.Rank = ADC_REGULAR_RANK_2;
I have re-done the configuration with Cubemx several times but the problem remains
Is it a bug?
Can I do something?
It is annoying to have to remember to manually add a line of code in adc.c when I change the configuration in Cubemx.
Thanks
2024-08-22 06:45 AM - edited 2024-08-22 06:51 AM
Hello @giancarlofi
Please share your ioc file to reproduce this case.
You can check the "Keep User Code when regenerating" option and change your code in the USER CODE sections, it will be kept as it is, but this option applies only to user sections.
2024-08-22 07:26 AM
2024-08-23 02:07 AM
Hi @giancarlofi,
I checked your ioc file and the line for ADC_CHANNEL_2 is generated:
Make sure to use the latest release of STM32CubeMX and STM32CubeG4 firmware package.
2024-08-23 02:41 AM
Hi Imen, thank you for your response but the adc is hadc5 not hadc2.
2024-08-24 09:42 AM
2024-08-26 01:37 AM - edited 2024-08-26 02:31 AM
Hi @giancarlofi ,
You are right. I escalated this issue internally for fix (via internal ticket number 189389)
(PS: The internal ticket number 189389 is only for reference, not available outside of ST)
Thank you for your contribution.
2024-08-26 02:09 AM
Thanks Imen,
to get information on the bug resolution can i follow some maillist or forum?
2024-08-26 03:44 AM
We will be back to you when we fix the issue, or you can follow the Main fixed issues for coming releases via wiki page: STM32CubeMX errata - stm32mcu.