This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EK-TM4C1294XL: USBHCD Causes issue to LWIP

Part Number: EK-TM4C1294XL

Hi,

I have created TCP server on static ip using Tiwavare library (Non -RTOS) and is receiving data from client successfully. but when adding USB HOST for USB Drive Interface. I Found that  

USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE); function causes Lwip to stop work and hence server is not started on static i/p. Please Note that there is some modification in LWIP.c and LWIP.h FIles  so, that TCP Server/ Client can be created using static I/p, withought this static i/p doesnot work. 

If the  USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);   then server works fine, But USB drive will not get detected.

enet_tcpecho_server.zip

Regards

Khodidas

  • Hi,

      If you want to use static address, you should configure the lwipopts.h file instead. You need not modify any other LwIP source files.  Follow the below two steps.

      1. In lwipopts.h file modify the below two defines to disable DHCP and AUTOIP:

    #define LWIP_DHCP 0
    #define LWIP_AUTOIP 0

      2. In your call to LwIPInit() you need to specify IPADDR_USE_STATIC flag like below example.

    lwIPInit(g_ui32SysClock, pui8MACArray,
    (192 << 24) | (168 << 16) | (254 << 8) | 82, // example static address 192.168.254.82
    (255 << 24) | (255 << 16) | (0 << 8) | 0,       // example netwrok mask 255.255.255.0
    (255 << 24) | (255 << 16) | (0 << 8) | 0,       // example gateway mask 255.55.255.0
    IPADDR_USE_STATIC);                             // Static Address

      

  • Hi,,

    I have tried this ,it works for static IP, But my issue is that  server gets started and everything works fine, when i insert USB drive to USB Port , server stops working, hence detection of USB drive causes some issue, which causes stops USB implementation as well as TCP Server both, and code stuck in infinite loop withought giving any error, that's why I shared entire project to look out the issue.

  • and code stuck in infinite loop withought giving any error,

    The problem is that you didn't have a vector (USB0OTGModeIntHandler) plugged for the USB. You need this in your startup_ccs.c file. 

    lwIPEthernetIntHandler, // Ethernet
    IntDefaultHandler, // Hibernate
    USB0OTGModeIntHandler, // USB0
    IntDefaultHandler, // PWM Generator 3
    IntDefaultHandler, // uDMA Software Transfer

    Once I add it, it works for me. I modified your code to use my own static IP address. I also modified the code to echo the data back to the client. See below. Note that as suggested in my last reply, you only need to modify the lwipopts.h and call the LwIPInit() with the IPADDR_USE_STATIC flag. See my last reply for detail. 

  • HI,

    can you share the modified files. I added , vector for USB in startup_ccs.c file. It resolved TCP server issue. But my usb stick didn't get detected, I observed that USBHCDEvents usb events not generated. Thank You for  Static IP resolution.

  • Hi,

      Here is the modified project. Again, I only made very minor modification. Below is mainly what I changed.

      1. Modify  lwipopts,h for static IP address

      2. Make call to LwIPInit() to specify static address

      3. Add interrupt vector for USB

      4. I let the original example code determine the MAC address. You hardcoded it.  

      5. I let the server echo back the data.

    All I tried was to find out why the Ethernet got stuck in the infinite loop as reported by you. I didn't investigate if the USB is working or not. I think that is for you to find out. I strongly recommend that you make sure each individual feature is working before putting them together. For example, get the USB working all by itself before you integrate with the Ethernet and DMA stuffs. If you were to verify the USB by itself you would have found out that you are missing the USB interrupt vector. 

    enet_tcpecho_server_04262021.zip

  • I have tested the Modified project send by you, it is working fine. In my code changes/ implementation suggested by you is done and works fine. In Both code USB Enumeration doesn't start and hence not detecting any USB device, the status remains "STATE_NO_DEVICE"

  • Hi,

      It is good that you confirm it is working on the Ethernet side even after the USB stick is plugged in. For the USB side, did you get it to work when it is standing alone? As I mentioned before, it will help you debug if you have each individual feature proven working before putting then all together. 

  • Yes, I have made Separate USB HOST MSC Example and is working perfect. Then after when I combine the code and found this issue.

  • I have made Separate USB HOST MSC Example and is working perfect.

    You said the TivaWare USB HOST MSC example is working. That is good to know. However, in your enet_tcpecho_server.c file, I see that the USB code is much stripped down from the MSC example. Can you confirm that your stripped down USB code when standing alone is also working. In another word, if you remove the Ethernet code or comment out the echo_init() will it work? 

      This is what I'd suggest you try:

      - Remove the Ethernet code or comment out the echo_init() in your existing code. Does the USB work? If not, you need to find out what exactly you changed/stripped from the MSC example that makes it not work now. 

      - Use the MSC example as a starting point and add the Ethernet code. Since you have proven the MSC example works and the Ethernet portion of the code is probably smaller. You can add the Ethernet code gradually and make sure each time you add something the USB MSC continue to work. Don't add all the Ethernet code at once. If you add something that immediately breaks the USB, then what is that something you add to cause that. We can then debug from there. 

  • Yes, I have stripped down USB code, the removed portion is for reading and writing of data with flash. While i have debugged USB HOST MSC and found that on connecting any device to USB, it generates USBHCDEvents and call a callback function which is already declared in the code. this events decide the type of device connected. I have also tested by commenting echo_init() , still issue remains as it is, i am sharing you USB HOST MSC project for further check. meanwhile i will also try to resolve it.3730.usb_host_msc.zip

  • Hi,

      First of all, I'm not a USB expert. So my help on the USB debug will be limited. I may need to forward your question to our USB expert. With that said, I ran your project as is without any modification and I can see the input.txt created and if I do a 'cat' command I'm able to see the "Hello" in the file. See below. 

  • Thank You for help, What you have tested is USB HOST MSC Example that works for me also, i provide for the reference purpose of the merged code named enet_tcpecho_server, which was earlier shared in this discussion. Hope to have soon reply from USB expert

  • Hi,

      Before I send your question to the expert, have you had a chance to work on my recommendation? Let me repeat below again.  Since you have a working MSC example, please just add the Ethernet code piecewise at a time. I hope that you will be easier.  

      - Use the MSC example as a starting point and add the Ethernet code. Since you have proven the MSC example works and the Ethernet portion of the code is probably smaller. You can add the Ethernet code gradually and make sure each time you add something the USB MSC continue to work. Don't add all the Ethernet code at once. If you add something that immediately breaks the USB, then what is that something you add to cause that. We can then debug from there. 

      - Once you get the combine code to work, then again gradually remove the MSC code that you don't need piece by piece at a time. Each time you remove something do a testing to make sure it works before remove additional code. This way it will be easier to debug the subtle difference that causes the issue. 

  • Surely, i will work on that and get back to you soon. Thank you for suggesting a different approach , i haven't think this way.