Skip to content

Commit

Permalink
mimxrt/eth: Avoid a race condition for Ethernet.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robert-hh authored and dpgeorge committed Mar 8, 2022
1 parent 04f92a2 commit 4774501
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ports/mimxrt/eth.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 5 additions & 3 deletions ports/mimxrt/mpconfigport.h
Expand Up @@ -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
Expand Down

0 comments on commit 4774501

Please sign in to comment.