mt6701 uart_redirect
This commit is contained in:
53
3rd/uart_redircet.c
Normal file
53
3rd/uart_redircet.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "ti_msp_dl_config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* ARM Compiler 6 半主机模式禁用声明 */
|
||||
#if (__ARMCC_VERSION >= 6010050)
|
||||
__asm(".global __use_no_semihosting\n\t");
|
||||
__asm(".global __ARM_use_no_argv \n\t");
|
||||
#else
|
||||
#pragma import(__use_no_semihosting)
|
||||
#endif
|
||||
|
||||
FILE __stdout;
|
||||
|
||||
/* 系统退出函数实现 */
|
||||
void _sys_exit(int x)
|
||||
{
|
||||
x = x;
|
||||
while (1)
|
||||
; /* 死循环防止程序异常退出 */
|
||||
}
|
||||
|
||||
/* ARM Compiler 6 printf重定向实现 */
|
||||
int fputc(int c, FILE *stream)
|
||||
{
|
||||
/* 等待UART发送缓冲区就绪 */
|
||||
while (DL_UART_Main_isBusy(UART_0_INST))
|
||||
;
|
||||
|
||||
/* 发送字符 */
|
||||
DL_UART_Main_transmitData(UART_0_INST, (uint8_t)c);
|
||||
return c;
|
||||
}
|
||||
|
||||
int fputs(const char *restrict s, FILE *restrict stream)
|
||||
{
|
||||
uint16_t i, len;
|
||||
len = strlen(s);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
fputc(s[i], stream);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int puts(const char *_ptr)
|
||||
{
|
||||
int count = fputs(_ptr, stdout);
|
||||
count += fputc('\n', stdout); /* 自动添加换行 */
|
||||
return count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user