这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 行业应用 » 汽车电子 » 【S32K3学习整理】使用 LPUART 的loopback 模式实现核间通讯

共2条 1/1 1 跳转至

【S32K3学习整理】使用 LPUART 的loopback 模式实现核间通讯

高工
2026-09-10 17:43:11     打赏

【简介】

在之前的帖子中(【S32K3学习整理】LPUART Loop Mode 使用)介绍了S32K3 的LPUART 的loopback 模式的使用。此方式UART 模块可以将发送的数据回环到内部,如果两个Core,Core0 通过UART 的回环模式发送数据,CORE1读取UART的回环数据就可以实现核间通讯的功能了。基于以上想法我们来配置S32K324 的两个核的UART 配置来完成核间通讯的功能验证。

本地配置CORE0 的UART 参数配置并关闭中断,中断信号由CORE1 来响应。

image.png

image.png

在CORE1 侧开启UART的中断配置。

image.png

添加如下的测试代码core 发送串口数据,在Core1 端的中断函数中打印接收到的数据。

#if defined(LPUART_UART_IP_INSTANCE_USING_3)
static uint8_t uart3_rx_data;
#endif
static int lpuart_init(void)
{
#if defined(LPUART_UART_IP_INSTANCE_USING_1)
static uint8_t uart1_rx_data;
LOG_I("LPUART1 init.");
Lpuart_Uart_Ip_Init(1,&Lpuart_Uart_Ip_xHwConfigPB_1);

/* Enable the LPUART transmitter */
Lpuart_Uart_Ip_SetTransmitterCmd(IP_LPUART_1,true);
/* Enable the LPUART receiver */
Lpuart_Uart_Ip_SetReceiverCmd(IP_LPUART_1, true);

/* open uart rx data full event */
Lpuart_Uart_Ip_SetIntMode(IP_LPUART_1, LPUART_UART_IP_INT_RX_DATA_REG_FULL, true);

Lpuart_Uart_Ip_AsyncReceive(1,&uart1_rx_data,1);
#endif

#if defined(LPUART_UART_IP_INSTANCE_USING_3)
LOG_I("LPUART3 init.");

Lpuart_Uart_Ip_Init(3,&Lpuart_Uart_Ip_xHwConfigPB_3);

/* Enable the LPUART transmitter */
Lpuart_Uart_Ip_SetTransmitterCmd(IP_LPUART_3,true);
/* Enable the LPUART receiver */
Lpuart_Uart_Ip_SetReceiverCmd(IP_LPUART_3, true);

/* 4. Enable receiver manually */
IP_LPUART_3->FIFO |= LPUART_FIFO_RXFLUSH_MASK;
IP_LPUART_3->FIFO |= LPUART_FIFO_TXFLUSH_MASK;

/* open uart rx data full event */
Lpuart_Uart_Ip_SetIntMode(IP_LPUART_3, LPUART_UART_IP_INT_RX_DATA_REG_FULL, true);
#if defined (CORE1)
Lpuart_Uart_Ip_AsyncReceive(3,&uart3_rx_data,1);
#endif
#endif
return 1;
}


static uint8_t uart3_buffer[5];
static uint8_t uart3_buffer_index = 0;

#if defined(LPUART_UART_IP_INSTANCE_USING_3)
void lpuart3_callback_handler(const Lpuart_Uart_Ip_EventType Event,const void *UserData)
{
if(Event == LPUART_UART_IP_EVENT_RX_FULL)
{
PRINTF("%c \r\n",uart3_rx_data);
/* Get date and write to ringbuffer */
uart3_buffer[uart3_buffer_index++] = uart3_rx_data;
if(uart3_buffer_index >= sizeof(uart3_buffer))
uart3_buffer_index = 0;
}
/* Start to recive uart data */
if(Event == LPUART_UART_IP_EVENT_END_TRANSFER)
Lpuart_Uart_Ip_AsyncReceive(3,&uart3_rx_data,1);

if(Event == LPUART_UART_IP_EVENT_ERROR)
Lpuart_Uart_Ip_AsyncReceive(3,&uart3_rx_data,1);
}
#endif


unsigned int uart(char argc, char **argv)
{
if(strcmp(argv[1],"send") == 0)
{
char *ptr = "hello";
for (int i = 0; i < 5; i++)
{
while((IP_LPUART_3->STAT & LPUART_STAT_TC_MASK)>>LPUART_STAT_TC_SHIFT==0);
IP_LPUART_3->DATA = ptr[i];
vTaskDelay(1);
}
}
else if(strcmp(argv[1],"recv") == 0)
{
PRINTF("recv data %c%c%c%c%c\r\n", uart3_buffer[0], uart3_buffer[1], uart3_buffer[2], uart3_buffer[3], uart3_buffer[4]);
}
return 0;
}


   上述测试代码运行验证core0通过UART3 发送的hello 字符串,core1 的UART3中断函数中打印和core0发送的一致。

image.png

使用外设的回环模式进行核间通讯相当共享内存效率是低的多,该实验的目的主要为了验证在K3芯片下通过外设的回环模式实现核间通讯的可行性。


           


专家
2026-09-11 07:32:22     打赏
2楼

谢谢楼主分享


共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]