【发布时间】:2018-09-24 00:11:17
【问题描述】:
目前我正在开发一个软件,但我被卡住了。我需要一些帮助。
我正在使用 stm32f103、hal 和库 freertos。
我编写了一个小串行调试器函数,通过 uart 或 usb cdc 发送字符。
这是我的定义:
在头文件中:
#if ( DEBUG == DEBUG_ENABLE )
/* printf definetion */
#define DEBUG_MSG( FLAG, fmt, ...)
do
{
if( FLAG )
printf( "[%08d]%s:%d:%s(): " fmt "\r\n", HAL_GetTick(), __FILE__, __LINE__, __func__, ##__VA_ARGS__);
}while( 0 );
#else
#define DEBUG_MSG( FLAG, fmt, ... )
#endif
在c文件中:
#define PUTCHAR_PROTOTYE int fputc( int ch, FILE *f )
PUTCHAR_PROTOTYE
{
#if DEBUG_PORT == USB_DEBUG
CDC_Transmit_FS((uint8_t *)&ch, 1);
#elif DEBUG_PORT == UART_DEBUG
HAL_UART_Transmit( pDEBUG_PORT, ( uint8_t * )&ch, 1, 0xFFFF );
#else
#error "Define a debug port!"
#endif
return ch;
}
我正在使用这个:DEBUG_MSG(MAIN_DEBUG, "Gsm manager thread started!");
当调试器端口为 uart_debug 时,完全没有问题。一切运行完美。
但是每当我选择 usb_debug 端口时,就会发生一些事情。
虽然调试端口是 usb cdc,但我收到如下文本:
“[0[0[0[0[6””
但在调试模式下,在 putc 函数中,我在CDC_Transmit_FS((uint8_t *)&ch, 1); 行设置了一个断点,然后按 F5,我得到了:
[00010046]../Src/main.c:633:gsmmanager_handler(): Gsm 管理器线程已启动!
字符串就像我期望的那样。如果我在CDC_Transmit_FS((uint8_t *)&ch, 1); 后面加上CDC_Transmit_FS((uint8_t *)"test", strlen("test")); 行,我得到:
[0[0测试
字符串。
所以我什么都不懂。会是什么?
【问题讨论】: