CubeMx 配置
fputc 实现
/* USER CODE BEGIN 0 */
#include <stdio.h>
/* USER CODE END 0 */
/* USER CODE BEGIN 1 */
int fputc(int ch, FILE *f)
{/* Place your implementation of fputc here *//* e.g. write a character to the USART */uint8_t send_data = ch;HAL_UART_Transmit(&huart1, &send_data, 1, HAL_MAX_DELAY);return ch;
}
/* USER CODE END 1 */
使能 libc
编译报错解决
- Undefined symbol use two region memory (referred from startup stm32xxx)
- Undefined symbol initial sp (referred from entry2.o)
解决这两个错误也 比较简单,在 .s 启动文件中将 Stack_Size
改大一点就可以了
Stack_Size EQU 0x600
或者直接在 CubeMx 生成的时候修改配置
串口打印
/* USER CODE BEGIN PV */
#include <stdio.h>
/* USER CODE END PV */
/* USER CODE BEGIN 2 */printf("this is printf example\r\n");/* USER CODE END 2 */