refactor(hal): extract assist_debug, debug_probe and trace into esp_hal_debug_assist

Move the following modules from the hal component into a new dedicated
esp_hal_debug_assist component, following the esp_hal_timg pattern:

- assist_debug (hal + target-specific LL headers)
- debug_probe (types + target-specific LL headers)
- riscv_trace (hal + types + source + target-specific LL headers)
- trace_ll (esp32/esp32s2/esp32s3 target-specific LL headers)

Update the following components to depend on esp_hal_debug_assist:
esp_system, riscv, bootloader_support, esp_hw_support, esp_riscv_trace

Remove riscv_trace_hal.c from the hal component.
This commit is contained in:
morris
2026-07-21 11:28:11 +08:00
parent e8a5192a18
commit 26a22512eb
32 changed files with 459 additions and 242 deletions
@@ -1,247 +0,0 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
// The LL layer for DEBUG_ASSIST peripheral
#pragma once
#include "soc/assist_debug_reg.h"
#ifndef __ASSEMBLER__
#include <stdbool.h>
#include <stdint.h>
#include "esp_attr.h"
#include "soc/hp_sys_clkrst_struct.h"
#include "soc/bus_monitor_struct.h"
#include "soc/lp_clkrst_struct.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* The bus monitor peripheral provides stack overflow/underflow monitoring.
*
*/
FORCE_INLINE_ATTR void assist_debug_ll_sp_spill_monitor_enable(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.core_1_montr_ena.core_1_sp_spill_min_ena = 1;
BUS_MONITOR.core_1_montr_ena.core_1_sp_spill_max_ena = 1;
} else {
BUS_MONITOR.core_0_montr_ena.core_0_sp_spill_min_ena = 1;
BUS_MONITOR.core_0_montr_ena.core_0_sp_spill_max_ena = 1;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_sp_spill_monitor_disable(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.core_1_montr_ena.core_1_sp_spill_min_ena = 0;
BUS_MONITOR.core_1_montr_ena.core_1_sp_spill_max_ena = 0;
} else {
BUS_MONITOR.core_0_montr_ena.core_0_sp_spill_min_ena = 0;
BUS_MONITOR.core_0_montr_ena.core_0_sp_spill_max_ena = 0;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_sp_spill_interrupt_enable(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.core_1_intr_ena.core_1_sp_spill_min_intr_ena = 1;
BUS_MONITOR.core_1_intr_ena.core_1_sp_spill_max_intr_ena = 1;
} else {
BUS_MONITOR.core_0_intr_ena.core_0_sp_spill_min_intr_ena = 1;
BUS_MONITOR.core_0_intr_ena.core_0_sp_spill_max_intr_ena = 1;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_sp_spill_interrupt_disable(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.core_1_intr_ena.core_1_sp_spill_min_intr_ena = 0;
BUS_MONITOR.core_1_intr_ena.core_1_sp_spill_max_intr_ena = 0;
} else {
BUS_MONITOR.core_0_intr_ena.core_0_sp_spill_min_intr_ena = 0;
BUS_MONITOR.core_0_intr_ena.core_0_sp_spill_max_intr_ena = 0;
}
}
FORCE_INLINE_ATTR bool assist_debug_ll_sp_spill_is_fired(uint32_t core_id)
{
if (core_id) {
return BUS_MONITOR.core_1_intr_raw.core_1_sp_spill_min_raw || BUS_MONITOR.core_1_intr_raw.core_1_sp_spill_max_raw;
} else {
return BUS_MONITOR.core_0_intr_raw.core_0_sp_spill_min_raw || BUS_MONITOR.core_0_intr_raw.core_0_sp_spill_max_raw;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_sp_spill_interrupt_clear(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.core_1_intr_clr.core_1_sp_spill_min_clr = 1;
BUS_MONITOR.core_1_intr_clr.core_1_sp_spill_max_clr = 1;
} else {
BUS_MONITOR.core_0_intr_clr.core_0_sp_spill_min_clr = 1;
BUS_MONITOR.core_0_intr_clr.core_0_sp_spill_max_clr = 1;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_sp_spill_set_min(uint32_t core_id, uint32_t min)
{
if (core_id) {
BUS_MONITOR.core_1_sp_min.core_1_sp_min = min;
} else {
BUS_MONITOR.core_0_sp_min.core_0_sp_min = min;
}
}
FORCE_INLINE_ATTR uint32_t assist_debug_ll_sp_spill_get_min(uint32_t core_id)
{
if (core_id) {
return BUS_MONITOR.core_1_sp_min.core_1_sp_min;
} else {
return BUS_MONITOR.core_0_sp_min.core_0_sp_min;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_sp_spill_set_max(uint32_t core_id, uint32_t max)
{
if (core_id) {
BUS_MONITOR.core_1_sp_max.core_1_sp_max = max;
} else {
BUS_MONITOR.core_0_sp_max.core_0_sp_max = max;
}
}
FORCE_INLINE_ATTR uint32_t assist_debug_ll_sp_spill_get_max(uint32_t core_id)
{
if (core_id) {
return BUS_MONITOR.core_1_sp_max.core_1_sp_max;
} else {
return BUS_MONITOR.core_0_sp_max.core_0_sp_max;
}
}
FORCE_INLINE_ATTR uint32_t assist_debug_ll_sp_spill_get_pc(uint32_t core_id)
{
if (core_id) {
return BUS_MONITOR.core_1_sp_pc.core_1_sp_pc;
} else {
return BUS_MONITOR.core_0_sp_pc.core_0_sp_pc;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_enable_pc_recording(uint32_t core_id, bool enable)
{
if (core_id) {
BUS_MONITOR.core_1_rcd_en.core_1_rcd_pdebugen = enable;
BUS_MONITOR.core_1_rcd_en.core_1_rcd_recorden = enable;
} else {
BUS_MONITOR.core_0_rcd_en.core_0_rcd_pdebugen = enable;
BUS_MONITOR.core_0_rcd_en.core_0_rcd_recorden = enable;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_enable_bus_clock(uint32_t core_id, bool enable)
{
if (core_id) {
HP_SYS_CLKRST.busmon_ctrl0.reg_busmon_core1_clk_en = enable;
} else {
HP_SYS_CLKRST.busmon_ctrl0.reg_busmon_core0_clk_en = enable;
}
}
FORCE_INLINE_ATTR void assist_debug_ll_reset_register(uint32_t core_id)
{
if (core_id) {
HP_SYS_CLKRST.busmon_ctrl0.reg_busmon_core1_rst_en = true;
HP_SYS_CLKRST.busmon_ctrl0.reg_busmon_core1_rst_en = false;
} else {
HP_SYS_CLKRST.busmon_ctrl0.reg_busmon_core0_rst_en = true;
HP_SYS_CLKRST.busmon_ctrl0.reg_busmon_core0_rst_en = false;
}
}
FORCE_INLINE_ATTR bool assist_debug_ll_is_debugger_active(void)
{
return BUS_MONITOR.core_0_debug_mode.core_0_debug_module_active;
}
FORCE_INLINE_ATTR void assist_debug_ll_lockup_monitor_enable(uint32_t core_id, bool enable)
{
if (core_id) {
BUS_MONITOR.core_1_montr_ena.core_1_trace_lockup_ena = enable;
} else {
BUS_MONITOR.core_0_montr_ena.core_0_trace_lockup_ena = enable;
}
}
// trap_idx: 0 = latest trap, 1 = previous trap
// MCause for the exception
FORCE_INLINE_ATTR uint32_t assist_debug_ll_lockup_get_cause(uint32_t core_id, int trap_idx)
{
if (core_id) {
return trap_idx ? BUS_MONITOR.core_1_trace_lockup_cause_1.core_1_trace_lockup_recording_cause_1
: BUS_MONITOR.core_1_trace_lockup_cause_0.core_1_trace_lockup_recording_cause_0;
} else {
return trap_idx ? BUS_MONITOR.core_0_trace_lockup_cause_1.core_0_trace_lockup_recording_cause_1
: BUS_MONITOR.core_0_trace_lockup_cause_0.core_0_trace_lockup_recording_cause_0;
}
}
FORCE_INLINE_ATTR uint32_t assist_debug_ll_lockup_get_tval(uint32_t core_id, int trap_idx)
{
if (core_id) {
return trap_idx ? BUS_MONITOR.core_1_trace_lockup_tval_1.core_1_trace_lockup_recording_tval_1
: BUS_MONITOR.core_1_trace_lockup_tval_0.core_1_trace_lockup_recording_tval_0;
} else {
return trap_idx ? BUS_MONITOR.core_0_trace_lockup_tval_1.core_0_trace_lockup_recording_tval_1
: BUS_MONITOR.core_0_trace_lockup_tval_0.core_0_trace_lockup_recording_tval_0;
}
}
FORCE_INLINE_ATTR uint32_t assist_debug_ll_lockup_get_iaddr(uint32_t core_id, int trap_idx)
{
if (core_id) {
return trap_idx ? BUS_MONITOR.core_1_trace_lockup_iaddr_1.core_1_trace_lockup_recording_iaddr_1
: BUS_MONITOR.core_1_trace_lockup_iaddr_0.core_1_trace_lockup_recording_iaddr_0;
} else {
return trap_idx ? BUS_MONITOR.core_0_trace_lockup_iaddr_1.core_0_trace_lockup_recording_iaddr_1
: BUS_MONITOR.core_0_trace_lockup_iaddr_0.core_0_trace_lockup_recording_iaddr_0;
}
}
FORCE_INLINE_ATTR uint32_t assist_debug_ll_lockup_get_priv(uint32_t core_id, int trap_idx)
{
if (core_id) {
return trap_idx ? BUS_MONITOR.core_1_trace_lockup_priv_1.core_1_trace_lockup_recording_priv_1
: BUS_MONITOR.core_1_trace_lockup_priv_0.core_1_trace_lockup_recording_priv_0;
} else {
return trap_idx ? BUS_MONITOR.core_0_trace_lockup_priv_1.core_0_trace_lockup_recording_priv_1
: BUS_MONITOR.core_0_trace_lockup_priv_0.core_0_trace_lockup_recording_priv_0;
}
}
/* Enable the hardware lockup reset for the given core via LP_CLKRST.
* This controls whether a CPU lockup (exception inside exception handler) triggers
* a system reset. Defaults to 0 on S31 so must be explicitly set. */
FORCE_INLINE_ATTR void assist_debug_ll_lockup_reset_enable(uint32_t core_id)
{
if (core_id) {
LP_CLKRST.hpcore1_reset_ctrl.hpcore1_lockup_reset_en = 1;
} else {
LP_CLKRST.hpcore0_reset_ctrl.hpcore0_lockup_reset_en = 1;
}
}
#ifdef __cplusplus
}
#endif
#endif // __ASSEMBLER__
@@ -1,166 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "hal/misc.h"
#include "hal/assert.h"
#include "soc/hp_system_struct.h"
#include "soc/lp_system_struct.h"
#include "hal/debug_probe_types.h"
/**
* @brief Define how many channels are there in one debug probe unit
*/
#define DEBUG_PROBE_LL_CHANNELS_PER_UNIT 2
#ifdef __cplusplus
extern "C" {
#endif
// translate the HAL types into register values
#define DEBUG_PROBE_LL_PART_TO_REG_VAL(part) ((uint8_t[]) {0, 1}[(part)])
/**
* @brief Enable the debug probe module
*
* @param unit_id unit identifier, see debug_probe_unit_id_t
* @param en true: enable, false: disable
*/
static inline void debug_probe_ll_enable_unit(debug_probe_unit_id_t unit_id, bool en)
{
if (unit_id == DEBUG_PROBE_UNIT_HP) {
HP_SYSTEM.probea_ctrl.reg_probe_global_en = en;
} else {
LP_SYS.lp_probea_ctrl.probe_global_en = en;
}
}
/**
* @brief Enable a specific channel in the debug probe unit
*
* @param unit_id unit identifier, see debug_probe_unit_id_t
* @param channel channel number (only support 0 and 1)
* @param en true: enable, false: disable
*/
static inline void debug_probe_ll_enable_channel(debug_probe_unit_id_t unit_id, int channel, bool en)
{
// channel 0 is always enabled
if (channel == 1) {
if (unit_id == DEBUG_PROBE_UNIT_HP) {
HP_SYSTEM.probeb_ctrl.reg_probe_b_en = en;
} else {
LP_SYS.lp_probeb_ctrl.probe_b_en = en;
}
}
}
/**
* @brief Set the target module for a probe channel
*
* @param unit_id unit identifier, see debug_probe_unit_id_t
* @param channel channel number (only support 0 and 1)
* @param target_module HP: soc_debug_probe_target_t, LP: soc_debug_probe_target_lp_t
*/
static inline void debug_probe_ll_channel_set_target_module(debug_probe_unit_id_t unit_id, uint8_t channel, uint8_t target_module)
{
if (channel == 0) {
if (unit_id == DEBUG_PROBE_UNIT_HP) {
HP_SYSTEM.probea_ctrl.reg_probe_a_top_sel = target_module;
} else {
LP_SYS.lp_probea_ctrl.probe_a_top_sel = target_module;
}
} else {
if (unit_id == DEBUG_PROBE_UNIT_HP) {
HP_SYSTEM.probeb_ctrl.reg_probe_b_top_sel = target_module;
} else {
LP_SYS.lp_probeb_ctrl.probe_b_top_sel = target_module;
}
}
}
/**
* @brief Add signals from a specific group to the probe channel
*
* @note One sig_group contains 4 bytes of signals. The sig_byte_idx is used to select the byte in the sig_group.
*
* @param channel channel number (only support 0 and 1)
* @param sig_byte_idx signal byte index (0-3)
* @param sig_group signal group (0-15)
*/
static inline void debug_probe_ll_channel_add_signal_group(debug_probe_unit_id_t unit_id, uint8_t channel, uint8_t sig_byte_idx, uint8_t sig_group)
{
if (unit_id == DEBUG_PROBE_UNIT_HP) {
if (channel == 0) {
HP_SYSTEM.probea_ctrl.reg_probe_a_mod_sel &= ~(0xf << (sig_byte_idx * 4));
HP_SYSTEM.probea_ctrl.reg_probe_a_mod_sel |= (sig_group << (sig_byte_idx * 4));
} else {
HP_SYSTEM.probeb_ctrl.reg_probe_b_mod_sel &= ~(0xf << (sig_byte_idx * 4));
HP_SYSTEM.probeb_ctrl.reg_probe_b_mod_sel |= (sig_group << (sig_byte_idx * 4));
}
} else {
if (channel == 0) {
LP_SYS.lp_probea_ctrl.probe_a_mod_sel &= ~(0xf << (sig_byte_idx * 4));
LP_SYS.lp_probea_ctrl.probe_a_mod_sel |= (sig_group << (sig_byte_idx * 4));
} else {
LP_SYS.lp_probeb_ctrl.probe_b_mod_sel &= ~(0xf << (sig_byte_idx * 4));
LP_SYS.lp_probeb_ctrl.probe_b_mod_sel |= (sig_group << (sig_byte_idx * 4));
}
}
}
/**
* @brief Set the lower 16 bits of the probe output
*
* @param part where does the probe_top_out[15:0] come from
*/
static inline void debug_probe_ll_set_lower16_output(debug_probe_unit_id_t unit_id, int channel, debug_probe_split_u16_t part)
{
uint8_t val = (uint8_t)(channel * 2 + DEBUG_PROBE_LL_PART_TO_REG_VAL(part));
if (unit_id == DEBUG_PROBE_UNIT_HP) {
HP_SYSTEM.probea_ctrl.reg_probe_l_sel = val;
} else {
LP_SYS.lp_probea_ctrl.probe_l_sel = val;
}
}
/**
* @brief Set the upper 16 bits of the probe output
*
* @param part where does the probe_top_out[31:16] come from
* @note Only probe_top_out[15:0] can be routed to GPIO pads, but both HP and LP units still keep a 32-bit probe_top_out register.
*/
static inline void debug_probe_ll_set_upper16_output(debug_probe_unit_id_t unit_id, int channel, debug_probe_split_u16_t part)
{
uint8_t val = (uint8_t)(channel * 2 + DEBUG_PROBE_LL_PART_TO_REG_VAL(part));
if (unit_id == DEBUG_PROBE_UNIT_HP) {
HP_SYSTEM.probea_ctrl.reg_probe_h_sel = val;
} else {
LP_SYS.lp_probea_ctrl.probe_h_sel = val;
}
}
/**
* @brief Read the value that currently being probed
*
* @note Can only route the LSB probe_top_out[15:0] to the GPIO pad. But the register still saves 32 signal bits.
*
* @return the value that currently being probed
*/
static inline uint32_t debug_probe_ll_read_output(debug_probe_unit_id_t unit_id)
{
if (unit_id == DEBUG_PROBE_UNIT_HP) {
return HP_SYSTEM.probe_out.reg_probe_top_out;
} else {
return LP_SYS.lp_probe_out.probe_top_out;
}
}
#ifdef __cplusplus
}
#endif