Skip to content

Commit dbdd04e

Browse files
committed
drivers: debub: coresight: Added coresight_nrf
Added driver and bindings for the coresight nrf submodule. add integrated it for the nrf54h20. The coresight subsystem is a combination of ARM Coresight peripherals that get configured together to achieve a simplified configuration based on a desired operating mode. This also replaces the previous handling in the nrf54h20 soc.c which was powering the subsystem up but not configuring it. Signed-off-by: Karsten Koenig <[email protected]>
1 parent 99e1955 commit dbdd04e

File tree

12 files changed

+669
-94
lines changed

12 files changed

+669
-94
lines changed

drivers/debug/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
zephyr_library()
55

66
# zephyr-keep-sorted-start
7-
zephyr_library_sources_ifdef(CONFIG_DEBUG_SILABS_PTI debug_silabs_pti.c)
7+
zephyr_library_sources_ifdef(CONFIG_DEBUG_CORESIGHT_NRF debug_coresight_nrf.c)
88
zephyr_library_sources_ifdef(CONFIG_DEBUG_NRF_ETR debug_nrf_etr.c)
9+
zephyr_library_sources_ifdef(CONFIG_DEBUG_SILABS_PTI debug_silabs_pti.c)
910
# zephyr-keep-sorted-stop

drivers/debug/Kconfig.nrf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,68 @@ config DEBUG_NRF_ETR_SHELL_ASYNC_RX_BUFFER_COUNT
111111
endif # DEBUG_NRF_ETR_SHELL
112112

113113
endif # DEBUG_NRF_ETR
114+
115+
menuconfig DEBUG_CORESIGHT_NRF
116+
bool "Coresight Trace support"
117+
default y
118+
depends on DT_HAS_NORDIC_CORESIGHT_NRF_ENABLED
119+
select PINCTRL
120+
select NRF_IRONSIDE_TDD_SERVICE
121+
help
122+
Support CoreSight peripherals in Test and Debug Domain for ARM
123+
CoreSight System Trace Macrocell (STM) trace support.
124+
125+
if DEBUG_CORESIGHT_NRF
126+
127+
config DEBUG_CORESIGHT_NRF_ATB_TRACE_ID_STM_GLOBAL
128+
def_hex 0x40
129+
help
130+
Global trace ID used by STM.
131+
132+
config DEBUG_CORESIGHT_NRF_STM_SYNC_BYTE_COUNT
133+
int "STM: Emit synhronization packet every N bytes"
134+
range 0 4095
135+
default 512
136+
137+
config DEBUG_CORESIGHT_NRF_STM_HWEVENTS
138+
bool "STM: Enable hardware events"
139+
help
140+
Enable the output of hardware events in STM.
141+
142+
config DEBUG_CORESIGHT_NRF_TPIU_FFCR_TRIG
143+
bool "TPIU: Use flush request trigger"
144+
default y
145+
help
146+
Use CTI channel 1 for triggering flush request in TPIU.
147+
148+
config DEBUG_CORESIGHT_NRF_TPIU_SYNC_FRAME_COUNT
149+
int "TPIU: Emit synchronisation packet every N frames"
150+
default 8
151+
152+
config DEBUG_CORESIGHT_NRF_TPIU_PORTSIZE
153+
int "TPIU: Size of the current TPIU port in bits"
154+
range 1 32
155+
default 4
156+
157+
config DEBUG_CORESIGHT_NRF_ATBFUNNEL_HOLD_TIME
158+
int "ATBFUNNEL: Hold time for the transaction"
159+
range 1 15
160+
default 4
161+
help
162+
Number of transactions that are output on the funnel master port from the
163+
same slave.
164+
165+
config DEBUG_CORESIGHT_NRF_TSGEN_CLK_DIV
166+
int
167+
default 8
168+
help
169+
Clock division factor for generating trace timestamps. The timestamp
170+
counter should not be slower than 10% of the fastest processor clock
171+
frequency in the system, therefore its clock speed is divided by
172+
eight.
173+
174+
module = DEBUG_CORESIGHT_NRF
175+
module-str = CoreSight Trace
176+
source "subsys/logging/Kconfig.template.log_config"
177+
178+
endif # DEBUG_CORESIGHT_NRF

