You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/11/07 13:29:59 UTC

[mynewt-core] branch master updated (434b9c0 -> c07422f)

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


    from 434b9c0  Merge pull request #2081 from vrahane/2079_log_console_buf_reader
     new 9703ed3  hal: Add hal_debug_break functions
     new 5540015  riscv: Debugger detection
     new f20a9d3  Add HAL_DEBUG_BREAK
     new d671842  os_fault: Break into debugger before fault handler is executed
     new 6c2195d  hal_system: Use HAL_DEBUG_BREAK
     new 642da90  kernel: Remove software breakpoint from __assert_func
     new c07422f  mcu/mips: Add hal_debug_break implementation

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/bsp/hifive1/hifive1_debug.sh                    |  3 +-
 hw/hal/include/hal/{hal_nvreg.h => hal_debug.h}    | 43 ++++++++++------------
 hw/hal/syscfg.yml                                  |  5 +++
 hw/mcu/ambiq/apollo2/include/mcu/cortex_m4.h       |  6 +++
 hw/mcu/ambiq/apollo2/src/hal_system.c              |  7 +---
 hw/mcu/arc/snps/include/mcu/mcu_arc.h              |  8 +++-
 hw/mcu/arc/snps/src/hal_system.c                   |  7 +---
 hw/mcu/dialog/da1469x/include/mcu/cortex_m33.h     |  7 ++++
 hw/mcu/dialog/da1469x/src/hal_system.c             |  4 +-
 hw/mcu/mips/danube/include/mcu/mips.h              |  6 +++
 hw/mcu/native/include/mcu/mcu_sim.h                |  2 +
 hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h     |  7 ++++
 hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h     | 10 +++++
 hw/mcu/nordic/nrf52xxx/src/hal_system.c            | 11 ++----
 hw/mcu/nxp/MK64F12/include/mcu/cortex_m4.h         |  6 +++
 hw/mcu/nxp/MK64F12/src/hal_system.c                |  7 +---
 hw/mcu/nxp/mkw41z/include/mcu/cortex_m0.h          |  6 +++
 hw/mcu/sifive/fe310/include/mcu/fe310.h            |  6 +++
 hw/mcu/sifive/fe310/src/hal_system.c               | 13 ++++---
 hw/mcu/stm/stm32_common/src/hal_system.c           |  7 +---
 hw/mcu/stm/stm32f0xx/include/mcu/cortex_m0.h       |  6 +++
 hw/mcu/stm/stm32f1xx/include/mcu/cortex_m3.h       |  6 +++
 hw/mcu/stm/stm32f3xx/include/mcu/cortex_m4.h       |  6 +++
 hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h       |  6 +++
 hw/mcu/stm/stm32f7xx/include/mcu/cortex_m7.h       |  6 +++
 hw/mcu/stm/stm32l0xx/include/mcu/cortex_m0.h       |  6 +++
 hw/mcu/stm/stm32l1xx/include/mcu/cortex_m3.h       |  6 +++
 hw/mcu/stm/stm32l4xx/include/mcu/cortex_m4.h       |  6 +++
 hw/mcu/stm/stm32wbxx/include/mcu/cortex_m4.h       |  6 +++
 hw/{mcu/native => util/break_hook_example}/pkg.yml | 16 ++++----
 .../break_hook_example/src/break_hook_example.c    | 12 +++---
 .../hash => util/break_hook_example}/syscfg.yml    |  6 +--
 kernel/os/include/os/os_fault.h                    |  7 +++-
 kernel/os/src/arch/cortex_m0/os_fault.c            |  7 +---
 kernel/os/src/arch/cortex_m3/os_fault.c            |  7 +---
 kernel/os/src/arch/cortex_m33/os_fault.c           |  7 +---
 kernel/os/src/arch/cortex_m4/os_fault.c            |  8 ----
 kernel/os/src/arch/cortex_m7/os_fault.c            |  6 ---
 sys/sysinit/include/sysinit/sysinit.h              |  1 +
 39 files changed, 185 insertions(+), 117 deletions(-)
 copy hw/hal/include/hal/{hal_nvreg.h => hal_debug.h} (59%)
 copy hw/{mcu/native => util/break_hook_example}/pkg.yml (71%)
 copy crypto/mbedtls/selftest/src/testcases/ccm_test.c => hw/util/break_hook_example/src/break_hook_example.c (86%)
 copy hw/{drivers/hash => util/break_hook_example}/syscfg.yml (88%)


