From 9388b24c161f037371ac11262301d030c07feafe Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 18 Mar 2013 20:02:03 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5452 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32F37x/adc_lld.h | 9 ------ testhal/STM32F37x/ADC/main.c | 61 +++++++++++++++++------------------- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/os/hal/platforms/STM32F37x/adc_lld.h b/os/hal/platforms/STM32F37x/adc_lld.h index 240bd9a67..9af0e5b5c 100644 --- a/os/hal/platforms/STM32F37x/adc_lld.h +++ b/os/hal/platforms/STM32F37x/adc_lld.h @@ -440,14 +440,10 @@ typedef struct { uint32_t cr2; /** * @brief ADC LTR register initialization data. - * @note Set to zero in order to disable the low threshold of the - * analog watchdog. */ uint32_t ltr; /** * @brief ADC HTR register initialization data. - * @note Set to 4095 (0xFFF) in order to disable the high threshold - * of the analog watchdog. */ uint32_t htr; /** @@ -662,11 +658,6 @@ extern "C" { void adcSTM32EnableVBATE(void); void adcSTM32DisableVBATE(void); #endif /* STM32_ADC_USE_ADC */ -#if 0 - void sdadcSTM32VREFSelect(SDADC_VREF_SEL svs); - void sdadcSTM32Calibrate(ADCDriver* adcdp, SDADC_NUM_CALIB_SEQ numCalibSequences, - ADCConversionGroup* grpp); -#endif /* STM32_ADC_USE_SDADC */ #ifdef __cplusplus } #endif diff --git a/testhal/STM32F37x/ADC/main.c b/testhal/STM32F37x/ADC/main.c index c2e81b4c3..20e8ff8db 100644 --- a/testhal/STM32F37x/ADC/main.c +++ b/testhal/STM32F37x/ADC/main.c @@ -54,7 +54,7 @@ static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) { /* * ADC conversion group. * Mode: Linear buffer, 8 samples of 2 channels, SW triggered. - * Channels: IN7, IN8. + * Channels: IN1, IN9. */ static const ADCConversionGroup adcgrpcfg1 = { FALSE, @@ -63,51 +63,49 @@ static const ADCConversionGroup adcgrpcfg1 = { adcerrorcallback, .u.adc = { 0, /* CR1 */ - 0, /* CR2 */ + ADC_CR2_SWSTART, /* CR2 */ 0, /* LTR */ - 4095, /* HTR */ + 0, /* HTR */ { /* SMPR[2] */ 0, - 0 + ADC_SMPR2_SMP_AN9(ADC_SAMPLE_41P5) | ADC_SMPR2_SMP_AN1(ADC_SAMPLE_41P5), }, { /* SQR[3] */ 0, 0, - 0 + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN1) } } }; -#if 0 /* * ADC conversion group. * Mode: Continuous, 16 samples of 8 channels, SW triggered. - * Channels: IN7, IN8, IN7, IN8, IN7, IN8, Sensor, VBat/2. + * Channels: IN1, IN9, IN1, IN9, IN1, IN9, VBat, Sensor. */ static const ADCConversionGroup adcgrpcfg2 = { TRUE, ADC_GRP2_NUM_CHANNELS, adccallback, adcerrorcallback, - 0, /* CFGR */ - ADC_TR(0, 4095), /* TR1 */ - ADC_CCR_TSEN | ADC_CCR_VBATEN, /* CCR */ - { /* SMPR[2] */ - ADC_SMPR1_SMP_AN7(ADC_SMPR_SMP_19P5) - | ADC_SMPR1_SMP_AN8(ADC_SMPR_SMP_19P5), - ADC_SMPR2_SMP_AN16(ADC_SMPR_SMP_61P5) - | ADC_SMPR2_SMP_AN17(ADC_SMPR_SMP_61P5), - }, - { /* SQR[4] */ - ADC_SQR1_SQ1_N(ADC_CHANNEL_IN7) | ADC_SQR1_SQ2_N(ADC_CHANNEL_IN8) | - ADC_SQR1_SQ3_N(ADC_CHANNEL_IN7) | ADC_SQR1_SQ4_N(ADC_CHANNEL_IN8), - ADC_SQR2_SQ5_N(ADC_CHANNEL_IN7) | ADC_SQR2_SQ6_N(ADC_CHANNEL_IN8) | - ADC_SQR2_SQ7_N(ADC_CHANNEL_IN16) | ADC_SQR2_SQ8_N(ADC_CHANNEL_IN17), - 0, - 0 + .u.adc = { + 0, /* CR1 */ + ADC_CR2_SWSTART, /* CR2 */ + 0, /* LTR */ + 0, /* HTR */ + { /* SMPR[2] */ + ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_239P5) | ADC_SMPR1_SMP_VREF(ADC_SAMPLE_239P5), + ADC_SMPR2_SMP_AN9(ADC_SAMPLE_41P5) | ADC_SMPR2_SMP_AN1(ADC_SAMPLE_41P5) + }, + { /* SQR[3] */ + 0, + ADC_SQR2_SQ8_N(ADC_CHANNEL_SENSOR) | ADC_SQR2_SQ7_N(ADC_CHANNEL_VBAT), + ADC_SQR3_SQ6_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ5_N(ADC_CHANNEL_IN1) | + ADC_SQR3_SQ4_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ3_N(ADC_CHANNEL_IN1) | + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN1) + } } }; -#endif /* * Red LEDs blinker thread, times are in milliseconds. @@ -141,21 +139,18 @@ int main(void) { halInit(); chSysInit(); - /* - * Setting up analog inputs used by the demo. - */ - palSetGroupMode(GPIOC, PAL_PORT_BIT(1) | PAL_PORT_BIT(2), - 0, PAL_MODE_INPUT_ANALOG); - /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Activates the ADC1 driver and the temperature sensor. + * Activates the ADC1 driver, the temperature sensor and the VBat + * measurement. */ adcStart(&ADCD1, NULL); + adcSTM32EnableTSVREFE(); + adcSTM32EnableVBATE(); /* * Linear conversion. @@ -166,14 +161,14 @@ int main(void) { /* * Starts an ADC continuous conversion. */ -// adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH); + adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH); /* * Normal main() thread activity, in this demo it does nothing. */ while (TRUE) { if (palReadPad(GPIOA, GPIOA_WKUP_BUTTON)) { -// adcStopConversion(&ADCD1); + adcStopConversion(&ADCD1); } chThdSleepMilliseconds(500); } -- cgit v1.2.3