1. 首先使用 stm32
cubeMX 设定模式, 并生成 工程以及代码。
2. 使用 sw4stm32 打开工程, 编译调试
note: debug configuration修改 debugger 的 Mode setup wei software system reset,。 才能调试。
使用 STM32Cube/Repository/STM32Cube_FW_F4_V1.21.0/Projects/STM32F401RE-Nucleo/Examples/UART 的范例来作串口手法
即main.c 末尾只要加入代码 即可实现printf输出。
点击(此处)折叠或打开
- /* Private function prototypes -----------------------------------------------*/
- #ifdef __GNUC__
- /* With GCC, 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(&huart_shell, (uint8_t *)&ch, 1, 0xFFFF);
- return ch;
- }