Page 1 of 1

STM32F030x4 ADC blocks other threads

Posted: Thu Oct 08, 2020 6:05 pm
by ceremcem
Intention

I'm trying to adapt the testhal/STM32/STM32F0xx/ADC example on my custom board.

Problem

Normally I expect to read analog value from ADC input and the led blinker thread should toggle the output. However,
1. When I define adcgrpcfg1.circular as TRUE, it perfectly reads Analog Input but fails to execute the thread.
2. If I disable "adcStartConversion()" call, ADC conversion (obviously) doesn't work but the led blinker thread works.
3. If I set adcgrpcfg1.circular as FALSE, replace "adcStartConversion()" with "adcConvert()" and periodically call it, both ADC and blinker thread works, but the blinker thread experiences a lot of jitter.

Configuration and Reproduction Code
Full code can be found here: https://github.com/ceremcem/chibi-examp ... 8d384748bc. PA0 is configured as Digital Output and PA1 is configured as Analog Input, see app/adc/io.h and hw/for-adc-app/STM32F030x4/board.h.

Hardware definitions reside at hw/for-adc-app/ directory.

The ADCConversionGroup struct is as follows (declared in app/adc/main.h):

Code: Select all

static const ADCConversionGroup adcgrpcfg1 = {
  circular : TRUE,
  num_channels : ADC_CH_NUM,
  end_cb : adcReadCallback1,
  error_cb : NULL,
  cfgr1 : ADC_CFGR1_CONT \
            | ADC_CFGR1_RES_12BIT,

  // Treshold Register
  tr: ADC_TR(0, 0),                                       

  smpr : ADC_SMPR_SMP_13P5,
  chselr: ADC_CHSELR_CHSEL1
};


Dependencies are: (see dependencies.txt):

Code: Select all

ChibiOS/stable_18.2.x d050860843c6d5c3ef5cf8ab3e5d4cd03060aaf0
GCC 5.3.1


Should I use GPT and periodically call Linear Buffer configuration inside timer callback, or am I doing something wrong?

Re: STM32F030x4 ADC blocks other threads

Posted: Thu Oct 08, 2020 7:52 pm
by Giovanni
Hi,

What is your sampling speed and buffer size? if it is too fast or the buffer too small then you get an IRQ storm from the DMA and that prevents non-ISR code execution.

Giovanni

Re: STM32F030x4 ADC blocks other threads

Posted: Sat Oct 10, 2020 12:21 pm
by ceremcem
Buffer size is 1 but I don't know my sampling speed. I'm just mimicking the testhal/STM32/STM32F0xx/ADC, where is the location of sampling speed declaration in that example?

I'd been suspecting the sampling speed because I couldn't figure out where to configure it.

Re: STM32F030x4 ADC blocks other threads

Posted: Sat Oct 10, 2020 1:58 pm
by Giovanni
Hi,

Is you ADC SW-triggered? if so then it is an IRQ-storm, you get continuous interrupts because the circular conversion mode.

Thow possible solutions:
1) Disable circular mode and start your ADC when needed.
2) Trigger your ADC using a timer, this way you can control the interrupts rate.

Giovanni

Re: STM32F030x4 ADC blocks other threads

Posted: Sat Oct 10, 2020 9:58 pm
by rew
Does CHIBIOS always ask for an interrupt at the end of the buffer? I'd think that chibos would disable the IRQ if the user-code doesn't ask to be notified.

This means that in circular mode, you can have the ADC converting at max speed and the latest converted value is simply available in a memory location. Sounds like a way of using the system that could be useful.

Re: STM32F030x4 ADC blocks other threads

Posted: Sat Oct 10, 2020 10:13 pm
by Giovanni
It is a driver implementation detail, the callback is always invoked by design. Disabling the notifications would require a driver change (in adc_lld_start()).

Giovanni

Re: STM32F030x4 ADC blocks other threads

Posted: Wed Oct 14, 2020 10:33 am
by ceremcem
Giovanni wrote:Hi,

Is you ADC SW-triggered? if so then it is an IRQ-storm, you get continuous interrupts because the circular conversion mode.

Thow possible solutions:
1) Disable circular mode and start your ADC when needed.
2) Trigger your ADC using a timer, this way you can control the interrupts rate.

Giovanni


I think ADC is SW-triggered, yes, but I currently don't know how to be sure.

I tried both of your suggestions and both works pretty well. I implemented those options in ChibiOS Configurator@5df4435 and full example code can be found here. Thanks.