打印调试信息几种途径:
1.串口打印:
将fputc映射到UART,通过USB-TLL转接板打印调试信息。
STM32F103官方提供的代码:
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(EVAL_COM1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
{
}
return ch;
}
1.通过Jlink仿真器打印:
cortex-M3内核支持ITM机制,可以通过Jlink打印调试信息。 ITM相关函数在core_cm3.h中有定义,需要将fputc重新映射到ITM,实现printf。
注意:
ITM需要使用SWD的仿真口(且需要连接SWO),而不是常用的Jlink仿真口。
需要激活ITM的Port0端口来捕获信息
时钟需要配置和开发板的时钟一致
SWD接口如下:
fputc映射代码如下:
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
#ifdef DEBUG_USART1
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{
__NOP();
}
return ch;
#endif
#ifdef DEBUG_ITM
/* Place your implementation of fputc here */
/* e.g. write a character to the ITM */
ITM_SendChar((uint32_t)ch);
return ch;
#endif
}
IAR配置如下:
使用SWD
配置ITM的Prot0端口 和 时钟, SWO变绿说明,SWO正常使用
仿真:
将数据逻辑断点打在randomvalue变量处,使用Timeline窗口查看randomvalue。 打印随机数变量 randomvalue到Terminal IO窗口,
后续使用NIST的STS来验证随机数是否符合标准