cancel
Showing results for 
Search instead for 
Did you mean: 

Can this be an issue with CubeMX?

Scott Dev
Senior
Posted on April 07, 2017 at 16:42

Hi

   I am beginning to wonder if this is an issue with CubeMX? I recently posted an issue I am having below on the ADC of the STM32L073 chip. Its a small application created with CubeMX and have checked it many times, and still have the same issues as in the link below. I wanted to check it many times (most of the day) before thinking it must be a CubeMX issue. The 'HAL_ADC_ConvCpltCallback' was only called once on one channel , even though 3 channels have been added. The if (__HAL_ADC_GET_FLAG(hadc, ADC_IT_EOC)) code was executed, and straight after the 'if (__HAL_ADC_GET_FLAG(hadc, ADC_IT_EOS))' was also executed. This makes me think that it is setup for only 1 channel to convert. 

https://community.st.com/0D50X00009XkYLuSAN

   << link to issue

I have it working, but more like a work around. Within CubeMX I have 'Discontinues convertion mode ' Enabled. And within the HAL_ADC_ConvCpltCallback(..) routine I done the following, just to check to see if it works:  In my main.cpp routine I call HAL_ADC_Start_IT(&hadc); to start convertion, then:

HAL_ADC_ConvCpltCallback(..)

{

      if (__HAL_ADC_GET_FLAG(hadc, ADC_IT_EOC))  //check convertion on channel

        {

            EOCCount++;

            ADC_Raw[ADC_index++]=HAL_ADC_GetValue(hadc);

            if(ADC_index==3)

                ADC_index=0;  //after the 3 channels converted reset

            else

                HAL_ADC_Start_IT(hadc); //restart on next channel

        }

//this time, the below got called only once as expected, after the 3 ADC_IT_EOC above were executed.

        if (__HAL_ADC_GET_FLAG(hadc, ADC_IT_EOS))

        {

    EOSCount++;

}

Anyone suggest the best way to go from here regarding this?

Thanks

Scott

null
5 REPLIES 5
Imen.D
ST Employee
Posted on April 10, 2017 at 18:21

Hi

devlin.scott

,

Thank you for reported issue.

I will raise this internally for more checking and we come back to you soon.

Imen

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

Hi Imen

I having the exact same issues on the stm32L011k4, has this been resolved?

Thanks

Nathan

Posted on June 08, 2017 at 11:50

Hi

gates.nathan

,

I have checked the status of this issue internally and our teamis working on the analysis for fixing it in the coming releases.

Sorry for any inconvenienceit may bring for you.

Best Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Cyril FENARD
ST Employee
Posted on September 07, 2017 at 13:05

Hi Scott Dev,

It is not safe to call HAL_ADC_Start_IT(hadc) after each EOC interrupt because the value that is read may not correspond to the channel you are expecting in the sequence of ADC channels (Especially if the sequence is already finished).

Please try to check what are the frequencies of the CPU code and the sample time of the ADC.

CPU speed should be enough compare to sampling time of ADC. May you try with sampling time being longer?

Please find also some advices from Philippe CHERBONNEL:

'When ADC conversions in sequence, it is recommended to use DMA transfer:

- if using ADC only (polling or interruption), each conversion of the sequence has its result stored in data register and overwrites the data of previous conversion. If the CPU does not read data register is time (CPU load too high versus ADC IRQ priority), then the ADC conversion data is lost (overwritten by conversion of the following sequence rank).

- if using ADC+DMA, all ADC conversions are transferred independently of CPU load. DMA manages to transfer all data in a table with circular rollback.

Note: If using interruption at each DMA transfer completion (this is the case using HAL driver, optional using LL driver), user must take care that DMA IT occurrence rate does not saturate CPU. This can be done by decreasing ADC conversion rate (increase ADC sampling time, decrease ADC trigger frequency, …).

You can find some examples in STM32L0 FW package (can be downloaded here:

http://www.st.com/en/embedded-software/stm32cubel0.html

).

Some examples showing ADC+DMA transfer with several channels are available here:

- using LL driver:

…\Firmware\Projects\STM32L073RZ-Nucleo\Examples_LL\ADC\ADC_MultiChannelSingleConversion

- using HAL driver:

…\Firmware\Projects\STM32L053R8-Nucleo\Examples\ADC\ADC_Sequencer

'

Philippe also reminded the following link:

https://community.st.com/thread/36558-adc-values-reading-with-dma

Thanks to Philippe and hope it is going to help you.

Regards

Cyril

Posted on September 11, 2017 at 17:08

Thanks Cyril

   I have decided to not use CubeMX , I used it to learn the processor and amazed at the large overhead of the code. I am now just using the registers .

Thanks

Scott