IMXRT1060 USB Device RNDIS + lwIP -- lwIP stuck at netif_add

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IMXRT1060 USB Device RNDIS + lwIP -- lwIP stuck at netif_add

Jump to solution
1,159 Views
mbora
Contributor III

Hi,

I try to develop USB Device RNDIS and lwIP together. My code is based on usb_vnic_bmlwip_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.

0 Kudos
1 Solution
1,147 Views
mbora
Contributor III

For anyone who also struggles, you need  to add

/*!
 * @brief Interrupt service for SysTick timer.
 */
void SysTick_Handler(void)
{
    time_isr();
}

 in main loop. Enjoy 

View solution in original post

7 Replies
526 Views
john8
Contributor III

Hi Maria,

Many thanks for your reply.

I am trying (struggling actually) to add "USB Device RNDIS" to the evkmimxrt1060_lwip_httsrv_freertos example project in the sdk.

I have used the evkmimxrt1060_dev_cdc_vnic_freertos project as a guide and your code above to integrate the USB device netif to lwip. But I am not certain how to add the netif.

The project enumerates the usb device ok and web pages are served via the ethernet connection, but not the rndis. ideally I would like both interfaces working but I really need rndis first.

I have looked at your code above and I understand what you have done there but I am not sure of the queue feature or how you interface the rndis_send and rndis_receive functions/packets/queue to the netif->input and netif->linkoutput...

any help or example code would be appreciated. I have posted my mcuxpresso project I have thus far and your comments would be greatly appreciated if you have the time. 

kind regards,

John Coppola

0 Kudos
514 Views
mbora
Contributor III

Hi John,

I will attach you the whole project. I based it on USB VNIC and USB VCOM examples.

The most important files for you are:

/lwip/port/usb_ethernetif_freertos.c

/source/virtual_nic_enet_adapter.c

/source/composite.c

If the code is not understandable to you I will try to help you.

Also, please keep in mind that it was just POC for a bigger project, and the code isn't very pretty or well commented like it should be.

Hope this would help you.

Maria

0 Kudos
506 Views
john8
Contributor III

Hi Maria,

This is much appreciated. Once I have a working sample, I can take it from there. I will let you know if I have any questions and how I go.

Thankyou for sharing and let me know if I can return the favour.

 

Kind regards,

John Coppola

0 Kudos
499 Views
mbora
Contributor III
No problem, I'm happy I could help :).
Maria
1,148 Views
mbora
Contributor III

For anyone who also struggles, you need  to add

/*!
 * @brief Interrupt service for SysTick timer.
 */
void SysTick_Handler(void)
{
    time_isr();
}

 in main loop. Enjoy 

537 Views
john8
Contributor III

Hi,

I am trying to do the same thing. I was wondering if you has any other information that might help me and whether you integrated FreeRTOS as well or is it baremetal?

thanks in advance

 

John

 

0 Kudos
529 Views
mbora
Contributor III
Hi,
I also integrated it with FreeRTOS. What are you interested in particularly? Did you manage to get the USB to work?
Feel free to ask, I will try to help you.
Maria
0 Kudos