huart4.Instance = UART4;
huart4.Init.BaudRate = 115200;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_8;
huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK)
{
Error_Handler();
}
移植官方的printf重定向和测试函数
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the UART4 and Loop until the end of transmission */
HAL_UART_Transmit(&huart4, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
GETCHAR_PROTOTYPE
{
uint8_t ch = 0;
/* Clear the Overrun flag just before receiving the first character */
__HAL_UART_CLEAR_OREFLAG(&huart4);
HAL_UART_Receive(&huart4, (uint8_t *)&ch, 1, 0xFFFF);
HAL_UART_Transmit(&huart4, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
void Test_Validation_Menu(void)
{
int menu_option = 0;
uint8_t stop_test = 0;
char menu_select[5];
char menu1[] ="Test1";
char menu2[] ="Test2";
char menu3[] ="Test3";
char menu_init[] ="MENU0";
uint8_t duration = 0;
do
{
printf("\r\n Select the test options:\r\n");
printf("\r\n Test1: Fast Toggle LED");
printf("\r\n Test2: Slow Toggle LED");
printf("\r\n Test3: Exit \r\n");
strcpy(menu_select, menu_init);
menu_option=0;
duration=0;
menu_option = Serial_Scanf(menu_select,5);
/* CASE 'Test1' selected */
if(strncmp(menu_select, menu1, menu_option) == 0)
{
printf("\r\n ** Start Fast Toggle Test : see LED_GREEN!\r\n");
while(duration < 50)
{
/* Toggle LED_GREEN for error */
BSP_LED_Toggle(LED_GREEN);
HAL_Delay(100);
duration++;
}
printf("\r\n ** Fast Toggle Test is Finished!\r\n");
}
/* CASE 'Test2' selected */
else if(strncmp(menu_select, menu2, menu_option) == 0)
{
printf("\r\n ** Start Slow Toggle Test : see LED_GREEN!\r\n");
while(duration < 10)
{
/* Toggle LED_GREEN for error */
BSP_LED_Toggle(LED_GREEN);
HAL_Delay(500);
duration++;
}
printf("\r\n ** Slow Toggle Test is Finished!\r\n");
}
/* CASE 'Exit' selected */
else if(strncmp(menu_select, menu3, menu_option) == 0)
{
printf("\n\r >> Getchar = Test finished successfully. ** \n\r");
stop_test=1;
}
/* CASE wrong selection */
else
{
printf("\r\n !! INVALID CHOICE\r\n");
}
} while (stop_test != 1);
}
/* USER CODE END 4 */
引用: Jacktang 发表于 2024-1-13 20:48 测试效果如果整个视频,看看蓝色LED不同的闪烁就更完美
现在补上0.0