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 <[email protected]>
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;
 }

Reply via email to