Working Example for FreeRTOS+TCP and STM32F7

I have an STM32F7 Nucleo and am trying to get a TCP example working. I have been able to get an lwip example working so I know that hardware is fine. I have been following the FreeRTOS+TCP Tutorial with the STM32 Drivers and I can build and run the project successfully. The problem arises when I try to call FreeRTOS_IPInit(…). It seems to return pdTRUE and then i can see that vApplicationIPNetworkEventHook() gets called once every couple seconds or so, but the eNetworkEvent paramater never seems to go to eNetworkUp. I was wondering if there is an F7 Example like the F4 example I can reference, because I’ve looked through the F4 and I can’t seem to find where I am going wrong.

Hein may be able to give a more direct answer, but to start with I would be interested in why the network hook is being called repeatedly - I would guess because
it is continuously failing to bring the network up and so periodically retrying. Can you step through the code that is attempting to bring the network up to see at which point it is failing? If you are using the same initialisation code that you use successfully
with lwIP then it might be that there is an incompatibility in how return values are being interpreted, or something equally as simple (hopefully ;o) .

Ok, coincidentally I was able to get something working. It turns out I had left the original stm32 Eth drivers in the project, and it was referencing them instead of the correct FreeRTOS ones. So now the network hook is called correctly only once. My next issue is the board does not respond to pings, but I will spend some time debugging as it is likely something silly.

There is a FreeRTOSIPconfig.h setting that enables/disables responding to pings (from memory, not in a posting check t the moment). Suggest checking that first.

Yes, I have ipconfigREPLY_TO_INCOMING_PINGS set to 1 and I am using a static IP address.

These weeks I am revising all network interfaces. The AWS/FreeRTOS repo runs a bit behind: some interfaces had significant changes since they were put there.

I used to attach newer versions to my posts on Sourceforge. But since I can not attach ZIP files on this forum, I have put the network interfaces in a new private Github repo.

Note that this is a private release without any warranty.

The official sources of AWS/FreeRTOS and libraries can be found here.

When you run Wireshark, do you see gratuitous ARP messages from the IP-address of your board? You should see them every 20 seconds (arpGRATUITOUS_ARP_PERIOD).

Also, can you put a break-point when any packet comes in? See if it comes through xMayAcceptPacket() in NetworkInterface.c.

I replaced all of my original FreeRTOS+TCP with the code in your repo. Still not getting pings. I looked at wire shark, but I have no experience with it. It seems as if when I ping the device it resolves the address, there is a gratuitous ARP from the STM32, and the host sends another ARP to the STM32 but there is no response. I’m not seeing constant 20s ARP from the STM32.

On another note: there were two compilation errors for missing declarations from xApplicationGetRandomNumber and xCheckLoopback. Could you explain what that is about? I was originally using the uxRand implementation but it seems that it will be replaced with xApplicationGetRandomNumber so I just implemented the function and called uxRand inside to get it working.

wire shark, but I have no experience with it

Just start it up and make sure that you choose the correct ( LAN ) adapter.

Here is an example of 3 types of ARP messages:


Note the filter on the top, I filled in the protocol name “arp”.

The big question is: can you device send and can it receive packets? The first thing to check is the PHY Link Status: does it get up?

I did notice one thing though, there is no phyHandling.h/.c in your or the Amazon repo.

You find the latest in my Github repo: phyHandling.c and phyHandling.h
This PHY handler can be used for any 100 Mbps PHY on any platform.

I’m using one that I found somewhere but could the problem be in this file?

There could be a small extension but nothing essential.

there were two compilation errors for missing declarations from xApplicationGetRandomNumber()

Yes, please look at PR #1494. The global function ulRand32() returns zero when it fails. But zero is a valid random number.

This is the implementation that I used for the STM32Fx platform:

BaseType_t xApplicationGetRandomNumber( uint32_t *pulValue )
{
HAL_StatusTypeDef xResult;
BaseType_t xReturn;
uint32_t ulValue;

	xResult = HAL_RNG_GenerateRandomNumber( &hrng, &ulValue );
	if( xResult == HAL_OK )
	{
		xReturn = pdPASS;
		*pulValue = ulValue;
	}
	else
	{
		xReturn = pdFAIL;
	}
	return xReturn;
}

and xCheckLoopback()

That is an idea that hasn’t made it to becoming a pull-request yet: it adds a “loop-back device”. If the target IP address is the address of the adapter, the packet will be bounced back to the IP-task. Good for self-testing without physical network.

You see it implemented in FreeRTOS_ARP.c but the code is disabled with a #if 0.

Ok, yes I see that the STM does do one Gratuitous ARP, but that is it. Using your image from above, I’m not seeing the ARP with length 62, where the microchip responds to the host.

I also tried creating a whole new project from scratch and it seems to still not be working. Are there any settings in FreeRTOSConfig that could be preventing the IP stack to work correctly? I’m using sort of a default configuration out of STMCubeMX so perhaps there is a task setting causing the problem??

I know that the driver still has a problem if memory caching is enabled. Try it while switched off, maybe that helps.
If not, I would like to see you project, especially the 2 config files: FreeRTOSConfig.h and FreeRTOSIPConfig.h.
Unfortunately you can not attach files other than pictures.
So if you want, send them to hein [at] htibosch [dot] net

Im sorry, is the caching controlled by a config setting or something else?

I scrounged up a wifi router with DHCP. I set the configuration option to use DHCP in FreeRTOSIPConfig.h and using wireshark, it seems that the STM tries to obtain a IP dynamically, and the router responds with a DHCP offer, but the STM does not accept. There are 3 Discover-Offer actions and then the STM reverts back to the static IP address.

It then performs 1 Gratuitious ARP and that is it.

I won’t be able to send the config files until tomorrow most likely, but I will say I used the FreeROTS Labs STM32F4 TCP example as a reference for my project. I used most of the same settings except the differences noted on your github readme for the STM32F7

Im sorry, is the caching controlled by a config setting or something else?

In main() of my own STM32F7 project I find this code:

//  SCB_EnableDCache();
    /* Disable DCache for STM32F7 family */
    SCB_DisableDCache();

It then performs 1 Gratuitious ARP and that is it.

As a test, you might want to increase the frequency of this to e.g. every 500 ms, define in FreeRTOSIPConfig.h:

#define arpGRATUITOUS_ARP_PERIOD         ( pdMS_TO_TICKS( 500 ) )

I am curious to see if you only see 1 packet, or a few, and for how long?

If not, I would like to see you project, especially the 2 config
files: FreeRTOSConfig.h and FreeRTOSIPConfig.h .

Good news: this forum now also allows to attach files that are not pictures ( zip, gz, tar, c, h, cpp ), so there is no need to send things privately.

As a test, you might want to increase the frequency of this to e.g. every 500 ms

Tried this and it still only does 1 ARP. The following is what I see in wireshark:

Disabling DCache causes a hard fault on my MCU, but I took a look at CubeMX and it looks like DCache is disable by default anyways so I don’t think it is active.

As for my FreeRTOS config files and my main file, here they are:

main.c (20.5 KB)FreeRTOSConfig.h (6.1 KB) FreeRTOSIPConfig.h (8.0 KB)