2.另一种方法:(其实大同小异)
需要添加以下代码
(论坛里应该有完整介绍这个的帖子,但是我没搜到,也许是沉了。)
- #pragma import(__use_no_semihosting)
- /******************************************************************************
- *标准库需要的支持函数
- ******************************************************************************/
- struct __FILE
- {
- int handle;
- /* Whatever you require here. If the only file you are using is */
- /* standard output using printf() for debugging, no file handling */
- /* is required. */
- };
- /* FILE is typedef’ d in stdio.h. */
- FILE __stdout;
- /// <summary>
- /// 定义_sys_exit()以避免使用半主机模式
- /// </summary>
- /// <param name="x"></param>
- /// <returns></returns>
- _sys_exit(int x)
- {
- x = x;
- }
- int fputc(int ch, FILE *f)
- {
- //USART_SendData(USART1, (u8) ch);
- USART1->DR = (u8) ch;
-
- /* Loop until the end of transmission */
- while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
- {
- }
- return ch;
- }
|