scanf重定向完不能用啊,[C] 纯文本查看 复制代码 #include <LowLevelIOInterface.h>
#include <stdint.h>
#include "usart.h"
#include <stddef.h>
extern UART_HandleTypeDef hlpuart1;
// __no_init volatile unsigned char kbIO @0x1000;
#pragma module_name = "?__read"
// size_t __read(int handle, unsigned char *buffer, size_t size)
// {
// if (buffer == 0)
// {
// /*
// * This means that we should flush internal buffers. Since we
// * don't we just return. (Remember, "handle" == -1 means that all
// * handles should be flushed.)
// */
// return 0;
// }
// /* This template only writes to "standard out" and "standard err",
// * for all other file handles it returns failure. */
// if (handle != _LLIO_STDIN && handle != _LLIO_STDERR)
// {
// return _LLIO_ERROR;
// }
// /* Sending in normal mode */
// if (HAL_UART_Receive(&hlpuart1, (uint8_t *)buffer, size, 0xFFFF) == HAL_OK)
// {
// return size;
// }
// else
// {
// return _LLIO_ERROR;
// }
// }
size_t __read(int handle, unsigned char *buf, size_t bufSize)
{
size_t nChars = 0; /* Check for stdin (only necessary if FILE descriptors are enabled) */
if (handle != 0)
{
return -1;
}
for (/*Empty*/; bufSize > 0; --bufSize)
{
unsigned char c = NULL;
while (!(hlpuart1.Instance->ISR & 1 << 5))
;
c = (uint8_t)hlpuart1.Instance->RDR & (uint8_t)0x00fff;
if (c == 0)
break;
*buf++ = c;
++nChars;
}
return nChars;
} |