2024-08-16 01:58 PM
I just updated to CubeMX 6.12.0 and Firmware Pack STM32Cube FW_H7 V1.11.2. I noticed that the internal ADC selection (for ADC3 on STM32H750) is only partially working. The first time you select an internal channel, it works. However, if you then select a different internal channel, it does not enable the new channel. I verified this by reading ADC3_Common CCR register. I also tested with optimizations off to be sure it wasn't an optimization issue. I am using Keil MDK-ARM.
To reproduce:
1) Call HAL_ADC_ConfigChannel() with channel set to ADC_CHANNEL_VREFINT (do a conversion if desired)
2) Call HAL_ADC_ConfigChannel() with channel set to ADC_CHANNEL_VBAT (do a conversion if desired)
In the above steps, only VREFEN will be set. VBATEN will not be set on the second call. Switching the order will make VBATEN set but VREFEN will never be set.
To work around, I have to manually select the desired internal channel any time I use more than 1 internal ADC channel. I suspect this could be a root cause for many posts related to reading the internal ADC values, as many people are reading VREFINT first and then getting unexpected VBAT or TEMPSENSOR readings afterward.
HAL ADC library should be updated to correctly enable the internal channel every time HAL_ADC_ConfigChannel() is called. One step further, it would be nice to have HAL ADC automatically DISABLE the internal channel after a conversion on the channel is complete, at least for VBAT (I ran across some note saying the backup battery can drain faster when VBATEN is left on), unless there are intrinsic delays involved in enabling said channels. (I noticed for example that the TEMPSENSOR channel has a delay happening in the HAL library when used).
2024-08-16 02:34 PM
Hello @DPade.1
Could you please share your .ioc file.
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-16 02:48 PM
2024-08-16 02:52 PM
If you are wondering about the 3 internal channel checkboxes in CubeMX, they are checked. But it seems the HAL code does not use these to set the corresponding CCR bits...or at least it doesn't seem to set them during the init code before it gets to the main loop.