printf.c 930 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "stdio.h"
  2. #include "stm32f4xx_conf.h"
  3. #include "sys.h"
  4. //////////////////////////////////////////////////////////////////////////////////
  5. //如果使用ucos,则包括下面的头文件即可.
  6. #if SYSTEM_SUPPORT_OS
  7. #include "FreeRTOS.h" //FreeRTOS使用
  8. #endif
  9. //////////////////////////////////////////////////////////////////
  10. //加入以下代码,支持printf函数,而不需要选择use MicroLIB
  11. #if 1
  12. #pragma import(__use_no_semihosting)
  13. //标准库需要的支持函数
  14. struct __FILE
  15. {
  16. int handle;
  17. };
  18. FILE __stdout;
  19. //定义_sys_exit()以避免使用半主机模式
  20. void _sys_exit(int x)
  21. {
  22. x = x;
  23. }
  24. //重定义fputc函数
  25. /*
  26. int fputc(int ch, FILE *f)
  27. {
  28. while((USART1->SR&0X40)==0);//循环发送,直到发送完毕
  29. USART1->DR = (u8) ch;
  30. return ch;
  31. } */
  32. void my_fputc(uchar c);
  33. int fputc(int ch, FILE *f)
  34. {
  35. my_fputc(ch);
  36. return ch;
  37. }
  38. #endif