Starting ADC from PWM callback.

Discussions and support about ChibiOS/RT, the free embedded RTOS.
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Starting ADC from PWM callback.

Postby rew » Sun Jul 14, 2024 7:27 pm

Hi,
I'm working on an STM32F303RB currently and I'm trying to get the ADC running. I can trigger the ADC once using my commandline-command. Now I want to trigger it 40k times per second (or less we'll see) from the pwm/timer callback. I could probably setup and automatic trigger to let the hardware do it for me but this seemed easier (the PWM callback function is demoed in the pwm example).

When I call adcStartConversion I get an SV#4 : non-I class function called from interrupt. Called from an ISR.

When I call adcStartConversionI I get an SV#10 misplaced I-class function. I-class function not called from within a critical zone.

The call stack says otherwise:

Code: Select all

#0  chSysHalt (reason=reason@entry=0x8011ffc "SV#10")
    at chibios/os/rt/src/chsys.c:227
#1  0x0800a20c in chDbgCheckClassI () at chibios/os/rt/src/chdebug.c:256
#2  0x08000f3c in adcStartConversionI (adcp=0x200011a8 <ADCD1>, depth=8,
    samples=0x20002af0 <samples1.lto_priv>,
    grpp=0x8011398 <adcgrpcfg1.lto_priv>) at chibios/os/hal/src/hal_adc.c:191
#3  pwmpcb (pwmp=<optimized out>) at main.c:235
#4  0x0800f424 in VectorA4 ()
    at chibios/os/hal/ports/STM32/STM32F3xx/stm32_isr.c:267


So how is this supposed to work?

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

Re: Starting ADC from PWM callback.

Postby rew » Sun Jul 14, 2024 8:03 pm

Found it:

Code: Select all

  chSysLockFromISR ();
  adcStartConversionI(&ADCD1, &adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH);
  chSysUnlockFromISR ();

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

Re: Starting ADC from PWM callback.

Postby Giovanni » Mon Jul 15, 2024 5:36 am

Hi,

Correct, from callbacks you need to call I-Class functions, those whose name is terminated by a "I", in addition, you need to enclose the call between osalSysLockFromISR/osalSysLockFromISR.

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 5 guests