Skip to content

Commit 4a6c6d5

Browse files
committed
stm32f469: Add utility code
1 parent 026824a commit 4a6c6d5

File tree

8 files changed

+438
-0
lines changed

8 files changed

+438
-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+
# 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+
OBJS = ../util/clock.o ../util/console.o
19+
20+
BINARY = main
21+
22+
LDSCRIPT = ../stm32f469-discovery.ld
23+
24+
include ../../Makefile.include
25+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Console Example
2+
---------------
3+
4+
These examples include some helper functions, one set are the
5+
clock setup for the board and the console function with has
6+
some basic support for sending strings to and from the debug
7+
part on the STM32F469-Discovery board.
8+
9+
The main function simply initializes the console for 115200
10+
baud and sets up a very simple interactive loop. Reset on
11+
control-C is enabled so when the example is running, if you
12+
hold the control key and C the board will reset and restart.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2013 Chuck McManis <[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+
/*
21+
* USART example (alternate console)
22+
*/
23+
24+
#include <stdint.h>
25+
#include <libopencm3/stm32/gpio.h>
26+
#include <libopencm3/stm32/rcc.h>
27+
#include <libopencm3/stm32/usart.h>
28+
#include "../util/clock.h"
29+
#include "../util/console.h"
30+
31+
/*
32+
* Set up the GPIO subsystem with an "Alternate Function"
33+
* on some of the pins, in this case connected to a
34+
* USART.
35+
*/
36+
int main(void)
37+
{
38+
char buf[128];
39+
int len;
40+
41+
clock_setup(); /* initialize our clock */
42+
43+
console_setup(115200);
44+
45+
/* At this point our console is ready to go so we can create our
46+
* simple application to run on it.
47+
*/
48+
console_puts("\nUART Demonstration Application\n");
49+
while (1) {
50+
console_puts("Enter a string: ");
51+
len = console_gets(buf, 128);
52+
if (len) {
53+
console_puts("\nYou entered : '");
54+
console_puts(buf);
55+
console_puts("'\n");
56+
} else {
57+
console_puts("\nNo string entered\n");
58+
}
59+
}
60+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Utility Functions
2+
-----------------
3+
4+
Not part of the library, these utility functions provide some
5+
helper functions for the examples that simplify things.
6+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2013 Chuck McManis <[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+
/*
21+
* Now this is just the clock setup code from systick-blink as it is the
22+
* transferrable part.
23+
*/
24+
25+
#include <libopencm3/stm32/rcc.h>
26+
#include <libopencm3/stm32/gpio.h>
27+
#include <libopencm3/cm3/nvic.h>
28+
#include <libopencm3/cm3/systick.h>
29+
30+
/* Common function descriptions */
31+
#include "../util/clock.h"
32+
33+
/* milliseconds since boot */
34+
static volatile uint32_t system_millis;
35+
/* millisecond count down when sleeping */
36+
static volatile uint32_t system_delay;
37+
38+
/* Called when systick fires */
39+
void sys_tick_handler(void)
40+
{
41+
system_millis++;
42+
if (system_delay != 0) {
43+
system_delay--;
44+
}
45+
}
46+
47+
/* simple sleep for delay milliseconds */
48+
void msleep(uint32_t delay)
49+
{
50+
system_delay = delay;
51+
while (system_delay > 0);
52+
}
53+
54+
/* Getter function for the current time */
55+
uint32_t mtime(void)
56+
{
57+
return system_millis;
58+
}
59+
60+
/*
61+
* clock_setup(void)
62+
*
63+
* This function sets up both the base board clock rate
64+
* and a 1khz "system tick" count. The SYSTICK counter is
65+
* a standard feature of the Cortex-M series.
66+
*/
67+
void clock_setup(void)
68+
{
69+
/* Base board frequency, set to 168Mhz */
70+
rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
71+
72+
/* clock rate / 168000 to get 1mS interrupt rate */
73+
systick_set_reload(168000);
74+
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
75+
systick_counter_enable();
76+
77+
/* this done last */
78+
systick_interrupt_enable();
79+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* This include file describes the functions exported by clock.c
3+
*/
4+
#ifndef __CLOCK_H
5+
#define __CLOCK_H
6+
7+
/*
8+
* Definitions for functions being abstracted out
9+
*/
10+
void msleep(uint32_t);
11+
uint32_t mtime(void);
12+
void clock_setup(void);
13+
14+
#endif /* generic header protector */
15+

0 commit comments

Comments
 (0)