STM32F030x4 ADC blocks other threads Topic is solved

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

ceremcem
Posts: 67
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 7 times
Been thanked: 6 times

STM32F030x4 ADC blocks other threads

Postby ceremcem » Thu Oct 08, 2020 6:05 pm

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?

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F030x4 ADC blocks other threads

Postby Giovanni » Thu Oct 08, 2020 7:52 pm

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

ceremcem
Posts: 67
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 7 times
Been thanked: 6 times

Re: STM32F030x4 ADC blocks other threads

Postby ceremcem » Sat Oct 10, 2020 12:21 pm

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.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F030x4 ADC blocks other threads  Topic is solved

Postby Giovanni » Sat Oct 10, 2020 1:58 pm

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

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: STM32F030x4 ADC blocks other threads

Postby rew » Sat Oct 10, 2020 9:58 pm

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.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F030x4 ADC blocks other threads

Postby Giovanni » Sat Oct 10, 2020 10:13 pm

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

ceremcem
Posts: 67
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 7 times
Been thanked: 6 times

Re: STM32F030x4 ADC blocks other threads

Postby ceremcem » Wed Oct 14, 2020 10:33 am

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.
Attachments
for-adc-app.zip
(61.78 KiB) Downloaded 163 times


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 49 guests