void platform_early_init(void) { /* set up clocking for a board with an external oscillator */ Chip_SetupXtalClocking(); /* Set USB PLL input to main oscillator */ Chip_Clock_SetUSBPLLSource(SYSCTL_PLLCLKSRC_MAINOSC); /* Setup USB PLL (FCLKIN = 12MHz) * 4 = 48MHz MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2) FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */ Chip_Clock_SetupUSBPLL(3, 1); /* Powerup USB PLL */ Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPLL_PD); /* Wait for PLL to lock */ while (!Chip_Clock_IsUSBPLLLocked()) {} /* Set default system tick divder to 1 */ Chip_Clock_SetSysTickClockDiv(1); /* start the generic systick driver */ arm_cm_systick_init(Chip_Clock_GetMainClockRate()); lpc_debug_early_init(); }
void sam_timer_early_init(void) { #if 0 pmc_enable_periph_clk(ID_TC0); uint32_t ul_div; uint32_t ul_tcclks; uint32_t ul_sysclk = MCLK; // sysclk_get_cpu_hz(); tc_find_mck_divisor(100, ul_sysclk, &ul_div, &ul_tcclks, ul_sysclk); tc_init(TC0, 0, TC_CMR_TCCLKS_TIMER_CLOCK1 | TC_CMR_CPCTRG); tc_write_rc(TC0, 0, (ul_sysclk / ul_div) / 4); tc_find_mck_divisor(100, ul_sysclk, &ul_div, &ul_tcclks, ul_sysclk); tc_init(TC0, 0, TC_CMR_TCCLKS_TIMER_CLOCK1 | TC_CMR_CPCTRG); tc_write_rc(TC0, 0, 0xffff); // slowest we can run /* Configure and enable interrupt on RC compare */ NVIC_SetPriority(ID_TC0, arm_cm_highest_priority()); NVIC_EnableIRQ((IRQn_Type) ID_TC0); tc_enable_interrupt(TC0, 0, TC_IER_CPCS); #endif tc_start(TC0, 0); arm_cm_systick_init(MCLK); }
void platform_early_init(void) { // Do general system init SystemInit(); SystemClock_Config(); // Enable the flash ART controller __HAL_FLASH_ART_ENABLE(); __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); /* read the unique id */ stm32_unique_id[0] = *REG32(0x1ff0f420); stm32_unique_id[1] = *REG32(0x1ff0f424); stm32_unique_id[2] = *REG32(0x1ff0f428); /* seed the random number generator based on this */ srand(stm32_unique_id[0] ^ stm32_unique_id[1] ^ stm32_unique_id[2]); // Start the systick timer uint32_t sysclk = HAL_RCC_GetSysClockFreq(); arm_cm_systick_init(sysclk); stm32_timer_early_init(); stm32_gpio_early_init(); stm32_flash_early_init(); stm32_rng_init(); /* clear the reboot reason */ RCC->CSR |= (1<<24); // ITM_SendChar('1'); }