【TI毫米波雷达笔记】UART串口外设初始化配置及驱动(以IWR6843AOP为例)
最基本的工程建立好以后
需要给SOC进行初始化配置
int main (void)
{//刷一下内存memset ((void *)L3_RAM_Buf, 0, sizeof(L3_RAM_Buf));int32_t errCode; //存放SOC初始化错误代码SOC_Cfg socCfg; //SOC配置结构体Task_Params taskParams; //任务参数SOC_Handle socHandle;ESM_init(0U); //与安全等有关,可略过/* Initialize the SOC configuration: *//* 初始化SOC配置结构体 */memset ((void *)&socCfg, 0, sizeof(SOC_Cfg));memset((void *)&MMWave_Global_Params,0,sizeof(MMWave_Global));/* 配置SOC配置结构体 *//* Populate the SOC configuration: */socCfg.clockCfg = SOC_SysClock_INIT;socCfg.mpuCfg = SOC_MPUCfg_CONFIG;/* require to UNHALT the DSS if this core is available in selected device */socCfg.dssCfg = SOC_DSSCfg_UNHALT;/* Initialize the SOC Module: This is done as soon as the application is started* to ensure that the MPU is correctly configured. *//* SOC初始化,必须在系统运行后尽快调用该初始化函数 */socHandle = SOC_init (&socCfg, &errCode);if (socHandle == NULL){System_printf ("Error: SOC Module Initialization failed [Error code %d]\n", errCode);return -1;}/* Wait for BSS powerup */if (SOC_waitBSSPowerUp(socHandle, &errCode) < 0){/* Debug Message: */System_printf ("Debug: SOC_waitBSSPowerUp failed with Error [%d]\n", errCode);return 0;}/* Check if the SOC is a secure device */if (SOC_isSecureDevice(socHandle, &errCode)){/* Disable firewall for JTAG and LOGGER (UART) which is needed by all unit tests */SOC_controlSecureFirewall(socHandle,(uint32_t)(SOC_SECURE_FIREWALL_JTAG | SOC_SECURE_FIREWALL_LOGGER),SOC_SECURE_FIREWALL_DISABLE,&errCode);}MMWave_Global_Params.handle.socHandle = socHandle;/* Debug Message: */System_printf ("Debug: Launching the MMW HWA Demo\n");/* Initialize the Task Parameters. *//* 创建一个任务用于测试 */Task_Params_init(&taskParams);//taskParams.priority = 3; //优先级3MMWave_Global_Params.task.init = Task_create(MMWave_InitTask, &taskParams, NULL);/* Start BIOS */BIOS_start();return 0;
}
最是基础配置模板
包含了时钟 MPC DSS BSS上电等等
初始化后 调用GPIO和UART初始化
GPIO_init(); //GPIO初始化UART_init(); //串口初始化
同时进行引脚复用配置:
void Init_Pinmux(void)
{/* 串口引脚初始化 *//* 共有两个串口,分别为UART-1和UART-3,序号为0和2 *//* Setup the PINMUX to bring out the MSS UART-1 */Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINN5_PADBE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);Pinmux_Set_FuncSel(SOC_XWR68XX_PINN5_PADBE, SOC_XWR68XX_PINN5_PADBE_MSS_UARTA_TX);Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINN4_PADBD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);Pinmux_Set_FuncSel(SOC_XWR68XX_PINN4_PADBD, SOC_XWR68XX_PINN4_PADBD_MSS_UARTA_RX);// 这一块用不上/* Setup the PINMUX to bring out the MSS UART-3 */
// Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINF14_PADAJ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
// Pinmux_Set_FuncSel(SOC_XWR68XX_PINF14_PADAJ, SOC_XWR68XX_PINF14_PADAJ_MSS_UARTB_TX);/*********************************************************************** Setup the PINMUX:* - for QSPI Flash**********************************************************************/Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINR12_PADAP, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);Pinmux_Set_FuncSel(SOC_XWR68XX_PINR12_PADAP, SOC_XWR68XX_PINR12_PADAP_QSPI_CLK);Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINP11_PADAQ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);Pinmux_Set_FuncSel(SOC_XWR68XX_PINP11_PADAQ, SOC_XWR68XX_PINP11_PADAQ_QSPI_CSN);Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINR13_PADAL, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);Pinmux_Set_FuncSel(SOC_XWR68XX_PINR13_PADAL, SOC_XWR68XX_PINR13_PADAL_QSPI_D0);Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINN12_PADAM, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);Pinmux_Set_FuncSel(SOC_XWR68XX_PINN12_PADAM, SOC_XWR68XX_PINN12_PADAM_QSPI_D1);Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINR14_PADAN, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);Pinmux_Set_FuncSel(SOC_XWR68XX_PINR14_PADAN, SOC_XWR68XX_PINR14_PADAN_QSPI_D2);Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINP12_PADAO, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);Pinmux_Set_FuncSel(SOC_XWR68XX_PINP12_PADAO, SOC_XWR68XX_PINP12_PADAO_QSPI_D3);
}
我这里只用了一个串口 引脚为:
SOC_XWR68XX_PINN4_PADBD
和SOC_XWR68XX_PINN4_PADBD
在手册上可以查到:
之后就是UART串口配置以及串口测试:
void Init_UART(void)
{UART_Params uart0_params;UART_Params_init(&uart0_params);uart0_params.baudRate = 115200; //波特率115200*8uart0_params.clockFrequency = MSS_SYS_VCLK; //系统时钟频率200MHzuart0_params.dataLength = UART_LEN_8; //8bit字长uart0_params.isPinMuxDone = 1; //已经完成引脚复用初始化uart0_params.parityType = UART_PAR_NONE; //无校验位uart0_params.readDataMode = UART_DATA_BINARY; //按位方式读取数据uart0_params.readEcho = UART_ECHO_OFF; //关闭回显uart0_params.readReturnMode = UART_RETURN_FULL; //完整读取uart0_params.stopBits = UART_STOP_ONE; //1停止位uart0_params.writeDataMode = UART_DATA_BINARY; //按位方式写入(发送)数据MMWave_Global_Params.handle.uart0_handle = UART_open(0, &uart0_params); //打开串口if(MMWave_Global_Params.handle.uart0_handle == NULL){System_printf("UART0 open fail\n!");return;}System_printf("UART0 open success\n!");uint8_t buf[]="[INFO] UART0 Test\n";UART_write(MMWave_Global_Params.handle.uart0_handle, buf, sizeof(buf));
}
在串口终端上面可以看到串口输出
串口回环:
while(1)
{//不断读取收到的数据,并通过串口发送出去//该函数会使进程进入挂起等待状态,不会使其他任务无法执行//可以发现打印任务也可以执行UART_read(handle, &dat, 1);UART_write(handle, &dat, 1);}