主题中讨论的其他器件: LP-MSPM0G3507
工具与软件:
您好、先生、
我试图使用 printf()来打印变量、但它似乎是挂起的、我曾尝试添加堆大小、但仍然有同样的问题。 是否有任何可能的方法来解决该问题?
该代码用于打印从 UART 接收到的字符。
printf ("GOT %x\n"、recvChar);
我的目标板是 LP-MSPM0L2228。
谢谢!
Edware
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
您好、先生、
我试图使用 printf()来打印变量、但它似乎是挂起的、我曾尝试添加堆大小、但仍然有同样的问题。 是否有任何可能的方法来解决该问题?
该代码用于打印从 UART 接收到的字符。
printf ("GOT %x\n"、recvChar);
我的目标板是 LP-MSPM0L2228。
谢谢!
Edware
您好、 Edware
printf 不会在 LP-MSPM0L2228上测试、但 printf 在 LP-MSPM0G3507上运行良好。
在 G3507上、在调试时、printf 会在 CCS 控制台窗口中打印调试日志。
您可以试用 L2228。
此外、您还可以使用 GitHub 中的以下演示代码:
e2e.ti.com/.../TinyPrintf_5F00_uart_5F00_rw_5F00_M0G3507_5F00_nortos_5F00_ticlang.zip
这使用旧版本 SDK 和 syscfg、需要切换到最新版本、也需要从 G3507更改为 L2228。
此致、
Helic
您好、 Edware
有关 UART 接口更改、请参阅演示注释。
* @Tips: * You can modify the hardware of MSPM0 in printf.c file, Line 132: * Function: static inline void _putchar(const char _c). * You can use the macro definitions in printf.h to turn off * complex printf functions such as float point numbers, * longlong type variables, to reduce the program size.
此致、
Helic
尊敬的 Helic:
谢谢你。 我知道我可以修改_putchar()函数。
static inline void _putchar (const char _c){
但我不知道 CIO 的实例。 是否有向 CIO 输出消息的示例?
谢谢!
Edware
您好、 Edware
您可以在 ticlang 中找到一些相关代码、例如 fputs.c、如下所示:
此器件函数会将 CIO 输出作业发送到 CCS 控制台。
/*****************************************************************************/
/* FPUTS - Write a string to a stream */
/* */
/* This function writes string _PTR to stream _FP, returning the number */
/* of characters written upon success, or an EOF upon failure. */
/* */
/*****************************************************************************/
_CODE_ACCESS int fputs(const char * __restrict _ptr, FILE * __restrict _fp)
{
/*------------------------------------------------------------------------*/
/* Local variables */
/*------------------------------------------------------------------------*/
size_t num_left, ptr_strlen;
char *fpos = (char *)_ptr;
int room_left,
flush_flag = 0,
num_to_write;
/*------------------------------------------------------------------------*/
/* The current thread in a multi-threaded application must protect access */
/* to the file stream. In this case, _fp may be updated, so we must */
/* ensure that the local copy of _fp is flushed to shared memory before */
/* leaving the critical section (invalidated if it is not modified). */
/*------------------------------------------------------------------------*/
__TI_file_lock(_fp);
/*------------------------------------------------------------------------*/
/* Make sure that the stream is writeable. */
/*------------------------------------------------------------------------*/
if (!__TI_wrt_ok(_fp))
{
__TI_data_synch_INV(_fp, sizeof(FILE));
__TI_file_unlock(_fp);
return (EOF);
}
room_left = (int)(_fp->bufend - _fp->pos);
ptr_strlen = num_left = strlen(_ptr);
/*------------------------------------------------------------------------*/
/* If the stream is non-buffered, call the lowlevel WRITE function. */
/*------------------------------------------------------------------------*/
if (_BUFFMODE(_fp) == _IONBF)
{
int num_written = 0;
while (num_left > 0)
{
int write_return = write(_fp->fd, _ptr + num_written, num_left);
if (write_return < 0)
{
_SET(_fp, _STATERR);
__TI_data_synch_WBINV(_fp, sizeof(FILE));
__TI_file_unlock(_fp);
return (EOF);
}
else
{
num_written += write_return;
num_left -= write_return;
}
}
__TI_data_synch_WBINV(_fp, sizeof(FILE));
__TI_file_unlock(_fp);
return ptr_strlen;
}
/*------------------------------------------------------------------------*/
/* Write the string into the buffer, flushing it when full. */
/*------------------------------------------------------------------------*/
while (num_left > 0)
{
num_to_write = (num_left > room_left) ? room_left : num_left;
if ((_BUFFMODE(_fp) == _IOLBF) && memchr(fpos, '\n', num_to_write))
{
num_to_write = (char *)memchr(fpos, '\n', num_to_write) - fpos + 1;
flush_flag = 1;
}
memcpy(_fp->pos, fpos, num_to_write);
/*---------------------------------------------------------------------*/
/* Update pointers and counters. */
/*---------------------------------------------------------------------*/
_fp->pos += num_to_write;
fpos += num_to_write;
num_left -= num_to_write;
room_left -= num_to_write;
/*---------------------------------------------------------------------*/
/* If the buffer is full, flush it. Any I/O errors cause this */
/* function to exit, returning an EOF. */
/*---------------------------------------------------------------------*/
if (room_left == 0 || flush_flag)
{
if (__TI_doflush(_fp))
{
_SET(_fp, _STATERR);
__TI_data_synch_WBINV(_fp, sizeof(FILE));
__TI_file_unlock(_fp);
return (EOF);
}
room_left = (int)(_fp->bufend - _fp->pos);
_SET(_fp, _MODEW);
flush_flag = 0;
}
}
__TI_data_synch_WBINV(_fp, sizeof(FILE));
__TI_file_unlock(_fp);
return ptr_strlen;
}
但我从来没有尝试将 tinyprintf 与 CIO 合并。
此致、
Helic