Skip to main content
hemogloben
Associate II
June 19, 2017
Solved

STM32F3 ADC Bug in Interrupt Enable of HAL

  • June 19, 2017
  • 1 reply
  • 922 views
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.

    This topic has been closed for replies.
    Best answer by Imen.D
    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

    1 reply

    Imen.DBest answer
    ST Technical Moderator
    June 20, 2017
    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

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    hemogloben
    Associate II
    June 20, 2017
    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.)