本帖最后由 nongfuxu 于 2021-4-25 03:27 编辑
hc32f460启动代码如下
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
这里
void SystemInit(void){
SystemCoreClockUpdate();
}
void SystemCoreClockUpdate(void) // Update SystemCoreClock variable
{
uint8_t tmp = 0u;
uint32_t plln = 19u, pllp = 1u, pllm = 0u, pllsource = 0u;
/* Select proper HRC_VALUE according to ICG1.HRCFREQSEL bit */
/* ICG1.HRCFREQSEL = '0' represent HRC_VALUE = 20000000UL */
/* ICG1.HRCFREQSEL = '1' represent HRC_VALUE = 16000000UL */
if (1UL == (HRC_FREQ_MON() & 1UL))
{
HRC_VALUE = HRC_16MHz_VALUE;
}
else
{
HRC_VALUE = HRC_20MHz_VALUE;
}
tmp = M4_SYSREG->CMU_CKSWR_f.CKSW;
switch (tmp)
{
case 0x00: /* use internal high speed RC */
SystemCoreClock = HRC_VALUE;
break;
case 0x01: /* use internal middle speed RC */
SystemCoreClock = MRC_VALUE;
break;
case 0x02: /* use internal low speed RC */
SystemCoreClock = LRC_VALUE;
break;
case 0x03: /* use external high speed OSC */
SystemCoreClock = XTAL_VALUE;
break;
case 0x04: /* use external low speed OSC */
SystemCoreClock = XTAL32_VALUE;
break;
case 0x05: /* use MPLL */
/* PLLCLK = ((pllsrc / pllm) * plln) / pllp */
pllsource = M4_SYSREG->CMU_PLLCFGR_f.PLLSRC;
plln = M4_SYSREG->CMU_PLLCFGR_f.MPLLN;
pllp = M4_SYSREG->CMU_PLLCFGR_f.MPLLP;
pllm = M4_SYSREG->CMU_PLLCFGR_f.MPLLM;
/* use exteranl high speed OSC as PLL source */
if (0ul == pllsource)
{
SystemCoreClock = (XTAL_VALUE) / (pllm + 1ul) * (plln + 1ul) / (pllp + 1ul);
}
/* use interanl high RC as PLL source */
else if (1ul == pllsource)
{
SystemCoreClock = (HRC_VALUE) / (pllm + 1ul) * (plln + 1ul) / (pllp + 1ul);
}
else
{
/* Reserved */
}
break;
}
}
以下几点难以理解,请教
1、HRC_FREQ_MON()
#define HRC_FREQ_MON() (*((volatile unsigned int*)(0x40010684UL)))
|
取0x40010684UL地址然后给这个地址赋值