[mynewt-core] 01/07: hal: Add hal_debug_break functions

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 9703ed3c22530e3e853312c0a0094a9aa879078a
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri May 10 14:12:28 2019 +0200

    hal: Add hal_debug_break functions
    
    Add unified function to set code breakpoint.
---
 hw/mcu/ambiq/apollo2/include/mcu/cortex_m4.h   |  6 ++++++
 hw/mcu/arc/snps/include/mcu/mcu_arc.h          |  8 ++++++--
 hw/mcu/dialog/da1469x/include/mcu/cortex_m33.h |  7 +++++++
 hw/mcu/native/include/mcu/mcu_sim.h            |  2 ++
 hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h |  7 +++++++
 hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h | 10 ++++++++++
 hw/mcu/nxp/MK64F12/include/mcu/cortex_m4.h     |  6 ++++++
 hw/mcu/nxp/mkw41z/include/mcu/cortex_m0.h      |  6 ++++++
 hw/mcu/sifive/fe310/include/mcu/fe310.h        |  6 ++++++
 hw/mcu/stm/stm32f0xx/include/mcu/cortex_m0.h   |  6 ++++++
 hw/mcu/stm/stm32f1xx/include/mcu/cortex_m3.h   |  6 ++++++
 hw/mcu/stm/stm32f3xx/include/mcu/cortex_m4.h   |  6 ++++++
 hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h   |  6 ++++++
 hw/mcu/stm/stm32f7xx/include/mcu/cortex_m7.h   |  6 ++++++
 hw/mcu/stm/stm32l0xx/include/mcu/cortex_m0.h   |  6 ++++++
 hw/mcu/stm/stm32l1xx/include/mcu/cortex_m3.h   |  6 ++++++
 hw/mcu/stm/stm32l4xx/include/mcu/cortex_m4.h   |  6 ++++++
 hw/mcu/stm/stm32wbxx/include/mcu/cortex_m4.h   |  6 ++++++
 18 files changed, 110 insertions(+), 2 deletions(-)

diff --git a/hw/mcu/ambiq/apollo2/include/mcu/cortex_m4.h b/hw/mcu/ambiq/apollo2/include/mcu/cortex_m4.h
index bd67258..6b11382 100644
--- a/hw/mcu/ambiq/apollo2/include/mcu/cortex_m4.h
+++ b/hw/mcu/ambiq/apollo2/include/mcu/cortex_m4.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (128)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/arc/snps/include/mcu/mcu_arc.h b/hw/mcu/arc/snps/include/mcu/mcu_arc.h
index 4bcd558..fa51beb 100644
--- a/hw/mcu/arc/snps/include/mcu/mcu_arc.h
+++ b/hw/mcu/arc/snps/include/mcu/mcu_arc.h
@@ -20,14 +20,18 @@
 #ifndef __MCU_ARC_H__
 #define __MCU_ARC_H__
 
-#include "os/mynewt.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #define OS_TICKS_PER_SEC    (100)
 
