基於visual studio 2017 以及cubemx 搭建stm32的開發環境(2)
阿新 • • 發佈:2019-02-14
@param imp fin print set 分享 end spa 分享圖片
主要解決 vs2017中,printf無法打印數據的問題。
在keil環境下正常使用printf功能,但是以下的重定向代碼在vs2017下使用不了:
#ifdef __GNUC__ /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to ‘Yes‘) calls __io_putchar() */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif/* __GNUC__ */ /** * @brief Retargets the C library printf function to the USART. * @param None * @retval None */ PUTCHAR_PROTOTYPE { /* Place your implementation of fputc here */ /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */ HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); return ch; }
vs2017中將以下代碼添加入,不需要添加上述在keil中的代碼了:
int _write (int fd, char *ptr, int len) { HAL_UART_Transmit(&huart1, (uint8_t*) ptr, len, 0xFFFF); return len; } int _read (int fd, char *ptr, int len) { *ptr = 0x00; // Flush the character buffer HAL_UART_Receive(&huart1, (uint8_t*) ptr, 1, 0xFFFF); return 1; }
--------------------------------------------------------------------------
開發板:正點原子的stm32f407ZGT6
調試器:JLINK
使用軟件:cubemx,visual studio 2017
個人源碼如下:
鏈接:https://pan.baidu.com/s/1MDLE0TCcdZxTgvOvqYduVA
密碼:vfg7
參考以下網址:
http://www.stm32cube.com/question/668
基於visual studio 2017 以及cubemx 搭建stm32的開發環境(2)