This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UDP buffer allocation fails

Hello,

I'm trying to send UDP-packets from an LM3S9B96 to the PC. But every time when I call the Library-function "udp_get_buf(len);" I get an Hardfault-IRQ.
Receiving the UDP-Packets from the PC is no problem, so my initialization from the UDP should be ok.
Any ideas what could be wrong?

Thank you.

Regards,
Mike

Parents
  • Here are the important parts of my code:

    int main (void)
    {
            InitDevice();
            init_TcpNet();
    
            /* Initialize UDP Socket and start listening */
            ucMainUDP_socket = udp_get_socket (0, UDP_OPT_SEND_CS | UDP_OPT_CHK_CS, UDP_callback);
            if (ucMainUDP_socket != 0)
            {
            udp_open (ucMainUDP_socket, UDP_PORT_NUM);
            }
    
            //---RTOS-Setup
            os_sys_init_prio(InitTask,250);                 // init RTOS with 'InitTask' as start-Task and prio of 250
    }
    
    __task void InitTask(void)
    {
            // start 'UDPTask' with an priority of 100
            tID_UDPTask = os_tsk_create(UDPTask, 100);
            // start 'Timer'
            tID_TimerTask = os_tsk_create(tick_timer, 100);
    
            // we do not need 'InitTask' anymore
            os_tsk_delete_self();
    }
    
    __task void UDPTask(void)
    {
            while(1)
            {
                    main_TcpNet();
                    os_tsk_pass ();
            }
    }
    
    __task void tick_timer (void) {
      os_itv_set (10);
      while (1) {
        os_itv_wait ();
        /* Timer tick every 100 ms */
        timer_tick ();
      }
    }
    
    
    unsigned short UDP_callback (unsigned char soc, unsigned char *rip, unsigned short rport, unsigned char *buf, unsigned short len)
    {
            if (len < 10)
                    return (0);
    
            if (soc != ucMainUDP_socket)
            {
            /* Check if this is the socket we are connected to */
            return (0);
            }
    
            procrec(buf,len);
    
            return (0);
    }
    
    void procrec (U8 *buf, unsigned short len)
    {
    
            char udp_msg[]={"Hello World!"};
            static U8 remip[] = {192,168,240,77};
            U8 *sendbuf;
            U16 len1;
    
            len1 = strlen(udp_msg);
            if (ucMainUDP_socket != 0)
            {
    //              sendbuf = udp_get_buf(13);
    //              strcpy ((char*)sendbuf, udp_msg);
    //              udp_send (ucMainUDP_socket, remip, 23456, sendbuf, len1);
            }
            return;
    
    }
    


    Is there an evident mistake?

Reply
  • Here are the important parts of my code:

    int main (void)
    {
            InitDevice();
            init_TcpNet();
    
            /* Initialize UDP Socket and start listening */
            ucMainUDP_socket = udp_get_socket (0, UDP_OPT_SEND_CS | UDP_OPT_CHK_CS, UDP_callback);
            if (ucMainUDP_socket != 0)
            {
            udp_open (ucMainUDP_socket, UDP_PORT_NUM);
            }
    
            //---RTOS-Setup
            os_sys_init_prio(InitTask,250);                 // init RTOS with 'InitTask' as start-Task and prio of 250
    }
    
    __task void InitTask(void)
    {
            // start 'UDPTask' with an priority of 100
            tID_UDPTask = os_tsk_create(UDPTask, 100);
            // start 'Timer'
            tID_TimerTask = os_tsk_create(tick_timer, 100);
    
            // we do not need 'InitTask' anymore
            os_tsk_delete_self();
    }
    
    __task void UDPTask(void)
    {
            while(1)
            {
                    main_TcpNet();
                    os_tsk_pass ();
            }
    }
    
    __task void tick_timer (void) {
      os_itv_set (10);
      while (1) {
        os_itv_wait ();
        /* Timer tick every 100 ms */
        timer_tick ();
      }
    }
    
    
    unsigned short UDP_callback (unsigned char soc, unsigned char *rip, unsigned short rport, unsigned char *buf, unsigned short len)
    {
            if (len < 10)
                    return (0);
    
            if (soc != ucMainUDP_socket)
            {
            /* Check if this is the socket we are connected to */
            return (0);
            }
    
            procrec(buf,len);
    
            return (0);
    }
    
    void procrec (U8 *buf, unsigned short len)
    {
    
            char udp_msg[]={"Hello World!"};
            static U8 remip[] = {192,168,240,77};
            U8 *sendbuf;
            U16 len1;
    
            len1 = strlen(udp_msg);
            if (ucMainUDP_socket != 0)
            {
    //              sendbuf = udp_get_buf(13);
    //              strcpy ((char*)sendbuf, udp_msg);
    //              udp_send (ucMainUDP_socket, remip, 23456, sendbuf, len1);
            }
            return;
    
    }
    


    Is there an evident mistake?

Children