Skip to content

Commit

Permalink
platform/prime_hub: fix missing PLLR init
Browse files Browse the repository at this point in the history
This fixes missing init values in the osc clock init. This was found
in b094823 which broke dual boot due to zero initializing `osc_init`.

Since we are initializing all values, we don't need to zero initialize.

Partially reverts commit 463c9e9.
  • Loading branch information
dlech committed Feb 2, 2021
1 parent 935f7f3 commit 8e54d30
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/pbio/platform/prime_hub/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,23 +698,33 @@ extern uint32_t *_fw_isr_vector_src;

// Called from assembly code in startup.s
void SystemInit(void) {
// enable 8-byte stack alignment for IRQ handlers, in accord with EABI
SCB->CCR |= SCB_CCR_STKALIGN_Msk;

RCC_OscInitTypeDef osc_init;
RCC_ClkInitTypeDef clk_init;
// since the firmware starts at 0x08008000, we need to set the vector table offset
SCB->VTOR = (uint32_t)&_fw_isr_vector_src;

// bootloader disables interrupts
__enable_irq();

// Using external 16Mhz oscillator
RCC_OscInitTypeDef osc_init;
osc_init.OscillatorType = RCC_OSCILLATORTYPE_HSE;
osc_init.HSEState = RCC_HSE_ON;
osc_init.LSEState = RCC_LSE_OFF;
osc_init.HSIState = RCC_HSI_OFF;
osc_init.LSIState = RCC_LSI_OFF;
osc_init.PLL.PLLState = RCC_PLL_ON;
osc_init.PLL.PLLSource = RCC_PLLSOURCE_HSE;
osc_init.PLL.PLLM = 8; // VCO_IN 2MHz (16MHz / 8)
osc_init.PLL.PLLN = 96; // VCO_OUT 192MHz (2MHz * 96)
osc_init.PLL.PLLP = RCC_PLLP_DIV2; // PLLCLK 96MHz (not using max of 100 because of USB)
osc_init.PLL.PLLQ = 4; // 48MHz USB clock
osc_init.PLL.PLLR = 2; // 96MHz system clock

HAL_RCC_OscConfig(&osc_init);

RCC_ClkInitTypeDef clk_init;
clk_init.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
clk_init.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
clk_init.AHBCLKDivider = RCC_SYSCLK_DIV1; // HCLK 96MHz
Expand All @@ -723,15 +733,6 @@ void SystemInit(void) {

HAL_RCC_ClockConfig(&clk_init, FLASH_LATENCY_5);

// enable 8-byte stack alignment for IRQ handlers, in accord with EABI
SCB->CCR |= SCB_CCR_STKALIGN_Msk;

// since the firmware starts at 0x08008000, we need to set the vector table offset
SCB->VTOR = (uint32_t)&_fw_isr_vector_src;

// bootloader disables interrupts
__enable_irq();

// If we are running dual boot, jump to other firmware if no buttons are pressed
pbio_platform_dual_boot();

Expand Down

0 comments on commit 8e54d30

Please sign in to comment.