Exemple #1
0
void rcc_clock_setup_hsi(const clock_scale_t *clock)
{
	/* Enable internal high-speed oscillator. */
	rcc_osc_on(HSI);
	rcc_wait_for_osc_ready(HSI);
	/* Select HSI as SYSCLK source. */
	rcc_set_sysclk_source(RCC_CFGR_SW_HSI); /* XXX: se cayo */
	rcc_wait_for_sysclk_status(HSI);

	rcc_osc_off(PLL);
	rcc_wait_for_osc_not_ready(PLL);
	rcc_set_pll_source(clock->pllsrc);
	rcc_set_main_pll_hsi(clock->pll);
	/* Enable PLL oscillator and wait for it to stabilize. */
	rcc_osc_on(PLL);
	rcc_wait_for_osc_ready(PLL);
	/*
	 * Set prescalers for AHB, ADC, ABP1, ABP2.
	 * Do this before touching the PLL (TODO: why?).
	 */
	rcc_set_hpre(clock->hpre);
	rcc_set_ppre2(clock->ppre2);
	rcc_set_ppre1(clock->ppre1);
	/* Configure flash settings. */
	flash_set_ws(clock->flash_config);
	/* Select PLL as SYSCLK source. */
	rcc_set_sysclk_source(RCC_CFGR_SW_PLL); /* XXX: se cayo */
	/* Wait for PLL clock to be selected. */
	rcc_wait_for_sysclk_status(PLL);

	/* Set the peripheral clock frequencies used. */
	rcc_ppre1_frequency = clock->apb1_frequency;
	rcc_ppre2_frequency = clock->apb2_frequency;
}
Exemple #2
0
void rcc_clock_setup_hsi_3v3(const clock_scale_t *clock)
{
	/* Enable internal high-speed oscillator. */
	rcc_osc_on(HSI);
	rcc_wait_for_osc_ready(HSI);

	/* Select HSI as SYSCLK source. */
	rcc_set_sysclk_source(RCC_CFGR_SW_HSI);

//	/* Enable/disable high performance mode */
//	if (!clock->power_save) {
//		pwr_set_vos_scale(SCALE1);
//	} else {
//		pwr_set_vos_scale(SCALE2);
//	}

	/*
	 * Set prescalers for AHB, ADC, ABP1, ABP2.
	 * Do this before touching the PLL (TODO: why?).
	 */
	rcc_set_hpre(clock->hpre);
	rcc_set_ppre1(clock->ppre1);
	rcc_set_ppre2(clock->ppre2);

	rcc_set_main_pll_hsi(clock->pllm, clock->plln,
			clock->pllp, clock->pllq);

	/* Enable PLL oscillator and wait for it to stabilize. */
	rcc_osc_on(PLL);
	rcc_wait_for_osc_ready(PLL);

	/* Configure flash settings. */
	flash_set_ws(clock->flash_config);

	/* Select PLL as SYSCLK source. */
	rcc_set_sysclk_source(RCC_CFGR_SW_PLL);

	/* Wait for PLL clock to be selected. */
	rcc_wait_for_sysclk_status(PLL);

	/* Set the peripheral clock frequencies used. */
	rcc_apb1_frequency = clock->apb1_frequency;
	rcc_apb2_frequency = clock->apb2_frequency;

	/* Disable internal high-speed oscillator. */
	//rcc_osc_off(HSI);
}
Exemple #3
0
void clock_setup()
{
	/*
	RCC_CR |= (uint32_t)0x00000001;
	RCC_CFGR = 0x00000000;
	RCC_CR &= (uint32_t)0xFEF6FFFF;
	RCC_PLLCFGR = 0x24003010;
	RCC_CR &= (uint32_t)0xFFFBFFFF;
	RCC_CIR = 0x00000000;
	SCB_VTOR = 0x08000000;
	*/
    /*
    	.pllm = 16,
    	.plln = 336,
    	.pllp = 2,
    	.pllq = 7,
    	.hpre = RCC_CFGR_HPRE_DIV_NONE,
    	.ppre1 = RCC_CFGR_PPRE_DIV_4,
    	.ppre2 = RCC_CFGR_PPRE_DIV_2,
    	.flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE |
    			FLASH_ACR_LATENCY_5WS,
    	.apb1_frequency = 42000000,
    	.apb2_frequency = 84000000,
    */

    /* Enable internal high-speed oscillator. */
    rcc_osc_on(RCC_HSI);
    rcc_wait_for_osc_ready(RCC_HSI);

    /* Select HSI as SYSCLK source. */
    rcc_set_sysclk_source(RCC_CFGR_SW_HSI);

    pwr_set_vos_scale(PWR_SCALE1);

    rcc_set_main_pll_hsi(16, 336, 2, 8, 0);

    /* Enable PLL oscillator and wait for it to stabilize. */
    rcc_osc_on(RCC_PLL);
    rcc_wait_for_osc_ready(RCC_PLL);

    /* Configure flash settings. */
    flash_set_ws(FLASH_ACR_ICE | FLASH_ACR_DCE |
                 FLASH_ACR_LATENCY_5WS);

    /* Select PLL as SYSCLK source. */
    rcc_set_sysclk_source(RCC_CFGR_SW_PLL);

    rcc_set_hpre(RCC_CFGR_HPRE_DIV_NONE);
    rcc_set_ppre1(RCC_CFGR_PPRE_DIV_4);
    rcc_set_ppre2(RCC_CFGR_PPRE_DIV_2);

    /* Wait for PLL clock to be selected. */
    rcc_wait_for_sysclk_status(RCC_PLL);

    rcc_ahb_frequency = 168000000;
    rcc_apb1_frequency = 42000000;
    rcc_apb2_frequency = 84000000;

    /* Disable internal high-speed oscillator. */
    rcc_osc_off(RCC_HSI);

    // clock rate is 1680 to get 10uS interrupt rate
    systick_set_reload(168);
    systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
    systick_counter_enable();

    systick_interrupt_enable();

    rcc_periph_clock_enable(RCC_GPIOA);
    rcc_periph_clock_enable(RCC_GPIOB);
    rcc_periph_clock_enable(RCC_GPIOC);

    etk::set_tick_rate(1);
}