目前使用的IC型号是KL26Z256,外部晶振使用的是8M。通过Procssor Expert software软件得到的启动代码如下。
/*** !!! Here you can place your own code before PE initialization using property "User code before PE initialization" on the build options tab. !!! ***/
/* Disable the WDOG module */
/* SIM_COPC: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,COPT=0,COPCLKS=0,COPW=0 */
SIM->COPC = (uint32_t)((0x00<<2)&0xc);//SIM_COPC_COPT(0x00);
/* System clock initialization */
/* SIM_CLKDIV1: OUTDIV1=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,OUTDIV4=3,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */
SIM->CLKDIV1 = (uint32_t)(((0x00<<28)&0XF0000000)|((0x03<<16)&0x70000)); ///(SIM_CLKDIV1_OUTDIV1(0x00) | SIM_CLKDIV1_OUTDIV4(0x03)); /* Set the system prescalers to safe value */
/* SIM_SCGC5: PORTA=1 */
SIM->SCGC5 |= 0x200;//SIM_SCGC5_PORTA_MASK; /* Enable clock gate for ports to enable pin routing */
if ((PMC->REGSC & 0x8) != 0x0U) {
/* PMC_REGSC: ACKISO=1 */
PMC->REGSC |= 0x8; /* Release IO pads after wakeup from VLLS mode. */
}
/* SIM_CLKDIV1: OUTDIV1=4,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,OUTDIV4=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */
SIM->CLKDIV1 = (uint32_t)(((0x04<<28)&0XF0000000)|((0x00<<16)&0x70000));//(SIM_CLKDIV1_OUTDIV1(0x04) | SIM_CLKDIV1_OUTDIV4(0x00)); /* Update system prescalers */
/* SIM_SOPT2: PLLFLLSEL=1 */
SIM->SOPT2 |= 0x10000;//SIM_SOPT2_PLLFLLSEL_MASK; /* Select PLL as a clock source for various peripherals */
/* SIM_SOPT1: OSC32KSEL=3 */
SIM->SOPT1 |= (uint32_t)((0x03<<18)&0xc0000);//SIM_SOPT1_OSC32KSEL(0x03); /* LPO 1kHz oscillator drives 32 kHz clock for various peripherals */
/* SIM_SOPT2: TPMSRC=1 */
SIM->SOPT2 = (uint32_t)((SIM->SOPT2 & (uint32_t)~(uint32_t)(
(0x02<<24)&0x3000000//SIM_SOPT2_TPMSRC(0x02)
)) | (uint32_t)(
(0x01<<24)&0x3000000//SIM_SOPT2_TPMSRC(0x01)
)); /* Set the TPM clock */
/* PORTA_PCR18: ISF=0,MUX=0 */
PORTA->PCR18 &= (uint32_t)~(uint32_t)(0x1000000 | ((0x07<<8)&0x700));
/* PORTA_PCR19: ISF=0,MUX=0 */
PORTA->PCR19 &= (uint32_t)~(uint32_t)(0x1000000 | ((0x07<<8)&0x700));
/* Switch to FBE Mode */
/* MCG_C2: LOCRE0=0,RANGE0=2,HGO0=0,EREFS0=1,LP=0,IRCS=0 */
MCG->C2 = (uint8_t)((MCG->C2 & (uint8_t)~(uint8_t)(
0x80 |
((0x01<<4)&0x30)| //MCG_C2_RANGE0(0x01) |
0x80 |
0x2 |
0x1
)) | (uint8_t)(
((0x02<<4)&0x30) |
0x4
));
/* OSC0_CR: ERCLKEN=1,??=0,EREFSTEN=0,??=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
OSC0->CR = 0x80;
/* MCG_C1: CLKS=2,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
MCG->C1 = ((uint8_t)((0x02<<6)&0xc0) | (uint8_t)((0x03<<3)&0x38) | 0x2);
/* MCG_C4: DMX32=0,DRST_DRS=0 */
MCG->C4 &= (uint8_t)~(uint8_t)((0x80 | ((0x03<<5)&0x60)));
/* MCG_C5: ??=0,PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=1 */
MCG->C5 = (0x01<<0)&0x1F;//MCG_C5_PRDIV0(0x01);
/* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV0=1 */
MCG->C6 = (0x01<<0)&0x1F;//MCG_C6_VDIV0(0x01);
while((MCG->S & 0x10) != 0x00U) { /* Check that the source of the FLL reference clock is the external reference clock. */
}
while((MCG->S & 0x0CU) != 0x08U) { /* Wait until external reference clock is selected as MCG output */
}
/* Switch to PBE Mode */
/* MCG_C6: LOLIE0=0,PLLS=1,CME0=0,VDIV0=1 */
MCG->C6 = (0x40 | ((0x01<<0)&0x1F));
while((MCG->S & 0x0CU) != 0x08U) { /* Wait until external reference clock is selected as MCG output */
}
while((MCG->S & 0x40) == 0x00U) { /* Wait until locked */
}
/* Switch to PEE Mode */
/* MCG_C1: CLKS=0,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
MCG->C1 = (((0x00<<6)&0xC0)| ((0x03<<3)&0x38) | 0x2);
while((MCG->S & 0x0CU) != 0x0CU) { /* Wait until output of the PLL is selected */
}
jlink调试过程,发现运行到
while((MCG->S & 0x0CU) != 0x08U) { /* Wait until external reference clock is selected as MCG output */
}
的时候出现了死等,MCG->S状态寄存器值为零,一直没有返回。我查看数据手册,参数设置的值应该没有问题。出现状态寄存器死等的原因会是什么呢?求解。 |