Skip to main content
SHers
Associate III
Question

Looking for functional STM32F7 LwIP + FreeRTOS example

I’m trying to bring up a simple application on a dual-core STM32H755 Nucleo board. Requirements are Ethernet (fixed IP address) and FreeRTOS, using the M7 core (the M4 core can thumb-twiddle, it’s not needed yet).

I have tried configuring a bare-minimum project with these parameters in fully-updated STM32CubeMX and opening it in STM32CubeIDE, but surprise! It won’t build. No custom code, just the ST-created framework.

First issue is that ethernetif.c’s low_level_init() function is trying to initialize a nonexistent TxConfig variable. (I commented that out.)

Second issue is that the linker now throws 97 errors, starting with many errors of the form “Unknown destination type (ARM/Thumb) in ...”, followed by a flock of “dangerous relocation: unsupported relocation” errors. 

It should NOT be this hard to get a dead-simple program skeleton for a bog-standard use case to build on a current ST dev board using ST tools. 

None of the example code I can find on the ST Web site addresses the dual-core H7 MCU and the LwIP/FreeRTOS combination. 

 Can anyone point me at a basic example for this combination that will build? 

10 replies

Pavel A.

So do you have an F7 or H7? The ETH drivers and memory maps are different, please be certain.

Examples for H745 are here:  https://github.com/stm32-hotspot/STM32H7-LwIP-Examples -  should work for H755 as well.

 

 

 

SHers
SHersAuthor
Associate III

It’s an H7, thanks. (That’s what makes it all so tricky; a dual-core project in the CubeIDE is very different from a single-core project, so I can’t just file the serial numbers off my F4 code and assume that it will build. 

Based on the 745/755 datasheet, I think a 745 project ought to transfer to the 755 if I change the processor setting. 

Thanks!

Steve

Graduate

Hi,

 

May I ask if using lwIP is a requirement for your project?

 

If you are interested in a much simpler alternative, there is a solution that uses the Mongoose Networking library running on FreeRTOS on H755. The example is here, featuring a modern webserver with a dashboard. You can try and download it to your local workspace by going to the ‘Settings’ tab of the page, in the ‘Source Code Generator’ select the directory and then click the blue ‘Generate C/C++ Code’ in the upper right corner of the page to download. Open the project with CubeIDE, build it and run it.

 

This approach could save you quite a bit of time compared to configuring lwIP, which can sometimes require careful tuning of numerous settings to get everything working correctly. Mongoose has its own builtin network driver and its own builtin TCP/IP stack, avoiding lwIP. It also carries a much smaller memory footprint and with the well documented API you can implement most of the modern features of an embedded server (HTTP/HTTPS, MQTT, DNS, SNTP, etc.).

 

Alternatively, Mongoose can also be plugged with lwIP and offer you access to its application-level API. Let me know if you’d be interested in such an example.

 

Heads up, I’m part of the Mongoose development team, I hope this helps you with your project.

SHers
SHersAuthor
Associate III

This looks interesting; I’ll check it out. Thanks!

SHers
SHersAuthor
Associate III

A few updates on the above:

  1. The undefined TxConfig variable is ONLY undefined if you’re using LwIP with the RTOS. If the RTOS is not enabled, the CubeMX code generator generates the definition and uses it (apparently) properly. So it’s a code generator issue with the LwIP + RTOS combination.
  2. Those 97 errors went away when I redid the code generation and IDE prohect from sctarch.
  3. WARNING: The Nucleo board’s default strapping requires using HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY) in SystemClock_Config(). With the latest (1.13.0) revision of the Cube H7 support package, the code generator DOES NOT ALLOW the PWR_DIRECT_SMPS_SUPPLY option; you must set this option by hand. Using any of the code generator’s allowed options bricks the board and requires power-cycling and pulling BOOT0 high at the next boot, followed by a full chip-erase, to recover it.
  4. I’m still struggling to get ANY Nucleo example for this board to work with the RTOS and LwIP, even when using sworn-to-work examples I haven't changed at all. Some of this seems to be chip errata for my older-revision MCU. I can get the RTOS to run and blink LEDs from the default task, but the Ethernet stack doesn’t play well with others. The software stacks for this chip are, shall we say, still a work in progress.
Pavel A.

> WARNING: The Nucleo board’s default strapping requires using HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY) in SystemClock_Config(). With the latest (1.13.0) revision of the Cube H7 support package, the code generator DOES NOT ALLOW the PWR_DIRECT_SMPS_SUPPLY option; you must set this option by hand.

In newer versions of STM32H7 device library (since 1.12?) the power configuration is introduced in the new function ExitRun0Mode in system_stm32h7xx.c; it will be automatically called by the startup before SystemInit.

https://github.com/STMicroelectronics/cmsis-device-h7/blob/81db1ec63cdc191fae1565b772da3ea5aa29a683/Source/Templates/system_stm32h7xx.c#L474

One of macros described here should be defined in the compiler #defines. 

For compatibility with previous projects, if none of these macros is defined, ExitRun0Mode does nothing (see line 540);  the needed setup can be added in SystemConfig() or where you like to.

 

> I’m still struggling to get ANY Nucleo example for this board to work with the RTOS and LwIP, even when using sworn-to-work examples

Which have you tried from https://github.com/stm32-hotspot/STM32H7-LwIP-Examples ? How it failed?

 

SHers
SHersAuthor
Associate III

I hadn’t managed to find those examples yet. The CubeMX example page doesn’t mention them.

One problem with them is that they target the H7845, and I have an H755. Retargeting a CubeMX project to a different MCU is somewhere between difficult and fuggedabouddit, so in any case they are of somewhat limited value.

 

For now, having finally managed to get a non-RTOS project with LwIP to work, I’m going to put aside the RTOS question for some other poor soul to fix, and port my working F4 bootloader to the H755. 

SHers
SHersAuthor
Associate III

Final-ish update: 

I’ve managed to get LwIP to actually work on the H755 Nucleo without the RTOS. (The H745 Nucleo LwIP+RTOS examples linked above by Pavel A. do work on the H755 Nucleo board!)

To get the non-RTOS version working, I had to add a few hacks. There are still bugs in the CubeMX configurators.

  • Abovementioned HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY) in SystemClock_Config().
  • Turn on the Memory Management Tool and reconfigure the addresses for the RxDescripSection, TxDescripSection, and Rx_PoolSection to match the values used in the STM32H745_Nucleo_M7_ETH example
  • Edit the linker file STM32H755ZITZ_FLASH_MMT_TEMPLATE.ld to set the size of Rx_PoolSection to 19360 (the Cube tool insists on setting the pool size to the size of ONE pbuf, not the whole pool’s worth).
  • Brutally disable data caching by commenting out SCB_EnableDCache() in main.c (this may make all the MMT stuff moot, though if you don’t turn on the MMT, you won’t get the descriptor sections defined in the linker script). This last step was necessary even after marking the descriptor and LwIP pool sections as non-cacheable in the MMT.

Some of these steps may be redundant or unnecessary, I dunno. What I do know is that the setup modified as described works.