17 Replies Latest reply on Nov 10, 2017 1:22 PM by dieter 123

    CubeMX LWIP not working

    Raymond Buck

      I have just started experimenting with ST products. I have a STM32F4 Discovery board. I bought a DP83848 PHY on Ebay and connected it to the Discovery board. I downloaded a hex file from here:[http://blog.tkjelectronics.dk/2012/08/ethernet-on-stm32f4discovery-using-external-phy/]

       

      I am able to ping the board and access the web page with no issues.

       

      I then used CubeMX to create a project with nothing but LWIP and two GPIO pins. I figured I would start out simple. The goal was to see if I could get LWIP working. I generated the code and imported it into System Workbench and used STLink to program the board.

       

      I cannot ping the board (I enabled ICMP in CubeMX) and it does not make a DHCP request. I know the request is not being made because Wireshark never sees it.

       

      Do I have to put anything in the main() while loop for lwip to work? Do I need to make any modifications to use the DP83848? I noticed in CubeMX that in the Ethernet Settings, it states LAN8742A for the PHY. Maybe this is my issue? If so, what modifications need to be made to tell CubeMX to use the DP83848?

       

      I have been working on this for two days and making zero progress.

        • Re: CubeMX LWIP not working
          Imen D

          Hello,

           

          Welcome to our Community.
          You'll probably want to review LwIP examples as you can find in the STM32CubeF4 package:
          STM32Cube_FW_F4_V1.15.0\Projects\STM324x9I_EVAL\Applications\LwIP

          Looking to the available examples and these documents can help you a lot to go further in your application:

          - UM1718 for the STM32CubeMX use in the LwIP section.
          - UM1709 STM32Cube Ethernet IAP example: it maybe helpful as it provides a full description of how to implement In-Application Programming (IAP) using Ethernet communication.
          - AN3966 " LwIP TCP/IP stack demonstration for STM32F4x7 microcontrollers” .

          - UM1713 “Developing applications on STM32Cube with LwIP TCP/IP stack". 

           

          Hope this helps you.

           

          Imen

            • Re: CubeMX LWIP not working
              Raymond Buck

              Thanks Imen. I have already read UM1718 and UM1709. I just skimmed through UM1709 as I had no need for IAP. I will review the other two and see if they can help me.

               

              Ray

                • Re: CubeMX LWIP not working
                  Raymond Buck

                  I have made some progress, but not much. I changed the #define IS_ETH_PHY_ADDRESS(ADDRESS) in stm32f4xx_hal_eth.h from 0x20U to 0x01U to match the DP83848. Now when I start the board Wireshark sees this:

                  256    130.602404    0.0.0.0    255.255.255.255    DHCP    350    DHCP Discover - Transaction ID 0x5851f42d
                  257    130.604782    44:8a:5b:d3:4c:8b    Broadcast    ARP    60    Who has 172.16.1.107?  Tell 172.16.1.1
                  258    130.604782    44:8a:5b:d3:4c:8b    Broadcast    ARP    60    Who has 172.16.1.107?  Tell 172.16.1.1

                   

                  172.16.1.107 was cached in the DHCP lease tables. My guess it that in some of my testing, the DHCP server did manage to see the board and assign it an IP address. The MAC address in the DHCP table is 00:80:e1:00:00:00 which is what CubeMX assigned to the board.

                   

                  If I remove the 172.16.1.107 entry from the DHCP table and plug the board in, Wireshark only sees this:

                  347    0.000000    0.0.0.0    255.255.255.255    DHCP    350    DHCP Discover - Transaction ID 0x5851f42d

                   

                  So apparently the board isn't making a DHCP request, but the server(172.16.1.1) is able to see the MAC address???

                   

                  I don't know what else needs to be changed to let the stack know I am using a DP83848 instead of a LAN8742A PHY device. Can anyone tell me what else should be changed?

                • Re: CubeMX LWIP not working
                  Raymond Buck

                  Imen,

                   

                  I finally got my code running on the Discovery board. I can obtain an IP address via DHCP or set a static IP address. I am able to ping the board and it replies back.

                   

                  However, I have a question. How often should I call tje MX_LWIP_Process()? If I call it in the while(1) main loop, it severely hangs the processing of the while loop. I have two LEDs that toggle every 500 msec. If MX_LWIP_Process() is in the while(1) main loop, those LEDs only blink every 4 seconds.

                   

                  If I put MX_LWIP_Process() in a small delay routine inside of the while(1) main loop and call it every few milliseconds, the LEDs blink at their normal rate. I don't actually know how long the delay is, as apparently there is no way in System Workbench to time code execution. I just set a counter that counts down from 16384 to zero. The counter is decremented once each time through the while(1) main loop. If I knew how often to call the MX_LWIP_Process(), I could setup a timer to call it. Or maybe it would be better to use the SysTick timer to call it?

                   

                  My next challenge will be to get a web server running and figure out how the callback functions work.

                   

                  Ray

                    • Re: CubeMX LWIP not working
                      KIC8462852 EPIC204278916

                      In your HAL_Delay interrupt, create a global variable which countdown to zero and set a flag when reaching zero. In your main loop, clear the flag and set the delay, then infinite loop on your lwip polling until the flag is set. This ensure short latency. Same bare metal scheme for button debouncing and autorepeat when pressed continuously...

                        • Re: CubeMX LWIP not working
                          Raymond Buck

                          KIC8462852 EPIC204278916 wrote:

                          In your main loop, clear the flag and set the delay, then infinite loop on your lwip polling until the flag is set.

                          What value should I set delay to? If I understand correctly, HAL_Delay creates a 1ms delay? So if I set the delay to 5ms, I think that would mean it would take 5ms to respond to a ping request? Or I am not understanding what you are saying?

                        • Re: CubeMX LWIP not working
                          Mathias Zviedris

                          Hello Raymond,

                          how did you get the ethernet running ? Im sitting here since hours with the STM3210C-Eval board (F107) and cant get a ping or anything else... . I generated the sourcecode from cubemx and inserted the "MX_LWIP_Process();" into the while(1) of the main-loop.

                          What have i already tried ?

                          -changed phy adress of the DP83848 to 1

                          -fixed the ip adress and connected directly to the pc

                          Read everything what i can find ....

                           

                          Do you have any suggestions ?

                            • Re: CubeMX LWIP not working
                              Raymond Buck

                              Mathias,

                               

                              Yes, I got everything working. I am in the process of moving so I have the board packed up. I was using an F407 board and there may be differences between it and your board. I can place all the files from my project into a zip file and send them to a shared upload site if you think it would help.

                               

                              Raymond

                                • Re: CubeMX LWIP not working
                                  Mathias Zviedris

                                  Hi Raymond, 

                                  that would be great, if you can do that. I´m also wondering that i only can choose "Rx Mode = Polling Mode" under Ethernet Basic Configuration in STM32CubeMX. Was this the same in your project ?

                                   

                                  Thank you for your support !

                                  Mathias

                                    • Re: CubeMX LWIP not working
                                      Raymond Buck

                                      Mathias,

                                       

                                      I uploaded the zip file to here: https://ufile.io/8e4ls

                                      The name of the file is "STM_Ethernet.zip.

                                       

                                      You do not need a username or password as no login is required. The file will remain there for 30 days.

                                       

                                      Yes, the only option that was available under Basic Configuration was "Rx Mode = Pollng Mode". My guess is there was no option to choose interrupt as polling is probably the most easiest way to receive incoming data.

                                       

                                      I didn't look at the schematic of your board to see if the RMII connection pin numbers are the same as the F407 processor. If they are, you could load my hex file into your board and it should work. The hex file is in the Release folder and is named Eth-Test.hex.

                                       

                                      Good luck.

                                       

                                      Raymond

                                      1 of 1 people found this helpful
                                        • Re: CubeMX LWIP not working
                                          Mathias Zviedris

                                          Hi Raymond, 

                                          thank you again for uploading your files. I compared my code to yours and found some differences. Now i can ping the board :-). Now i want to try to setup a webserver. Unluckily the CubeMx only support LwIP version 1.4.1 for F107 series. So there is no "httpd" field to choose in CubeMx. I think i have to implement it somehow by hand.
                                          Mathias

                                          • Re: CubeMX LWIP not working
                                            Alexandre Reis

                                            Hi Raymond, how are you?

                                            Can you send me your project? I'm trying to connect a STM32F4Discovery to a LAN8710 PHY but my network cannot find the uC. I'm using this project (blog.tkjelectronics.dk/2012/08/ethernet-on-stm32f4discovery-using-external-phy/) to upload to my board with the provided changes for the LAN8710. Can you help me?

                                • Re: CubeMX LWIP not working
                                  dieter 123

                                  Hi

                                  How does it come ST is not fixing this issue:

                                  Bug description:

                                  1. start FW with ethernet disconnected

                                  2. wait for 10 secnds

                                  3. plug ethernet cable

                                  4. ping board

                                  -> board wont reply to ping.

                                   

                                  I am using the latest CUBE and F4 repository.

                                  What is the recommended fix here?

                                  Thx