简体   繁体   English

在 stm32 上使用调试器 swo

[英]Using debugger swo on stm32

As the title suggest I would like to use swo for debugging on an stm32F1 device without the use of st-link utils.I think I have flashed the code to send messages via swo on my chip but I can not establish a connection with the correct port as some tutorials suggested I use putty with the telnet port 2332 .正如标题所示,我想在不使用 st-link utils 的情况下使用 swo 在 stm32F1 设备上进行调试。一些教程建议我使用 putty 和 telnet 端口 2332 。 Specifics about my configuration:关于我的配置的细节: cubemx swo 配置 Relative code on my main我主要的相关代码

    int _write(int file, char *ptr, int len)
{
    int DataIdx;
    for (DataIdx = 0; DataIdx < len; DataIdx++)
    {
        __io_putchar(*ptr++);
    }
    return len;
}

... ...

   int main(){
    while (1)
      {
        printf("Hi\n");
      }
}

I have seen some tutorials using eclipse configurations or st-link utils but I have a very custom toolchain (I use conan, obko cmake configurations https://github.com/ObKo/stm32-cmake , ocb and linux) for the sole purpose of using c++ 2017 and libraries like boost so I can not use st-link utils.我看过一些使用 eclipse 配置或 st-link utils 的教程,但我有一个非常自定义的工具链(我使用 conan、obko cmake 配置https://github.com/ObKo/stm32-cmake、ocb和 linux)仅用于使用 c++ 2017 和像 boost 这样的库,所以我不能使用 st-link utils。

You need to enable ITM port 0 (or another one) then output the chars using this port.您需要启用 ITM 端口 0(或另一个),然后使用此端口输出字符。

When it works you can wrap it into the printf当它工作时,你可以将它包装到 printf 中

uint32_t ITM_SendChar (uint32_t ch)
{
  if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0) &&      /* ITM enabled */
      ((ITM->TER & 1) != 0)   )     /* ITM Port #0 enabled */
  {
    while (ITM->PORT[0].u32 == 0)
    {
      __NOP();
    }
    ITM->PORT[0].u8 = (uint8_t)ch;
  }
  return (ch);
}


The problem with my configurations was that I didn't have a parser on my computer for the ITM messages so even after having the right configurations on the chip when I was opening the port to communicate with the chip my terminal was empty of messages .我的配置的问题是我的计算机上没有用于ITM消息的解析器,因此即使在芯片上进行了正确的配置后,当我打开端口与芯片通信时,我的终端也没有消息。 Hopefully I found this very helpful parser on github so all I had to do after compiling the program with the above configurations was to run openocd with configuring two options about the frequency of the f1 chip and the fact that ITM port was open (here is my .cfg file ):希望我在 github 上找到了这个非常有用的解析器,所以在使用上述配置编译程序后,我所要做的就是运行openocd并配置两个关于f1芯片频率和ITM端口打开这一事实的选项(这是我的.cfg文件):

source [find interface/stlink-v2.cfg]
source [find target/stm32f1x.cfg]
init
tpiu config internal - uart off 72000000
itm ports on

and on another terminal I runed the parser script from github python3 swo_parser.py在另一个终端上,我从 github python3 swo_parser.py了解析器脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM