cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L433CC Not wake up from stop when portb is configured all analog, in RTC wakeup

FBald.1
Associate III

If I put port b all in analog the micro not wake up when in RTC wakeup mode (internal wakeup).

Any help?

Thanks in avance

void EnterStopMode(void)

{

 GPIO_InitTypeDef GPIO_InitStruct={0};

 /* Configure all GPIO as analog to reduce current consumption on non used IOs */

 /* Enable GPIOs clock */

 __HAL_RCC_GPIOC_CLK_ENABLE();

 __HAL_RCC_GPIOD_CLK_ENABLE();

 __HAL_RCC_GPIOE_CLK_ENABLE();

 __HAL_RCC_GPIOH_CLK_ENABLE();

 __HAL_RCC_GPIOA_CLK_ENABLE();

 __HAL_RCC_GPIOB_CLK_ENABLE();

 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

 // GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Pin = GPIO_PIN_All;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);

 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 // HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);   

 __HAL_RCC_GPIOC_CLK_DISABLE();

 __HAL_RCC_GPIOD_CLK_DISABLE();

 __HAL_RCC_GPIOE_CLK_DISABLE();

 __HAL_RCC_GPIOH_CLK_DISABLE();

 __HAL_RCC_GPIOA_CLK_DISABLE();

// __HAL_RCC_GPIOB_CLK_DISABLE();

 /* RTC configuration */

RTCHandle.Instance = RTC;

RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;

RTCHandle.Init.AsynchPrediv =0x7F; // LSE as RTC clock: RTC_ASYNCH_PREDIV

RTCHandle.Init.SynchPrediv = 0x00FF; // LSE as RTC clock: RTC_SYNCH_PREDIV;

RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;

RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

//__HAL_RCC_PWR_CLK_ENABLE(); // Enable Power Control clock

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 5, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);

//__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

//__HAL_RCC_PWR_CLK_ENABLE(); // Enable Power Control clock

HAL_SuspendTick();

HAL_PWR_DisableSleepOnExit();

/* Enter Stop Mode */

HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

////////////////

// STOP MODE

////////////////

HAL_ResumeTick();

/* Disable Wakeup Counter */

HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);

ReinitializePeripherial();

}

17 REPLIES 17
Mohamed Aymen HZAMI
ST Employee

Hello,

Enclosed my main configuration, try to run it on your board:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
RTC_HandleTypeDef hrtc;
 
/* USER CODE BEGIN PV */
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_RTC_Init(void);
void __GPIO_Config (void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
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 */
	
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_RTC_Init();
  /* USER CODE BEGIN 2 */
	
	 GPIO_InitTypeDef GPIO_InitStruct={0};
 __HAL_RCC_GPIOC_CLK_ENABLE();
 __HAL_RCC_GPIOD_CLK_ENABLE();
 __HAL_RCC_GPIOE_CLK_ENABLE();
 __HAL_RCC_GPIOH_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();
 __HAL_RCC_GPIOB_CLK_ENABLE();
 
 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Pin = GPIO_PIN_All;
 
 
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);   
	 
	 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
   GPIO_InitStruct.Pull =  GPIO_PULLDOWN;
   
   GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_13;  
   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
   GPIO_InitStruct.Pin = GPIO_PIN_3;  
   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
	
 __HAL_RCC_GPIOB_CLK_DISABLE();
 __HAL_RCC_GPIOC_CLK_DISABLE();
 __HAL_RCC_GPIOD_CLK_DISABLE();
 __HAL_RCC_GPIOE_CLK_DISABLE();
 __HAL_RCC_GPIOH_CLK_DISABLE();
 
 __GPIO_Config();
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 3, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
		HAL_SuspendTick();
		HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
		HAL_ResumeTick();
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
 
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 1;
  RCC_OscInitStruct.PLL.PLLN = 10;
  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();
  }
  /** 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;
  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_RTC;
  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure the main internal regulator output voltage
  */
  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
  {
    Error_Handler();
  }
}
 
/**
  * @brief RTC Initialization Function
  * @param None
  * @retval None
  */
