SWO是什么

使用SWO输出调试信息 - 图1

代码怎么写

由于SWO是内核Debug组件的的一部分,所以它的API在头文件Drivers/CMSIS/Include/core_cm3.h中。

  1. /**
  2. \brief ITM Send Character
  3. \details Transmits a character via the ITM channel 0, and
  4. \li Just returns when no debugger is connected that has booked the output.
  5. \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
  6. \param [in] ch Character to transmit.
  7. \returns Character to transmit.
  8. */
  9. __STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
  10. {
  11. if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
  12. ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */
  13. {
  14. while (ITM->PORT[0U].u32 == 0UL)
  15. {
  16. __NOP();
  17. }
  18. ITM->PORT[0U].u8 = (uint8_t)ch;
  19. }
  20. return (ch);
  21. }

工具怎么用

J-Link SWO Viewer

SWO Viewer 是J-Link软件包里的一个小工具,使用起来比较简单
image.png
image.png
image.png

STM32CubeIDE

翻译自 AN4989: STM32 microcontroller debug toolbox 7.3节

参考资料

AN4989 STM32 microcontroller debug toolbox
https://www.cxymm.net/article/wangjun_eric/105277707
https://blog.csdn.net/weixin_46623350/article/details/105305426