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.
This commit is contained in:
committed by
Karl Palsson
parent
849bdc8001
commit
0b9e7d0d5d
1
Makefile
1
Makefile
@@ -24,6 +24,7 @@ TARGETS := stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4 stm32/l0 stm32/l1
|
|||||||
TARGETS += lpc/lpc13xx lpc/lpc17xx #lpc/lpc43xx
|
TARGETS += lpc/lpc13xx lpc/lpc17xx #lpc/lpc43xx
|
||||||
TARGETS += tiva/lm3s tiva/lm4f
|
TARGETS += tiva/lm3s tiva/lm4f
|
||||||
TARGETS += efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
|
TARGETS += efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
|
||||||
|
TARGETS += vf6xx
|
||||||
|
|
||||||
# Be silent per default, but 'make V=1' will show all compiler calls.
|
# Be silent per default, but 'make V=1' will show all compiler calls.
|
||||||
ifneq ($(V),1)
|
ifneq ($(V),1)
|
||||||
|
|||||||
32
examples/vf6xx/colibri-vf61/Makefile.include
Normal file
32
examples/vf6xx/colibri-vf61/Makefile.include
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
## Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||||
|
## Copyright (C) 2011 Fergus Noble <fergusnoble@gmail.com>
|
||||||
|
## Copyright (C) 2014 Stefan Agner <stefan@agner.ch>
|
||||||
|
##
|
||||||
|
## This library is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This library is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU Lesser General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU Lesser General Public License
|
||||||
|
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
LIBNAME = opencm3_vf6xx
|
||||||
|
DEFS = -DVF6XX
|
||||||
|
|
||||||
|
FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||||
|
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 $(FP_FLAGS)
|
||||||
|
|
||||||
|
include ../../../Makefile.rules
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
38
examples/vf6xx/colibri-vf61/colibri-vf61.ld
Normal file
38
examples/vf6xx/colibri-vf61/colibri-vf61.ld
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
* Copyright (C) 2014 Stefan Agner <stefan@agner.ch>
|
||||||
|
*
|
||||||
|
* This library is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Linker script for Colibri VF61 (Vybrid VF610, use sysRAM0, 512KiB). */
|
||||||
|
|
||||||
|
/* Define memory regions. */
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Note: 0x1f000000 is an alias for code bus to the same memory
|
||||||
|
* located at 0x3f000000, hence start with the data section
|
||||||
|
* at an offset of 256KiB. One can define this section lenghts
|
||||||
|
* freely
|
||||||
|
*/
|
||||||
|
pc_ram (rwx) : ORIGIN = 0x1f000000, LENGTH = 256K
|
||||||
|
ps_ram (rwx) : ORIGIN = 0x3f040000, LENGTH = 256K
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Include the common ld script. */
|
||||||
|
INCLUDE libopencm3_vf6xx.ld
|
||||||
|
|
||||||
26
examples/vf6xx/colibri-vf61/uart/Makefile
Normal file
26
examples/vf6xx/colibri-vf61/uart/Makefile
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
## Copyright (C) 2014 Stefan Agner <stefan@agner.ch>
|
||||||
|
##
|
||||||
|
## This library is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This library is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU Lesser General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU Lesser General Public License
|
||||||
|
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = uart
|
||||||
|
|
||||||
|
LDSCRIPT = ../colibri-vf61.ld
|
||||||
|
|
||||||
|
include ../Makefile.include
|
||||||
|
|
||||||
73
examples/vf6xx/colibri-vf61/uart/uart.c
Normal file
73
examples/vf6xx/colibri-vf61/uart/uart.c
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
* Copyright (C) 2014 Stefan Agner <stefan@agner.ch>
|
||||||
|
*
|
||||||
|
* This library is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libopencm3/cm3/common.h>
|
||||||
|
#include <libopencm3/vf6xx/ccm.h>
|
||||||
|
#include <libopencm3/vf6xx/uart.h>
|
||||||
|
|
||||||
|
int _write(int file, char *ptr, int len);
|
||||||
|
|
||||||
|
int _write(int file, char *ptr, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (file == 1) {
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
uart_send_blocking(UART2, ptr[i]);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = EIO;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uart_init(void)
|
||||||
|
{
|
||||||
|
ccm_clock_gate_enable(CG9_UART2);
|
||||||
|
uart_enable(UART2);
|
||||||
|
uart_set_baudrate(UART2, 115200);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int counter = 0;
|
||||||
|
float fcounter = 0.0;
|
||||||
|
double dcounter = 0.0;
|
||||||
|
|
||||||
|
ccm_calculate_clocks();
|
||||||
|
uart_init();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write Hello World an integer, float and double all over
|
||||||
|
* again while incrementing the numbers.
|
||||||
|
*/
|
||||||
|
while (1) {
|
||||||
|
printf("Hello World! %i %f %f\r\n", counter, fcounter,
|
||||||
|
dcounter);
|
||||||
|
counter++;
|
||||||
|
fcounter += 0.01;
|
||||||
|
dcounter += 0.01;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user