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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-02 7:11 PM
@JBerry​ , @MTros.1​ this is a community forum and as you're presently working on H7 ethernet and using H7_FW v1.8.0, and as Piranha may also have a day job and mightn't be working on either, perhaps you're best positioned to do this investigation and contribute the answers.
I'd documented and fixed/improved the H7_FW v1.5.0/v1.6.0 ethernet problems at https://community.st.com/s/question/0D50X0000C6eNNSSQ2/bug-fixes-stm32h7-ethernet. It's valid for v1.7.0 too.
I haven't the time to read H7_FW v1.8.0 now. Could you read the the issues I'd documented and fixed/improved there, compare the fixes, and read the issues Piranha's posted here, and post the results of your analysis there and here please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-26 3:19 PM
Are you saying the current release of LWIP and FreeRTOS do not work at all without bug fixes, or just simply inefficient and bugs are present?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-20 9:23 AM
I stumbled upon this STM32 LwIP disaster also and after 1w of swearing and debugging, moved over to Mbed with my F7 device. Mbed TCP/IP stack and OS works out of a box. I'm still in mid development but haven't seen any network issues. But the grass is not bright green there either - the list of debuggable MCU's is quite short. Need dual project solution with shared code to get the job done. Develop and debug HW level code in STM32CubeIDE and run whole application in Mbed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-08 11:19 AM
Hello,
oh my god... Any update on this matter ? Do we have some working example code with FreeRTOS and LWIP ?
If not which one is closest one ?
I was about to debug code for simple UDP client using Socket API for LwIP, but I guess this is dead end path :-(...
Can I get any better if I use raw API of LwIP or even use LwIP without FreeRTOS ?
I don't have such complex task to do (gateway from UART connection to MQTT-SN server)...
@Mikk Leini​ : I'd be more than happy to read if you are willing to provide some more details about your work with STM32 and MbedOS.
Thanks in advance,
regards,
Rob.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-03-28 10:42 AM
Hi Piranha,
See my last answer in this topic:
In my case code generated by STM32CubeIDE was simply setting not enough stack size for "EthIf" thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-24 2:30 AM
Hello, Piranha.
I read many of your messages about Ethernet driver for LWIP.
I use NUCLEO-767ZI and I use BSD sockets and therefore FreeRTOS.
For NUCLEO-767ZI I wrote code and it work fine. But I decide move project on NUCLEO-H755. And I start fight with MPU and others...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-06 8:44 AM
This patch is for V1.6.0, has any of this been merged by ST into 1.7.0?
Thank you for your work.
It's tough to work with a PDF and code snipits. Moving this to a GitHub fork of 1.6.0 would allow all those changes to be tracked and pulled into our code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-05 8:08 AM
I am currently experiencing one of those strange behaviours. LWIP is not able to get IP but when I add one line of code somewhere - even if it is after LWIP initialisation (so totally irrevelant to LWIP operation) LWIP is working again. Problem will come and go as I am developing my application by adding more lines of code. All my threads have enough stack memory allocated but the problem looks like something related to memory. I am not sure how to debug it. I am using NUCLEO-F767ZI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-04 11:36 PM
Hi,
I am using CubeF4 v1.27.1 and Olimex P407 board. I wanted to use LwIP_HTTP_Server_Netconn_RTOS example with RMII interface. I have correctly configured all the Pins. I am able to ping the device but the moment web server is being browsed from browser the devices gets stuck in deadlock and ethernet interrupt stops working.
I found interrupt is being stopped due to DMA error
if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_AIS))
{
if (__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMAIER_AISE))
{
heth->ErrorCode |= HAL_ETH_ERROR_DMA;
/* if fatal bus error occurred */
if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_FBES))
{
/* Get DMA error code */
heth->DMAErrorCode = READ_BIT(heth->Instance->DMASR, (ETH_DMASR_FBES | ETH_DMASR_TPS | ETH_DMASR_RPS));
/********* here interrupt is being disabled from *****/
/* Disable all interrupts */
__HAL_ETH_DMA_DISABLE_IT(heth, ETH_DMAIER_NISE | ETH_DMAIER_AISE);
/********
/* Set HAL state to ERROR */
heth->gState = HAL_ETH_STATE_ERROR;
}
Please let me know if this is already fixed. ethernetif.c file is attached.
Regards,
Parvez Akhtar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-05 5:18 PM
This issue is already reported in the following topic. That link is also listed in the main post of this topic and reportedly ST is working on a fix. Also, if you have something else to add, please do it in the linked specific topic, not this one. :smiling_face_with_smiling_eyes:
