From 0b7a929ec62dc11a4b6d5f11fb2ac971dc41c0db Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Tue, 10 Feb 2015 13:09:43 +0100 Subject: [PATCH 1/5] cortex-m4_common: Add debugger break in crash.c --- cpu/cortex-m4_common/crash.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpu/cortex-m4_common/crash.c b/cpu/cortex-m4_common/crash.c index e00842272e..c329272397 100644 --- a/cpu/cortex-m4_common/crash.c +++ b/cpu/cortex-m4_common/crash.c @@ -52,6 +52,8 @@ NORETURN void core_panic(int crash_code, const char *message) /* disable watchdog and all possible sources of interrupts */ disableIRQ(); #if DEVELHELP + /* The bkpt instruction will signal to the debugger to break here. */ + __ASM("bkpt #0"); /* enter infinite loop, into deepest possible sleep mode */ while (1) { lpm_set(LPM_OFF); From 7829a55a8cbfbd5b7e77807829dee83f5b100f27 Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Tue, 10 Feb 2015 13:33:30 +0100 Subject: [PATCH 2/5] cortex-m4_common: Minor fixes for string handling in core_panic() --- cpu/cortex-m4_common/crash.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cpu/cortex-m4_common/crash.c b/cpu/cortex-m4_common/crash.c index c329272397..fb0e1b3963 100644 --- a/cpu/cortex-m4_common/crash.c +++ b/cpu/cortex-m4_common/crash.c @@ -24,8 +24,10 @@ #include "lpm.h" #include "crash.h" +#define PANIC_STR_SIZE 80 + /* "public" variables holding the crash data */ -char panic_str[80]; +char panic_str[PANIC_STR_SIZE]; int panic_code; /* flag preventing "recursive crash printing loop" */ @@ -36,7 +38,9 @@ NORETURN void core_panic(int crash_code, const char *message) { /* copy panic datas to "public" global variables */ panic_code = crash_code; - strncpy(panic_str, message, 80); + strncpy(panic_str, message, sizeof(panic_str)); + /* strncpy does not add any null-termination. */ + panic_str[sizeof(panic_str)-1] = '\0'; /* print panic message to console (if possible) */ if (crashed == 0) { crashed = 1; From 972e61529c429bddfe7345de20061bab8bc73539 Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Tue, 17 Feb 2015 13:15:40 +0100 Subject: [PATCH 3/5] cortex-m4_common: Update crash.c author and copyright after recent changes. --- cpu/cortex-m4_common/crash.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cpu/cortex-m4_common/crash.c b/cpu/cortex-m4_common/crash.c index fb0e1b3963..f10541300a 100644 --- a/cpu/cortex-m4_common/crash.c +++ b/cpu/cortex-m4_common/crash.c @@ -1,9 +1,10 @@ /* * Copyright (C) 2015 INRIA + * 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. + * 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. */ /** @@ -14,6 +15,7 @@ * @brief Crash handling functions implementation for ARM Cortex-based MCUs * * @author Oliver Hahm + * @author Joakim Gebart */ #include From 2605b57a35d6db8adfb7a51323164df14f9df207 Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Tue, 17 Feb 2015 13:16:26 +0100 Subject: [PATCH 4/5] cortex-m3_common: Update crash.c with changes from Cortex-M4. --- cpu/cortex-m3_common/crash.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cpu/cortex-m3_common/crash.c b/cpu/cortex-m3_common/crash.c index 9aa72b60f0..93e7ce471c 100644 --- a/cpu/cortex-m3_common/crash.c +++ b/cpu/cortex-m3_common/crash.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2014 INRIA + * Copyright (C) 2014-2015 INRIA + * 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 @@ -10,21 +11,25 @@ * @ingroup cortex-m3_common * @{ * - * @file crash.c + * @file * @brief Crash handling functions implementation for ARM Cortex-based MCUs * * @author Oliver Hahm + * @author Joakim Gebart */ -#include "cpu.h" -#include "lpm.h" -#include "crash.h" - #include #include +#include "cpu.h" +#include "irq.h" +#include "lpm.h" +#include "crash.h" + +#define PANIC_STR_SIZE 80 + /* "public" variables holding the crash data */ -char panic_str[80]; +char panic_str[PANIC_STR_SIZE]; int panic_code; /* flag preventing "recursive crash printing loop" */ @@ -35,7 +40,9 @@ NORETURN void core_panic(int crash_code, const char *message) { /* copy panic datas to "public" global variables */ panic_code = crash_code; - strncpy(panic_str, message, 80); + strncpy(panic_str, message, sizeof(panic_str)); + /* strncpy does not add any null-termination. */ + panic_str[sizeof(panic_str)-1] = '\0'; /* print panic message to console (if possible) */ if (crashed == 0) { crashed = 1; @@ -49,9 +56,10 @@ NORETURN void core_panic(int crash_code, const char *message) puts("\n\n"); } /* disable watchdog and all possible sources of interrupts */ - //TODO - dINT(); + disableIRQ(); #if DEVELHELP + /* The bkpt instruction will signal to the debugger to break here. */ + __ASM("bkpt #0"); /* enter infinite loop, into deepest possible sleep mode */ while (1) { lpm_set(LPM_OFF); From 5a09e54e1b3c0bee28408c9c0f8f30675afc206a Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Tue, 17 Feb 2015 13:16:40 +0100 Subject: [PATCH 5/5] cortex-m0_common: Update crash.c with changes from Cortex-M4. --- cpu/cortex-m0_common/crash.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cpu/cortex-m0_common/crash.c b/cpu/cortex-m0_common/crash.c index c5a20e5043..03d71cba84 100644 --- a/cpu/cortex-m0_common/crash.c +++ b/cpu/cortex-m0_common/crash.c @@ -1,9 +1,10 @@ /* * Copyright (C) 2015 INRIA + * 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. + * 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. */ /** @@ -14,6 +15,7 @@ * @brief Crash handling functions implementation for ARM Cortex-based MCUs * * @author Oliver Hahm + * @author Joakim Gebart */ #include @@ -24,8 +26,10 @@ #include "lpm.h" #include "crash.h" +#define PANIC_STR_SIZE 80 + /* "public" variables holding the crash data */ -char panic_str[80]; +char panic_str[PANIC_STR_SIZE]; int panic_code; /* flag preventing "recursive crash printing loop" */ @@ -36,7 +40,9 @@ NORETURN void core_panic(int crash_code, const char *message) { /* copy panic datas to "public" global variables */ panic_code = crash_code; - strncpy(panic_str, message, 80); + strncpy(panic_str, message, sizeof(panic_str)); + /* strncpy does not add any null-termination. */ + panic_str[sizeof(panic_str)-1] = '\0'; /* print panic message to console (if possible) */ if (crashed == 0) { crashed = 1; @@ -52,6 +58,8 @@ NORETURN void core_panic(int crash_code, const char *message) /* disable watchdog and all possible sources of interrupts */ disableIRQ(); #if DEVELHELP + /* The bkpt instruction will signal to the debugger to break here. */ + __ASM("bkpt #0"); /* enter infinite loop, into deepest possible sleep mode */ while (1) { lpm_set(LPM_OFF);