drivers/debug/coresight_arm.h

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef CORESIGHT_ARM_H_
8+
#define CORESIGHT_ARM_H_
9+
10+
#include <stdint.h>
11+
#include <stdbool.h>
12+
#include <errno.h>
13+
#include <zephyr/sys/sys_io.h>
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/**
20+
* @file
21+
* @brief Generic ARM CoreSight Hardware Abstraction Layer
22+
*
23+
* This HAL provides generic register definitions and utility functions for ARM CoreSight
24+
* peripherals. Platform-specific drivers should provide base addresses and use these
25+
* generic definitions for register access.
26+
*/
27+
28+
/* Common CoreSight unlock key as defined by ARM architecture */
29+
#define CORESIGHT_UNLOCK_KEY (0xC5ACCE55UL)
30+
31+
/* CoreSight register offsets */
32+
33+
/* Common CoreSight peripheral register offsets (found at the end of all CoreSight peripherals) */
34+
#define CORESIGHT_CLAIMSET_OFFSET (0xFA0UL) /* Claim Tag Set Register */
35+
#define CORESIGHT_CLAIMCLR_OFFSET (0xFA4UL) /* Claim Tag Clear Register */
36+
#define CORESIGHT_LAR_OFFSET (0xFB0UL) /* Lock Access Register */
37+
#define CORESIGHT_LSR_OFFSET (0xFB4UL) /* Lock Status Register */
38+
39+
/* ATB Funnel register offsets */
40+
#define ATBFUNNEL_CTRLREG_OFFSET (0x000UL) /* Control Register */
41+
42+
/* ATB Replicator register offsets */
43+
#define ATBREPLICATOR_IDFILTER0_OFFSET (0x000UL) /* ID Filter Register 0 */
44+
#define ATBREPLICATOR_IDFILTER1_OFFSET (0x004UL) /* ID Filter Register 1 */
45+
46+
/* ETR (Embedded Trace Router/TMC-ETR) register offsets */
47+
#define ETR_RSZ_OFFSET (0x004UL) /* RAM Size Register */
48+
#define ETR_RWP_OFFSET (0x018UL) /* RAM Write Pointer Register */
49+
#define ETR_CTL_OFFSET (0x020UL) /* Control Register */
50+
#define ETR_MODE_OFFSET (0x028UL) /* Mode Register */
51+
#define ETR_DBALO_OFFSET (0x118UL) /* Data Buffer Address Low Register */
52+
#define ETR_DBAHI_OFFSET (0x11CUL) /* Data Buffer Address High Register */
53+
#define ETR_FFCR_OFFSET (0x304UL) /* Formatter and Flush Control Register */
54+
55+
/* STM (System Trace Macrocell) register offsets */
56+
#define STM_STMHEER_OFFSET (0xD00UL) /* Hardware Event Enable Register */
57+
#define STM_STMHEMCR_OFFSET (0xD64UL) /* Hardware Event Master Control Register */
58+
#define STM_STMSPER_OFFSET (0xE00UL) /* Stimulus Port Enable Register */
59+
#define STM_STMTCSR_OFFSET (0xE80UL) /* Trace Control and Status Register */
60+
#define STM_STMTSFREQR_OFFSET (0xE8CUL) /* Timestamp Frequency Register */
61+
#define STM_STMSYNCR_OFFSET (0xE90UL) /* Synchronization Control Register */
62+
#define STM_STMAUXCR_OFFSET (0xE94UL) /* Auxiliary Control Register */
63+
64+
/* TPIU (Trace Port Interface Unit) register offsets */
65+
#define TPIU_CSPSR_OFFSET (0x004UL) /* Current Parallel Port Size Register */
66+
#define TPIU_FFCR_OFFSET (0x304UL) /* Formatter and Flush Control Register */
67+
#define TPIU_FSCR_OFFSET (0x308UL) /* Formatter Synchronization Counter Register */
68+
69+
/* CTI (Cross Trigger Interface) register offsets */
70+
#define CTI_CTICONTROL_OFFSET (0x000UL) /* CTI Control Register */
71+
#define CTI_CTIOUTEN0_OFFSET (0x0A0UL) /* CTI Trigger Output Enable Register 0 */
72+
#define CTI_CTIGATE_OFFSET (0x140UL) /* CTI Channel Gate Enable Register */
73+
74+
/* TSGEN (Timestamp Generator) register offsets */
75+
#define TSGEN_CNTCR_OFFSET (0x000UL) /* Counter Control Register */
76+
#define TSGEN_CNTFID0_OFFSET (0x020UL) /* Counter Frequency ID Register 0 */
77+
78+
/* Lock Status Register (LSR) bit fields */
79+
#define CORESIGHT_LSR_LOCKED_Pos (1UL)
80+
#define CORESIGHT_LSR_LOCKED_Msk (0x1UL << CORESIGHT_LSR_LOCKED_Pos)
81+
#define CORESIGHT_LSR_PRESENT_Pos (0UL)
82+
#define CORESIGHT_LSR_PRESENT_Msk (0x1UL << CORESIGHT_LSR_PRESENT_Pos)
83+
84+
/* STM Trace Control and Status Register (STMTCSR) bit fields */
85+
#define STM_STMTCSR_EN_Pos (0UL)
86+
#define STM_STMTCSR_EN_Msk (0x1UL << STM_STMTCSR_EN_Pos)
87+
#define STM_STMTCSR_TSEN_Pos (1UL)
88+
#define STM_STMTCSR_TSEN_Msk (0x1UL << STM_STMTCSR_TSEN_Pos)
89+
#define STM_STMTCSR_TRACEID_Pos (16UL)
90+
#define STM_STMTCSR_TRACEID_Msk (0x7FUL << STM_STMTCSR_TRACEID_Pos)
91+
92+
/* STM Hardware Event Master Control Register (STMHEMCR) bit fields */
93+
#define STM_STMHEMCR_EN_Pos (0UL)
94+
#define STM_STMHEMCR_EN_Msk (0x1UL << STM_STMHEMCR_EN_Pos)
95+
96+
/* STM Auxiliary Control Register (STMAUXCR) bit fields */
97+
#define STM_STMAUXCR_FIFOAF_Pos (0UL)
98+
#define STM_STMAUXCR_FIFOAF_Msk (0x1UL << STM_STMAUXCR_FIFOAF_Pos)
99+
100+
/* CTI Control Register (CTICONTROL) bit fields */
101+
#define CTI_CTICONTROL_GLBEN_Pos (0UL)
102+
#define CTI_CTICONTROL_GLBEN_Msk (0x1UL << CTI_CTICONTROL_GLBEN_Pos)
103+
104+
/* TPIU Formatter and Flush Control Register (FFCR) bit fields */
105+
#define TPIU_FFCR_ENFCONT_Pos (1UL)
106+
#define TPIU_FFCR_ENFCONT_Msk (0x1UL << TPIU_FFCR_ENFCONT_Pos)
107+
#define TPIU_FFCR_FONFLIN_Pos (4UL)
108+
#define TPIU_FFCR_FONFLIN_Msk (0x1UL << TPIU_FFCR_FONFLIN_Pos)
109+
#define TPIU_FFCR_ENFTC_Pos (0UL)
110+
#define TPIU_FFCR_ENFTC_Msk (0x1UL << TPIU_FFCR_ENFTC_Pos)
111+
112+
/* ETR Mode Register bit fields */
113+
#define ETR_MODE_MODE_Pos (0UL)
114+
#define ETR_MODE_MODE_Msk (0x3UL << ETR_MODE_MODE_Pos)
115+
#define ETR_MODE_MODE_CIRCULARBUF (0UL) /* Circular Buffer mode */
116+
#define ETR_MODE_MODE_SWFIFO1 (1UL) /* Software FIFO mode */
117+
#define ETR_MODE_MODE_HWFIFO (2UL) /* Hardware FIFO mode */
118+
#define ETR_MODE_MODE_SWFIFO2 (3UL) /* Software FIFO mode */
119+
120+
/* ETR Control Register bit fields */
121+
#define ETR_CTL_TRACECAPTEN_Pos (0UL)
122+
#define ETR_CTL_TRACECAPTEN_Msk (0x1UL << ETR_CTL_TRACECAPTEN_Pos)
123+
124+
/* ETR Formatter and Flush Control Register (FFCR) bit fields */
125+
#define ETR_FFCR_ENFT_Pos (0UL)
126+
#define ETR_FFCR_ENFT_Msk (0x1UL << ETR_FFCR_ENFT_Pos)
127+
#define ETR_FFCR_ENTI_Pos (1UL)
128+
#define ETR_FFCR_ENTI_Msk (0x1UL << ETR_FFCR_ENTI_Pos)
129+
130+
/* ATB Funnel Control Register bit fields */
131+
#define ATBFUNNEL_CTRLREG_ENS0_Pos (0UL)
132+
#define ATBFUNNEL_CTRLREG_ENS0_Msk (0x1UL << ATBFUNNEL_CTRLREG_ENS0_Pos)
133+
#define ATBFUNNEL_CTRLREG_ENS1_Pos (1UL)
134+
#define ATBFUNNEL_CTRLREG_ENS1_Msk (0x1UL << ATBFUNNEL_CTRLREG_ENS1_Pos)
135+
#define ATBFUNNEL_CTRLREG_ENS2_Pos (2UL)
136+
#define ATBFUNNEL_CTRLREG_ENS2_Msk (0x1UL << ATBFUNNEL_CTRLREG_ENS2_Pos)
137+
#define ATBFUNNEL_CTRLREG_ENS3_Pos (3UL)
138+
#define ATBFUNNEL_CTRLREG_ENS3_Msk (0x1UL << ATBFUNNEL_CTRLREG_ENS3_Pos)
139+
#define ATBFUNNEL_CTRLREG_ENS4_Pos (4UL)
140+
#define ATBFUNNEL_CTRLREG_ENS4_Msk (0x1UL << ATBFUNNEL_CTRLREG_ENS4_Pos)
141+
#define ATBFUNNEL_CTRLREG_ENS5_Pos (5UL)
142+
#define ATBFUNNEL_CTRLREG_ENS5_Msk (0x1UL << ATBFUNNEL_CTRLREG_ENS5_Pos)
143+
#define ATBFUNNEL_CTRLREG_ENS6_Pos (6UL)
144+
#define ATBFUNNEL_CTRLREG_ENS6_Msk (0x1UL << ATBFUNNEL_CTRLREG_ENS6_Pos)
145+
#define ATBFUNNEL_CTRLREG_ENS7_Pos (7UL)
146+
#define ATBFUNNEL_CTRLREG_ENS7_Msk (0x1UL << ATBFUNNEL_CTRLREG_ENS7_Pos)
147+
#define ATBFUNNEL_CTRLREG_HT_Pos (8UL)
148+
#define ATBFUNNEL_CTRLREG_HT_Msk (0xFUL << ATBFUNNEL_CTRLREG_HT_Pos)
149+
150+
/* TSGEN Counter Control Register bit fields */
151+
#define TSGEN_CNTCR_EN_Pos (0UL)
152+
#define TSGEN_CNTCR_EN_Msk (0x1UL << TSGEN_CNTCR_EN_Pos)
153+
154+
/**
155+
* @brief Check if a CoreSight peripheral is locked
156+
*
157+
* @param base_addr Base address of CoreSight peripheral
158+
* @return true if peripheral is locked, false otherwise
159+
*/
160+
static inline bool coresight_is_locked(mem_addr_t base_addr)
161+
{
162+
uint32_t lsr = *(volatile uint32_t *)(base_addr + CORESIGHT_LSR_OFFSET);
163+
164+
return (lsr & CORESIGHT_LSR_LOCKED_Msk) != 0;
165+
}
166+
167+
/**
168+
* @brief Unlock a CoreSight peripheral
169+
*
170+
* @param base_addr Base address of CoreSight peripheral
171+
* @retval 0 on success
172+
* @retval -EIO if unlock operation failed
173+
*/
174+
static inline int coresight_unlock(mem_addr_t base_addr)
175+
{
176+
*(volatile uint32_t *)(base_addr + CORESIGHT_LAR_OFFSET) = CORESIGHT_UNLOCK_KEY;
177+
178+
if (coresight_is_locked(base_addr)) {
179+
return -EIO;
180+
}
181+
182+
return 0;
183+
}
184+
185+
/**
186+
* @brief Lock a CoreSight peripheral
187+
*
188+
* @param base_addr Base address of CoreSight peripheral
189+
* @retval 0 on success
190+
* @retval -EIO if lock operation failed
191+
*/
192+
static inline int coresight_lock(mem_addr_t base_addr)
193+
{
194+
/* Write any value other than unlock key to Lock Access Register to lock */
195+
*(volatile uint32_t *)(base_addr + CORESIGHT_LAR_OFFSET) = 0x00000000;
196+
197+
if (!coresight_is_locked(base_addr)) {
198+
return -EIO;
199+
}
200+
201+
return 0;
202+
}
203+
204+
#ifdef __cplusplus
205+
}
206+
#endif
207+
208+
#endif /* CORESIGHT_ARM_H_ */

0 commit comments

Comments
 (0)