+static inline void
+hal_debug_break(void)
+{
+    asm("BRK_S");
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/dialog/da1469x/include/mcu/cortex_m33.h b/hw/mcu/dialog/da1469x/include/mcu/cortex_m33.h
index ca39ee8..c981e63 100644
--- a/hw/mcu/dialog/da1469x/include/mcu/cortex_m33.h
+++ b/hw/mcu/dialog/da1469x/include/mcu/cortex_m33.h
@@ -21,6 +21,7 @@
 #define __MCU_CORTEX_M33_H_
 
 #include "mcu/mcu.h"
+#include "core_cm33.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -28,6 +29,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (128)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/native/include/mcu/mcu_sim.h b/hw/mcu/native/include/mcu/mcu_sim.h
index 5c9f804..a6e55a9 100644
--- a/hw/mcu/native/include/mcu/mcu_sim.h
+++ b/hw/mcu/native/include/mcu/mcu_sim.h
@@ -31,6 +31,8 @@ extern const char *native_uart_dev_strs[];
 
 void mcu_sim_parse_args(int argc, char **argv);
 
+void static inline hal_debug_break(void) {}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h b/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
index 1b87233..d4b6a96 100644
--- a/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
+++ b/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
@@ -21,6 +21,7 @@
 #define __MCU_CORTEX_M0_H__
 
 #include "nrf51.h"
+#include "core_cm0.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -33,6 +34,12 @@ extern "C" {
  */
 #define OS_TICKS_PER_SEC    (128)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h b/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
index 94a3d5a..6c6105b 100644
--- a/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
+++ b/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
@@ -21,6 +21,8 @@
 #define __MCU_CORTEX_M4_H__
 
 #include "nrf.h"
+#include "core_cm4.h"
+#include <syscfg/syscfg.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -28,6 +30,14 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (128)
 
+static inline void
+hal_debug_break(void)
+{
+#if !MYNEWT_VAL(MCU_DEBUG_IGNORE_BKPT)
+    __BKPT(1);
+#endif
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/nxp/MK64F12/include/mcu/cortex_m4.h b/hw/mcu/nxp/MK64F12/include/mcu/cortex_m4.h
index 10384ab..4480e33 100644
--- a/hw/mcu/nxp/MK64F12/include/mcu/cortex_m4.h
+++ b/hw/mcu/nxp/MK64F12/include/mcu/cortex_m4.h
@@ -32,6 +32,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC	(1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/nxp/mkw41z/include/mcu/cortex_m0.h b/hw/mcu/nxp/mkw41z/include/mcu/cortex_m0.h
index 6955bb0..3c846e0 100644
--- a/hw/mcu/nxp/mkw41z/include/mcu/cortex_m0.h
+++ b/hw/mcu/nxp/mkw41z/include/mcu/cortex_m0.h
@@ -34,6 +34,12 @@ extern "C" {
  */
 #define OS_TICKS_PER_SEC	(1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/sifive/fe310/include/mcu/fe310.h b/hw/mcu/sifive/fe310/include/mcu/fe310.h
index 8b03211..9ccb65e 100644
--- a/hw/mcu/sifive/fe310/include/mcu/fe310.h
+++ b/hw/mcu/sifive/fe310/include/mcu/fe310.h
@@ -32,6 +32,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    MYNEWT_VAL(OS_TICKS_PER_SEC)
 
+static inline void
+hal_debug_break(void)
+{
+    __asm ("ebreak");
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f0xx/include/mcu/cortex_m0.h b/hw/mcu/stm/stm32f0xx/include/mcu/cortex_m0.h
index b9c7e6d..c27f1dc 100644
--- a/hw/mcu/stm/stm32f0xx/include/mcu/cortex_m0.h
+++ b/hw/mcu/stm/stm32f0xx/include/mcu/cortex_m0.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f1xx/include/mcu/cortex_m3.h b/hw/mcu/stm/stm32f1xx/include/mcu/cortex_m3.h
index d03775e..fa61e24 100644
--- a/hw/mcu/stm/stm32f1xx/include/mcu/cortex_m3.h
+++ b/hw/mcu/stm/stm32f1xx/include/mcu/cortex_m3.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f3xx/include/mcu/cortex_m4.h b/hw/mcu/stm/stm32f3xx/include/mcu/cortex_m4.h
index 5ad99a4..5e00717 100644
--- a/hw/mcu/stm/stm32f3xx/include/mcu/cortex_m4.h
+++ b/hw/mcu/stm/stm32f3xx/include/mcu/cortex_m4.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h b/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h
index 99d90fc..d846ed1 100644
--- a/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h
+++ b/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f7xx/include/mcu/cortex_m7.h b/hw/mcu/stm/stm32f7xx/include/mcu/cortex_m7.h
index 59fd9db..5ffb6dd 100644
--- a/hw/mcu/stm/stm32f7xx/include/mcu/cortex_m7.h
+++ b/hw/mcu/stm/stm32f7xx/include/mcu/cortex_m7.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32l0xx/include/mcu/cortex_m0.h b/hw/mcu/stm/stm32l0xx/include/mcu/cortex_m0.h
index 98e482d..fe0fe12 100644
--- a/hw/mcu/stm/stm32l0xx/include/mcu/cortex_m0.h
+++ b/hw/mcu/stm/stm32l0xx/include/mcu/cortex_m0.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32l1xx/include/mcu/cortex_m3.h b/hw/mcu/stm/stm32l1xx/include/mcu/cortex_m3.h
index cf0f2a6..41d945f 100644
--- a/hw/mcu/stm/stm32l1xx/include/mcu/cortex_m3.h
+++ b/hw/mcu/stm/stm32l1xx/include/mcu/cortex_m3.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32l4xx/include/mcu/cortex_m4.h b/hw/mcu/stm/stm32l4xx/include/mcu/cortex_m4.h
index 22ce8b3..7697201 100644
--- a/hw/mcu/stm/stm32l4xx/include/mcu/cortex_m4.h
+++ b/hw/mcu/stm/stm32l4xx/include/mcu/cortex_m4.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32wbxx/include/mcu/cortex_m4.h b/hw/mcu/stm/stm32wbxx/include/mcu/cortex_m4.h
index 27377da..5a04e73 100644
--- a/hw/mcu/stm/stm32wbxx/include/mcu/cortex_m4.h
+++ b/hw/mcu/stm/stm32wbxx/include/mcu/cortex_m4.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __BKPT(1);
+}
+
 #ifdef __cplusplus
 }
 #endif


[mynewt-core] 03/07: Add HAL_DEBUG_BREAK

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit f20a9d358f996979b047f1a947e3fd14e583d1fd
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri May 10 14:48:39 2019 +0200

    Add HAL_DEBUG_BREAK
    
    HAL_DEBUG_BREAK sets software breakpoint that if debugger is present
    stop execution.
    Before execution is stopped user provided function hal_break_hook()
    is called that can change configuration of hardware when leaving
    CPU stopped could damage device.
    
    Software breakpoints placed with HAL_DEBUG_BREAK can be disabled
    by setting HAL_ENABLE_SOFTWARE_BREAKPOINTS syscfg value to 0.
    
    Example package is added that shows how such callback could be used.
    Example package defines hal_break_hook() and syscfg variable that
    activates it.
---
 hw/hal/include/hal/hal_debug.h                     | 61 ++++++++++++++++++++++
 hw/hal/syscfg.yml                                  |  5 ++
 hw/util/break_hook_example/pkg.yml                 | 37 +++++++++++++
 .../break_hook_example/src/break_hook_example.c    | 27 ++++++++++
 hw/{hal => util/break_hook_example}/syscfg.yml     | 27 ++--------
 5 files changed, 134 insertions(+), 23 deletions(-)

diff --git a/hw/hal/include/hal/hal_debug.h b/hw/hal/include/hal/hal_debug.h
new file mode 100644
index 0000000..165daea
--- /dev/null
+++ b/hw/hal/include/hal/hal_debug.h
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * 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.
+ */
+
+
+/**
+ * @addtogroup HAL
+ * @{
+ *   @defgroup HALDebug HAL Debug
+ *   @{
+ */
+
+#ifndef H_HAL_DEBUG_
+#define H_HAL_DEBUG_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <syscfg/syscfg.h>
+
+#if MYNEWT_VAL(HAL_BREAK_HOOK)
+/* User defined function to be called before code is stopped in debugger */
+void hal_break_hook(void);
+#else
+static inline void hal_break_hook() {}
+#endif
+
+#ifndef HAL_DEBUG_BREAK
+#define HAL_DEBUG_BREAK()                                      \
+        (void)(MYNEWT_VAL(HAL_ENABLE_SOFTWARE_BREAKPOINTS) &&  \
+               hal_debugger_connected() &&                     \
+               (hal_break_hook(), 1) &&                        \
+               (hal_debug_break(), 1))
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_HAL_DEBUG_ */
+
+/**
+ *   @} HALDebug
+ * @} HAL
+ */
diff --git a/hw/hal/syscfg.yml b/hw/hal/syscfg.yml
index 4b67dce..29bd002 100644
--- a/hw/hal/syscfg.yml
+++ b/hw/hal/syscfg.yml
@@ -37,6 +37,11 @@ syscfg.defs:
         description: >
             If set, hal system reset callback gets called inside hal_system_reset().
         value: 0
+    HAL_ENABLE_SOFTWARE_BREAKPOINTS:
+        description: >
+            If set to 0 software breakpoints placed with HAL_DEBUG_BREAK macro will not
+            be executed.
+        value: 1
 
 syscfg.vals.OS_DEBUG_MODE:
     HAL_FLASH_VERIFY_WRITES: 1
diff --git a/hw/util/break_hook_example/pkg.yml b/hw/util/break_hook_example/pkg.yml
new file mode 100644
index 0000000..cf27252
--- /dev/null
+++ b/hw/util/break_hook_example/pkg.yml
@@ -0,0 +1,37 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# 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,
+# 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.
+#
+
+pkg.name: hw/util/break_hook_example
+pkg.description: >
+    Break hook example.
+    This package defines HAL_BREAK_HOOK syscfg value which informs HAL_DEBUG_BREAK to
+    use user provided callback before execution stops.
+    Example prints some log. Production code hook should not do any printing it should
+    do minimum to leave platform in safe state before CPU stops.
+
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - break_hook
+
+pkg.deps:
+    - "@apache-mynewt-core/hw/hal"
+
+pkg.req_apis:
+    - console
diff --git a/hw/util/break_hook_example/src/break_hook_example.c b/hw/util/break_hook_example/src/break_hook_example.c
new file mode 100644
index 0000000..e03f64c
--- /dev/null
+++ b/hw/util/break_hook_example/src/break_hook_example.c
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * 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.
+ */
+
+#include <syscfg/syscfg.h>
+#include <console/console.h>
+
+void
+hal_break_hook(void)
+{
+    console_printf("hal_break_hook called\n");
+}
diff --git a/hw/hal/syscfg.yml b/hw/util/break_hook_example/syscfg.yml
similarity index 51%
copy from hw/hal/syscfg.yml
copy to hw/util/break_hook_example/syscfg.yml
index 4b67dce..181eff7 100644
--- a/hw/hal/syscfg.yml
+++ b/hw/util/break_hook_example/syscfg.yml
@@ -1,3 +1,4 @@
+#
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -17,27 +18,7 @@
 #
 
 syscfg.defs:
-    HAL_FLASH_VERIFY_WRITES:
-        description: >
-            If enabled, flash contents are read back and verified after each
-            write.
-        value: 0
-    HAL_FLASH_VERIFY_ERASES:
-        description: >
-            If enabled, flash contents are read back and verified after each
-            erase.
-        value: 0
-    HAL_FLASH_VERIFY_BUF_SZ:
+    HAL_BREAK_HOOK:
         description: >
-            The buffer size to use when verifying writes and erases.  One
-            buffer of this size is allocated on the stack during verify
-            operations.
-        value: 16
-    HAL_SYSTEM_RESET_CB:
-        description: >
-            If set, hal system reset callback gets called inside hal_system_reset().
-        value: 0
-
-syscfg.vals.OS_DEBUG_MODE:
-    HAL_FLASH_VERIFY_WRITES: 1
-    HAL_FLASH_VERIFY_ERASES: 1
+            Informs hal that hal_break_hook exists and should be used.
+        value: 1


[mynewt-core] 04/07: os_fault: Break into debugger before fault handler is executed

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit d6718428c979b63a6e89b2663ccfe9436e69907d
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri May 10 14:57:04 2019 +0200

    os_fault: Break into debugger before fault handler is executed
    
    Change allows to stop execution at asserting line instead of
    inside __assert_func().
    This small change makes it easier to debug code.
    When debugger is not connected normal call to __assert_func() is done.
    User provided hook can be executed before debugger stop execution.
---
 kernel/os/include/os/os_fault.h       | 7 +++++--
 sys/sysinit/include/sysinit/sysinit.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/os/include/os/os_fault.h b/kernel/os/include/os/os_fault.h
index 1a3c6f5..e830e7a 100644
--- a/kernel/os/include/os/os_fault.h
+++ b/kernel/os/include/os/os_fault.h
@@ -21,6 +21,9 @@
 #define _OS_FAULT_H
 
 #include "syscfg/syscfg.h"
+#include "os/os_arch.h"
+#include "hal/hal_system.h"
+#include "hal/hal_debug.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -30,9 +33,9 @@ void __assert_func(const char *file, int line, const char *func, const char *e)
     __attribute((noreturn));
 
 #if MYNEWT_VAL(OS_CRASH_FILE_LINE)
-#define OS_CRASH() __assert_func(__FILE__, __LINE__, NULL, NULL)
+#define OS_CRASH() (HAL_DEBUG_BREAK(), __assert_func(__FILE__, __LINE__, NULL, NULL))
 #else
-#define OS_CRASH() __assert_func(NULL, 0, NULL, NULL)
+#define OS_CRASH() (HAL_DEBUG_BREAK(), __assert_func(NULL, 0, NULL, NULL))
 #endif
 
 #ifdef __cplusplus
diff --git a/sys/sysinit/include/sysinit/sysinit.h b/sys/sysinit/include/sysinit/sysinit.h
index 7694c42..d30cb57 100644
--- a/sys/sysinit/include/sysinit/sysinit.h
+++ b/sys/sysinit/include/sysinit/sysinit.h
@@ -67,6 +67,7 @@ void sysinit_panic_set(sysinit_panic_fn *panic_fn);
 #define SYSINIT_PANIC_ASSERT_MSG(rc, msg) do \
 {                                            \
     if (!(rc)) {                             \
+        HAL_DEBUG_BREAK();                   \
         SYSINIT_PANIC_MSG(msg);              \
     }                                        \
 } while (0)


[mynewt-core] 05/07: hal_system: Use HAL_DEBUG_BREAK

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 6c2195d9fde7e9ae1559a06c9ef7442f2bf1d35e
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri May 10 15:20:16 2019 +0200

    hal_system: Use HAL_DEBUG_BREAK
    
    in hal_system_reset() use HAL_DEBUG_BREAK() instead of
    explicit asm code.
---
 hw/mcu/ambiq/apollo2/src/hal_system.c    |  7 +------
 hw/mcu/arc/snps/src/hal_system.c         |  7 +------
 hw/mcu/dialog/da1469x/src/hal_system.c   |  4 +---
 hw/mcu/nordic/nrf52xxx/src/hal_system.c  | 11 +++--------
 hw/mcu/nxp/MK64F12/src/hal_system.c      |  7 +------
 hw/mcu/sifive/fe310/src/hal_system.c     |  6 ++----
 hw/mcu/stm/stm32_common/src/hal_system.c |  7 +------
 7 files changed, 10 insertions(+), 39 deletions(-)

diff --git a/hw/mcu/ambiq/apollo2/src/hal_system.c b/hw/mcu/ambiq/apollo2/src/hal_system.c
index 6b9f850..43058d8 100644
--- a/hw/mcu/ambiq/apollo2/src/hal_system.c
+++ b/hw/mcu/ambiq/apollo2/src/hal_system.c
@@ -39,12 +39,7 @@ hal_system_reset(void)
 #endif
 
     while (1) {
-        if (hal_debugger_connected()) {
-            /*
-             * If debugger is attached, breakpoint here.
-             */
-            asm("bkpt");
-        }
+        HAL_DEBUG_BREAK();
         NVIC_SystemReset();
     }
 }
diff --git a/hw/mcu/arc/snps/src/hal_system.c b/hw/mcu/arc/snps/src/hal_system.c
index a1d1c9a..758f88e 100644
--- a/hw/mcu/arc/snps/src/hal_system.c
+++ b/hw/mcu/arc/snps/src/hal_system.c
@@ -44,12 +44,7 @@ hal_system_reset(void)
 #endif
 
     while (1) {
-        if (hal_debugger_connected()) {
-            /*
-             * If debugger is attached, breakpoint here.
-             */
-            asm("BRK_S");
-        }
+        HAL_DEBUG_BREAK();
 /* TODO: Reset system! */
         //NVIC_SystemReset();
     }
diff --git a/hw/mcu/dialog/da1469x/src/hal_system.c b/hw/mcu/dialog/da1469x/src/hal_system.c
index 7c260ee..53baf10 100644
--- a/hw/mcu/dialog/da1469x/src/hal_system.c
+++ b/hw/mcu/dialog/da1469x/src/hal_system.c
@@ -72,9 +72,7 @@ hal_system_reset(void)
 #endif
 
     while (1) {
-        if (hal_debugger_connected()) {
-            asm("bkpt");
-        }
+        HAL_DEBUG_BREAK();
         NVIC_SystemReset();
     }
 }
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_system.c b/hw/mcu/nordic/nrf52xxx/src/hal_system.c
index 64bd94d..bc39088 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_system.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_system.c
@@ -18,7 +18,9 @@
  */
 
 #include "syscfg/syscfg.h"
+#include "mcu/cortex_m4.h"
 #include "hal/hal_system.h"
+#include "hal/hal_debug.h"
 #include "nrf.h"
 
 /**
@@ -48,14 +50,7 @@ hal_system_reset(void)
 #endif
 
     while (1) {
-        if (hal_debugger_connected()) {
-            /*
-             * If debugger is attached, breakpoint here.
-             */
-#if !MYNEWT_VAL(MCU_DEBUG_IGNORE_BKPT)
-            asm("bkpt");
-#endif
-        }
+        HAL_DEBUG_BREAK();
         NVIC_SystemReset();
     }
 }
