Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blue pill HSE 8 Mhz #1

Open
Miha22 opened this issue Sep 29, 2024 · 0 comments
Open

Blue pill HSE 8 Mhz #1

Miha22 opened this issue Sep 29, 2024 · 0 comments

Comments

@Miha22
Copy link

Miha22 commented Sep 29, 2024

If the f1 is blue pill (which is not recommended due to failure to correspond to documentation, but anyway..) then the method to set system clock to 72Mhz would be using PLL multiplier of 9.

void set_system_clock_to_72Mhz(void)
{
    // Configure Flash access latency for 72 MHz
    FLASH->ACR = 0x12;

    // Enable HSE (8 MHz external crystal)
    RCC->CR |= (1 << 16);  // HSEON: Enable HSE
    while (!(RCC->CR & (1 << 17)));  // Wait for HSE to become ready (HSERDY)

    // Set HSE as the PLL source
    RCC->CFGR |= (1 << 16);  // PLLSRC: HSE selected as PLL input

    // Set PLL multiplier to 9 (8 MHz * 9 = 72 MHz)
    RCC->CFGR |= (0b0111 << 18);  // PLLMUL: PLL multiplier of 9

    // Set APB1 prescaler to divide by 2 (to get 36 MHz for APB1)
    RCC->CFGR |= (1 << 10);  // PPRE1: APB1 low-speed prescaler set to 2 (36 MHz max)

    // Enable the PLL
    RCC->CR |= (1 << 24);  // PLLON: Enable the PLL
    while (!(RCC->CR & (1 << 25)));  // Wait for PLL to become ready (PLLRDY)

    // Set PLL as the system clock
    RCC->CFGR |= (0b10 << 0);  // SW: Set PLL as the system clock (SYSCLK)
}
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant