这个串口研究了4天多,最后重重排查,还得大神指导结果终于找到原因了,那是个小插曲,这里就不提了,下面进行测评串口。
平台:KEIL。
开发板:STM32H5.
目地:利用开发板串口打印出eeworld STM32H563。
1、原理图:要知道串口连接
2.cube mx配置
3、相关代码:
要注意增加头文件 #include <stdio.h>。
主函数:
int fputc(int ch, FILE *f)
{
HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 2);//huart1需要根据你的配置修改?? ?
return ch;
}
MX_GPIO_Init();
MX_ICACHE_Init();
MX_USART3_UART_Init();
/* USER CODE BEGIN 2 */
printf("eeworld STM32H563\r\n");
串口初始化:
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK)
{
Error_Handler();
}
4、输出结果:
|