Skip to content

Commit cb2a8c5

Browse files
committed
system(C0): update STM32C0xx system source file
Signed-off-by: Frederic Pillon <[email protected]>
1 parent f22cd54 commit cb2a8c5

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

system/STM32C0xx/system_stm32c0xx.c

+17-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
is no need to call the 2 first functions listed above, since SystemCoreClock
9494
variable is updated automatically.
9595
*/
96-
uint32_t SystemCoreClock = 48000000UL;
96+
uint32_t SystemCoreClock = 12000000UL;
9797

9898
const uint32_t AHBPrescTable[16UL] = {0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL, 6UL, 7UL, 8UL, 9UL};
9999
const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL};
@@ -171,26 +171,38 @@ void SystemCoreClockUpdate(void)
171171
{
172172
uint32_t tmp;
173173
uint32_t hsidiv;
174+
uint32_t sysdiv;
175+
#if defined(RCC_CR_SYSDIV)
176+
sysdiv = (uint32_t)(((RCC->CR & RCC_CR_SYSDIV) >> RCC_CR_SYSDIV_Pos) + 1U);
177+
#else
178+
sysdiv = 1U;
179+
#endif /* RCC_CR_SYSDIV */
174180

175181
/* Get SYSCLK source -------------------------------------------------------*/
176182
switch (RCC->CFGR & RCC_CFGR_SWS)
177183
{
178184
case RCC_CFGR_SWS_0: /* HSE used as system clock */
179-
SystemCoreClock = HSE_VALUE;
185+
SystemCoreClock = (HSE_VALUE / sysdiv);
186+
break;
187+
188+
#if defined(RCC_HSI48_SUPPORT)
189+
case RCC_CFGR_SW_1: /* HSI48 used as system clock */
190+
SystemCoreClock = (HSI48_VALUE / sysdiv);
180191
break;
192+
#endif /* RCC_HSI48_SUPPORT */
181193

182194
case (RCC_CFGR_SWS_1 | RCC_CFGR_SWS_0): /* LSI used as system clock */
183-
SystemCoreClock = LSI_VALUE;
195+
SystemCoreClock = (LSI_VALUE / sysdiv);
184196
break;
185197

186198
case RCC_CFGR_SWS_2: /* LSE used as system clock */
187-
SystemCoreClock = LSE_VALUE;
199+
SystemCoreClock = (LSE_VALUE / sysdiv);
188200
break;
189201

190202
case 0x00000000U: /* HSI used as system clock */
191203
default: /* HSI used as system clock */
192204
hsidiv = (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV))>> RCC_CR_HSIDIV_Pos));
193-
SystemCoreClock = (HSI_VALUE/hsidiv);
205+
SystemCoreClock = ((HSI_VALUE / sysdiv) / hsidiv);
194206
break;
195207
}
196208
/* Compute HCLK clock frequency --------------------------------------------*/

0 commit comments

Comments
 (0)