How to make Ethernet and lwIP working on STM32
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-09-28 4:10 PM - edited ‎2023-11-26 11:14 AM
This is an umbrella topic where I will collect the key problems and solutions to finally get networking on STM32 working. The issues formatted as bold are the most critical ones.
HAL ETH drivers have been significantly reworked since the following firmware packages: CubeF4 v1.27.0, CubeF7 v1.17.0, CubeH5 v1.0.0, CubeH7 v1.10.0
Series: F1, F2, F4, F7, H5, H7 (all STM32 with Ethernet)
- lwIP driver Tx deadlock. [reworked drivers]
- Missing compiler and CPU memory barriers. [legacy drivers]
- RMII mode not enabled because of lacking SYSCFG synchronization. [legacy drivers]
- Unwanted interrupts not masked.
- CubeMX generates wrong PHY configuration. [legacy drivers]
- Not possible to use a custom PHY driver in CubeMX. [reworked drivers]
- Wrong clock source and PLL configuration. [examples]
- lwIP driver zero-copy Rx PBUF pool size is inappropriate. [reworked drivers]
- CubeMX generates broken lwippools.h file for C++.
- CubeMX generates a dysfunctional lwIP application without RTOS.
- Unnecessary delay in LAN8742_Init() and link state management in low_level_init(). [reworked drivers]
- Unnecessary delays and peripheral reset in HAL_ETH_Init() function.
- Multiple flaws in a PTP API implementation. [reworked drivers]
- Poorly chosen MDIO frequency limits and scarce documentation.
Series: F1, F2, F4, F7 (older Synopsys basic peripheral)
- Many flaws as a result from incorrect porting of the reworked H7 series HAL ETH driver. [reworked drivers]
- No DMA access to a data in FLASH memory. [reworked drivers]
- Tx complete interrupt not triggered. [legacy drivers] The related documentation is also wrong.
- Wrong Tx checksum offload documentation.
- Wrong PTP clock source documentation.
- Wrong PPS output documentation.
Series: H5, H7 (newer Synopsys QoS peripheral)
- HAL ETH driver sets wrong MDIO frequency.
- Wrong descriptor ring length documentation.
- Wrong and misleading descriptor tail pointer documentation.
- Wrong or scarce DMA Rx resuming documentation.
Series: F7, H7 (Cortex-M7 CPU)
- Flawed MPU configuration and D-cache maintenance in lwIP driver. [reworked drivers]
- Overlapping and merged memory regions in linker script files.
- Critical spelling errors in linker script files.
- The example code in the article "DMA is not working on STM32H7 devices" is flawed in multiple ways.
lwIP API related:
- Ethernet link and DHCP management code is not thread-safe. When used with RTOS, the code ignores lwIP requirements described in Common pitfalls and Multithreading.
- The example code in the article "How to create project for STM32H7 with Ethernet and LwIP stack working" is not thread-safe. It uses RTOS and lwIP RAW API, but doesn't do lwIP core locking.
- Improper use of NETIF and link up/down statuses. The meaning of netif_set_up()/netif_set_down() functions changed in v2.0.0, but ST's code is not updated. Now NETIF must be up regardless of link state, but for a link state only the functions netif_set_link_up()/netif_set_link_down() must be used.
- Improper use of DHCP client. The code is for an outdated version of DHCP client, which needed external state management. Current versions fully manage the state internally. Monitoring of the state and reporting IP addresses can be done by a callback set up with netif_set_status_callback() without wasting a thread on it.
Other related information:
Another detailed topic by @alister​: "[bug fixes] STM32H7 Ethernet". While mostly dedicated to H7 series, it also has a good amount of information relevant to all Ethernet/lwIP related development.
Open source zero-copy Ethernet/lwIP driver example. The hardware driver is for F2 series, which means that it's almost the same for all Fx series. The lwIP related code and general ideas are still valid for all series.
My other closely related topic: "Actually working STM32 Ethernet and lwIP demonstration firmware". As that topic is currently unavailable, because ST still has not moved it to the new forum, I am attaching a PDF copy of that topic and the related firmware files to this topic.
Solved! Go to Solution.
- Labels:
-
Bug-report
-
Ethernet
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-03 8:05 AM - edited ‎2024-10-18 7:28 AM
Dear community members,
Thank you for your continuous support and feedback to identify potential issues related to Ethernet. The input provided in this conversation thread has helped us to improve the solution from HAL drivers examples and documentation perspectives.
As many of the mentioned issues have been fixed, we wanted to give you a status update (see below). We are aware that some issues persist, and we will continue the analysis to provide solutions. In the meantime, if you have further feedback, please let us know, and don’t hesitate to start a thread if you encounter an issue that has not yet been mentioned here.
Thanks,
Post |
Status |
Implemented in the new HAL_ETH_Driver. Refer to the thread Ethernet HAL Driver reworked by ST and available in 22Q1 (preview now available on GitHub) for more details about some of the applied fixes. (1) |
|
RMII mode not enabled because of lacking SYSCFG synchronization. |
|
Many flaws as a result from *** porting of the reworked H7 series HAL ETH driver.  |
|
Unnecessary delay in LAN8742_Init() and link state management in low_level_init(). |
Questions answered |
Unnecessary delays and peripheral reset in HAL_ETH_Init() function. |
|
Fixed in STM32CubeMX-6.9.0 |
|
FIXED IN STM32CubeF7 v1.17.2 |
|
Fixed mismatch in linker section names between linker file and source file. |
|
resolved in the STM32CubeH7 V1.10 |
|
Main reported issues fixed- Some enhancements are required |
|
Poorly chosen MDC (MDIO) frequency limits and scarce documentation. |
Documentation internally updated. 133712  (used for internal reference only) |
Move bufffers of fsdata_custom.c file from Flash to RAM. In v1.28 of Stm32cubeF4 |
|
Documentation internally updated. 140321 (used for internal reference only) |
|
Documentation internally updated. 141623 (used for internal reference only) |
|
Documentation internally updated. 118901 (used for internal reference only) |
|
Documentation internally updated. 121000 (used for internal reference only) |
|
Flawed MPU configuration and D-cache maintenance in lwIP driver. |
Fixes applied on Lwip projects in STM32CubeH7 v1.11.2 |
Investigation ongoing. We will update you case by case in this post. |
|
ETH_DMACSR_RBU error occurs and stalls the Ethernet receive on STM32H7. |
|
(1) the reworked Ethernet driver is available for:
- STM32CubeH7: V1.10.0 (or higher)
- STM32CubeF4 :V1.27.0 (or higher)
- STM32CubeF7 :V1.17.0 (or higher)
STM32CubeF1 and STM32CubeF2 don’t get a reworked Ethernet driver.
These updates are available From CubeMX version 6.4.0 and higher and we recommend using the latest tools and software versions to make sure latest fixes and patches are applied.
To enhance our support related to Ethernet topics, feel free to review the following material that hopefully help you in some use-cases: 
For issues related to documentation that were identified but not yet solved, feel free to keep an eye on the following knowledgebase articles: 
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-10-02 6:03 AM
As the main topic has hit a 10000 character limit, I'm changing this message to a list of fixed issues, which many people will still find useful.
Series: F1, F2, F4, F7 (older Synopsys basic peripheral)
- lwIP driver Rx deadlock. [Fixed in CubeMX v5.5.0]
Series: H7 (newer Synopsys QoS peripheral)
- lwIP driver Rx buffers released while still in use. The discussion in this topic also has a significant amount of related information. [Fixed in CubeH7 v1.10.0]
- HAL driver wrong Rx channel descriptor tail pointer. [Fixed in CubeH7 v1.8.0]
Series: F7, H7 (Cortex-M7 based)
- lwIP driver Rx data buffers not aligned to cache line size. The address and size of buffers, on which D-cache invalidation is done, must be aligned to __SCB_DCACHE_LINE_SIZE, which is 32 bytes for Cortex-M7. Instead of doing D-cache maintenance, newer ST provided code uses MPU to configure specific memory regions as non-cacheable. It's a very poor solution performance wise, but at least it is functionally correct. For a proper and decent solution it is recommended to read my article "Maintaining CPU data cache coherence for DMA buffers". [Fixed by using MPU.]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-10-04 7:54 AM
Hi @Piranha​ ,
Needed follow-up actions for each discussion are tracked internally by me & Imen.
I suggest to close the current question.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 1:31 AM
I've added substantial amount of new information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 11:28 AM
Hi Piranha,
Thank you very much for the information.
If I may please ask why you don't share the sources ? I will try to do the modifications for H7.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-01-06 6:00 AM
Can anyone send example project ? thanks so much Cubemx 5.4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-02-12 1:59 PM
My fixes and improvements to ST's STM32H7 ETH driver and lwIP ethernetif.c are at https://community.st.com/s/question/0D50X0000C6eNNSSQ2/bug-fixes-stm32h7-ethernet.
Source code and documentation attached.
I don't use evaluation boards or build example code.
You'll have to port my changes yourself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-02 7:27 AM
Thank you @Piranha​ for this detailed write-up! I've updated the original thread to point to this one. *excellent* information and lots of detail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-26 1:03 PM
I am attempting to get Ethernet work on an STM32H745 on the M7 core currently. But I am using CubeIDE 1.4.2 and CubeMX 6.0.1 with ver 1.8.0 of the H7 firmware package. Since these are a bit newer, it is unclear to me which of these issues are still present and which still need fixing. Does anyone have any updates that apply to the newer stuff?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-01 11:17 PM
Yes, I think same as you. It is worthy to make it clear which ones have remained until now.
