Skip to content

Commit a0145e5

Browse files
Fix deinit crash on STM32F7
1 parent 126bfd5 commit a0145e5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

connectivity/drivers/emac/TARGET_STM/STM32EthMACv1.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ void STM32EthMACv1::MACDriver::ETH_SetMDIOClockRange(ETH_TypeDef * const base) {
223223

224224
#if ENABLE_ERRATA_2_21_6_WORKAROUND
225225
void STM32EthMACv1::MACDriver::rmiiWatchdog() {
226+
// mbed_event_queue() is not ISR safe, so get the pointer before entering the critical section
227+
auto * const equeue = mbed_event_queue();
228+
226229
CriticalSectionLock lock;
227230

228231
if(!rmiiWatchdogRunning) {
@@ -233,7 +236,7 @@ void STM32EthMACv1::MACDriver::rmiiWatchdog() {
233236
/* some good packets are received */
234237
if (base->MMCRGUFCR > 0) {
235238
/* RMII Init is OK - cancel watchdog task */
236-
mbed_event_queue()->cancel(rmiiWatchdogRunning);
239+
equeue->cancel(rmiiWatchdogHandle);
237240
rmiiWatchdogRunning = false;
238241
} else if (base->MMCRFCECR > 10) {
239242
/* ETH received too many packets with CRC errors, resetting RMII */
@@ -319,9 +322,14 @@ CompositeEMAC::ErrCode STM32EthMACv1::MACDriver::deinit() {
319322
#if ENABLE_ERRATA_2_21_6_WORKAROUND
320323
// Disable RMII watchdog if still running
321324
if(rmiiWatchdogRunning) {
325+
// mbed_event_queue() is not ISR safe, so get the pointer before entering the critical section
326+
auto * const equeue = mbed_event_queue();
327+
322328
CriticalSectionLock lock;
323-
mbed_event_queue()->cancel(rmiiWatchdogRunning);
324-
rmiiWatchdogRunning = false;
329+
if(rmiiWatchdogRunning) { // Recheck flag inside critical section
330+
equeue->cancel(rmiiWatchdogHandle);
331+
rmiiWatchdogRunning = false;
332+
}
325333
}
326334
#endif
327335

0 commit comments

Comments
 (0)