cancel
Showing results for 
Search instead for 
Did you mean: 

Ethernet TX doesn't work because ETH_DMATxDescListInit() doesn't initialize the entire ETH_DMADescTypeDef

Robert Sexton
Associate II

The officially recommended recipe for lwIP on STM32H7 puts the ethernet DMA descriptors in SRAM1. SRAM1 is not zero'd by the default startup code.

It's unsafe for the network drivers to assume that buffers and critical data structures live in .bss.

Fix: ETH_DMATxDescListInit() should zero out the data structures w/ memset.

static void ETH_DMATxDescListInit(ETH_HandleTypeDef *heth)
{
  ETH_DMADescTypeDef *dmatxdesc;
  uint32_t i;
 
  // There is no guarantee that the Tx Descriptor is in pre-initialized memory
  // zero it out to be completely sure. 
  memset(&heth->TxDescList,0,sizeof(ETH_TxDescListTypeDef));
 
  /* Fill each DMATxDesc descriptor with the right values */
  for(i=0; i < (uint32_t)ETH_TX_DESC_CNT; i++)
.
.
.
 

10 REPLIES 10

I can only know what you've written and I'm guessing.

In comments you've linked https://github.com/STMicroelectronics/STM32CubeH7/blob/0a714a644cb53c0233f8cdb41a1685c64d554166/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_eth.c#L3058. Are you using that driver?

In the description you've said:

  1. ETH_DMATxDescListInit() doesn't initialize the entire ETH_DMADescTypeDef
  2. It's unsafe for the network drivers to assume that buffers and critical data structures live in .bss.

These are vague and confusing.

The driver may reasonably assume the handle is defined in .bss because the Cube that installed the driver also generated the code defines that.

The descriptors should not be in .bss, and by my reading, ETH_DMATxDescListInit (I don't use this driver code) initializes those ok. What specifically is it failing to "initialize"? What specifically is uninitialized?

Are the "buffers" your tx buffers? The driver can't see any tx buffers during init time. NULL (zero) pointers to those should be fine during init. Your tx buffers BTW do not need to be in .bss and this driver is not responsible for those.

If you could please post some better details, it would assist future readers and perhaps ST too.