You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/06/10 22:16:17 UTC
incubator-mynewt-core git commit: MYNEWT-304;
mcu hal - add routine system_debugger_attached() which tells whether
debugging via JTAG or not. If yes, we can stop in debugger when system
crashes/resets.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 8cee49624 -> 6ed23d287
MYNEWT-304; mcu hal - add routine system_debugger_attached() which tells
whether debugging via JTAG or not. If yes, we can stop in debugger
when system crashes/resets.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/6ed23d28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6ed23d28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6ed23d28
Branch: refs/heads/develop
Commit: 6ed23d287cc31e46b6fb9aff1062a68ad51889bd
Parents: 8cee496
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Jun 10 15:06:04 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Jun 10 15:15:52 2016 -0700
----------------------------------------------------------------------
hw/hal/include/hal/hal_system.h | 4 ++++
hw/mcu/nordic/nrf51xxx/src/hal_system.c | 9 ++++++++-
hw/mcu/nordic/nrf52xxx/src/hal_system.c | 10 ++++++++--
hw/mcu/stm/stm32f4xx/src/hal_system.c | 10 ++++++++--
libs/os/src/arch/cortex_m0/os_fault.c | 6 ++++++
libs/os/src/arch/cortex_m4/os_fault.c | 6 ++++++
6 files changed, 40 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6ed23d28/hw/hal/include/hal/hal_system.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_system.h b/hw/hal/include/hal/hal_system.h
index 32aad1a..97488ff 100644
--- a/hw/hal/include/hal/hal_system.h
+++ b/hw/hal/include/hal/hal_system.h
@@ -34,6 +34,10 @@ void system_reset(void) __attribute((noreturn));
*/
void system_start(void *img_start) __attribute((noreturn));
+/*
+ * Returns non-zero if there is a HW debugger attached.
+ */
+int system_debugger_connected(void);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6ed23d28/hw/mcu/nordic/nrf51xxx/src/hal_system.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_system.c b/hw/mcu/nordic/nrf51xxx/src/hal_system.c
index 152eaa3..0914660 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_system.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_system.c
@@ -6,7 +6,7 @@
* to you 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,
@@ -28,3 +28,10 @@ system_reset(void)
}
}
+int
+system_debugger_connected(void)
+{
+ /* XXX is there a way? */
+ return 0;
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6ed23d28/hw/mcu/nordic/nrf52xxx/src/hal_system.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_system.c b/hw/mcu/nordic/nrf52xxx/src/hal_system.c
index 1bcb581..a5a432f 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_system.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_system.c
@@ -6,7 +6,7 @@
* to you 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,
@@ -24,7 +24,7 @@ void
system_reset(void)
{
while (1) {
- if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) {
+ if (system_debugger_connected()) {
/*
* If debugger is attached, breakpoint here.
*/
@@ -33,3 +33,9 @@ system_reset(void)
NVIC_SystemReset();
}
}
+
+int
+system_debugger_connected(void)
+{
+ return CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6ed23d28/hw/mcu/stm/stm32f4xx/src/hal_system.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_system.c b/hw/mcu/stm/stm32f4xx/src/hal_system.c
index 75e7b5f..3beefa4 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_system.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_system.c
@@ -6,7 +6,7 @@
* to you 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,
@@ -24,7 +24,7 @@ void
system_reset(void)
{
while (1) {
- if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) {
+ if (system_debugger_connected()) {
/*
* If debugger is attached, breakpoint here.
*/
@@ -34,6 +34,12 @@ system_reset(void)
}
}
+int
+system_debugger_connected(void)
+{
+ return CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
+}
+
uint32_t
HAL_GetTick(void)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6ed23d28/libs/os/src/arch/cortex_m0/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_fault.c b/libs/os/src/arch/cortex_m0/os_fault.c
index 58be78c..563f91a 100644
--- a/libs/os/src/arch/cortex_m0/os_fault.c
+++ b/libs/os/src/arch/cortex_m0/os_fault.c
@@ -117,6 +117,12 @@ __assert_func(const char *file, int line, const char *func, const char *e)
(void)sr;
console_blocking_mode();
console_printf("Assert %s; failed in %s:%d\n", e ? e : "", file, line);
+ if (system_debugger_connected()) {
+ /*
+ * If debugger is attached, breakpoint before the trap.
+ */
+ asm("bkpt");
+ }
SCB->ICSR = SCB_ICSR_NMIPENDSET_Msk;
/* Exception happens right away. Next line not executed. */
system_reset();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6ed23d28/libs/os/src/arch/cortex_m4/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_fault.c b/libs/os/src/arch/cortex_m4/os_fault.c
index 9bc1db4..a6c2b7c 100644
--- a/libs/os/src/arch/cortex_m4/os_fault.c
+++ b/libs/os/src/arch/cortex_m4/os_fault.c
@@ -118,6 +118,12 @@ __assert_func(const char *file, int line, const char *func, const char *e)
(void)sr;
console_blocking_mode();
console_printf("Assert %s; failed in %s:%d\n", e ? e : "", file, line);
+ if (system_debugger_connected()) {
+ /*
+ * If debugger is attached, breakpoint before the trap.
+ */
+ asm("bkpt");
+ }
SCB->ICSR = SCB_ICSR_NMIPENDSET_Msk;
asm("isb");
system_reset();