上篇文章中我已经测试了串口功能,本次帖子就来使用串口通讯来进行点灯操作,其实是用到了串口通讯功能!!!!!
打开原理图


根据原理图配置好串口和LED,我前期已经配置好了,这里不赘述!!!
实现串口shell核心代码
#include "shell.h"
#include "usart9.h"
#include "LED.h"
#include <string.h>
#include <stdio.h>
#include <stdint.h>
void shell_init(void) {
printf("\r\n[Embedded Shell Ready]\r\n> ");
}
void shell_process(void) {
char c;
if(user9_uart_wait_receive() == REV_OK)
{
printf("\r\n");
if (strcmp(U9_RxBuff, "LED ON") == 0)
{
LED1_ON();LED2_ON();LED3_ON();
printf("LED turned ON\r\n");
}
else if (strcmp(U9_RxBuff, "LED OFF") == 0)
{
LED1_OFF();LED2_OFF();LED3_OFF();
printf("LED turned OFF\r\n");
}
else if (strcmp(U9_RxBuff, "HELP") == 0)
{
printf("Commands: LED ON, LED OFF, STATUS, HELP\r\n");
}
else
{
printf("Unknown command\r\n");
}
user9_uart_clear();
}
HAL_Delay(10);
}
#include "hal_data.h"
#include "LED.h"
#include "Systick.h"
#include "usart0.h"
#include "usart9.h"
#include "shell.h"
FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER
/*******************************************************************************************************************//**
-
main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
-
is called by main() when no RTOS is used.
*********************************************************************************************************************/
void hal_entry(void)
{
/ TODO: add your own code here */
hal_systick_init();
UART0_Init();UART9_Init();
shell_init();
while(1)
{
shell_process();
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
/*******************************************************************************************************************//**
-
This function is called at various points during the startup process. This implementation uses the event that is
-
called right before main() to set up the pins.
-
@param[in] event Where at in the start up process the code is currently at
**********************************************************************************************************************/
void R_BSP_WarmStart (bsp_warm_start_event_t event)
{
if (BSP_WARM_START_RESET == event)
{
#if BSP_FEATURE_FLASH_LP_VERSION != 0
R_FACI_LP->DFLCTL = 1U;
#endif
}
if (BSP_WARM_START_POST_C == event)
{
R_IOPORT_Open(&IOPORT_CFG_CTRL, &IOPORT_CFG_NAME);
#if BSP_CFG_SDRAM_ENABLED
R_BSP_SdramInit(true);
#endif
}
}
#if BSP_TZ_SECURE_BUILD
FSP_CPP_HEADER
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();
/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
{
}
FSP_CPP_FOOTER
#endif
主函数中调用

编译后烧录板子

打开串口助手,详情看视频