diff --git a/hw/mcu/nxp/MK64F12/src/hal_system.c b/hw/mcu/nxp/MK64F12/src/hal_system.c
index 6d141cf..eb85e5e 100644
--- a/hw/mcu/nxp/MK64F12/src/hal_system.c
+++ b/hw/mcu/nxp/MK64F12/src/hal_system.c
@@ -34,12 +34,7 @@ void hal_system_reset(void)
 #endif
 
     while (1) {
-        if (hal_debugger_connected()) {
-            /*
-             * If debugger is attached, breakpoint here.
-             */
-            asm("bkpt");
-        }
+        HAL_DEBUG_BREAK();
         NVIC_SystemReset();
     }
 }
diff --git a/hw/mcu/sifive/fe310/src/hal_system.c b/hw/mcu/sifive/fe310/src/hal_system.c
index 2a3ac7c..e8dda0e 100644
--- a/hw/mcu/sifive/fe310/src/hal_system.c
+++ b/hw/mcu/sifive/fe310/src/hal_system.c
@@ -29,10 +29,8 @@ hal_system_reset(void)
     hal_system_reset_cb();
 #endif
 
-    while(1) {
-        if (hal_debugger_connected()) {
-            asm ("ebreak");
-        }
+    while (1) {
+        HAL_DEBUG_BREAK();
     }
 }
 
