cancel
Showing results for 
Search instead for 
Did you mean: 

Reading GPIO in stop 1 mode

Gautham19
Associate II

As per datasheet of stm32u5 series during the Stop 1 mode DMA and peripherals are accessible. When tried to access the GPIO read. Controller during debug mode reading the GPIO, but in the run mode the GPIO is not getting read. How to read GPIO pin in App_ThreadX_LowPower_Enter. Based on reading the pin I'm triggering EXTI SWIER interrupt to wake up from Stop 1 mode.

 

Gautham19_1-1693913758389.png

Code used: 

/**

  * @brief  Enter LowPower Mode configuration

  * @param  None

  * @retval None

  */

void Enter_LowPower_Mode(void)

{

       uint8_t pinState =0;

 

       __HAL_RCC_PWR_CLK_ENABLE();

       HAL_PWREx_ConfigSRDDomain(PWR_SRD_DOMAIN_STOP);

       __HAL_RCC_AHB3_CLK_ENABLE();

       __HAL_RCC_APB3_CLK_ENABLE();

       __HAL_RCC_AHB2_1_CLK_ENABLE();

       __HAL_RCC_AHB2_2_CLK_ENABLE();

       __HAL_RCC_GPIOB_CLK_SLEEP_ENABLE();

  pinState = HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2);

  if(pinState)

    {

       EXTI->IMR1 = (1 << 6);

       EXTI->EMR1 = (1 << 6);

       EXTI->SWIER1 = (1 << 6);

    }

    HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);

}

/**

  * @brief  Exit LowPower Mode configuration

  * @param  None

  * @retval None

  */

void Exit_LowPower_Mode(void)

{

#if 1

  SystemClockRestore_Config();

  __HAL_RCC_PWR_CLK_ENABLE();

  __HAL_RCC_AHB1_CLK_ENABLE();

  __HAL_RCC_AHB2_1_CLK_ENABLE();

  __HAL_RCC_AHB2_2_CLK_ENABLE();

  HAL_UART_MspDeInit(&huart1);

  HAL_UART_MspInit(&huart1);

  __HAL_UART_DISABLE(&huart1);

  __HAL_UART_ENABLE(&huart1);

#endif

}

 

/**

  * @brief System Clock Configuration

  * @retval None

  */

void SystemClockRestore_Config(void)

{

  RCC_OscInitTypeDef RCC_OscInitStruct = {0};

  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 

  /** Configure the main internal regulator output voltage

  */

  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

  {

    Error_Handler();

  }

 

  /** Initializes the CPU, AHB and APB buses clocks

  */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI

                              |RCC_OSCILLATORTYPE_MSIK;

  RCC_OscInitStruct.HSIState = RCC_HSI_ON;

  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

  RCC_OscInitStruct.LSIState = RCC_LSI_ON;

  RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;

  RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV1;

  RCC_OscInitStruct.MSIKClockRange = RCC_MSIKRANGE_4;

  RCC_OscInitStruct.MSIKState = RCC_MSIK_ON;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

  RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;

  RCC_OscInitStruct.PLL.PLLM = 1;

  RCC_OscInitStruct.PLL.PLLN = 10;

  RCC_OscInitStruct.PLL.PLLP = 2;

  RCC_OscInitStruct.PLL.PLLQ = 2;

  RCC_OscInitStruct.PLL.PLLR = 1;

  RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;

  RCC_OscInitStruct.PLL.PLLFRACN = 0;

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

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;

 

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)

  {

    Error_Handler();

  }

 

  /** Enable the force of MSIK in stop mode

  */

  __HAL_RCC_MSIKSTOP_ENABLE();

}

 

3 REPLIES 3
Stassen.C
ST Employee

Hello Gautham19,

My first question is did you make sure that you still have your debug access available even in stop mode?

StassenC_0-1693915738317.png

Because if you read the RM you will see that if not configured correctly you lose access to your debug in STOP mode.

Regards,
Stassen

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.

Hi Stassen.C,

The DBGMCU->CR register is not set

Gautham19_0-1693919028600.png

Still I could able to Debug in stop 1 mode without any issue.

Stassen.C
ST Employee

Hi Gautham,

Did you do the test with the DBGMCU->CR set ?

Stassen

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.