From 3e97f9a04a4b3ccfa8e29d711c9ee56b2aee8d55 Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Sun, 12 Feb 2012 02:00:22 -0800 Subject: [PATCH] Converted the whole test_led lisa example and it's dependencies to libopencm3. --- conf/Makefile.stm32 | 2 +- sw/airborne/arch/stm32/led_hw.h | 70 ++++++++++--------- .../arch/stm32/mcu_periph/sys_time_arch.c | 12 ++-- .../arch/stm32/mcu_periph/sys_time_arch.h | 4 +- sw/airborne/boards/lisa_m_1.0.h | 14 ++-- sw/airborne/lisa/test_led.c | 13 ++-- 6 files changed, 61 insertions(+), 54 deletions(-) diff --git a/conf/Makefile.stm32 b/conf/Makefile.stm32 index 0e8417a659..bc880c9e33 100644 --- a/conf/Makefile.stm32 +++ b/conf/Makefile.stm32 @@ -154,7 +154,7 @@ else LDFLAGS += -D__thumb2__ -T$(LDSCRIPT) -nostartfiles -L$(GCC_LIB_DIR) -O$(OPT) endif LDFLAGS += -Wl,-Map=$(OBJDIR)/$(TARGET).map,--cref,--gc-sections -LDLIBS += -lc -lm -lgcc -lcmsis -lstm32 -lopencm3_stm32f1 +LDLIBS += -lc -lm -lgcc -lopencm3_stm32f1 CPFLAGS = -j .isr_vector -j .text -j .data CPFLAGS_BIN = -Obinary diff --git a/sw/airborne/arch/stm32/led_hw.h b/sw/airborne/arch/stm32/led_hw.h index ca3285f2bc..08c3296959 100644 --- a/sw/airborne/arch/stm32/led_hw.h +++ b/sw/airborne/arch/stm32/led_hw.h @@ -24,8 +24,8 @@ #ifndef LED_HW_H #define LED_HW_H -#include -#include +#include +#include #include BOARD_CONFIG @@ -50,19 +50,19 @@ #define LED_AFIO_REMAP(i) _LED_AFIO_REMAP(LED_ ## i ## _AFIO_REMAP) /* set pin as output */ -#define LED_INIT(i) { \ - GPIO_InitTypeDef GPIO_InitStructure; \ - RCC_APB2PeriphClockCmd(LED_GPIO_CLK(i), ENABLE); \ - GPIO_InitStructure.GPIO_Pin = LED_GPIO_PIN(i); \ - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; \ - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; \ - GPIO_Init(LED_GPIO(i), &GPIO_InitStructure); \ - LED_AFIO_REMAP(i); \ - } +#define LED_INIT(i) { \ + rcc_peripheral_enable_clock(&RCC_APB2ENR, \ + LED_GPIO_CLK(i)); \ + gpio_set_mode(LED_GPIO(i), \ + GPIO_MODE_OUTPUT_50_MHZ, \ + GPIO_CNF_OUTPUT_PUSHPULL, \ + LED_GPIO_PIN(i)); \ + LED_AFIO_REMAP(i); \ + } -#define LED_ON(i) {LED_GPIO(i)->BRR = LED_GPIO_PIN(i);} -#define LED_OFF(i) { LED_GPIO(i)->BSRR = LED_GPIO_PIN(i);} -#define LED_TOGGLE(i) { LED_GPIO(i)->ODR ^= LED_GPIO_PIN(i);} +#define LED_ON(i) { GPIO_BRR(LED_GPIO(i)) = LED_GPIO_PIN(i);} +#define LED_OFF(i) { GPIO_BSRR(LED_GPIO(i)) = LED_GPIO_PIN(i);} +#define LED_TOGGLE(i) { GPIO_ODR(LED_GPIO(i)) ^= LED_GPIO_PIN(i);} #define LED_PERIODIC() {} @@ -80,17 +80,19 @@ extern uint8_t led_status[NB_LED]; /* PC15 led_data */ #define LED_INIT(_i) { \ - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); \ - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); \ - GPIO_InitTypeDef GPIO_InitStructure; \ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; \ - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; \ - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; \ - GPIO_Init(GPIOA, &GPIO_InitStructure); \ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; \ - GPIO_Init(GPIOC, &GPIO_InitStructure); \ - for(uint8_t i=0; iBSRR = GPIO_Pin_15; \ - else \ - GPIOC->BRR = GPIO_Pin_15; \ - GPIOA->BSRR = GPIO_Pin_8; /* clock rising edge */ \ - GPIOA->BRR = GPIO_Pin_8; /* clock falling edge */ \ - } \ - } + for (uint8_t cnt = 0; cnt < NB_LED; cnt++) { \ + if (led_status[cnt]) \ + GPIO_BSRR(GPIOC) = GPIO15; \ + else \ + GPIO_BRR(GPIOC) = GPIO15; \ + GPIO_BSRR(GPIOA) = GPIO8; /* clock rising edge */ \ + GPIO_BRR(GPIOA) = GPIO8; /* clock falling edge */ \ + } \ + } #endif /* LED_STP08 */ diff --git a/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.c b/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.c index 58c7165821..ebd1e9872a 100644 --- a/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.c +++ b/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.c @@ -28,6 +28,8 @@ #include "mcu_periph/sys_time.h" +#include "libopencm3/stm32/systick.h" + #ifdef SYS_TIME_LED #include "led.h" #endif @@ -38,11 +40,11 @@ void sys_time_arch_init( void ) { * The timer interrupt is activated on the transition from 1 to 0, * therefore it activates every n+1 clock ticks. */ - if (SysTick_Config(SYS_TIME_RESOLUTION_CPU_TICKS-1)) - while(1); /* if reload of value is impossible, go into endless loop */ + systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB); + systick_set_reload(SYS_TIME_RESOLUTION_CPU_TICKS-1); - /* Set SysTick handler priority */ - NVIC_SetPriority(SysTick_IRQn, 0x0); + systick_interrupt_enable(); + systick_counter_enable(); } @@ -51,7 +53,7 @@ void sys_time_arch_init( void ) { // 97 days at 512hz // 12 hours at 100khz // -void sys_tick_irq_handler(void) { +void sys_tick_handler(void) { sys_time.nb_tick++; sys_time.nb_sec_rem += SYS_TIME_RESOLUTION_CPU_TICKS; diff --git a/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.h b/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.h index 4550633116..91f76a31af 100644 --- a/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.h +++ b/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.h @@ -32,8 +32,8 @@ #include "mcu_periph/sys_time.h" -#include -#include +#include +#include #include "std.h" extern void sys_tick_irq_handler(void); diff --git a/sw/airborne/boards/lisa_m_1.0.h b/sw/airborne/boards/lisa_m_1.0.h index de64b20a41..9f1137d1c8 100644 --- a/sw/airborne/boards/lisa_m_1.0.h +++ b/sw/airborne/boards/lisa_m_1.0.h @@ -10,20 +10,20 @@ /* Onboard LEDs */ #define LED_1_BANK #define LED_1_GPIO GPIOB -#define LED_1_GPIO_CLK RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO -#define LED_1_GPIO_PIN GPIO_Pin_4 -#define LED_1_AFIO_REMAP GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE) +#define LED_1_GPIO_CLK RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN +#define LED_1_GPIO_PIN GPIO4 +#define LED_1_AFIO_REMAP AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST #define LED_2_BANK #define LED_2_GPIO GPIOC -#define LED_2_GPIO_CLK RCC_APB2Periph_GPIOC -#define LED_2_GPIO_PIN GPIO_Pin_5 +#define LED_2_GPIO_CLK RCC_APB2ENR_IOPCEN +#define LED_2_GPIO_PIN GPIO5 #define LED_2_AFIO_REMAP ((void)0) #define LED_3_BANK #define LED_3_GPIO GPIOC -#define LED_3_GPIO_CLK RCC_APB2Periph_GPIOC -#define LED_3_GPIO_PIN GPIO_Pin_2 +#define LED_3_GPIO_CLK RCC_APB2ENR_IOPCEN +#define LED_3_GPIO_PIN GPIO2 #define LED_3_AFIO_REMAP ((void)0) diff --git a/sw/airborne/lisa/test_led.c b/sw/airborne/lisa/test_led.c index f3d5d1269d..0c755c154d 100644 --- a/sw/airborne/lisa/test_led.c +++ b/sw/airborne/lisa/test_led.c @@ -21,14 +21,11 @@ * Boston, MA 02111-1307, USA. */ -#include -#include - #include BOARD_CONFIG #include "mcu.h" #include "led.h" -void Delay(__IO uint32_t nCount); +void Delay(volatile uint32_t nCount); void led_on(int i); void led_off(int i); @@ -103,7 +100,13 @@ int main(void) { return 0; } -void Delay(__IO uint32_t nCount) { +/* + * XXX: do we really need volatile here? + * + * Also we should probably use systime instead as it is being linked into this + * test anyways... + */ +void Delay(volatile uint32_t nCount) { for(; nCount != 0; nCount--); }