AnsweredAssumed Answered

STM32H7 LWIP cache bug + fix

Question asked by Sven Almgren on Mar 26, 2018
Latest reply on Apr 17, 2018 by Jeremi Wójcicki

I have a Nucleo-H743ZI board that I'm running some ethernet code on, that I based on the LWIP example applications. The problem was that I could only ping it once on every reset. The problem went away when I disabled the cache, which lead me to an issue with low_level_output.

 

As the memory is configured as cachable and the TX buffers now live in regular user memory the dcache must be flushed before calling HAL_ETH_Transmit, so my solution is to call SCB_CleanDCache_by_Addr for every entry put into the Txbuffer:

 

static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
  uint32_t i=0, framelen = 0;
  struct pbuf *q;
  err_t errval = ERR_OK;
  ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT];
 
  memset(Txbuffer, 0 , 4*sizeof(ETH_BufferTypeDef));

  for(q = p; q != NULL; q = q->next)
  {
    if(i >= ETH_TX_DESC_CNT)     
      return ERR_IF;
   
    Txbuffer[i].buffer = q->payload;
    Txbuffer[i].len = q->len;
    framelen += q->len;
   
    SCB_CleanDCache_by_Addr((uint32_t *)q->payload, q->len);

    if(i>0)
    {
      Txbuffer[i-1].next = &Txbuffer[i];
    }
   
    i++;
  }

  TxConfig.Length = framelen;
  TxConfig.TxBuffer = Txbuffer;

  HAL_ETH_Transmit(&EthHandle, &TxConfig, 0);
 
  return errval;
}

Outcomes