diff --git a/cpu/kinetis_common/Makefile.include b/cpu/kinetis_common/Makefile.include index e52ffc5428..2ce8ec822a 100644 --- a/cpu/kinetis_common/Makefile.include +++ b/cpu/kinetis_common/Makefile.include @@ -9,3 +9,10 @@ export UNDEF += $(BINDIR)kinetis_common/startup.o # add the CPU specific fault handlers for the linker export UNDEF += $(BINDIR)kinetis_common/fault_handlers.o + +# Define a recipe to build the watchdog disable binary, used when flashing +$(RIOTCPU)/kinetis_common/dist/wdog-disable.bin: $(RIOTCPU)/kinetis_common/dist/wdog-disable.s + $(AD)$(MAKE) -C $(RIOTCPU)/kinetis_common/dist/ $(notdir $@) + +# Reset the default goal to not make wdog-disable.bin the default target. +.DEFAULT_GOAL := diff --git a/cpu/kinetis_common/dist/Makefile b/cpu/kinetis_common/dist/Makefile new file mode 100644 index 0000000000..d87f6d39b7 --- /dev/null +++ b/cpu/kinetis_common/dist/Makefile @@ -0,0 +1,9 @@ +wdog-disable.bin: wdog-disable.o + arm-none-eabi-objcopy -O binary -j .text.wdog_disable -S -g $^ $@ + +wdog-disable.o: wdog-disable.s + arm-none-eabi-as -mthumb -o $@ $^ + +.PHONY: clean +clean: + @rm wdog-disable.o diff --git a/cpu/kinetis_common/dist/README.md b/cpu/kinetis_common/dist/README.md new file mode 100644 index 0000000000..6490f1097f --- /dev/null +++ b/cpu/kinetis_common/dist/README.md @@ -0,0 +1,15 @@ +K60 tools +========= + +This directory contains tools for working with K60 CPUs. + +Watchdog disable +---------------- + +wdog-disable.bin is a location-independent watchdog disable function with a breakpoint instruction at the end. Useful for disabling the watchdog directly from OpenOCD. + +Usage: + + openocd -c 'reset halt' \ + -c 'load_image wdog-disable.bin 0x20000000 bin' \ + -c 'resume 0x20000000' # watchdog is disabled and core halted diff --git a/cpu/kinetis_common/dist/wdog-disable.s b/cpu/kinetis_common/dist/wdog-disable.s new file mode 100644 index 0000000000..7418b1b8ec --- /dev/null +++ b/cpu/kinetis_common/dist/wdog-disable.s @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Eistec AB + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/* GCC ARM assembler */ + + .text + .thumb + .align 2 + +/* Public functions declared in this file */ + .global wdog_disable + +.section .text.wdog_disable +.thumb_func +.func +wdog_disable: + movw r0, #0x200e + movw r1, #0xc520 + movt r0, #0x4005 + strh r1, [r0, #0] + movw r1, #0xd928 + strh r1, [r0, #0] + movw r0, #0x2000 + movs r1, #0xd2 + movt r0, #0x4005 + strh r1, [r0, #0] + bkpt #0 +.endfunc