From b8100ea5042013bb4eed67907b4e9d4e5c196df2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 16 Mar 2012 20:23:31 -0700 Subject: [PATCH] Add stm bringup timers and move most of the setup code to the stm dir Signed-off-by: Keith Packard --- src/stm-bringup/Makefile | 33 ++++++++++++++--------- src/stm-bringup/bringup.c | 56 ++++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/stm-bringup/Makefile b/src/stm-bringup/Makefile index 49966a4f..1ba480ba 100644 --- a/src/stm-bringup/Makefile +++ b/src/stm-bringup/Makefile @@ -1,34 +1,41 @@ +vpath % ..:../core:../product:../drivers:../stm +vpath ao-make-product.5c ../util + +ifndef VERSION +include ../Version +endif + CC=arm-none-eabi-gcc OBJCOPY=arm-none-eabi-objcopy -C_LIB=/local/src/pdclib/pdclib.a -C_INC=-I/local/src/pdclib/includes -I/local/src/pdclib/internals +PDCLIB=/home/keithp/sat +C_LIB=$(PDCLIB)/lib/pdclib.a +C_INC=-I$(PDCLIB)/include -DEF_CFLAGS=-g -std=gnu99 -O0 -mlittle-endian -mthumb -ffreestanding -nostdlib -I../../src/stm $(C_INC) +DEF_CFLAGS=-g -std=gnu99 -Os -mlittle-endian -mthumb -ffreestanding -nostdlib -I../../src/stm $(C_INC) # to run from SRAM -LD_FLAGS_RAM=-Wl,-Taltos-ram.ld -LD_FLAGS=-Wl,-Taltos.ld +LD_FLAGS_RAM=-L../stm -Wl,-Taltos-ram.ld +LD_FLAGS=-L../stm -Wl,-Taltos.ld CFLAGS=$(DEF_CFLAGS) -mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY -OBJS=bringup.o +SRC=bringup.c ao_interrupt.c +OBJ=$(SRC:.c=.o) all: bringup-ram.elf bringup.elf %.bin: %.elf $(OBJCOPY) -O binary $^ $@ -bringup.elf: $(OBJS) $(C_LIB) altos.ld - $(CC) $(CFLAGS) $(LD_FLAGS) -o $@ $(OBJS) $(C_LIB) -lgcc - -bringup-ram.elf: $(OBJS) $(C_LIB) altos-ram.ld - $(CC) $(CFLAGS) $(LD_FLAGS_RAM) -o $@ $(OBJS) $(C_LIB) -lgcc +bringup.elf: $(OBJ) $(C_LIB) altos.ld + $(CC) $(CFLAGS) $(LD_FLAGS) -o $@ $(OBJ) $(C_LIB) -lgcc -bringup.o: bringup.c - $(CC) -c $(CFLAGS) bringup.c +bringup-ram.elf: $(OBJ) $(C_LIB) altos-ram.ld + $(CC) $(CFLAGS) $(LD_FLAGS_RAM) -o $@ $(OBJ) $(C_LIB) -lgcc clean: + rm -f *.o rm -rf *.elf rm -rf *.bin diff --git a/src/stm-bringup/bringup.c b/src/stm-bringup/bringup.c index b6fe458d..c5fad4a3 100644 --- a/src/stm-bringup/bringup.c +++ b/src/stm-bringup/bringup.c @@ -250,13 +250,46 @@ serial_string(char *string) outbyte(c); } +volatile uint16_t tick_count; + +void +stm_tim6_isr(void) +{ + if (stm_tim6.sr & (1 << STM_TIM67_SR_UIF)) { + stm_tim6.sr = 0; + ++tick_count; + } +} + +#define TIMER_10kHz (STM_APB1 / 10000) + void set_timer6(void) { + stm_nvic_set_enable(STM_ISR_TIM6_POS); + stm_nvic_set_priority(STM_ISR_TIM6_POS, 1); + /* Turn on timer 6 */ stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_TIM6EN); - + stm_tim6.psc = TIMER_10kHz; + stm_tim6.arr = 100; + stm_tim6.cnt = 0; + + /* Enable update interrupt */ + stm_tim6.dier = (1 << STM_TIM67_DIER_UIE); + + /* Poke timer to reload values */ + stm_tim6.egr |= (1 << STM_TIM67_EGR_UG); + + stm_tim6.cr2 = (STM_TIM67_CR2_MMS_RESET << STM_TIM67_CR2_MMS); + + /* And turn it on */ + stm_tim6.cr1 = ((0 << STM_TIM67_CR1_ARPE) | + (0 << STM_TIM67_CR1_OPM) | + (1 << STM_TIM67_CR1_URS) | + (0 << STM_TIM67_CR1_UDIS) | + (1 << STM_TIM67_CR1_CEN)); } void @@ -273,7 +306,7 @@ main (void) printf ("hello, "); delay(); stm_gpiob.odr = (1 << 6); - printf ("world\n"); + printf ("world %d\n", tick_count); delay(); } } @@ -285,22 +318,3 @@ delay(void) for (i = 0; i < 1000000; i++) __asm__ __volatile__ ("nop\n\t":::"memory"); } - -static int x = 7; - -extern char __stack__; -extern char __text_start__, __text_end__; -extern char __data_start__, __data_end__; -extern char __bss_start__, __bss_end__; - -void start(void) { - memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__); - memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__); - main(); -} - -__attribute__ ((section(".interrupt"))) -static const void *interrupt[] = { - &__stack__, - start, -}; -- 2.30.2