X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fstm-bringup%2Fbringup.c;h=30b442cdfd3948fa43e2f28a6af25e4ba3ca9c37;hp=b6fe458db895d7763e5d724d99deb745389eff6f;hb=7f46240dfc57164f0c1b0c4c4ed9695bca63860d;hpb=9279fd42793123784ce83ca151df6f4630487722 diff --git a/src/stm-bringup/bringup.c b/src/stm-bringup/bringup.c index b6fe458d..30b442cd 100644 --- a/src/stm-bringup/bringup.c +++ b/src/stm-bringup/bringup.c @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -250,13 +251,46 @@ serial_string(char *string) outbyte(c); } +volatile AO_TICK_TYPE 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 +307,7 @@ main (void) printf ("hello, "); delay(); stm_gpiob.odr = (1 << 6); - printf ("world\n"); + printf ("world %d\n", tick_count); delay(); } } @@ -285,22 +319,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, -};