Skip to content

Commit 0b9e7d0

Browse files
agnerskarlp
authored andcommitted
vf6xx: add UART example
The UART's baud rate is calculated using the current clock configuration from the clock module. This example makes use of the standard C library and writes the characters to the UART in blocking mode.
1 parent 849bdc8 commit 0b9e7d0

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ TARGETS := stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4 stm32/l0 stm32/l1
2424
TARGETS += lpc/lpc13xx lpc/lpc17xx #lpc/lpc43xx
2525
TARGETS += tiva/lm3s tiva/lm4f
2626
TARGETS += efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
27+
TARGETS += vf6xx
2728

2829
# Be silent per default, but 'make V=1' will show all compiler calls.
2930
ifneq ($(V),1)
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) 2010 Piotr Esden-Tempski <[email protected]>
6+
## Copyright (C) 2011 Fergus Noble <[email protected]>
7+
## Copyright (C) 2014 Stefan Agner <[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+
LIBNAME = opencm3_vf6xx
24+
DEFS = -DVF6XX
25+
26+
FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16
27+
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 $(FP_FLAGS)
28+
29+
include ../../../Makefile.rules
30+
31+
32+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
* Copyright (C) 2014 Stefan Agner <[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 Colibri VF61 (Vybrid VF610, use sysRAM0, 512KiB). */
22+
23+
/* Define memory regions. */
24+
MEMORY
25+
{
26+
/*
27+
* Note: 0x1f000000 is an alias for code bus to the same memory
28+
* located at 0x3f000000, hence start with the data section
29+
* at an offset of 256KiB. One can define this section lenghts
30+
* freely
31+
*/
32+
pc_ram (rwx) : ORIGIN = 0x1f000000, LENGTH = 256K
33+
ps_ram (rwx) : ORIGIN = 0x3f040000, LENGTH = 256K
34+
}
35+
36+
/* Include the common ld script. */
37+
INCLUDE libopencm3_vf6xx.ld
38+
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) 2014 Stefan Agner <[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 = uart
22+
23+
LDSCRIPT = ../colibri-vf61.ld
24+
25+
include ../Makefile.include
26+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
* Copyright (C) 2014 Stefan Agner <[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 <stdio.h>
22+
#include <errno.h>
23+
#include <libopencm3/cm3/common.h>
24+
#include <libopencm3/vf6xx/ccm.h>
25+
#include <libopencm3/vf6xx/uart.h>
26+
27+
int _write(int file, char *ptr, int len);
28+
29+
int _write(int file, char *ptr, int len)
30+
{
31+
int i;
32+
33+
if (file == 1) {
34+
for (i = 0; i < len; i++)
35+
uart_send_blocking(UART2, ptr[i]);
36+
return i;
37+
}
38+
39+
errno = EIO;
40+
return -1;
41+
}
42+
43+
static void uart_init(void)
44+
{
45+
ccm_clock_gate_enable(CG9_UART2);
46+
uart_enable(UART2);
47+
uart_set_baudrate(UART2, 115200);
48+
}
49+
50+
int main(void)
51+
{
52+
int counter = 0;
53+
float fcounter = 0.0;
54+
double dcounter = 0.0;
55+
56+
ccm_calculate_clocks();
57+
uart_init();
58+
59+
/*
60+
* Write Hello World an integer, float and double all over
61+
* again while incrementing the numbers.
62+
*/
63+
while (1) {
64+
printf("Hello World! %i %f %f\r\n", counter, fcounter,
65+
dcounter);
66+
counter++;
67+
fcounter += 0.01;
68+
dcounter += 0.01;
69+
}
70+
71+
return 0;
72+
}
73+

0 commit comments

Comments
 (0)