2014-12-13 12:21 PM
STM32CubeMX 4.5.0 generates the following code for multichannel ADC
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_1|ADC_CHANNEL_6|ADC_CHANNEL_8;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
But HAL_ADC_ConfigChannel stm32l0xx_hal_adc.c V1.1.0 has
assert_param(IS_ADC_CHANNEL(sConfig->Channel));
which crashes because IS_ADC_CHANNEL() checks for a single channel, not a set.
The fix is to comment out this assert_param(). I have not checked whether ADC actually works. Are there any examples of actual conversions using stm32l0xx_hal_adc.c ?
Best regards,
Tomasz Motylewski
K&J Schmittschneider AG
#multichannel #stm32l0 #stm32cubemx #adc
2015-01-22 01:16 AM
HiTomasz,
In fact, theHAL ADC sequencer must be configured channel by channel.In your example, the correct configuration is:sConfig.Channel = ADC_CHANNEL_1;
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
{
/* Channel Configuration Error */
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_6;
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
{
/* Channel Configuration Error */
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_8;
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
{
/* Channel Configuration Error */
Error_Handler();
}
This configuration procedure is due to compatibility reasons over ADC IPs over all STM32 families.
From hardware point of view, STM32L0 ADC could be configured the way you mention because sequencer is dependent to channel number. But other STM32 ADC (STM32F1, STM32F3, STM32F4, STM32L1, STM32L4) have a sequencer fully configurable: each channel can be set to a defined rank.
Therefore, if you migrate from STM32L0 to another STM32, the HAL ADC configuration with be compatible.
The configuration issue you have encountered in CubeMX will be corrected.
An example showing how to use the ADC sequencer will be included in the next STM32L0 firmware package release, named ''ADC_Sequencer''.
With regards,
Heisenberg.