Skip to content

Commit f560bc2

Browse files
author
brabo
authored
Merge pull request #6 from benjaminlevine/master
Merging basic L4 examples
2 parents 70fa56e + 6b84a27 commit f560bc2

File tree

8 files changed

+291
-0
lines changed

8 files changed

+291
-0
lines changed

examples/stm32/l4/Makefile.include

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
##
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+
LIBNAME = opencm3_stm32l4
22+
DEFS += -DSTM32L4
23+
24+
FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16
25+
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 $(FP_FLAGS)
26+
27+
################################################################################
28+
# OpenOCD specific variables
29+
30+
OOCD ?= openocd
31+
OOCD_INTERFACE ?= stlink-v2-1
32+
OOCD_BOARD ?= stm32l4discovery
33+
34+
################################################################################
35+
# Black Magic Probe specific variables
36+
# Set the BMP_PORT to a serial port and then BMP is used for flashing
37+
BMP_PORT ?=
38+
39+
################################################################################
40+
# texane/stlink specific variables
41+
#STLINK_PORT ?= :4242
42+
43+
44+
include ../../../../Makefile.rules
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
##
2+
## This file is part of the libopencm3 project.
3+
##
4+
## Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
## Copyright (C) 2016 Benjamin Levine <[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+
BINARY = button
22+
23+
LDSCRIPT = ../nucleo-l476rg.ld
24+
25+
include ../../Makefile.include
26+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# README
2+
3+
This example blinks the GREEN LED on the ST Nucleo STM32L476RG eval board.
4+
5+
When you press the 'USER' button, the blinking is faster.
6+
7+
## Board connections
8+
9+
*none required*
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 Stephen Caudle <[email protected]>
7+
* Copyright (C) 2016 Benjamin Levine <[email protected]>
8+
*
9+
* This library is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
#include <libopencm3/stm32/rcc.h>
24+
#include <libopencm3/stm32/gpio.h>
25+
26+
uint16_t exti_line_state;
27+
28+
/* Set STM32 to 48 MHz. */
29+
static void clock_setup(void)
30+
{
31+
rcc_clock_setup_pll(&rcc_clock_config[RCC_CLOCK_VRANGE1_HSI16_PLL_48MHZ]);
32+
}
33+
34+
static void gpio_setup(void)
35+
{
36+
/* Enable GPIOA clock. */
37+
rcc_periph_clock_enable(RCC_GPIOA);
38+
39+
/* Set GPIO5 (in GPIO port A) to 'output push-pull'. */
40+
gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO5);
41+
}
42+
43+
static void button_setup(void)
44+
{
45+
/* Enable GPIOC clock. */
46+
rcc_periph_clock_enable(RCC_GPIOC);
47+
48+
/* Set GPIO13 (in GPIO port C) to 'input open-drain'. */
49+
gpio_mode_setup(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO13);
50+
}
51+
52+
int main(void)
53+
{
54+
int i;
55+
56+
clock_setup();
57+
button_setup();
58+
gpio_setup();
59+
60+
/* Blink the LED (PA5) on the board. */
61+
while (1) {
62+
gpio_toggle(GPIOA, GPIO5);
63+
64+
/* Upon button press, blink more quickly. */
65+
exti_line_state = GPIOC_IDR;
66+
if ((exti_line_state & (1 << 13)) != 0) {
67+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
68+
__asm__("nop");
69+
}
70+
}
71+
72+
for (i = 0; i < 500000; i++) { /* Wait a bit. */
73+
__asm__("nop");
74+
}
75+
}
76+
77+
return 0;
78+
}
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 = ../nucleo-l476rg.ld
23+
24+
include ../../Makefile.include
25+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# README
2+
3+
This is the smallest-possible example program using libopencm3.
4+
5+
It's intended for the ST Nucleo-L476LG eval board. It should blink
6+
the green LED on the board.
7+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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) 2012 Karl Palsson <[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_AHB2ENR |= RCC_AHB2ENR_GPIOAEN;
30+
/* Using API functions: */
31+
rcc_periph_clock_enable(RCC_GPIOA);
32+
33+
/* Set GPIO5 (in GPIO port A) to 'output push-pull'. */
34+
/* Using API functions: */
35+
gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO5);
36+
}
37+
38+
int main(void)
39+
{
40+
int i;
41+
42+
gpio_setup();
43+
44+
/* Blink the LED (PA5) on the board. */
45+
while (1) {
46+
/* Manually: */
47+
// GPIOA_BSRR = (GPIO5 << 16); /* LED off */
48+
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
49+
// __asm__("nop");
50+
// GPIOB_BRR = GPIO5; /* LED on */
51+
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
52+
// __asm__("nop");
53+
54+
/* Using API functions gpio_set()/gpio_clear(): */
55+
// gpio_set(GPIOA, GPIO5); /* LED off */
56+
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
57+
// __asm__("nop");
58+
// gpio_clear(GPIOA, GPIO5); /* LED on */
59+
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
60+
// __asm__("nop");
61+
62+
/* Using API function gpio_toggle(): */
63+
gpio_toggle(GPIOA, GPIO5); /* LED on/off */
64+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
65+
__asm__("nop");
66+
}
67+
}
68+
69+
return 0;
70+
}
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 L476RG (STM32L476RG, 1024K flash, 96K RAM). */
22+
23+
/* Define memory regions. */
24+
MEMORY
25+
{
26+
rom (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
27+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 96K
28+
}
29+
30+
/* Include the common ld script. */
31+
INCLUDE libopencm3_stm32l4.ld
32+

0 commit comments

Comments
 (0)