static void MX_RTC_Init(void)
{
 
  /* USER CODE BEGIN RTC_Init 0 */
 
  /* USER CODE END RTC_Init 0 */
 
  /* USER CODE BEGIN RTC_Init 1 */
 
  /* USER CODE END RTC_Init 1 */
  /** Initialize RTC Only
  */
  hrtc.Instance = RTC;
  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  hrtc.Init.AsynchPrediv = 127;
  hrtc.Init.SynchPrediv = 255;
  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN RTC_Init 2 */
 
  /* USER CODE END RTC_Init 2 */
 
}
 
/* USER CODE BEGIN 4 */
void __GPIO_Config (void)
{
	GPIO_InitTypeDef gpio;
	
	__HAL_RCC_GPIOA_CLK_ENABLE();
	
	gpio.Mode = GPIO_MODE_OUTPUT_PP;
	gpio.Pin  = GPIO_PIN_8;
	gpio.Pull = GPIO_PULLUP;
	gpio.Speed= GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(GPIOA,&gpio);
}
/* USER CODE END 4 */
 
/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
 
  /* USER CODE END Error_Handler_Debug */
}
 
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Best Regards,

Mohamed Aymen.

Hello Mohamed,
Thank you ,I try your code.
Fausto
Il 09/09/2020 17:13, ST Community ha scritto:
Hello Mohamed,
I tried your example, but when I run it crashes at the line where it sets port A and doesn't go ahead:
HAL_GPIO_Init (GPIOA, & GPIO_InitStruct);
and it doesn't go on.
Do you have any suggestions for me.
Thanks in advance
Fausto
Il 09/09/2020 17:13, ST Community ha scritto:
Hello Mohamed, for port A it's OK,but if I put portB all analog, I not see any writing on uart3 from terminal emulator. what have todo to reconfigure the huart3? If I exclude " HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);  " work but the current is high for my battery operation. Thanks again in avance. Fausto This is my c source /* USER CODE BEGIN Header */ /** ******************************************************************************   * @file           : main.c   * @brief          : Main program body ******************************************************************************   * @attention   *   *

