我正在使用Atollic Truestudio IDE(基于Eclipse)开发各种STM32L4 Nucleo板上的固件。迄今为止,我一直通过虚拟COM端口使用UART进行printf。
我想迁移到使用STM32 ITM进行printf。
更具体地说,我正在处理Nucleo-L4A6ZG。调试通过gdb服务器进行。
在Atollic中,我修改了我的调试配置以启用80MHz的核心时钟的SWV。我根据STM32L4参考手册如下修改了我的启动脚本。我不确定这是否必要,因为TrueStudio / Eclipse允许从GUI设置SWV,但这种方式似乎更容易:
我已经修改了我的_write函数,如下所示:
我想迁移到使用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
我已经修改了我的_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;
}
逐步调试后,我发现代码执行到了这一行:ITM->PORT[0U].u8 = (uint8_t)ch;
最后我在IDE的SWV控制台中启动跟踪,但没有输出。
你有什么想法吗?SWV的核心时钟是什么?我不确定它对应什么。