From 13d1d184c8ca5120895935366b21ded41c850177 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 30 Dec 2018 11:22:26 +0000 Subject: More H7 ADC code. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12494 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- testhal/STM32/STM32L4xx/GPT-ADC/main.c | 2 +- .../multi/ADC/cfg/stm32h743_nucleo144/portab.c | 48 +++++++++++++++++--- .../multi/ADC/cfg/stm32h743_nucleo144/portab.h | 4 +- testhal/STM32/multi/ADC/main.c | 53 ++++++++++++++++++++-- 4 files changed, 95 insertions(+), 12 deletions(-) (limited to 'testhal/STM32') diff --git a/testhal/STM32/STM32L4xx/GPT-ADC/main.c b/testhal/STM32/STM32L4xx/GPT-ADC/main.c index b7d0875f8..648b1992f 100644 --- a/testhal/STM32/STM32L4xx/GPT-ADC/main.c +++ b/testhal/STM32/STM32L4xx/GPT-ADC/main.c @@ -78,7 +78,7 @@ static const ADCConversionGroup adcgrpcfg1 = { adccallback, adcerrorcallback, ADC_CFGR_EXTEN_RISING | ADC_CFGR_EXTSEL_SRC(12), /* CFGR */ - 0, /* CFGR2 */ + 0, /* CFGR2 */ ADC_TR(0, 4095), /* TR1 */ { /* SMPR[2]*/ ADC_SMPR1_SMP_AN0(ADC_SMPR_SMP_247P5) | diff --git a/testhal/STM32/multi/ADC/cfg/stm32h743_nucleo144/portab.c b/testhal/STM32/multi/ADC/cfg/stm32h743_nucleo144/portab.c index 226f4ba11..2e16ae935 100644 --- a/testhal/STM32/multi/ADC/cfg/stm32h743_nucleo144/portab.c +++ b/testhal/STM32/multi/ADC/cfg/stm32h743_nucleo144/portab.c @@ -45,7 +45,8 @@ const GPTConfig portab_gptcfg1 = { }; const ADCConfig portab_adccfg1 = { - .difsel = 0U + .difsel = 0U, + .calibration = 0U }; void adccallback(ADCDriver *adcp); @@ -56,17 +57,50 @@ void adccallback(ADCDriver *adcp); void adcerrorcallback(ADCDriver *adcp, adcerror_t err); /* - * ADC conversion group. - * Mode: Continuous, 16 samples of 2 channels, HW triggered by - * GPT4-TRGO. - * Channels: VRef, PA0. + * ADC conversion group 1. + * Mode: One shot, 2 channels, SW triggered. + * Channels: IN0, IN5. */ const ADCConversionGroup portab_adcgrpcfg1 = { - .circular = true, + .circular = false, .num_channels = ADC_GRP1_NUM_CHANNELS, + .end_cb = NULL, + .error_cb = adcerrorcallback, + .cfgr = 0U, + .cfgr2 = 0U, + .ccr = 0U, + .pcsel = ADC_SELMASK_IN0 | ADC_SELMASK_IN5, + .ltr1 = 0x00000000U, + .htr1 = 0x03FFFFFFU, + .ltr2 = 0x00000000U, + .htr2 = 0x03FFFFFFU, + .ltr3 = 0x00000000U, + .htr3 = 0x03FFFFFFU, + .smpr = { + ADC_SMPR1_SMP_AN0(ADC_SMPR_SMP_384P5) | + ADC_SMPR1_SMP_AN5(ADC_SMPR_SMP_384P5), + 0U + }, + .sqr = { + ADC_SQR1_SQ1_N(ADC_CHANNEL_IN0) | ADC_SQR1_SQ2_N(ADC_CHANNEL_IN5), + 0U, + 0U, + 0U + } +}; + +/* + * ADC conversion group 2. + * Mode: Continuous, 2 channels, HW triggered by GPT4-TRGO. + * Channels: IN0, IN5. + */ +const ADCConversionGroup portab_adcgrpcfg2 = { + .circular = true, + .num_channels = ADC_GRP2_NUM_CHANNELS, .end_cb = adccallback, .error_cb = adcerrorcallback, - .cfgr = ADC_CFGR_EXTEN_RISING | ADC_CFGR_EXTSEL_SRC(12), + .cfgr = ADC_CFGR_EXTEN_RISING | + ADC_CFGR_EXTSEL_SRC(12), /* TIM4_TRGO */ .cfgr2 = 0U, .ccr = 0U, .pcsel = ADC_SELMASK_IN0 | ADC_SELMASK_IN5, diff --git a/testhal/STM32/multi/ADC/cfg/stm32h743_nucleo144/portab.h b/testhal/STM32/multi/ADC/cfg/stm32h743_nucleo144/portab.h index 955d830f7..56ae995fa 100644 --- a/testhal/STM32/multi/ADC/cfg/stm32h743_nucleo144/portab.h +++ b/testhal/STM32/multi/ADC/cfg/stm32h743_nucleo144/portab.h @@ -38,9 +38,11 @@ #define PORTAB_SD1 SD2 -#define PORTAB_DAC_TRIG 5 +#define PORTAB_GPT1 GPTD4 +#define PORTAB_ADC1 ADCD1 #define ADC_GRP1_NUM_CHANNELS 2 +#define ADC_GRP2_NUM_CHANNELS 2 /*===========================================================================*/ /* Module pre-compile time settings. */ diff --git a/testhal/STM32/multi/ADC/main.c b/testhal/STM32/multi/ADC/main.c index 19328dc26..68d5f3130 100644 --- a/testhal/STM32/multi/ADC/main.c +++ b/testhal/STM32/multi/ADC/main.c @@ -19,6 +19,44 @@ #include "portab.h" +/*===========================================================================*/ +/* ADC driver related. */ +/*===========================================================================*/ + +#define ADC_GRP1_BUF_DEPTH 1 +#define ADC_GRP2_BUF_DEPTH 64 + +adcsample_t samples1[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH]; +adcsample_t samples2[ADC_GRP2_NUM_CHANNELS * ADC_GRP2_BUF_DEPTH]; + +/* + * ADC streaming callback. + */ +size_t nx = 0, ny = 0; +void adccallback(ADCDriver *adcp) { + + (void)adcp; + + /* Updating counters.*/ + if (adcIsBufferComplete(adcp)) { + nx += 1; + } + else { + ny += 1; + } +} + +/* + * ADC errors callback, should never happen. + */ +void adcerrorcallback(ADCDriver *adcp, adcerror_t err) { + + (void)adcp; + (void)err; + + chSysHalt("it happened"); +} + /*===========================================================================*/ /* Application code. */ /*===========================================================================*/ @@ -32,11 +70,10 @@ static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); - palSetLineMode(LINE_ARD_D13, PAL_MODE_OUTPUT_PUSHPULL); while (true) { - palSetLine(LINE_ARD_D13); + palSetLine(LINE_LED1); chThdSleepMilliseconds(500); - palClearLine(LINE_ARD_D13); + palClearLine(LINE_LED1); chThdSleepMilliseconds(500); } } @@ -64,6 +101,16 @@ int main(void) { */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); + /* + * Activates the PORTAB_ADC1 driver and the temperature sensor. + */ + adcStart(&PORTAB_ADC1, &portab_adccfg1); + adcSTM32EnableVREF(&PORTAB_ADC1); + adcSTM32EnableTS(&PORTAB_ADC1); + + /* Performing a one-shot conversion on two channels.*/ + adcConvert(&PORTAB_ADC1, &portab_adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH); + /* * Normal main() thread activity, if the button is pressed then the * conversion is stopped. -- cgit v1.2.3