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 - tests/awd-timer-dma/Makefile.stm32l1-generic | 18 -- tests/awd-timer-dma/README.md | 2 - tests/awd-timer-dma/awd-timer-dma.c | 219 ------------- tests/awd-timer-dma/awd-timer-dma.h | 12 - tests/awd-timer-dma/main-stm32l1-generic.c | 42 --- tests/i2c-master/Makefile | 15 - tests/i2c-master/Makefile.stm32f072-disco | 23 -- tests/i2c-master/Makefile.stm32f4-disco | 40 --- tests/i2c-master/Makefile.stm32l1-generic | 18 -- tests/i2c-master/README.md | 31 -- tests/i2c-master/hw.h | 42 --- tests/i2c-master/i2c-master.c | 121 -------- tests/i2c-master/i2c-master.h | 19 -- tests/i2c-master/main-stm32f072-disco.c | 104 ------- tests/i2c-master/main-stm32f4-disco.c | 79 ----- tests/i2c-master/main-stm32l1-generic.c | 80 ----- tests/qemu/Makefile | 40 --- tests/qemu/README.md | 20 -- tests/qemu/main.c | 58 ---- tests/rcc-legal-ranges/Makefile.stm32l1-generic | 28 -- tests/rcc-legal-ranges/README.md | 14 - tests/rcc-legal-ranges/main-stm32l1-generic.c | 154 --------- tests/spi-master/Makefile | 15 - tests/spi-master/Makefile.dut-stm32l073rz | 21 -- tests/spi-master/Makefile.host-stm32l1-generic | 18 -- tests/spi-master/README.md | 25 -- tests/spi-master/hw.h | 41 --- tests/spi-master/main-dut-stm32l073rz.c | 140 --------- tests/spi-master/main-host-stm32l1-generic.c | 114 ------- tests/uart-basic/Makefile.dut-stm32l073rz | 26 -- tests/uart-basic/Makefile.stm32f072disco | 26 -- tests/uart-basic/Makefile.stm32f3-disco | 29 -- tests/uart-basic/Makefile.stm32f4-disco | 29 -- tests/uart-basic/Makefile.stm32l053disco | 26 -- tests/uart-basic/Makefile.stm32l476disco | 26 -- tests/uart-basic/main-dut-stm32l073rz.c | 78 ----- tests/uart-basic/main-stm32f072disco.c | 64 ---- tests/uart-basic/main-stm32f3-disco.c | 136 -------- tests/uart-basic/main-stm32f4-disco.c | 63 ---- tests/uart-basic/main-stm32l053disco.c | 78 ----- tests/uart-basic/main-stm32l476disco.c | 77 ----- tests/uart-basic/uart-basic.c | 71 ----- tests/uart-basic/uart-basic.h | 44 --- tests/usb-serial-rs485/Makefile.stm32f103-generic | 38 --- tests/usb-serial-rs485/Makefile.stm32f4-disco | 38 --- tests/usb-serial-rs485/README | 33 -- tests/usb-serial-rs485/main-stm32f103-generic.c | 204 ------------ tests/usb-serial-rs485/main-stm32f4-disco.c | 199 ------------ tests/usb-serial-rs485/ringb.c | 59 ---- tests/usb-serial-rs485/ringb.h | 60 ---- tests/usb-serial-rs485/syscfg.h | 59 ---- tests/usb-serial-rs485/usb_cdcacm-arch.c | 82 ----- tests/usb-serial-rs485/usb_cdcacm.c | 363 ---------------------- tests/usb-serial-rs485/usb_cdcacm.h | 74 ----- 71 files changed, 4413 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 delete mode 100644 tests/awd-timer-dma/Makefile.stm32l1-generic delete mode 100644 tests/awd-timer-dma/README.md delete mode 100644 tests/awd-timer-dma/awd-timer-dma.c delete mode 100644 tests/awd-timer-dma/awd-timer-dma.h delete mode 100644 tests/awd-timer-dma/main-stm32l1-generic.c delete mode 100644 tests/i2c-master/Makefile delete mode 100644 tests/i2c-master/Makefile.stm32f072-disco delete mode 100644 tests/i2c-master/Makefile.stm32f4-disco delete mode 100644 tests/i2c-master/Makefile.stm32l1-generic delete mode 100644 tests/i2c-master/README.md delete mode 100644 tests/i2c-master/hw.h delete mode 100644 tests/i2c-master/i2c-master.c delete mode 100644 tests/i2c-master/i2c-master.h delete mode 100644 tests/i2c-master/main-stm32f072-disco.c delete mode 100644 tests/i2c-master/main-stm32f4-disco.c delete mode 100644 tests/i2c-master/main-stm32l1-generic.c delete mode 100644 tests/qemu/Makefile delete mode 100644 tests/qemu/README.md delete mode 100644 tests/qemu/main.c delete mode 100644 tests/rcc-legal-ranges/Makefile.stm32l1-generic delete mode 100644 tests/rcc-legal-ranges/README.md delete mode 100644 tests/rcc-legal-ranges/main-stm32l1-generic.c delete mode 100644 tests/spi-master/Makefile delete mode 100644 tests/spi-master/Makefile.dut-stm32l073rz delete mode 100644 tests/spi-master/Makefile.host-stm32l1-generic delete mode 100644 tests/spi-master/README.md delete mode 100644 tests/spi-master/hw.h delete mode 100644 tests/spi-master/main-dut-stm32l073rz.c delete mode 100644 tests/spi-master/main-host-stm32l1-generic.c delete mode 100644 tests/uart-basic/Makefile.dut-stm32l073rz delete mode 100644 tests/uart-basic/Makefile.stm32f072disco delete mode 100644 tests/uart-basic/Makefile.stm32f3-disco delete mode 100644 tests/uart-basic/Makefile.stm32f4-disco delete mode 100644 tests/uart-basic/Makefile.stm32l053disco delete mode 100644 tests/uart-basic/Makefile.stm32l476disco delete mode 100644 tests/uart-basic/main-dut-stm32l073rz.c delete mode 100644 tests/uart-basic/main-stm32f072disco.c delete mode 100644 tests/uart-basic/main-stm32f3-disco.c delete mode 100644 tests/uart-basic/main-stm32f4-disco.c delete mode 100644 tests/uart-basic/main-stm32l053disco.c delete mode 100644 tests/uart-basic/main-stm32l476disco.c delete mode 100644 tests/uart-basic/uart-basic.c delete mode 100644 tests/uart-basic/uart-basic.h delete mode 100644 tests/usb-serial-rs485/Makefile.stm32f103-generic delete mode 100644 tests/usb-serial-rs485/Makefile.stm32f4-disco delete mode 100644 tests/usb-serial-rs485/README delete mode 100644 tests/usb-serial-rs485/main-stm32f103-generic.c delete mode 100644 tests/usb-serial-rs485/main-stm32f4-disco.c delete mode 100644 tests/usb-serial-rs485/ringb.c delete mode 100644 tests/usb-serial-rs485/ringb.h delete mode 100644 tests/usb-serial-rs485/syscfg.h delete mode 100644 tests/usb-serial-rs485/usb_cdcacm-arch.c delete mode 100644 tests/usb-serial-rs485/usb_cdcacm.c delete mode 100644 tests/usb-serial-rs485/usb_cdcacm.h (limited to 'tests') 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 diff --git a/tests/awd-timer-dma/Makefile.stm32l1-generic b/tests/awd-timer-dma/Makefile.stm32l1-generic deleted file mode 100644 index 1ccdd67..0000000 --- a/tests/awd-timer-dma/Makefile.stm32l1-generic +++ /dev/null @@ -1,18 +0,0 @@ -BOARD = stm32l1-generic -PROJECT = awd-timer-dma-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += awd-timer-dma.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3 -DEVICE=stm32l151xb -OOCD_FILE = openocd.stm32l1-generic.cfg -include ../../rules.mk diff --git a/tests/awd-timer-dma/README.md b/tests/awd-timer-dma/README.md deleted file mode 100644 index 58f851c..0000000 --- a/tests/awd-timer-dma/README.md +++ /dev/null @@ -1,2 +0,0 @@ - -Exploring analog watchdog and timer triggered adc via dma diff --git a/tests/awd-timer-dma/awd-timer-dma.c b/tests/awd-timer-dma/awd-timer-dma.c deleted file mode 100644 index ffb16db..0000000 --- a/tests/awd-timer-dma/awd-timer-dma.c +++ /dev/null @@ -1,219 +0,0 @@ -/** - * Testing AWD interrupt, with timer triggered dma - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "awd-timer-dma.h" - -/* Everyone has tim6 right? */ -#define TIMER TIM6 -#define TIMER_RCC RCC_TIM6 - -/* what external channel should be included? (Connect a pot here) */ -#define EXT_CHAN_RCC RCC_GPIOA -#define EXT_CHAN_PORT GPIOA -#define EXT_CHAN_PIN GPIO5 -#define EXT_CHAN_CHAN 5 - -// 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_48CYC -#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 - -/* dma destination */ -static uint16_t adc_buffer[3]; -static int awd_hits; - -/** - * set up a timer from a 100khz timer base. - * @param sample_rate minimum is ~2hz, max is just under 100khz - */ -static void timer_trigger_setup(int sample_rate) -{ - uint32_t timer = TIMER; - - timer_disable_counter(timer); - TIM_CNT(timer) = 0; - /* 100kHz base */ - timer_set_prescaler(timer, (rcc_apb1_frequency / (100*1000)) -1); - timer_set_period(timer, ((100*1000)/sample_rate) - 1); - timer_set_master_mode(timer, TIM_CR2_MMS_UPDATE); -} - -void adc1_isr(void) { - if (ADC_SR(ADC1) & ADC_SR_AWD) { - ADC_SR(ADC1) &= ~ADC_SR_AWD; - awd_hits++; - } -} - - -void task_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); - rcc_periph_clock_enable(RCC_DMA1); - rcc_periph_clock_enable(RCC_TIM6); - rcc_periph_clock_enable(EXT_CHAN_RCC); - gpio_mode_setup(EXT_CHAN_PORT, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, EXT_CHAN_PIN); - adc_power_off(ADC1); - - -#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_VREF, 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 - - adc_enable_scan_mode(ADC1); - uint8_t channel_array[] = {EXT_CHAN_CHAN, ADC_CHANNEL_TEMP, ADC_CHANNEL_VREF}; - adc_set_regular_sequence(ADC1, ARRAY_SIZE(channel_array), channel_array); - - adc_enable_external_trigger_regular(ADC1, ADC_CR2_EXTSEL_TIM6_TRGO, ADC_CR2_EXTEN_RISING_EDGE); - /* power down when not in use please. */ - ADC_CR1(ADC1) |= ADC_CR1_PDD | ADC_CR1_PDI; - adc_power_on(ADC1); - -#if 1 - /* adc-v2 has this as "adc_is_power_on*/ - while ((ADC_SR(ADC1) & ADC_SR_ADONS) == 0) { - ; - } -#endif - - /* hard code a threshold for now , around a third */ - adc_set_watchdog_low_threshold(ADC1, 1400); - adc_enable_analog_watchdog_on_selected_channel(ADC1, EXT_CHAN_CHAN); - adc_enable_analog_watchdog_regular(ADC1); - adc_enable_awd_interrupt(ADC1); - nvic_enable_irq(NVIC_ADC1_IRQ); - - dma_channel_reset(DMA1, DMA_CHANNEL1); // channel1 is adc - dma_set_memory_address(DMA1, DMA_CHANNEL1, (uint32_t)adc_buffer); - dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR_MSIZE_16BIT); - dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL1); - dma_set_peripheral_address(DMA1, DMA_CHANNEL1, (uint32_t) & ADC_DR(ADC1)); - dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR_PSIZE_16BIT); - dma_set_number_of_data(DMA1, DMA_CHANNEL1, ARRAY_SIZE(adc_buffer)); - -// dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL1); - dma_enable_transfer_error_interrupt(DMA1, DMA_CHANNEL1); - dma_set_read_from_peripheral(DMA1, DMA_CHANNEL1); - - // This is essential to stop overflows. - dma_enable_circular_mode(DMA1, DMA_CHANNEL1); - - dma_enable_channel(DMA1, DMA_CHANNEL1); - nvic_enable_irq(NVIC_DMA1_CHANNEL1_IRQ); - - //Keep on requesting DMA, as long as ADC is running - ADC_CR2(ADC1) |= ADC_CR2_DDS; - adc_enable_dma(ADC1); - - timer_trigger_setup(100); // slowly for now... - /* Reset timer count and start */ - TIM_CNT(TIM6) = 0; - timer_enable_counter(TIM6); - -} - -static float adc_calc_tempf(unsigned int adc_raw_temp) { -#if (HAS_ROM_CALIBRATION == 1) - float slope = ((110-30) * 1.0f)/((ST_TSENSE_CAL2_110C - ST_TSENSE_CAL1_30C) * 1.0f); - return slope * (adc_raw_temp - ST_TSENSE_CAL1_30C) + 30; -#else - return ts_v * 1.0; -#endif -} - -void task_run(void) -{ - static int last_awd_hits; - float temperature = adc_calc_tempf(adc_buffer[1]); - printf("Last adc reading: %d, last temp: %f (raw=%d), last cal: %d\n", - adc_buffer[0], temperature, adc_buffer[1], adc_buffer[2]); - if (awd_hits > last_awd_hits) { - printf("Got %d AWD hits since last run\n", awd_hits); - last_awd_hits = awd_hits; - } -} diff --git a/tests/awd-timer-dma/awd-timer-dma.h b/tests/awd-timer-dma/awd-timer-dma.h deleted file mode 100644 index 71bd158..0000000 --- a/tests/awd-timer-dma/awd-timer-dma.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - - void task_init(void); - void task_run(void); - -#ifdef __cplusplus -} -#endif diff --git a/tests/awd-timer-dma/main-stm32l1-generic.c b/tests/awd-timer-dma/main-stm32l1-generic.c deleted file mode 100644 index 17d6b2c..0000000 --- a/tests/awd-timer-dma/main-stm32l1-generic.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Oct 2015 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "trace.h" -#include "awd-timer-dma.h" - -#define LED_DISCO_GREEN_PORT GPIOB -#define LED_DISCO_GREEN_PIN GPIO7 - - -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); - - task_init(); - while (1) { - task_run(); - for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/i2c-master/Makefile b/tests/i2c-master/Makefile deleted file mode 100644 index 52841cd..0000000 --- a/tests/i2c-master/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/i2c-master/Makefile.stm32f072-disco b/tests/i2c-master/Makefile.stm32f072-disco deleted file mode 100644 index 02e987c..0000000 --- a/tests/i2c-master/Makefile.stm32f072-disco +++ /dev/null @@ -1,23 +0,0 @@ -BOARD = stm32f072-disco -PROJECT = i2c-master-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += i2c-master.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/i2c-master/Makefile.stm32f4-disco b/tests/i2c-master/Makefile.stm32f4-disco deleted file mode 100644 index 2456820..0000000 --- a/tests/i2c-master/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 = i2c-master-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += i2c-master.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/i2c-master/Makefile.stm32l1-generic b/tests/i2c-master/Makefile.stm32l1-generic deleted file mode 100644 index ea75919..0000000 --- a/tests/i2c-master/Makefile.stm32l1-generic +++ /dev/null @@ -1,18 +0,0 @@ -BOARD = stm32l1-generic -PROJECT = i2c-master-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += i2c-master.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3 -DEVICE=stm32l151xb -OOCD_FILE = openocd.stm32l1-generic.cfg -include ../../rules.mk diff --git a/tests/i2c-master/README.md b/tests/i2c-master/README.md deleted file mode 100644 index 9ebb3c5..0000000 --- a/tests/i2c-master/README.md +++ /dev/null @@ -1,31 +0,0 @@ -i2c master mode tests. - -While many of the disco boards have some form of i2c device onboard, -which would, on the face of it, make testing easy, it's a different -device on each board, and there are boards without it. - -Instead, use a known I2C peripheral on all boards, and require/expect -a known fixed i2c slave device. (Eventually, this will be a soft -controllable i2c slave in the auto test setup ;) - -the "trigger" pin is bounced when each iteration of the test code starts, -allowing synchronization with a sigrok script that helps assure that -results are as expected. - -Debug is via SWO wherever possible, uart (tx only) on less capable cores - -Pinouts: (External PullUps REQUIRED!) - -board SCLK SDA i2cperiph trigger uart -f4-disco PB8 PB9 i2c1 PB13 -l1-disco PB8 PB9 i2c1 PB13 -f072-disco PB8 PB9 i2c1 PB12 PA9! - - -Notes for monitoring with sigrok: -$ sigrok-cli -d fx2lafw -C D0=SDA,D1=SCL,D2=Trig -c samplerate=4Mhz:captureratio=4 --time=150ms -t Trig=r -o cap2.cli.sr -# Then open the .sr file in pulseview. something's wrong with decoding -# directly from the cli! - -# or.... -$ sigrok-cli -d fx2lafw -C D0=SDA,D1=SCL,D2=Trig -c samplerate=4Mhz:captureratio=4 --time=150ms -t Trig=r -P i2c:scl=SCL:sda=SDA diff --git a/tests/i2c-master/hw.h b/tests/i2c-master/hw.h deleted file mode 100644 index 8b235be..0000000 --- a/tests/i2c-master/hw.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Feb 2017 Karl Palsson - */ - -#include -#include - -#pragma once - -struct hw_detail -{ - uint32_t periph; /* eg: I2C1 */ - uint32_t periph_rcc; /* eg: RCC_I2C1 */ - uint32_t periph_rst; /* eg: RST_I2C1 */ - uint32_t pins; /* eg: GPIO8 | GPIO9 */ /* ASSUMES SAME PORT*/ - uint32_t port; /* eg GPIOB */ - uint32_t port_rcc; /* eg RCC_GPIOB */ - uint32_t trigger_rcc; - uint32_t trigger_port; - uint32_t trigger_pin; - int i2c_clock_megahz; /* eg 42 for APB1 on an F4@168Mhz */ -}; - -extern struct hw_detail hw_details; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Expected to setup clocks, turn on all peripherals, and configure - * any gpios necessary. - * @param hw pointer to hw details necessary - */ - void hw_setup(struct hw_detail* hw); - - /* let devices have a status led */ - void hw_set_led(bool val); - -#ifdef __cplusplus -} -#endif diff --git a/tests/i2c-master/i2c-master.c b/tests/i2c-master/i2c-master.c deleted file mode 100644 index 3adbbf0..0000000 --- a/tests/i2c-master/i2c-master.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Feb 2017, Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include "trace.h" -#include "hw.h" -#include "i2c-master.h" - -#define SENSOR_ADDRESS (0x40) - -enum sht21_cmd_e { - SHT21_CMD_TEMP_HOLD = 0xe3, - SHT21_CMD_HUMIDITY_HOLD = 0xe5, - SHT21_CMD_TEMP_NOHOLD = 0xf3, - SHT21_CMD_HUMIDITY_NOHOLD = 0xf5, - SHT21_CMD_WRITE_REG = 0xe6, - SHT21_CMD_READ_REG = 0xe7, - SHT21_CMD_RESET = 0xfe, - /* 0xfa, 0x0f to read serial */ -}; - - -void i2cm_init(void) -{ - rcc_periph_clock_enable(hw_details.periph_rcc); - rcc_periph_reset_pulse(hw_details.periph_rst); - - i2c_set_speed(hw_details.periph, i2c_speed_sm_100k, hw_details.i2c_clock_megahz); - //i2c_set_speed(hw_details.periph, i2c_speed_fm_400k, hw_details.i2c_clock_megahz); - - i2c_peripheral_enable(hw_details.periph); -} - - -static float sht21_convert_temp(uint16_t raw) -{ - //assert((raw & 0x2) == 0x2); - raw &= ~0x3; /* Clear lower status bits */ - float tf = -46.85 + 175.72 * ((float) raw / 65536.0); - return tf; -} - -static float sht21_convert_humi(uint16_t raw) -{ - //assert((raw & 0x2) == 0); - raw &= ~0x3; /* Clear lower status bits */ - float tf = -6 + 125 * ((float) raw / 65536.0); - return tf; -} - -static float sht21_read_temp_hold(uint32_t i2c) -{ - uint8_t data[3]; - uint8_t cmd = SHT21_CMD_TEMP_HOLD; - i2c_transfer7(i2c, SENSOR_ADDRESS, &cmd, 1, data, sizeof(data)); - uint8_t crc = data[2]; - uint16_t temp = data[0] << 8 | data[1]; - // TODO - calcualte CRC and check! - printf("CRC=%#x, data0=%#x, data1=%#x\n", crc, data[0], data[1]); - return sht21_convert_temp(temp); -} - -static float sht21_read_humi_hold(uint32_t i2c) -{ - uint8_t data[3]; - uint8_t cmd = SHT21_CMD_HUMIDITY_HOLD; - i2c_transfer7(i2c, SENSOR_ADDRESS, &cmd, 1, data, sizeof(data)); - - uint8_t crc = data[2]; - uint16_t left = data[0] << 8 | data[1]; - // TODO - calcualte CRC and check! - printf("CRC=%#x, data0=%#x, data1=%#x\n", crc, data[0], data[1]); - return sht21_convert_humi(left); -} - -static void sht21_readid(void) -{ - uint8_t raw = 0; - uint8_t cmd = SHT21_CMD_READ_REG; - printf("RP..."); - i2c_transfer7(hw_details.periph, SENSOR_ADDRESS, &cmd, 1, &raw, 1); - printf("..S/S\n"); - // or, with stop/start - i2c_transfer7(hw_details.periph, SENSOR_ADDRESS, &cmd, 1, 0, 0); - i2c_transfer7(hw_details.periph, SENSOR_ADDRESS, 0, 0, &raw, 1); - - printf("raw user reg = %#x\n", raw); - int resolution = ((raw & 0x80) >> 6) | (raw & 1); - printf("temp resolution is in %d bits\n", 14 - resolution); - printf("battery status: %s\n", (raw & (1 << 6) ? "failing" : "good")); - printf("On chip heater: %s\n", (raw & 0x2) ? "on" : "off"); - - uint8_t req1[] = {0xfa, 0x0f}; - uint8_t res[8]; - i2c_transfer7(hw_details.periph, SENSOR_ADDRESS, req1, sizeof(req1), res, 8); - uint8_t req2[] = {0xfc, 0xc9}; - uint8_t res2[8]; - i2c_transfer7(hw_details.periph, SENSOR_ADDRESS, req1, sizeof(req1), res2, 8); - - printf("Serial = %02x%02x %02x%02x %02x%02x %02x%02x\n", - res2[3], res2[4], res[0], res[2], res[4], res[6], res2[0], res2[1]); -} - -void i2cm_task(void) -{ - static int i = 1; - printf(">>>>Starting iteration %d\n", i++); - gpio_set(hw_details.trigger_port, hw_details.trigger_pin); - sht21_readid(); - float temp = sht21_read_temp_hold(hw_details.periph); - float humi = sht21_read_humi_hold(hw_details.periph); - gpio_clear(hw_details.trigger_port, hw_details.trigger_pin); - printf("Temp: %f C, RH: %f\n", temp, humi); - -} \ No newline at end of file diff --git a/tests/i2c-master/i2c-master.h b/tests/i2c-master/i2c-master.h deleted file mode 100644 index 7a44b66..0000000 --- a/tests/i2c-master/i2c-master.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * common i2c master code headers. - * Karl Palsson - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - - - void i2cm_init(void); - void i2cm_task(void); - -#ifdef __cplusplus -} -#endif - diff --git a/tests/i2c-master/main-stm32f072-disco.c b/tests/i2c-master/main-stm32f072-disco.c deleted file mode 100644 index 41a4902..0000000 --- a/tests/i2c-master/main-stm32f072-disco.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include - -#include -#include "hw.h" -#include "i2c-master.h" - -#define LED_DISCO_GREEN_PORT GPIOC -#define LED_DISCO_GREEN_PIN GPIO9 - - - -struct hw_detail hw_details = { - .periph = I2C1, - .periph_rcc = RCC_I2C1, - .periph_rst = RST_I2C1, - .pins = GPIO8 | GPIO9, /* our external i2c device on I2c1 */ - .port = GPIOB, - .port_rcc = RCC_GPIOB, - .trigger_rcc = RCC_GPIOB, - .trigger_port = GPIOB, - .trigger_pin = GPIO12, - .i2c_clock_megahz = 48, -}; - - -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); -} - -/** - * Setup any gpios or anything hardware specific. - * Should _only_ be things that can't be done in shared i2cm_init! - */ -static void i2cm_hw_init(void) -{ - /* trigger pin gpio */ - rcc_periph_clock_enable(hw_details.trigger_rcc); - gpio_mode_setup(hw_details.trigger_port, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, hw_details.trigger_pin); - - /* i2c control lines */ - rcc_periph_clock_enable(hw_details.port_rcc); - gpio_mode_setup(hw_details.port, GPIO_MODE_AF, GPIO_PUPD_NONE, hw_details.pins); - gpio_set_output_options(hw_details.port, GPIO_OTYPE_OD, GPIO_OSPEED_HIGH, hw_details.pins); - gpio_set_af(hw_details.port, GPIO_AF1, hw_details.pins); - - /* select sysclk as i2c clock! */ - RCC_CFGR3 |= RCC_CFGR3_I2C1SW; -} - - -static void setup(void) -{ - setup_usart(); - printf("hi guys!\n"); - i2cm_hw_init(); - i2cm_init(); -} - -int main(void) -{ - int i; - rcc_clock_setup_in_hsi48_out_48mhz(); - /* green led for ticking */ - rcc_periph_clock_enable(RCC_GPIOC); - gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN); - gpio_set(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - - setup(); - - while (1) { - i2cm_task(); - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - for (i = 0; i < 0x800000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - -} - diff --git a/tests/i2c-master/main-stm32f4-disco.c b/tests/i2c-master/main-stm32f4-disco.c deleted file mode 100644 index 605872f..0000000 --- a/tests/i2c-master/main-stm32f4-disco.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Feb 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "trace.h" - -#include "hw.h" -#include "i2c-master.h" - -#define LED_DISCO_GREEN_PORT GPIOD -#define LED_DISCO_GREEN_PIN GPIO12 - - -struct hw_detail hw_details = { - .periph = I2C1, - .periph_rcc = RCC_I2C1, - .periph_rst = RST_I2C1, - .pins = GPIO8 | GPIO9, /* our external i2c device on I2c1 */ - .port = GPIOB, - .port_rcc = RCC_GPIOB, - .trigger_rcc = RCC_GPIOB, - .trigger_port = GPIOB, - .trigger_pin = GPIO13, -}; - - -/* provided in board files please*/ -/** - * Setup any gpios or anything hardware specific. - * Should _only_ be things that can't be done in shared i2cm_init! - */ -static void i2cm_hw_init(void) -{ - /* trigger pin gpio */ - rcc_periph_clock_enable(hw_details.trigger_rcc); - gpio_mode_setup(hw_details.trigger_port, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, hw_details.trigger_pin); - - /* i2c control lines */ - rcc_periph_clock_enable(hw_details.port_rcc); - gpio_mode_setup(hw_details.port, GPIO_MODE_AF, GPIO_PUPD_NONE, hw_details.pins); - gpio_set_output_options(hw_details.port, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, hw_details.pins); - gpio_set_af(hw_details.port, GPIO_AF4, hw_details.pins); -} - -static void setup(void) -{ - printf("hi guys!\n"); - i2cm_hw_init(); - i2cm_init(); -} - - -int main(void) -{ - int i, j; - rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); - /* green led for ticking */ - rcc_periph_clock_enable(RCC_GPIOD); - gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - LED_DISCO_GREEN_PIN); - setup(); - - while (1) { - i2cm_task(); - 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/i2c-master/main-stm32l1-generic.c b/tests/i2c-master/main-stm32l1-generic.c deleted file mode 100644 index 874cf7d..0000000 --- a/tests/i2c-master/main-stm32l1-generic.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Feb 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "trace.h" - -#include "hw.h" -#include "i2c-master.h" - -#define LED_DISCO_GREEN_PORT GPIOB -#define LED_DISCO_GREEN_PIN GPIO7 - - -struct hw_detail hw_details = { - .periph = I2C1, - .periph_rcc = RCC_I2C1, - .periph_rst = RST_I2C1, - .pins = GPIO8 | GPIO9, /* our external i2c device on I2c1 */ - .port = GPIOB, - .port_rcc = RCC_GPIOB, - .trigger_rcc = RCC_GPIOB, - .trigger_port = GPIOB, - .trigger_pin = GPIO13, - .i2c_clock_megahz = 32, -}; - - -/* provided in board files please*/ -/** - * Setup any gpios or anything hardware specific. - * Should _only_ be things that can't be done in shared i2cm_init! - */ -static void i2cm_hw_init(void) -{ - /* trigger pin gpio */ - rcc_periph_clock_enable(hw_details.trigger_rcc); - gpio_mode_setup(hw_details.trigger_port, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, hw_details.trigger_pin); - - /* i2c control lines */ - rcc_periph_clock_enable(hw_details.port_rcc); - gpio_mode_setup(hw_details.port, GPIO_MODE_AF, GPIO_PUPD_NONE, hw_details.pins); - gpio_set_output_options(hw_details.port, GPIO_OTYPE_OD, GPIO_OSPEED_10MHZ, hw_details.pins); - gpio_set_af(hw_details.port, GPIO_AF4, hw_details.pins); -} - -static void setup(void) -{ - printf("hi guys!\n"); - i2cm_hw_init(); - i2cm_init(); -} - - -int main(void) -{ - int i, j; - rcc_clock_setup_pll(&rcc_clock_config[RCC_CLOCK_VRANGE1_HSI_PLL_32MHZ]); - /* green led for ticking */ - rcc_periph_clock_enable(RCC_GPIOB); - gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - LED_DISCO_GREEN_PIN); - setup(); - - while (1) { - i2cm_task(); - 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/qemu/Makefile b/tests/qemu/Makefile deleted file mode 100644 index 67e84ab..0000000 --- a/tests/qemu/Makefile +++ /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 = lm3s -PROJECT = qemu-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../shared - -CFILES = main.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3 - -DEVICE=lm3s6965 - -include ../../rules.mk - -qemu: $(PROJECT).elf - qemu-system-arm -semihosting -M lm3s6965evb --kernel $^ -serial stdio - -qemu-dbg: $(PROJECT).elf - qemu-system-arm -semihosting -M lm3s6965evb --kernel $^ -serial stdio -S -gdb tcp::3333 diff --git a/tests/qemu/README.md b/tests/qemu/README.md deleted file mode 100644 index 4f02adb..0000000 --- a/tests/qemu/README.md +++ /dev/null @@ -1,20 +0,0 @@ -This project is used as a demonstrator on how to run a small baremetal application -on a LM3S6965 board, which can be emulated on qemu as well (using qemu-system-arm -with -M lm3s6965evb). - -For this reason, this application is not portable to other platforms at the moment. - -To execute in qemu run: - -`make qemu` - -To debug using gcc run: - -`make qemu-dbg` - -and then attach a gdb to localhost tcp port 3333. - -Requirements: -qemu-system-arm -openocd - diff --git a/tests/qemu/main.c b/tests/qemu/main.c deleted file mode 100644 index 863ce9e..0000000 --- a/tests/qemu/main.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - - -/* LM3S Specifics, usart and RCC */ -#include -#include - -static volatile uint32_t jiffies = 0u; - -static void printbanner(void) -{ - char msg[] = "One second elapsed!\r\n"; - char *c = msg; - while (*c != 0) { - usart_send(USART0_BASE, (uint16_t )*c); - c++; - } -} - -void sys_tick_handler(void) -{ - jiffies++; -} - -static inline uint32_t systick_app_config(uint32_t n_ticks) -{ - /* constant from systick_set_reload -- as this returns something that's - * * not void, this is the only possible error condition */ - if (n_ticks & ~0x00FFFFFF) { - return 1; - } - - systick_set_reload(n_ticks); - systick_set_clocksource(1); - systick_interrupt_enable(); - systick_counter_enable(); - - return 0; -} - -#define HZ 1000 - -int main(void) -{ - uint32_t last_time = 0; - rcc_clock_setup_in_xtal_8mhz_out_50mhz(); - systick_app_config(HZ); - - nvic_set_priority(NVIC_SYSTICK_IRQ, 0); - jiffies = 0; - while(1) { - if (jiffies > HZ) { - printbanner(); - jiffies = 0; - } - } -} diff --git a/tests/rcc-legal-ranges/Makefile.stm32l1-generic b/tests/rcc-legal-ranges/Makefile.stm32l1-generic deleted file mode 100644 index b9ecc71..0000000 --- a/tests/rcc-legal-ranges/Makefile.stm32l1-generic +++ /dev/null @@ -1,28 +0,0 @@ - -BOARD = stm32l1-generic -PROJECT = rcc-legal-ranges-$(BOARD) -BUILD_DIR = bin-$(BOARD) -OPT=-O0 - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).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... -LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/l1/stm32l15xx6.ld # pessimistic ;) -OPENCM3_LIB = opencm3_stm32l1 -OPENCM3_DEFS = -DSTM32L1 -FP_FLAGS ?= -ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -# Use the base targets, as we're playing with clocking too much for swo -OOCD_INTERFACE = stlink-v2 -OOCD_TARGET = stm32l1 - -include ../../rules.mk diff --git a/tests/rcc-legal-ranges/README.md b/tests/rcc-legal-ranges/README.md deleted file mode 100644 index 2313ebd..0000000 --- a/tests/rcc-legal-ranges/README.md +++ /dev/null @@ -1,14 +0,0 @@ - -Tests whether legal clock config structures can actually be used. -This primarily is testing whether the order of steps taken for -turning on and selecting different clocks, power ranges and flash -wait state configuration are robust enough. - -## PASSING -On boot you should get two slow blinks. -After boot, you should get continuous 5/2 fast/slow blinks as it -continuously shuffles and resets clock configurations. - -## FAILING -The board stops blinking at any point in the sequence - diff --git a/tests/rcc-legal-ranges/main-stm32l1-generic.c b/tests/rcc-legal-ranges/main-stm32l1-generic.c deleted file mode 100644 index 8c97bad..0000000 --- a/tests/rcc-legal-ranges/main-stm32l1-generic.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Aug 2016 Karl Palsson - */ - -#include -#include -#include -#include -#include - -/* Disco board is b6 */ -#define LEDPORT GPIOB -#define LEDPIN GPIO6 - -#ifndef ARRAY_LENGTH -#define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0])) -#endif - -/* - * A set of valid clock configurations with HSI as the source. - * thankfully, L1 allows apb1/apb2 to reach full ahb speed in all cases. - */ -struct rcc_clock_scale valid_hsi_clocks[] = { - { - /* 8Mhz, hsi/div2, max perf for range 2 with 0 ws */ - .hpre = RCC_CFGR_HPRE_SYSCLK_DIV2, - .ppre1 = RCC_CFGR_PPRE1_HCLK_NODIV, - .ppre2 = RCC_CFGR_PPRE2_HCLK_NODIV, - .voltage_scale = PWR_SCALE2, - .flash_config = FLASH_ACR_LATENCY_0WS, - .ahb_frequency = 8e6, - .apb1_frequency = 8e6, - .apb2_frequency = 8e6, - }, - { - /* Slowest hsi possible */ - .hpre = RCC_CFGR_HPRE_SYSCLK_DIV512, - .ppre1 = RCC_CFGR_PPRE1_HCLK_NODIV, - .ppre2 = RCC_CFGR_PPRE1_HCLK_NODIV, - .voltage_scale = PWR_SCALE3, - .flash_config = FLASH_ACR_LATENCY_0WS, - .ahb_frequency = 31250, - .apb1_frequency = 31250, - .apb2_frequency = 31250, - }, - { - /* Fastest HSI possible, range 1, 0ws */ - .hpre = RCC_CFGR_HPRE_SYSCLK_NODIV, - .ppre1 = RCC_CFGR_PPRE1_HCLK_NODIV, - .ppre2 = RCC_CFGR_PPRE1_HCLK_NODIV, - .voltage_scale = PWR_SCALE1, - .flash_config = FLASH_ACR_LATENCY_0WS, - .ahb_frequency = 16e6, - .apb1_frequency = 16e6, - .apb2_frequency = 16e6, - }, - { - /* highest perf for range 3 with 0 wait states */ - .hpre = RCC_CFGR_HPRE_SYSCLK_DIV8, - .ppre1 = RCC_CFGR_PPRE1_HCLK_NODIV, - .ppre2 = RCC_CFGR_PPRE1_HCLK_NODIV, - .voltage_scale = PWR_SCALE3, - .flash_config = FLASH_ACR_LATENCY_0WS, - .ahb_frequency = 2e6, - .apb1_frequency = 2e6, - .apb2_frequency = 2e6, - }, - { - /* Fastest HSI for range 2, 0ws */ - .hpre = RCC_CFGR_HPRE_SYSCLK_NODIV, - .ppre1 = RCC_CFGR_PPRE1_HCLK_NODIV, - .ppre2 = RCC_CFGR_PPRE1_HCLK_NODIV, - .voltage_scale = PWR_SCALE1, - .flash_config = FLASH_ACR_LATENCY_0WS, - .ahb_frequency = 16e6, - .apb1_frequency = 16e6, - .apb2_frequency = 16e6, - }, - { - /* highest perf for range 3 */ - .hpre = RCC_CFGR_HPRE_SYSCLK_DIV4, - .ppre1 = RCC_CFGR_PPRE1_HCLK_NODIV, - .ppre2 = RCC_CFGR_PPRE1_HCLK_NODIV, - .voltage_scale = PWR_SCALE3, - .flash_config = FLASH_ACR_LATENCY_1WS, - .ahb_frequency = 4e6, - .apb1_frequency = 4e6, - .apb2_frequency = 4e6, - }, -}; - -int shuffled[ARRAY_LENGTH(valid_hsi_clocks)]; - -/** - * blink led count times, with vile hack * 1000 asm nops - */ -static void hack_blink(int count, int hack) -{ - for (int i = 0; i < count; i++) { - gpio_toggle(LEDPORT, LEDPIN); - for (int k = 0; k < hack * 1000; k++) { - __asm__("nop"); - } - } -} - -/* Stack overflow, wiki, whathaveyou */ -/* FIXME oh yeah, did I mention that rand() is always zero? */ -static void shuffle_fisher_yates(int *array, size_t n) -{ - if (n > 1) { - size_t i; - for (i = 0; i < n - 1; i++) { - size_t j = i + rand() / (RAND_MAX / (n - i) + 1); - int t = array[j]; - array[j] = array[i]; - array[i] = t; - } - } -} - -static void run_clock_set(void) -{ - shuffle_fisher_yates(shuffled, ARRAY_LENGTH(shuffled)); - - struct rcc_clock_scale *clock; - for (size_t i = 0; i < ARRAY_LENGTH(shuffled); i++) { - clock = &valid_hsi_clocks[i]; - rcc_clock_setup_hsi(clock); - /** blink quickly/slowly as we run through these */ - hack_blink(10, clock->ahb_frequency / (500 * 1000)); - hack_blink(4, clock->ahb_frequency / (200 * 1000)); - } -} - -int main(void) -{ - /* Allow leds on any port */ - RCC_AHBENR |= 0xff; - gpio_mode_setup(LEDPORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LEDPIN); - /* blink twice with slow msi reset clock */ - hack_blink(4, 60); - - /* ok, now, "randomly" sort the list of clocks to try them out */ - for (size_t i = 0; i < ARRAY_LENGTH(shuffled); i++) { - shuffled[i] = i; - } - - while (1) { - run_clock_set(); - } - - return 0; -} diff --git a/tests/spi-master/Makefile b/tests/spi-master/Makefile deleted file mode 100644 index 52841cd..0000000 --- a/tests/spi-master/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/spi-master/Makefile.dut-stm32l073rz b/tests/spi-master/Makefile.dut-stm32l073rz deleted file mode 100644 index 899c0fe..0000000 --- a/tests/spi-master/Makefile.dut-stm32l073rz +++ /dev/null @@ -1,21 +0,0 @@ -BOARD = dut-stm32l073rz -PROJECT = spi-master-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFLAGS = -DSTDIO_USART=USART2 -CFILES = main-$(BOARD).c -#CFILES += spi-master.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=stm32l073rz -OOCD_FILE = openocd.dut-stm32l073rz.cfg -include ../../rules.mk diff --git a/tests/spi-master/Makefile.host-stm32l1-generic b/tests/spi-master/Makefile.host-stm32l1-generic deleted file mode 100644 index 8996ff7..0000000 --- a/tests/spi-master/Makefile.host-stm32l1-generic +++ /dev/null @@ -1,18 +0,0 @@ -BOARD = host-stm32l1-generic -PROJECT = spi-slave-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -#CFILES += spi-master.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3 -DEVICE=stm32l151xb -OOCD_FILE = openocd.stm32l1-generic.cfg -include ../../rules.mk diff --git a/tests/spi-master/README.md b/tests/spi-master/README.md deleted file mode 100644 index 504a074..0000000 --- a/tests/spi-master/README.md +++ /dev/null @@ -1,25 +0,0 @@ -SPI master mode tests - -While some of the disco boards have some form of spi device onboard, -which would, on the face of it, make testing easy, it's a different -device on each board, and there are boards without it. - -Instead, use a known SPI peripheral on all boards, and require/expect -a known fixed SPI slave device. Use a soft controller SPI slave device -for the far side, for double the test coverage! - -the "trigger" pin is bounced when each iteration of the test code starts, -allowing synchronization with a sigrok script that helps assure that -results are as expected. - -Debug is via SWO wherever possible, PA2 (tx only) on less capable cores - -Pinouts: - (red) (orange) (yellow)(brown) (black) -board CLK MISO MOSI CS periph trigger -f4-disco PB13 PB14 PB15 PB12 spi2 PB11 -l1-disco PB13 PB14 PB15 PB12 spi2 PB11 - - -Notes for monitoring with sigrok: -$ sigrok-cli -d fx2lafw -C D0=TRIG,D1=CS,D2=CLK,D3=MISO,D4=MOSI -c samplerate=12Mhz:captureratio=4 --time=150ms -t TRIG=r -P spi:clk=CLK:miso=MISO:mosi=MOSI -A spi=mosi-data diff --git a/tests/spi-master/hw.h b/tests/spi-master/hw.h deleted file mode 100644 index 2cbbea8..0000000 --- a/tests/spi-master/hw.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * March 2017 Karl Palsson - */ - -#include -#include - -#pragma once - -struct hw_detail -{ - uint32_t periph; /* eg: SPI2 */ - uint32_t periph_rcc; /* eg: RCC_SPI2 */ - uint32_t periph_rst; /* eg: RST_SPI2 */ - uint32_t pins; /* to set to the AF for the periph */ - uint32_t port; /* eg GPIOB */ - uint32_t port_rcc; /* for the gpio pins */ - uint32_t trigger_rcc; - uint32_t trigger_port; - uint32_t trigger_pin; -}; - -extern struct hw_detail hw_details; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Expected to setup clocks, turn on all peripherals, and configure - * any gpios necessary. - * @param hw pointer to hw details necessary - */ - void hw_setup(struct hw_detail* hw); - - /* let devices have a status led */ - void hw_set_led(bool val); - -#ifdef __cplusplus -} -#endif diff --git a/tests/spi-master/main-dut-stm32l073rz.c b/tests/spi-master/main-dut-stm32l073rz.c deleted file mode 100644 index 058d841..0000000 --- a/tests/spi-master/main-dut-stm32l073rz.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * March 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hw.h" - -#define LED_DISCO_GREEN_PORT GPIOB // actually cs -#define LED_DISCO_GREEN_PIN GPIO6 - - -struct hw_detail hw_details = { - .periph = SPI1, - .periph_rcc = RCC_SPI1, - .periph_rst = RST_SPI1, - .pins = GPIO5| GPIO6 | GPIO7, /* SPI pins for setting AF with */ - .port = GPIOA, - .port_rcc = RCC_GPIOA, - .trigger_rcc = RCC_GPIOB, - .trigger_port = GPIOB, - .trigger_pin = GPIO8, // pb6 is d7 on the LA -}; - - -/* provided in board files please*/ -/** - * Setup any gpios or anything hardware specific. - * Should _only_ be things that can't be done in shared init() - */ -static void hw_init(void) -{ - /* trigger pin gpio */ - rcc_periph_clock_enable(hw_details.trigger_rcc); - gpio_mode_setup(hw_details.trigger_port, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, hw_details.trigger_pin); - - /* spi control lines */ - rcc_periph_clock_enable(hw_details.port_rcc); - gpio_mode_setup(hw_details.port, GPIO_MODE_AF, GPIO_PUPD_NONE, hw_details.pins); - gpio_set_output_options(hw_details.port, GPIO_OTYPE_PP, GPIO_OSPEED_MED, hw_details.pins); - gpio_set_af(hw_details.port, GPIO_AF0, hw_details.pins); -} - -static void test_init(void) -{ - /* Setup SPI parameters. */ - rcc_periph_clock_enable(hw_details.periph_rcc); - spi_init_master(hw_details.periph, SPI_CR1_BAUDRATE_FPCLK_DIV_32, SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE, - SPI_CR1_CPHA_CLK_TRANSITION_1, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST); - /* Ignore the stupid NSS pin. */ - spi_enable_software_slave_management(hw_details.periph); - spi_set_nss_high(hw_details.periph); - - /* Finally enable the SPI. */ - spi_enable(hw_details.periph); -} - -static void test_task(void) { - static int i = 0; - printf("DUT iter %d\n", i++); - gpio_set(hw_details.trigger_port, hw_details.trigger_pin); - gpio_clear(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - spi_xfer(hw_details.periph, 0xaa); - spi_xfer(hw_details.periph, 0x42); - spi_xfer(hw_details.periph, 0x69); - gpio_set(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - gpio_clear(hw_details.trigger_port, hw_details.trigger_pin); -} - -static -void setup_usart(void) -{ - uint32_t dev = USART2; - rcc_periph_clock_enable(RCC_USART2); - rcc_periph_clock_enable(RCC_GPIOA); - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2|GPIO3); - gpio_set_af(GPIOA, GPIO_AF4, GPIO2|GPIO3); - - usart_set_baudrate(dev, 115200); - usart_set_databits(dev, 8); - usart_set_parity(dev, USART_PARITY_NONE); - usart_set_stopbits(dev, USART_STOPBITS_1); - usart_set_mode(dev, USART_MODE_TX_RX); - usart_set_flow_control(dev, USART_FLOWCONTROL_NONE); - - /* Finally enable the USART. */ - usart_enable(dev); -} - - -static void setup(void) -{ - setup_usart(); - printf("hi guys!\n"); - hw_init(); - test_init(); -} - - -int main(void) -{ - const struct rcc_clock_scale myclock = { - .pll_source = RCC_CFGR_PLLSRC_HSI16_CLK, - .pll_mul = RCC_CFGR_PLLMUL_MUL4, - .pll_div = RCC_CFGR_PLLDIV_DIV2, - .hpre = RCC_CFGR_HPRE_NODIV, - .ppre1 = RCC_CFGR_PPRE1_NODIV, - .ppre2 = RCC_CFGR_PPRE2_NODIV, - .voltage_scale = PWR_SCALE1, - .flash_waitstates = 1, - .ahb_frequency = 32e6, - .apb1_frequency = 32e6, - .apb2_frequency = 32e6, - }; - int i, j; - rcc_clock_setup_pll(&myclock); - rcc_periph_clock_enable(RCC_SYSCFG); - - /* green led for ticking */ - rcc_periph_clock_enable(RCC_GPIOB); - gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN); - gpio_set(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - setup(); - - while (1) { - test_task(); - //gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - for (i = 0; i < 0x80000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - return 0; -} diff --git a/tests/spi-master/main-host-stm32l1-generic.c b/tests/spi-master/main-host-stm32l1-generic.c deleted file mode 100644 index fa40ba1..0000000 --- a/tests/spi-master/main-host-stm32l1-generic.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * March 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "trace.h" - -#include "hw.h" - -struct hw_detail hw_details = { - .periph = SPI2, - .periph_rcc = RCC_SPI2, - .periph_rst = RST_SPI2, - .pins = GPIO13| GPIO14 | GPIO15, /* SPI pins for setting AF with */ - .port = GPIOB, - .port_rcc = RCC_GPIOB, - .trigger_rcc = RCC_GPIOB, - .trigger_port = GPIOB, - .trigger_pin = GPIO9, -}; - - -/* provided in board files please*/ -/** - * Setup any gpios or anything hardware specific. - * Should _only_ be things that can't be done in shared init() - */ -static void hw_init(void) -{ - /* trigger pin gpio */ - rcc_periph_clock_enable(hw_details.trigger_rcc); - gpio_mode_setup(hw_details.trigger_port, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, hw_details.trigger_pin); - - /* spi control lines */ - rcc_periph_clock_enable(hw_details.port_rcc); - gpio_mode_setup(hw_details.port, GPIO_MODE_AF, GPIO_PUPD_NONE, hw_details.pins); - gpio_set_output_options(hw_details.port, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, hw_details.pins); - gpio_set_af(hw_details.port, GPIO_AF5, hw_details.pins); -} - -static void test_init(void) -{ - /* Setup SPI parameters. */ - rcc_periph_clock_enable(hw_details.periph_rcc); - /* mostly, this is just "write 0 to cr1" */ - spi_set_slave_mode(hw_details.periph); - spi_send_msb_first(hw_details.periph); - spi_set_dff_8bit(hw_details.periph); - spi_set_clock_phase_0(hw_details.periph); - spi_set_clock_polarity_0(hw_details.periph); - spi_set_frf_motorola(hw_details.periph); - - /* we're a spi slave, use a CS pin */ - spi_disable_software_slave_management(hw_details.periph); - SPI_CR2(hw_details.periph) &= ~SPI_CR2_SSOE; - - /* Finally enable the SPI. */ - spi_enable(hw_details.periph); -} - -static void test_task(void) { - static int i = 0; - uint32_t spi = hw_details.periph; - if (SPI_SR(spi) & SPI_SR_TXE) { - /* ready to load next data in */ - SPI_DR(spi) = i++; - } - - if (SPI_SR(spi) & SPI_SR_RXNE) { - uint8_t data = SPI_DR(spi); - trace_send8(2, data); - } -} - - -static void setup(void) -{ - printf("hi guys!\n"); - hw_init(); - test_init(); -} - - -int main(void) -{ - const struct rcc_clock_scale myclock = { - .pll_source = RCC_CFGR_PLLSRC_HSE_CLK, - .pll_mul = RCC_CFGR_PLLMUL_MUL4, - .pll_div = RCC_CFGR_PLLDIV_DIV2, - .hpre = RCC_CFGR_HPRE_SYSCLK_NODIV, - .ppre1 = RCC_CFGR_PPRE1_HCLK_NODIV, - .ppre2 = RCC_CFGR_PPRE2_HCLK_NODIV, - .voltage_scale = PWR_SCALE1, - .flash_waitstates = 1, - .ahb_frequency = 32e6, - .apb1_frequency = 32e6, - .apb2_frequency = 32e6, - }; - int i, j; - rcc_clock_setup_pll(&myclock); - setup(); - - while (1) { - test_task(); - } - return 0; -} diff --git a/tests/uart-basic/Makefile.dut-stm32l073rz b/tests/uart-basic/Makefile.dut-stm32l073rz deleted file mode 100644 index d8575d9..0000000 --- a/tests/uart-basic/Makefile.dut-stm32l073rz +++ /dev/null @@ -1,26 +0,0 @@ -# This is just a makefile. -# Consider it released into the public domain, or, where not available, -# available under your choice of BSD2clause, MIT, X11, ISC or Apache2 licenses -# Karl Palsson -BOARD = dut-stm32l073rz -PROJECT = uart-basic-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += uart-basic.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3/ - -### This section can go to an arch shared rules eventually... -DEVICE=stm32l073rz -#OOCD_INTERFACE = stlink-v2 -#OOCD_TARGET = stm32l0x -OOCD_FILE = ../../openocd/openocd.$(BOARD).cfg - -include ../../rules.mk diff --git a/tests/uart-basic/Makefile.stm32f072disco b/tests/uart-basic/Makefile.stm32f072disco deleted file mode 100644 index c7fd490..0000000 --- a/tests/uart-basic/Makefile.stm32f072disco +++ /dev/null @@ -1,26 +0,0 @@ -# This is just a makefile. -# Consider it released into the public domain, or, where not available, -# available under your choice of BSD2clause, MIT, X11, ISC or Apache2 licenses -# Karl Palsson -BOARD = stm32f072disco -PROJECT = uart-basic-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += uart-basic.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3/ - -### This section can go to an arch shared rules eventually... -DEVICE=stm32f072rb -#OOCD_INTERFACE = stlink-v2 -#OOCD_TARGET = stm32f0x -OOCD_FILE = ../../openocd/openocd.$(BOARD).cfg - -include ../../rules.mk diff --git a/tests/uart-basic/Makefile.stm32f3-disco b/tests/uart-basic/Makefile.stm32f3-disco deleted file mode 100644 index 2320af0..0000000 --- a/tests/uart-basic/Makefile.stm32f3-disco +++ /dev/null @@ -1,29 +0,0 @@ -# This is just a makefile. -# Consider it released into the public domain, or, where not available, -# available under your choice of BSD2clause, MIT, X11, ISC or Apache2 licenses -# Karl Palsson -BOARD = stm32f3-disco -PROJECT = uart-basic-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += uart-basic.c -# No trace, we're using the uart explicitly here, deliberately. -# Perhaps later we'll use trace differently, or with different files -#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=stm32f303vct6 -#OOCD_INTERFACE = stlink-v2 -#OOCD_TARGET = stm32f3x -OOCD_FILE = ../../openocd/openocd.stm32f3-disco.cfg - -include ../../rules.mk diff --git a/tests/uart-basic/Makefile.stm32f4-disco b/tests/uart-basic/Makefile.stm32f4-disco deleted file mode 100644 index 40e2e1c..0000000 --- a/tests/uart-basic/Makefile.stm32f4-disco +++ /dev/null @@ -1,29 +0,0 @@ -# This is just a makefile. -# Consider it released into the public domain, or, where not available, -# available under your choice of BSD2clause, MIT, X11, ISC or Apache2 licenses -# Karl Palsson -BOARD = stm32f4-disco -PROJECT = uart-basic-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += uart-basic.c -# No trace, we're using the uart explicitly here, deliberately. -# Perhaps later we'll use trace differently, or with different files -#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/uart-basic/Makefile.stm32l053disco b/tests/uart-basic/Makefile.stm32l053disco deleted file mode 100644 index 5858eaf..0000000 --- a/tests/uart-basic/Makefile.stm32l053disco +++ /dev/null @@ -1,26 +0,0 @@ -# This is just a makefile. -# Consider it released into the public domain, or, where not available, -# available under your choice of BSD2clause, MIT, X11, ISC or Apache2 licenses -# Karl Palsson -BOARD = stm32l053disco -PROJECT = uart-basic-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += uart-basic.c - -VPATH += $(SHARED_DIR) - -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) - -OPENCM3_DIR=../../libopencm3/ - -### This section can go to an arch shared rules eventually... -DEVICE=stm32l053c8 -#OOCD_INTERFACE = stlink-v2 -#OOCD_TARGET = stm32l0x -OOCD_FILE = ../../openocd/openocd.$(BOARD).cfg - -include ../../rules.mk diff --git a/tests/uart-basic/Makefile.stm32l476disco b/tests/uart-basic/Makefile.stm32l476disco deleted file mode 100644 index 79b8ab7..0000000 --- a/tests/uart-basic/Makefile.stm32l476disco +++ /dev/null @@ -1,26 +0,0 @@ -# This is just a makefile. -# Consider it released into the public domain, or, where not available, -# available under your choice of BSD2clause, MIT, X11, ISC or Apache2 licenses -# Karl Palsson -BOARD = stm32l476disco -PROJECT = uart-basic-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += uart-basic.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.$(BOARD).cfg - -include ../../rules.mk diff --git a/tests/uart-basic/main-dut-stm32l073rz.c b/tests/uart-basic/main-dut-stm32l073rz.c deleted file mode 100644 index 17a68da..0000000 --- a/tests/uart-basic/main-dut-stm32l073rz.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Oct 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "uart-basic.h" - -#define LED_NUC_RCC RCC_GPIOA -#define LED_NUC_PORT GPIOA -#define LED_NUC_PIN GPIO5 - -void usart2_isr(void) -{ - ub_irq_handler(); -} - -static void setup_rcc_hack(void) -{ - /* FIXME L0 doesn't have rcc setup helpers (yet) */ - rcc_osc_on(RCC_HSI16); - rcc_wait_for_osc_ready(RCC_HSI16); - rcc_set_sysclk_source(RCC_HSI16); - - /* ok, we manually poked around, let the lib know */ - rcc_apb1_frequency = rcc_apb2_frequency = 16e6; -} - -static void board_init(void) -{ - rcc_periph_clock_enable(RCC_GPIOA); - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2 | GPIO3); - /* usart is AF4 */ - gpio_set_af(GPIOA, GPIO_AF4, GPIO2 | GPIO3); -} - -int main(void) -{ - int i; - int j = 0; - setup_rcc_hack(); - board_init(); - struct ub_hw ub = { - .uart = USART2, - .uart_nvic = NVIC_USART2_IRQ, - .uart_rcc = RCC_USART2, - }; - ub_init(&ub); - printf("hi guys!\n"); - /* green led for ticking */ - rcc_periph_clock_enable(LED_NUC_RCC); - gpio_mode_setup(LED_NUC_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - LED_NUC_PIN); - - - while (1) { - gpio_toggle(LED_NUC_PORT, LED_NUC_PIN); - - for (i = 0; i < 0x40000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - ub_task(); - gpio_toggle(LED_NUC_PORT, LED_NUC_PIN); - for (i = 0; i < 0x40000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/uart-basic/main-stm32f072disco.c b/tests/uart-basic/main-stm32f072disco.c deleted file mode 100644 index fdd630e..0000000 --- a/tests/uart-basic/main-stm32f072disco.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Oct 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "uart-basic.h" - -#define LED_DISCO_GREEN_RCC RCC_GPIOC -#define LED_DISCO_GREEN_PORT GPIOC -#define LED_DISCO_GREEN_PIN GPIO9 - -void usart3_4_isr(void) -{ - ub_irq_handler(); -} - -static void board_init(void) { - rcc_periph_clock_enable(RCC_GPIOB); - gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO10|GPIO11); - /* usart3 is AF4 */ - gpio_set_af(GPIOB, GPIO_AF4, GPIO10|GPIO11); -} - -int main(void) -{ - int i; - int j = 0; - rcc_clock_setup_in_hsi48_out_48mhz(); - board_init(); - struct ub_hw ub = { - .uart = USART3, - .uart_nvic = NVIC_USART3_4_IRQ, - .uart_rcc = RCC_USART3, - }; - ub_init(&ub); - printf("hi guys!\n"); - /* green led for ticking */ - rcc_periph_clock_enable(LED_DISCO_GREEN_RCC); - gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - LED_DISCO_GREEN_PIN); - - - while (1) { - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - - for (i = 0; i < 0xa0000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - ub_task(); - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - for (i = 0; i < 0xa0000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/uart-basic/main-stm32f3-disco.c b/tests/uart-basic/main-stm32f3-disco.c deleted file mode 100644 index 94c6937..0000000 --- a/tests/uart-basic/main-stm32f3-disco.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Oct 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "uart-basic.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); -} - -void usart2_exti26_isr(void) -{ - ub_irq_handler(); -} - -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); - - /* board init for uart2 on pa2/3 */ - rcc_periph_clock_enable(RCC_GPIOA); - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2|GPIO3); - /* usart is AF7 */ - gpio_set_af(GPIOA, GPIO_AF7, GPIO2|GPIO3); - - struct ub_hw ub = { - .uart = USART2, - .uart_nvic = NVIC_USART2_EXTI26_IRQ, - .uart_rcc = RCC_USART2, - }; - ub_init(&ub); - printf("hi guys!\n"); - - while (1) { - gpio_toggle(GPIOE, GPIO8); - - for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - ub_task(); - gpio_toggle(GPIOE, GPIO8); - for (i = 0; i < 0x100000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/uart-basic/main-stm32f4-disco.c b/tests/uart-basic/main-stm32f4-disco.c deleted file mode 100644 index 86d9b4a..0000000 --- a/tests/uart-basic/main-stm32f4-disco.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Oct 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "uart-basic.h" - -#define LED_DISCO_GREEN_PORT GPIOD -#define LED_DISCO_GREEN_PIN GPIO12 - -void usart2_isr(void) -{ - ub_irq_handler(); -} - -static void board_init(void) { - rcc_periph_clock_enable(RCC_GPIOA); - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2|GPIO3); - /* usart is AF7 */ - gpio_set_af(GPIOA, GPIO_AF7, GPIO2|GPIO3); -} - -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); - board_init(); - struct ub_hw ub = { - .uart = USART2, - .uart_nvic = NVIC_USART2_IRQ, - .uart_rcc = RCC_USART2, - }; - ub_init(&ub); - 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); - - - while (1) { - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - - for (i = 0; i < 0x800000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - ub_task(); - 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/uart-basic/main-stm32l053disco.c b/tests/uart-basic/main-stm32l053disco.c deleted file mode 100644 index 8c97f1d..0000000 --- a/tests/uart-basic/main-stm32l053disco.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Oct 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "uart-basic.h" - -#define LED_DISCO_GREEN_RCC RCC_GPIOB -#define LED_DISCO_GREEN_PORT GPIOB -#define LED_DISCO_GREEN_PIN GPIO4 - -void usart1_isr(void) -{ - ub_irq_handler(); -} - -static void setup_rcc_hack(void) -{ - /* FIXME L0 doesn't have rcc setup helpers (yet) */ - rcc_osc_on(RCC_HSI16); - rcc_wait_for_osc_ready(RCC_HSI16); - rcc_set_sysclk_source(RCC_HSI16); - - /* ok, we manually poked around, let the lib know */ - rcc_apb1_frequency = rcc_apb2_frequency = 16e6; -} - -static void board_init(void) -{ - rcc_periph_clock_enable(RCC_GPIOA); - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO10); - /* usart1 is AF4 */ - gpio_set_af(GPIOA, GPIO_AF4, GPIO9 | GPIO10); -} - -int main(void) -{ - int i; - int j = 0; - setup_rcc_hack(); - board_init(); - struct ub_hw ub = { - .uart = USART1, - .uart_nvic = NVIC_USART1_IRQ, - .uart_rcc = RCC_USART1, - }; - ub_init(&ub); - printf("hi guys!\n"); - /* green led for ticking */ - rcc_periph_clock_enable(LED_DISCO_GREEN_RCC); - gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - LED_DISCO_GREEN_PIN); - - - while (1) { - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - - for (i = 0; i < 0x40000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - ub_task(); - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - for (i = 0; i < 0x40000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/uart-basic/main-stm32l476disco.c b/tests/uart-basic/main-stm32l476disco.c deleted file mode 100644 index 82c98f0..0000000 --- a/tests/uart-basic/main-stm32l476disco.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Oct 2017 Karl Palsson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "uart-basic.h" - -#define LED_DISCO_GREEN_RCC RCC_GPIOE -#define LED_DISCO_GREEN_PORT GPIOE -#define LED_DISCO_GREEN_PIN GPIO8 - -void usart2_isr(void) -{ - ub_irq_handler(); -} - -static void setup_rcc_hack(void) -{ - pwr_set_vos_scale(PWR_SCALE1); - flash_set_ws(FLASH_ACR_LATENCY_2WS); - rcc_set_msi_range(RCC_CR_MSIRANGE_48MHZ); - - /* ok, we manually poked around, let the lib know */ - rcc_apb1_frequency = rcc_apb2_frequency = 48e6; -} - -static void board_init(void) -{ - rcc_periph_clock_enable(RCC_GPIOD); - gpio_mode_setup(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO5 | GPIO6); - /* usart2 is AF7 */ - gpio_set_af(GPIOD, GPIO_AF7, GPIO5 | GPIO6); -} - -int main(void) -{ - int i; - int j = 0; - setup_rcc_hack(); - board_init(); - struct ub_hw ub = { - .uart = USART2, - .uart_nvic = NVIC_USART2_IRQ, - .uart_rcc = RCC_USART2, - }; - ub_init(&ub); - printf("hi guys!\n"); - /* green led for ticking */ - rcc_periph_clock_enable(LED_DISCO_GREEN_RCC); - gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - LED_DISCO_GREEN_PIN); - - - while (1) { - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - - for (i = 0; i < 0xa0000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - ub_task(); - gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); - for (i = 0; i < 0xa0000; i++) { /* Wait a bit. */ - __asm__("NOP"); - } - } - - return 0; -} diff --git a/tests/uart-basic/uart-basic.c b/tests/uart-basic/uart-basic.c deleted file mode 100644 index 8c5124c..0000000 --- a/tests/uart-basic/uart-basic.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Karl Palsson Oct 2017 - * Considered to be available under your choice of: - * BSD2 clause, Apache2, MIT, X11 or ISC licenses - */ - -#include -#include -#include -#include -#include -#include -#include "uart-basic.h" - -/* prototype to make linking happy */ -int _write(int file, char *ptr, int len); - -static struct ub_hw *ub; -static uint8_t last_rxb; - -/* Implement _write for newlib to use printf */ -int _write(int file, char *ptr, int len) -{ - int i; - - if (file == STDOUT_FILENO || file == STDERR_FILENO) { - for (i = 0; i < len; i++) { - if (ptr[i] == '\n') { - usart_send_blocking(ub->uart, '\r'); - } - usart_send_blocking(ub->uart, ptr[i]); - } - return i; - } - errno = EIO; - return -1; -} - -void ub_init(struct ub_hw *ub_input) -{ - ub = ub_input; - rcc_periph_clock_enable(ub->uart_rcc); - - usart_set_baudrate(ub->uart, 115200); - usart_set_databits(ub->uart, 9); - usart_set_stopbits(ub->uart, USART_STOPBITS_1); - usart_set_mode(ub->uart, USART_MODE_TX_RX); - usart_set_parity(ub->uart, USART_PARITY_EVEN); - usart_set_flow_control(ub->uart, USART_FLOWCONTROL_NONE); - - usart_enable_rx_interrupt(ub->uart); - nvic_enable_irq(ub->uart_nvic); - usart_enable(ub->uart); -} - -void ub_task(void) -{ - if (last_rxb) { - printf("Last rx char was: <%c>\n", last_rxb); - last_rxb = 0; - } else { - printf("enter a character!\n"); - } -} - -void ub_irq_handler(void) -{ - if (usart_get_flag(ub->uart, USART_FLAG_RXNE)) { - last_rxb = usart_recv(ub->uart); - } -} diff --git a/tests/uart-basic/uart-basic.h b/tests/uart-basic/uart-basic.h deleted file mode 100644 index 8e3b8f6..0000000 --- a/tests/uart-basic/uart-basic.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Karl Palsson Oct 2017 - * Considered to be available under your choice of: - * BSD2 clause, Apache2, MIT, X11 or ISC licenses - */ - -#pragma once - -#include -#include - -struct ub_hw { - /** usart itself, eg USART2 */ - uint32_t uart; - /** RCC_xxx flag for this usart, eg RCC_USART2 */ - uint32_t uart_rcc; - /** eg NVIC_USART2_IRQ */ - uint32_t uart_nvic; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Initialise the uart itself. - * gpios are required to have been already configured as needed - * @param ub - */ -void ub_init(struct ub_hw *ub); - -/** - * Call this, it will "do stuff" - */ -void ub_task(void); - -/** - * Call this from your board irq handler, it will "do the right thing" - */ -void ub_irq_handler(void); - -#ifdef __cplusplus -} -#endif diff --git a/tests/usb-serial-rs485/Makefile.stm32f103-generic b/tests/usb-serial-rs485/Makefile.stm32f103-generic deleted file mode 100644 index 747238d..0000000 --- a/tests/usb-serial-rs485/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 = usb-serial-rs485-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += usb_cdcacm.c usb_cdcacm-arch.c -CFILES += ringb.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) -OPENCM3_DIR=../../libopencm3 - -# Copy this to some arch shared? -DEVICE=stm32f103c8 -OOCD_FILE= ../../openocd/openocd.stm32f4-disco.cfg - -include ../../rules.mk - diff --git a/tests/usb-serial-rs485/Makefile.stm32f4-disco b/tests/usb-serial-rs485/Makefile.stm32f4-disco deleted file mode 100644 index 1c60091..0000000 --- a/tests/usb-serial-rs485/Makefile.stm32f4-disco +++ /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 = stm32f4-disco -PROJECT = usb-serial-rs485-$(BOARD) -BUILD_DIR = bin-$(BOARD) - -SHARED_DIR = ../../shared - -CFILES = main-$(BOARD).c -CFILES += usb_cdcacm.c usb_cdcacm-arch.c -CFILES += ringb.c -CFILES += trace.c trace_stdio.c - -VPATH += $(SHARED_DIR) -INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) -OPENCM3_DIR=../../libopencm3 - -# Copy this to some arch shared? -DEVICE=stm32f405xg -OOCD_FILE= ../../openocd/openocd.stm32f4-disco.cfg - -include ../../rules.mk - diff --git a/tests/usb-serial-rs485/README b/tests/usb-serial-rs485/README deleted file mode 100644 index 0e5b2cd..0000000 --- a/tests/usb-serial-rs485/README +++ /dev/null @@ -1,33 +0,0 @@ ------------------------------------------------------------------------------- -README ------------------------------------------------------------------------------- - -current status: -f1: frootloop3 gets corrupt data in rx path, _after_ serial rx, -but the usb in packets (wireshark) show the corruption. (LA on serial lines is clean) -f4: frootloop3 tests clean -=> suspect libopecm3 usb bug? - -frootloop3: github.com/karlp/frootloop3 - - - -This implements a USB CDC-ACM device, connected to USART2 (PA2-tx/PA3-rx) -An interrupt driven tx ring buffer is used for usb->serial, and a similar -interrupt driven rx ring buffer is used for serial->usb. -Baud rates from 2400-460800 are tested with zmodem transfers in both directions. - -Parity not yet finished, and baudrates below 1200 need fiddling with clock prescalers. -When it's finished, rs485 support should be available via the TC interrupt. - -A GPIO is toggled around USART transmissions to control an RS485 line -transceiver, following ST's app note. The RS485 driver enable line is, -by default, just the onboard red LEDs. - -The orange/blue LEDs indicate tx/rx activity, but especially for the rx line, -you won't really see it without heavy data rates. - -This example is heavily based on the existing usb_cdcacm and usart demos. - - -KARL - check https://github.com/dhylands/libopencm3-usb-serial/blob/master/usb.c to see if it passes the same tests or not diff --git a/tests/usb-serial-rs485/main-stm32f103-generic.c b/tests/usb-serial-rs485/main-stm32f103-generic.c deleted file mode 100644 index 415a18b..0000000 --- a/tests/usb-serial-rs485/main-stm32f103-generic.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2014 Karl Palsson - * - * 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 . - */ - -#include -#include -#include -#include - -#include -#include "syscfg.h" -#include "usb_cdcacm.h" -#include "ringb.h" -#include "trace.h" - -#define ER_DEBUG -#ifdef ER_DEBUG -#define ER_DPRINTF(fmt, ...) \ - do { printf(fmt, ## __VA_ARGS__); } while (0) -#else -#define ER_DPRINTF(fmt, ...) \ - do { } while (0) -#endif - -static inline void gpio_really(uint32_t port, uint16_t pin, const bool set) -{ - int shift = set ? 0 : 16; - GPIO_BSRR(port) = pin << shift; -} - - -extern struct ringb rx_ring, tx_ring; -static void usart_setup(void) -{ - /* Enable the USART2 interrupt. */ - nvic_enable_irq(NVIC_USART2_IRQ); - - /* USART2 pins are on port A */ - rcc_periph_clock_enable(RCC_GPIOA); - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX); - gpio_set_mode(GPIOA, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_USART2_RX); - - /* Enable clocks for USART2. */ - rcc_periph_clock_enable(RCC_USART2); - - /* Setup USART2 parameters. */ - usart_set_baudrate(USART2, 115200); - usart_set_databits(USART2, 8); - usart_set_stopbits(USART2, USART_STOPBITS_1); - usart_set_mode(USART2, USART_MODE_TX_RX); - usart_set_parity(USART2, USART_PARITY_NONE); - usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); - - /* Enable USART2 Receive interrupt. */ - usart_enable_rx_interrupt(USART2); - - /* Finally enable the USART. */ - usart_enable(USART2); -} - -void usart2_isr(void) -{ - gpio_really(GPIOA, GPIO5, 1); - // usbser-rxne() - /* Check if we were called because of RXNE. */ - if (usart_get_interrupt_source(USART2, USART_SR_RXNE)) { - gpio_set(LED_RX_PORT, LED_RX_PIN); - uint8_t c = usart_recv(USART2); - if (ringb_put(&rx_ring, c)) { - // good, - } else { - // fatal, you should always have drained by now. - // (when you've got it all ironed out, _actually_ - // just drop and count drops), but not yet... - ER_DPRINTF("rx buffer full\n"); - while(1); - } - trace_send8(STIMULUS_RING_PUSH, c); - gpio_clear(LED_RX_PORT, LED_RX_PIN); - } - // usbser-irq-txe() - if (usart_get_interrupt_source(USART2, USART_SR_TXE)) { - if (ringb_depth(&tx_ring) == 0) { - // turn off tx empty interrupts, nothing left to send - cdcacm_arch_txirq(0, 0); - ER_DPRINTF("OFF\n"); - // Turn on tx complete interrupts, for rs485 de - USART_CR1(USART2) |= USART_CR1_TCIE; - } else { - int c = ringb_get(&tx_ring); - usart_send(USART2, c); - } - } - // usbser-irq-txc? rs485 is auto on some devices, but can be emulated anyway - if (usart_get_interrupt_source(USART2, USART_SR_TC)) { - ER_DPRINTF("TC"); - // turn off the complete irqs, we're done now. - USART_CR1(USART2) &= ~USART_CR1_TCIE; - USART_SR(USART2) &= ~USART_SR_TC; - cdcacm_arch_pin(0, CDCACM_PIN_RS485DE, 0); - } - gpio_really(GPIOA, GPIO5, 0); -} - -void usb_cdcacm_setup_pre_arch(void) -{ - // Hack to reenumerate - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO12); - gpio_clear(GPIOA, GPIO12); - for (unsigned int i = 0; i < 800000; i++) { - __asm__("nop"); - } -} - -void usb_cdcacm_setup_post_arch(usbd_device *dev) -{ - (void)dev; -} - -void cdcacm_arch_pin(int port, enum cdcacm_pin pin, bool set) -{ - (void)port; // TODO if you want to handle multiple ports - switch (pin) { - case CDCACM_PIN_LED_TX: - gpio_really(LED_TX_PORT, LED_TX_PIN, set); - break; - case CDCACM_PIN_LED_RX: - gpio_really(LED_RX_PORT, LED_RX_PIN, set); - break; - case CDCACM_PIN_RS485DE: - gpio_really(RS485DE_PORT, RS485DE_PIN, set); - break; - default: - break; - } -} - -void cdcacm_arch_txirq(int port, bool set) { - (void)port; //FIXME if you make this multi port - if (set) { - usart_enable_tx_interrupt(USART2); - } else { - usart_disable_tx_interrupt(USART2); - } -} - -void cdcacm_arch_set_line_state(int port, uint8_t dtr, uint8_t rts) -{ - (void)port; // FIXME if you want multiple ports - (void) dtr; - (void) rts; - // LM4f has an implementation of this if you're keen -} - - - - -int main(void) -{ - rcc_clock_setup_in_hse_8mhz_out_72mhz(); - ER_DPRINTF("And we're alive!\n"); - /* Led */ - rcc_periph_clock_enable(RCC_GPIOC); - gpio_set_mode(LED_RX_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_RX_PIN); - // IRQ timing - rcc_periph_clock_enable(RCC_GPIOA); - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); - gpio_set_mode(RS485DE_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, RS485DE_PIN); - - usart_setup(); - - usb_cdcacm_setup_pre_arch(); - usbd_device *usbd_dev = usb_cdcacm_init(&st_usbfs_v1_usb_driver, - "stm32f103-generic"); - usb_cdcacm_setup_post_arch(usbd_dev); - - - ER_DPRINTF("Looping...\n"); - volatile int i = 0; - while (1) { - usbd_poll(usbd_dev); - usb_cdcacm_poll(usbd_dev); - } - -} - diff --git a/tests/usb-serial-rs485/main-stm32f4-disco.c b/tests/usb-serial-rs485/main-stm32f4-disco.c deleted file mode 100644 index ac3cdff..0000000 --- a/tests/usb-serial-rs485/main-stm32f4-disco.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2014 Karl Palsson - * - * 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 . - */ - -#include -#include -#include -#include - -#include -#include "syscfg.h" -#include "usb_cdcacm.h" -#include "ringb.h" -#include "trace.h" - -#define ER_DEBUG -#ifdef ER_DEBUG -#define ER_DPRINTF(fmt, ...) \ - do { printf(fmt, ## __VA_ARGS__); } while (0) -#else -#define ER_DPRINTF(fmt, ...) \ - do { } while (0) -#endif - -static inline void gpio_really(uint32_t port, uint16_t pin, const bool set) -{ - int shift = set ? 0 : 16; - GPIO_BSRR(port) = pin << shift; -} - -extern struct ringb rx_ring, tx_ring; -static void usart_setup(void) -{ - /* Enable the USART2 interrupt. */ - nvic_enable_irq(NVIC_USART2_IRQ); - - /* USART2 pins are on port A */ - rcc_periph_clock_enable(RCC_GPIOA); - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2 | GPIO3); - gpio_set_af(GPIOA, GPIO_AF7, GPIO2 | GPIO3); - - /* Enable clocks for USART2. */ - rcc_periph_clock_enable(RCC_USART2); - - /* Setup USART2 parameters. */ - usart_set_baudrate(USART2, 115200); - usart_set_databits(USART2, 8); - usart_set_stopbits(USART2, USART_STOPBITS_1); - usart_set_mode(USART2, USART_MODE_TX_RX); - usart_set_parity(USART2, USART_PARITY_NONE); - usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); - - /* Enable USART2 Receive interrupt. */ - usart_enable_rx_interrupt(USART2); - - /* Finally enable the USART. */ - usart_enable(USART2); -} - -void usart2_isr(void) -{ - gpio_really(GPIOA, GPIO5, 1); - // usbser-rxne() - /* Check if we were called because of RXNE. */ - if (usart_get_flag(USART2, USART_SR_RXNE)) { - gpio_set(LED_RX_PORT, LED_RX_PIN); - uint8_t c = usart_recv(USART2); - if (ringb_put(&rx_ring, c)) { - // good, - } else { - // fatal, you should always have drained by now. - // (when you've got it all ironed out, _actually_ - // just drop and count drops), but not yet... - ER_DPRINTF("rx buffer full\n"); - while(1); - } - gpio_clear(LED_RX_PORT, LED_RX_PIN); - } - // usbser-irq-txe() - if (usart_get_flag(USART2, USART_SR_TXE)) { - if (ringb_depth(&tx_ring) == 0) { - // turn off tx empty interrupts, nothing left to send - usart_disable_tx_interrupt(USART2); - ER_DPRINTF("OFF\n"); - // Turn on tx complete interrupts, for rs485 de -// USART_CR1(USART2) |= ~USART_CR1_TCIE; - } else { - int c = ringb_get(&tx_ring); - usart_send(USART2, c); - } - } - // usbser-irq-txc? rs485 is auto on some devices, but can be emulated anyway -// if (usart_get_flag(USART2, USART_SR_TC)) { -// ER_DPRINTF("TC"); -// // turn off the complete irqs, we're done now. -// USART_SR(USART2) &= ~USART_SR_TC; -// USART_CR1(USART2) &= ~USART_CR1_TCIE; -// gpio_clear(LED_TX_PORT, LED_TX_PIN); -// gpio_clear(RS485DE_PORT, RS485DE_PIN); -// } - gpio_really(GPIOA, GPIO5, 0); -} - -void usb_cdcacm_setup_pre_arch(void) -{ - rcc_periph_clock_enable(RCC_GPIOA); - rcc_periph_clock_enable(RCC_OTGFS); - - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, - GPIO9 | GPIO11 | GPIO12); - gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12); - -} - -void usb_cdcacm_setup_post_arch(usbd_device *dev) -{ - (void)dev; -} - - -void cdcacm_arch_pin(int port, enum cdcacm_pin pin, bool set) -{ - (void)port; // TODO if you want to handle multiple ports - switch (pin) { - case CDCACM_PIN_LED_TX: - gpio_really(LED_TX_PORT, LED_TX_PIN, set); - break; - case CDCACM_PIN_LED_RX: - gpio_really(LED_RX_PORT, LED_RX_PIN, set); - break; - case CDCACM_PIN_RS485DE: - gpio_really(RS485DE_PORT, RS485DE_PIN, set); - break; - default: - break; - } -} - -void cdcacm_arch_txirq(int port, bool set) { - (void)port; //FIXME if you make this multi port - if (set) { - usart_enable_tx_interrupt(USART2); - } else { - usart_disable_tx_interrupt(USART2); - } -} - -void cdcacm_arch_set_line_state(int port, uint8_t dtr, uint8_t rts) -{ - (void)port; // FIXME if you want multiple ports - (void) dtr; - (void) rts; - // LM4f has an implementation of this if you're keen -} - - -int main(void) -{ - rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); - ER_DPRINTF("And we're alive!\n"); - /* Leds and rs485 are on port D */ - rcc_periph_clock_enable(RCC_GPIOD); - gpio_mode_setup(LED_RX_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - LED_RX_PIN | LED_TX_PIN); - gpio_mode_setup(RS485DE_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - RS485DE_PIN); - - rcc_periph_clock_enable(RCC_GPIOA); - gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO5); - - usart_setup(); - usb_cdcacm_setup_pre_arch(); - usbd_device *usbd_dev = usb_cdcacm_init(&otgfs_usb_driver, "stm32f4-disco"); - usb_cdcacm_setup_post_arch(usbd_dev); - - ER_DPRINTF("Looping...\n"); - volatile int i = 0; - while (1) { - usbd_poll(usbd_dev); - usb_cdcacm_poll(usbd_dev); - } - -} - diff --git a/tests/usb-serial-rs485/ringb.c b/tests/usb-serial-rs485/ringb.c deleted file mode 100644 index 245325b..0000000 --- a/tests/usb-serial-rs485/ringb.c +++ /dev/null @@ -1,59 +0,0 @@ - -#include "ringb.h" -void ringb_init(struct ringb *ring, uint8_t *buf, int len) -{ - ring->buf_len = len; - ring->buf = buf; - ring->idx_r = 0; - ring->idx_w = 0; -} - -int ringb_get(struct ringb *ring) { -#if 1 - int rval; - if (ring->idx_r != ring->idx_w) { - rval = ring->buf[ring->idx_r]; - ring->idx_r = (ring->idx_r + 1) % ring->buf_len; - return rval; - } - return -1; -#else - if (((ring->idx_w - ring->idx_r) % ring->buf_len) >= 0) { - int rval = ring->buf[ring->idx_r]; - ring->idx_r = (ring->idx_r + 1) % ring->buf_len; - return rval; - } else { - return -1; - } -#endif -} - -bool ringb_put(struct ringb *ring, uint8_t c) { -#if 1 - unsigned int next = (ring->idx_w + 1) % ring->buf_len; - if (next != ring->idx_r) { - ring->buf[ring->idx_w] = c; - ring->idx_w = next; - return true; - } - return false; -#else - if (((ring->idx_w - ring->idx_r) % ring->buf_len) == 0) { - return false; - } - ring->buf[ring->idx_w] = c; - ring->idx_w = (ring->idx_w + 1) % ring->buf_len; - return true; -#endif - -} - - -void ringb_flush(struct ringb *ring) { - ring->idx_r = 0; - ring->idx_w = 0; -} - -int ringb_depth(struct ringb *ring) { - return ((unsigned int)(ring->idx_w - ring->idx_r) % ring->buf_len); -} \ No newline at end of file diff --git a/tests/usb-serial-rs485/ringb.h b/tests/usb-serial-rs485/ringb.h deleted file mode 100644 index c3d5356..0000000 --- a/tests/usb-serial-rs485/ringb.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Karl Palsson - * Considered to be released under your choice of: - * MIT/ISC/Apache2/BSD2Clause/GPLv2 - * If you're looking for elegant compact performance you've come to the wrong - * place hombre. - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -struct ringb { - volatile unsigned int idx_r; - volatile unsigned int idx_w; - uint8_t *buf; - int buf_len; -}; - -/** - * Load up a ring buffer. Always suceeds - * @param ring struct saving state, provided by the user - * @param buf where the data will be kept - * @param len size of buf in in elements. - */ -void ringb_init(struct ringb *ring, uint8_t *buf, int len); - -/** - * push data in - * @param ring - * @param c - * @return true if space was available - */ -bool ringb_put(struct ringb *ring, uint8_t c); - -/** - * pull data out - * @param ring - * @return -1 for no data, uint8_t range for valid. - */ -int ringb_get(struct ringb *ring); - -/** - * Toss data and reset to empty - * @param ring - */ -void ringb_flush(struct ringb *ring); - -int ringb_depth(struct ringb *ring); - - - -#ifdef __cplusplus -} -#endif diff --git a/tests/usb-serial-rs485/syscfg.h b/tests/usb-serial-rs485/syscfg.h deleted file mode 100644 index d643af1..0000000 --- a/tests/usb-serial-rs485/syscfg.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2014 Karl Palsson - * - * 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 . - */ - -#ifndef SYSCFG_H -#define SYSCFG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define STIMULUS_RING_DRAIN 2 -#define STIMULUS_RING_PUSH 3 -#define STIMULUS_TXC 4 -#define STIMULUS_TX 5 - -#if defined STM32F1 -#define LED_RX_PORT GPIOC -#define LED_RX_PIN GPIO13 -#define LED_TX_PORT GPIOC -#define LED_TX_PIN GPIO13 -#define RS485DE_PORT GPIOA -#define RS485DE_PIN GPIO8 -/* TODO: should really make a stm32f4discovery.h file... */ -#elif defined STM32F4 - -#define LED_RX_PORT GPIOD -#define LED_RX_PIN GPIO15 /* Blue, but you won't see this one much */ -#define LED_TX_PORT GPIOD -#define LED_TX_PIN GPIO13 /* orange */ -/* On stm32f4 discovery, this is actually another led... */ -#define RS485DE_PORT GPIOD -#define RS485DE_PIN GPIO14 /* red */ - -#define STREAM_USART2_TX 6 -#endif - - -#ifdef __cplusplus -} -#endif - -#endif /* SYSCFG_H */ - diff --git a/tests/usb-serial-rs485/usb_cdcacm-arch.c b/tests/usb-serial-rs485/usb_cdcacm-arch.c deleted file mode 100644 index e868861..0000000 --- a/tests/usb-serial-rs485/usb_cdcacm-arch.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2014 Karl Palsson - * - * 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 . - */ - -#include -#include -#include -#include -#include - -#include "usb_cdcacm.h" -#include "syscfg.h" -#include "ringb.h" - - - -int glue_set_line_coding_cb(uint32_t baud, uint8_t databits, - enum usb_cdc_line_coding_bParityType cdc_parity, - enum usb_cdc_line_coding_bCharFormat cdc_stopbits) -{ - int uart_parity; - int uart_stopbits; - - if (databits < 8 || databits > 9) { - return 0; - } - - /* Be careful here, ST counts parity as a data bit */ - switch (cdc_parity) { - case USB_CDC_NO_PARITY: - uart_parity = USART_PARITY_NONE; - break; - case USB_CDC_ODD_PARITY: - uart_parity = USART_PARITY_ODD; - databits++; - break; - case USB_CDC_EVEN_PARITY: - uart_parity = USART_PARITY_EVEN; - databits++; - break; - default: - return 0; - } - - switch (cdc_stopbits) { - case USB_CDC_1_STOP_BITS: - uart_stopbits = USART_STOPBITS_1; - break; - case USB_CDC_2_STOP_BITS: - uart_stopbits = USART_STOPBITS_2; - break; - default: - return 0; - } - - /* Disable the UART while we mess with its settings */ - usart_disable(USART2); - /* Set communication parameters */ - usart_set_baudrate(USART2, baud); - usart_set_databits(USART2, databits); - usart_set_parity(USART2, uart_parity); - usart_set_stopbits(USART2, uart_stopbits); - /* Back to work. */ - usart_enable(USART2); - - return 1; -} diff --git a/tests/usb-serial-rs485/usb_cdcacm.c b/tests/usb-serial-rs485/usb_cdcacm.c deleted file mode 100644 index 099c4ad..0000000 --- a/tests/usb-serial-rs485/usb_cdcacm.c +++ /dev/null @@ -1,363 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2010 Gareth McMullin - * Copyright (C) 2013 Alexandru Gagniuc - * - * 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 . - */ -/* - * This package is _meant_ to be platform independent, just a full - * cdc-acm impl, with callbacks - */ - -#include "usb_cdcacm.h" - -#include -#include -#include -#include -#include -// NOTHING ELSE! this file _does_ not know about part specifics! - -#include "syscfg.h" -#include "ringb.h" - -#define ER_DEBUG -#ifdef ER_DEBUG -#define ER_DPRINTF(fmt, ...) \ - do { printf(fmt, ## __VA_ARGS__); } while (0) -#else -#define ER_DPRINTF(fmt, ...) \ - do { } while (0) -#endif - - -static uint8_t usbd_control_buffer[128]; -static usbd_device *acm_dev; - -static const struct usb_device_descriptor dev = { - .bLength = USB_DT_DEVICE_SIZE, - .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = 0x2000, - .bDeviceClass = USB_CLASS_CDC, - .bDeviceSubClass = 0, - .bDeviceProtocol = 0, - .bMaxPacketSize0 = 64, - .idVendor = 0xc03e, - .idProduct = 0xb007, - .bcdDevice = 0x2000, - .iManufacturer = 1, - .iProduct = 2, - .iSerialNumber = 3, - .bNumConfigurations = 1, -}; - -/* - * This notification endpoint isn't implemented. According to CDC spec it's - * optional, but its absence causes a NULL pointer dereference in the - * Linux cdc_acm driver. - */ -static const struct usb_endpoint_descriptor comm_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x83, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 16, - .bInterval = 1, -}}; - -static const struct usb_endpoint_descriptor data_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x01, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = 64, - .bInterval = 1, -}, { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x82, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = 64, - .bInterval = 1, -}}; - -static const struct { - struct usb_cdc_header_descriptor header; - struct usb_cdc_call_management_descriptor call_mgmt; - struct usb_cdc_acm_descriptor acm; - struct usb_cdc_union_descriptor cdc_union; -} __attribute__ ((packed)) cdcacm_functional_descriptors = { - .header = { - .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_HEADER, - .bcdCDC = 0x0110, - }, - .call_mgmt = { - .bFunctionLength = - sizeof(struct usb_cdc_call_management_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, - .bmCapabilities = 0, - .bDataInterface = 1, - }, - .acm = { - .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_ACM, - .bmCapabilities = (1 << 1), - }, - .cdc_union = { - .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_UNION, - .bControlInterface = 0, - .bSubordinateInterface0 = 1, - } -}; - -static const struct usb_interface_descriptor comm_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 0, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_CDC, - .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, - .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, - .iInterface = 0, - - .endpoint = comm_endp, - - .extra = &cdcacm_functional_descriptors, - .extralen = sizeof(cdcacm_functional_descriptors) -}}; - -static const struct usb_interface_descriptor data_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 1, - .bAlternateSetting = 0, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_DATA, - .bInterfaceSubClass = 0, - .bInterfaceProtocol = 0, - .iInterface = 0, - - .endpoint = data_endp, -}}; - -static const struct usb_interface ifaces[] = {{ - .num_altsetting = 1, - .altsetting = comm_iface, -}, { - .num_altsetting = 1, - .altsetting = data_iface, -}}; - -static const struct usb_config_descriptor config = { - .bLength = USB_DT_CONFIGURATION_SIZE, - .bDescriptorType = USB_DT_CONFIGURATION, - .wTotalLength = 0, - .bNumInterfaces = 2, - .bConfigurationValue = 1, - .iConfiguration = 0, - .bmAttributes = 0x80, - .bMaxPower = 0x32, - - .interface = ifaces, -}; - -static char serial[] = "none"; -static const char *usb_strings[] = { - "libopencm3", - "usb_to_serial_cdcacm", - serial, - "DEMO", -}; - -struct ringb rx_ring; -static uint8_t rx_ring_data[64]; -struct ringb tx_ring; -static uint8_t tx_ring_data[128]; -bool nakked = false; - - -static int cdcacm_control_request(usbd_device *usbd_dev, - struct usb_setup_data *req, uint8_t **buf, - uint16_t *len, - void (**complete) (usbd_device *usbd_dev, - struct usb_setup_data * - req)) -{ - uint8_t dtr, rts; - - (void) complete; - (void) buf; - (void) usbd_dev; - - switch (req->bRequest) { - case USB_CDC_REQ_SET_CONTROL_LINE_STATE: - { - /* - * This Linux cdc_acm driver requires this to be implemented - * even though it's optional in the CDC spec, and we don't - * advertise it in the ACM functional descriptor. - */ - - dtr = (req->wValue & (1 << 0)) ? 1 : 0; - rts = (req->wValue & (1 << 1)) ? 1 : 0; - ER_DPRINTF("CTRLRQ:%d Set Line state: dtr:%d rts: %d\n", req->wIndex, dtr, rts); - - // FIXME - need to get port based on wIndex I believe? - cdcacm_arch_set_line_state(0, dtr, rts); - - return 1; - } - case USB_CDC_REQ_SET_LINE_CODING: - { - struct usb_cdc_line_coding *coding; - - if (*len < sizeof (struct usb_cdc_line_coding)) - return 0; - - coding = (struct usb_cdc_line_coding *) *buf; - ER_DPRINTF("CTRLRQ: line coding: %lu(%u:%u:%u)\n", coding->dwDTERate, - coding->bDataBits, coding->bParityType, coding->bCharFormat); - return glue_set_line_coding_cb(coding->dwDTERate, - coding->bDataBits, - coding->bParityType, - coding->bCharFormat); - } - } - return 0; -} - -static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) -{ - uint8_t buf[64]; - /* nak right now, we're not sure whether we'll be able to even process this!*/ - usbd_ep_nak_set(usbd_dev, ep, 1); - int len = usbd_ep_read_packet(usbd_dev, ep, buf, 64); - ER_DPRINTF("Hrx%db\n", len); - cdcacm_arch_pin(0, CDCACM_PIN_LED_TX, 1); - cdcacm_arch_pin(0, CDCACM_PIN_RS485DE, 1); - for (int x = 0; x < len; x++) { - if (!ringb_put(&tx_ring, buf[x])) { - // failed to process usb traffic properly. - // should _never_ happen, means we failed to nak in time. - // this is _never_recoverable beyond watchdog reset. - while(1); - } - // look up port to suart mapping which side? - cdcacm_arch_txirq(0, 1); - } - if (ringb_depth(&tx_ring) < 64) { - ER_DPRINTF("ACK\n"); - usbd_ep_nak_set(usbd_dev, ep, 0); - } else { - nakked = true; - } -} - -static void cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue) -{ - (void) wValue; - - usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, - cdcacm_data_rx_cb); - usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL); - usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); - - usbd_register_control_callback(usbd_dev, - USB_REQ_TYPE_CLASS | - USB_REQ_TYPE_INTERFACE, - USB_REQ_TYPE_TYPE | - USB_REQ_TYPE_RECIPIENT, - cdcacm_control_request); -} - -/* FIXME - need to report this! */ -void cdcacm_line_state_changed_cb(uint8_t linemask) -{ - const int size = sizeof (struct usb_cdc_notification) + 2; - uint8_t buf[size]; - - struct usb_cdc_notification *notify = (void *) buf; - notify->bmRequestType = 0xa1; - notify->bNotification = USB_CDC_NOTIFY_SERIAL_STATE; - notify->wValue = 0; - notify->wIndex = 1; - notify->wLength = 2; - uint16_t *data = (void *) &buf[sizeof (struct usb_cdc_notification)]; - *data = linemask; - - while (usbd_ep_write_packet(acm_dev, 0x83, buf, size) == size); -} - - -/* Y0, moron, nothing's stopping rx irqs from happening, have fun when you overflow temp buffer! */ -static void task_drain_rx(struct ringb *r) { - uint8_t zero_copy_is_for_losers[sizeof(rx_ring_data)]; - int zci = 0; - int c = ringb_get(r); - while (c >= 0) { - //trace_send8(STIMULUS_RING_DRAIN, c); - zero_copy_is_for_losers[zci++] = c; - c = ringb_get(r); - } - if (zci) { - //trace_send16(STIMULUS_RING_DRAIN, zci); - ER_DPRINTF("Drx %db\n", zci); - usbd_ep_write_packet(acm_dev, 0x82, zero_copy_is_for_losers, zci); - } -} - - -usbd_device * usb_cdcacm_init(const usbd_driver *driver, const char *userserial) -{ - ringb_init(&rx_ring, rx_ring_data, sizeof(rx_ring_data)); - ringb_init(&tx_ring, tx_ring_data, sizeof(tx_ring_data)); - if (userserial) { - usb_strings[2] = userserial; - } - - acm_dev = usbd_init(driver, &dev, &config, usb_strings, 4, - usbd_control_buffer, sizeof (usbd_control_buffer)); - usbd_register_set_config_callback(acm_dev, cdcacm_set_config); - return acm_dev; -} - - -void usb_cdcacm_poll(usbd_device *usbd_dev) // FIXME -drop to acm_dev internal -{ - // Originally, calling this every 50 times caused some rx character droppage, - // and every 500 times caused _none_. _probably_ needs to be tied to - // a timer and something like the current baud rate and the inter character time - static int i = 0; - if (i++ > 500) { - // hacktastic - if (ringb_depth(&tx_ring) < 64 && nakked) { - usbd_ep_nak_set(usbd_dev, 1, 0); - nakked = false; - } - - task_drain_rx(&rx_ring); - i = 0; - } - - -} \ No newline at end of file diff --git a/tests/usb-serial-rs485/usb_cdcacm.h b/tests/usb-serial-rs485/usb_cdcacm.h deleted file mode 100644 index d4e47e0..0000000 --- a/tests/usb-serial-rs485/usb_cdcacm.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2014 Karl Palsson - * - * 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 . - */ -/* - * This is the header file for a usb_cdcacm implmentation, usb_cdcacm.c is the - * platform independent portion, and usb_cdcacm-arch.c should be re-implemented - * for other platforms. - */ - -#ifndef USB_CDCACM_H -#define USB_CDCACM_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - - enum cdcacm_pin { - CDCACM_PIN_NONE, - CDCACM_PIN_LED_TX, - CDCACM_PIN_LED_RX, - CDCACM_PIN_RS485DE, - }; - - usbd_device * usb_cdcacm_init(const usbd_driver *driver, const char *userserial); - void usb_cdcacm_setup_pre_arch(void); - void usb_cdcacm_setup_post_arch(usbd_device *dev); - void usb_cdcacm_poll(usbd_device *usbd_dev); - void cdcacm_line_state_changed_cb(uint8_t linemask); - - /** - * Called by the cdcacm core to toggle pins as need be - * @param port which serial port, 0 normally - * @param pin logical pin - * @param set set or clear - */ - void cdcacm_arch_pin(int port, enum cdcacm_pin pin, bool set); - - /** - * enable the tx emmpty irq for the logical port - * @param port - * @param set - */ - void cdcacm_arch_txirq(int port, bool set); - - void cdcacm_arch_set_line_state(int port, uint8_t dtr, uint8_t rts); - - int glue_set_line_coding_cb(uint32_t baud, uint8_t databits, - enum usb_cdc_line_coding_bParityType cdc_parity, - enum usb_cdc_line_coding_bCharFormat cdc_stopbits); - -#ifdef __cplusplus -} -#endif - -#endif /* USB_CDCACM_H */ - -- cgit