cancel
Showing results for 
Search instead for 
Did you mean: 

LwIP problems from code generated via STM32CubeMX (SMT32H7)

KR1
Associate III

Hello,

I seem to be having some problems with the code generated via STM32CubeMX on the NUCLEO-H743ZI development board. I want to configure it to run on LwIP/RAW API. I can create such a configuration for its close relative: the NUCLEO F767ZI development board. In the latter case I take the following steps:

  1.  Set the HCLK to 216 MHz (clocked from the HSI);
  2. Enable the ETH peripheral, set it to RMII mode, and set ETH_TXD0 and ETH_TX_EN pins to PG13 and PG11 (others are mapped appropriately);
  3.  Set the PHY address to 0 in ETH Configuration>General: Ethernet Configuration
  4.  Enable the LwIP middleware;
  5. Enable ICMP (LWIP_BROADCAST_PING and LWIP_MULTICAST_PING in LwIP Key Options>IPMP Options). This step is not necessary, although it helps to determine if all is well with the device.

After I generate the code, I add an extern variable to my main.c to be able to track whether the device has obtained an IP address:

/* USER CODE BEGIN PV */
 
/* Private variables ---------------------------------------------------------*/
 
extern struct netif gnetif;
 
/* USER CODE END PV */

Moreover, I add the standard LwIP/RAW IP callbacks t the main loop:

/* Infinite loop */
 
 /* USER CODE BEGIN WHILE */
 
 while (1)
 
 {
 
 
 
 /* USER CODE END WHILE */
 
 
 
 /* USER CODE BEGIN 3 */
 
 ethernetif_input(&gnetif);
 
 sys_check_timeouts();
 
 }
 
 /* USER CODE END 3 */

This code works well and I am able to get an IP address (I can determine it frome the gnetif->ip_addr field), I can see all the proper ARP request in WireShark and I am able to ping the device:

0690X000006C7VhQAK.png

Herein, I am filtering only the traffic from/to the appropriate (STM32) MAC address 00:80:E1:00:00:00.

For the NUCLEO-H7432ZI board, I essentially follow the same steps, with a couple of minor deviations:

  1.  Set the HCLK to 400 MHz (clocked from the HSI);
  2. Enable the ETH peripheral, set it to RMII mode, and set ETH_TXD0 and ETH_TX_EN pins to PG13 and PG11 (others are mapped appropriately);
  3. Enable the CPU DCache (under Cortex_M7 Configuration)
  4. Enable the LWIP middleware
  5. Select LAN8742/LAN8742 as the Driver_PHY (under LwIP>Platform Settings)
  6. Enable ICMP (LWIP_BROADCAST_PING and LWIP_MULTICAST_PING in LwIP Key Options>IPMP Options).

I change the code in main.c appropriately as for the F7 example. Moreover, I edit the linker file to partition the RAM from 0x24000000 to 0x2407FFFF (there is an instruction in ETH>Parameter Setting to do so in order to get the ETH peripheral working).

