@@ -62,20 +62,30 @@ void SystemClock_Config(void)
6262 }
6363
6464#ifdef USE_HSE
65- /*
66- using high speed external oscillator
67- */
68- LL_RCC_HSE_EnableBypass ();
69- LL_RCC_HSE_Enable ();
70- #if HSE_VALUE == 24000000
71- LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSE , LL_RCC_PLLM_DIV_3 , 20 , LL_RCC_PLLR_DIV_2 );
72- #elif HSE_VALUE == 16000000
73- LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSE , LL_RCC_PLLM_DIV_2 , 20 , LL_RCC_PLLR_DIV_2 );
74- #elif HSE_VALUE == 8000000
75- LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSE , LL_RCC_PLLM_DIV_1 , 20 , LL_RCC_PLLR_DIV_2 );
76- #else
77- #error "Unsupported HSE_VALUE"
78- #endif
65+ /*
66+ Using high-speed external source (HSE)
67+ - Default: Bypass mode (external oscillator)
68+ - Define USE_HSE_BYPASS to disable bypass (use crystal)
69+ */
70+ #if defined(USE_HSE_BYPASS ) && (USE_HSE_BYPASS == 0 )
71+ LL_RCC_HSE_DisableBypass (); // Use crystal mode
72+ #else
73+ LL_RCC_HSE_EnableBypass (); // Default: Use external oscillator
74+ #endif
75+ LL_RCC_HSE_Enable ();
76+
77+ // Wait for HSE to be ready
78+ while (LL_RCC_HSE_IsReady () != 1U ) {}
79+
80+ #if HSE_VALUE == 24000000
81+ LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSE , LL_RCC_PLLM_DIV_3 , 20 , LL_RCC_PLLR_DIV_2 );
82+ #elif HSE_VALUE == 16000000
83+ LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSE , LL_RCC_PLLM_DIV_2 , 20 , LL_RCC_PLLR_DIV_2 );
84+ #elif HSE_VALUE == 8000000
85+ LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSE , LL_RCC_PLLM_DIV_1 , 20 , LL_RCC_PLLR_DIV_2 );
86+ #else
87+ #error "Unsupported HSE_VALUE"
88+ #endif
7989
8090#elif defined(USE_LSE )
8191 /*
0 commit comments