FreeRTOS+TCP NetworkInterface port to STM32 using HAL

mpi wrote on Thursday, April 12, 2018:

I’m not sure if this is the right place to ask but I’ve tryed with STM support comunity without success so I’ll give it a try.

I’m trying to to port the NetworkInterface.c to STM32H7
I’m following the instructions provided for creating network drivers for other chips.
As for first step I’m interesting in implementing the simplest solution that do not involves using DMA.
BufferAllocation_2 is the selected network buffer scheme

I’m not sure how HAL libraries shpuld be used to implement xNetworkInterfaceOutput

BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor, BaseType_t xReleaseAfterSend );
/* The network interface port layer must provide a function called xNetworkInterfaceOutput() that sends data received from the embedded TCP/IP stack to the Ethernet MAC driver for transmission.*/
BaseType_t xNetworkInterfaceOutput(NetworkBufferDescriptor_t * const pxDescriptor, BaseType_t xReleaseAfterSend)
{

/* Simple network interfaces just use Ethernet peripheral driver library functions to copy data from the FreeRTOS+TCP buffer into the peripheral driver's own buffer. */

#if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM != 0 )
{
   ProtocolPacket_t *pxPacket;

   /* If the peripheral must calculate the checksum, it wants
   the protocol checksum to have a value of zero. */
   pxPacket = ( ProtocolPacket_t * ) ( pxDescriptor->pucEthernetBuffer );

   if( pxPacket->xICMPPacket.xIPHeader.ucProtocol == ipPROTOCOL_ICMP )
   {
      pxPacket->xICMPPacket.xICMPHeader.usChecksum = ( uint16_t )0u;
   }
}
#endif

/* Copy data from the FreeRTOS+TCP buffer into the peripheral driver's own    buffer 
        The start of the data is located
        by pxDescriptor->pucEthernetBuffer. The length of the data is located
        by pxDescriptor->xDataLength. */

/** --------------------------------------QUESTION--------------------------------------------- HAL ETH  Implementation  
ETH_BufferTypeDef Txbuffer;
	Txbuffer.buffer = pxDescriptor->pucEthernetBuffer;
	Txbuffer.len = pxDescriptor->xDataLength;
	Txbuffer.next = NULL;

	/* ETH packet  TxConfig is defined and initialized in eth.c*/
    TxConfig.Length = pxDescriptor->xDataLength;
    TxConfig.TxBuffer = &Txbuffer;

	HAL_StatusTypeDef status = HAL_ETH_Transmit(&heth, &TxConfig, 0);

// I get error! because ...
// (heth->Instance->DMACSR & ETH_DMACSR_FBE) != (uint32_t)RESET)
	if(status == HAL_ERROR){
		// Error.
	}

 -----------------------------------------------------------------------------------------------------*/

/* Call the standard trace macro to log the send event. */
iptraceNETWORK_INTERFACE_TRANSMIT();

if( xReleaseAfterSend != pdFALSE )
{
/* It is assumed SendData() copies the data out of the FreeRTOS+TCP Ethernet
buffer. The Ethernet buffer is therefore no longer needed, and must be
freed for re-use. */
vReleaseNetworkBufferAndDescriptor( pxDescriptor );
}

return pdTRUE;
}

This is my first time with HAL and Ethernet and is confusing to understand how I should proceed.

Thanks for any help or suggestion.