FreeRTOS+TCP for STM32H7?

onesmallstep wrote on Friday, January 11, 2019:

Looking at the FreeRTOS+TCP code, I see that they have network interface drivers written for the STM32F4 and STM32F7, but not the STM32H7.

Is there a working port of the NetworkInterface code for the STM32H7 anywhere, or is one planned for the future?

Thank you.

heinbali01 wrote on Friday, January 11, 2019:

Hi Nick, I know of one person who worked on making a Network Interface for STM32H7: Thomas Kindler.
I’m attaching his NetworkInterface.c. There is no handling of the PHY yet.
I posted a generic driver for most 100 Mbps PHY’s here

heinbali01 wrote on Friday, January 11, 2019:

Sorry, I forgot the important attachment. Many thanks to Thomas Kindler :slight_smile:

onesmallstep wrote on Friday, January 11, 2019:

Excellent, thank you!

Does this work with the existing stm32h7xx_hal_eth files without any modification?

heinbali01 wrote on Saturday, January 12, 2019:

Does this work with the existing stm32h7xx_hal_eth files without any modification?

Yes it was developed to be used with the STM32H7xx HAL library, including the ETH module.
For the combined driver for STM32F4/STM32F7, I changed the ETH module, mostly to allow for zero-copying:

  • Packets are received directly in a NetworkBufferDescriptor_t.
  • And when sending a packet, DMA will work with the NetworkBufferDescriptor_t as provided by the IP-task.
    Hence the driver doesn’t copy any network packet.

I like Thomas’ module because it shows a NetworkInterface.c in it’s simplest form.

It is quite essential though to add initialisation of the PHY, and also it is important to monitor the Link Status of the PHY. Without that it will also work, but only as long as the device is connected to a switch or a router.

If you want, send me an email and I will help you to make this working. My address is hein [at] htibosch [dot] net

nicmig wrote on Wednesday, February 06, 2019:

Hi! any progress on that? I am also working with an STM32H743 nucleo-144. Would be great to have a working NetworkInterface.

nicmig wrote on Wednesday, February 06, 2019:

heinbali01 wrote on Thursday, February 07, 2019:

No progress has been made on the STM32H7x +TCP driver. I don’t have time to do it, but if anyone wants to develop and test it further, I will help as much as I can. Hein

onesmallstep wrote on Wednesday, February 13, 2019:

Thank you, that is very generous of you!

Unfortunately I got diverted by another task, but I will eventually get back to this. Perhaps by then this network module will be finished, if not I may contact you for some direction.

Thanks again!

Did someones manage to get this working with zero copy… i’m close, but not close enough… no packet get out or in!!!

Alain, if you attach the driver and your FreeRTOSIPConfig.h file, I will have a look at it.

Ok packet are sent,
At this time the packet is supposed to be DHCP discover… but there is missing information in the packet… it is malformed…

I have LwIP packet vs FreeRTOS+TCP packet here. I use zero copy method, and it work. the descriptor are OK… it’s only the pucEthernetBuffer that is wrong…

what i am missing here??

PACKET with error sent with FreeRTOS+TCP

0000   ff ff ff ff ff ff 12 34 56 78 9a bc df f8 f4 04   .......4Vx......
0010   01 1e ec 14 08 60 5f f4 b6 73 00 00 00 00 ff ff   .....`_..s......
0020   ff ff 00 44 00 43 01 0a 00 00 01 01 06 00 ff 54   ...D.C.........T
0030   c7 f5 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0040   00 00 00 00 00 00 12 34 56 78 9a bc 00 00 00 00   .......4Vx......
0050   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0060   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0070   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0080   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0090   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00a0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00b0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00c0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00d0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00e0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00f0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0100   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0110   00 00 00 00 00 00 63 82 53 63 35 01 01 3d 06 12   ......c.Sc5..=..
0120   34 56 78 9a bc 37 03 01 03 06 ff 00               4Vx..7......

PACKET without error sent with LwIP using the same ethernet driver

0000   ff ff ff ff ff ff 12 34 56 78 9a bc 08 00 45 00   .......4Vx....E. 
0010   01 50 00 00 00 00 ff 11 ba 9d 00 00 00 00 ff ff   .P..............
0020   ff ff 00 44 00 43 01 3c d5 8b 01 01 06 00 58 51   ...D.C.<......XQ
0030   f4 2d 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .-..............
0040   00 00 00 00 00 00 12 34 56 78 9a bc 00 00 00 00   .......4Vx......
0050   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0060   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0070   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0080   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0090   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00a0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00b0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00c0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00d0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00e0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
00f0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0100   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0110   00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05   ......c.Sc5..9..
0120   dc 37 03 01 03 1c ff 00 00 00 00 00 00 00 00 00   .7..............
0130   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0140   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0150   00 00 00 00 00 00 00 00 00 00 00 00 00 00         ..............

Here snippet for xNetworkInterfaceOutput function

ETH_Buffer_t		   Buffer;

BaseType_t xNetworkInterfaceOutput(NetworkBufferDescriptor_t* const Descriptor,         BaseType_t ReleaseAfterSend)
{
        ETH_TX_PacketConfig_t  TX_Config;

        LED_Flash(LED_RX_TX, 5, 1);

        Buffer.pBuffer       = Descriptor->pucEthernetBuffer;
        Buffer.Next          = NULL;
        Buffer.Length        = Descriptor->xDataLength;

        memset(&TX_Config, 0x00, sizeof(ETH_TX_PacketConfig_t));

        TX_Config.ChecksumCtrl = 0x30000; 
        TX_Config.Length	   = Descriptor->xDataLength;
        TX_Config.pTX_Buffer   = &Buffer;
        TX_Config.Attributes   = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD;`

        ETH_Transmit(&TX_Config, 5);

        if(ReleaseAfterSend == pdTRUE)
        {
             vReleaseNetworkBufferAndDescriptor(Descriptor);
        }

        return pdPASS;
} 

