STMicroelectronics / stm32l0xx_hal_driver

Provides the STM32Cube MCU Component "hal_driver" of the STM32L0 series.
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

ADC External Trigger Conversion Sources Incorrect for Category 1 Devices #7

Open mbrossett opened 1 year ago

mbrossett commented 1 year ago

Using custom board with STM32L011F3P3. IDE is Keil MDK Version 5.38 with ST32CubeMX version 6.9.1.

The STM32L0xx reference manual (Feb 2022) states on page 281, that the TIM21_TRGO trigger is only available on Category 1 devices, which is defined on page 47 as the STM32L011x and STM32L021x devices.

CubeMX does not allow setting the ADC external trigger conversion source as TIM21_TRGO. Upon inspection of the HAL driver (stm32l0xx_hal_adc_ex.h, line 68) it is coded to only allow TIM21_TRGO on Cat. 2, 3, and 5 devices (all except Cat. 1).

To determine if the reference manual or the HAL driver was wrong, I manually set the external trigger to TIM21_TRGO (hadc.Init.ExternalTrigConv = ADC_CFGR1_EXTSEL_2;) per ref. manual page 281. Debugging the code I verified the callback, HAL_ADC_ConvCpltCallback(), was being fired and the debug output pin was being toggled in the center of each pulse width of the PWM output as expected. See code snippets below. Screenshots of CubeMX config, HAL driver, ref. manual are attached for reference.

// top of main.c... HAL_TIM_Base_Start_IT(&htim21); HAL_TIM_PWM_Start_IT(&htim21, TIM_CHANNEL_1); HAL_ADC_Start_IT(&hadc);

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) { adcVal = HAL_ADC_GetValue(hadc); HAL_GPIO_TogglePin(DEBUG_OUT_GPIO_Port, DEBUG_OUT_Pin); }

RefManual_ADC_ExtTrigConv_Sources

RefManual_Device_Categories

ST32CubeMX_ADC_Config

ST32CubeMX_TIM21_Config

stm32l0xx_hal_adc_ex_BUG

RJMSTM commented 1 year ago

Hello @mbrossett ,

Thank you for this report. We will get back to you as soon as we analyze it further. This may take some time. Thank you for your comprehension.

With regards, Rania

mbrossett commented 1 year ago

Thank you @RJMSTM