【简介】
在之前的帖子中我们验证UART 的接收功能使用的CPU中断的方式来读取数据,我们在此基础上使用DMA来接收数据验证DMA的功能。
RTD 的uart 的驱动要使用DMA首先要打开驱动中的DMA控制开关。

同时需要把 dma_ip 模块驱动程序加入到工程中。

生成代码后对应的DMA 驱动程序已经被加入到工程中。

在RM配置中使能DMA mux 路由配置。


DMA 通路配置完成后我们就可以在lpuart 中将配置的DMA通路进行关联。

配置好dma 通道和uart 模块后在intctrl 中断管理中注册中断函数,并添加对应的数据回调处理函数。


以上配置完成后添加如下的代码初始化DMA 和 uart 模块。
static int s32k3_dma_init(void)
{
/* Initialize DMA */
(void)Dma_Ip_Init(&Dma_Ip_Sa_xDmaInitPB);
/* Initialize DMA mux */
Dma_Mux_Ip_Init(&Dma_Mux_Config);
return 1;
}
Lpuart_Uart_Ip_Init(6,&Lpuart_Uart_Ip_xHwConfigPB_6);
/* Enable the LPUART transmitter */
Lpuart_Uart_Ip_SetTransmitterCmd(IP_LPUART_6,true);
/* Enable the LPUART receiver */
Lpuart_Uart_Ip_SetReceiverCmd(IP_LPUART_6, true);
/* open uart rx data full event */
Lpuart_Uart_Ip_SetIntMode(IP_LPUART_6, LPUART_UART_IP_INT_RX_DATA_REG_FULL, true);
if(config->TransferType == LPUART_UART_IP_USING_INTERRUPTS)
{
/* Interrupt control for LPUART 6 */
IntCtrl_Ip_InstallHandler(LPUART6_IRQn, littleshell_uart_isr_handler, NULL_PTR);
IntCtrl_Ip_SetPriority(LPUART6_IRQn, 0);
IntCtrl_Ip_EnableIrq(LPUART6_IRQn);
}
else
{
Lpuart_Uart_Ip_AsyncReceive(6,&uart_rx.data,1);
}上述代码运行后串口输入‘1’debug 发现dma 中断已经触发,此时DMA已经将‘1’搬运到我们指定的buffer中,至此DMA已经按照预期的将串口接收数据搬运到我们指定的内存中。

我要赚赏金
