3

I'm sending some information using LoRaWAN on a STM32WB and after that, I enter standby mode. The problem is that after my standby, a new join is done. I have heard that my join could be keep in memory using MIB functions but I don't manage to use them properly and continue to do a join do not make a join at all... Does somebody know how to use them or a good tutorial somewhere? (I didn't find anything for the moment)

Here is what I am trying actually :

uint32_t last_time = 0;

int main(void)
{
  /* USER CODE BEGIN 1 */
  data_t data;
  LoraFlagStatus join_status = LORA_RESET;

  /* USER CODE END 1 */

  /* 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_DMA_Init();
  MX_ADC1_Init();
  MX_I2C1_Init();
  MX_LPTIM1_Init();
  MX_LPUART1_UART_Init();
  MX_RF_Init();
  HW_RTC_Init();
  MX_SPI1_Init();
  MX_I2C3_Init();
  MX_SPI2_Init();
  /* USER CODE BEGIN 2 */
  /* Reduce the System clock to below 2 MHz */
  SystemClock_Decrease();

  /* Set regulator voltage to scale 2 */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE2);

  HAL_PWREx_EnableLowPowerRunMode();

  float iaq;

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  MibRequestConfirm_t mibReq;

  mibReq.Type = MIB_NETWORK_ACTIVATION;

  LoRaMacMibGetRequestConfirm( &mibReq );

  if( mibReq.Param.NetworkActivation == ACTIVATION_TYPE_NONE )
  {
      lora_init();
      join_status = lora_join();
  }

  while (1)
  {

    //sensor code and lora send

      lora_update(); /* Must be called for the LoRa stack to work */

      pres = false;


      /* Enable and set RTC_WKUP_IRQ */
      HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 2, 0);
      HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);

      /* Check if the system was resumed from StandBy mode */
      /* Note: On STM32WB, both CPU1 and CPU2 must be in standby mode to set the entire system in standby mode */
      if(   (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
         && (__HAL_PWR_GET_FLAG(PWR_FLAG_C2SB) != RESET)
        )
      {
        /* Clear Standby flag */
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_C2SB);
      }

      /* Insert 5 seconds delay */
      HAL_Delay(5000);

      /* Disable all used wakeup sources*/
      HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);

      /* Clear all related wakeup flags */
      __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

      /* Re-enable wakeup source */
      /* ## Setting the Wake up time ############################################*/
      HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, 60, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);;

      /* Specific procedure on STM32WB, in case of initial power-up and RF stack no started */
      if(   (LL_PWR_IsActiveFlag_C1SB() == 0)
         || (LL_PWR_IsActiveFlag_C2SB() == 0)
        )
      {
        /* Set the lowest low-power mode for CPU2: shutdown mode */
        LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
      }

      /* Enter the Standby mode */
      HAL_PWR_EnterSTANDBYMode();

    /* USER CODE END WHILE */

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


/* USER CODE BEGIN 4 */
/**
  * @brief  System Clock Speed decrease
  *         The system Clock source is shifted from HSI to MSI
  *         while at the same time, MSI range is set to RCC_MSIRANGE_5
  *         to go down to 2MHz
  * @param  None
  * @retval None
  */
void SystemClock_Decrease(void)
{
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};

  /* Select MSI as system clock source */
  /* Note: Keep AHB and APB prescaler settings from previous structure initialization */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
  if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /* Disable PLL to reduce power consumption since MSI is used from that point */
  /* Change MSI frequency */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_OFF;
  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
}

/* USER CODE END 4 */
Tarick Welling
  • 3,119
  • 3
  • 19
  • 44
Sidka
  • 86
  • 4
  • Hey! Welcome to SO! Can you post some code that you have tried out? This way your question is more likely to get answered. – Pedro Filipe Jun 19 '20 at 15:52
  • 1
    Hey, thank you, I have edited my post with my actual code – Sidka Jun 22 '20 at 07:27
  • Are you using I-Cube LRWAN? I do not think there is any code that makes sure that the LoRa state is preserved across standby mode which does not keep all RAM on STM32 if my memory serves me correctly (but your MCU may be different than the STM32L4 that I used). I assume the Linker script determines what ends up in the preserved region. I have seen good results with stopmode (which preserves all RAM) on an STM32L4, i.e. no rejoin was necessary. I think the `lora_update` function would be crucial to understanding what happens on your system. – PaulR Jun 22 '20 at 14:57
  • Yes, I am using the I-Cube LRWAN. Well if it is not possible with standby I will use something else... I already began to try to use the stop mode but my peripherals do not work anymore after the wake up and I did not find why yet – Sidka Jun 22 '20 at 15:45
  • They probably don't work because you don't re-enable them. Peripherals are de-configured in stop mode. – Tarick Welling Jul 01 '20 at 09:33
  • Yes I know, but some of them aren't re-enable corectly I think. Maybe I will open a new subject for this. – Sidka Jul 02 '20 at 07:14
  • One caveat I ran into with stopmode and I-Cube LRWAN is that I-Cube LRWAN accesses the Radio (attached via SPI in our case) from interrupt service routines. I had to disable interrupts before deconfiguring peripherals and only enable interrupts after everything was reconfigured, because the SPI peripheral must be turned off during stop mode. – PaulR Jul 24 '20 at 15:53
  • Oh ok, I will try. Thanks for the advice! – Sidka Jul 27 '20 at 07:12

0 Answers0