If I upload this (nearly identical) build to the NUCLEAO-H743ZI board, I get no network activity (No ARP requests to get an IP address.

Now I know that the issue is somewhere in the STM32CubeMX generated configuration. The hardware itself is good. There is an example of a LwIP HTTP server in STM32Cube_FW_H7_V1.1.0 which works just fine if I upload it to the board. The LwIP_HTTP_Server_Netconn_RTOS example in STM32Cube_FW_H7_V1.1.0 is somewhat different: it uses a RTOS and the Netconn API. For my application I want to stick with Raw API (and no RTOS). So my question would be, what am I missing in my microcontroller configuration?

1 ACCEPTED SOLUTION

Accepted Solutions

Dear Wael,

Sorry for the delay. The suggestions did not work, but now I have managed it without using RTOS:

I changed to LwiP TCP/IP stack without RTOS (Raw API), because this did work for us.

Using Raw API worked mostly well, but there were also some crashes remaining, if too much Ajax requests were fired

at once and the LwIP Server had to receive and to send too much data without any time of idling.

The problem seems to be the instruction - cache! The data - cache is not the problem.

Finally, I made following changes in module "ethernetif.c" (LwIP Raw API):

static err_t low_level_output(struct netif *netif, struct pbuf *p)

{

 SCB_DisableICache();   // Disable Instruction-cache at beginning of function

 for (....)

 ...

 SCB_EnableICache();   // Enable Instruction-cache at end of function

 return errval;

 }

static struct pbuf * low_level_input(struct netif *netif)

{

 (HAL_ETH_IsRxDataAvailable(&heth))

 {

   SCB_DisableICache(); // Disable Instruction-cache at beginning of function in case of success!

   ...

   SCB_EnableICache();   // Enable Instruction-cache at end of function

   return p;

 }

 else

  {

   return NULL;

  }

}

I do not use main-loop for Lwip-Process polling.

// while (1)

//   {

//      MX_LWIP_Process();   // in lwip.c this function calls: ethernetif_input() in ethernetif.c

//   }

I simply use Ethernet - Interrupt for Lwip-Process instead include in "stm32h7xx_it.c":

void ETH_IRQHandler(void)

{

 uint32_t rest;

 do

 {

    rest = ethernetif_input(&gnetif);                     

 } while (rest );

 // --------------- Clear the flags, when done ------------------------

  __HAL_ETH_DMA_CLEAR_IT(&heth, ETH_DMACSR_RI | ETH_DMACSR_NIS);

  __HAL_ETH_DMA_CLEAR_IT(&heth, ETH_DMACSR_TI | ETH_DMACSR_NIS);

  __HAL_ETH_DMA_CLEAR_IT(&heth, (ETH_DMACSR_CDE | ETH_DMACSR_ETI | ETH_DMACSR_RWT |

                         ETH_DMACSR_RBU | ETH_DMACSR_AIS));

  __HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG(ETH_WAKEUP_EXTI_LINE);

}

This gives a more comfortable "RTOS" feeling and works perfectly now.

In main-loop something else can be performed.

NOW IT IS WORKING PERFECTLY!

Best Regards,

Roland

View solution in original post

23 REPLIES 23
Imen.D
ST Employee

Hello @KR​ ,

I invite you to follow this FAQ, this may help you:

Ethernet not working on STM32H7x3

https://community.st.com/s/article/FAQ-Ethernet-not-working-on-STM32H7x3

Kind Regards,

Imen.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
KR1
Associate III

Copying the entire void MPU_Config(void) routine seemed to do the trick. Thanks!

I would suggest adding a warning in STM32CubeMX that MPU needs to be enabled and properly configured for ETH to work (I guess it could even generate the necessary code snippet). Because right now it informs only about the RAM pointers, PHY drivers, and DCache.

Hello Imen,

you wrote following in the link: https://community.st.com/s/article/FAQ-Ethernet-not-working-on-STM32H7x3

It is strongly recommended to follow the same configuration as in examples provided in STM32CubeH7 package:

But even the example does not work properly and leaves a lot of settings open, because CubeMX has to be used additionally to get it work. I (and maybe many other users do not want to adjust hundreds of parameters to get it work).

Please read my full article to see the problems. (Or at least final questions marked by asterisks).

Background:

I installed older version of LwIP with RTOS on Nucleo-144 - F746ZG board and it worked fine after setting the "forbidden" macro directive "LWIP_TCPIP_CORE_LOCKING" to "1" instead of "0".

LwIP and RTOS are working fine, even if installing some more threads for testing and two new interrupts (SPI5 and peripheral pin - Interrupt). No problem!

The nucleo board works as a server. Every 110ms our webpage makes a new XMLHttpRequest(), which is answered by the board by sending a 56kByte Bitmap every 110ms using the "netconn_write(…)" function in module "httpserver_netconn.c"

Like many other users, I now have this problem:

Now, I switched to Nucleo-144-H743ZI board, because I need more internal RAM - Memory.

There is no way to get same application running stable on the H743-board. I have tried Examples "LwIP_HTTP_Server_Netconn_RTOS" from both Library H7_V1.3.0 and from Library H7_V1.1.0

For instance: Transmission of 56kByte periodically every 110ms works fine for 20 seconds, than it stops for 2 seconds, than it continues for 7 seconds, than it hangs for 5 seconds and so on…

Sometimes the "http_server_netconn_thread" quits working completely. Than I have to reset the H743 board.

New new patch file "ethernetif.c" Version 1.3.1 did not solve this problem!

I think, even the original example "LwIP_HTTP_Server_Netconn_RTOS" for nucleo H743-board is not working perfectly, because it takes long time, when loading picture "stm32.jpg" (jumping man). When using chrome debugger (F12) and examinating network traffic, you can see very different response times, when reloading the demo homepage from nucleo-144 server. Sometimes data is pending endlessly.

Another problem is the fact, that this Webserver demo example is difficult to install, because HAL-Library and Middlewares are missing. You have to use CubeMX to get a LwIP with RTOS - template. There are several settings in the "Clock configuration" tab. How to set up the oscillator? How to set up LwIP and RTOS?

After generating code by cubeMX, the files of "LwIP_HTTP_Server_Netconn_RTOS" have to be copied to the Include and Source directory, which was made by cubeMX. Some files generated by cubeMX have to be overwritten by the older example files. Which of these? (We suppose all new cube generated files have to be overwritten by the example files).

Regarding this huge amount of settings, I think every user will get a different "LwIP_HTTP_Server_Netconn_RTOS" executable. So there is no reliable instance of demonstration code, where we can talk about. There is no .hex file for this example.

Which one of "FreeRTOSConfig.h" has to be used for example. The Cube generated file or the file from the example? Which main.c file, which ethernetif.c file?

Which linker script is correct? The cube generated or the one included in the example?

****** Here are my final questions ******:

What can be the cause of these sporadically problems?

(There seems to be a problem in pending data transmission, even when using the original untouched webserver demo).

Did you every consider this problem or do I have a "buggy" demo - executable because of the many uncertainties made by nearly infinite CubeMX setup possibilities and many files, which exist double and have to be overwritten?

To avoid this:

Is there any complete working "LwIP_HTTP_Server_Netconn_RTOS" webserver example including necessary HAL-Library, Middlewares and linker script, so that I can talk about exactly the same executable for the nucleo-144-H747ZI board than other users?

If there is no complete template. Is there at least a working STM32CubeMx project file *.ioc for this example?

Hello @RMuel.18.303​ ,

Thank you for your contribution. You raise some interesting points with details.

Your issue has been raised as part of the HAL and CubeMX team for check and analysis.

We will come back to you soon with update.

Kind Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Imen.D
ST Employee

Hello,

The STM32CubeMX can't generate a working LwIP application for STM32H7. Thus you has to setup and configure your application and activate the right flags.

In addition the code generated by CubeMX (MPU config, lwipots.h, FreeRTOSConfig.h, ...) is little different from code of the original application and it's not up to date.

So, I think it would be better to test with the application LwIP_HTTP_Server_Netconn_RTOS from the patch release STM32CubeH7_V1.3.2 package which tested successfully.

Kind Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Imen.D
ST Employee

Hello,

Please feel free to provide your feedback regarding the new patch STM32CubeH7_V1.3.2 package.

Kind Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
WBOUG
Senior

Hi @KR​ 

Can you please give me your ioc file?

Best Regards,

Wael

Dear Imen,

Yes, I have tried the STM32CubeH7_V1.3.2 in a complete new procject. As I have already expected, there is no improvement over the STM32CubeH7_V1.3.1 patch.

In the the new patch, you only added UID_BASE constant in stm32h743xx.h header file.

This was the only difference to V1.3.1 patch. The "ethernetif.c" interface driver file is still the same.

I am still missing a complete working sample including "httpserver_netconn.c", "fsdata_custom.c" and working "main.c" module, which just has to be compiled to get it work

on nucleo-H743ZI board as a webserver demo.

My example is working for a certain time (10 minutes), transmitting 260kB data every 100ms form Nucleo-Board H743ZI Server to client (PC) by XMLHttpRequest (...), as long as I do not reload my homepage asynchronously.

If homepage is reloaded, the system crashes immediately and I have to press the reset button at nucleo-board.

If there is no asynchronous request, the system crashes sporadically after 2~20 minutes.

The same problem occours in your (not modified) HTTP server example, if demo-homepage

(with the "jumping man" picture) is reloaded several times (Pressing F5 at Browser in short intervals).

This problem did not occur on nucleo-F746ZG board using older LwiP stack and HAL libraries

for the F746ZG controller.

Kind Regards,

Roland

Hi @RMuel.18.303​ 

Can you please give me your ioc file?

Best Regards,

Wael