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.
UPDATE: nowadays the official repo of FreeRTOS_+TCP can be found on Github.
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.
UPDATE: all drivers are now on the official repo on Github.
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
andFreeRTOSIPConfig.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)
Is there any more progress on this? I’ve been fighting with LwIP + FreeRTOS on the STM32F746 for a few weeks and have just about given up trying to get it working. I’m looking for something a bit more “ready to use”… does FreeRTOS+TCP fit the bill?
I don’t mind some low level hacking but the state of affairs regarding Ethernet / TCP/IP on STM32 seems pretty bad. I’m looking for something zero copy that can just work and obtain the max wire speed with TCP or UDP packets.
Please let me know the best way to go about integrating FreeRTOS+TCP into my project. I’m working on a nucleo-144 dev board BTW.
I’m afraid that I don’t know much about the lwIP port for STM32F7x.
FreeRTOS+TCP has a generic driver that works for both STM32F4x and STM32F7x.
I have a repo with some FreeRTOS+TCP projects using Make, see here. You will find a STM32F7x project.
f you have any more questions, feel free to ask the here.
Thanks for the reply! I checked out those projects but it seems like the ST library used is a really old version… so I can’t really figure out what has been changed compared with code generated from Cube. Basically my goal is to generate my project with Cube and then integrate the TCP stuff. I already have FreeRTOS running and it seems to work fine, but Cube doesn’t offer the option of setting up FreeRTOS+TCP, so I’m hoping I can download some kind of ready-to-use package and find instructions on integrating it.
From what I’ve learned so far, the main issue is that the stock HAL Ethernet driver intends the user to copy data in and out of the DMA buffers used for TX and RX… a lot of people talk about a “zero copy” approach where the buffers used by the TCP stack are shared by the Ethernet hardware… does +TCP support doing this? Does your example support this?
P.S. What is the difference between “Abe_Library” and “ST_Library” in the example stm32F7 projects?
it seems like the ST library used is a really old version…
The +TCP driver has forked the ETH driver from ST and changed it to use zero-copy techniques in both directions:
#define ipconfigZERO_COPY_RX_DRIVER ( 1 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
Have you read the driver’s readme.txt already?
I would recommend that you remove all files like stm32f7xx_hal_eth.{c,h} from the HAL directories. They will be replaced with the ones you find in portable/NetworkInterface/STM32Fxx:
stm32fxx_hal_eth.c
stm32f2xx_hal_eth.h
stm32f4xx_hal_eth.h
stm32f7xx_hal_eth.h
stm32fxx_hal_eth.h
So yes, you can set-up your project with CUBE and then upgrade the FreeRTOS kernel to the latest release and also add FreeRTOS+TCP.
…a lot of people talk about a “zero copy” approach where the buffers
used by the TCP stack are shared by the Ethernet hardware… does +TCP
support doing this? Does your example support this?
Yes, zero-copy is supported, and I use it in all STM32 projects.
P.S. What is the difference between “Abe_Library” and “ST_Library” in the example stm32F7 projects?
I see both directories in an IAR/Keil project, but I don’t know the difference, except that one is older than the other.