[原创] 【STM32MP135F-DK】裸机printf测试

镜花水月000   2024-1-13 13:48 楼主
在上一贴点亮LED工程的基础上,本贴进行串口printf的裸机测试。工程参考自官网例程
134404r0ianpgleaip0t70.png
使能串口4
134404eptbubo5aa8q8u86.png
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 */

 

最后下载测试,下载方法见我上一贴
下面是测试效果,可以看到输入不同的指令,蓝色LED会有不同的闪烁现象。
134404bhkllwm43tkklttn.png
 

回复评论 (4)

测试效果如果整个视频,看看蓝色LED不同的闪烁就更完美

点赞  2024-1-13 20:48

A7当裸机,其他厂要用做裸机特别麻烦,只有linux的。st 这个赞一个!

默认摸鱼,再摸鱼。2022、9、28
点赞  2024-1-15 19:32
引用: Jacktang 发表于 2024-1-13 20:48 测试效果如果整个视频,看看蓝色LED不同的闪烁就更完美

现在补上0.0

点赞  2024-1-18 20:10

串口peintf


 

点赞  2024-1-18 20:11
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复