Skip to content

Commit ed20591

Browse files
author
brabo
authored
Merge pull request #12 from hyves42/master
Add example blink project for nucleo-f401re board
2 parents 67caf31 + dd61fe6 commit ed20591

File tree

4 files changed

+131
-0
lines changed

4 files changed

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

0 commit comments

Comments
 (0)