2021-12-15 01:25 PM
I'm attempting to cause an STM32WL (currently on a WL55JC1 devboard) to sleep using the shutdown mode, and am running into a an issue where the MCU immediately exits sleep after it enters it.
Here's what I believe to be the sleep related portions of my code - I can post more if needed:
int main(void)
{
HAL_Init();
HAL_PWR_EnableBkUpAccess();
uint32_t tickstart = HAL_GetTick();
HAL_StatusTypeDef ret = HAL_OK;
while (!(READ_BIT(PWR->CR1, PWR_CR1_DBP) == (PWR_CR1_DBP)))
{
if ((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
{
ret = HAL_TIMEOUT;
break;
}
}
__HAL_RCC_BACKUPRESET_FORCE(); //[JT] - Debug
__HAL_RCC_BACKUPRESET_RELEASE(); //[JT] - Debug
HAL_PWR_DisableBkUpAccess();
SystemClock_Config();
MX_GPIO_Init();
MX_RTC_Init();
MX_SUBGHZ_Init();
MX_USART2_UART_Init();
MX_SubGHz_Phy_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart2, Rx_data, 1);
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
/* Clear Standby flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
printf("wakeup from stdby");
// HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
}
while (1)
{
HAL_Delay(5000);
printf("going to sleep \n");
HAL_Delay(3000);
HAL_SuspendTick();
HAL_PWREx_EnterSHUTDOWNMode();
HAL_ResumeTick();
}
}
When going into sleep, I attempt to suspend the systick, and then use the HAL macro to enter the shutdown sleep mode. From what I've read this seems to be all I need, but obviously not in this case.
The exit from sleep happens regardless of the onboard ST-Link module on my devboard being powered or not.
NRST is currently floating, since when I pull it to ground the chip shuts down and pulls 700uA. Another puzzle to figure out.
Edit: Not sure if it will help, but here's my system clock config:
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 busses 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();
}
}
2021-12-20 11:10 AM
Still stumped on this one. I'm able to get to a "sleep" state using this code below, but its still pulling 3.1mA of current.
Radio.Sleep();
HAL_SUBGHZ_MspDeInit(&hsubghz);
LL_RCC_RF_EnableReset();
__disable_irq();
HAL_SuspendTick();
HAL_PWREx_DisableSRAMRetention();
HAL_PWREx_EnableFlashPowerDown(PWR_FLASHPD_LPSLEEP);
HAL_PWREx_EnterSHUTDOWNMode();
(sorry for formatting, pasting from CubeIDE into the code snippet box causes issues)