雅特力公司的MCU有著性能超群,價格優(yōu)越的巨大優(yōu)勢,缺點是相關(guān)資料少一些,我們可以充分利用ST的現(xiàn)有資源來開發(fā)它。
我用雅特力的STM32F437開發(fā)板,使用原子?stm32f407的開發(fā)板自帶程序,測試串口程序,原設(shè)定串口波特率為115200,但是輸出亂碼,波特率改成230400,串口輸出正常。
? ? ? ? ? ? 于是決心修改一下,時鐘配置。主要參考《STM32f4xx中文參考手冊.PDF》和RM_AT32F435-F437_CH_V2.03.pdf 。
主要問題出現(xiàn)在RCC PLL配置寄存器(RCC_PLLCFGR)
STM32F4XX的RCC PLL配置寄存器
?
?AT32F407RCC PLL配置寄存器
?
可以看到? ? PLL_P? ? 只能是4/8/16/32
#define PLL_P ? ? ?4 //定義為4
看到了他們的配置不同,下面開始修改代碼
(1)修改SystemInit()函數(shù)。
void SystemInit(void)
{
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
/* Reset the RCC clock configuration to the default reset state ------------*/
/* Set HSION bit */
RCC->CR |= (uint32_t)0x00000001;
/* Reset CFGR register */
RCC->CFGR = 0x00000000;
/* Reset HSEON, CSSON and PLLON bits */
RCC->CR &= (uint32_t)0xFEF6FFFF;
/* Reset PLLCFGR register */
//RCC->PLLCFGR = 0x24003010;
RCC->PLLCFGR = 0x00033002;//AT32F437
/* Reset HSEBYP bit */
RCC->CR &= (uint32_t)0xFFFBFFFF;
/* Disable all interrupts */
RCC->CIR = 0x00000000;
#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
SystemInit_ExtMemCtl();
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
/* Configure the System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings ----------------------------------*/
SetSysClock();
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}
修改配置寄存器初始值,防止硬件錯誤。
2.修改SetSysClock()中的配置代碼
//stm32f407 原代碼
/* Configure the main PLL */
RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
(RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24);
//修改成如下代碼
/* Configure the main PLL */
RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 2) +1) << 16) |
(RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24);
3.修改? RCC_GetClocksFreq()和void SystemCoreClockUpdate(void)函數(shù)
將原代碼:
pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) +1 ) *2;
改成如下代碼
pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) -1 )* 4;
4. 修改延時函數(shù),我目前的時鐘是336MHZ
? ?delay_init(336);?? ??? ?//延時初始化?
經(jīng)這樣修改,串口輸出和延時輸出正常工作。文章來源:http://www.zghlxwxcb.cn/news/detail-432037.html
可以看到還有PLLQ 是不一樣的,抽空處理一下,請大家期待下期!文章來源地址http://www.zghlxwxcb.cn/news/detail-432037.html
到了這里,關(guān)于從STM32F407到AT32F407(一)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!