diff --git a/hw/mcu/stm/stm32_common/src/hal_system.c b/hw/mcu/stm/stm32_common/src/hal_system.c
index f201678..04dc298 100644
--- a/hw/mcu/stm/stm32_common/src/hal_system.c
+++ b/hw/mcu/stm/stm32_common/src/hal_system.c
@@ -30,12 +30,7 @@ hal_system_reset(void)
 #endif
 
     while (1) {
-        if (hal_debugger_connected()) {
-            /*
-             * If debugger is attached, breakpoint here.
-             */
-            asm("bkpt");
-        }
+        HAL_DEBUG_BREAK();
         NVIC_SystemReset();
     }
 }


[mynewt-core] 07/07: mcu/mips: Add hal_debug_break implementation

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit c07422feb33fa88644fffa1751375047ebac85eb
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Nov 7 11:27:57 2019 +0100

    mcu/mips: Add hal_debug_break implementation
---
 hw/mcu/mips/danube/include/mcu/mips.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/mcu/mips/danube/include/mcu/mips.h b/hw/mcu/mips/danube/include/mcu/mips.h
index 5cf1b74..529cc1a 100644
--- a/hw/mcu/mips/danube/include/mcu/mips.h
+++ b/hw/mcu/mips/danube/include/mcu/mips.h
@@ -22,4 +22,10 @@
 
 #define OS_TICKS_PER_SEC    (1000)
 
