cancel
Showing results for 
Search instead for 
Did you mean: 

lwIP library needs delay to work outside of debug mode.

_AdamNtrx
Associate II

Hello! I've been trying to use lwIP library with my STM32F769I-DISCO development board to assign IP address to the microcontroller. While in debug mode everything works fine, in normal mode, however, it doesn't. I had to add two 1s delays before MX_GPIO_Init();MX_LWIP_Init() instructions and SystemClock_Config() instruction to make my program work outside of debug mode (they can be replaced with one 2s delay before GPIO and LWIP init functions).

The code is presented below:

<code>

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "lwip.h"

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */

extern ETH_HandleTypeDef heth;
extern struct netif gnetif;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MPU_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{
  /* MPU Configuration--------------------------------------------------------*/
  MPU_Config();

  /* Enable the CPU Cache */

  /* Enable I-Cache---------------------------------------------------------*/
  SCB_EnableICache();

  /* Enable D-Cache---------------------------------------------------------*/
  SCB_EnableDCache();

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */
 
  HAL_Delay(1000);
 
  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */
  HAL_Delay(1000); //delay to make things work outside of debug mode.
  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_LWIP_Init();

  /* USER CODE BEGIN WHILE */
  while (1)
  {
      ethernetif_input(&gnetif);
      sys_check_timeouts();

    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

</code>

 

I don't know why delays aren't needed in debug mode and are crucial outside of it, but it looks like some kind of bug to me. I decided to make this post in case somebody else also meets with this strange behaviour and in hope that it gets fixed in the future. Also I attach my STM32CubeIDE project with the code.

 

Regards!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Imen.D
ST Employee

Hello @_AdamNtrx ,

You can start your project from ready-to-use LwIP project:

STM32CubeF7/Projects/STM32F769I-Discovery/Applications/LwIP at master · STMicroelectronics/STM32CubeF7 · GitHub

You can also follow the instructions (step-by-step) provided in this article: How to create a project for STM32H7 with Ethernet ... - STMicroelectronics Community (instructions application for STM32F7).

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

View solution in original post

4 REPLIES 4
Imen.D
ST Employee

Hello @_AdamNtrx ,

You can start your project from ready-to-use LwIP project:

STM32CubeF7/Projects/STM32F769I-Discovery/Applications/LwIP at master · STMicroelectronics/STM32CubeF7 · GitHub

You can also follow the instructions (step-by-step) provided in this article: How to create a project for STM32H7 with Ethernet ... - STMicroelectronics Community (instructions application for STM32F7).

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

I changed the configuration of TCP/IP according to Adam BERLINGER's guide and now I don't need the 2s delay. I don' understand the magic behind this but the guide seemed to help with setting up the connection. Thank you!

PS I don't use MPU or FreeRTOS in most recent project. Also I periodically call MX_LWIP_Process in main loop, as recommended in the guide.

Your project works only by modifying the configuration of the TCP/IP ? I have the same issue(but in stm32f407series), but unfortunately this modification not work for me.

Yes, if I remember correctly I made only these changes and it fixed the problem. There are other valuable tips in the rest of the Adam Berlinger's guide, so maybe one of them could help you with resolving your issue.