mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-11-24 11:14:26 +03:00
[FL-635] Enable LSE CSS (#371)
* LSE CSS: explicitly configure and start LSE + LSI1 and enable LSECSS at boot, enable LSECSS interrupt in firmware. * F4: backport LSE CSS shenanigans. * Split LSE/HSE CSS handling routines, add TODO for missing notification.
This commit is contained in:
parent
73e5379520
commit
9df4d8e2ed
@ -31,6 +31,8 @@
|
||||
#define BOOT_USB_DP_PIN LL_GPIO_PIN_12
|
||||
#define BOOT_USB_PIN (BOOT_USB_DM_PIN | BOOT_USB_DP_PIN)
|
||||
|
||||
#define RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady())
|
||||
|
||||
void target_led_control(char* c) {
|
||||
LL_GPIO_SetOutputPin(LED_RED_PORT, LED_RED_PIN);
|
||||
LL_GPIO_SetOutputPin(LED_GREEN_PORT, LED_GREEN_PIN);
|
||||
@ -98,17 +100,19 @@ void gpio_init() {
|
||||
void rtc_init() {
|
||||
// LSE and RTC
|
||||
LL_PWR_EnableBkUpAccess();
|
||||
if(!LL_RCC_LSE_IsReady()) {
|
||||
if(!RTC_CLOCK_IS_READY()) {
|
||||
// Start LSI1 needed for CSS
|
||||
LL_RCC_LSI1_Enable();
|
||||
// Try to start LSE normal way
|
||||
LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_MEDIUMLOW);
|
||||
LL_RCC_LSE_Enable();
|
||||
uint32_t c = 0;
|
||||
while(!LL_RCC_LSE_IsReady() && c < 200) {
|
||||
while(!RTC_CLOCK_IS_READY() && c < 200) {
|
||||
LL_mDelay(10);
|
||||
c++;
|
||||
}
|
||||
// Plan B: reset backup domain
|
||||
if(!LL_RCC_LSE_IsReady()) {
|
||||
if(!RTC_CLOCK_IS_READY()) {
|
||||
target_led_control("-R.R.R.");
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
LL_RCC_ReleaseBackupDomainReset();
|
||||
@ -116,6 +120,8 @@ void rtc_init() {
|
||||
}
|
||||
// Set RTC domain clock to LSE
|
||||
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
|
||||
// Enable LSE CSS
|
||||
LL_RCC_LSE_EnableCSS();
|
||||
}
|
||||
// Enable clocking
|
||||
LL_RCC_EnableRTC();
|
||||
|
@ -23,6 +23,8 @@
|
||||
#define BOOT_USB_DP_PIN LL_GPIO_PIN_12
|
||||
#define BOOT_USB_PIN (BOOT_USB_DM_PIN | BOOT_USB_DP_PIN)
|
||||
|
||||
#define RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady())
|
||||
|
||||
void target_led_control(char* c) {
|
||||
api_hal_light_set(LightRed, 0x00);
|
||||
api_hal_light_set(LightGreen, 0x00);
|
||||
@ -80,17 +82,19 @@ void gpio_init() {
|
||||
void rtc_init() {
|
||||
// LSE and RTC
|
||||
LL_PWR_EnableBkUpAccess();
|
||||
if(!LL_RCC_LSE_IsReady()) {
|
||||
if(!RTC_CLOCK_IS_READY()) {
|
||||
// Start LSI1 needed for CSS
|
||||
LL_RCC_LSI1_Enable();
|
||||
// Try to start LSE normal way
|
||||
LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_MEDIUMLOW);
|
||||
LL_RCC_LSE_Enable();
|
||||
uint32_t c = 0;
|
||||
while(!LL_RCC_LSE_IsReady() && c < 200) {
|
||||
while(!RTC_CLOCK_IS_READY() && c < 200) {
|
||||
LL_mDelay(10);
|
||||
c++;
|
||||
}
|
||||
// Plan B: reset backup domain
|
||||
if(!LL_RCC_LSE_IsReady()) {
|
||||
if(!RTC_CLOCK_IS_READY()) {
|
||||
target_led_control("-R.R.R.");
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
LL_RCC_ReleaseBackupDomainReset();
|
||||
@ -98,6 +102,8 @@ void rtc_init() {
|
||||
}
|
||||
// Set RTC domain clock to LSE
|
||||
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
|
||||
// Enable LSE CSS
|
||||
LL_RCC_LSE_EnableCSS();
|
||||
}
|
||||
// Enable clocking
|
||||
LL_RCC_EnableRTC();
|
||||
|
@ -73,10 +73,11 @@ void SystemClock_Config(void)
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE
|
||||
|RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
| RCC_OSCILLATORTYPE_LSI1 | RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
@ -126,9 +127,11 @@ void SystemClock_Config(void)
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
// Enable CSS for both clocks
|
||||
// CSS for HSE
|
||||
HAL_RCC_EnableCSS();
|
||||
// CSS for LSE
|
||||
HAL_RCCEx_EnableLSECSS();
|
||||
HAL_RCCEx_EnableLSECSS_IT();
|
||||
}
|
||||
|
||||
void Error_Handler(void) {
|
||||
|
@ -188,12 +188,12 @@ void SysTick_Handler(void)
|
||||
*/
|
||||
void TAMP_STAMP_LSECSS_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 0 */
|
||||
HAL_RCC_CSSCallback();
|
||||
/* USER CODE END TAMP_STAMP_LSECSS_IRQn 0 */
|
||||
/* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 1 */
|
||||
|
||||
/* USER CODE END TAMP_STAMP_LSECSS_IRQn 1 */
|
||||
if (!LL_RCC_LSE_IsReady()) {
|
||||
// TODO: notify user about issue with LSE
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
LL_RCC_ReleaseBackupDomainReset();
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,9 +202,6 @@ void TAMP_STAMP_LSECSS_IRQHandler(void)
|
||||
void RCC_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN RCC_IRQn 0 */
|
||||
if (!LL_RCC_LSE_IsReady()) {
|
||||
HAL_RCC_CSSCallback();
|
||||
}
|
||||
/* USER CODE END RCC_IRQn 0 */
|
||||
/* USER CODE BEGIN RCC_IRQn 1 */
|
||||
|
||||
|
@ -15,8 +15,7 @@
|
||||
volatile uint32_t api_hal_power_insomnia = 1;
|
||||
|
||||
void HAL_RCC_CSSCallback(void) {
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
LL_RCC_ReleaseBackupDomainReset();
|
||||
// TODO: notify user about issue with HSE
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
|
@ -74,10 +74,11 @@ void SystemClock_Config(void)
|
||||
LL_RCC_HSE_SetCapacitorTuning(0x18);
|
||||
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE
|
||||
|RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
| RCC_OSCILLATORTYPE_LSI1 | RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
@ -127,9 +128,11 @@ void SystemClock_Config(void)
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
// Enable CSS for both clocks
|
||||
// CSS for HSE
|
||||
HAL_RCC_EnableCSS();
|
||||
// CSS for LSE
|
||||
HAL_RCCEx_EnableLSECSS();
|
||||
HAL_RCCEx_EnableLSECSS_IT();
|
||||
}
|
||||
|
||||
void Error_Handler(void) {
|
||||
|
@ -188,12 +188,12 @@ void SysTick_Handler(void)
|
||||
*/
|
||||
void TAMP_STAMP_LSECSS_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 0 */
|
||||
HAL_RCC_CSSCallback();
|
||||
/* USER CODE END TAMP_STAMP_LSECSS_IRQn 0 */
|
||||
/* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 1 */
|
||||
|
||||
/* USER CODE END TAMP_STAMP_LSECSS_IRQn 1 */
|
||||
if (!LL_RCC_LSE_IsReady()) {
|
||||
// TODO: notify user about issue with LSE
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
LL_RCC_ReleaseBackupDomainReset();
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,9 +202,6 @@ void TAMP_STAMP_LSECSS_IRQHandler(void)
|
||||
void RCC_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN RCC_IRQn 0 */
|
||||
if (!LL_RCC_LSE_IsReady()) {
|
||||
HAL_RCC_CSSCallback();
|
||||
}
|
||||
/* USER CODE END RCC_IRQn 0 */
|
||||
/* USER CODE BEGIN RCC_IRQn 1 */
|
||||
|
||||
|
@ -15,8 +15,7 @@
|
||||
volatile uint32_t api_hal_power_insomnia = 1;
|
||||
|
||||
void HAL_RCC_CSSCallback(void) {
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
LL_RCC_ReleaseBackupDomainReset();
|
||||
// TODO: notify user about issue with HSE
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user