the FreeRTOSIPConfig.h

#pragma once

#define FREERTOS_IP_CONFIG_H

#include "ip_cfg.h"

extern UBaseType_t uxRand();

#define ipconfigUSE_LLMNR								0
#define ipconfigUSE_NBNS								0
#define ipconfigUSE_DNS_CACHE							0
#define ipconfigUSE_NETWORK_EVENT_HOOK 					0
#define ipconfigUSE_DHCP								1
#define ipconfigUSE_TCP									0
#define ipconfigUSE_TCP_WIN								0
#define ipconfigUSE_DNS									0

// General setting
#define ipconfigBYTE_ORDER 								pdFREERTOS_LITTLE_ENDIAN
#define	ipconfigZERO_COPY_TX_DRIVER						1
#define ipconfigZERO_COPY_RX_DRIVER						1
#define ipconfigETHERNET_AN_ENABLE						0
#define ipconfigETHERNET_AUTO_CROSS_ENABLE  			0
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM   		1
#define ipconfigRAND32()								uxRand()
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD				(120000 / portTICK_PERIOD_MS)
#define ipconfigINCLUDE_FULL_INET_ADDR					1
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS			ETH_RX_DESCRIPTOR_CNT
#define ipconfigEVENT_QUEUE_LENGTH						(ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5)
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 			1
#define ipconfigNETWORK_MTU								1500
#define ipconfigREPLY_TO_INCOMING_PINGS					1
#define ipconfigSUPPORT_OUTGOING_PINGS					0
#define ipconfigSUPPORT_SELECT_FUNCTION					1
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES  		1
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES		1
#define ipconfigPACKET_FILLER_SIZE 						2
#define ipconfigIS_VALID_PROG_ADDRESS(x)				((x) != NULL)

// TCP Setting
#define ipconfigTCP_TIME_TO_LIVE						128 					// also defined in FreeRTOSIPConfigDefaults.h
#define ipconfigTCP_HANG_PROTECTION						1
#define ipconfigTCP_HANG_PROTECTION_TIME				30
#define ipconfigTCP_KEEP_ALIVE							1
#define ipconfigTCP_KEEP_ALIVE_INTERVAL					20  					// in seconds
#define ipconfigTCP_WIN_SEG_COUNT						240
#define ipconfigTCP_RX_BUFFER_LENGTH					1000
#define ipconfigTCP_TX_BUFFER_LENGTH					1000

// UDP Setting
#define ipconfigUDP_TIME_TO_LIVE						128
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS 			(5000 / portTICK_PERIOD_MS)

// DNS Setting
#define ipconfigDNS_CACHE_NAME_LENGTH					16
#define ipconfigDNS_CACHE_ENTRIES						4
#define ipconfigDNS_REQUEST_ATTEMPTS					2

// ARP Setting
#define ipconfigARP_CACHE_ENTRIES						6
#define ipconfigMAX_ARP_RETRANSMISSIONS 				5
#define ipconfigMAX_ARP_AGE								150

// Socket Setting
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME			5000
#define	ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME			5000

// IP Setting
#define ipconfigIP_TASK_PRIORITY						(configMAX_PRIORITIES - 2)
#define ipconfigIP_TASK_STACK_SIZE_WORDS				(configMINIMAL_STACK_SIZE * 5)

#define portINLINE __inline

By the way, I just noticed an ARP packet, that was sent after the DHCP failed sequence… and it is a good packet…

Could you please make a PCAP of the DHCP packet from FreeRTOS+TCP? That is easier than looking at binary data.
If it doesn’t let you upload PCAP or PCAPNG, please ZIP it first.

I found the problem this morning, it was not related to FreeRTOS+TCP, but instead it was my buggy LD Script… it prevented the variables from being initialize at startup, so my xDefaultPartUDPPacketHeader array was full of crappy data.

Thank you… at least it was a rubber duck process.

Thanks for taking the time to report back.

Hi everyone, i’m trying to implement FreeRTOS + TCP using an STM32H7 MCU. I was searching on people who have already implemented it and found this discussion !

I tried to click on the link bringing to the Sourceforge site but it is mentionned that i don’t have the permissions to access.
Is it possible to have a look on the NetworkInterface file please ?

I look forward to your reply

Thank you.

Normally I can find any file from any version, but I can not find a copy of mentioned NetworkInterface_STM32H7.c.
As you know the forum moved from Sourceforge to freertos.org. All posts were copied, but the attachment could not be copied.

I hope that someone who works with FreeRTOS+TCP and STM32H7 responds to this thread.

Is this helpful, it is in the old SourceForge post from 2018. STM32Fxxx_driver.zip (47.5 KB)

I had to change from .7z to .zip to attach to this message.

Actually I haven’t looked up the differences between the EMAC of an STM32F7 and an STM32H7. If they are much the same you can as well use the generic driver that Richard attached.

You can also find that driver in github/freertos