© Copyright (c) 2020 STMicroelectronics.   * All rights reserved.

  *   * This software component is licensed by ST under BSD 3-Clause license,   * the "License"; You may not use this file except in compliance with the   * License. You may obtain a copy of the License at:   *                        opensource.org/licenses/BSD-3-Clause   * ******************************************************************************   */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include #include /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ RTC_HandleTypeDef hrtc; UART_HandleTypeDef huart3; /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_RTC_Init(void); static void MX_USART3_UART_Init(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */  void SetAllAnalog()  {       GPIO_InitTypeDef GPIO_InitStruct={0};  __HAL_RCC_GPIOC_CLK_ENABLE();  __HAL_RCC_GPIOD_CLK_ENABLE();  __HAL_RCC_GPIOE_CLK_ENABLE();  __HAL_RCC_GPIOH_CLK_ENABLE();  __HAL_RCC_GPIOA_CLK_ENABLE();  __HAL_RCC_GPIOB_CLK_ENABLE();  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;  GPIO_InitStruct.Pull = GPIO_NOPULL;  GPIO_InitStruct.Pin = GPIO_PIN_All;  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);  HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;    GPIO_InitStruct.Pull =  GPIO_PULLDOWN;   // GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_13;   // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);   // GPIO_InitStruct.Pin = GPIO_PIN_3;   // HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);  __HAL_RCC_GPIOA_CLK_DISABLE();  __HAL_RCC_GPIOB_CLK_DISABLE();  __HAL_RCC_GPIOC_CLK_DISABLE();  __HAL_RCC_GPIOD_CLK_DISABLE();  __HAL_RCC_GPIOE_CLK_DISABLE();  __HAL_RCC_GPIOH_CLK_DISABLE();  } /* USER CODE END 0 */ /**   * @brief  The application entry point.   * @retval int   */ 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 */   /* USER CODE END SysInit */   /* Initialize all configured peripherals */   MX_GPIO_Init();   MX_RTC_Init();   MX_USART3_UART_Init();   /* USER CODE BEGIN 2 */  //__GPIO_Config();  char TextStr[32];  int Counter=0;   /* USER CODE END 2 */   /* Infinite loop */   /* USER CODE BEGIN WHILE */   while (1)   {     HAL_Init();     SystemClock_Config();     MX_GPIO_Init();     MX_RTC_Init();     MX_USART3_UART_Init();     HAL_Delay(1000);     sprintf(TextStr,"Counter=%d\r\n",Counter++);     HAL_UART_Transmit(&huart3,(uint8_t*) TextStr, strlen(TextStr), 500);     SetAllAnalog();     /*         HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 3, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);         HAL_SuspendTick();         HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);         HAL_ResumeTick();     */     /* USER CODE END WHILE */     /* USER CODE BEGIN 3 */   }   /* USER CODE END 3 */ } /**   * @brief System Clock Configuration   * @retval None   */ void SystemClock_Config(void) {   RCC_OscInitTypeDef RCC_OscInitStruct = {0};   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};   /** Initializes the CPU, AHB and APB busses clocks   */   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_MSI;   RCC_OscInitStruct.LSIState = RCC_LSI_ON;   RCC_OscInitStruct.MSIState = RCC_MSI_ON;   RCC_OscInitStruct.MSICalibrationValue = 0;   RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)   {     Error_Handler();   }   /** Initializes the CPU, AHB and APB busses clocks   */   RCC_ClkInitStruct.ClockType = 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;   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)   {     Error_Handler();   }   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART3;   PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;   PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)   {     Error_Handler();   }   /** Configure the main internal regulator output voltage   */   if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)   {     Error_Handler();   } } /**   * @brief RTC Initialization Function   * @param None   * @retval None   */ static void MX_RTC_Init(void) {   /* USER CODE BEGIN RTC_Init 0 */   /* USER CODE END RTC_Init 0 */   /* USER CODE BEGIN RTC_Init 1 */   /* USER CODE END RTC_Init 1 */   /** Initialize RTC Only   */   hrtc.Instance = RTC;   hrtc.Init.HourFormat = RTC_HOURFORMAT_24;   hrtc.Init.AsynchPrediv = 127;   hrtc.Init.SynchPrediv = 255;   hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;   hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;   hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;   hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;   if (HAL_RTC_Init(&hrtc) != HAL_OK)   {     Error_Handler();   }   /* USER CODE BEGIN RTC_Init 2 */   /* USER CODE END RTC_Init 2 */ } /**   * @brief USART3 Initialization Function   * @param None   * @retval None   */ static void MX_USART3_UART_Init(void) {   /* USER CODE BEGIN USART3_Init 0 */   /* USER CODE END USART3_Init 0 */   /* USER CODE BEGIN USART3_Init 1 */   /* USER CODE END USART3_Init 1 */   huart3.Instance = USART3;   huart3.Init.BaudRate = 115200;   huart3.Init.WordLength = UART_WORDLENGTH_8B;   huart3.Init.StopBits = UART_STOPBITS_1;   huart3.Init.Parity = UART_PARITY_NONE;   huart3.Init.Mode = UART_MODE_TX_RX;   huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;   huart3.Init.OverSampling = UART_OVERSAMPLING_16;   huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;   huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;   if (HAL_UART_Init(&huart3) != HAL_OK)   {     Error_Handler();   }   /* USER CODE BEGIN USART3_Init 2 */   /* USER CODE END USART3_Init 2 */ } /**   * @brief GPIO Initialization Function   * @param None   * @retval None   */ static void MX_GPIO_Init(void) {   /* GPIO Ports Clock Enable */   __HAL_RCC_GPIOB_CLK_ENABLE(); } /* USER CODE BEGIN 4 */ void __GPIO_Config (void) {     GPIO_InitTypeDef gpio;     __HAL_RCC_GPIOA_CLK_ENABLE();     gpio.Mode = GPIO_MODE_OUTPUT_PP;     gpio.Pin  = GPIO_PIN_8;     gpio.Pull = GPIO_PULLUP;     gpio.Speed= GPIO_SPEED_FREQ_HIGH;     HAL_GPIO_Init(GPIOA,&gpio); } /* USER CODE END 4 */ /**   * @brief  This function is executed in case of error occurrence.   * @retval None   */ void Error_Handler(void) {   /* USER CODE BEGIN Error_Handler_Debug */   /* User can add his own implementation to report the HAL error return state */   /* USER CODE END Error_Handler_Debug */ } #ifdef  USE_FULL_ASSERT /**   * @brief  Reports the name of the source file and the source line number   *         where the assert_param error has occurred.   * @param  file: pointer to the source file name   * @param  line: assert_param error line source number   * @retval None   */ void assert_failed(char *file, uint32_t line) {   /* USER CODE BEGIN 6 */   /* User can add his own implementation to report the file name and line number,      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */   /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ Il 09/09/2020 17:13, ST Community ha scritto:
