Skip to main content
Explorer
February 11, 2020
Solved

[bug fixes] STM32H7 Ethernet

  • February 11, 2020
  • 34 replies
  • 44437 views

@Amel NASRI​, @ranran​, @Piranha​, @Harrold​, @Pavel A.​ 

V2 of my fixes and improvements to H7_FW V1.5.0/V1.6.0 Ethernet...

Changes include

  • Decoupling receive buffers from receive descriptors so buffers may be held any length time without choking receive.
  • Optionally queuing transmit, so transmit doesn't need to block until complete.
  • Many bug fixes.

Find full details and source in the attached zip. V1 was posted to another developer's question. Please post any questions about V2 here.

    This topic has been closed for replies.
    Best answer by Amel NASRI

    Dear All,

    Our Experts tried to answer almost all the limitations reported in this thread.

    Please refer to this post for more details.

    At this point, I suggest to close this discussion as it becomes difficult for us to follow it with the great number of comments.

    Don't hesitate to submit your new posts asking new questions.

    Thanks for all the ones involved to make ST solutions more efficient.

    -Amel

    34 replies

    Visitor II
    October 28, 2020

    Hi Alister,

    Thank you by your work. Do you have anything like this to F429ZI or F767Zi board? I could not generate and run examples in CubeMX that use ethernet, RTOS and LwIP, yet.

    Thanks,

    Geraldo.

    alisterAuthor
    Explorer
    October 28, 2020

    Hi Geraldo

    I've nothing on F4. The shop I work has F7 with working ethernet including fixes to rx-DMA, rx-buffer-managements, auto-negotiation, maybe some others. Its FW_F7 version is more than 3 years old. I can't share it.

    Check @Piranha​'s many threads and posts. Here are some:

    https://community.st.com/s/question/0D50X0000BOtfhnSQB/how-to-make-ethernet-and-lwip-working-on-stm32

    https://community.st.com/s/question/0D50X0000AhNBoWSQW/actually-working-stm32-ethernet-and-lwip-demonstration-firmware

    https://community.st.com/s/question/0D50X0000B2AG7FSQW/ethernet-send-complete-interrupt-not-triggered-in-stm32f7

    Check searches of the community:

    https://community.st.com/s/global-search/stm32f4%20ethernet

    https://community.st.com/s/global-search/stm32f7%20ethernet

    Check Google:

    https://www.google.com/search?q=%22stm32f7%22+ethernet+driver+fixes&oq=%22stm32f7%22+ethernet+driver+fixes

    Does anyone following this thread have a link to F4/F7 fixes they can share?

    [EDIT] You could clarify if your boards are purported to be supported by the examples, and how it doesn't work. Also as the focus of this thread is H7 ethernet, please post to an existing F4 and/or F7 thread describing the same problems or, if you can't find one, start another.

    Visitor II
    October 29, 2020

    Hi Alister,

    Thanks by your answer. I´ll read the documents.

    By the way. I´ve some tests. For example in cubemx, I tried configure ETH, RTOS with CMCIS_v1 (and with CMCIS_v1) and Lwip. But with the generated code any IP adress is assigned. So I´m not sure about the correct con figuration to put the system with RTOS and Lwip to run. I´m analysing the LwIP_HTTP_Server_Netconn_RTOS example. I saw it use CMCIS_v1.So I tryied configure a project in CubeMX to use RTOS with cmcis_v1 and Lwip. The project compile and run, but the IP is not assigned (with or not using DHCP). I thinks it´s a problem with the DHCP or LwIP configuration. So I´ll check.

    I´m a eletrical engineer student in Brasil in a critical situation. I´ve to finish a prototype that use socket to send information to a remote server. I´ve tried Texas board, but I decide change and try STM. But It´s very dificult to develop project without an oficial tutorial to explain for example "A simple socket example in CubeMX using RTOs and LwIP?". You have to read a lot of documentation that doesn´t reference and put the real version of packages used, for example CMSIS, LwIP, etc; So its hard, but I´ll try.

    Thanks and if your have any suggestion to prepare a simple project configuration based in F429ZI or F767ZI to use RTOS and Socket and could send to me, I´ll be great. My email is geraldo@mlink.com.br. I´ll search the links and open a new thread to F4 or F7.

    Bellow is the code that I´ve tested without sucess. The generated code call MX_LWIP_Init(); So I decided adapt the code from LwIP_HTTP_Server_Netconn_RTOS examples. But it didn´t run. It compile but the IP is not assigned.

    /* USER CODE END 4 */

    /* USER CODE BEGIN Header_StartDefaultTask */

    /**

     * @brief Function implementing the defaultTask thread.

     * @param argument: Not used

     * @retval None

     */

    /* USER CODE END Header_StartDefaultTask */

    void StartDefaultTask(void const * argument)

    {

     /* init code for LWIP */

    // MX_LWIP_Init();

     /* USER CODE BEGIN 5 */

    /* Create tcp_ip stack thread */

    tcpip_init(NULL, NULL);

    /* Initialize the LwIP stack */

    Netif_Config();

     /* Notify user about the network interface config */

     User_notification(&gnetif);

    #ifdef USE_DHCP

     /* Start DHCPClient */

     osThreadDef(DHCP, DHCP_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE * 2);

     osThreadCreate (osThread(DHCP), &gnetif);

    #endif

     /* Infinite loop */

     for(;;)

     {

      /* Delete the Init Thread */

      osThreadTerminate(NULL);

     }

     /* USER CODE END 5 */

    }

    Thanks,

    Geraldo.

    Visitor II
    November 1, 2020

    I found this thread based on the thread: "How to make Ethernet and lwIP working on STM32" in which the OP frustratingly points out a lot of defects in the STM32 code but refuses to post any actual code... what the actual heck? So thank you alister for making the world a better place! Does the code posted here by alister cover all the topics mentioned in the other thread?

    I'm working on the STM32F746 with CubeMX 5.6.1 and STM32Cube MCU package 1.16.0. I built working ethernet code with a simple http server and DHCP. I'm planning to try patching code based on the examples here, but just wondering the best way to do that since I know this is designed for the H7. Are there any tips for doing this successfully?

    Also, I see references to "iperf2" but have never used this before... I'd like to test the performance and also measure the CPU overhead. If anyone has ideas on how to set this up with the stock firmware and LwIP it would be very helpful! I want to have a solid base on which to build Ethernet-based projects and just want to make sure I'm not running into any issues later. I'll gladly publish my base code for the STM32F746ZG Nucleo-144 dev board if I can get some help to patch the necessary bits.

    alisterAuthor
    Explorer
    November 1, 2020

    >thank you alister for making the world a better place

    Thank you elmood.

    >what the actual heck?

    You've more than you've paid for. He's shared a lot of clues.

    >"iperf2"

    Cube generates it at Middlewares\Third_Party\LwIP\src\apps\lwiperf\lwiperf.c. lwIP v2.0.3 supports TCP server only. V2.1.2 supports TCP client and server. There’s UDP support at https://savannah.nongnu.org/patch/?9751. Its tool can be found at https://sourceforge.net/projects/iperf2/. iperf-2.0.9-win64 works with lwIP v2.0.3, or iperf-2.0.14a-win.exe with -C (compatibility). 

    >Does the code posted here by alister cover all the topics mentioned in the other thread?

    It's on my todo list to check a potential lockup when an MMC count reaches 2^31, mentioned at https://community.st.com/s/question/0D50X0000AIdSc0SQF/unwanted-interrupts-for-ethernetmac-mmc.

    The code works as is. It must have an MCU region for the DMA descriptors. You could code it for without. But I think that's a poor choice and performance wouldn't improve. It's a poor choice because there's a principle in software that bugs are proportional to lines of code, and that doesn't mean skimp on comments. It means you want a job done once and used many.

    >STM32F746

    Similar, but different. Please create a new thread for it.

    Visitor II
    November 12, 2020

    I’ve tried posting new threads in the past and never get replies.

    After inspecting your code and trying to understand how to port to F7 or F4 I can across some lwip docs where they recommend a very simple zero copy pseudo code.

    Also it seems like the stock HAL drivers use user supplied buffers for TX and RX so why is it necessary to even modify the HAL driver at all? Wouldn’t it be possible to just make the DMA buffers also useable by LwIP as pbufs? I’d like a solution that is more portable but after comparing the HAL changes against the stock H7 code I’m lost, and there is no hope for me to port this stuff to other chips. I’m very good designing my own code but not good at reversing other people’s work. :(

    At this point I’m looking for other IP stack recommendations if anyone has any... honestly I just want to work on my actual application code.

    Visitor II
    November 10, 2020

    (edit: sorry I have answered in the wrong position, and I cannot delete this. I have moved my answer below!)

    Explorer II
    November 26, 2020

    To remove an answer, use the tag (black triangle on the right of the message) and leave a message to the moderator.

    Visitor II
    November 25, 2020

    Hey, @alister​ 

    I'm working on a custom board project and I'm still in the prototype phase. On board I have a 7" display, ethernet, sd-card,RS485, RS232 and other peripherals. Recently I switched from STM32F767 mcu to fully pin compatible STM32H753. On the F7 project I  implemented VNC server. So when porting the project from F7 to H7 I issued very strange behaviours with ethernet (VNC server disconnecting randomly). Until I found your fix I lost one week of debugging and looking for a bug in my code. So now that I patched drivers following your fix everything works like never before. Many thanks to you for sharing the fix. But I'm wondering why STs HAL team is not doing anything to fix that issue.  You documented all the fixes well and shared all the code. So If I can patch that in one hour why can't they fix it in 9 months. @Amel NASRI​ ​ I think this needs to be number one priority in next release of drivers !

    Visitor II
    December 6, 2020

    I have adapted @alister​'s V2 code to work with the LAN8742A PHY found on the NUCLEO H743ZI2 board and made a few minor changes to make it easier to integrate with projects created using STM32CubeIDE.  My modified code (along with instructions on how to integrate it into an existing STM32CubeIDE project) can be found here on github: https://github.com/dgburr/H743ZI2-ethernet

    I hope that proves useful to somebody out there.  Thanks to @alister ​for your great work!

    Explorer II
    December 6, 2020

    Thank you very much !!!!

    Visitor II
    December 22, 2020

    Greetings to all strugling with Ethernet!

    PLEASE teak a quick peak at the topic posted here:

    https://community.st.com/s/question/0D53W00000S8YnYSAV/semaphore-hang-when-trying-to-send-data-bigger-than-one-tcp-frame

    and try to identify the type of the bug we are experiencing. If someone has any idea please give a suggestion as we are desperate to make our product work, but failing to so for several months now.

    On the other hand, If there is any expert in this field who is willing to guide us in solving this problem we are willing to donate and/or pay for the time spent on this piece of code we are trying to fix. Just drop me a mail to:

    spasovski.dejan@gmail.com

    Its scarry how stuck we are with a problem of sending few kilobytes through Ethernet in the 21st century in the tme of communications, where this should be long time closed issue by ST firmware developers. Shame ST MCUs are well built, but the libraries generated by cube are making it nightmare to work with.

    Instead of focusing on our application development we are stuck for months solving bugs and concepts from the maker of the chip for something that these days sould be no brainer to implement and shoul take no time to drop into a project.

    We have spent a lot of money on our custom hardware and we are stuck with this MCU, but eventually if this goes on furher we would need to select another platform and sadly say goodbye ST.

    I hope some good fellow will show up to enlighten us.

    Thanksnin advance!

    Regards

    Dejan

    alisterAuthor
    Explorer
    December 22, 2020

    This thread describes a modified working Ethernet driver for the STM32H7.

    The thread you've linked says you're using STMCubeID generated code. So that wouldn't be this Ethernet driver.

    I'm posting a reply to your thread (sorry I've no quick answer).

    Unless someone seeing this knows the fix and it's to do with the modified driver of this thread, please move this discussion to Dejan's thread.

    Regards

    Alister

    Visitor II
    January 7, 2021

    I've been also struggling similar problem quite long time. My problem is that network service (ex. ping/udp) suddenly stop about 3 or 5 mins after started. (The traffic is bigger the time is shorter.)

    I've tested the bug-fixed files but failed. today I tried as below.

    ** Make low_level_output and low_level_input no running concurrently **

    ethernetif.c (not bug-fixed, from generated one by Cube)

    /* USER CODE BEGIN 3 */

    SemaphoreHandle_t eth_sem;

    /* USER CODE END 3 */ 

    static void low_level_init(struct netif *netif)

    {

    // original code

    /* USER CODE BEGIN OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */

     vSemaphoreCreateBinary(eth_sem);

     osThreadDef(EthIf, ethernetif_input, osPriorityRealtime, 0, INTERFACE_THREAD_STACK_SIZE);

     osThreadCreate (osThread(EthIf), netif);

    /* USER CODE END OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */

    // original code

    }

    static err_t low_level_output(struct netif *netif, struct pbuf *p)

    {

      xSemaphoreTake(eth_sem, pdMS_TO_TICKS(1));

    // original code

     xSemaphoreGive(eth_sem);

     return errval;

    }

    static struct pbuf * low_level_input(struct netif *netif)

    {

      xSemaphoreTake(eth_sem, pdMS_TO_TICKS(1));

    // original code

     xSemaphoreGive(eth_sem);

     return p;

    }

    Even if it's not  fundamental solution, the result is quite good(stopping doesn't occur anymore) for me and performance also not bad.

    alisterAuthor
    Explorer
    January 8, 2021

    >I've tested the bug-fixed files but failed

    Which is it? You failed to port the fixes or the fixes failed?

    The shop I work have used these fixes/imrovements without problem more than a year in a product with moderate ingress traffic, many concurrent connections, UDP and TCP, bearing data, control and management. The fixes/improvements are good for us.

    I'd be grateful if you'd share specific details. If there's a problem with the fixes/improvements, I want to know.

    >today I tried as below.

    You've prevented concurrent receive/transmit. With the material I've shared here it shouldn't take long to properly isolate and fix it. Without isolating it, you couldn't know your workaround is completely safe. Maybe its incidence is only reduced.

    Visitor II
    January 8, 2021

    Porting was successful but my problem still occurs.

    My MCU network traffic is about under 1mbps tx, 1mbps rx. (<- It's hard to generate problem but happens definitely)

    To generate problem easily, I make more traffic 3mbps tx/rx. (<- Stop network service after 1~3 minutes)

    Today I've test it for about 3 hours with my modification and have no problem until now.

    I'll share more details that I've found.

    Visitor II
    March 24, 2021

    Hello everyone,

    I am trying to integrate this code into my code, but in the file stm32h7xx_hal_eth.c, in the function HAL_ETH_Init (line 345 I think) where the software set the bit to reset the MAC subsystems, it seems like the reset is not working, any idea on leads on how can I solve this problem?

    Regards

    Alan

    Visitor II
    March 24, 2021

    Which board are you using? Does it use the LAN8742 PHY?

    Visitor II
    March 25, 2021

    Hi,

    Thank you for the answer, I am using the Nucleo STM32H745ZI-Q, I think is compatible since with oder projects with the configuration of this LAN there is no issue.

    Regards

    Alan

    Visitor II
    March 25, 2021

    I already solved this issue, I just configure the system to make it work on timer 7 and 6 so RTOS can work with Systick. Thanks for the help.

    Regards