From 9daf450eb37b30539ef31b88dafea407180b4b7a Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Thu, 21 Dec 2017 11:02:36 +0200 Subject: [PATCH] K64F Ethernet: avoid using NULL thread during init The K64F Ethernet driver installs an interrupt handler that sets thread flags, and this could be called before the thread was initialised, so it would use a NULL thread ID. This triggers an RTX error-checking trap in debug builds, and could also lead to other problems with received packets not being processed. Adjusted so the RX interrupt handler does nothing if the thread isn't initialised yet, and manually trigger a RX event flag after initialising the thread in case any interrupts were ignored. An alternative would have been to implement eth_arch_enable_interrupts, but this mechanism is not present in the EMAC world - drivers will have to start returning interrupts in their power up. Fixes #5680 --- .../lwip-eth/arch/TARGET_Freescale/k64f_emac.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c b/features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c index ed7f32b77b..e07e700b15 100644 --- a/features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c +++ b/features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c @@ -140,7 +140,9 @@ static void k64f_tx_reclaim(struct k64f_enetdata *k64f_enet) */ void enet_mac_rx_isr() { - osThreadFlagsSet(k64f_enetdata.thread, FLAG_RX); + if (k64f_enetdata.thread) { + osThreadFlagsSet(k64f_enetdata.thread, FLAG_RX); + } } void enet_mac_tx_isr() @@ -756,6 +758,9 @@ err_t eth_arch_enetif_init(struct netif *netif) /* Worker thread */ k64f_enetdata.thread = sys_thread_new("k64f_emac_thread", emac_thread, netif->state, THREAD_STACKSIZE, THREAD_PRIORITY)->id; + /* Trigger thread to deal with any RX packets that arrived before thread was started */ + enet_mac_rx_isr(); + return ERR_OK; }