| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #if 0
- #include "stm32f4xx.h"
- #include <stdio.h>
- #define DEBUG_PRINTF_UART USART1 /* USART1 */
- #ifdef __CC_ARM
- #pragma import(__use_no_semihosting)
- // 标准库需要的支持函数
- struct __FILE
- {
- int handle;
- };
- FILE __stdout;
- // 定义_sys_exit()以避免使用半主机模式
- void _sys_exit(int x) { x = x; }
- // 重定义fputc函数
- int fputc(int ch, FILE *f)
- {
- // 这是一个完整的正确的串口发送一个字节的写法,
- // 不会出现第一个或最后一个字节发送不出来的情况(putstring的时候经常出现最后一个字节发送不出来)
- while ((DEBUG_PRINTF_UART->SR & 0X80) == 0)
- ; // 等待发送寄存器为空
- DEBUG_PRINTF_UART->DR = (u8)ch; // 发送数据
- while ((DEBUG_PRINTF_UART->SR & 0X40) == 0)
- ; // 等待发送完成
- return ch;
- }
- #elif defined __GNUC__
- int _write(int file, char *ptr, int len)
- {
- int DataIdx;
- for (DataIdx = 0; DataIdx < len; DataIdx++)
- {
- while ((DEBUG_PRINTF_UART->SR & 0X80) == 0)
- ; // 等待发送寄存器为空
- DEBUG_PRINTF_UART->DR = (u8) * (ptr + DataIdx); // 发送数据
- while ((DEBUG_PRINTF_UART->SR & 0X40) == 0)
- ; // 等待发送完成
- }
- return len;
- }
- void _read(void)
- {
- }
- void _close(void)
- {
- }
- void _lseek(void)
- {
- }
- #endif
- #endif
|