STM32WB5MMGH6 consuming to much current at Stop 2 Mode
I'm using an STM32WB5MMGH6 and it's consuming too much current at Stop 2 Mode.
The existing BLE connections are closed and advertising is stopped. All unnecessary peripherals, gpios and interrupts are disabled. The system clock is changed to MSI at 1MHz and Systick is disabled.
In the current conditions, the system consumes about 1 mA while in Stop Mode 2.
We tried using Shutdown Mode and got a consumption of about 100 uA which corresponds to the expected current bleed eliminating a hardware problem. Using Stop Mode 2 we expected about the same consumption.
What's missing so that i can achieve a lower consumption?
Here is the code snippet:
GPIO_InitTypeDef GPIO_InitStruct = { 0 };
// Configure the system clock
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
HAL_NVIC_DisableIRQ(ADC1_IRQn); // ADC INT
HAL_NVIC_DisableIRQ(EXTI1_IRQn); // GAUGE_NINT
HAL_NVIC_DisableIRQ(EXTI15_10_IRQn); // SENS_INT1
HAL_NVIC_DisableIRQ(EXTI3_IRQn); // IMU_DRDY
HAL_NVIC_DisableIRQ(TIM1_TRG_COM_TIM17_IRQn);
HAL_NVIC_DisableIRQ(TIM2_IRQn);
HAL_NVIC_DisableIRQ(TIM1_UP_TIM16_IRQn);
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
HAL_Delay(100);
lsm6dsl_stop(&lsm6dsl_driver); //POWER DOWN IMU SENSORS
HAL_I2C_DeInit(&hi2c1);
HAL_SPI_DeInit(&hspi2);
HAL_PCD_DeInit(&hpcd_USB_FS);
HAL_CRYP_DeInit(&hcryp1);
HAL_CRC_DeInit(&hcrc);
HAL_ADC_DeInit(&hadc1);
HAL_UART_DeInit(&hlpuart1);
HAL_SYSCFG_DisableVREFBUF();
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = EXT_FLASH_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(EXT_FLASH_CS_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = EXT_FLASH_NWP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(EXT_FLASH_NWP_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = GAUGE_NINT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GAUGE_NINT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = IMU_DRDY_ACCGYR_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(IMU_DRDY_ACCGYR_GPIO_Port, &GPIO_InitStruct);
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_I2C1_CLK_DISABLE();
__HAL_RCC_USART1_CLK_DISABLE();
__HAL_RCC_SPI2_CLK_DISABLE();
__HAL_RCC_USB_CLK_DISABLE();
GPIO_InitStruct.Pin = IMU_GAUGE_SDA_Pin | IMU_GAUGE_SCL_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = EXT_FLASH_SCLK_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(EXT_FLASH_SCLK_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = EXT_FLASH_SDO_Pin | EXT_FLASH_SDI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = USB_DP_Pin | USB_DM_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LPUART1_TX_Pin | LPUART1_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
// Enable MSI oscillator
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = 0; // You can set a calibration value if needed
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4; // Adjust the range based on your requirements
HAL_RCC_OscConfig(&RCC_OscInitStruct);
// Select MSI as the system clock source and configure the HCLK, PCLK1, and PCLK2
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 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.AHBCLK2Divider = RCC_SYSCLK_DIV2;
RCC_ClkInitStruct.AHBCLK4Divider = RCC_SYSCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
HAL_SuspendTick();
DBGMCU->CR = 0; // Disable debug and trace in low-power modes
LL_PWR_DisableBootC2();
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE2);
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