Mohamed Aymen HZAMI
ST Employee

Hello,

In the SetAllAnalog() fuction you need to keep the state of the GPIOs that you are using in the USART3.

Best Regards,

Mohamed Aymen.

FBald.1
Associate III

1129/5000

Hi Mohamed.

Thank you very much for your availability, I'll explain what our goal is.

My application requires to be battery powered for at least ten years.

Therefore it is necessary that when in stop mode, it absorbs the current indicated in the datasheet or at most 1/2 uA.

Our requirement is to stop the processor in order not to lose the data in RAM and when you wake up resume communication with external devices, uart, spi, analog and gpio regularly, do some processing and return to stop mode to wake up after 15 minutes, this cycle for 10 years.

So what I'm trying is not working is to put the micro to sleep and when it wakes up it works regularly.

Do you have an example of how to put the micro in the condition to absorb the minimum possible current?

How can I keep the status of the pins dedicated to the uart?

We have measured, if I do not put port B in analogue, that when it goes into stop mode, it absorbs 350 uA, which for our application is too high, we must necessarily go below 3 uA.

Thanks again for your help.

Fausto

Mohamed Aymen HZAMI
ST Employee

Hello,

For the USART's GPIOs you can keep their state like this :

 void SetAllAnalog()
 {
 GPIO_InitTypeDef GPIO_InitStruct={0};
 __HAL_RCC_GPIOC_CLK_ENABLE();
 __HAL_RCC_GPIOD_CLK_ENABLE();
 __HAL_RCC_GPIOE_CLK_ENABLE();
 __HAL_RCC_GPIOH_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();
 __HAL_RCC_GPIOB_CLK_ENABLE();
 
 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Pin = GPIO_PIN_All;
 
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
   GPIO_InitStruct.Pull =  GPIO_PULLDOWN;
 
/* In this case we keep the state of GPIOA_PIN_2 and 13 */
GPIO_InitStruct.Pin = GPIO_PIN_All & (~GPIO_PIN_2 ) & (~GPIO_PIN_13); 
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
/* In this case we keep the state of GPIOB_PIN_3 */
GPIO_InitStruct.Pin = GPIO_PIN_All & (~GPIO_PIN_3) ; 
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 __HAL_RCC_GPIOA_CLK_DISABLE();
 __HAL_RCC_GPIOB_CLK_DISABLE();
 __HAL_RCC_GPIOC_CLK_DISABLE();
 __HAL_RCC_GPIOD_CLK_DISABLE();
 __HAL_RCC_GPIOE_CLK_DISABLE();
 __HAL_RCC_GPIOH_CLK_DISABLE();
 }

Best Regards,

Mohamed Aymen.

Hello Mohamed,
I try it, but if I keep the pin , I have <3 uA current in stop state.
Thank you very much.
Fausto
Il 14/09/2020 16:36, ST Community ha scritto:
Mohamed Aymen HZAMI
ST Employee

Hello Fausto,

Can you please send me your code in order to reproduce the same behavior.

Thanks and Best Regards,

Mohamed Aymen.