strange problem with lwip udp, only broadcast address works
I'm using stm32cubeMX to create the project on a nucleo F767ZI board
I'm using FreeRTOS and LWIP for a simple UDP sender.
I can get IP address form DHCP and ping works, and the packet can be sentout without any problem if the destination is the broadcast address, if I set it to some computer's address, the program will hang, I tried to put a LED GPIO after the send function call, seems it's not return from that function. on line debuging shows it's endup in a hard fault with unaligned memory access.
I also tried specify the IP address instead of using DHCP, still only works in boradcast only. The program will also endup in hard fault with unaligned memory access.
While the dubuging, I found a stange problem, The DHCP works, both ping and DHCP server shows the board has successfuly got the ip address.
If the destination is a broadcast, during the debug, I can find the "struct netif *netif_default;" and "struct netif *netif_list;" in netif.c is pointing to the correct interface with the correct ip address, netmask and gateway.
However, when the UDP send destination is set to a specific ip address, even before calling the udp send, the "struct netif *netif_default;" and "struct netif *netif_list;" in netif.c shows the ipaddress is 0, which lead to unable to find the route. and hanging the system which shouldn't happen. It suppose to return error that unable to find the host instead of hanging.
Here is the code:
void StartDefaultTask(void const * argument)
{
uint8_t pui8Text[19] = "This is a Test 1.\n";
volatile err_t tErr;
struct netconn* ptUDP;
struct netbuf* ptNetBuf;
ptUDP = netconn_new(NETCONN_UDP);
tErr = netconn_bind(ptUDP, IP_ADDR_ANY, 5555);
// IP4_ADDR(&tDest, 192, 168, 001, 160); // not work
IP4_ADDR(&tDest, 192, 168, 001, 255); // works
// IP4_ADDR(&tDest, 255, 255, 255, 255); // works
// tDest.addr = 0xa001a8c0; // not work
// tDest.addr = 0xffffffff; // works
ptNetBuf = netbuf_new();
netbuf_alloc(ptNetBuf, 18);
netbuf_ref(ptNetBuf, pui8Text, 18);
vTaskDelay(pdMS_TO_TICKS(1000));
for(;;)
{
tErr = netconn_sendto(ptUDP, ptNetBuf, &tDest, 5555);
vTaskDelay(pdMS_TO_TICKS(100));
}
}
