5.35 DBG 使用说明

本章说明 N32H49x 标准外设库中 DBG 驱动的文件组成与 8 个公开函数,内容包括芯片唯一 ID、器件信息读取与调试暂停配置;当前 SDK 没有 DBG 示例工程。SWD 接口、JTAG 接口与调试控制寄存器请配合用户手册的“调试支持(DBG)”章节阅读。

5.35.1 相关文件

相对路径 作用
firmware/n32h49x_std_periph_driver/inc/n32h49x_dbg.h 定义调试暂停宏(睡眠、停止、待机与各外设在内核停止时的行为),并按 ID 读取、器件信息、配置三个区段声明 8 个公开函数
firmware/n32h49x_std_periph_driver/src/n32h49x_dbg.c 实现上述 8 个函数:逐字节读取三处 ID,解析版本号、器件型号与 FLASH、SRAM 容量,读改写调试控制寄存器
firmware/CMSIS/device/n32h49x.h 定义 UCID、UID、DBGMCU_ID 基地址,以及 DBG 寄存器结构指针与控制寄存器位定义

5.35.2 API 参考

搜索 API共 8 个函数

以下 8 个公开函数按 n32h49x_dbg.h 的声明顺序分为 3 组;每个条目给出功能摘要与 n32h49x_dbg.c 中该函数正上方的注释原文。

ID 读取

GetUCID、GetUID、GetDBGMCU_ID

器件信息

DBG_GetRevNum、DBG_GetDevNum、DBG_GetFlashSize、DBG_GetSramSize

配置

DBG_ConfigPeriph

void GetUCID(uint8_t *UCIDbuf)读取唯一客户 ID。
源码注释
name    GetUCID.
fun     get unique customer id.
param   UCIDbuf
return  none
void GetUID(uint8_t *UIDbuf)读取唯一器件 ID。
源码注释
name    GetUID.
fun     get unique device id.
param   UIDbuf
return  none
void GetDBGMCU_ID(uint8_t *DBGMCU_IDbuf)该函数的源码注释未提供功能说明。
源码注释
@brief  Returns the DBGMCU_ID.
@return DBGMCU_ID
uint32_t DBG_GetRevNum(void)读取芯片的版本号。
源码注释
name    DBG_GetRevNum.
fun     get the revision number.
param   none
return  revision number
uint32_t DBG_GetDevNum(void)读取器件型号标识。
源码注释
name    DBG_GetDevNum.
fun     get the device identifer.
param   none
return  Device identifier
void DBG_ConfigPeriph(uint32_t DBG_Periph, FunctionalState Cmd)配置在内核处于调试模式下时,指定外设继续运行还是停止。
源码注释
name    DBG_ConfigPeriph.
fun     Configures the specified peripheral run or stop when the MCU under Debug mode.
param   DBG_Periph :
                - DBG_SLEEP             \* Keep debugger connection during SLEEP mode *\
                - DBG_STOP              \* Keep debugger connection during STOP mode *\
                - DBG_STANDBY           \* Keep debugger connection during STANDBY mode *\
                - DBG_IWDG_STOP         \* IWDG stopped when Core is halted. *\
                - DBG_WWDG_STOP         \* WWDG stopped when Core is halted. *\
                - DBG_I2C1SMBUS_TIMEOUT \* I2C1 SMBUS timeout mode stopped when Core is halted *\
                - DBG_I2C2SMBUS_TIMEOUT \* I2C2 SMBUS timeout mode stopped when Core is halted *\
                - DBG_I2C3SMBUS_TIMEOUT \* I2C3 SMBUS timeout mode stopped when Core is halted *\
                - DBG_I2C4SMBUS_TIMEOUT \* I2C4 SMBUS timeout mode stopped when Core is halted *\
                - DBG_ATIM1_STOP        \* ATIM1 counter stopped when core is halted *\
                - DBG_ATIM2_STOP        \* ATIM2 counter stopped when core is halted *\
                - DBG_ATIM3_STOP        \* ATIM3 counter stopped when core is halted *\
                - DBG_BTIM1_STOP        \* BTIM1 counter stopped when core is halted *\
                - DBG_BTIM2_STOP        \* BTIM2 counter stopped when core is halted *\
                - DBG_GTIM1_STOP        \* GTIM1 counter stopped when core is halted *\
                - DBG_GTIM2_STOP        \* GTIM2 counter stopped when core is halted *\
                - DBG_GTIM3_STOP        \* GTIM3 counter stopped when core is halted *\
                - DBG_GTIM4_STOP        \* GTIM4 counter stopped when core is halted *\
                - DBG_GTIM5_STOP        \* GTIM5 counter stopped when core is halted *\
                - DBG_GTIM6_STOP        \* GTIM6 counter stopped when core is halted *\
                - DBG_GTIM7_STOP        \* GTIM7 counter stopped when core is halted *\
                - DBG_GTIM8_STOP        \* GTIM8 counter stopped when core is halted *\
                - DBG_GTIM9_STOP        \* GTIM9 counter stopped when core is halted *\
                - DBG_GTIM10_STOP       \* GTIM10 counter stopped when core is halted *\
