我在使用 newlib 的 printf 函数时遇到一个奇怪的问题,该函数被重定向到 uart 端口。
这个问题可以通过一个例子很好的解释。
printf(" hi ");
...
...//some other simple code. like a++;
...
printf(" hello ");
Run Code Online (Sandbox Code Playgroud)
现在,当我运行该程序时,直到到达/调用下一个 printf 之前,“hi”才会出现。即,当应该打印“hello”时,它会打印“hi”,.. 始终会执行 1 个调用的延迟。最后一个 printf 根本没有被打印。
我的 UART 代码在哪里:
int write(int file, char *ptr, int len) {
unsigned int i;
int de =1;
//initialize_Uart(de);// NOT REQUIRED as UBOOT has already done the job.
/* Transmitting a char from UART */
for (i = 0; i < len; ++i, ++ptr)
{
while (!(IN_8(DUART1_ULSR1)&(0x20))); // wait for the …Run Code Online (Sandbox Code Playgroud)