+static inline void
+hal_debug_break(void)
+{
+    __asm ("break");
+}
+
 #endif /* __MCU_MIPS_H__ */


[mynewt-core] 02/07: riscv: Debugger detection

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 55400154767711b8fb761f472ea6232959a03bb2
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Aug 8 11:53:57 2019 +0200

    riscv: Debugger detection
    
    This is workaround for debugger detection and can be
    used till better way is found.
    
    Debugger sets magic value to one of hardware registers that
    is not used for anything else.
    hal_debugger_connected() checks this register for magic value
    set by debugger script.
    Debugger disconnection will not be detected.
---
 hw/bsp/hifive1/hifive1_debug.sh      | 3 ++-
 hw/mcu/sifive/fe310/src/hal_system.c | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/bsp/hifive1/hifive1_debug.sh b/hw/bsp/hifive1/hifive1_debug.sh
index e1dbc17..d9768b9 100755
--- a/hw/bsp/hifive1/hifive1_debug.sh
+++ b/hw/bsp/hifive1/hifive1_debug.sh
@@ -32,5 +32,6 @@
 FILE_NAME=$BIN_BASENAME.elf
 CFG="-f $CORE_PATH/hw/bsp/hifive1/riscv_openocd.cfg"
 GDB=riscv64-unknown-elf-gdb
