Gui*_*ean 5 debugging arm stm32 nucleo
我正在使用 Atollic Truestudio IDE(基本上是 Eclipse)在各种 STM32L4 Nucleo 板上开发固件。到目前为止,我一直通过 UART 使用 printf,这要归功于虚拟 COM 端口。
我想使用 STM32 ITM 迁移到 printf。
更准确地说,我致力于 Nucleo-L4A6ZG。调试是通过 gdb 服务器进行的。
在 Atollic 上,我修改了调试配置以启用核心时钟为 80MHz 的 SWV。我按照 STM32L4 参考手册中的描述修改了启动脚本,如下所示。我不确定这是必要的,因为 TrueStudio/Eclipse 允许从 GUI 设置 SWV,但这种方式似乎更容易:
# Set character encoding
set host-charset CP1252
set target-charset CP1252
# Reset to known state
monitor reset
# Load the program executable
load
# Reset the chip to get to a known state. Remove "monitor reset" command
# if the code is not located at default address and does not run by reset.
monitor reset
# Enable Debug connection in low power modes (DBGMCU->CR) + TPIU for SWV
set *0xE0042004 = (*0xE0042004) | 0x67
# Write 0xC5ACCE55 to the ITM Lock Access Register to unlock the write access to the ITM registers
set *0xE0000FB0 =0xC5ACCE55
# Write 0x00010005 to the ITM Trace Control Register to enable the ITM with Synchronous enabled and an ATB ID different from 0x00
set *0xE0000E80= 0x00010005
# Write 0x1 to the ITM Trace Enable Register to enable the Stimulus Port 0
set *0xE0000E00= (*0xE0000E00) | 0x1
#write 1 to ITM trace privilege register to unmask Stimulus ports 7:0
set *0xE0000E40= (*0xE0000E40) | 0x1
# Set a breakpoint at main().
tbreak main
# Run to the breakpoint.
continue
Run Code Online (Sandbox Code Playgroud)
我修改了 _write 函数如下:
static inline unsigned long ITM_SendChar (unsigned long ch)
{
if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */
{
while (ITM->PORT[0U].u32 == 0UL)
{
__asm("nop");
}
ITM->PORT[0U].u8 = (uint8_t)ch;
}
return (ch);
}
int _write(int file, char *ptr, int len)
{
//return usart_write(platform_get_console(), (u8 *)ptr, len);
int i=0;
for(i=0 ; i<len ; i++)
ITM_SendChar((*ptr++));
return len;
}
Run Code Online (Sandbox Code Playgroud)
一步一步调试我发现我已经上线了ITM->PORT[0U].u8 = (uint8_t)ch;
最后,我在 IDE 的 SWV 控制台中启动跟踪,但没有得到任何输出。
知道我缺少什么吗?SWV的核心时钟怎么样?我不确定它对应什么。
我在 Nucleo-F103RB 上也遇到了类似的情况。实现此功能的原因是在 CubeMX 上选择“跟踪异步”调试选项,而不是“串行线”。跟踪异步调试将 PB3 引脚专用为 SWO 引脚。
然后按如下所示设置调试配置: 项目调试配置以启用串行线查看器 (SWV)
另外,我在 main.c 文件本身内部定义了 write 函数,更改 syscalls.c 中的定义是行不通的。
最后,在调试项目时,在“串行线查看器设置”下,仅启用(检查)ITM Stimulus 端口上的端口 0,如下所示: 调试视角中的串行线查看器设置
当我为时间戳和一些跟踪事件启用预分频器时,我注意到一件事,跟踪输出不会显示相当多的跟踪日志。