2025-05-25 8:19 AM
Hello everyone !
I'm currently working on the STM NUCLEO-wl55jc card and I'm having a few problems with it.
I'm using the Ping Pong example code, which allows LoRa point-to-point communication between 2 cards. This works perfectly.
My problem now is that I'd like to put one of my 2 cards in StandBy mode. So I use the function ‘HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);’ -> line 113, to initialise the wakeup pin, and the function ‘HAL_PWR_EnterSTANDBYMode();’ -> line 117, to enter StandBy mode. Then, in my while(1) loop, under ‘ifdef GO_TO_LOW_POWER’, I simply want to turn on an LED when I exit StandBy mode and start LoRa communication using this ‘MX_SubGHz_Phy_Process();’ -> line 146, function. However, when a pulse arrives on the wakeup pin, PA0, the LED lights up but unfortunately communication doesn't take place. So I wanted to know if this was the right way to proceed and if my card really went into StandBy mode at the start or not. Because when it's supposed to be in this mode, 2 LEDs are lit on the card, which I find strange.
In addition, I power my board in STD_5V_ALONE mode, so only the MCU, and I measure the current directly on jumper JP1, to get an idea of the current consumed by the processor and I measure around 8mA. I noticed that if I removed this line "MX_SubGHz_Phy_Init();" -> line 96, the consumption fell to 0mA, which could correspond to the StandBy current, I don't really know. Perhaps the call to this function is preventing my card from entering StandBy mode? I'm a bit at a loss here.
I'm sharing my main.c with you so that you can get a better idea of my problem.
For information, to download the code onto my card, I do a ‘build’ and then a ‘run’ for each of my cards.
If anyone could help me it would be a great pleasure.
Thanks in advance !
KYZ.
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "app_subghz_phy.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
//Test
/* 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();
//Initialize LoRa communication
MX_SubGHz_Phy_Init();
/* USER CODE BEGIN 2 */
/*------------------------------------------------------------
//Code permettant de switcher entre les 2 cartes différentes
------------------------------------------------------------*/
#ifdef GO_TO_LOW_POWER //Carte LOW_POWER
//Clear previous flags
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
//Activate the wakeup pin
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);
//Enter StandBy mode
HAL_PWR_EnterSTANDBYMode();
#else //Carte normale
#endif
/*------------------------------------------------------------
--------------------------------------------------------------
------------------------------------------------------------*/
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
#ifdef GO_TO_LOW_POWER //For the low power card which is in StandBy mode
//Used to check whether or not you are coming from STANDBY mode
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
//The card has woken up from STANDBY
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); // Nettoyer le flag
//The LED lights up when you exit STANDBYL modeThe board has woken up from STANDBY
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET); // Allumer la LED
//To start the PingPong between the two cards (LoRa)
MX_SubGHz_Phy_Process();
}
#else //For the another card
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET); //LED on
HAL_Delay(200);
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET); //LED off
HAL_Delay(200);
#endif
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure LSE Drive Capability
*/
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3|RCC_CLOCKTYPE_HCLK
|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @PAram file: pointer to the source file name
* @PAram line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
while (1)
{
}
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
2025-05-25 8:43 AM
Hello @KYZ
On the STM32WL LoRa context, for low power modes. You can use the functions of the Tiny_LPM utility so you can enable and disable low power modes (sleep, stop and off modes). More details are available on the AN5406 and specially on the chapter 9.3.
Best Regards.
STTwo-32
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-05-25 12:25 PM - last edited on 2025-05-25 1:02 PM by STTwo-32
Hello @STTwo-32,
Thank you for your quick response. So if I understand correctly, I need to call the "PWR_EnterOffMode" function, which will allow me to enter Standby mode (low power consumption). But is the function I was using previously, namely "HAL_PWR_EnterSTANDBYMode();," correct? Because for me, this function should allow me to enter Standby mode, right? I don't really understand why I would use one function or the other.
Best regards
KYZ