Commit b30aa796 authored by Martin Horauer's avatar Martin Horauer
Browse files

added a Watchdog example

parent 812d2021
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
################################################################################
= Watchdog Example
This example illustrates how you can use the watchdog timer on the XMC. The
watchdog timer is not supported by default from mbed. So this guide shows how
you can write classes to support specific XMC hardware which is not supported by
mbed. Check out the following tutorial, which descibes how you can write your
own mbed library:
https://os.mbed.com/cookbook/Writing-a-Library[https://os.mbed.com/cookbook/Writing-a-Library].
A watchdog library for the XMC is available here:
https://github.com/mbed-Infineon-XMC/XMCWatchdog-Library.git[https://github.com/mbed-Infineon-XMC/XMCWatchdog-Library.git].
The watchdog timer is configured to 5s. If `wd.service()` is not called at least
once during this period, the watchdog timer will reset the microcontroller. In
this example `wd.service()` is called every second. (LED 2 blink) If button2 is
pressed the wadchdog timer expires because `wd.service()` is not longer called
and the XMC will reset after 5 seconds. At the next start the XMC checks with
`wd.watchdogCauseReset()` if the watchdog timer was the cause of a reset; in
this case LED1 is turned on.
== 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 Usage
== 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
executable (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 "Watchdog.h"
/******************************************************************** Globals */
/* create an object of a Watchdog class named wd
see targets/TARGET_Infineon/TARGET_XMC4XXX/Watchdog/Watchdog.cpp
*/
Watchdog wd;
/* create an object of the DigitalOut classes named led1 and led2, respectively
see drivers/DigitalOut.h
*/
DigitalOut led1 (LED1);
DigitalOut led2 (LED2);
/* create an object of the InterruptIn class named button
see drivers/InterruptIn.h
the parameters SW is defined in
targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
InterruptIn button (SW2);
/* define a globale variable */
volatile int wd_flag = 0;
/****************************************************************** Callbacks */
void rise (void)
{
wd_flag = 1;
}
/****************************************************************** Functions */
int main (void)
{
/* check if watchdog was cause of reset */
if (wd.watchdogCausedReset()) {
/* turn led1 on if wadchdog timer expired */
led1 = 1;
}
/* attach a rise handler to the button object that is invoked
whenever a rising edge is detected on the respective input
*/
button.rise (&rise);
/* configure & start watchdog timer for 5 seconds
with the help of the .configure() method
*/
wd.configure (5.0);
while (1) {
/* delay for 1 second */
wait (1);
if (!wd_flag) {
/* clear the watchdog timer every second as long as SW2 (Button2 on the
RelaxKit) was not pressed
*/
wd.service();
/* toggle LED2 */
led2 = !led2;
}
}
}
/*! 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 = ""
/* 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 "xmc_wdt.h"
#include "xmc_scu.h"
#include "Watchdog.h"
#include "mbed.h"
/****************************************************************** Globals **/
XMC_WDT_CONFIG_t wdt_cfg;
/**************************************************************** Functions **/
/** @brief Constructor
*
*/
Watchdog::Watchdog() {
/* Check if watchdog was cause of reset */
if ((XMC_SCU_RESET_GetDeviceResetReason() & XMC_SCU_RESET_REASON_WATCHDOG) != 0){
wdreset = true;
}else{
wdreset = false;
}
/* Clear system reset status */
SCU_RESET->RSTCLR |= SCU_RESET_RSTCLR_RSCLR_Msk;
}
/** @brief Destuctor
*
*/
Watchdog::~Watchdog() {
XMC_WDT_Stop();
}
/** @brief Configure watchdog timer
*
* @param time Time in seconds
*/
void Watchdog::configure(float time) {
/* Use standby clock as watchdog clock source */
XMC_SCU_HIB_EnableHibernateDomain();
XMC_SCU_CLOCK_SetWdtClockSource(XMC_SCU_CLOCK_WDTCLKSRC_STDBY);
XMC_SCU_CLOCK_EnableClock(XMC_SCU_CLOCK_WDT);
wdt_time = time / (1 / (double)XMC_SCU_CLOCK_GetWdtClockFrequency());
/* Configure watchdog */
wdt_cfg.window_lower_bound = 0;
wdt_cfg.window_upper_bound = (uint32_t)wdt_time;
wdt_cfg.service_pulse_width = 255;
XMC_WDT_Init(&wdt_cfg);
XMC_WDT_Start();
}
/** @brief Watchdog service
*
*/
void Watchdog::service() {
XMC_WDT_Service();
}
/** @brief Check if watchdog was cause of reset
*
* @return true if yes, no otherwise
*/
bool Watchdog::watchdogCausedReset() {
return wdreset;
}
/*EOF*/
/** Watchdog class for the XMC MCU family.
*
* Example:
*/
#ifndef WATCHDOG_H
#define WATCHDOG_H
#include "mbed.h"
class Watchdog {
public:
/** Create HelloWorld instance
*/
Watchdog();
/** Delete HelloWorld instance
*/
~Watchdog();
/** Print the text
*
* @param timeout in seconds
*/
void configure(float timeout);
/** Watchdog service
*/
void service();
/** Check if watchdog was cause of reset
*
* @returns
* true watchdog was cause of reset
* fasle watchdog was not cause of reset
*/
bool watchdogCausedReset();
private:
double wdt_time;
bool wdreset;
};
#endif // WATCHDOG_H
/*EOF*/
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