正如标题所示,我想在不使用 st-link utils 的情况下使用 swo 在 stm32F1 设备上进行调试。一些教程建议我使用 putty 和 telnet 端口 2332 。
我的配置详情:
我主要的相关代码
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");
}
}
我看过一些使用 eclipse 配置或 st-link utils 的教程,但我有一个非常自定义的工具链(我使用 conan、obko cmake 配置 https://github.com/ObKo/stm32-cmake、ocb 和 linux),其唯一目的是使用 c++ 2017 和像 boost 这样的库,所以我不能使用 st-link 工具。
最佳答案
您需要启用 ITM 端口 0(或另一个),然后使用此端口输出字符。
当它工作时,你可以将它包装到 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);
}
关于c++ - 在 stm32 上使用调试器 swo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60523894/