mimxrt/eth: Avoid a race condition for Ethernet.

That caused Ethernet to lock up at high data rates after ~200MByte data
average in a row.  Tested now with data bursts up to 10 GByte and overall
data rates of ~8MByte/s at the Eth100 port.
This commit is contained in:
robert-hh 2022-02-23 14:15:27 +01:00 committed by Damien George
parent 04f92a2825
commit 4774501cab
2 changed files with 7 additions and 4 deletions

View File

@ -291,6 +291,7 @@ void eth_init(eth_t *self, int mac_idx, const phy_operations_t *phy_ops, int phy
ENET_Init(ENET, &g_handle, &enet_config, &buffConfig[0], hw_addr, CLOCK_GetFreq(kCLOCK_IpgClk));
ENET_SetCallback(&g_handle, eth_irq_handler, (void *)self);
NVIC_SetPriority(ENET_IRQn, IRQ_PRI_PENDSV);
ENET_EnableInterrupts(ENET, ENET_RX_INTERRUPT);
ENET_ClearInterruptStatus(ENET, ENET_TX_INTERRUPT | ENET_RX_INTERRUPT | ENET_ERR_INTERRUPT);
ENET_ActiveRead(ENET);
@ -348,7 +349,7 @@ STATIC err_t eth_netif_output(struct netif *netif, struct pbuf *p) {
p = p->next;
}
status = eth_send_frame_blocking(ENET, &g_handle, tx_frame, length);
}
}
return status == kStatus_Success ? ERR_OK : ERR_BUF;
}

View File

@ -169,9 +169,11 @@ uint32_t trng_random_u32(void);
// For regular code that wants to prevent "background tasks" from running.
// These background tasks (LWIP, Bluetooth) run in PENDSV context.
// TODO: Check for the settings of the STM32 port in irq.h
#define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = disable_irq();
#define MICROPY_PY_PENDSV_REENTER atomic_state = disable_irq();
#define MICROPY_PY_PENDSV_EXIT enable_irq(atomic_state);
#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003)
#define IRQ_PRI_PENDSV NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 15, 0)
#define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = raise_irq_pri(IRQ_PRI_PENDSV);
#define MICROPY_PY_PENDSV_REENTER atomic_state = raise_irq_pri(IRQ_PRI_PENDSV);
#define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state);
// Use VfsLfs2's types for fileio/textio
#define mp_type_fileio mp_type_vfs_lfs2_fileio