cancel
Showing results for 
Search instead for 
Did you mean: 

STOP2 mode not Entering from HAL_PWREx_EnterSTOP2Mode

Soumyajit Das
Associate
Posted on March 14, 2017 at 07:19

MCU: STM32L443VCT

-

I am calling 'HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);' from the main application of my code but it seems that the function returns immediately (MCU not entering STOP2 mode). What I might be doing wrong, or where should I look for issues? Am I missing something. Do I need to do any sort of configuration so that the MCU enters STOP2 mode?

I know that I have not configured any wakeup event, but initially I am just trying to make sure that the MCU enters the STOP2 mode

-

My program flows as follows: (SystemClock_Config is the only function called before calling HAL_PWREx_EnterSTOP2Mode)

-

void

SystemClock_Config(

void

)

{

RCC_OscInitTypeDef

RCC_OscInitStruct;

RCC_ClkInitTypeDef

RCC_ClkInitStruct;

RCC_PeriphCLKInitTypeDef

PeriphClkInit;

RCC_OscInitStruct.

OscillatorType

= RCC_OSCILLATORTYPE_MSI;

RCC_OscInitStruct.

MSIState

= RCC_MSI_ON;

RCC_OscInitStruct.

MSICalibrationValue

= 0;

RCC_OscInitStruct.

MSIClockRange

= RCC_MSIRANGE_6;

RCC_OscInitStruct.

PLL

.

PLLState

= RCC_PLL_ON;

RCC_OscInitStruct.

PLL

.

PLLSource

= RCC_PLLSOURCE_MSI;

RCC_OscInitStruct.

PLL

.

PLLM

= 1;

RCC_OscInitStruct.

PLL

.

PLLN

= 40;

RCC_OscInitStruct.

PLL

.

PLLP

= RCC_PLLP_DIV7;

RCC_OscInitStruct.

PLL

.

PLLQ

= RCC_PLLQ_DIV2;

RCC_OscInitStruct.

PLL

.

PLLR

= RCC_PLLR_DIV2;

if

(HAL_RCC_OscConfig(&RCC_OscInitStruct) !=

HAL_OK

)

{

Error_Handler();

}

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_DIV1;

RCC_ClkInitStruct.

APB2CLKDivider

= RCC_HCLK_DIV1;

if

(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) !=

HAL_OK

)

{

Error_Handler();

}

PeriphClkInit.

PeriphClockSelection

= RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2

|RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_LPUART1

|RCC_PERIPHCLK_I2C1|RCC_PERIPHCLK_SDMMC1

|RCC_PERIPHCLK_RNG|RCC_PERIPHCLK_ADC;

PeriphClkInit.

Usart1ClockSelection

= RCC_USART1CLKSOURCE_PCLK2;

PeriphClkInit.

Usart2ClockSelection

= RCC_USART2CLKSOURCE_PCLK1;

PeriphClkInit.

Usart3ClockSelection

= RCC_USART3CLKSOURCE_PCLK1;

/*

* WARNING: Lpuart1ClockSelection have been changed from

* RCC_LPUART1CLKSOURCE_PCLK1 to RCC_LPUART1CLKSOURCE_HSI.

* This will result into feeding 16 MHz clock into LP UART

* instead of 80 MHz clock. Hence, effective clock frequency

* will be 5 (80 / 16) times slower than original frequency.

*/

PeriphClkInit.

Lpuart1ClockSelection

= RCC_LPUART1CLKSOURCE_PCLK1;

//RCC_LPUART1CLKSOURCE_HSI;//RCC_LPUART1CLKSOURCE_PCLK1;

PeriphClkInit.

I2c1ClockSelection

= RCC_I2C1CLKSOURCE_PCLK1;

PeriphClkInit.

AdcClockSelection

= RCC_ADCCLKSOURCE_PLLSAI1;

PeriphClkInit.

RngClockSelection

= RCC_RNGCLKSOURCE_PLLSAI1;

PeriphClkInit.

Sdmmc1ClockSelection

= RCC_SDMMC1CLKSOURCE_PLLSAI1;

PeriphClkInit.

PLLSAI1

.

PLLSAI1Source

= RCC_PLLSOURCE_MSI;

PeriphClkInit.

PLLSAI1

.

PLLSAI1M

= 1;

PeriphClkInit.

PLLSAI1

.

PLLSAI1N

= 16;

PeriphClkInit.

PLLSAI1

.

PLLSAI1P

= RCC_PLLP_DIV7;

PeriphClkInit.

PLLSAI1

.

PLLSAI1Q

= RCC_PLLQ_DIV2;

PeriphClkInit.

PLLSAI1

.

PLLSAI1R

= RCC_PLLR_DIV2;

PeriphClkInit.

PLLSAI1

.

PLLSAI1ClockOut

= RCC_PLLSAI1_48M2CLK|RCC_PLLSAI1_ADC1CLK;

if

(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) !=

HAL_OK

)

{

Error_Handler();

}

__HAL_RCC_PWR_CLK_ENABLE();

if

(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) !=

HAL_OK

)

{

Error_Handler();

}

HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */

HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

-----

#sleep-wakeup #stop2 #stm32
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 15, 2017 at 09:59

Hi Schaltegger Fabian,

  I figured out my issue. I was keeping the JTAG programmer (ST-Link) connected which was blocking the MCU from entering STOP2 mode. Now, after program download to MCU is over, I am disconnecting the JTAG connector & then power cycling the board. Everything seems to work fine!

Thanks

View solution in original post

2 REPLIES 2
scag
Associate II
Posted on March 15, 2017 at 07:52

Hi, I had the same problem with my STM32L476RG

Try to disable the Systick timer. If any IRQ is pending, the core does not enter stop2 mode.

Good luck

Posted on March 15, 2017 at 09:59

Hi Schaltegger Fabian,

  I figured out my issue. I was keeping the JTAG programmer (ST-Link) connected which was blocking the MCU from entering STOP2 mode. Now, after program download to MCU is over, I am disconnecting the JTAG connector & then power cycling the board. Everything seems to work fine!

Thanks