From 6df66b77ba5b27bce5630694742f2dac57b8d3eb Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 17 Jul 2018 15:43:26 +0200 Subject: Isolate usb-serial-rs485 tree --- tests/adc-power/Makefile | 15 -- tests/adc-power/Makefile.stm32f072-disco | 23 --- tests/adc-power/Makefile.stm32f103-generic | 38 ----- tests/adc-power/Makefile.stm32f3-disco | 22 --- tests/adc-power/Makefile.stm32f4-disco | 40 ------ tests/adc-power/Makefile.stm32l1-generic | 18 --- tests/adc-power/Makefile.stm32l4-disco | 23 --- tests/adc-power/README.md | 17 --- tests/adc-power/adc-power.c | 211 ---------------------------- tests/adc-power/adc-power.h | 25 ---- tests/adc-power/main-stm32f072-disco.c | 67 --------- tests/adc-power/main-stm32f103-generic.c | 52 ------- tests/adc-power/main-stm32f3-disco.c | 133 ------------------ tests/adc-power/main-stm32f4-disco.c | 52 ------- tests/adc-power/main-stm32l1-generic.c | 53 ------- tests/adc-power/main-stm32l4-disco.c | 74 ---------- tests/adc-power/openocd.stm32l1-generic.cfg | 15 -- 17 files changed, 878 deletions(-) delete mode 100644 tests/adc-power/Makefile delete mode 100644 tests/adc-power/Makefile.stm32f072-disco delete mode 100644 tests/adc-power/Makefile.stm32f103-generic delete mode 100644 tests/adc-power/Makefile.stm32f3-disco delete mode 100644 tests/adc-power/Makefile.stm32f4-disco delete mode 100644 tests/adc-power/Makefile.stm32l1-generic delete mode 100644 tests/adc-power/Makefile.stm32l4-disco delete mode 100644 tests/adc-power/README.md delete mode 100644 tests/adc-power/adc-power.c delete mode 100644 tests/adc-power/adc-power.h delete mode 100644 tests/adc-power/main-stm32f072-disco.c delete mode 100644 tests/adc-power/main-stm32f103-generic.c delete mode 100644 tests/adc-power/main-stm32f3-disco.c delete mode 100644 tests/adc-power/main-stm32f4-disco.c delete mode 100644 tests/adc-power/main-stm32l1-generic.c delete mode 100644 tests/adc-power/main-stm32l4-disco.c delete mode 100644 tests/adc-power/openocd.stm32l1-generic.cfg (limited to 'tests/adc-power') diff --git a/tests/adc-power/Makefile b/tests/adc-power/Makefile deleted file mode 100644 index 8aa770d..0000000 --- a/tests/adc-power/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# This is just a stub makefile used for travis builds -# to keep things all compiling. Normally you'd use -# one of the makefiles directly. - -# These hoops are to enable parallel make correctly. -GZ_ALL := $(wildcard Makefile.*) - -all: $(GZ_ALL:=.all) -clean: $(GZ_ALL:=.clean) - -%.all: - $(MAKE) -f $* all -%.clean: - $(MAKE) -f $* clean - diff --git a/tests/adc-power/Makefile.stm32f072-disco b/tests/adc-power/Makefile.stm32f072-disco deleted file mode 100644 index 63917f3..0000000 --- a/tests/adc-power/Makefile.stm32f072-disco +++ /dev/null @@ -1,23 +0,0 @@ -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 -DEVICE=stm32f072rb -#OOCD_INTERFACE = stlink-v2 -#OOCD_TARGET = stm32f0x -OOCD_FILE = ../../openocd/openocd.stm32f072-disco.cfg - -include ../../rules.mk diff --git a/tests/adc-power/Makefile.stm32f103-generic b/tests/adc-power/Makefile.stm32f103-generic deleted file mode 100644 index 845affa..0000000 --- a/tests/adc-power/Makefile.stm32f103-generic +++ /dev/null @@ -1,38 +0,0 @@ -## -## This file is part of the libopencm3 project. -## -## This library is free software: you can redistribute it and/or modify -## it under the terms of the GNU Lesser General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public License -## along with this library. If not, see . -## - -BOARD = stm32f103-generic -PROJECT = adc-power-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += adc-power.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3 - -DEVICE=stm32f103x8 -#OOCD_INTERFACE = jlink -#OOCD_TARGET = stm32f1x -OOCD_FILE = ../../openocd/openocd.stm32f103-generic.cfg -include ../../rules.mk diff --git a/tests/adc-power/Makefile.stm32f3-disco b/tests/adc-power/Makefile.stm32f3-disco deleted file mode 100644 index bdde640..0000000 --- a/tests/adc-power/Makefile.stm32f3-disco +++ /dev/null @@ -1,22 +0,0 @@ - -BOARD = stm32f3-disco -PROJECT = adc-power-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += adc-power.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3/ -DEVICE=stm32f303vct6 -#OOCD_INTERFACE = stlink-v2 -#OOCD_TARGET = stm32f3x -OOCD_FILE = ../../openocd/openocd.stm32f3-disco.cfg - -include ../../rules.mk diff --git a/tests/adc-power/Makefile.stm32f4-disco b/tests/adc-power/Makefile.stm32f4-disco deleted file mode 100644 index 412ff52..0000000 --- a/tests/adc-power/Makefile.stm32f4-disco +++ /dev/null @@ -1,40 +0,0 @@ -## -## This file is part of the libopencm3 project. -## -## This library is free software: you can redistribute it and/or modify -## it under the terms of the GNU Lesser General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public License -## along with this library. If not, see . -## - -BOARD = stm32f4-disco -PROJECT = adc-power-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += adc-power.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3/ - -### This section can go to an arch shared rules eventually... -DEVICE=stm32f405xg -#OOCD_INTERFACE = stlink-v2 -#OOCD_TARGET = stm32f4x -OOCD_FILE = ../../openocd/openocd.stm32f4-disco.cfg - -include ../../rules.mk diff --git a/tests/adc-power/Makefile.stm32l1-generic b/tests/adc-power/Makefile.stm32l1-generic deleted file mode 100644 index 0814ef1..0000000 --- a/tests/adc-power/Makefile.stm32l1-generic +++ /dev/null @@ -1,18 +0,0 @@ -BOARD = stm32l1-generic -PROJECT = adc-power-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += adc-power.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3 -DEVICE=stm32l151x8 -OOCD_FILE = openocd.stm32l1-generic.cfg -include ../../rules.mk diff --git a/tests/adc-power/Makefile.stm32l4-disco b/tests/adc-power/Makefile.stm32l4-disco deleted file mode 100644 index 245d01a..0000000 --- a/tests/adc-power/Makefile.stm32l4-disco +++ /dev/null @@ -1,23 +0,0 @@ - -BOARD = stm32l4-disco -PROJECT = adc-power-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += adc-power.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3/ - -### This section can go to an arch shared rules eventually... -DEVICE=stm32l476vgt6 -#OOCD_INTERFACE = stlink-v2-1 -#OOCD_TARGET = stm32l4x -OOCD_FILE = ../../openocd/openocd.stm32l4-disco.cfg -include ../../rules.mk diff --git a/tests/adc-power/README.md b/tests/adc-power/README.md deleted file mode 100644 index 3f36045..0000000 --- a/tests/adc-power/README.md +++ /dev/null @@ -1,17 +0,0 @@ - -For most boards, adc channels 1 and 5 are PA1 and PA5. - -Not the F3. oh no, that board is cray cray. PA0 and PF4 - -For boards with a Cortex-M3 or better, debug output is on ITM -channel 0 (Yay!) -For M0/M0+ boards, debug is via a tx only UART on PA9. - -https://github.com/libopencm3/libopencm3/pull/471 -https://github.com/libopencm3/libopencm3/pull/457 -https://github.com/libopencm3/libopencm3/pull/534 - -https://github.com/libopencm3/libopencm3/issues/456 -https://github.com/libopencm3/libopencm3/issues/455 -https://github.com/libopencm3/libopencm3/issues/454 - diff --git a/tests/adc-power/adc-power.c b/tests/adc-power/adc-power.c deleted file mode 100644 index bcd9c87..0000000 --- a/tests/adc-power/adc-power.c +++ /dev/null @@ -1,211 +0,0 @@ -/** - * Testing ADC power up and power down, for timing and actual on/off - * Uses TIM6, because DWT_CYCCNT not available on cm0(+) :( - * (And with no DWT, no ITM timestamping either, get a real mcu!) - */ - -#include -#include -#include -#include -#include - -#include "adc-power.h" - -/* Everyone has tim6 right? */ -#define TIMER TIM6 -#define TIMER_RCC RCC_TIM6 - -// TODO - stick this in libopencm3? -#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) - -// Still have some bad shit to deal with... -#if defined(STM32F0) -#define SEPARATE_ADC_SAMPLING 0 -#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_239DOT5 // 4usec or more for tempsensor -#define HAS_CALIBRATION 1 -#elif defined(STM32F1) -#define SEPARATE_ADC_SAMPLING 0 -#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_28DOT5CYC // 17usecs or more. >~15cycles at 9Mhz -#define SEPARATE_VREF 0 -#define HAS_CALIBRATION 1 -#define HAS_ROM_CALIBRATION 0 -#elif defined(STM32F3) -#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_181DOT5CYC -#define SAMPLE_TIME_TEMP ADC_SMPR_SMP_601DOT5CYC // 2.2usecs or more -#define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP -#define HAS_CALIBRATION 1 -#elif defined(STM32F4) -#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_28CYC -#define SAMPLE_TIME_TEMP ADC_SMPR_SMP_144CYC // 10 usecs or more, in theory needs 840cycles! -#define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP -#define ADC_CHANNEL_TEMP ADC_CHANNEL_TEMP_F40 -#define SEPARATE_VREF 0 -#elif defined(STM32L1) -#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_24CYC -#define SAMPLE_TIME_TEMP ADC_SMPR_SMP_192CYC -#define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP -#define SEPARATE_VREF 0 -#elif defined(STM32L4) -#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_247DOT5CYC -#define SAMPLE_TIME_TEMP ADC_SMPR_SMP_247DOT5CYC -#define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP -#define HAS_CALIBRATION 1 -#else -#error "no sample time for your target yet?!" -#endif - -#ifndef SEPARATE_VREF -#define SEPARATE_VREF 1 -#endif -#ifndef SEPARATE_ADC_SAMPLING -#define SEPARATE_ADC_SAMPLING 1 -#endif -#ifndef HAS_CALIBRATION -#define HAS_CALIBRATION 0 -#endif -#ifndef HAS_ROM_CALIBRATION -#define HAS_ROM_CALIBRATION 1 -#endif - - -void adc_power_init(void) -{ - /* Some basic ADC config, that we won't touch again */ -#if defined(STM32F3) - /* silly f303 */ - 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; - RCC_CCIPR |= 3 << 28; // system clock as adc clock. (with CKMODE == 0) - adc_enable_regulator(ADC1); - - ADC_CR(ADC1) &= ~ADC_CR_ADCALDIF; - ADC_CR(ADC1) |= ADC_CR_ADCAL; - while (ADC_CR(ADC1) & ADC_CR_ADCAL); - - -#else - rcc_periph_clock_enable(RCC_ADC1); -#if 0 - // DANGER DANGER! doing this without DMA is dum. - // but... we're busy polling, we should be right... right? - // (dma across platforms is teh suck) - adc_enable_scan_mode(ADC1); - ADC_CR2 |= ADC_CR2_EOCS; // FIXME -#else - // FIXME - f0! adc_disable_scan_mode(ADC1); -#endif - -#endif -#if (SEPARATE_ADC_SAMPLING == 1) - adc_set_sample_time_on_all_channels(ADC1, SAMPLE_TIME_BASIC); - adc_set_sample_time(ADC1, ADC_CHANNEL_TEMP, SAMPLE_TIME_TEMP); - adc_set_sample_time(ADC1, ADC_CHANNEL_TEMP, SAMPLE_TIME_VREF); -#else - adc_set_sample_time_on_all_channels(ADC1, SAMPLE_TIME_BASIC); -#endif - adc_enable_temperature_sensor(); -#if (SEPARATE_VREF == 1) - adc_enable_vrefint(); -#endif - - /* - * We're going to setup a timer to run at top speed, so... "fast" - * but we don't actually care about the rate itself. We just - * want to collect how many ticks it takes to enable and disable - * the adc. - */ - rcc_periph_clock_enable(TIMER_RCC); - timer_reset(TIMER); - timer_set_prescaler(TIMER, 0); - timer_enable_counter(TIMER); -} - -static uint16_t read_adc_naiive(uint8_t channel) -{ - uint8_t channel_array[16]; - channel_array[0] = channel; - adc_set_regular_sequence(ADC1, 1, channel_array); - // FIXME - use a trigger, see f1 notes! -#if defined (STM32F1) - adc_start_conversion_direct(ADC1); -#else - adc_start_conversion_regular(ADC1); -#endif - while (!adc_eoc(ADC1)); - return adc_read_regular(ADC1); -} - -static float adc_calc_tempf(unsigned int ts_v, unsigned int vref) { -#if (HAS_ROM_CALIBRATION == 1) - float adjusted_vtemp = ts_v * ST_VREFINT_CAL * 1.0f / vref * 1.0f; - float slope = (110-30) * 1.0f / (ST_TSENSE_CAL2_110C - ST_TSENSE_CAL1_30C) * 1.0f; - return slope * (adjusted_vtemp - ST_TSENSE_CAL1_30C) + 30; -#else - (void)vref; - return ts_v * 1.0; -#endif -} - -static int adc_calc_tempi(unsigned int ts, unsigned int vref) { -#if (HAS_ROM_CALIBRATION == 1) - int adjusted_vtemp = ts * ST_VREFINT_CAL / vref; - int slope = (110-30) / (ST_TSENSE_CAL2_110C - ST_TSENSE_CAL1_30C); - return slope * (adjusted_vtemp - ST_TSENSE_CAL1_30C) + 30; -#else - (void)vref; - return ts * 1.00; -#endif -} - -void adc_power_task_up(void) { - TIM_CNT(TIMER) = 0; - // Welcome to f1 world. -#if defined (STM32F1) - adc_power_on(ADC1); - for (int i = 0; i < 0x80000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } -#endif -#if (HAS_CALIBRATION == 1) - adc_calibrate(ADC1); -#endif - adc_power_on(ADC1); - unsigned int td = TIM_CNT(TIMER); - - /* just for kicks, let's time some sequences too.... - * I mean, we're going to do some conversions right? */ - adc_set_single_conversion_mode(ADC1); - TIM_CNT(TIMER) = 0; - unsigned int v1 = read_adc_naiive(1); // 8 for l4! - unsigned int v5 = read_adc_naiive(5); - unsigned int temp_adc = read_adc_naiive(ADC_CHANNEL_TEMP); - unsigned int vref_adc = read_adc_naiive(ADC_CHANNEL_VREF); - unsigned int tconv = TIM_CNT(TIMER); - TIM_CNT(TIMER) = 0; - float tempf = adc_calc_tempf(temp_adc, vref_adc); - int tconvf = TIM_CNT(TIMER); - TIM_CNT(TIMER) = 0; - int tempi = adc_calc_tempi(temp_adc, vref_adc); - int tconvi = TIM_CNT(TIMER); - - printf("ton: %u, tconv: %u, ch1: %u, ch5: %u\n", td, tconv, v1, v5); - printf("\tTemperature: %f (tc %d) or %d (tc %d) (raw ts: %d, raw vref: %d)\n", - tempf, tconvf, tempi, tconvi, temp_adc, vref_adc); - //printf("\tT1-30 %d, t2-110 %d, vrefcal: %d\n", ST_TSENSE_CAL1_30C, ST_TSENSE_CAL2_110C, ST_VREFINT_CAL); -} - -void adc_power_task_down() -{ - TIM_CNT(TIMER) = 0; - adc_power_off(ADC1); - /* double power off should be safe */ - adc_power_off(ADC1); - unsigned int td = TIM_CNT(TIMER); - printf("toff in: %u\n", td); -} diff --git a/tests/adc-power/adc-power.h b/tests/adc-power/adc-power.h deleted file mode 100644 index 2775d1a..0000000 --- a/tests/adc-power/adc-power.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * File: adc-power.h - * Author: karlp - * - * Created on October 17, 2015, 12:19 AM - */ - -#ifndef ADC_POWER_H -#define ADC_POWER_H - -#ifdef __cplusplus -extern "C" { -#endif - - void adc_power_init(void); - void adc_power_task_up(void); - void adc_power_task_down(void); - - -#ifdef __cplusplus -} -#endif - -#endif /* ADC_POWER_H */ - diff --git a/tests/adc-power/main-stm32f072-disco.c b/tests/adc-power/main-stm32f072-disco.c deleted file mode 100644 index 744c384..0000000 --- a/tests/adc-power/main-stm32f072-disco.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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_STOPBITS_1); - 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"); - } - } - -} - diff --git a/tests/adc-power/main-stm32f103-generic.c b/tests/adc-power/main-stm32f103-generic.c deleted file mode 100644 index 815ab16..0000000 --- a/tests/adc-power/main-stm32f103-generic.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Oct 2015 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "trace.h" -#include "adc-power.h" - -#define LED_PORT GPIOC -#define LED_PIN GPIO13 - -int main(void) -{ - int i; - int j = 0; - rcc_clock_setup_in_hse_8mhz_out_72mhz(); - rcc_periph_clock_enable(RCC_GPIOC); - printf("hi guys!\n"); - /* green led for ticking */ - gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN); - - rcc_periph_clock_enable(RCC_GPIOA); - gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO0); - gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO5); - - - adc_power_init(); - while (1) { - adc_power_task_up(); - gpio_toggle(LED_PORT, LED_PIN); - - for (i = 0; i < 0x80000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - adc_power_task_down(); - gpio_toggle(LED_PORT, LED_PIN); - for (i = 0; i < 0x80000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/adc-power/main-stm32f3-disco.c b/tests/adc-power/main-stm32f3-disco.c deleted file mode 100644 index fd155fa..0000000 --- a/tests/adc-power/main-stm32f3-disco.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Oct 2015 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "trace.h" -#include "adc-power.h" - -/* f3 pll setup, based on l1/f4*/ - -typedef struct { - uint8_t pll_mul; - uint8_t pll_div; - uint8_t pll_source; - uint32_t flash_config; - uint8_t hpre; - uint8_t ppre1; - uint8_t ppre2; - uint32_t apb1_frequency; - uint32_t apb2_frequency; - uint32_t ahb_frequency; -} rcc_clock_scale_t; - -static void rcc_clock_setup_pll_f3_special(const rcc_clock_scale_t *clock) -{ - /* Turn on the appropriate source for the PLL */ - // TODO, some f3's have extra bits here - enum rcc_osc my_osc; - if (clock->pll_source == RCC_CFGR_PLLSRC_HSE_PREDIV) { - my_osc = RCC_HSE; - } else { - my_osc = RCC_HSI; - } - rcc_osc_on(my_osc); - while (!rcc_is_osc_ready(my_osc)); - - /* Configure flash settings. */ - flash_set_ws(clock->flash_config); - - /* - * Set prescalers for AHB, ADC, ABP1, ABP2. - * Do this before touching the PLL (TODO: why?). - */ - rcc_set_hpre(clock->hpre); - rcc_set_ppre1(clock->ppre1); - rcc_set_ppre2(clock->ppre2); - - rcc_osc_off(RCC_PLL); - while (rcc_is_osc_ready(RCC_PLL)); - rcc_set_pll_source(clock->pll_source); - rcc_set_pll_multiplier(clock->pll_mul); - // TODO - iff pll_div != 0, then maybe we're on a target that - // has the dividers? - - /* Enable PLL oscillator and wait for it to stabilize. */ - rcc_osc_on(RCC_PLL); - while (!rcc_is_osc_ready(RCC_PLL)); - - /* Select PLL as SYSCLK source. */ - rcc_set_sysclk_source(RCC_CFGR_SW_PLL); - rcc_wait_for_sysclk_status(RCC_PLL); - - /* Set the peripheral clock frequencies used. */ - rcc_ahb_frequency = clock->ahb_frequency; - rcc_apb1_frequency = clock->apb1_frequency; - rcc_apb2_frequency = clock->apb2_frequency; -} - -static void setup_clocks(void) -{ - rcc_clock_scale_t clock_full_hse8mhz ={ - .pll_mul = RCC_CFGR_PLLMUL_PLL_IN_CLK_X9, - .pll_source = RCC_CFGR_PLLSRC_HSE_PREDIV, - .hpre = RCC_CFGR_HPRE_DIV_NONE, - .ppre1 = RCC_CFGR_PPRE1_DIV_2, - .ppre2 = RCC_CFGR_PPRE2_DIV_NONE, - .flash_config = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_2WS, - .apb1_frequency = 36000000, - .apb2_frequency = 72000000, - .ahb_frequency = 72000000, - }; - - rcc_clock_setup_pll_f3_special(&clock_full_hse8mhz); -} - -int main(void) -{ - int i; - int j = 0; - setup_clocks(); - /* Board led */ - rcc_periph_clock_enable(RCC_GPIOE); - gpio_mode_setup(GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO8); - gpio_set(GPIOE, GPIO8); - printf("hi guys!\n"); - - // ADC seems to take these no matter what? -// rcc_periph_clock_enable(RCC_GPIOA); -// rcc_periph_clock_enable(RCC_GPIOF); -// gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0); -// gpio_mode_setup(GPIOF, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO4); - - adc_power_init(); - for (i = 0; i < 0x1000; i++) { /* need as much as 10 usecs for vreg */ - __asm__("NOP"); - } - while (1) { - adc_power_task_up(); - gpio_toggle(GPIOE, GPIO8); - - for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - printf("tick...\n"); - adc_power_task_down(); - gpio_toggle(GPIOE, GPIO8); - for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/adc-power/main-stm32f4-disco.c b/tests/adc-power/main-stm32f4-disco.c deleted file mode 100644 index 6c0c822..0000000 --- a/tests/adc-power/main-stm32f4-disco.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Oct 2015 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "trace.h" -#include "adc-power.h" - -#define LED_DISCO_GREEN_PORT GPIOD -#define LED_DISCO_GREEN_PIN GPIO12 - -int main(void) -{ - int i; - int j = 0; - rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); - rcc_periph_clock_enable(RCC_GPIOD); - 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); - - rcc_periph_clock_enable(RCC_GPIOA); - gpio_mode_setup(GPIOA, 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 < 0x800000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - adc_power_task_down(); - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - for (i = 0; i < 0x800000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/adc-power/main-stm32l1-generic.c b/tests/adc-power/main-stm32l1-generic.c deleted file mode 100644 index 00f3a05..0000000 --- a/tests/adc-power/main-stm32l1-generic.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Oct 2015 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "trace.h" -#include "adc-power.h" - -#define LED_DISCO_GREEN_PORT GPIOB -#define LED_DISCO_GREEN_PIN GPIO9 - - -int main(void) -{ - int i; - int j = 0; - rcc_clock_setup_pll(&rcc_clock_config[RCC_CLOCK_VRANGE1_HSI_PLL_32MHZ]); - rcc_periph_clock_enable(RCC_GPIOB); - 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); - - 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(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - - for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - adc_power_task_down(); - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/adc-power/main-stm32l4-disco.c b/tests/adc-power/main-stm32l4-disco.c deleted file mode 100644 index 37a3241..0000000 --- a/tests/adc-power/main-stm32l4-disco.c +++ /dev/null @@ -1,74 +0,0 @@ - -/* - * Nov 2015 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#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 -#define LED_DISCO_GREEN_PIN GPIO8 - -static int hack(void) { - pwr_set_vos_scale(PWR_SCALE1); - flash_set_ws(FLASH_ACR_LATENCY_2WS); - rcc_set_msi_range(RCC_CR_MSIRANGE_48MHZ); - return 0; -} - -int main(void) -{ - int i; - int j = 0; - 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 - rcc_periph_clock_enable(RCC_PWR); - hack(); - 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 */ - // This is the reset state, so not really necessary. - gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0); - gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1); - gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO2); - gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO3); - gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5); - - // This is NOT the reset state! very important! - GPIO_ASCR(GPIOA) |= GPIO0 | GPIO1 | GPIO2 | GPIO3 | 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"); - } - } - - return 0; -} diff --git a/tests/adc-power/openocd.stm32l1-generic.cfg b/tests/adc-power/openocd.stm32l1-generic.cfg deleted file mode 100644 index 6b39750..0000000 --- a/tests/adc-power/openocd.stm32l1-generic.cfg +++ /dev/null @@ -1,15 +0,0 @@ -# l1 generic, using a l4 disco board -#source [find interface/stlink-v2-1.cfg] -# l1 disco itself or similar -source [find interface/stlink-v2.cfg] -set WORKAREASIZE 0x2000 -source [find target/stm32l1.cfg] - -#hla_serial "066DFF495351885087171826" # My l4 disco -hla_serial "S?l\x06H?WQ%\x10\x18?" # My l1 disco - -tpiu config internal swodump.stm32l1-generic.log uart off 32000000 - -# Uncomment to reset on connect, for grabbing under WFI et al -reset_config srst_only srst_nogate -# reset_config srst_only srst_nogate connect_assert_srst -- cgit