Add stm bringup timers and move most of the setup code to the stm dir
authorKeith Packard <keithp@keithp.com>
Sat, 17 Mar 2012 03:23:31 +0000 (20:23 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 29 Mar 2012 04:37:02 +0000 (21:37 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
src/stm-bringup/Makefile
src/stm-bringup/bringup.c

index 49966a4fd5a9c4a1a6486b04f6a08daca53c7875..1ba480ba9d401c19b9f2eace0fae53f311106122 100644 (file)
@@ -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
 
index b6fe458db895d7763e5d724d99deb745389eff6f..c5fad4a320b975e87051fd44ba50201fcd7f438c 100644 (file)
@@ -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,
-};