cancel
Showing results for 
Search instead for 
Did you mean: 

Basic UDP Echo server works in debug, but not run mode NUCLEO-F746ZG

KMill
Senior

I have a Nucleo F746ZG board and I've implemented a small UDP echo server in LwIP standalone mode. (No RTOS)

If I hit 'debug' and as soon as the code stops on the first instruction hit 'continue' then it works perfectly.

If however I just run the code, (no debugging) or reset the board it does not work. It sits in a loop patiently waiting for a DHCP address. I know this because I use the three LEDs to show status. 

Here is my main loop code:

 

int main(void)
{
  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */

  /* 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 */
  /* USER CODE END Init */

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

  /* USER CODE BEGIN SysInit */
  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART3_UART_Init();
  MX_USB_OTG_FS_PCD_Init();
  MX_LWIP_Init();
  /* USER CODE BEGIN 2 */

  HAL_GPIO_WritePin(LED_GREEN_PORT, LED_GREEN_PIN, GPIO_PIN_RESET);
  HAL_GPIO_WritePin(LED_BLUE_PORT, LED_BLUE_PIN, GPIO_PIN_RESET);
  HAL_GPIO_WritePin(LED_RED_PORT, LED_RED_PIN, GPIO_PIN_SET);

  while(dhcp_supplied_address(&gnetif)==0) {
	  ethernetif_input(&gnetif);
  	  sys_check_timeouts();
	  HAL_Delay(100);
  }

  HAL_GPIO_WritePin(LED_BLUE_PORT, LED_BLUE_PIN, GPIO_PIN_SET);

  udpServer_init();

  HAL_GPIO_WritePin(LED_GREEN_PORT, LED_GREEN_PIN, GPIO_PIN_SET);
  HAL_GPIO_WritePin(LED_RED_PORT, LED_RED_PIN, GPIO_PIN_RESET);


  /* USER CODE END 2 */

  /* 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 */
}

 

As you can see it's reasonably straightforward. I turn on the RED led, wait for a DHCP address (pumping the LWiP timeouts as required) and when it comes in switch on the BLUE led, and then when everything is running, switch off the RED and turn on the green. 

In debug this works fine, even without stepping.

In run time it stops after the red led comes on.

I'm guessing timing issue, or HAL_Delay() is hanging up? 

Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
ASEHST
ST Employee

Hello @KMill,

It appears that is a timing or synchronization issue. Debug mode can introduce additional delays that allow certain components to initialize correctly. Please try adding a delay after the initialization of the peripherals.

 

With Regards,

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

View solution in original post

2 REPLIES 2
ASEHST
ST Employee

Hello @KMill,

It appears that is a timing or synchronization issue. Debug mode can introduce additional delays that allow certain components to initialize correctly. Please try adding a delay after the initialization of the peripherals.

 

With Regards,

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

Hi @ASEHST 

Thanks for your suggestion.

If I add 1800ms of delay after SystemClockConfig() then it all works.

I tried 1500ms too, but it was too little. I would love to understand what is happening here, but for now I'll just include that delay. I have placed it inside the USER CODE BEGIN SysInit block.

Thanks again.