cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo--f429zi Ethernet Wakeup through EXTI line interrupt does not working

Nsait.1
Associate

Dear STM support,

I'm trying work on waking up from stop mode with magic packet.

In debugging mode, I caught a breakpoint in method ETH_WKUP_IRQHandler() and succeeded in the device waking up.

But not in debugging mode, the device was not waken up. (I judge it waking up simply based on measuring current.)

My code is as follows.

main.c

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
 
  /** Configure LSE Drive Capability 
  */
  HAL_PWR_EnableBkUpAccess();
  /** Configure the main internal regulator output voltage 
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 216;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 2;
  RCC_OscInitStruct.PLL.PLLR = 2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Activate the Over-Drive mode 
  */
  if (HAL_PWREx_EnableOverDrive() != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
  {
    Error_Handler();
  }
  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART3
                              |RCC_PERIPHCLK_I2C2;
  PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
  PeriphClkInitStruct.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
}

tcpecho.c

static void tcpecho_thread(void *arg)
{
  struct netconn *conn, *newconn;
  err_t err, accept_err;
  struct netbuf *buf;
  void *data;
  u16_t len;
      
  LWIP_UNUSED_ARG(arg);
 
  /* Create a new connection identifier. */
  conn = netconn_new(NETCONN_TCP);
  //conn = netconn_new(NETCONN_UDP);
  if (conn!=NULL)
  {  
    /* Bind connection to well known port number LISTEN_PORT. */
    err = netconn_bind(conn, NULL, LISTEN_PORT);
 
    if (err == ERR_OK)
    {
      /* Tell connection to go into listening mode. */
      netconn_listen(conn);
 
      while (1)
      {
          // procedure 1~4
          HAL_ETH_Stop(ethHandle);
          // procedure 5
          __HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG();
          __HAL_ETH_WAKEUP_EXTI_ENABLE_RISING_EDGE_TRIGGER();
          __HAL_ETH_WAKEUP_EXTI_ENABLE_IT();
          // procedure 6
          //HAL_NVIC_DisableIRQ(ETH_IRQn);
          HAL_NVIC_EnableIRQ(ETH_WKUP_IRQn);
          HAL_NVIC_SetPriority(ETH_WKUP_IRQn, 0, 0);
          __HAL_RCC_ETH_CLK_ENABLE();
          // procedure 7
          __HAL_ETH_MAGIC_PACKET_DETECTION_ENABLE(ethHandle);
          __HAL_ETH_GLOBAL_UNICAST_WAKEUP_ENABLE(ethHandle);
          // procedure 8
          __HAL_ETH_POWER_DOWN_ENABLE(ethHandle);
          // procedure 9
          (ethHandle->Instance)->MACCR |= ETH_MACCR_RE;
          __IO uint32_t tmpreg3 = 0U;
          /* Enable the MAC reception */
          (ethHandle->Instance)->MACCR |= ETH_MACCR_RE;
          /* Wait until the write operation will be taken into account:
           at least four TX_CLK/RX_CLK clock cycles */
          tmpreg3 = (ethHandle->Instance)->MACCR;
          (ethHandle->Instance)->MACCR = tmpreg3;
          /* Enable Power Control clock */
          __HAL_RCC_PWR_CLK_ENABLE();
         HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
 
        /* Grab new connection. */
         //accept_err = netconn_accept(conn, &newconn);
         accept_err = ERR_MEM;
        /* Process the new connection. */
        if (accept_err == ERR_OK)
        {
 
          while (netconn_recv(newconn, &buf) == ERR_OK)
          {
            do
            {
              netbuf_data(buf, &data, &len);
              xprintf("@tcpecho %u >%s<\n", len, (const char *)data);
 
              netconn_write(newconn,
                  l_tcpEcho.resultBuf, sizeof(l_tcpEcho.resultBuf),
                  NETCONN_COPY);
            }
            while (netbuf_next(buf) >= 0);
 
            netbuf_delete(buf);
          }
 
          /* Close connection and discard connection identifier. */
          netconn_close(newconn);
          netconn_delete(newconn);
        }
      }
    }
    else
    {
      netconn_delete(newconn);
    }
  }
}

stm32f2xx_it.h

void ETH_WKUP_IRQHandler(void)
{
    /* USER CODE BEGIN ETH_WKUP_IRQn 0 */
 
    HAL_ETH_Start(ethHandle);
    SystemClock_Config();
    /* USER CODE END ETH_WKUP_IRQn 0 */
 
    HAL_ETH_IRQHandler(ethHandle);
    /* USER CODE BEGIN ETH_WKUP_IRQn 1 */
 
    /* USER CODE END ETH_WKUP_IRQn 1 */
}

​I suspect my clock configuration is wrong, but i have no idea.

Could you help me with this issue?

Best regards,

1 REPLY 1
CA_SUS
Associate II

Hi,

I'm stuck with a very similar issue on a STM32F746: I enter the low power mode (stop) after the complete controller init sequence finished.

Waking up works when I start the programm via debugger (run or debug, both work).

When I restart it with a power cycle, the STM32 doesn't react to magic packets anymore.

It looks to me like due to the debugger, the controller is woken up for very short periods and only reacts to the magic packets because of that. If I use "HAL_DBGMCU_EnableDBGStopMode()" the wakeup works, because then the controller always behaves like a debugger is connected. But obviously that is no feasible solution.

Did you find a solution to your problem @Nsait.1​ ?

Best Regards