hellonsn 发表于 2018-1-9 08:30:53

Who can help check the clock configuration code for stm32f072-sicovery board.THS

void stm32f0_clockconfig(void)
{
uint32_t regval;

/*Verify if PLL is already setup.If so configure to use HSI mode */

if ((getreg32(STM32F0_RCC_CFGR) & RCC_CFGR_SWS_MASK) == RCC_CFGR_SWS_PLL)
    {
      /* Select HSI mode */

      regval= getreg32(STM32F0_RCC_CFGR);
      regval &= ~RCC_CFGR_SW_MASK;
      putreg32(regval, STM32F0_RCC_CFGR);

      while ((getreg32(STM32F0_RCC_CFGR) & RCC_CFGR_SWS_MASK) != RCC_CFGR_SWS_HSI);
    }

/* Disable the PLL */

regval= getreg32(STM32F0_RCC_CR);
regval &= ~RCC_CR_PLLON;
putreg32(regval, STM32F0_RCC_CR);
while ((getreg32(STM32F0_RCC_CR) & RCC_CR_PLLRDY) != 0);

/* Enable FLASH prefetch buffer and set flash latency */

regval = getreg32(STM32_FLASH_ACR);
regval &= ~FLASH_ACR_LATENCY_MASK;
regval |= (FLASH_ACR_LATENCY_1 | FLASH_ACR_PRTFBE);
putreg32(regval, STM32_FLASH_ACR);

/* Set HCLK = SYSCLK */

regval= getreg32(STM32F0_RCC_CFGR);
regval &= ~RCC_CFGR_HPRE_MASK;
regval |= RCC_CFGR_HPRE_SYSCLK;
putreg32(regval, STM32F0_RCC_CFGR);

/* Set PCLK = HCLK */

regval &= ~RCC_CFGR_PPRE1_MASK;
regval |= RCC_CFGR_PPRE1_HCLK;
putreg32(regval, STM32F0_RCC_CFGR);

/* Configure the PLL to generate the system clock
   *
   * 1. Use source = HSI/2
   * 2. Use PREDIV = 1
   * 3. Use multiplier from board.h
   */

regval &= ~(RCC_CFGR_PLLSRC_MASK | RCC_CFGR_PLLXTPRE_MASK | RCC_CFGR_PLLMUL_MASK);
regval |= (RCC_CFGR_PLLSRC_HSId2 | RCC_CFGR_PLLXTPRE_DIV1 | STM32F0_CFGR_PLLMUL);
putreg32(regval, STM32F0_RCC_CFGR);

/* Enable the PLL */

regval= getreg32(STM32F0_RCC_CR);
regval |= RCC_CR_PLLON;
putreg32(regval, STM32F0_RCC_CR);
while ((getreg32(STM32F0_RCC_CR) & RCC_CR_PLLRDY) == 0);

/* Configure to use the PLL */

regval= getreg32(STM32F0_RCC_CFGR);
regval |= RCC_CFGR_SW_PLL;
putreg32(regval, STM32F0_RCC_CFGR);
while ((getreg32(STM32F0_RCC_CFGR) & RCC_CFGR_SW_MASK) != RCC_CFGR_SW_PLL);

/* Enable basic peripheral support */
/* Enable all GPIO modules */

regval= getreg32(STM32F0_RCC_AHBENR);
regval |= RCC_AHBENR_IOPAEN | RCC_AHBENR_IOPAEN | RCC_AHBENR_IOPAEN |\
            RCC_AHBENR_IOPAEN | RCC_AHBENR_IOPAEN | RCC_AHBENR_IOPAEN;
putreg32(regval, STM32F0_RCC_AHBENR);
}

Could anyone give some suggestion for the clock configuration on stm32f072-discovery board ?




Dandjinh 发表于 2018-1-9 09:09:44

it's easy to build configuration using stm32cube which is visualized

Inc_brza 发表于 2018-1-9 09:20:40

Dandjinh 发表于 2018-1-9 09:09
it's easy to build configuration using stm32cube which is visualized

what is your question. your clock configuration code do not work? or u just want other guys check the code for u?

anywill 发表于 2018-1-9 09:30:34

本帖最后由 anywill 于 2018-1-9 14:01 编辑

use cubemx to easy to simple:Lit's a good chance to show my chinglish

哈佛祖安智 发表于 2018-1-9 11:23:18

ask PoZong for help.

ctang 发表于 2018-1-9 11:33:14

it's easy to fuck code.
页: [1]
查看完整版本: Who can help check the clock configuration code for stm32f072-sicovery board.THS