Merge pull request #2420 from gebart/pr/cortex-m4-crash-bkpt

cortex-m4_common: Add debugger break in crash.c + minor string handling fix
This commit is contained in:
Joakim Gebart 2015-02-17 16:06:33 +01:00
commit b6eeb65f70
3 changed files with 44 additions and 20 deletions

View File

@ -1,9 +1,10 @@
/* /*
* Copyright (C) 2015 INRIA * Copyright (C) 2015 INRIA
* Copyright (C) 2015 Eistec AB
* *
* This file is subject to the terms and conditions of the GNU Lesser * This file is subject to the terms and conditions of the GNU Lesser General
* General Public License v2.1. See the file LICENSE in the top level * Public License v2.1. See the file LICENSE in the top level directory for more
* directory for more details. * details.
*/ */
/** /**
@ -14,6 +15,7 @@
* @brief Crash handling functions implementation for ARM Cortex-based MCUs * @brief Crash handling functions implementation for ARM Cortex-based MCUs
* *
* @author Oliver Hahm <oliver.hahm@inria.fr> * @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/ */
#include <string.h> #include <string.h>
@ -24,8 +26,10 @@
#include "lpm.h" #include "lpm.h"
#include "crash.h" #include "crash.h"
#define PANIC_STR_SIZE 80
/* "public" variables holding the crash data */ /* "public" variables holding the crash data */
char panic_str[80]; char panic_str[PANIC_STR_SIZE];
int panic_code; int panic_code;
/* flag preventing "recursive crash printing loop" */ /* 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 */ /* copy panic datas to "public" global variables */
panic_code = crash_code; 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) */ /* print panic message to console (if possible) */
if (crashed == 0) { if (crashed == 0) {
crashed = 1; crashed = 1;
@ -52,6 +58,8 @@ NORETURN void core_panic(int crash_code, const char *message)
/* disable watchdog and all possible sources of interrupts */ /* disable watchdog and all possible sources of interrupts */
disableIRQ(); disableIRQ();
#if DEVELHELP #if DEVELHELP
/* The bkpt instruction will signal to the debugger to break here. */
__ASM("bkpt #0");
/* enter infinite loop, into deepest possible sleep mode */ /* enter infinite loop, into deepest possible sleep mode */
while (1) { while (1) {
lpm_set(LPM_OFF); lpm_set(LPM_OFF);

View File

@ -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 * 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 * Public License v2.1. See the file LICENSE in the top level directory for more
@ -10,21 +11,25 @@
* @ingroup cortex-m3_common * @ingroup cortex-m3_common
* @{ * @{
* *
* @file crash.c * @file
* @brief Crash handling functions implementation for ARM Cortex-based MCUs * @brief Crash handling functions implementation for ARM Cortex-based MCUs
* *
* @author Oliver Hahm <oliver.hahm@inria.fr> * @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/ */
#include "cpu.h"
#include "lpm.h"
#include "crash.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "cpu.h"
#include "irq.h"
#include "lpm.h"
#include "crash.h"
#define PANIC_STR_SIZE 80
/* "public" variables holding the crash data */ /* "public" variables holding the crash data */
char panic_str[80]; char panic_str[PANIC_STR_SIZE];
int panic_code; int panic_code;
/* flag preventing "recursive crash printing loop" */ /* 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 */ /* copy panic datas to "public" global variables */
panic_code = crash_code; 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) */ /* print panic message to console (if possible) */
if (crashed == 0) { if (crashed == 0) {
crashed = 1; crashed = 1;
@ -49,9 +56,10 @@ NORETURN void core_panic(int crash_code, const char *message)
puts("\n\n"); puts("\n\n");
} }
/* disable watchdog and all possible sources of interrupts */ /* disable watchdog and all possible sources of interrupts */
//TODO disableIRQ();
dINT();
#if DEVELHELP #if DEVELHELP
/* The bkpt instruction will signal to the debugger to break here. */
__ASM("bkpt #0");
/* enter infinite loop, into deepest possible sleep mode */ /* enter infinite loop, into deepest possible sleep mode */
while (1) { while (1) {
lpm_set(LPM_OFF); lpm_set(LPM_OFF);

View File

@ -1,9 +1,10 @@
/* /*
* Copyright (C) 2015 INRIA * Copyright (C) 2015 INRIA
* Copyright (C) 2015 Eistec AB
* *
* This file is subject to the terms and conditions of the GNU Lesser * This file is subject to the terms and conditions of the GNU Lesser General
* General Public License v2.1. See the file LICENSE in the top level * Public License v2.1. See the file LICENSE in the top level directory for more
* directory for more details. * details.
*/ */
/** /**
@ -14,6 +15,7 @@
* @brief Crash handling functions implementation for ARM Cortex-based MCUs * @brief Crash handling functions implementation for ARM Cortex-based MCUs
* *
* @author Oliver Hahm <oliver.hahm@inria.fr> * @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/ */
#include <string.h> #include <string.h>
@ -24,8 +26,10 @@
#include "lpm.h" #include "lpm.h"
#include "crash.h" #include "crash.h"
#define PANIC_STR_SIZE 80
/* "public" variables holding the crash data */ /* "public" variables holding the crash data */
char panic_str[80]; char panic_str[PANIC_STR_SIZE];
int panic_code; int panic_code;
/* flag preventing "recursive crash printing loop" */ /* 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 */ /* copy panic datas to "public" global variables */
panic_code = crash_code; 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) */ /* print panic message to console (if possible) */
if (crashed == 0) { if (crashed == 0) {
crashed = 1; crashed = 1;
@ -52,6 +58,8 @@ NORETURN void core_panic(int crash_code, const char *message)
/* disable watchdog and all possible sources of interrupts */ /* disable watchdog and all possible sources of interrupts */
disableIRQ(); disableIRQ();
#if DEVELHELP #if DEVELHELP
/* The bkpt instruction will signal to the debugger to break here. */
__ASM("bkpt #0");
/* enter infinite loop, into deepest possible sleep mode */ /* enter infinite loop, into deepest possible sleep mode */
while (1) { while (1) {
lpm_set(LPM_OFF); lpm_set(LPM_OFF);