STM32H723 Ethernet UDP Transmit Fails After Several Hours (pbuf_alloc Failure)
I am testing Ethernet on STM32H723ZGT6 by transmitting UDP packets (1024 bytes) every 1 ms.
Setup / Implementation:
-
No CubeMX / HAL used
-
Fully bare-metal Ethernet driver (lwIP integrated manually)
-
Ethernet interrupts enabled and serviced
-
RX handled inside while(1) loop
-
Non-blocking transmit path
-
MPU enabled
Memory configuration:
-
RX pool located in AXI RAM
-
lwIP heap: 32232 bytes in D2_SRAM
Observed Behavior:
- System runs normally for many hours (sometimes >12 hours)
-
Eventually UDP transmit stops working
-
Ping continues to work without issues
Debugging shows failure occurs at:
pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
After failure:
1) pbuf_alloc() returns NULL (ERR_MEM)
2) ETH->DMACSR reads 0
while (1)
{
sys_check_timeouts();
if (eth_rx_rdy)
{
eth_rx_rdy = 0;
ethernetif_poll(&gnetif);
ETH->DMACIER |= ETH_DMACIER_RIE;
}
if (sys_now() - udp_tx_timer >= 1) // 1 ms transmit interval
{
ret = udp_server_send(udp_tx, sizeof(udp_tx));
if (ret != ERR_OK)
{
printf("err: %lu\r\n", ETH->DMACSR);
}
udp_tx_timer = sys_now();
}
}
err_t udp_server_send(const void *out, u16_t len)
{
if (!upcb)
return ERR_VAL;
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
if (!p)
return ERR_MEM;
err_t err = pbuf_take(p, out, len);
if (err == ERR_OK)
{
err = udp_send(upcb, p);
if (err == ERR_OK)
tx_sent++;
}
pbuf_free(p);
return err;
}
-
What could cause pbuf allocation failure after long run time while ping still works?
-
Could this indicate lwIP heap exhaustion / memory leak / fragmentation?
-
Is there anything STM32H7-specific (DMA / cache / MPU / memory region placement) that might trigger this?
-
Does DMACSR = 0 provide any diagnostic meaning in this scenario?
- For UDP transmission, would it be better to use PBUF_ROM or PBUF_REF instead of PBUF_RAM? Since PBUF_POOL is generally not recommended for TX.
Any suggestions or debugging directions ?
~AJ
