cancel
Showing results for 
Search instead for 
Did you mean: 

Low-power mode STM32WLE5

valcarcexyz
Visitor

We are developing with the STM32WLE5JC6, everything works, but now we are trying to reduce current consumption. When using the "End node skeleton", it seems to work, however, we are trying to define our own skeleton, because we neither want the ADC nor the trace system for production.

I know that the problem is related to the sequencer, because is entering in the low power mode (through the `UTIL_SEQ_Idle`) before the retransmission has finished, so it just does nothing, I guess that the same happens when a TX is done. Most of the code is a copy-paste from the end node skeleton.

I suspect that we need to disable the stop mode while it is joining with the `UTIL_LPM_SetStopMode`, however, I do not know where the code should be placed; in the end node skeleton, it is disabled during the vcom transmission, so it is not very clear that it is actually this the problem, is it?

Relevant function implementations are found below.

The IDLE definition:

/* /Core/Src/sys_app.c */
void UTIL_SEQ_Idle(void)
{
  UTIL_LPM_EnterLowPower();
}

/* /Utilities/lpm/tiny_lpm/stm32_lpm.c */
void UTIL_LPM_EnterLowPower( void )
{
  UTIL_LPM_ENTER_CRITICAL_SECTION_ELP( );

  if( StopModeDisable != UTIL_LPM_NO_BIT_SET )
  {
    /**
     * At least one user disallows Stop Mode
     * SLEEP mode is required
     */
      UTIL_PowerDriver.EnterSleepMode( );
      UTIL_PowerDriver.ExitSleepMode( );
  }
  else
  { 
    if( OffModeDisable != UTIL_LPM_NO_BIT_SET )
    {
      /**
       * At least one user disallows Off Mode
       * STOP mode is required
       */
        UTIL_PowerDriver.EnterStopMode( );
        UTIL_PowerDriver.ExitStopMode( );
    }
    else
    {
      /**
       * OFF mode is required
       */
      UTIL_PowerDriver.EnterOffMode( );
      UTIL_PowerDriver.ExitOffMode( );
    }
  }
  
  UTIL_LPM_EXIT_CRITICAL_SECTION_ELP( );
}

The system app init function:

/* /Core/Src/sys_app.c */
void SystemApp_Init(void)
{
  /* USER CODE BEGIN SystemApp_Init_1 */
  __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);
  UTIL_TIMER_Init();
  SYS_TimerInitialisedFlag = 1;
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);

  UTIL_LPM_Init();
  UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE);
  /* USER CODE END SystemApp_Init_1 */
}

The lorawan init function:

/* /LoRaWAN/App/lora_app.c */
void LoRaWAN_Init(void)
{
  /* USER CODE BEGIN LoRaWAN_Init_LV */
  UTIL_TIMER_Status_t timer_status;
  timer_status = UTIL_TIMER_Create(&StopJoinTimer, JOIN_TIME, UTIL_TIMER_ONESHOT, OnStopJoinTimerEvent, NULL);
  UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LmHandlerProcess), UTIL_SEQ_RFU, LmHandlerProcess);
  UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), UTIL_SEQ_RFU, SendTxData);
  UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LoRaStoreContextEvent), UTIL_SEQ_RFU, StoreContext);
  UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), UTIL_SEQ_RFU, StopJoin);

  LmHandlerErrorStatus_t status;
  LoraInfo_Init();
  /* USER CODE END LoRaWAN_Init_LV */

  /* USER CODE BEGIN LoRaWAN_Init_1 */

  /* USER CODE END LoRaWAN_Init_1 */

  /* Init the Lora Stack*/
  LmHandlerInit(&LmHandlerCallbacks, APP_VERSION);

  /* USER CODE BEGIN LoRaWAN_Init_Last */
  status = LmHandlerConfigure(&LmHandlerParams);
  if (status != LORAMAC_HANDLER_SUCCESS) {
	  Error_Handler();
  }
  printf("LoRaWAN init SUCCESS\n");
  /* USER CODE END LoRaWAN_Init_Last */
}

static void OnStopJoinTimerEvent(void *context)
{
  if (ActivationType == ACTIVATION_TYPE_OTAA)
  {
    UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), CFG_SEQ_Prio_0);
  }
}
static void StopJoin(void)
{
  UTIL_TIMER_Stop(&TxTimer);

  if (LORAMAC_HANDLER_SUCCESS != LmHandlerStop())
  {
    APP_LOG(TS_OFF, VLEVEL_M, "LmHandler Stop on going ...\r\n");
  }
  else
  {
    APP_LOG(TS_OFF, VLEVEL_M, "LmHandler Stopped\r\n");
    if (LORAWAN_DEFAULT_ACTIVATION_TYPE == ACTIVATION_TYPE_ABP)
    {
      ActivationType = ACTIVATION_TYPE_OTAA;
      APP_LOG(TS_OFF, VLEVEL_M, "LmHandler switch to OTAA mode\r\n");
    }
    else
    {
      ActivationType = ACTIVATION_TYPE_ABP;
      APP_LOG(TS_OFF, VLEVEL_M, "LmHandler switch to ABP mode\r\n");
    }
    LmHandlerConfigure(&LmHandlerParams);
    LmHandlerJoin(ActivationType, true);
    UTIL_TIMER_Start(&TxTimer);
  }
  UTIL_TIMER_Start(&StopJoinTimer);
}

It is my first time working with the sequencer, so I am a bit confused. Any guidance will be appreciated, thanks in advance. 

0 REPLIES 0