Skip to content

Commit 46537f4

Browse files
skotopesglitchcore
andauthored
FL-501 CSS for both clock domains (#264)
* CSS for both clock domains. Stale LSE detection and RTC domain reset on start. * migrate to f4 Co-authored-by: aanper <[email protected]>
1 parent df27d77 commit 46537f4

File tree

15 files changed

+114
-7
lines changed

15 files changed

+114
-7
lines changed

firmware/targets/f3/Inc/stm32wbxx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
#endif /* HSI48_VALUE */
153153

154154
#if !defined (LSE_STARTUP_TIMEOUT)
155-
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
155+
#define LSE_STARTUP_TIMEOUT 1000U /*!< Time out for LSE start up, in ms */
156156
#endif /* HSE_STARTUP_TIMEOUT */
157157

158158
/**

firmware/targets/f3/Inc/stm32wbxx_it.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void MemManage_Handler(void);
5353
void BusFault_Handler(void);
5454
void UsageFault_Handler(void);
5555
void DebugMon_Handler(void);
56+
void TAMP_STAMP_LSECSS_IRQHandler(void);
57+
void RCC_IRQHandler(void);
5658
void EXTI1_IRQHandler(void);
5759
void EXTI2_IRQHandler(void);
5860
void ADC1_IRQHandler(void);

firmware/targets/f3/Src/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void SystemClock_Config(void)
154154
/** Configure LSE Drive Capability
155155
*/
156156
HAL_PWR_EnableBkUpAccess();
157-
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
157+
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_MEDIUMLOW);
158158
/** Configure the main internal regulator output voltage
159159
*/
160160
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
@@ -220,7 +220,11 @@ void SystemClock_Config(void)
220220
Error_Handler();
221221
}
222222
/* USER CODE BEGIN Smps */
223-
223+
if (!LL_RCC_LSE_IsReady()) {
224+
LL_RCC_ForceBackupDomainReset();
225+
LL_RCC_ReleaseBackupDomainReset();
226+
NVIC_SystemReset();
227+
}
224228
/* USER CODE END Smps */
225229
/** Enables the Clock Security System
226230
*/

firmware/targets/f3/Src/rtc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
8686
/* RTC clock enable */
8787
__HAL_RCC_RTC_ENABLE();
8888
__HAL_RCC_RTCAPB_CLK_ENABLE();
89+
90+
/* RTC interrupt Init */
91+
HAL_NVIC_SetPriority(TAMP_STAMP_LSECSS_IRQn, 5, 0);
92+
HAL_NVIC_EnableIRQ(TAMP_STAMP_LSECSS_IRQn);
8993
/* USER CODE BEGIN RTC_MspInit 1 */
9094

9195
/* USER CODE END RTC_MspInit 1 */
@@ -103,6 +107,9 @@ void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
103107
/* Peripheral clock disable */
104108
__HAL_RCC_RTC_DISABLE();
105109
__HAL_RCC_RTCAPB_CLK_DISABLE();
110+
111+
/* RTC interrupt Deinit */
112+
HAL_NVIC_DisableIRQ(TAMP_STAMP_LSECSS_IRQn);
106113
/* USER CODE BEGIN RTC_MspDeInit 1 */
107114

108115
/* USER CODE END RTC_MspDeInit 1 */

firmware/targets/f3/Src/stm32wbxx_hal_msp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ void HAL_MspInit(void)
7474
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
7575

7676
/* Peripheral interrupt init */
77+
/* RCC_IRQn interrupt configuration */
78+
HAL_NVIC_SetPriority(RCC_IRQn, 5, 0);
79+
HAL_NVIC_EnableIRQ(RCC_IRQn);
7780
/* HSEM_IRQn interrupt configuration */
7881
HAL_NVIC_SetPriority(HSEM_IRQn, 5, 0);
7982
HAL_NVIC_EnableIRQ(HSEM_IRQn);

