Skip to content

Commit 71ea475

Browse files
author
brabo
authored
Merge pull request #9 from ChuckM/469disco
469disco
2 parents a229e57 + 2d43df4 commit 71ea475

File tree

29 files changed

+1408
-0
lines changed

29 files changed

+1408
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Examples for the STM32F469-Discovery board
2+
------------------------------------------
3+
4+
This directory contains various examples which use libopencm3 and run on
5+
the [ST Micro STM32F469-Discovery][disco] board. This board has a number
6+
of on board peripherals such as a MicroSD card slot, USB OTG connector,
7+
MEMS microphones, 800 x 450 touch screen graphics, and four user LEDs.
8+
9+
Additionally the board is loaded with the ST/Link V2.1-1 software which is
10+
[mBed][] compatible. That means it shows up as a debug device, a disk device,
11+
and a serial port on the host machine. The examples showing use of the serial
12+
port configure this port so that additional hardware is not needed.
13+
14+
[disco]: http://www.st.com/web/catalog/tools/FM116/CL1620/SC959/SS1532/LN1848/PF262395
15+
[mBed]: http://mbed.org/
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_fancy
21+
22+
LDSCRIPT = ../stm32f469-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 STM32F469IDISCOVERY eval board. It should blink
6+
the LEDs on the board.
7+
8+
## Board connections
9+
10+
*none required*
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 Damjan Marion <[email protected]>
6+
* Copyright (C) 2011 Mark Panajotovic <[email protected]>
7+
* Copyright (C) 2015 Piotr Esden-Tempski <[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+
/* Set STM32 to 168 MHz. */
27+
static void clock_setup(void)
28+
{
29+
rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
30+
31+
/* Enable GPIOD, GPIOG, and GPIOK clock. */
32+
rcc_periph_clock_enable(RCC_GPIOD);
33+
rcc_periph_clock_enable(RCC_GPIOG);
34+
rcc_periph_clock_enable(RCC_GPIOK);
35+
}
36+
37+
static void gpio_setup(void)
38+
{
39+
/* Set GPIO6 (in GPIO port G) to 'output push-pull'. */
40+
gpio_mode_setup(GPIOG, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO6);
41+
/* Set GPIO4 and GPIO5 (in GPIO port D) to 'output push-pull'. */
42+
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO4 | GPIO5);
43+
/* Set GPIO3 (in GPIO port K) to 'output push-pull'. */
44+
gpio_mode_setup(GPIOK, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3);
45+
}
46+
47+
int main(void)
48+
{
49+
int i;
50+
51+
clock_setup();
52+
gpio_setup();
53+
54+
/* Set two LEDs for wigwag effect when toggling. */
55+
gpio_set(GPIOG, GPIO6);
56+
gpio_set(GPIOK, GPIO3);
57+
58+
/* Blink the LEDs (PG13 and PG14) on the board. */
59+
while (1) {
60+
/* Toggle LEDs. */
61+
gpio_toggle(GPIOG, GPIO6);
62+
gpio_toggle(GPIOD, GPIO4 | GPIO5);
63+
gpio_toggle(GPIOK, GPIO3);
64+
for (i = 0; i < 6000000; i++) { /* Wait a bit. */
65+
__asm__("nop");
66+
}
67+
}
68+
69+
return 0;
70+
}
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_minimal
21+
22+
LDSCRIPT = ../stm32f469-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 STM32F469IDISCOVERY eval board. It should blink
6+
the GREEN LED on the board.
7+
8+
## Board connections
9+
10+
*none required*
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 Piotr Esden-Tempski <[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 GPIOD clock. */
28+
/* Manually: */
29+
/* RCC_AHB1ENR |= RCC_AHB1ENR_IOPGEN; */
30+
/* Using API functions: */
31+
rcc_periph_clock_enable(RCC_GPIOG);
32+
33+
/* Set GPIO13 (in GPIO port G) to 'output push-pull'. */
34+
/* Manually: */
35+
/* GPIOG_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << 2); */
36+
/* GPIOG_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << 2); */
37+
/* Using API functions: */
38+
gpio_mode_setup(GPIOG, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO6);
39+
}
40+
41+
int main(void)
42+
{
43+
int i;
44+
45+
gpio_setup();
46+
47+
/* Blink the LED (PG13) on the board. */
48+
while (1) {
49+
/* Manually: */
50+
#if 0
51+
GPIOG_BSRR = GPIO13; /* LED off */
52+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
53+
__asm__("nop");
54+
}
55+
GPIOG_BRR = GPIO13; /* LED on */
56+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
57+
__asm__("nop");
58+
}
59+
#endif
60+
61+
/* Using API functions gpio_set()/gpio_clear(): */
62+
#if 0
63+
gpio_set(GPIOG, GPIO13); /* LED off */
64+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
65+
__asm__("nop");
66+
}
67+
gpio_clear(GPIOG, GPIO13); /* LED on */
68+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
69+
__asm__("nop");
70+
}
71+
#endif
72+
73+
/* Using API function gpio_toggle(): */
74+
gpio_toggle(GPIOG, GPIO6); /* LED on/off */
75+
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
76+
__asm__("nop");
77+
}
78+
}
79+
80+
return 0;
81+
}
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_systick
21+
22+
LDSCRIPT = ../stm32f469-discovery.ld
23+
24+
include ../../Makefile.include
25+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# README
2+
3+
This example is the similar to blink\_fancy except that it uses the
4+
systick timer to generate time accurate delays. Shows how to set
5+
up the systick timer to create an interrupt every millisecond and
6+
how to write a delay routine (msleep) that can then delay for a
7+
specific number of milliseconds.
8+
9+
## Board connections
10+
11+
*none required*
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
* Copyright (C) 2011 Damjan Marion <[email protected]>
6+
* Copyright (C) 2011 Mark Panajotovic <[email protected]>
7+
* Copyright (C) 2013 Chuck McManis <[email protected]>
8+
* Copyright (C) 2015 Piotr Esden-Tempski <[email protected]>
9+
*
10+
* This library is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This library is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Lesser General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Lesser General Public License
21+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
24+
/* This version derived from fancy blink */
25+
26+
#include <libopencm3/stm32/rcc.h>
27+
#include <libopencm3/stm32/gpio.h>
28+
#include <libopencm3/cm3/nvic.h>
29+
#include <libopencm3/cm3/systick.h>
30+
31+
/* monotonically increasing number of milliseconds from reset
32+
* overflows every 49 days if you're wondering
33+
*/
34+
volatile uint32_t system_millis;
35+
36+
/* Called when systick fires */
37+
void sys_tick_handler(void)
38+
{
39+
system_millis++;
40+
}
41+
42+
/* sleep for delay milliseconds */
43+
static void msleep(uint32_t delay)
44+
{
45+
uint32_t wake = system_millis + delay;
46+
while (wake > system_millis);
47+
}
48+
49+
/*
50+
* systick_setup(void)
51+
*
52+
* This function sets up the 1khz "system tick" count. The SYSTICK counter is a
53+
* standard feature of the Cortex-M series.
54+
*/
55+
static void systick_setup(void)
56+
{
57+
/* clock rate / 1000 to get 1mS interrupt rate */
58+
systick_set_reload(168000);
59+
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
60+
systick_counter_enable();
61+
/* this done last */
62+
systick_interrupt_enable();
63+
}
64+
65+
/* Set STM32 system clock to 168 MHz. */
66+
static void clock_setup(void)
67+
{
68+
rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
69+
70+
/* Enable GPIOD clock. */
71+
rcc_periph_clock_enable(RCC_GPIOD);
72+
}
73+
74+
static void gpio_setup(void)
75+
{
76+
/* Set GPIO4-5 (in GPIO port D) to 'output push-pull'. */
77+
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
78+
GPIO4 | GPIO5);
79+
}
80+
81+
int main(void)
82+
{
83+
clock_setup();
84+
gpio_setup();
85+
systick_setup();
86+
87+
/* Set two LEDs for wigwag effect when toggling. */
88+
gpio_set(GPIOD, GPIO4);
89+
90+
/* Blink the LEDs (PG13 and PG14) on the board. */
91+
while (1) {
92+
gpio_toggle(GPIOD, GPIO4 | GPIO5);
93+
msleep(100);
94+
}
95+
96+
return 0;
97+
}

0 commit comments

Comments
 (0)