External ADC trigger with PWM -> chSysHalt() Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times
Contact:

External ADC trigger with PWM -> chSysHalt()  Topic is solved

Postby wurstnase » Fri Mar 09, 2018 11:30 am

Hi all,

I want to make a continuous conversion with external trigger with the pwm driver.
Everything work expected when using the I-class functions for pwmEnableChannelI and pwmEnableChannelNotificationI.

I'm using a STM32F103 with the latest stable branch 18.2.x.

In the 'normal' functions is a check:

Code: Select all

void pwmEnableChannelNotification(PWMDriver *pwmp, pwmchannel_t channel) {
  osalDbgCheck((pwmp != NULL) && (channel < pwmp->channels));

and I run into chSysHalt() in this case. Because there is not check in I-Class, this works as expected.

Code: Select all

static const ADCConversionGroup adcgrp1cfg = {
  TRUE,
  ADC_GRP1_NUM_CHANNELS,
  NULL, /* adc callback */
  NULL, /* error callback */
  0, ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL_SRC(0x5), /* CR1, CR2 */
  0,
  ADC_SMPR2_SMP_AN2(ADC_SAMPLE_71P5),
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
  0,
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN2),
};


Code: Select all

static const PWMConfig pwm_cfg = {
    250000,
    250,
    NULL,
    {
        {PWM_OUTPUT_DISABLED, NULL},
        {PWM_OUTPUT_DISABLED, NULL},
        {PWM_OUTPUT_DISABLED, NULL},
        {PWM_OUTPUT_ACTIVE_HIGH, adc_pwm_cb},
    },
    0,
    0,
};


Code: Select all

static void startConversion(void *ip)
{
  AnalogDriver *analog = (AnalogDriver *)ip;
  (void)analog;

  adc_counter = 0;
  pwmEnableChannelI(&PWMD4, 3, 1);
  pwmEnableChannelNotificationI(&PWMD4, 3);
}


Code: Select all

static void adc_pwm_cb(PWMDriver *pwmp){
  (void)pwmp;
  adc_counter++;
  chSysLockFromISR();
  chThdResumeI(&analog_tp, MSG_OK);
  chSysUnlockFromISR();
  if (adc_counter >= ADC_NUM_CONVERSIONS) {
    chSysLockFromISR();
    pwmDisableChannelI(&PWMD4, 3);
    chSysUnlockFromISR();
  }
}
\o/ Nico

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

Re: External ADC trigger with PWM -> chSysHalt()

Postby Giovanni » Fri Mar 09, 2018 12:13 pm

Sorry, it is not clear to me what is your question.

Giovanni

User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times
Contact:

Re: External ADC trigger with PWM -> chSysHalt()

Postby wurstnase » Fri Mar 09, 2018 5:10 pm

Oh sorry.

I expect to be able to use pwmEnableChannelNotification(&PWMD4, 3) but pwmp->channels is zero. Probably I'm missing something?
\o/ Nico

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

Re: External ADC trigger with PWM -> chSysHalt()

Postby Giovanni » Fri Mar 09, 2018 6:25 pm

That field is only initialized and never changed, verify that it contains 4 after halInit(). If it is cleared afterward then it could be a stack overflow corrupting it.

Giovanni

User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times
Contact:

Re: External ADC trigger with PWM -> chSysHalt()

Postby wurstnase » Sat Mar 10, 2018 2:44 pm

Thanks for the hint. I will check it on Monday. Last time searching through the source I found only an init to zero.
\o/ Nico

User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times
Contact:

Re: External ADC trigger with PWM -> chSysHalt()

Postby wurstnase » Sun Mar 11, 2018 8:58 pm

Got my fault.

Was a bit confusing. The hal PWM driver pwmInit will execute pwm_lld_init, which will execute the pwmObjectInit.
In my source I execute the pwmObjectInit for each pwm separately. But the pwm_lld_init itself will set the channels and the pwmObjectInit will set this to zero.
\o/ Nico

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

Re: External ADC trigger with PWM -> chSysHalt()

Postby Giovanni » Sun Mar 11, 2018 9:30 pm

Usually halInit() calls all the required initializers, there is never need to call xxxObjectInit().

Giovanni

User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times
Contact:

Re: External ADC trigger with PWM -> chSysHalt()

Postby wurstnase » Mon Mar 12, 2018 8:03 am

This makes sense. Thanks. Problem solved.
\o/ Nico


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 17 guests