cancel
Showing results for 
Search instead for 
Did you mean: 

Current consumption in sleep mode for STM32f401re

NNada.1
Associate II

Hello Everyone ,

I have a wrote a code to send STM32F401re to sleep with all peripherals on at 84Mhz , as per the datasheet i should be seeing a current consumption of 18-20mA, however I am seeing a consumption of 27mA.

The code sends data through UART on pressing the user button given in Nucleo64 board. then again goes to sleep using WFI intruction

Can anyone explain me where am I going wrong?

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 */
 
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
  ALL_PERIPHERAL_ENABLE
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */
 
  //Configure GPIO as input and enable interurt
  //C13
 
  configure_input_pin();
 
  //COndifure NVIC and EXIT block
 
 
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  uint8_t temp[]="The applcation has begin\n";
  uint8_t msg[20];
  while (1)
  {
    /* USER CODE END WHILE */
		HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
		HAL_UART_Transmit(&huart2, temp, strlen(temp), HAL_MAX_DELAY);
		sprintf(msg,"\n\rThe clock frequency now is %d",HAL_RCC_GetHCLKFreq());
		HAL_UART_Transmit(&huart2, msg, strlen(msg), HAL_MAX_DELAY);
 
		sprintf(msg,"\n\rThe p1 clock frequency now is %d",HAL_RCC_GetPCLK1Freq());
		HAL_UART_Transmit(&huart2, msg, strlen(msg), HAL_MAX_DELAY);
 
		sprintf(msg,"\n\rThe p2 clock frequency now is %d",HAL_RCC_GetPCLK2Freq());
		HAL_UART_Transmit(&huart2, msg, strlen(msg), HAL_MAX_DELAY);
 
		HAL_SuspendTick();
		__WFI();
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  uint8_t latency;
 
  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
 
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource= RCC_PLLSOURCE_HSI;
#if (AllPeripheralEn_84Mhz)|| (AllPeripheralEn_84Mhz)
  RCC_OscInitStruct.PLL.PLLM=16;
  RCC_OscInitStruct.PLL.PLLN=168;
  RCC_OscInitStruct.PLL.PLLP=2;
  latency=FLASH_LATENCY_2;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
 
#else if(AllPeripheralEn_40Mhz)|| (AllPeripheralEn_40Mhz)
  RCC_OscInitStruct.PLL.PLLM=16;
  RCC_OscInitStruct.PLL.PLLN=80;
  RCC_OscInitStruct.PLL.PLLP=2;
  latency = FLASH_LATENCY_1
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
#endif
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Initializes the CPU, AHB and APB buses clocks
  */
  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;
 
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, latency) != HAL_OK)
  {
    Error_Handler();
  }
}

1 REPLY 1
KDJEM.1
ST Employee

Hello @NNada.1​ and welcome to STCommunity :) ,

Please make sure that all free pins are set as Analog to optimize the power consumption. For that, I advise you to take a look to this FAQ.

Also, please don't forget to add this commend line to enter sleep mode:

HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.

Thank you

Kaouthar

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.