From 999b66d53108a014194e7a30f20d4a269fdda6b4 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 29 Jul 2022 08:22:42 +0200 Subject: [PATCH] extmod/network_wiznet5k: Schedule clearing of interrupt flags. Avoiding conflicts between the IRQ and an active transfers. Before this change the device could lock up in heavy traffic situations. Fix found and code supplied by @omogenot. --- extmod/network_wiznet5k.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c index 5a26c0895..bdf94993d 100644 --- a/extmod/network_wiznet5k.c +++ b/extmod/network_wiznet5k.c @@ -177,11 +177,10 @@ STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self); STATIC mp_obj_t mpy_wiznet_read_int(mp_obj_t none_in) { (void)none_in; - wizchip_clrinterrupt(IK_SOCK_0); - setSn_IR(0, Sn_IR_RECV); - - // Handle incoming data - wiznet5k_try_poll(); + // Handle incoming data, unless the SPI bus is busy + if (mp_hal_pin_read(wiznet5k_obj.cs)) { + wiznet5k_try_poll(); + } return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mpy_wiznet_read_int_obj, mpy_wiznet_read_int); @@ -343,6 +342,10 @@ void wiznet5k_poll(void) { } } } + wizchip_clrinterrupt(IK_SOCK_0); + #if _WIZCHIP_ == W5100S + setSn_IR(0, Sn_IR_RECV); // W5100S driver bug: must write to the Sn_IR register to reset the IRQ signal + #endif } #endif // MICROPY_PY_LWIP