cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 ADC Bug in Interrupt Enable of HAL

hemogloben
Associate II
Posted on June 20, 2017 at 00:07

I've been working on a board based on the STM32F3 with a large number of ADCs and other peripherals. I'll also be using multiple I2C and UART peripherals; the responsiveness of I2C and UART is much higher than the ADCs so I have to reserve DMA usage for I2C and UART.

Due to the above restriction, I planned to use the Single ADC Conversion interrupt to manually store the results of conversions. After implementing this I ran into an issue caused by HAL not respecting by choice of End of Conversion Selection:

In my Initialization code, all four ADCs were configured with

handle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;�?

After running into issues I traced the source of the problem back to lines ~2074 of stm32f3xx_hal_adc_ex.c:

They Are:

 /* Enable ADC end of conversion interrupt */
 /* Enable ADC overrun interrupt */ 
 switch(hadc->Init.EOCSelection)
 {
 case ADC_EOC_SEQ_CONV: 
 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
 __HAL_ADC_ENABLE_IT(hadc, (ADC_IT_EOS));
 break;
 /* case ADC_EOC_SINGLE_CONV */
 default:
 __HAL_ADC_ENABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS));
 break;
 }�?�?�?�?�?�?�?�?�?�?�?�?�?

They Should be:

 /* Enable ADC end of conversion interrupt */
 /* Enable ADC overrun interrupt */ 
 switch(hadc->Init.EOCSelection)
 {
 case ADC_EOC_SEQ_CONV: 
 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
 __HAL_ADC_ENABLE_IT(hadc, (ADC_IT_EOS));
 break;
 /* case ADC_EOC_SINGLE_CONV */
 case ADC_EOC_SINGLE_CONV:
 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOS);
 __HAL_ADC_ENABLE_IT(hadc, (ADC_IT_EOC));
 break;
 /* case ADC_EOC_SINGLE_SEC_CONV */
 default:
 __HAL_ADC_ENABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS));
 break;
 }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I know I'm not using the latest version of the F3 libraries (haven't had a chance to update yet), but I checked V1.8 and the issue is still present.

1 ACCEPTED SOLUTION

Accepted Solutions
Imen.D
ST Employee
Posted on June 20, 2017 at 15:48

Hi

Artes.Benjamin

,

ADC_EOC_SINGLE_SEQ_CONV is not used in HAL driver. It is commented as reserved for future usebutit will be removed

in the next release of CubeF3.

#define ADC_EOC_SINGLE_SEQ_CONV ((uint32_t)(ADC_ISR_EOC | ADC_ISR_EOS)) /*!< reserved for future use */

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

View solution in original post

2 REPLIES 2
Imen.D
ST Employee
Posted on June 20, 2017 at 15:48

Hi

Artes.Benjamin

,

ADC_EOC_SINGLE_SEQ_CONV is not used in HAL driver. It is commented as reserved for future usebutit will be removed

in the next release of CubeF3.

#define ADC_EOC_SINGLE_SEQ_CONV ((uint32_t)(ADC_ISR_EOC | ADC_ISR_EOS)) /*!< reserved for future use */

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on June 20, 2017 at 22:12

Marked as correct.

I saw that note, but is there a reason that:

  1. This wasn't implemented in the first place?
  2. This is being removed?

It seems like a useful setting to have that is supported by the hardware; why is the HAL removing it?  Removing it will likely result in users just manually setting EOC in the IER which, depending on HAL's implementation, could expose them up to MORE bugs (as the HAL code seems to be written with the assumption that the User isn't changing settings in the peripheral outside of HAL calls.)