-
+# Magic value that is checked inside hal_debugger_connected()
+EXTRA_GDB_CMDS="set *0x100000BC=0x5151A2BC"
 openocd_debug
diff --git a/hw/mcu/sifive/fe310/src/hal_system.c b/hw/mcu/sifive/fe310/src/hal_system.c
index 3c5f121..2a3ac7c 100644
--- a/hw/mcu/sifive/fe310/src/hal_system.c
+++ b/hw/mcu/sifive/fe310/src/hal_system.c
@@ -19,6 +19,7 @@
 
 #include "os/mynewt.h"
 #include "hal/hal_system.h"
+#include <platform.h>
 
 void
 hal_system_reset(void)
@@ -38,5 +39,9 @@ hal_system_reset(void)
 int
 hal_debugger_connected(void)
 {
-    return 0;
+    /*
+     * This always on domain register is now used to detect debugger
+     * connection. openocd scripts sets magic value 0x5151A2BC when connected.
+     */
+    return AON_REG(AON_BACKUP15) == 0x5151A2BC;
 }


[mynewt-core] 06/07: kernel: Remove software breakpoint from __assert_func

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 642da90738e3d17037803ccd8d4c66b333d2430e
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Aug 7 13:38:12 2019 +0200

    kernel: Remove software breakpoint from __assert_func
    
    In case of assert failure breakpoint is placed in faulting
    line. Removed code would stop again at breakpoint inside
    __assert_func which is redundant.
