Duet3D / RepRapFirmware

OO C++ RepRap Firmware
GNU General Public License v3.0
945 stars 535 forks source link

Unexpected SBC SPI interrupts in MB6HC standalone mode can cause hard fault #972

Closed dc42 closed 7 months ago

dc42 commented 7 months ago

As at version 3.5.0-rc.4 method SbcInterface::Spin() is called when in standalone mode. This initialises the SBC SPI interface so that it can receive transfers from a connected SBC and (according to the comments) return a response indicating that RRF is running in standalone mode. However, the SPI interrupt service routine now passes the SPI interrupt on to the WiFi module when not in SBC mode, which results in a hard fault if noise is received on the SBC SS signal. Even if the interrupt was processed using the SBC ISR, it is unlikely that the code would work because the ISR wakes up the SBC task, which doesn't run in standalone mode.

Example hard fault data, from 3.5.0-rc.4:

Last reset 00:01:13 ago, cause: software
Last software reset at 2024-04-09 14:25, reason: MemoryProtectionFault mmarValid daccViol, Gcodes spinning, available RAM 66676, slot 2
Software reset code 0x4163 HFSR 0x00000000 CFSR 0x00000082 ICSR 0x0043c004 BFAR 0x00000118 SP 0x2045ffb0 Task MAIN Freestk 72058 ok
Stack: 40078000 80000000 00011508 40058000 00000000 ffffffed 0042d080 8101003a ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
Error status: 0x00Faulted at:
.text._ZN13WiFiInterface12GetNewStatusEv
                0x0042d060       0x70 ./src/Networking/ESP8266WiFi/WiFiInterface.o
                0x0042d060                SPI1_WiFi_Handler()
Error is at offset: 0x20
dc42 commented 7 months ago

I propose that we remove this code from RepRap.cpp:

#if HAS_SBC_INTERFACE
    // Keep the SBC task spinning from the main task in standalone mode to respond to a SBC if necessary
    if (!UsingSbcInterface())
    {
        ticksInSpinState = 0;
        spinningModule = Module::SbcInterface;
        sbcInterface->Spin();
    }
#endif

With this code removed, function SbcInterface::Spin() can also be removed.

dc42 commented 7 months ago

Code removed, issue believed solved.