Skip to main content
Explorer
August 20, 2024
Solved

lwIP library needs delay to work outside of debug mode.

  • August 20, 2024
  • 1 reply
  • 1764 views

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!

 

    This topic has been closed for replies.
    Best answer by Imen.D

    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).

    1 reply

    Imen.DAnswer
    Technical Moderator
    August 23, 2024

    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).

    _AdamNtrxAuthor
    Explorer
    August 28, 2024

    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.

    Explorer
    September 21, 2024

    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.