---
 kernel/os/src/arch/cortex_m0/os_fault.c  | 7 +------
 kernel/os/src/arch/cortex_m3/os_fault.c  | 7 +------
 kernel/os/src/arch/cortex_m33/os_fault.c | 7 +------
 kernel/os/src/arch/cortex_m4/os_fault.c  | 8 --------
 kernel/os/src/arch/cortex_m7/os_fault.c  | 6 ------
 5 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/kernel/os/src/arch/cortex_m0/os_fault.c b/kernel/os/src/arch/cortex_m0/os_fault.c
index 8e61c22..816b4b3 100644
--- a/kernel/os/src/arch/cortex_m0/os_fault.c
+++ b/kernel/os/src/arch/cortex_m0/os_fault.c
@@ -121,12 +121,7 @@ __assert_func(const char *file, int line, const char *func, const char *e)
 #if MYNEWT_VAL(OS_ASSERT_CB)
     os_assert_cb();
 #endif
-    if (hal_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. */
     hal_system_reset();
diff --git a/kernel/os/src/arch/cortex_m3/os_fault.c b/kernel/os/src/arch/cortex_m3/os_fault.c
index cfe94ab..a1e844e 100644
--- a/kernel/os/src/arch/cortex_m3/os_fault.c
+++ b/kernel/os/src/arch/cortex_m3/os_fault.c
@@ -134,12 +134,7 @@ __assert_func(const char *file, int line, const char *func, const char *e)
 #if MYNEWT_VAL(OS_ASSERT_CB)
     os_assert_cb();
 #endif
-    if (hal_debugger_connected()) {
-       /*
-        * If debugger is attached, breakpoint before the trap.
-        */
-       asm("bkpt");
-    }
+
     SCB->ICSR = SCB_ICSR_NMIPENDSET_Msk;
     asm("isb");
     hal_system_reset();
diff --git a/kernel/os/src/arch/cortex_m33/os_fault.c b/kernel/os/src/arch/cortex_m33/os_fault.c
index a1b0bd8..5c45da9 100644
--- a/kernel/os/src/arch/cortex_m33/os_fault.c
+++ b/kernel/os/src/arch/cortex_m33/os_fault.c
@@ -144,12 +144,7 @@ __assert_func(const char *file, int line, const char *func, const char *e)
 #if MYNEWT_VAL(OS_ASSERT_CB)
     os_assert_cb();
 #endif
-    if (hal_debugger_connected()) {
-       /*
-        * If debugger is attached, breakpoint before the trap.
-        */
-       asm("bkpt");
-    }
+
     SCB->ICSR = SCB_ICSR_PENDNMISET_Msk;
     asm("isb");
     hal_system_reset();
diff --git a/kernel/os/src/arch/cortex_m4/os_fault.c b/kernel/os/src/arch/cortex_m4/os_fault.c
index 55cb83e..6809f90 100644
--- a/kernel/os/src/arch/cortex_m4/os_fault.c
+++ b/kernel/os/src/arch/cortex_m4/os_fault.c
@@ -151,14 +151,6 @@ __assert_func(const char *file, int line, const char *func, const char *e)
     os_assert_cb();
 #endif
 
-    if (hal_debugger_connected()) {
-       /*
-        * If debugger is attached, breakpoint before the trap.
-        */
-#if !MYNEWT_VAL(MCU_DEBUG_IGNORE_BKPT)
-       asm("bkpt");
-#endif
-    }
     SCB->ICSR = SCB_ICSR_NMIPENDSET_Msk;
     asm("isb");
     hal_system_reset();
diff --git a/kernel/os/src/arch/cortex_m7/os_fault.c b/kernel/os/src/arch/cortex_m7/os_fault.c
index 6b138b5..c0c5e1b 100644
--- a/kernel/os/src/arch/cortex_m7/os_fault.c
+++ b/kernel/os/src/arch/cortex_m7/os_fault.c
@@ -134,12 +134,6 @@ __assert_func(const char *file, int line, const char *func, const char *e)
     os_assert_cb();
 #endif
 
-    if (hal_debugger_connected()) {
-       /*
-        * If debugger is attached, breakpoint before the trap.
-        */
-       asm("bkpt");
-    }
     SCB->ICSR = SCB_ICSR_NMIPENDSET_Msk;
     asm("isb");
     hal_system_reset();