f0 working (one fixme)
need scan mode upstream?
This commit is contained in:
parent
c522c29dca
commit
19a85ae45b
6 changed files with 146 additions and 3 deletions
14
openocd/openocd.stm32f072-disco.cfg
Normal file
14
openocd/openocd.stm32f072-disco.cfg
Normal file
|
|
@ -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
|
||||
|
||||
9
rules.stm32f0.mk
Normal file
9
rules.stm32f0.mk
Normal file
|
|
@ -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
|
||||
|
||||
34
shared/usart_stdio.c
Normal file
34
shared/usart_stdio.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
19
tests/adc-power/Makefile.stm32f072-disco
Normal file
19
tests/adc-power/Makefile.stm32f072-disco
Normal file
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
67
tests/adc-power/main-stm32f072-disco.c
Normal file
67
tests/adc-power/main-stm32f072-disco.c
Normal file
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue