| 配置UART 在STM32中,确保UART已正确配置。波特率和数据位等设置应与串行终端一致。例如:
 
 c
 复制代码
 void MX_USART1_UART_Init(void)
 {
 huart1.Instance = USART1;
 huart1.Init.BaudRate = 115200; // 设置适当的波特率
 huart1.Init.WordLength = UART_WORDLENGTH_8B;
 huart1.Init.StopBits = UART_STOPBITS_1;
 huart1.Init.Parity = UART_PARITY_NONE;
 huart1.Init.Mode = UART_MODE_TX_RX;
 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
 HAL_UART_Init(&huart1);
 }
 输出调试信息
 使用HAL_UART_Transmit函数将调试信息发送到串口:
 
 c
 复制代码
 void debug_print(const char *message)
 {
 HAL_UART_Transmit(&huart1, (uint8_t*)message, strlen(message), HAL_MAX_DELAY);
 }
 在你的代码中,使用该函数输出调试信息:
 
 c
 复制代码
 debug_print("System starting...\n");
 
 |