Page 1 of 1

udp_send fails depending on a buffer size

Posted: Fri Sep 13, 2019 1:09 pm
by julienD
Hello,

I'm building an app that sends data over udp.

As a beginning, I did something like this:

Code: Select all

static void udpServerTask(void *pvParameters) {

    tcpip_adapter_ip_info_t ip_info;
    tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);

    struct udp_pcb *upcb;
    err_t err;

    upcb = udp_new_ip_type(IPADDR_TYPE_V4);
    ip4_addr_t serverIp;

    if (upcb != NULL) {
        serverIp = ip_info.gw;
        err = udp_connect(upcb, &serverIp, UDP_SERVER_PORT);

        struct pbuf *p;
        char data[128] = "$GPGGA,121222.33,4500.0000,N,00000.0000,W,1,05,3.2,280.2,M,-34.0,M,,*59";   // ok
        char *d;
        d = data;

        while (1) {
            p = pbuf_alloc(PBUF_TRANSPORT, strlen((char*) d), PBUF_POOL);
            if (p != NULL) {
                err = pbuf_take(p, (char*) d, strlen((char*) d));
                err = udp_send(upcb, p);
                pbuf_free(p);
            } 

            vTaskDelay(500 / portTICK_PERIOD_MS);
        }
    }
    
    while (1)
        taskYIELD();
}
With this code, it works as expected (I receive the data on the other side) but if I change declaration of data to send from (look at the size of the array):

Code: Select all

     char data[128] = "$GPGGA,121222.33,4500.0000,N,00000.0000,W,1,05,3.2,280.2,M,-34.0,M,,*59";
to:

Code: Select all

     char data[255] = "$GPGGA,121222.33,4500.0000,N,00000.0000,W,1,05,3.2,280.2,M,-34.0,M,,*59";
then function udp_send fails with errorCode -6 which is "ERR_VAL, No PCB or PCB is dual-stack".

I also noticed a supect warning that I was unable to remove:

Code: Select all

warning: passing argument 2 of 'udp_connect' from incompatible pointer type [-Wincompatible-pointer-types]
  err = udp_connect(upcb, &serverIp, UDP_SERVER_PORT);
I don't understand what happens. I'm not sure it is udp related or OS related. Btw the task is allocated with a huge stack:

Code: Select all

 xTaskCreate(udpServerTask, "xcTrackServer", 4096 * 4, NULL, 5, NULL);
Is is allocated in SYSTEM_EVENT_STA_GOT_IP event.