summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2022-07-27 21:01:29 +0200
committerDamien George <damien@micropython.org>2022-08-09 16:35:57 +1000
commit73699a846c031ecde70cf6bd629ef9a8232291e3 (patch)
treee83073ee6e3607ea867feb38669e6c1b446da5bd
parentbe2beab71a1a1047299601af70e99053fac508e5 (diff)
extmod/network_wiznet5k: Deinit the NIC before (re-)initialisation.
If nic.active(True) is called several times in a row, the device may lock up. Even if that is bad coding practice, calling wiznet5k_deinit() in wiznet5k_init() prevents the lock.
-rw-r--r--extmod/network_wiznet5k.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c
index 02bf90244..5a26c0895 100644
--- a/extmod/network_wiznet5k.c
+++ b/extmod/network_wiznet5k.c
@@ -198,6 +198,16 @@ STATIC void wiznet5k_config_interrupt(bool enabled) {
);
}
+void wiznet5k_deinit(void) {
+ for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
+ if (netif == &wiznet5k_obj.netif) {
+ netif_remove(netif);
+ netif->flags = 0;
+ break;
+ }
+ }
+}
+
STATIC void wiznet5k_init(void) {
// Configure wiznet for raw ethernet frame usage.
@@ -219,6 +229,9 @@ STATIC void wiznet5k_init(void) {
wiznet5k_config_interrupt(true);
}
+ // Deinit before a new init to clear the state from a previous activation
+ wiznet5k_deinit();
+
// Hook the Wiznet into lwIP
wiznet5k_lwip_init(&wiznet5k_obj);
@@ -229,16 +242,6 @@ STATIC void wiznet5k_init(void) {
mod_network_register_nic(&wiznet5k_obj);
}
-void wiznet5k_deinit(void) {
- for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
- if (netif == &wiznet5k_obj.netif) {
- netif_remove(netif);
- netif->flags = 0;
- break;
- }
- }
-}
-
STATIC void wiznet5k_send_ethernet(wiznet5k_obj_t *self, size_t len, const uint8_t *buf) {
uint8_t ip[4] = {1, 1, 1, 1}; // dummy
int ret = WIZCHIP_EXPORT(sendto)(0, (byte *)buf, len, ip, 11); // dummy port