aa911 发表于 2019-6-6 19:33

关于STM32F072启动的问题

本帖最后由 aa911 于 2019-6-6 19:41 编辑

由于所用的DEMO版需要,我把第7行改为第8行 ,程序一直在第10行到第14行的地方循环执行,MCU无法正常工作,请问各位问题出在哪?static void SetSysClock(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;

/* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/
/* Enable HSE */   
//RCC->CR |= ((uint32_t)RCC_CR_HSEON);
         RCC->CR &= ~((uint32_t)RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
    HSEStatus = RCC->CR & RCC_CR_HSERDY;
    StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));

if ((RCC->CR & RCC_CR_HSERDY) != RESET)
{
    HSEStatus = (uint32_t)0x01;
}
else
{
    HSEStatus = (uint32_t)0x00;
}

if (HSEStatus == (uint32_t)0x01)
{
    /* Enable Prefetch Buffer and set Flash Latency */
    FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY;

    /* HCLK = SYSCLK */
    RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
      
    /* PCLK = HCLK */
    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1;

    /* PLL configuration = HSI * 6 = 48 MHz */
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL6);
            
    /* Enable PLL */
    RCC->CR |= RCC_CR_PLLON;

    /* Wait till PLL is ready */
    while((RCC->CR & RCC_CR_PLLRDY) == 0)
    {
    }

    /* Select PLL as system clock source */
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
    RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;   

    /* Wait till PLL is used as system clock source */
    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
    {
    }
}
else
{ /* If HSE fails to start-up, the application will have wrong clock
         configuration. User can add here some code to deal with this error */
}
}

airwill 发表于 2019-6-7 22:27

这是在等待时钟就绪, 说明时钟电路有问题

aa911 发表于 2019-6-8 09:45

airwill 发表于 2019-6-7 22:27
这是在等待时钟就绪, 说明时钟电路有问题

使用的是内部时钟,没有外部时钟。

xufujun 发表于 2019-6-8 16:00

aa911 发表于 2019-6-8 09:45
使用的是内部时钟,没有外部时钟。

那就把这段代码注释掉,没有放晶振,HSE初始化肯定失败啊

aa911 发表于 2019-6-8 16:43

xufujun 发表于 2019-6-8 16:00
那就把这段代码注释掉,没有放晶振,HSE初始化肯定失败啊

已经解决,谢谢哈

xufujun 发表于 2019-6-9 14:17

aa911 发表于 2019-6-8 16:43
已经解决,谢谢哈

小事情,不客气
页: [1]
查看完整版本: 关于STM32F072启动的问题