STM32F4 ADC driver crash system on start
Posted: Tue Feb 07, 2017 1:22 pm
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
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();
}
}