param   Cmd:
          - ENABLE
          - DISABLE
return  none
uint32_t DBG_GetFlashSize(void)读取本芯片的 FLASH 容量。
源码注释
name    DBG_GetFlashSize.
fun     Get FLASH size of this chip.
param   none
return  FLASH size in bytes.
uint32_t DBG_GetSramSize(void)读取本芯片的 SRAM 容量。
源码注释
name    DBG_GetSramSize.
fun     Get SRAM size of this chip.
param   none
return  SRAM size in bytes.

5.35.3 Demo 示例说明

当前 SDK 未提供 DBG 的独立示例工程。

5.35.4 注意与排障

场景 检查与建议 来源
调试接口切换 芯片默认使用 JTAG 调试接口;
JTAG 与 SWD 都使能时,复位后默认使用 5 线 JTAG 接口;
JTAG 切换到 SWD 需先发 50 个以上 JTCK 周期的 JTMS=1,再发 16 位 0xE79E,最后再发 50 个以上 JTMS=1;
SWD 切回 JTAG 使用 16 位 0xE73C,其余步骤相同。
用户手册
调试引脚复用 JTMS/SWDIO 为 PA13、JTCK/SWCLK 为 PA14、JTDI 为 PA15、JTDO 为 PB3 或 PG15、NJTRST 为 PB4;
使用 JTAG 时可不用 NJTRST,此时 PB4 可作通用 GPIO;
使用 SWD 时 JTDI、JTDO、NJTRST 三个引脚可作通用 GPIO;
不使用调试功能时上述 5 个引脚都可作通用 GPIO。
用户手册
低功耗模式调试 低功耗模式调试需保证内核的 FCLK 与 HCLK 处于开启状态;
DBG_SLEEP 模式需配置 DBG_CTRL.SLEEP 位,为 HCLK 提供与 FCLK 相同的系统时钟;
DBG_STOP 与 DBG_STANDBY 模式需分别配置 DBG_CTRL.STOP、DBG_CTRL.STDBY 位,启动内部 RC 振荡器为 HCLK 与 FCLK 提供时钟。
用户手册
外设调试 将 DBG_CTRL 中外设控制位的相应位置 1,内核停止后相应外设进入调试状态;
定时器计数器停止并进入调试状态;
I2C 的 SMBUS 保持状态;
WWDG 与 IWDG 计数器停止并进入调试状态。
用户手册
寄存器访问 必须按字(32 位)方式操作 DBG 外设寄存器,寄存器基地址为 0xE0042000;
DBG_CTRL 的 POR 复位值为 0x00000000,系统复位不会重置该寄存器。
用户手册
国民技术开发套件文档中心

按芯片系列在线查阅国民技术 MCU 开发套件的芯片资料、SDK、驱动 API 与 Demo 示例说明。

© 2026 国民技术股份有限公司 版权所有粤ICP备11069485号本站使用不含 Cookie 的匿名访问统计