From f4ebd4a603a3a0b903424bb35ef68e9844a7dbe9 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Fri, 4 Mar 2016 00:40:08 +0000 Subject: attempt actual adc on l4 (insufficient,needs clocks yet) --- tests/adc-power/Makefile.stm32l4-disco | 5 ++--- tests/adc-power/adc-power.c | 6 ++++++ tests/adc-power/main-stm32l4-disco.c | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/adc-power/Makefile.stm32l4-disco b/tests/adc-power/Makefile.stm32l4-disco index 99fc9e2..7957e9d 100644 --- a/tests/adc-power/Makefile.stm32l4-disco +++ b/tests/adc-power/Makefile.stm32l4-disco @@ -6,9 +6,8 @@ BUILD_DIR = bin-$(BOARD) SHARED_DIR = ../../shared CFILES = main-$(BOARD).c -# hah, not yet! -#CFILES += adc-power.c -#CFILES += trace.c trace_stdio.c +CFILES += adc-power.c +CFILES += trace.c trace_stdio.c VPATH += $(SHARED_DIR) diff --git a/tests/adc-power/adc-power.c b/tests/adc-power/adc-power.c index bb70aa7..a188649 100644 --- a/tests/adc-power/adc-power.c +++ b/tests/adc-power/adc-power.c @@ -62,6 +62,12 @@ void adc_power_init(void) rcc_periph_clock_enable(RCC_ADC12); rcc_adc_prescale(RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_1, RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_1); adc_enable_regulator(ADC1); +#elif defined (STM32L4) + /* same same but different */ + rcc_periph_clock_enable(RCC_ADC1); + ADC_CR(ADC1) &= ~ADC_CR_DEEPPWD; + adc_enable_regulator(ADC1); + #else rcc_periph_clock_enable(RCC_ADC1); #if 0 diff --git a/tests/adc-power/main-stm32l4-disco.c b/tests/adc-power/main-stm32l4-disco.c index 4b8ca43..a23266f 100644 --- a/tests/adc-power/main-stm32l4-disco.c +++ b/tests/adc-power/main-stm32l4-disco.c @@ -10,6 +10,9 @@ #include #include +#include "trace.h" +#include "adc-power.h" + #define LED_DISCO_RED_PORT GPIOB #define LED_DISCO_RED_PIN GPIO2 #define LED_DISCO_GREEN_PORT GPIOE @@ -20,20 +23,30 @@ int main(void) { int i; int j = 0; - rcc_periph_clock_enable(RCC_GPIOB); - rcc_periph_clock_enable(RCC_GPIOE); + rcc_periph_clock_enable(RCC_GPIOB); // led + rcc_periph_clock_enable(RCC_GPIOE); // led + rcc_periph_clock_enable(RCC_GPIOA); // adcs + rcc_periph_clock_enable(RCC_GPIOC); // adcs + printf("hi guys!\n"); /* green led for ticking */ gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN); gpio_mode_setup(LED_DISCO_RED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_RED_PIN); + /* ADC 1 channels 1 and 5 */ + gpio_mode_setup(GPIOC, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0); + gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5); + + adc_power_init(); while (1) { + adc_power_task_up(); gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); for (i = 0; i < 0x10000; i++) { /* Wait a bit. */ __asm__("NOP"); } + adc_power_task_down(); gpio_toggle(LED_DISCO_RED_PORT, LED_DISCO_RED_PIN); for (i = 0; i < 0x10000; i++) { /* Wait a bit. */ __asm__("NOP"); -- cgit