cancel
Showing results for 
Search instead for 
Did you mean: 

Discovery board STM32L0 (LoRaWAN) -> How to configure the stop mode correctly?

pmathelin
Associate II

Hello!

I come there after some days of work on the stop mode on the dicovery board STM32L0 with LoRaWAN.

I tried to generate a new project which does nothing, to test the stop mode with RTC following the datasheet and measure the current consumption. I have some issues with doing this.

I use a multimeter on the JP2 tu measure the consumption when the board is powered by USB. Without the stop mode, the consuption is arround 11 mA and when I activate the stop mode after suspending Tick, the current consumption is arround 3.1 mA, which still is far far away from the consumption mentioned in the datasheet.

You can find my main following, maybe you can help me to find how can I enter in stop mode correctly? 😊

Thank you for your help !

int main(void)
{
	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();
 
	/* Configure the system clock */
	SystemClock_Config();
 
	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_RTC_Init();
	MX_SPI1_Init();
	MX_USART2_UART_Init();
	/* USER CODE BEGIN 2 */
 
	/* LOW POWER CODE */
	HAL_Delay(1000);
	HAL_SuspendTick();
	__HAL_RCC_PWR_CLK_ENABLE();
	HAL_PWREx_EnableUltraLowPower();		// Ultra low power mode
	HAL_PWREx_EnableFastWakeUp();			// Fast wake-up for ultra low power mode
	HAL_DeInit();
	MX_GPIO_Disable();
	// TCXO disabled with JP9 on 1-2
	__HAL_RCC_SPI1_CLK_DISABLE();
	__HAL_RCC_USART2_CLK_DISABLE();
	__HAL_RCC_ADC1_CLK_DISABLE();
	__HAL_RCC_TIM21_CLK_DISABLE();
	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);		// clear wake up flag
	HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
 
	HAL_ResumeTick();
	SystemClock_Config();
	/* LOW POWER CODE END */
 
	/* Infinite loop */
	while (1)
	{
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
		HAL_Delay(500);
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
		HAL_Delay(500);
	}
}

1 ACCEPTED SOLUTION

Accepted Solutions
pmathelin
Associate II

Hello,

Finally I found a solution to reach 1.4uA on the DEMO-BOARD and 1.9uA on the BRKABZ.

My problem was about a pin which was configured as output but should have been configured as analog/no_pull. After checking the pins one by one I figured it out and now, it works properly.

You can find the solution in attachment.

I hope it will help you 🙂

View solution in original post

3 REPLIES 3
pmathelin
Associate II

i found a part of a solution. Now I reach 90uA instead of 11mA yesterday.

To decrease the power consumption, I just added a function to put the Semtech SX1276 LoRa transceiver in low power mode, which is not puted in this mode by default when we use the stop mode.

So, you can find below the code for the first improvments:

void LPM_EnterStopMode(void){
	BACKUP_PRIMASK();
	DISABLE_IRQ( );
 
	main_rf_disable();					// Put Semtech SX1276 into Sleep Mode (IDDSL = 0.2 uA typ)
	HAL_SPI_DeInit(&hspi);				// Disable SPI
	HW_IoDeInit();
	HW_AdcDeInit();
	main_dbg_disable();					// Disable debug module and pins (SWCLK & SWDIO)
 
	__HAL_RCC_PWR_CLK_ENABLE();			// Enable power control clock
	HAL_PWR_DisablePVD();				// Disable the Power Voltage Detector
	HAL_PWREx_EnableUltraLowPower();
	HAL_PWREx_EnableFastWakeUp();
 
	__HAL_RCC_GPIOA_CLK_DISABLE();
	__HAL_RCC_GPIOB_CLK_DISABLE();
	__HAL_RCC_GPIOC_CLK_DISABLE();
	__HAL_RCC_GPIOH_CLK_DISABLE();
	HAL_SuspendTick();
 
	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); 				// Clear wakeUp flag
	RESTORE_PRIMASK( );
 
	// Switch to STOPMode
	HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
}
void main_rf_disable(void)
{
    // SX1276 SPI instruction to read version
    uint8_t sx1276_cmd_rd_reg_version[2] =
    {
        0x42,   // Read bit + RegVersion
        0x00,   // Data
    };
 
    // data
    uint8_t data[2];
 
    // SX1276 SPI instruction to put it into Sleep Mode
    uint8_t sx1276_cmd_sleep_mode[2] =
    {
        0x81,   // Write bit + RegOpMode
        0x00,   // Sleep Mode
    };
 
    // Power up TCXO
    HAL_GPIO_WritePin(RADIO_TCXO_VCC_PORT, RADIO_TCXO_VCC_PIN , GPIO_PIN_SET);
    HAL_Delay(10); // Wait at least 5 ms
 
    // Reset
    HAL_GPIO_WritePin(RADIO_RESET_PORT, RADIO_RESET_PIN, GPIO_PIN_RESET);
    HAL_Delay(10);  // Wait at least 1 ms
    HAL_GPIO_WritePin(RADIO_RESET_PORT, RADIO_RESET_PIN, GPIO_PIN_SET);
    HAL_Delay(10);  // Wait at least 6 ms
 
    // CS low
    HAL_GPIO_WritePin(RADIO_NSS_PORT, RADIO_NSS_PIN, GPIO_PIN_RESET);
    // Read RegVersion register
    HAL_SPI_TransmitReceive(&hspi, sx1276_cmd_rd_reg_version, data, 2, HAL_MAX_DELAY);
    // CS high
    HAL_GPIO_WritePin(RADIO_NSS_PORT, RADIO_NSS_PIN, GPIO_PIN_SET);
    HAL_Delay(10);
 
    // CS low
    HAL_GPIO_WritePin(RADIO_NSS_PORT, RADIO_NSS_PIN, GPIO_PIN_RESET);
    // Select Sleep Mode in RegOpMode register
    HAL_SPI_Transmit(&hspi, sx1276_cmd_sleep_mode, 2, HAL_MAX_DELAY);
    // CS high
    HAL_GPIO_WritePin(RADIO_NSS_PORT, RADIO_NSS_PIN, GPIO_PIN_SET);
    HAL_Delay(10);
 
    // Set RF Switch to receive mode
    HAL_GPIO_WritePin(RADIO_ANT_SWITCH_PORT_RX, RADIO_ANT_SWITCH_PIN_RX, GPIO_PIN_SET);
    HAL_GPIO_WritePin(RADIO_ANT_SWITCH_PORT_TX_RFO, RADIO_ANT_SWITCH_PIN_TX_RFO, GPIO_PIN_RESET);
    HAL_GPIO_WritePin(RADIO_ANT_SWITCH_PORT_TX_BOOST, RADIO_ANT_SWITCH_PIN_TX_BOOST, GPIO_PIN_RESET);
 
    // Power down TCXO
    HAL_GPIO_WritePin(RADIO_TCXO_VCC_PORT, RADIO_TCXO_VCC_PIN , GPIO_PIN_RESET);
}
 
void main_dbg_disable(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
 
    GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
    GPIO_InitStructure.Pull = GPIO_NOPULL;
    GPIO_InitStructure.Pin = (GPIO_PIN_13 | GPIO_PIN_14);
    HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
 
    __HAL_RCC_DBGMCU_CLK_ENABLE();
    HAL_DBGMCU_DisableDBGStopMode();
    __HAL_RCC_DBGMCU_CLK_DISABLE();
}

Still looking to decrease the power consumption to at least 4uA. If you have any suggestion, feal free to comment 😉

PS: think to unplug the ST-Link which consumes 300uA

ulissestpBR
Associate III

Thank you pmathelin for posting this solution to your own question.

I'm using this link as a guide to implement Stop Mode in my project too. Maybe this could help your implementation too?

Did you had any other improvements?

Btw I think ST could use your solution in their reference manuals.

Thanks again, I'll try your implementation.

Best regards!

pmathelin
Associate II

Hello,

Finally I found a solution to reach 1.4uA on the DEMO-BOARD and 1.9uA on the BRKABZ.

My problem was about a pin which was configured as output but should have been configured as analog/no_pull. After checking the pins one by one I figured it out and now, it works properly.

You can find the solution in attachment.

I hope it will help you 🙂