Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_PowerProfile_Server_Router/Core/Src/stm32_lpm_if.c')
-rw-r--r--Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_PowerProfile_Server_Router/Core/Src/stm32_lpm_if.c200
1 files changed, 132 insertions, 68 deletions
diff --git a/Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_PowerProfile_Server_Router/Core/Src/stm32_lpm_if.c b/Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_PowerProfile_Server_Router/Core/Src/stm32_lpm_if.c
index 01d478092..fba978d88 100644
--- a/Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_PowerProfile_Server_Router/Core/Src/stm32_lpm_if.c
+++ b/Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_PowerProfile_Server_Router/Core/Src/stm32_lpm_if.c
@@ -6,7 +6,7 @@
***************************************************************************************
* @attention
*
- * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
+ * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
@@ -17,8 +17,8 @@
******************************************************************************
*/
/* USER CODE END Header */
-
-/* Includes ------------------------------------------------------------------*/
+
+/* Includes ------------------------------------------------------------------*/
#include "stm32_lpm_if.h"
#include "stm32_lpm.h"
#include "app_conf.h"
@@ -27,20 +27,22 @@
/* USER CODE END include */
/* Exported variables --------------------------------------------------------*/
-const struct UTIL_LPM_Driver_s UTIL_PowerDriver =
+const struct UTIL_LPM_Driver_s UTIL_PowerDriver =
{
PWR_EnterSleepMode,
PWR_ExitSleepMode,
-
+
PWR_EnterStopMode,
- PWR_ExitStopMode,
-
+ PWR_ExitStopMode,
+
PWR_EnterOffMode,
PWR_ExitOffMode,
};
/* Private function prototypes -----------------------------------------------*/
static void Switch_On_HSI( void );
+static void EnterLowPower( void );
+static void ExitLowPower( void );
/* USER CODE BEGIN Private_Function_Prototypes */
/* USER CODE END Private_Function_Prototypes */
@@ -69,14 +71,17 @@ static void Switch_On_HSI( void );
*/
void PWR_EnterOffMode( void )
{
-/* USER CODE BEGIN PWR_EnterOffMode */
+/* USER CODE BEGIN PWR_EnterOffMode_1 */
+/* USER CODE END PWR_EnterOffMode_1 */
/**
* The systick should be disabled for the same reason than when the device enters stop mode because
* at this time, the device may enter either OffMode or StopMode.
*/
HAL_SuspendTick();
+ EnterLowPower();
+
/************************************************************************************
* ENTER OFF MODE
***********************************************************************************/
@@ -100,8 +105,12 @@ void PWR_EnterOffMode( void )
__force_stores( );
#endif
- __WFI( );
-/* USER CODE END PWR_EnterOffMode */
+ __WFI();
+
+/* USER CODE BEGIN PWR_EnterOffMode_2 */
+
+/* USER CODE END PWR_EnterOffMode_2 */
+ return;
}
/**
@@ -111,11 +120,14 @@ void PWR_EnterOffMode( void )
*/
void PWR_ExitOffMode( void )
{
-/* USER CODE BEGIN PWR_ExitOffMode */
+/* USER CODE BEGIN PWR_ExitOffMode_1 */
+/* USER CODE END PWR_ExitOffMode_1 */
HAL_ResumeTick();
+/* USER CODE BEGIN PWR_ExitOffMode_2 */
-/* USER CODE END PWR_ExitOffMode */
+/* USER CODE END PWR_ExitOffMode_2 */
+ return;
}
/**
@@ -126,7 +138,9 @@ void PWR_ExitOffMode( void )
*/
void PWR_EnterStopMode( void )
{
-/* USER CODE BEGIN PWR_EnterStopMode */
+/* USER CODE BEGIN PWR_EnterStopMode_1 */
+
+/* USER CODE END PWR_EnterStopMode_1 */
/**
* When HAL_DBGMCU_EnableDBGStopMode() is called to keep the debugger active in Stop Mode,
* the systick shall be disabled otherwise the cpu may crash when moving out from stop mode
@@ -140,31 +154,7 @@ void PWR_EnterStopMode( void )
/**
* This function is called from CRITICAL SECTION
*/
- while( LL_HSEM_1StepLock( HSEM, CFG_HW_RCC_SEMID ) );
-
- if ( ! LL_HSEM_1StepLock( HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID ) )
- {
- if( LL_PWR_IsActiveFlag_C2DS( ) )
- {
- /* Release ENTRY_STOP_MODE semaphore */
- LL_HSEM_ReleaseLock( HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID, 0 );
-
- /**
- * The switch on HSI before entering Stop Mode is required
- */
- Switch_On_HSI( );
- }
- }
- else
- {
- /**
- * The switch on HSI before entering Stop Mode is required
- */
- Switch_On_HSI( );
- }
-
- /* Release RCC semaphore */
- LL_HSEM_ReleaseLock( HSEM, CFG_HW_RCC_SEMID, 0 );
+ EnterLowPower();
/************************************************************************************
* ENTER STOP MODE
@@ -181,7 +171,11 @@ void PWR_EnterStopMode( void )
#endif
__WFI();
-/* USER CODE END PWR_EnterStopMode */
+
+/* USER CODE BEGIN PWR_EnterStopMode_2 */
+
+/* USER CODE END PWR_EnterStopMode_2 */
+ return;
}
/**
@@ -192,37 +186,19 @@ void PWR_EnterStopMode( void )
*/
void PWR_ExitStopMode( void )
{
-/* USER CODE BEGIN PWR_ExitStopMode */
+/* USER CODE BEGIN PWR_ExitStopMode_1 */
+
+/* USER CODE END PWR_ExitStopMode_1 */
/**
* This function is called from CRITICAL SECTION
*/
-
- /* Release ENTRY_STOP_MODE semaphore */
- LL_HSEM_ReleaseLock( HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID, 0 );
-
- while( LL_HSEM_1StepLock( HSEM, CFG_HW_RCC_SEMID ) );
-
- if(LL_RCC_GetSysClkSource( ) == LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
- {
- LL_RCC_HSE_Enable( );
- while(!LL_RCC_HSE_IsReady( ));
- LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE);
- while (LL_RCC_GetSysClkSource( ) != LL_RCC_SYS_CLKSOURCE_STATUS_HSE);
- }
- else
- {
- /**
- * As long as the current application is fine with HSE as system clock source,
- * there is nothing to do here
- */
- }
-
- /* Release RCC semaphore */
- LL_HSEM_ReleaseLock( HSEM, CFG_HW_RCC_SEMID, 0 );
+ ExitLowPower();
HAL_ResumeTick();
+/* USER CODE BEGIN PWR_ExitStopMode_2 */
-/* USER CODE END PWR_ExitStopMode */
+/* USER CODE END PWR_ExitStopMode_2 */
+ return;
}
/**
@@ -233,7 +209,9 @@ void PWR_ExitStopMode( void )
*/
void PWR_EnterSleepMode( void )
{
-/* USER CODE BEGIN PWR_EnterSleepMode */
+/* USER CODE BEGIN PWR_EnterSleepMode_1 */
+
+/* USER CODE END PWR_EnterSleepMode_1 */
HAL_SuspendTick();
@@ -250,7 +228,10 @@ void PWR_EnterSleepMode( void )
#endif
__WFI( );
-/* USER CODE END PWR_EnterSleepMode */
+/* USER CODE BEGIN PWR_EnterSleepMode_2 */
+
+/* USER CODE END PWR_EnterSleepMode_2 */
+ return;
}
/**
@@ -261,11 +242,14 @@ void PWR_EnterSleepMode( void )
*/
void PWR_ExitSleepMode( void )
{
-/* USER CODE BEGIN PWR_ExitSleepMode */
+/* USER CODE BEGIN PWR_ExitSleepMode_1 */
+/* USER CODE END PWR_ExitSleepMode_1 */
HAL_ResumeTick();
+/* USER CODE BEGIN PWR_ExitSleepMode_2 */
-/* USER CODE END PWR_ExitSleepMode */
+/* USER CODE END PWR_ExitSleepMode_2 */
+ return;
}
/*************************************************************
@@ -274,6 +258,85 @@ void PWR_ExitSleepMode( void )
*
*************************************************************/
/**
+ * @brief Setup the system to enter either stop or off mode
+ * @param none
+ * @retval none
+ */
+static void EnterLowPower( void )
+{
+ /**
+ * This function is called from CRITICAL SECTION
+ */
+
+ while( LL_HSEM_1StepLock( HSEM, CFG_HW_RCC_SEMID ) );
+
+ if ( ! LL_HSEM_1StepLock( HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID ) )
+ {
+ if( LL_PWR_IsActiveFlag_C2DS() || LL_PWR_IsActiveFlag_C2SB() )
+ {
+ /* Release ENTRY_STOP_MODE semaphore */
+ LL_HSEM_ReleaseLock( HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID, 0 );
+
+ /**
+ * The switch on HSI before entering Stop Mode is required on Cut2.0
+ * It is useless from Cut2.1
+ */
+ Switch_On_HSI( );
+ }
+ }
+ else
+ {
+ /**
+ * The switch on HSI before entering Stop Mode is required on Cut2.0
+ * It is useless from Cut2.1
+ */
+ Switch_On_HSI( );
+ }
+
+ /* Release RCC semaphore */
+ LL_HSEM_ReleaseLock( HSEM, CFG_HW_RCC_SEMID, 0 );
+
+ return;
+}
+
+/**
+ * @brief Restore the system to exit stop mode
+ * @param none
+ * @retval none
+ */
+static void ExitLowPower( void )
+{
+ /* Release ENTRY_STOP_MODE semaphore */
+ LL_HSEM_ReleaseLock( HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID, 0 );
+
+ while( LL_HSEM_1StepLock( HSEM, CFG_HW_RCC_SEMID ) );
+
+ if(LL_RCC_GetSysClkSource( ) == LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
+ {
+/* Restore the clock configuration of the application in this user section */
+/* USER CODE BEGIN ExitLowPower_1 */
+ LL_RCC_HSE_Enable( );
+ __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_1);
+ while(!LL_RCC_HSE_IsReady( ));
+ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE);
+ while (LL_RCC_GetSysClkSource( ) != LL_RCC_SYS_CLKSOURCE_STATUS_HSE);
+/* USER CODE END ExitLowPower_1 */
+ }
+ else
+ {
+/* If the application is not running on HSE restore the clock configuration in this user section */
+/* USER CODE BEGIN ExitLowPower_2 */
+
+/* USER CODE END ExitLowPower_2 */
+ }
+
+ /* Release RCC semaphore */
+ LL_HSEM_ReleaseLock( HSEM, CFG_HW_RCC_SEMID, 0 );
+
+ return;
+}
+
+/**
* @brief Switch the system clock on HSI
* @param none
* @retval none
@@ -285,6 +348,7 @@ static void Switch_On_HSI( void )
LL_RCC_SetSysClkSource( LL_RCC_SYS_CLKSOURCE_HSI );
LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSI);
while (LL_RCC_GetSysClkSource( ) != LL_RCC_SYS_CLKSOURCE_STATUS_HSI);
+ return;
}
/* USER CODE BEGIN Private_Functions */