Skip to content

Commit 9959a4a

Browse files
committed
Add STM32F7 miniblink example
1 parent 070e5bb commit 9959a4a

File tree

5 files changed

+187
-0
lines changed

5 files changed

+187
-0
lines changed

examples/stm32/f7/Makefile.include

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
##
2+
## This file is part of the libopencm3 project.
3+
##
4+
## Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
## Copyright (C) 2010 Piotr Esden-Tempski <[email protected]>
6+
## Copyright (C) 2011 Fergus Noble <[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+
LIBNAME = opencm3_stm32f7
23+
DEFS = -DSTM32F7
24+
25+
FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv5-sp-d16
26+
ARCH_FLAGS = -mthumb -mcpu=cortex-m7 $(FP_FLAGS)
27+
28+
################################################################################
29+
# OpenOCD specific variables
30+
31+
OOCD ?= openocd
32+
OOCD_INTERFACE ?= stlink-v2
33+
OOCD_BOARD ?= stm32f7discovery
34+
35+
################################################################################
36+
# Black Magic Probe specific variables
37+
# Set the BMP_PORT to a serial port and then BMP is used for flashing
38+
BMP_PORT ?=
39+
40+
################################################################################
41+
# texane/stlink specific variables
42+
#STLINK_PORT ?= :4242
43+
44+
45+
include ../../../../Makefile.rules
46+
47+
48+
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 = miniblink
21+
22+
LDSCRIPT = ../stm32f7-discovery.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 STM32F4DISCOVERY eval board. It should blink
6+
the GREEN LED on the board.
7+
8+
## Board connections
9+
10+
*none required*
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
#include <libopencm3/stm32/rcc.h>
22+
#include <libopencm3/stm32/gpio.h>
23+
24+
static void gpio_setup(void)
25+
{
26+
/* Enable GPIOD clock. */
27+
/* Manually: */
28+
// RCC_AHB1ENR |= RCC_AHB1ENR_IOPDEN;
29+
/* Using API functions: */
30+
rcc_periph_clock_enable(RCC_GPIOI);
31+
32+
/* Set GPIO12 (in GPIO port D) to 'output push-pull'. */
33+
/* Manually: */
34+
// GPIOD_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2));
35+
// GPIOD_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4));
36+
/* Using API functions: */
37+
gpio_mode_setup(GPIOI, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO1);
38+
}
39+
40+
int main(void)
41+
{
42+
int i;
43+
44+
gpio_setup();
45+
46+
/* Blink the LED (PC8) on the board. */
47+
while (1) {
48+
/* Manually: */
49+
// GPIOD_BSRR = GPIO12; /* LED off */
50+
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
51+
// __asm__("nop");
52+
// GPIOD_BRR = GPIO12; /* LED on */
53+
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
54+
// __asm__("nop");
55+
56+
/* Using API functions gpio_set()/gpio_clear(): */
57+
// gpio_set(GPIOD, GPIO12); /* LED off */
58+
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
59+
// __asm__("nop");
60+
// gpio_clear(GPIOD, GPIO12); /* LED on */
61+
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
62+
// __asm__("nop");
63+
64+
/* Using API function gpio_toggle(): */
65+
gpio_toggle(GPIOI, GPIO1); /* LED on/off */
66+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
67+
__asm__("nop");
68+
}
69+
}
70+
71+
return 0;
72+
}
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 ST STM32F4DISCOVERY (STM32F407VG, 1024K flash, 128K RAM). */
22+
23+
/* Define memory regions. */
24+
MEMORY
25+
{
26+
rom (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
27+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 240K
28+
}
29+
30+
/* Include the common ld script. */
31+
INCLUDE libopencm3_stm32f7.ld
32+

0 commit comments

Comments
 (0)