firmware/targets/f3/Src/stm32wbxx_it.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
extern PCD_HandleTypeDef hpcd_USB_FS;
6060
extern ADC_HandleTypeDef hadc1;
6161
extern COMP_HandleTypeDef hcomp1;
62+
extern RTC_HandleTypeDef hrtc;
6263
extern TIM_HandleTypeDef htim1;
6364
extern TIM_HandleTypeDef htim2;
6465
extern TIM_HandleTypeDef htim17;
@@ -166,6 +167,34 @@ void DebugMon_Handler(void)
166167
/* please refer to the startup file (startup_stm32wbxx.s). */
167168
/******************************************************************************/
168169

170+
/**
171+
* @brief This function handles RTC tamper and time stamp, CSS on LSE interrupts through EXTI line 18.
172+
*/
173+
void TAMP_STAMP_LSECSS_IRQHandler(void)
174+
{
175+
/* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 0 */
176+
HAL_RCC_CSSCallback();
177+
/* USER CODE END TAMP_STAMP_LSECSS_IRQn 0 */
178+
/* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 1 */
179+
180+
/* USER CODE END TAMP_STAMP_LSECSS_IRQn 1 */
181+
}
182+
183+
/**
184+
* @brief This function handles RCC global interrupt.
185+
*/
186+
void RCC_IRQHandler(void)
187+
{
188+
/* USER CODE BEGIN RCC_IRQn 0 */
189+
if (!LL_RCC_LSE_IsReady()) {
190+
HAL_RCC_CSSCallback();
191+
}
192+
/* USER CODE END RCC_IRQn 0 */
193+
/* USER CODE BEGIN RCC_IRQn 1 */
194+
195+
/* USER CODE END RCC_IRQn 1 */
196+
}
197+
169198
/**
170199
* @brief This function handles EXTI line1 interrupt.
171200
*/

firmware/targets/f3/api-hal/api-hal-power.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#include <api-hal-power.h>
2+
#include <main.h>
23
#include <bq27220.h>
34
#include <bq25896.h>
45

6+
void HAL_RCC_CSSCallback(void) {
7+
LL_RCC_ForceBackupDomainReset();
8+
LL_RCC_ReleaseBackupDomainReset();
9+
NVIC_SystemReset();
10+
}
11+
512
void api_hal_power_init() {
613
bq27220_init();
714
bq25896_init();

firmware/targets/f3/f3-1/Inc/stm32wbxx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
#endif /* HSI48_VALUE */
153153

154154
#if !defined (LSE_STARTUP_TIMEOUT)
155-
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
155+
#define LSE_STARTUP_TIMEOUT 1000U /*!< Time out for LSE start up, in ms */
156156
#endif /* HSE_STARTUP_TIMEOUT */
157157

158158
/**

firmware/targets/f3/f3-1/Inc/stm32wbxx_it.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void MemManage_Handler(void);
5353
void BusFault_Handler(void);
5454
void UsageFault_Handler(void);
5555
void DebugMon_Handler(void);
56+
void TAMP_STAMP_LSECSS_IRQHandler(void);
57+
void RCC_IRQHandler(void);
5658
void EXTI1_IRQHandler(void);
5759
void EXTI3_IRQHandler(void);
5860
void ADC1_IRQHandler(void);

firmware/targets/f3/f3-1/Src/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void SystemClock_Config(void)
154154
/** Configure LSE Drive Capability
155155
*/
156156
HAL_PWR_EnableBkUpAccess();
157-
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
157+
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_MEDIUMLOW);
158158
/** Configure the main internal regulator output voltage
159159
*/
160160
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
@@ -221,6 +221,12 @@ void SystemClock_Config(void)
221221
}
222222
/* USER CODE BEGIN Smps */
223223

224+
if (!LL_RCC_LSE_IsReady()) {
225+
LL_RCC_ForceBackupDomainReset();
226+
LL_RCC_ReleaseBackupDomainReset();
227+
NVIC_SystemReset();
228+
}
229+
224230
/* USER CODE END Smps */
225231
/** Enables the Clock Security System
226232
*/

0 commit comments

Comments
 (0)