From 19a85ae45beb97d5b260e80320e233f95c0e302b Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Tue, 3 Nov 2015 23:53:42 +0000 Subject: f0 working (one fixme) need scan mode upstream? --- tests/adc-power/Makefile.stm32f072-disco | 19 +++++++++ tests/adc-power/adc-power.c | 6 +-- tests/adc-power/main-stm32f072-disco.c | 67 ++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 tests/adc-power/Makefile.stm32f072-disco create mode 100644 tests/adc-power/main-stm32f072-disco.c (limited to 'tests') diff --git a/tests/adc-power/Makefile.stm32f072-disco b/tests/adc-power/Makefile.stm32f072-disco new file mode 100644 index 0000000..99eade8 --- /dev/null +++ b/tests/adc-power/Makefile.stm32f072-disco @@ -0,0 +1,19 @@ +BOARD = stm32f072-disco +PROJECT = adc-power-$(BOARD) +BUILD_DIR = bin-$(BOARD) + +SHARED_DIR = ../../shared + +CFILES = main-$(BOARD).c +CFILES += adc-power.c +# No trace on cm0! +#CFILES += trace.c trace_stdio.c +CFILES += usart_stdio.c + +VPATH += $(SHARED_DIR) + +INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) + +OPENCM3_DIR=../../libopencm3 +include ../../rules.stm32f0.mk +include ../../rules.mk diff --git a/tests/adc-power/adc-power.c b/tests/adc-power/adc-power.c index 734e3af..c673666 100644 --- a/tests/adc-power/adc-power.c +++ b/tests/adc-power/adc-power.c @@ -22,7 +22,7 @@ // Still have some bad shit to deal with... #if defined(STM32F0) #define SEPARATE_ADC_SAMPLING 0 -#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_239DOT5 +#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_239DOT5 // 4usec or more for tempsensor #elif defined(STM32F3) #define SAMPLE_TIME_BASIC ADC_SMPR1_SMP_181DOT5CYC #define SAMPLE_TIME_TEMP ADC_SMPR1_SMP_601DOT5CYC // 2.2usecs or more @@ -67,7 +67,7 @@ void adc_power_init(void) adc_enable_scan_mode(ADC1); ADC_CR2 |= ADC_CR2_EOCS; // FIXME #else - adc_disable_scan_mode(ADC1); + // FIXME - f0! adc_disable_scan_mode(ADC1); #endif #endif @@ -150,4 +150,4 @@ void adc_power_task_down() adc_power_off(ADC1); unsigned int td = TIM_CNT(TIMER); printf("toff in: %u\n", td); -} \ No newline at end of file +} diff --git a/tests/adc-power/main-stm32f072-disco.c b/tests/adc-power/main-stm32f072-disco.c new file mode 100644 index 0000000..4a960e1 --- /dev/null +++ b/tests/adc-power/main-stm32f072-disco.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2015 Karl Palsson + */ + +#include +#include +#include +#include +#include + +#include +#include "adc-power.h" + +static +void setup_usart(void) +{ + uint32_t dev = USART1; + rcc_periph_clock_enable(RCC_USART1); + rcc_periph_clock_enable(RCC_GPIOA); + gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9); + gpio_set_af(GPIOA, GPIO_AF1, GPIO9); + + usart_set_baudrate(dev, 115200); + usart_set_databits(dev, 8); + usart_set_parity(dev, USART_PARITY_NONE); + usart_set_stopbits(dev, USART_CR2_STOP_1_0BIT); + usart_set_mode(dev, USART_MODE_TX); + usart_set_flow_control(dev, USART_FLOWCONTROL_NONE); + + /* Finally enable the USART. */ + usart_enable(dev); +} + +int main(void) +{ + int i; + rcc_clock_setup_in_hsi48_out_48mhz(); + setup_usart(); + + /* LED on for boot progress */ + rcc_periph_clock_enable(RCC_GPIOC); + gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO7); + gpio_set(GPIOC, GPIO7); + + printf("hi guys!\n"); + + rcc_periph_clock_enable(RCC_GPIOA); + gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1); + gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5); + adc_power_init(); + while (1) { + adc_power_task_up(); + gpio_toggle(GPIOC, GPIO7); + + for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ + __asm__("NOP"); + } + printf("tick...\n"); + adc_power_task_down(); + gpio_toggle(GPIOC, GPIO7); + for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ + __asm__("NOP"); + } + } + +} + -- cgit