apache / nuttx

Apache NuttX is a mature, real-time embedded operating system (RTOS)
https://nuttx.apache.org/
Apache License 2.0
2.6k stars 1.11k forks source link

STM32F4 Ethernet MAC error handling. #8576

Closed fjpanag closed 1 year ago

fjpanag commented 1 year ago

While browsing the STM32F4 reference manual, I noticed this note in page 1166:

33.6.6 - Error response to DMA For any data transfer initiated by a DMA channel, if the slave replies with an error response, that DMA stops all operations and updates the error bits and the fatal bus error bit in the Status register (ETH_DMASR register). That DMA controller can resume operation only after soft- or hard-resetting the peripheral and re-initializing the DMA.

I checked the Ethernet driver, these errors are checked here.

However, there is no error handling at all!
The check is enabled only when CONFIG_DEBUG_NET is enabled, and only does some logging.

This is not very good, and it can be related to a bug that I experience occasionally (the MAC dies completely).

I am thinking that the best course of action would be to cause an ifdown.
Higher layers of the software will be able to detect this, and request a new ifup, effectively resetting the interface. Similar handling to simply disconnecting the cable, for example.

How can the low-level driver cause such an event (without compromising the OS architecture)?
Or is there any suggestion of better handling this?

acassis commented 1 year ago

@fjpanag maybe there could be some more graceful recover from this supposed issue. It is strange because there are people using Ethernet on STM32F407 with NuttX for years without facing these issues you are facing.

Look that ethernet_watchdog function: https://lists.gnu.org/archive/html/lwip-users/2012-09/msg00053.html basically it just resume the DMA operation when some issue is reported on DMASR. Please test this approach, maybe it could solve your issue.