2555 views|0 replies

6841

Posts

11

Resources
The OP
 

[National Technology N32G457 Review] UART-DMA indefinite length packet loss test [Copy link]

 

Purpose: Test the receiving and sending stability of the development board serial port at various baud rates

Evaluation environment: 1. Development board: National Technology N32G457XVL-STB V1.1

2. USB-TTL: CP2102

3. Serial port assistant: SSCM V5.13.1

4. Development software: RT-Thread studio 2.1.5

Serial port receiving and sending program:

/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-01-23     Administrator       the first version
 */

#include <rtthread.h>
#include "uartdma.h"
#include <rtdevice.h>

#define UART2_NAME "uart2" /* 串口设备名称 */

/* 串口接收消息结构体 */
struct rx_msg
{
    rt_device_t dev;
    rt_size_t size;
};

struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;

/* 串口设备句柄 */
static rt_device_t serial2;
/* 消息队伍控制块 */
static struct rt_messagequeue rx_mq;

/*接收数据回调函数 */
static rt_err_t uart2_input(rt_device_t dev, rt_size_t size)
{
    struct rx_msg msg;
    rt_err_t result;
    msg.dev = dev;
    msg.size = size;

    result = rt_mq_send(&rx_mq, &msg, sizeof(msg));
    if(result == -RT_EFULL)
    {
        /* 消息队伍满 */
        rt_kprintf("message queue full!\r\n");
    }
    return result;
}

static void serial2_thread_entry(void *parameter)
{
    struct rx_msg msg;
    rt_err_t result;
    rt_uint32_t rx_length;
    static char rx_buffer[RT_SERIAL_RB_BUFSZ +1];
    while(1)
    {
        rt_memset(&msg, 0, sizeof(msg));
        /* 从消息队列中读取消息 */
        result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), RT_WAITING_FOREVER);
        if(result == RT_EOK)
        {
            /* 从串口读取数据 */
            rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
            rx_buffer[rx_length] = '\0';
            /* 通过串品设备输出读取到的消息息 */
            rt_device_write(msg.dev, 0, rx_buffer, rx_length);
            /*打印数据 */
            rt_kprintf("%s\n", rx_buffer);

        }
    }
}

int uart2_dma_sample(void)
{
    rt_err_t ret = RT_EOK;
    char uart_name[RT_NAME_MAX];
    static char msg_pool[256];
    char str[] = "Hello RT-Thread!\r\n";
    config.baud_rate = BAUD_RATE_921600;
    rt_strncpy(uart_name, UART2_NAME, RT_NAME_MAX);

    /* 查找串口设备 */
    serial2 = rt_device_find(uart_name);
    if(!serial2)
    {
        rt_kprintf("Find %s failed!\r\n", uart_name);
        return RT_ERROR;
    }

    /* 初始化消息队列 */
    rt_mq_init(&rx_mq,
            "rx_mq",
            msg_pool,
            sizeof(struct rx_msg),
            sizeof(msg_pool),
            RT_IPC_FLAG_FIFO);

    /* 以DMA接收及轮询发送方式打开串口设备 */
    rt_device_control(serial2, RT_DEVICE_CTRL_CONFIG, &config);
    rt_device_open(serial2, RT_DEVICE_FLAG_DMA_RX);
    /* 设置接收回调函数 */
    rt_device_set_rx_indicate(serial2, uart2_input);
    /* 发送字符串 */
    rt_device_write(serial2, 0, str, (sizeof(str) - 1));

    /* 创建serial2 线程 */
    rt_thread_t thread_uart2 = rt_thread_create("serial2", serial2_thread_entry, RT_NULL, 1024, 25, 10);
    if(thread_uart2 != RT_NULL)
    {
        rt_thread_startup(thread_uart2);
    }
    else {
        ret = RT_ERROR;
    }
    return ret;
}

The test method is: use the serial port assistant to send 64 characters at a time, record the difference between sending and receiving, and the test time is about 30 seconds.

The test results are shown in the following table:

Baud rate Sending interval send data Receive data Difference
921600 1ms 123200 123200 0
115200 1ms 122624 122624 0
9600 1ms 28864 24128 4376
9600 50ms 30848 25792 5056
9600 100ms 17216 17216 0

At high baud rates, the serial port processed data in time without packet loss, while at 9600 baud rate, packet loss occurred because the sending was blocked and could not be processed. From the test results, the serial port data processing of this chip is commendable, especially the DMA receiving processing capability.

921600:

115200

9600

9600 interval 50ms:

9600 interval 100ms

This post is from Domestic Chip Exchange
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list