Skip to content

Commit 8622a33

Browse files
committed
Add example blink project for nucleo-f401re board
1 parent 393fe8e commit 8622a33

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##
2+
## This file is part of the libopencm3 project.
3+
##
4+
## Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
##
6+
## This library is free software: you can redistribute it and/or modify
7+
## it under the terms of the GNU Lesser General Public License as published by
8+
## the Free Software Foundation, either version 3 of the License, or
9+
## (at your option) any later version.
10+
##
11+
## This library is distributed in the hope that it will be useful,
12+
## but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
## GNU Lesser General Public License for more details.
15+
##
16+
## You should have received a copy of the GNU Lesser General Public License
17+
## along with this library. If not, see <http://www.gnu.org/licenses/>.
18+
##
19+
20+
BINARY = blink
21+
22+
LDSCRIPT = ../nucleo-f401re.ld
23+
24+
include ../../Makefile.include
25+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# README
2+
3+
This is the smallest-possible example program using libopencm3.
4+
5+
It's intended for the ST Nucleo-F401RE eval board. It should blink
6+
the GREEN LED on the board.
7+
8+
## Board connections
9+
10+
*none required*
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
* Copyright (C) 2011 Stephen Caudle <[email protected]>
6+
* Copyright (c) 2015 Chuck McManis <[email protected]>
7+
*
8+
* This library is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
#include <libopencm3/stm32/rcc.h>
23+
#include <libopencm3/stm32/gpio.h>
24+
25+
static void gpio_setup(void)
26+
{
27+
/* Enable GPIOA clock. */
28+
/* Manually: */
29+
/*RCC_AHB1ENR |= RCC_AHB1ENR_IOPAEN; */
30+
/* Using API functions: */
31+
rcc_periph_clock_enable(RCC_GPIOA);
32+
33+
/* Set GPIO5 (in GPIO port A) to 'output push-pull'. */
34+
/* Manually: */
35+
/*GPIOA_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2)); */
36+
/*GPIOA_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4)); */
37+
/* Using API functions: */
38+
gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO5);
39+
}
40+
41+
int main(void)
42+
{
43+
int i;
44+
45+
gpio_setup();
46+
47+
/* Blink the LED (PC8) on the board. */
48+
while (1) {
49+
/* Manually: */
50+
/* GPIOA_BSRR = GPIO5; */ /* LED off */
51+
/* for (i = 0; i < 1000000; i++) */ /* Wait a bit. */
52+
/* __asm__("nop"); */
53+
/* GPIOA_BRR = GPIO5; */ /* LED on */
54+
/* for (i = 0; i < 1000000; i++) */ /* Wait a bit. */
55+
/* __asm__("nop"); */
56+
57+
/* Using API functions gpio_set()/gpio_clear(): */
58+
/* gpio_set(GPIOA, GPIO5); */ /* LED off */
59+
/* for (i = 0; i < 1000000; i++) */ /* Wait a bit. */
60+
/* __asm__("nop"); */
61+
/* gpio_clear(GPIOA, GPIO5); */ /* LED on */
62+
/* for (i = 0; i < 1000000; i++) */ /* Wait a bit. */
63+
/* __asm__("nop"); */
64+
65+
/* Using API function gpio_toggle(): */
66+
gpio_toggle(GPIOA, GPIO5); /* LED on/off */
67+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
68+
__asm__("nop");
69+
}
70+
}
71+
72+
return 0;
73+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
* Copyright (C) 2011 Stephen Caudle <[email protected]>
6+
*
7+
* This library is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/* Linker script for Nucleo F411RE (STM32F411RE, 512K flash, 128K RAM). */
22+
23+
/* Define memory regions. */
24+
MEMORY
25+
{
26+
rom (rx) : ORIGIN = 0x08000000, LENGTH = 512K
27+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 96K
28+
}
29+
30+
/* Include the common ld script. */
31+
INCLUDE libopencm3_stm32f4.ld
32+

0 commit comments

Comments
 (0)