首页 文章

在Nucleo STM32板上设置SWV printf

提问于
浏览
1

我正在使用Atollic Truestudio IDE(基本上是Eclipse)在各种STM32L4 Nucleo板上开发固件 . 到目前为止,由于虚拟COM端口,我通过UART使用printf .

我想使用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的核心时钟怎么样?我不确定它对应的是什么 .

1 回答

  • 1

    我在Nucleo-F103RB上遇到了类似的情况 . 这样做的工作是在CubeMX上选择“Trace Asynchronous”调试选项而不是“Serial Wire” . 跟踪异步调试将PB3引脚专用作SWO引脚 .

    然后按如下方式设置调试配置:Project debug configuration to enable Serial Wire Viewer (SWV)

    另外,我在main.c文件本身内部定义了write函数,改变syscalls.c中的定义是行不通的 .

    最后在调试项目时,在ITM刺激端口上的"Serial Wire Viewer settings"仅启用(检查)端口0,如下所示:Serial Wire Viewer settings in Debug perpective

    当我为预分频器启用时间戳和一些跟踪事件时,我注意到一件事,跟踪输出不会显示相当多的跟踪日志 .

相关问题