From 52a78e69658eca65bcb8d6577df2de2db7932c9e Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Aug 2021 18:06:26 +1000 Subject: [PATCH] drivers/cyw43: Fix cyw43_deinit so it can be called many times in a row. This makes sure deinit() can be called on the interface many times without error, and that the state of the driver is fully reset. Fixes issue #7493. Signed-off-by: Damien George --- drivers/cyw43/cyw43_ctrl.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/cyw43/cyw43_ctrl.c b/drivers/cyw43/cyw43_ctrl.c index aaa266b0d..9bd7602de 100644 --- a/drivers/cyw43/cyw43_ctrl.c +++ b/drivers/cyw43/cyw43_ctrl.c @@ -102,28 +102,25 @@ void cyw43_init(cyw43_t *self) { } void cyw43_deinit(cyw43_t *self) { + if (cyw43_poll == NULL) { + return; + } + CYW_ENTER - cyw43_ll_bus_sleep(&self->cyw43_ll, true); - cyw43_delay_ms(2); + // Stop the TCP/IP network interfaces. cyw43_tcpip_deinit(self, 0); cyw43_tcpip_deinit(self, 1); - self->itf_state = 0; - - // Disable async polling + // Turn off the SDIO bus. + #if USE_SDIOIT sdio_enable_irq(false); - cyw43_poll = NULL; - - #ifdef pyb_pin_WL_RFSW_VDD - // Turn the RF-switch off - mp_hal_pin_low(pyb_pin_WL_RFSW_VDD); #endif - - // Power down the WL chip and the SDIO bus - mp_hal_pin_low(pyb_pin_WL_REG_ON); sdio_deinit(); + // Power off the WLAN chip and make sure all state is reset. + cyw43_init(self); + CYW_EXIT }