stm32duino / STM32Ethernet

Arduino library to support Ethernet for STM32 based board
163 stars 44 forks source link

stm32_eth_scheduler() and timer interrupt #45

Closed manitou48 closed 2 years ago

manitou48 commented 4 years ago

I'm looking at porting your arduino-like lib and your LwIP lib for use with Teensy 3.5/3.6/4.1. I have an lwip implmentation that uses callbacks and polling with the Teensy. I haven't run any tests with your libs yet, so my question is based on code inspection. As I understand your non-RTOS implementation, there seems to be a potential conflict (race condition) with the timer-based (1 ms) calls to stm32_eth_scheduler() and the calls to the scheduler embedded in DHCP and UDP modules. It would seem a timer-based call to the scheduler could interrupt a scheduler invocation from DHCP or UDP. Thanks for any enlightenment.

fpistm commented 4 years ago

Hi @manitou48 yes this is not RTOS oriented. Which scheduler invocation from DHCP or UDP you talk about ?

manitou48 commented 4 years ago

here is list of calls to stm32_eth_scheduler (inclusing the TIMER based call)

  stm32_eth_scheduler();
  stm32_eth_scheduler();
  stm32_eth_scheduler();
  stm32_eth_scheduler();
  stm32_eth_scheduler();
./EthernetUdp.cpp
  stm32_eth_scheduler();
    // stm32_eth_scheduler() will be called every 1ms.
  stm32_eth_scheduler();
void stm32_eth_scheduler(void)
        stm32_eth_scheduler();
./utility/stm32_eth.cpp
  stm32_eth_scheduler();
    stm32_eth_scheduler();
  stm32_eth_scheduler();
./Dhcp.cpp
    stm32_eth_scheduler();
    stm32_eth_scheduler();
  stm32_eth_scheduler();
  stm32_eth_scheduler();
./EthernetClient.cpp
  stm32_eth_scheduler();
./STM32Ethernet.cpp

there is also Ethernet.schedule(), though none of the examples use it.

maybe stm32_eth_scheduler() is re-entrant?

fpistm commented 4 years ago

Ah ok. So yes a call to stm32_eth_scheduler can be interrupted by the timer IRQ call. I could not tell if this is an issue, this will need more investigations anyway no related issue was raised around this. This is like this since the library was created but as said this should requireed more investigations to tell if this could be an issue mainly when ETH_INPUT_USE_IT and LWIP_DHCP are enabled. Feel free to contribut on this 😉

fpistm commented 2 years ago

Hi @manitou48,

@ABOSTM made a PR to avoid this. Now each call of stm32_eth_scheduler trig the interrupt handler.