中级会员
 
- 积分
- 361
- 金钱
- 361
- 注册时间
- 2014-1-20
- 在线时间
- 0 小时
|
5金钱
最近在用STM32F030C8这块芯片,SystemInit()给整到startup.s里面去了。库里面默认是HSI作为系统时钟,但是运用过程发现问题,所以做了改动,并且timer与RTC都能跑。
但是Systick工作不正常了(Systick 之前是由外部8M提供的,现在外部晶振拆掉了,由于做低功耗)。现在Systick怎么改由内部提供???
代码部分红色注释是原来的,这应该是库里面的一个错误,RCC_CR_HSEON明明是外部晶振。。。
static void SetSysClock(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
/* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/
/* Enable HSE */
RCC->CR |= ((uint32_t)RCC_CR_HSION); // RCC_CR_HSEON
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CR & RCC_CR_HSIRDY; // RCC_CR_HSERDY
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT)); //HSE_STARTUP_TIMEOUT
if ((RCC->CR & RCC_CR_HSIRDY) != RESET) // RCC_CR_HSERDY
{
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 = HSE * 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_HSI_DIV2 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL12); //RCC_CFGR_PLLSRC_PREDIV1 RCC_CFGR_PLLMULL6
/* Enable PLL */
RCC->CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */
while((RCC->CR & RCC_CR_PLLRDY) == 0) //0x02000000
{
}
/* Select PLL as system clock source */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); //0x11
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 */
}
}
|
最佳答案
查看完整内容[请看2#楼]
回复【3楼】xuande:
---------------------------------
选择内部HSI时钟作为系统时钟,但是固件库里面说明是HSI,但是SysInit() 选择RCC_CR_HSEON,所以改了。
8M二分频,12倍频达到48M。之前Systick没有作用是Systick时钟源没有选对,现在可以了。
|