2024-08-20 07:20 AM
I recently changed the configuration of working product from HAL API to LL API to improve performances.
Unfortunately, the LL initialisation code generated by the STM32CubeIDE for the ADC was incomplete, and forgets to set the PCSEL register when needed, resulting in the ADC converter just generating random numbers.
By comparing the registers with the 2 initialisation methods, I found the solution by adding LL_ADC_SetChannelPreselection() when needed.
Below is the code generated by the IDE, and with the 2 missing calls added (after the BUG: comment)
Note: the LL_ADC_SetChannelPreselection() calls should NOT be added when using analog only pads, like PA0_C, PA1_C, PC2_C, PC3_C. However, for general I/O pads, if LL_ADC_SetChannelPreselection() is missing, then the ADC just convert noise.
/** Configure Regular Channel
*/
LL_ADC_REG_SetSequencerRanks(ADC2, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_12);
LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_12, LL_ADC_SAMPLINGTIME_8CYCLES_5);
LL_ADC_SetChannelSingleDiff(ADC2, LL_ADC_CHANNEL_12, LL_ADC_SINGLE_ENDED);
/** Configure Regular Channel
*/
LL_ADC_REG_SetSequencerRanks(ADC2, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_13);
LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_13, LL_ADC_SAMPLINGTIME_8CYCLES_5);
LL_ADC_SetChannelSingleDiff(ADC2, LL_ADC_CHANNEL_13, LL_ADC_SINGLE_ENDED);
/* USER CODE BEGIN ADC2_Init 2 */
/* BUG: these two calls are missing from code generated by the STM32CubeIDE */
LL_ADC_SetChannelPreselection(ADC2, LL_ADC_CHANNEL_12);
LL_ADC_SetChannelPreselection(ADC2, LL_ADC_CHANNEL_13);
/* USER CODE END ADC2_Init 2 */
Solved! Go to Solution.
2024-08-21 01:50 AM
Hello @cberg.1
Sorry for my late replay. I've escalated this issue, after investigation, For correction on the coming releases (under internal ticket number 189043).
Best Regards.
STTwo-32
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-08-20 07:25 AM - edited 2024-08-20 07:33 AM
Hello @cberg.1
Could you please share your .ioc file so I can analyze the issue. Also, add you CubeFirmware, CubeMX and CubeIDE versions.
Best Regards.
STTwo-32
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-08-20 09:05 AM
Hello,
Latest IDE version (1.16.0) and Latest H7 firmware package.
Please find attached the IOC file.
Note (1): All the devices are configured by the M4.
Note (2): Only ADC2 is misconfigured. ADC1 and ADC3 are configured properly.
Cedrics-MBP:ide cedric$ cat dl3smart.ioc |grep Version
File.Version=6
MxCube.Version=6.12.0
MxDb.Version=DB.6.0.120
2024-08-21 01:50 AM
Hello @cberg.1
Sorry for my late replay. I've escalated this issue, after investigation, For correction on the coming releases (under internal ticket number 189043).
Best Regards.
STTwo-32
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.