Hi,
I try to develop USB Device RNDIS and lwIP together. My code is based on usb_vnic_bm, lwip_ping_bm and lwip_dhcp_usb_bm examples.
My flow is as follows:
- in main function I initialize USB Device, then lwIP, then in while loop i set up a task that Transmits and Receives buffers by USB (similar to usb_vnic_bm),
- virtual_enet_adapter.c/.h files were remade to not use ENET functions, but to just use queue feature
- netif->linkoutput function puts packets incoming from IP stack to host and later they are send in USB_DeviceVnicTransmit function (it checks if there are any new packet on queue, if so it transmits them on USB)
- packets incoming from host to IP stack are captured into queue by USB_DeviceVnicReceive function that happens in main loop which issues neitf->input function
By this point, please tell me if by workflow is correct. I call lwIP only from mainloop callstack (at least i think i do so
My problem begins in initialization. Actually, main function never gets to while loop. It stops in EthernetifRndisInit function. Code is listed below.
void main(void)
{
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1TxClkOutputDir, true);
USB_DeviceApplicationInit();
lwIPInit();
while (1)
{
#if USB_DEVICE_CONFIG_USE_TASK
USB_DeviceTaskFn(g_cdcVnic.deviceHandle);
#endif
if ((1 == g_cdcVnic.attach))
{
/* User Code */
USB_DeviceVnicTransmit();
USB_DeviceVnicReceive();
}
sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
}
}
err_t EthernetifRndisInit(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
netif->mtu = 1500U;
netif->state = NULL;
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
netif->output = etharp_output;
netif->linkoutput = EthernetifOutput;
/* set MAC hardware address length */
netif->hwaddr_len = ETH_HWADDR_LEN;
memcpy(netif->hwaddr,&g_hwaddr[0], ENET_MAC_ADDR_SIZE);
/*USB enet card is ready*/
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
usb_echo("lwIP started\r\n");
return ERR_OK;
}
void lwIPInit(void)
{
ip4_addr_t netifIPaddr, netifNetmask, netifGw;
time_init();
IP4_ADDR(&netifIPaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
IP4_ADDR(&netifNetmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3);
IP4_ADDR(&netifGw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3);
lwip_init();
netif_add(&rndisNetif, &netifIPaddr, &netifNetmask, &netifGw, NULL,
EthernetifRndisInit, ethernet_input);
netif_set_default(&rndisNetif);
netif_set_up(&rndisNetif);
//netif_set_link_up(&rndisNetif);
ping_init(&netifGw);
}
My function stops exactly at usb_echo("lwIP started\r\n"); print. It prints only "lwIP start", not more, and does nothing more. I can see that device didn't die, because all the callbacks from USB happen, but I think that I got into some kind of infinite loop, but I can find where it is, and why.
I tried putting whole lwIPInit function in critical section, which helped, because whole initialization worked, but right after getting out of it, same thing happened and main loop didn't go further.
Can anyone provide me some tips on what it can be? Or maybe example on how USB Device RNDIS + lwIP should work together?
Thank you, and have a nice day.