From 1a160d794be0f67410f8e1bf3c559ad8aa42210e Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Wed, 8 May 2013 03:17:43 -0500 Subject: [PATCH] lm4f: Add basic UART echo example Nothing fancy, just a demonstration of the blocking send and recieve. Also update libopencm3 submodule to include the lm4f UART API. Signed-off-by: Alexandru Gagniuc --- .../uart_echo_simple/Makefile | 25 +++++++ .../uart_echo_simple/README | 14 ++++ .../uart_echo_simple/uart_echo_simple.c | 69 +++++++++++++++++++ libopencm3 | 2 +- 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/Makefile create mode 100644 examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/README create mode 100644 examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/uart_echo_simple.c diff --git a/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/Makefile b/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/Makefile new file mode 100644 index 0000000..1e1c4b4 --- /dev/null +++ b/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/Makefile @@ -0,0 +1,25 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2012 Alexandru Gagniuc +## +## 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 . +## + +BINARY = uart_echo_simple + +LDSCRIPT = ../ek-lm4f120xl.ld + +include ../../Makefile.include + diff --git a/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/README b/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/README new file mode 100644 index 0000000..e47dbcd --- /dev/null +++ b/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/README @@ -0,0 +1,14 @@ +------------------------------------------------------------------------------ +README +------------------------------------------------------------------------------ + +This example demonstrates the ease of setting up the UART with libopencm3. +Basic UART echo is achieved by using blocking reads and writes. The UART is set +up as 921600-8N1. +PA0 is the Rx pin, and PA1 is the Tx pin (from the LM4F perspective). These +pins are connected to the CDCACM interface on the debug chip, so no hardware is +necessary to test this example. Just connect the debug USB cable and use a +terminal program to open the ACM port with 921600-8N1. + +For example: +$ picocom /dev/ttyACM0 -b921600 diff --git a/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/uart_echo_simple.c b/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/uart_echo_simple.c new file mode 100644 index 0000000..61cbc22 --- /dev/null +++ b/examples/lm4f/stellaris-ek-lm4f120xl/uart_echo_simple/uart_echo_simple.c @@ -0,0 +1,69 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2011 Gareth McMullin + * Copyright (C) 2012 Alexandru Gagniuc + * + * 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 . + */ + +#include +#include +#include + +static void uart_setup(void) +{ + u32 pins; + /* Enable GPIOA in run mode. */ + periph_clock_enable(RCC_GPIOA); + /* Configure PA0 and PA1 as alternate function pins */ + pins = GPIO0 | GPIO1; + GPIO_AFSEL(GPIOA) |= pins; + GPIO_DEN(GPIOA) |= pins; + /* PA0 and PA1 are muxed to UART0 during power on, by default */ + + /* Enable the UART clock */ + periph_clock_enable(RCC_UART0); + /* We need a brief delay before we can access UART config registers */ + __asm__("nop"); + /* Disable the UART while we mess with its setings */ + uart_disable(UART0); + /* Configure the UART clock source as precision internal oscillator */ + uart_clock_from_piosc(UART0); + /* Set communication parameters */ + uart_set_baudrate(UART0, 921600); + uart_set_databits(UART0, 8); + uart_set_parity(UART0, UART_PARITY_NONE); + uart_set_stopbits(UART0, 1); + /* Now that we're done messing with the settings, enable the UART */ + uart_enable(UART0); + +} + +int main(void) +{ + u8 rx; + + uart_setup(); + + /* + * Yes, it's that simple ! + */ + while(1) { + rx = uart_recv_blocking(UART0); + uart_send_blocking(UART0, rx); + } + + return 0; +} diff --git a/libopencm3 b/libopencm3 index 92d1134..4d15da9 160000 --- a/libopencm3 +++ b/libopencm3 @@ -1 +1 @@ -Subproject commit 92d1134a16903569f2efad5e858e16917e0da155 +Subproject commit 4d15da995e6019d5cb6d098b683452ff6647ffe2