【STM32MP135F-DK】裸机printf测试
<div class='showpostmsg'><div>在上一贴点亮LED工程的基础上,本贴进行串口printf的裸机测试。工程参考自官网例程</div><div></div>
<div>使能串口4</div>
<div>
<pre>
<code class="language-cpp">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;
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 */</code></pre>
<p> </p>
</div>
<div>最后下载测试,下载方法见我上一贴</div>
<div>下面是测试效果,可以看到输入不同的指令,蓝色LED会有不同的闪烁现象。</div>
<div></div>
<div> </div>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>测试效果如果整个视频,看看蓝色LED不同的闪烁就更完美</p>
<p>A7当裸机,其他厂要用做裸机特别麻烦,只有linux的。st 这个赞一个!</p>
Jacktang 发表于 2024-1-13 20:48
测试效果如果整个视频,看看蓝色LED不同的闪烁就更完美
<p>现在补上0.0</p>
镜花水月000 发表于 2024-1-18 20:10
现在补上0.0
<p>18f365a5d9129db4ab332012ebd4f784<br />
<br />
</p>
页:
[1]