You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2020/11/25 12:07:58 UTC
[mynewt-core] 01/05: hw/mcu/dialog: Add support for Micro Trace
Buffer (MTB)
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit c4c5236fd867ed2fadd509be9127d637604ecfa0
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Sat Nov 21 01:27:53 2020 +0100
hw/mcu/dialog: Add support for Micro Trace Buffer (MTB)
This adds support for Micro Trace Buffer (MTB) which allows to store
trace information of executed instructions in dedicated RAM area.
Stored data can be then used to recreate exact program flow.
MTB support is enabled by "MCU_MTB_ENABLE: 1". This will configure
MTB on boot, enable code which persists MTB registers state in deep
sleep and also reserves last 8KB of RAM for trace buffer.
Additionally, by setting "MCU_MTB_AUTO_START: 1", MTB is enabled on
boot.
Note that enabling MTB changes main stack location since it cannot be
placed at the end of RAM anymore since that area (8KB) is used by MTB.
Make sure to rebuild flash loader, bootloader and app with new code as
otherwise jumping from bootloader to app or from app to flash loader
will fail.
---
.../src/arch/cortex_m33/gcc_startup_da1469x.S | 22 +++++++++++++++++++
hw/mcu/dialog/da1469x/da1469x.ld | 9 +++++++-
.../src/arch/cortex_m33/da1469x_m33_sleep.S | 25 ++++++++++++++++++++++
hw/mcu/dialog/da1469x/src/system_da1469x.c | 5 +++++
hw/mcu/dialog/da1469x/syscfg.yml | 13 +++++++++++
5 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/hw/bsp/dialog_da1469x-dk-pro/src/arch/cortex_m33/gcc_startup_da1469x.S b/hw/bsp/dialog_da1469x-dk-pro/src/arch/cortex_m33/gcc_startup_da1469x.S
index 616f319..d173f79 100644
--- a/hw/bsp/dialog_da1469x-dk-pro/src/arch/cortex_m33/gcc_startup_da1469x.S
+++ b/hw/bsp/dialog_da1469x-dk-pro/src/arch/cortex_m33/gcc_startup_da1469x.S
@@ -32,6 +32,9 @@
.equ SYS_CTRL_REG, 0x50000024
.equ CACHE_FLASH_REG, 0x100C0040
.equ RESET_STAT_REG, 0x500000BC
+ .equ MTB_POSITION_REG, 0xE0043000
+ .equ MTB_MASTER_REG, 0xE0043004
+ .equ MTB_FLOW_REG, 0xE0043008
.globl __StackTop
.globl __StackLimit
@@ -154,6 +157,25 @@ wakeup_handler:
.globl Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
+#if MYNEWT_VAL(MCU_MTB_ENABLE)
+ mov r2, #0
+ ldr r1, =MTB_POSITION_REG
+ str r2, [r1]
+ ldr r1, =MTB_FLOW_REG
+ str r2, [r1]
+ ldr r1, =MTB_MASTER_REG
+#if MYNEWT_VAL(MCU_MTB_AUTO_START)
+ ldr r2, =0x80000009
+#else
+ ldr r2, =0x00000009
+#endif
+ str r2, [r1]
+#else
+ ldr r1, =MTB_MASTER_REG
+ mov r2, #0
+ str r2, [r1]
+#endif
+
/* Make sure interrupt vector is remapped at 0x0 */
ldr r1, =SYS_CTRL_REG
ldrh r2, [r1, #0]
diff --git a/hw/mcu/dialog/da1469x/da1469x.ld b/hw/mcu/dialog/da1469x/da1469x.ld
index d76ef05..f6714d9 100644
--- a/hw/mcu/dialog/da1469x/da1469x.ld
+++ b/hw/mcu/dialog/da1469x/da1469x.ld
@@ -210,11 +210,18 @@ SECTIONS
*(.stack*)
} > RAM
+ /* Dummy section to calculate whether we need to move stack out of MTB
+ * buffer or not. */
+ .mtb (NOLOAD) :
+ {
+ KEEP(*(.mtb));
+ }
+
_ram_start = ORIGIN(RAM);
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
- __StackTop = ORIGIN(RAM) + LENGTH(RAM);
+ __StackTop = ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.mtb);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
diff --git a/hw/mcu/dialog/da1469x/src/arch/cortex_m33/da1469x_m33_sleep.S b/hw/mcu/dialog/da1469x/src/arch/cortex_m33/da1469x_m33_sleep.S
index df0d75e..d380465 100644
--- a/hw/mcu/dialog/da1469x/src/arch/cortex_m33/da1469x_m33_sleep.S
+++ b/hw/mcu/dialog/da1469x/src/arch/cortex_m33/da1469x_m33_sleep.S
@@ -46,6 +46,10 @@ da1469x_m33_sleep_state:
.saved_fpu:
.space 8 /* FPCCR, FPDSCR */
#endif
+#if MYNEWT_VAL(MCU_MTB_ENABLE)
+.saved_mtb:
+ .space 12 /* POSITION, MASTER, FLOW */
+#endif
.size da1469x_m33_sleep_state, . - da1469x_m33_sleep_state
@@ -64,6 +68,9 @@ da1469x_m33_sleep_state:
.equ QSPIC_CTRLBUS_OFFSET, 0x000
.equ QSPIC_CTRLMOD_OFFSET, 0x004
.equ QSPIC_WRITEDATA_OFFSET, 0x018
+ .equ MTB_POSITION_REG, 0xE0043000
+ .equ MTB_MASTER_REG, 0xE0043004
+ .equ MTB_FLOW_REG, 0xE0043008
.equ SCB_CPACR_MASK, 0x00F00000 /* CP10 and CP11 */
.equ SCB_SHCSR_MASK, 0x000F0000 /* xxxFAULTENA */
@@ -114,6 +121,13 @@ da1469x_m33_sleep:
stmia r3!, {r4-r5}
#endif
+#if MYNEWT_VAL(MCU_MTB_ENABLE)
+/* Save MTB state */
+ ldr r0, =MTB_POSITION_REG
+ ldm r0, {r4-r6}
+ stmia r3!, {r4-r6}
+#endif
+
/* Clear RESET_STAT_REG so wakeup handler can detect wakeup from deep sleep */
ldr r0, =RESET_STAT_REG
movs r3, #0
@@ -231,6 +245,17 @@ da1469x_m33_wakeup:
str r5, [r0, #(FPU_FPDSCR_OFFSET)]
#endif
+#if MYNEWT_VAL(MCU_MTB_ENABLE)
+/* Restore MTB state */
+ ldmia r3!, {r4-r6}
+ ldr r0, =MTB_POSITION_REG
+ str r4, [r0]
+ ldr r0, =MTB_FLOW_REG
+ str r6, [r0]
+ ldr r0, =MTB_MASTER_REG
+ str r5, [r0]
+#endif
+
/* Restore MSP, PSP and CONTROL */
ldr r3, =.saved_msp
ldmia r3!, {r0-r2}
diff --git a/hw/mcu/dialog/da1469x/src/system_da1469x.c b/hw/mcu/dialog/da1469x/src/system_da1469x.c
index 5539fd0..9d1e8f6 100644
--- a/hw/mcu/dialog/da1469x/src/system_da1469x.c
+++ b/hw/mcu/dialog/da1469x/src/system_da1469x.c
@@ -38,6 +38,11 @@
extern uint8_t __StackLimit;
+#if MYNEWT_VAL(MCU_MTB_ENABLE)
+/* Dummy symbol to reserve 8KB of RAM for MTB */
+uint32_t __attribute__((section(".mtb"))) mtb_dummy[2048];
+#endif
+
void
SystemInit(void)
{
diff --git a/hw/mcu/dialog/da1469x/syscfg.yml b/hw/mcu/dialog/da1469x/syscfg.yml
index 0671504..9369cf9 100644
--- a/hw/mcu/dialog/da1469x/syscfg.yml
+++ b/hw/mcu/dialog/da1469x/syscfg.yml
@@ -86,6 +86,19 @@ syscfg.defs:
general usage.
value: 0
+ MCU_MTB_ENABLE:
+ description: >
+ Enable support for Micro Trace Buffer (MTB).
+ This will reserve RAM space for MTB buffer, configure
+ MTB on boot and properly store/restore MTB registers
+ state during deep sleep to allow continuous trace.
+ value: 0
+ MCU_MTB_AUTO_START:
+ description: >
+ Auto start MTB trace on boot. If disabled, MTB can be
+ still enabled manually either via code or debugger.
+ value: 0
+
MCU_FLASH_MIN_WRITE_SIZE:
description: >
Specifies the required alignment for internal flash writes.