From 1c5dfd9d224c5baa259edafeaa130b4094dbde2c Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Tue, 21 Feb 2012 16:12:29 -0800 Subject: Added fancyblink for lisa/m V2 --- examples/stm32/f1/lisa-m-2/fancyblink/Makefile | 25 ++++ examples/stm32/f1/lisa-m-2/fancyblink/fancyblink.c | 148 +++++++++++++++++++++ examples/stm32/f1/lisa-m-2/lisa-m.ld | 31 +++++ 3 files changed, 204 insertions(+) create mode 100644 examples/stm32/f1/lisa-m-2/fancyblink/Makefile create mode 100644 examples/stm32/f1/lisa-m-2/fancyblink/fancyblink.c create mode 100644 examples/stm32/f1/lisa-m-2/lisa-m.ld (limited to 'examples/stm32/f1/lisa-m-2') diff --git a/examples/stm32/f1/lisa-m-2/fancyblink/Makefile b/examples/stm32/f1/lisa-m-2/fancyblink/Makefile new file mode 100644 index 0000000..52f5d95 --- /dev/null +++ b/examples/stm32/f1/lisa-m-2/fancyblink/Makefile @@ -0,0 +1,25 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2009 Uwe Hermann +## +## 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, either version 3 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 +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . +## + +BINARY = fancyblink + +LDSCRIPT = ../lisa-m.ld + +include ../../Makefile.include + diff --git a/examples/stm32/f1/lisa-m-2/fancyblink/fancyblink.c b/examples/stm32/f1/lisa-m-2/fancyblink/fancyblink.c new file mode 100644 index 0000000..730850d --- /dev/null +++ b/examples/stm32/f1/lisa-m-2/fancyblink/fancyblink.c @@ -0,0 +1,148 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2009 Uwe Hermann + * Copyright (C) 2011 Piotr Esden-Tempski + * + * 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, either version 3 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +/* Set STM32 to 72 MHz. */ +void clock_setup(void) +{ + rcc_clock_setup_in_hse_12mhz_out_72mhz(); + + /* Enable GPIOA, GPIOB, GPIOC, and AFIO clocks. */ + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); +} + +void gpio_setup(void) +{ + /* LED1 */ + /* Set GPIO8 (in GPIO port A) to 'output push-pull'. */ + gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); + + /* LED2 */ + /* Set GPIO15 (in GPIO port C) to 'output push-pull'. */ + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); + + /* JTAG_TRST */ + /* Set GPIO4 (in GPIO port B) to 'output push-pull'. */ + gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO4); + + AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST; + + /* ADC4 */ + /* Set GPIO5 (in GPIO port C) to 'output push-pull'. */ + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); + + /* ADC6 */ + /* Set GPIO2 (in GPIO port C) to 'output push-pull'. */ + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO2); + + /* Preconfigure the LEDs. */ + gpio_set(GPIOA, GPIO8); + gpio_set(GPIOC, GPIO15); + gpio_set(GPIOB, GPIO4); + gpio_set(GPIOC, GPIO5); + gpio_set(GPIOC, GPIO2); +} + +void led_set(int id, int on) +{ + if (on) { + switch (id) { + case 0: + gpio_clear(GPIOA, GPIO8); /* LED1 On */ + break; + case 1: + gpio_clear(GPIOB, GPIO4); /* JTAG_TRST On */ + break; + case 2: + gpio_clear(GPIOC, GPIO2); /* ADC6 On */ + break; + case 3: + gpio_clear(GPIOC, GPIO5); /* ADC4 On */ + break; + case 4: + gpio_clear(GPIOC, GPIO15); /* LED2 On */ + break; + } + } else { + switch (id) { + case 0: + gpio_set(GPIOA, GPIO8); /* LED1 On */ + break; + case 1: + gpio_set(GPIOB, GPIO4); /* JTAG_TRST On */ + break; + case 2: + gpio_set(GPIOC, GPIO2); /* ADC6 On */ + break; + case 3: + gpio_set(GPIOC, GPIO5); /* ADC4 On */ + break; + case 4: + gpio_set(GPIOC, GPIO15); /* LED2 On */ + break; + } + } +} + +void led_advance(void) +{ + static int state = 0; + + if (state < 5) { + led_set(state, 1); + } else if (state < 10) { + led_set(state - 5, 0); + } else if (state < 15) { + led_set(14 - state, 1); + } else if (state < 20) { + led_set(19 - state, 0); + } + + state++; + if(state == 20) state = 0; + +} + +int main(void) +{ + int i; + + clock_setup(); + gpio_setup(); + + /* Blink the LEDs (PC13 and PB4) on the board. */ + while (1) { + led_advance(); + for (i = 0; i < 800000; i++) /* Wait a bit. */ + __asm__("nop"); + } + + return 0; +} diff --git a/examples/stm32/f1/lisa-m-2/lisa-m.ld b/examples/stm32/f1/lisa-m-2/lisa-m.ld new file mode 100644 index 0000000..5630c9b --- /dev/null +++ b/examples/stm32/f1/lisa-m-2/lisa-m.ld @@ -0,0 +1,31 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2009 Uwe Hermann + * + * 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, either version 3 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Linker script for Lisa-M (STM32F103RBT6, 128K flash, 20K RAM). */ + +/* Define memory regions. */ +MEMORY +{ + rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K +} + +/* Include the common ld script. */ +INCLUDE libopencm3_stm32f1.ld + -- cgit v1.2.3