我在CC430f5137上遇到一个MCU内核问题:
我们的产品需要在运行过程中动态地调节MCU主频,具体来说F_DCO频率会根据需要从10M调节至20M,或者20M降低至10M, (相应的MCLK会在5M和20M之间切换)。
现在发现有一批次CC5317的MCU在这个过程中有时会死掉。我检查了频率-内核电压的设置程序段,是完全按照CC5137的用户手册来的。
附代码片段:
//内核电压调节函数
static void pmm_level_set(uint8_t level)
{
// Open PMM registers for write
PMMCTL0_H = PMMPW_H;
// Set SVS/SVM high side new level
SVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level;
// Set SVM low side to new level
SVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level;
// Wait till SVM is settled
while ((PMMIFG & SVSMLDLYIFG) == 0);
// Clear already set flags
PMMIFG &= ~(SVMLVLRIFG + SVMLIFG);
// Set VCore to new level
PMMCTL0_L = PMMCOREV0 * level;
// Wait till new level reached
if ((PMMIFG & SVMLIFG))
while ((PMMIFG & SVMLVLRIFG) == 0);
// Set SVS/SVM low side to new level
SVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level;
// Lock PMM registers for write access
PMMCTL0_H = 0x00;
}
// 升频,DCO升至20M,MCLK升至20M.
static void high_speed_select(void)
{
while (current_pmm_level < 3) {
++current_pmm_level;
// Increase V_Core for high speed operation
// One level at a time.
pmm_level_set(current_pmm_level);
}
// Values in comment valid if the FLLREFCLK is at 32768 Hz.
UCSCTL1 = DCORSEL_6;// DCORSEL = 6: range [4.6, 88.0] MHz.
// DISMOD = 0 -> Modulation enabled.
UCSCTL2 = FLLD_3 // FLLD = 3 -> f_DCOCLK / 8,
+ 75; // FLLN = 75 -> / 75
// 32768 * 8 * 75 = 19660800 Hz. f_DCO ~ 20MHz.
UCSCTL5 = DIVM__1 // f_MCLK @ ~20 MHz
| DIVS__2; // f_SMCLK @ ~10 MHz
UCSCTL7 &= ~DCOFFG; // Clear DCO error flag
current_speed = SPEED_HIGH;
}
希望能得到帮助,谢谢!
灰小子:
你的电源电压没问题吧?随着主频的升高,mcu对供电电压的要求有个升高
HG:
在升主频之前,先调用函数把电压升上去。
降主频之后,再把电压降下来。
电压来回切换稍微等一段时间等稳定。