This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/AM3352: UDP send error

Part Number: AM3352
Other Parts Discussed in Thread: SYSBIOS, AM3358

Tool/software: TI-RTOS

Hi

     I have creat a project to send data in UDP,this is my test file.

It can send 10 datas by udp,but it will failed after about a few minutes.

the log shows error on the API sendto,it returns -1,and I have check the error code,it is 64.

It will stop after sending 23,740 or so.

please help me to resolve this issue.

#define MAXBUF  10
#define NDK_UDPPORT 5555


/* talk to NDK echo server running on Concerto board */
#define SERVER_UDPPORT 5555
#define SERVER_IP "192.168.0.112"

#define SLEEPTIME 1000

#define Sleep Task_sleep

/* port the UDP echo Linux side tool "udpSendRecv" to NDK on Freon */
void udpEchoClient(void)
{
    int i;
    SOCKET sockfd;
    int sleepTime = SLEEPTIME;
    struct sockaddr_in bindAddr;
    struct sockaddr_in servAddr;
    int bytes_read, bytes_sent;
    char *buffer;
    struct sockaddr_in fromAddr; /* originally was type 'sockaddr_storage' */
    int fromAddrLen = sizeof(fromAddr);
    int ret = 0;

    int count = 0;
    int id;
    time_t start;
    unsigned int buffSize  = MAXBUF;

    ret = fdOpenSession(TaskSelf());
    UART_printf( "fdOpenSession result = %d\n",ret);
    Task_sleep(10000);
    buffer = malloc(buffSize);
    if (!buffer) {
        UART_printf("failed to malloc buffer!\n");
        goto QUIT;
    }
    memset(buffer, 0, buffSize);

    /* initialize destination address */
    memset(&servAddr, 0, sizeof(servAddr));
    servAddr.sin_family = AF_INET;
    inet_aton(SERVER_IP, &servAddr.sin_addr);
    servAddr.sin_port = NDK_htons(SERVER_UDPPORT);

    /* create the socket */
    /* TODO: assuming socket created successufully, due to cast error */
    sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if(NULL == sockfd)
    {
        UART_printf( "socket failed\n");
    }

    /* bind our socket to a particular port. Must bind else server reply drops! */
    memset(&bindAddr, 0, sizeof(bindAddr));
    bindAddr.sin_family = AF_INET;
    bindAddr.sin_addr.s_addr = INADDR_ANY;
    bindAddr.sin_port = NDK_htons(NDK_UDPPORT);
    if (bind(sockfd, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) < 0) {
        UART_printf("failed to bind() the socket!\n");
        goto QUIT;
    }

    /* print out sockets info */
    UART_printf("Starting test with a %d uSec delay between transmits\n", sleepTime);

    /* loop */
    i = 0;
    while (1)
    {
        buffer[0] = (char)(++i);
        buffer[buffSize - 1] = (char)~i;

        /* send the data */
        bytes_sent = sendto(sockfd, buffer, buffSize, 0, (struct sockaddr *)&servAddr, sizeof(servAddr));

        if (bytes_sent < 0 || bytes_sent != buffSize) {
           UART_printf("[id %d] stopping test. sendto returned %d (error %d)\n", id,
                   bytes_sent, fdError());
           goto QUIT;
        }

        Task_sleep(1000);
    }

QUIT:
        UART_printf("--- at QUIT\n");
    /* clean up */
    if (sockfd) {
        fdClose(sockfd);
    }

    free(buffer);

    fdCloseSession(TaskSelf());
}

  • Hi,

    Please provide the CCS project for this and clarify the SYSBIOS, XDC, NDK version. Also instruction how do you test? What is running on PC side?

    Regards, Eric 

  • Hi

    The PDK version is pdk_am335x_1_0_13,sysbios is bios_6_73_01_01,NDK version is ndk_3_40_01_01.

    the basic project is NIMU_BasicExample_bbbAM335x_armExampleproject,I have add the udp task for test.

    I run a sokit software on the PC side which can receive udp packets.

  • Hi Eric

        Is there any update today?

  • Hi,

    Your code is a continuous send using UDP from EVM to PC, it is possible that the NDK sends the packets too fast and the EMAC driver can't handle it and there is no free Tx descriptor available. 

    Are you able to add a counter to see if this is the case in pdk_am335x_1_0_14\packages\ti\transport\ndk\nimu\src\v4\cpsw_nimu_eth.c:

    volatile int sendError = 0;
    {{ void CpswHwPktTxNext( NIMU_CpswPdInfo *pi )}}
    {{ {}}


         sendResult = emac_send(0, &csl_send_pkt);

         if(sendResult){{{}}

            NIMU_drv_log1("CPSW_sendPacket() returned error %08x\n",i); /* Free the packet as the packet did not go on the wire*/

            PBM_free( (PBM_Handle)csl_send_pkt.AppPrivate );

            sendError++;

    {{    }}}

    To see if you have any sendError?

    Regards, Eric

  • Hi Eric

       I added a variable to record the number of cycles sent.

    When 1215 packets of data were sent,

    the sockit tool in the PC segment could no longer receive the data.

    However, the counter on the device side showed that it was still sending normally until 2510 packets.

    In addition, I doubled the interval of sending data.

    Sockit tool could receive 608 packets of data.

    The device side made an error when sending the 1255th packet,

    which was exactly half of the time interval without modification.

  • Hi,

    If your PC tool can't receive packets while the A8 is still sending, then it is your PC tool problem. You may check the setup of the PC side, if any buffer size you can increase.

    For the A8 side, if you can confirm the packets counter increased correctly at the switch level, then A8 is working as expected. Please look at the AM3358 Techincal Reference Manual, 14.3.2.20 CPSW_3G Network Statistics. Good Tx Frames (Offset = 34h) to make sure.

    Regards, Eric 

  • Hi

    I don't think it is a problem of PC segment tools.

    Udp does not consider the state of the receiver when sending data.

    It is only responsible for sending data, regardless of whether the receiver receives data or not.

    In addition, I want to reiterate that my problem is to call the socket sending interface, which is not the sending interface of CPSW.

  • Hi,

    If you think the problem is CPSW send:

    1. At the application level, you have a Tx counter
    2. At the NDK level, you have a Tx counter, please look at CCS expression window with global variables: NDK_udps, NDK_ips
    3. At the MIMU driver level, I suggested you to add a counter,  sendError++;
    4. At the CPSW switch level, I suggested you track Tx good frame counter in CPSW port statistics
    5. At the Rx side, you have a Rx counter

    What you find is that counter at 1 doesn't match counter 5, can you follow the suggestion 2-4 to see where the packets got lost.

    Regards, Eric