Added fancyblink for lisa/m V2
This commit is contained in:
parent
c654b2199a
commit
1c5dfd9d22
25
examples/stm32/f1/lisa-m-2/fancyblink/Makefile
Normal file
25
examples/stm32/f1/lisa-m-2/fancyblink/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
##
|
||||||
|
## 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 <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = fancyblink
|
||||||
|
|
||||||
|
LDSCRIPT = ../lisa-m.ld
|
||||||
|
|
||||||
|
include ../../Makefile.include
|
||||||
|
|
148
examples/stm32/f1/lisa-m-2/fancyblink/fancyblink.c
Normal file
148
examples/stm32/f1/lisa-m-2/fancyblink/fancyblink.c
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
* Copyright (C) 2011 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
31
examples/stm32/f1/lisa-m-2/lisa-m.ld
Normal file
31
examples/stm32/f1/lisa-m-2/lisa-m.ld
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user