STM32F4 ADC driver crash system on start

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

Moderator: RoccoMarco

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

STM32F4 ADC driver crash system on start

Post by Tabulous »

Target STM32F411

ADC driver crash system on start when call to adcStart( &ADCD1, NULL ); is made. Debugger drop out and system un-responsive.

the call to this in adc_lld_start is the last thing before system runs off a cliff
adcp->adc->CR2 = ADC_CR2_ADON;


below is the code. psuInit(); is call from start of C Main

Code: Select all

#include "ch.h"
#include "hal.h"

#include "psu.h"
#include "debug.h"

/* Private define  */
/* Total number of channels to be sampled by a single ADC operation.*/
#define ADC_GRP1_NUM_CHANNELS       5

/* Depth of the conversion buffer, channels are sampled five times each.*/
#define ADC_GRP1_BUF_DEPTH          2

/* This is the scaling factor to convert to voltages.*/
#define ADC_SCALING_VDCDC           (0.0007324f)

/* Private typedef */
/* Private variables */
static psu_data_t psu_data;

static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];

/* Private function prototypes */
static void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n);

/*
 * ADC conversion group.
 * Mode:        Linear buffer, 4 samples of 2 channels, SW triggered.
 * Channels:    IN11   (48 cycles sample time)
 *              Sensor (192 cycles sample time)
 */
static const ADCConversionGroup adcgrpcfg = {
  FALSE,
  ADC_GRP1_NUM_CHANNELS,
  adccb,
  NULL,
  /* HW dependent part.*/
  0,
  ADC_CR2_SWSTART,
  ADC_SMPR2_SMP_AN5(ADC_SAMPLE_480) |
  ADC_SMPR2_SMP_AN6(ADC_SAMPLE_480) |
  ADC_SMPR2_SMP_AN7(ADC_SAMPLE_480) |
  ADC_SMPR2_SMP_AN8(ADC_SAMPLE_480) |
  ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480) ,
//  ADC_SMPR1_SMP_VBAT(ADC_SAMPLE_480) |
//  ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_480),
  0,
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
  0,
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN5) |
  ADC_SQR3_SQ2_N(ADC_CHANNEL_IN6) |
  ADC_SQR3_SQ3_N(ADC_CHANNEL_IN7) |
  ADC_SQR3_SQ4_N(ADC_CHANNEL_IN8) |
  ADC_SQR3_SQ5_N(ADC_CHANNEL_IN9) ,
//  ADC_SQR2_SQ7_N(ADC_CHANNEL_VBAT) |
//  ADC_SQR2_SQ8_N(ADC_CHANNEL_SENSOR)
};

void psuInit( void )
{

    /*
     * Initializes the ADC driver 1
     * and enable the thermal sensor
     * and enable the vbat sensor.
     */
//    adcSTM32EnableVBATE();
//    adcSTM32EnableTSVREFE();
    adcStart( &ADCD1, NULL );

    adcStartConversion( &ADCD1,
                        &adcgrpcfg,
                        samples,
                        ADC_GRP1_BUF_DEPTH );
}

/*
 * ADC end conversion callback.
 */
void adccb( ADCDriver *adcp, adcsample_t *buffer, size_t n )
{

    (void) n;
    (void)buffer;
    /* Note, only in the ADC_COMPLETE state because the ADC driver fires an
       intermediate callback when the buffer is half full.*/

    if( adcp->state == ADC_COMPLETE )
    {
        /* Calculates the average values from the ADC samples.*/
        psu_data.Vdcdc = ((samples[0] + samples[5]) / ADC_GRP1_BUF_DEPTH) * ADC_SCALING_VDCDC;

        chSysLockFromISR();
        adcStartConversionI( &ADCD1, &adcgrpcfg, samples, ADC_GRP1_BUF_DEPTH );
        chSysUnlockFromISR();
    }
}
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4 ADC driver crash system on start

Post by Giovanni »

Hi,

I haven't tested the driver on an F411 but it works fine for sure on F401, F407 and others.

Are you sure that clocks are initialized correctly? unresponsive debugger is strange even for a crash, it is the system going down hard.

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: STM32F4 ADC driver crash system on start

Post by Tabulous »

do F401, F407 use ADCv2 ?


once adcp->adc->CR2 = ADC_CR2_ADON; is done the system / debugger is unresponsive. It just resets and keeps looping.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4 ADC driver crash system on start

Post by Giovanni »

All F4s use the same ADC.

Looks like an HW issue, are you using a Nucleo board?

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: STM32F4 ADC driver crash system on start

Post by Tabulous »

Giovanni wrote:All F4s use the same ADC.

Looks like an HW issue, are you using a Nucleo board?

Giovanni


I'm starting to think that too, its custom hardware and i think the Vref+ is missing. Weird how that can make the software fail like this.....
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: STM32F4 ADC driver crash system on start

Post by Tabulous »

Just for anyone else that may run into this, the issue was VDDA, Voltage too low due to wrong resistor in filter network.


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

Re: STM32F4 ADC driver crash system on start

Post by rew »

Yeah, there are some restrictions in the datasheet about VDDA, and those are VERY serious, as in the whole chip will lock up if you don't follow the rules.
Post Reply