Commit 42f79811 authored by Martin Horauer's avatar Martin Horauer
Browse files

added APP_UART

parent f90b5f17
This diff is collapsed.
TARGET=XMC_4500_RELAX_KIT
TOOLCHAIN=GCC_ARM
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>APP_BLINKY</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
\ No newline at end of file
################################################################################
# Makefile for XMC4500 RelaxKit using uCOS-III
# v1, 02/2018
# Martin Horauer, UAS Technikum Wien
#
# Supported: Windows, Linux, OSX
# Requirements:
# * GCC ARM https://launchpad.net/gcc-arm-embedded/+download
# * SEGGER JLINK https://www.segger.com/jlink-software.html
# * DOXYGEN http://www.stack.nl/~dimitri/doxygen/
################################################################################
# USAGE
# -----
# make .... build the program image
# make debug .... build the program image and invoke gdb
# make flash .... build an flash the application
# make erase .... erase the target device
# make doc .... run doxygen - output will be in > doc
# make clean .... remove intermediate and generated files
################################################################################
# define the name of the generated output file
#
TARGET = main
################################################################################
# below only edit with care
#
VENDOR = Infineon
################################################################################
# define the following symbol -D JLINK_RTT to enable JLINK_RTT tracing
# -D SEMI_HOSTING to enable semi hosted tracing
# comment the line to disable tracing
TRACE = -D SEMI_HOSTING
################################################################################
# TOOLS & ARGS
#
SRC = $(wildcard *.cpp)
TERMINAL = gnome-terminal
TOOLCHAIN = GCC_ARM
BOARD = XMC_4500_RELAX_KIT
BUILDDIR = BUILD
DOCDIR = DOC
MBED = mbed
GDB = arm-none-eabi-gdb
# DETERMINE OS
ifdef SystemRoot
RM = del /Q
FixPath = $(subst /,\,$1)
else
RM = rm -rf
FixPath = $1
endif
GDB_ARGS = -ex "target remote :2331"
GDB_ARGS += -ex "monitor reset"
GDB_ARGS += -ex "load"
GDB_ARGS += -ex "monitor reset"
################################################################################
# SEMI_HOSTED DEBUGGING
GDB_ARGS += -ex "monitor SWO EnableTarget 16000000 0 1 0"
# RTT OPTION
#GDB_ARGS += -ex "monitor exec SetRTTAddr 0x20000000"
#GDB_ARGS += -ex "monitor exec SetRTTSearchRanges 0x20000000 0x1000"
################################################################################
# BUILD RULES
all: $(SRC) build
################################################################################
# CREATE A DEBUG VESRION
build: $(SRC)
@echo "----------------------------------------------------------------------"
@echo "Building with DEBUG Symbols"
@echo ""
$(MBED) compile -m $(BOARD) -t $(TOOLCHAIN) -N main --profile mbed-os/tools/profiles/debug.json
@echo ""
################################################################################
# CREATE A RELEASE VESRION
release: $(SRC)
@echo "----------------------------------------------------------------------"
@echo "Build a RELEASE version"
@echo ""
$(MBED) compile -m $(BOARD) -t $(TOOLCHAIN) -N main
@echo ""
################################################################################
# DEBUG RULES
debug: build $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).elf
ifdef SystemRoot
@call start JLinkGDBServer -Device XMC4500-1024 -if SWD
else
$(TERMINAL) -e "JLinkGDBServer -Device XMC4500-1024 -if SWD" &
sleep 1 && $(TERMINAL) -e "telnet 127.0.0.1 2333" &
endif
$(GDB) -q $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).elf $(GDB_ARGS)
################################################################################
# FLASH RULES
flash: build $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).hex
echo -e 'speed 4000\nconnect\nh\nloadbin $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).hex,0xC000000\nr\ng\nq' | JLinkExe -Device XMC4500-1024 -if SWD
################################################################################
# ERASE DEVICE
erase:
echo -e 'speed 4000\nconnect\nerase\nr\nq' | JLinkExe -Device XMC4500-1024 -if SWD
################################################################################
# DOCUMENTATION RULES
doc: $(SRC)
doxygen
################################################################################
# CLEAN RULES
clean:
$(RM) $(call FixPath, *.pyc)
$(RM) $(call FixPath, ${BUILDDIR}/*)
$(RM) $(call FixPath, ${DOCDIR}/html/*)
################################################################################
# EOF
################################################################################
= UART Example
This example illustrates how to use mbed-Serial to communicate via a
UART. This example uses UART1 with 9600-8N1. On startup a welcome text is
printed and afterwards all received characters are send back with an index
number.
image::serial.png[]
In detail: The application first create a separate thread "com_thread()". In
the endless loop of the application LED1 is toggled.
The thread "com_thread()" initializes the baudrate of the UART and attaches a
callback function "callback_rx()" to the UART IRQ. Then the thread checks the
mailbox. The mailbox is allocated and filled in with a number in the
"callback_rx()" function. When the thread receives a mail event via the mailbox
it uses the pointer to obtain the content from the mailbox. Then it outputs a
message via the UART conatining the value received from the mailbox along with a
character entered by the user. Next, it toggles LED2. Finally, the thread frees
the memory block from the mail.
The "callback_rx()" function simply allocates memory for the mail - fills in a
number (that is incremented) into the mail, and puts this message into the
mailbox (queue).
== Makefile Usage
[source%nowrap, bash]
----
make # build the application
make flash # flash the application
make debug # debug the application
make erase # erase the program memory
make doc # invoke doxygen
make clean # clean the project
----
= Manual
== Building
[source%nowrap, bash]
----
mbed compile -c -m XMC_4500_RELAX_KIT -t GCC_ARM -N main
----
This creates several files in the BUILD directory where you can find the
executables (bin, elf, hex ...).
== Flashing
[source%nowrap, bash]
----
$ JLinkExe -Device XMC4500-1024 -if SWD -speed 4000
J-LINK> h
J-Link> loadfile BUILD/XMC_4500_RELAX_KIT/GCC_ARM/main.hex
J-Link> r
J-Link> g
----
== Debugging
(1) Build the application with debug symbols enabled by adding `--profile mbed-os/tools/profiles/debug.json`.
[source%nowrap, bash]
----
mbed compile -c -m XMC_4500_RELAX_KIT -t GCC_ARM -N main --profile mbed-os/tools/profiles/debug.json
----
(2) Start the `JLinkGDEBServer`, e.g.:
[source%nowrap, bash]
----
JLinkGDBServer -Device XMC4500-1024 -if SWD
----
(3) In order to log messages printed to `stdout` we connect to port 2333 via
telnet.
[source%nowrap, bash]
----
telnet 127.0.0.1 2333
----
(4) We launch the debugger and control the debug session:
[source%nowrap, bash]
----
arm-none-eabi-gdb -q BUILD/XMC_4500_RELAX_KIT/GCC_ARM/main.elf
(gdb) target remote :2331
(gdb) monitor reset
(gdb) load
(gdb) monitor reset
(gdb) b main
(gdb) c
[...]
----
This diff is collapsed.
/* mbed Example Program
* Copyright (c) 2006-2014 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/******************************************************************* Includes */
#include "mbed.h"
#include "rtos.h"
/******************************************************************** Typedef */
typedef struct {
/* number of received character */
uint32_t idx;
} mail_t;
/******************************************************************** Globals */
/* create objects of the class DigitalOut: "led_flash", "led_serial"
see drivers/DigitalOut.h
the argument LED1/LED2 are defined in:
see targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
DigitalOut led_flash (LED1); // LED1 = P1.1
DigitalOut led_serial (LED2); // LED2 = P1.0
/* create an object of class DigitalIn: "mypin1"
see drivers/DigitalIn.h
the argument SW2 is defined in:
see targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
DigitalIn mypin1 (SW2); // BUTTON2 = P1.15
/* create an object of class Serial: "device"
see drivers/Serial.h
if the baudrate is omitted it will be defined at compile time
using the symbol MBED_CONF_PLATFORM_STDIO_BAUD_RATE see:
mbed compile --config -m XMC_4500_RELAX_KIT -t GCC_ARM
Tx and Rx have to be specified or at least use NC for not connected
the names of the pins are specified in
targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
Serial device (P0_1, P0_0); // UART1 -> Tx = P0.1, Rx = P0.0
/* create an object from class Thread: "thread1"
see rtos/Thread.h
*/
Thread thread1;
/* create an object of the class Mail: "mail_box"
this C++ class employs templating:
mail_t .... data type of the mail messages - struct declaration see above
16 ........ size of the mailbox
see rtos/Mail.h
*/
Mail<mail_t, 16> mail_box;
/****************************************************************** Callbacks */
/**
* Callback for UART RX
*/
void callback_rx()
{
static int _idx = 0;
/* allocate space for the mail using the method .alloc()
see rtos/Mail.h
*/
mail_t *mail = mail_box.alloc();
/* fill the mailbox with content */
mail->idx = _idx++;
/* use the .put() method to put the mail message into the mailbox (queue) */
mail_box.put (mail);
}
/**
* Communication Thread
*/
void com_thread()
{
/* Configure the UART
use the method .baud() from the class SerialBase
see drivers/SerialBase.cpp
*/
device.baud (9600);
/* Attach a callback function to the object "device"
this callback is invoked whenever a character is received or transmitted
the second parameter like "mbed::Serial::RxIrq" can be used to trigger
the callback only on a receive IRQ - in the XMC, however, receive and
transmit IRQ are bothe the same IRQ
see platform/Callback.h & drivers/SerialBase.cpp
*/
device.attach (&callback_rx);
/* invoke the Stream::printf() method see
platform/Stream.cpp
*/
device.printf ("Serial-Example!!\n");
while (1) {
/* use the .get() method to obtain an event from the mailbox (queue)
osEvent is declared in rtos/TARGET_CORTEX/rtx4/cmsis_os.h as a struct
consisting of the elements "status", "value" and "def" (ID)
*/
osEvent evt = mail_box.get();
/* if it is a mail event ... */
if (evt.status == osEventMail) {
/* obtain the address to our mail from the osEvent structure
-> a pointer to our mail
*/
mail_t *mail = (mail_t*) evt.value.p;
/* output a string using the .printf() method
see platform/Stream.cpp
use the .getc() method to obtain another input character from
the UART - the receive IRQ will also trigger callback_rx()
see drivers/SerialBase.cpp
*/
device.printf ("%03d-%c\n", mail->idx, device.getc());
/* operator overloading using "operator="
see drivers/DigitalOut.h
-> toggles LED2 whenever a message is output
*/
led_serial = !led_serial;
/* free a memory block from mail
see rtos/Mail.h
*/
mail_box.free (mail);
}
}
}
/**
* Main Function
*/
int main()
{
/* use the method start on the object thread1
the parameter is the name of the function to be executed
*/
thread1.start (com_thread);
while (1) {
/* operator overloading using "operator="
see drivers/DigitalOut.h
-> toggles LED1
*/
led_flash = !led_flash;
/* invoke the function wait() see
platform/mbed_wait_api_rtos.cpp
*/
wait (1);
}
}
/*! EOF */
../mbed-os/
\ No newline at end of file
https://github.com/mbed-Infineon-XMC/mbed-os.git
"""
mbed SDK
Copyright (c) 2016 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import subprocess
from os.path import join, abspath, dirname
#ROOT = abspath(join(dirname(__file__), "."))
##############################################################################
# Build System Settings
##############################################################################
#BUILD_DIR = abspath(join(ROOT, "build"))
# ARM
#ARM_PATH = "C:/Program Files/ARM"
# GCC ARM
#GCC_ARM_PATH = ""
GCC_ARM_PATH = dirname(subprocess.check_output(["which", "arm-none-eabi-gcc"]))
# GCC CodeRed
#GCC_CR_PATH = "C:/code_red/RedSuite_4.2.0_349/redsuite/Tools/bin"
# IAR
#IAR_PATH = "C:/Program Files (x86)/IAR Systems/Embedded Workbench 7.0/arm"
# Goanna static analyser. Please overload it in private_settings.py
#GOANNA_PATH = "c:/Program Files (x86)/RedLizards/Goanna Central 3.2.3/bin"
#BUILD_OPTIONS = []
# mbed.org username
#MBED_ORG_USER = ""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment