summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2015-11-03 23:53:42 +0000
committerKarl Palsson <karlp@tweak.net.au>2016-03-04 00:43:21 +0000
commit19a85ae45beb97d5b260e80320e233f95c0e302b (patch)
treea4686cd846ae987a0e355ab7d2d047c9653982ca
parentc522c29dcab2be8c8ee629e22a3f632d8c614282 (diff)
downloadolsndot-19a85ae45beb97d5b260e80320e233f95c0e302b.tar.gz
olsndot-19a85ae45beb97d5b260e80320e233f95c0e302b.tar.bz2
olsndot-19a85ae45beb97d5b260e80320e233f95c0e302b.zip
f0 working (one fixme)
need scan mode upstream?
-rw-r--r--openocd/openocd.stm32f072-disco.cfg14
-rw-r--r--rules.stm32f0.mk9
-rw-r--r--shared/usart_stdio.c34
-rw-r--r--tests/adc-power/Makefile.stm32f072-disco19
-rw-r--r--tests/adc-power/adc-power.c6
-rw-r--r--tests/adc-power/main-stm32f072-disco.c67
6 files changed, 146 insertions, 3 deletions
diff --git a/openocd/openocd.stm32f072-disco.cfg b/openocd/openocd.stm32f072-disco.cfg
new file mode 100644
index 0000000..b16f969
--- /dev/null
+++ b/openocd/openocd.stm32f072-disco.cfg
@@ -0,0 +1,14 @@
+source [find interface/stlink-v2.cfg]
+set WORKAREASIZE 0x4000
+source [find target/stm32f0x.cfg]
+
+# serial of my f072 disco board.
+hla_serial "Q?o\x06PgHW#$\x16?"
+
+# no trace on cm0
+#tpiu config internal swodump.stm32f4disco.log uart off 168000000
+
+# 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/rules.stm32f0.mk b/rules.stm32f0.mk
new file mode 100644
index 0000000..bcd82be
--- /dev/null
+++ b/rules.stm32f0.mk
@@ -0,0 +1,9 @@
+LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f0/stm32f07xzb.ld
+OPENCM3_LIB = opencm3_stm32f0
+OPENCM3_DEFS = -DSTM32F0
+#FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16
+ARCH_FLAGS = -mthumb -mcpu=cortex-m0 $(FP_FLAGS)
+#OOCD_INTERFACE = stlink-v2
+#OOCD_TARGET = stm32f4x
+OOCD_FILE = openocd.stm32f072disco.cfg
+
diff --git a/shared/usart_stdio.c b/shared/usart_stdio.c
new file mode 100644
index 0000000..6a6866e
--- /dev/null
+++ b/shared/usart_stdio.c
@@ -0,0 +1,34 @@
+/*
+ * support for stdio output to a usart
+ * Karl Palsson, 2015 <karlp@tweak.net.au>
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <libopencm3/stm32/usart.h>
+
+#ifndef STDIO_USART
+#define STDIO_USART USART1
+#endif
+
+int _write(int file, char *ptr, int len);
+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(STDIO_USART, '\r');
+ }
+ usart_send_blocking(STDIO_USART, ptr[i]);
+ }
+ return i;
+ }
+ errno = EIO;
+ return -1;
+}
+
+
diff --git a/tests/adc-power/Makefile.stm32f072-disco b/tests/adc-power/Makefile.stm32f072-disco
new file mode 100644
index 0000000..99eade8
--- /dev/null
+++ b/tests/adc-power/Makefile.stm32f072-disco
@@ -0,0 +1,19 @@
+BOARD = stm32f072-disco
+PROJECT = adc-power-$(BOARD)
+BUILD_DIR = bin-$(BOARD)
+
+SHARED_DIR = ../../shared
+
+CFILES = main-$(BOARD).c
+CFILES += adc-power.c
+# No trace on cm0!
+#CFILES += trace.c trace_stdio.c
+CFILES += usart_stdio.c
+
+VPATH += $(SHARED_DIR)
+
+INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR))
+
+OPENCM3_DIR=../../libopencm3
+include ../../rules.stm32f0.mk
+include ../../rules.mk
diff --git a/tests/adc-power/adc-power.c b/tests/adc-power/adc-power.c
index 734e3af..c673666 100644
--- a/tests/adc-power/adc-power.c
+++ b/tests/adc-power/adc-power.c
@@ -22,7 +22,7 @@
// Still have some bad shit to deal with...
#if defined(STM32F0)
#define SEPARATE_ADC_SAMPLING 0
-#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_239DOT5
+#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_239DOT5 // 4usec or more for tempsensor
#elif defined(STM32F3)
#define SAMPLE_TIME_BASIC ADC_SMPR1_SMP_181DOT5CYC
#define SAMPLE_TIME_TEMP ADC_SMPR1_SMP_601DOT5CYC // 2.2usecs or more
@@ -67,7 +67,7 @@ void adc_power_init(void)
adc_enable_scan_mode(ADC1);
ADC_CR2 |= ADC_CR2_EOCS; // FIXME
#else
- adc_disable_scan_mode(ADC1);
+ // FIXME - f0! adc_disable_scan_mode(ADC1);
#endif
#endif
@@ -150,4 +150,4 @@ void adc_power_task_down()
adc_power_off(ADC1);
unsigned int td = TIM_CNT(TIMER);
printf("toff in: %u\n", td);
-} \ No newline at end of file
+}
diff --git a/tests/adc-power/main-stm32f072-disco.c b/tests/adc-power/main-stm32f072-disco.c
new file mode 100644
index 0000000..4a960e1
--- /dev/null
+++ b/tests/adc-power/main-stm32f072-disco.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2015 Karl Palsson <karlp@tweak.net.au>
+ */
+
+#include <libopencm3/cm3/nvic.h>
+#include <libopencm3/stm32/crs.h>
+#include <libopencm3/stm32/gpio.h>
+#include <libopencm3/stm32/rcc.h>
+#include <libopencm3/stm32/usart.h>
+
+#include <stdio.h>
+#include "adc-power.h"
+
+static
+void setup_usart(void)
+{
+ uint32_t dev = USART1;
+ rcc_periph_clock_enable(RCC_USART1);
+ rcc_periph_clock_enable(RCC_GPIOA);
+ gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
+ gpio_set_af(GPIOA, GPIO_AF1, GPIO9);
+
+ usart_set_baudrate(dev, 115200);
+ usart_set_databits(dev, 8);
+ usart_set_parity(dev, USART_PARITY_NONE);
+ usart_set_stopbits(dev, USART_CR2_STOP_1_0BIT);
+ usart_set_mode(dev, USART_MODE_TX);
+ usart_set_flow_control(dev, USART_FLOWCONTROL_NONE);
+
+ /* Finally enable the USART. */
+ usart_enable(dev);
+}
+
+int main(void)
+{
+ int i;
+ rcc_clock_setup_in_hsi48_out_48mhz();
+ setup_usart();
+
+ /* LED on for boot progress */
+ rcc_periph_clock_enable(RCC_GPIOC);
+ gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO7);
+ gpio_set(GPIOC, GPIO7);
+
+ printf("hi guys!\n");
+
+ rcc_periph_clock_enable(RCC_GPIOA);
+ gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
+ gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5);
+ adc_power_init();
+ while (1) {
+ adc_power_task_up();
+ gpio_toggle(GPIOC, GPIO7);
+
+ for (i = 0; i < 0x100000; i++) { /* Wait a bit. */
+ __asm__("NOP");
+ }
+ printf("tick...\n");
+ adc_power_task_down();
+ gpio_toggle(GPIOC, GPIO7);
+ for (i = 0; i < 0x100000; i++) { /* Wait a bit. */
+ __asm__("NOP");
+ }
+ }
+
+}
+