2024-01-19 06:22 AM
Hi,
using the code below, the device will not run when set to 250 MHz (PLL1DIVR = 99). It works fine at 200 MHz, and slightly above.
HSE is a 25 MHz crystal.
What am I missing?
static void SystemClockConfig(void)
{
// Must set Vcore to max before we can run at 250 MHz.
PWR->VOSCR = 0b11 << 4;
while ((PWR->VOSSR & BIT(3)) == 0)
;
// Enable HSE.
RCC->CR &= ~BIT(18); // HSE oscillator is not bypassed.
RCC->CR |= BIT(16); // HSE on.
// Wait for HSE stable.
while ((RCC->CR & BIT(17)) == 0)
;
// Setup PLL1
// Set prescaler clock source = HSE.
// Set input frequency range to 4-8 MHz.
// Set FRACEN = 0;
// Set VCOSEL = 0 (192 to 836 MHz)
// Set input prescaler to divide by 5 (25 MHz / 5 = 5 MHz). Allowed input range is 1 to 16 MHz.
// Enable output P.
RCC->PLL1CFGR = 0b00000000000000010000010100001011;
// Set SH_REG = 0 to operate in integer mode.
RCC->PLL1FRACR = 0;
// Fractional latch enable. 0->1 latches the content of FRACN1 into the modulator.
RCC->PLL1CFGR |= BIT(4);
// Set DIV to 80 (5 * 80 = 400 MHz). Set post-divider P = 1, equals / 2 which is minimum. This yields PLL1_P_CK = 200 MHz.
RCC->PLL1DIVR &= 0b11111111111111111111111000000000;
RCC->PLL1DIVR |= 79; // +1 is added to value.
// Enable PLL and wait for lock.
RCC->CR |= BIT(24);
while ((RCC->CR & BIT(25)) == 0)
;
// Set SYSCLK = PLL1.
RCC->CFGR1 = (RCC->CFGR1 & 0xFFFFFFFC) | 0b11;
}
Solved! Go to Solution.
2024-01-19 06:49 AM - edited 2024-01-19 06:50 AM
Not really looking to pick through your bare metal code.
I would suggest more effective ways of masking on data to registers, and watch particularly blind writes to registers, like VOS
Check with HAL examples, see if those work. Even if that's not what you want to use in the end, it establishes a situation others might care to look into or replicate.
For custom board check VCAP, and supplies in general
Watch wait states in FLASH
2024-01-19 06:49 AM - edited 2024-01-19 06:50 AM
Not really looking to pick through your bare metal code.
I would suggest more effective ways of masking on data to registers, and watch particularly blind writes to registers, like VOS
Check with HAL examples, see if those work. Even if that's not what you want to use in the end, it establishes a situation others might care to look into or replicate.
For custom board check VCAP, and supplies in general
Watch wait states in FLASH
2024-01-19 06:56 AM
Hello,
As stated by Tesla, start by using the HAL. If it does not reach the frequency, indeed, there is an issue otherwise you need to check your code and inspire from the HAL to access to the registers.
2024-01-19 07:36 AM
I agree with you that HAL might be useful for finding working examples, but the HAL code is terrible in terms of readability and ruins the understanding of the MCU by adding an intermediate layer. I want to master the MCU, not the HAL.
Anyway, increasing the flash wait state did the trick.
Thank you very much!
2024-01-21 12:41 AM