单片机/MCU论坛
直播中

吕钢格

7年用户 904经验值
私信 关注

MB9BF114R启动后程序一直跑在while中如何解决?

使用PDL2.0.2导入uart_printf的例程,在确认晶振起振的情况下,程序一直跑在SystemInit的while (!(FM_CRG->SCM_STR   (1UL << 1)));中,应该如何解决这个问题?

FM_CRG->BSC_PSR   = BSC_PSR_Val;                /* set System Clock presacaler */  FM_CRG->APBC0_PSR = APBC0_PSR_Val;              /* set APB0 presacaler */  FM_CRG->APBC1_PSR = APBC1_PSR_Val;              /* set APB1 presacaler */  FM_CRG->APBC2_PSR = APBC2_PSR_Val;              /* set APB2 presacaler */  FM_CRG->SWC_PSR   = SWC_PSR_Val | (1UL << 7);   /* set SW Watchdog presacaler */  FM_CRG->TTC_PSR   = TTC_PSR_Val;                /* set Trace Clock presacaler */  FM_CRG->CSW_TMR   = CSW_TMR_Val;                /* set oscillation stabilization wait time */    if (SCM_CTL_Val   (1UL << 1)) {                    /* Main clock oscillator enabled ? */    FM_CRG->SCM_CTL |= (1UL << 1);                /* enable main oscillator */     while (!(FM_CRG->SCM_STR   (1UL << 1)));      /* wait for Main clock oscillation stable */  }    if (SCM_CTL_Val   (1UL << 3)) {                    /* Sub clock oscillator enabled ? */    FM_CRG->SCM_CTL |= (1UL << 3);                /* enable sub oscillator */     while (!(FM_CRG->SCM_STR   (1UL << 3)));      /* wait for Sub clock oscillation stable */  }  FM_CRG->PSW_TMR   = PSW_TMR_Val;                /* set PLL stabilization wait time */  FM_CRG->PLL_CTL1  = PLL_CTL1_Val;               /* set PLLM and PLLK */  FM_CRG->PLL_CTL2  = PLL_CTL2_Val;               /* set PLLN          */    if (SCM_CTL_Val   (1UL << 4)) {                    /* PLL enabled ? */    if ((SCM_CTL_Val   (1ul << 1u)) == 0u)  // if main clock disable, use high-speed CR for PLL    {        FM_CRG->PSW_TMR_f.PINC = 1u;    }        FM_CRG->SCM_CTL  |= (1UL << 4);               /* enable PLL */     while (!(FM_CRG->SCM_STR   (1UL << 4)));      /* wait for PLL stable */  }


以下是system_fm3.h中宏的配置
#define CLOCK_SETUP           CLOCK_SETTING_CMSIS  // <<< Define clock setup macro here  #define __CLKMO               (8000000UL)          // <<< External   4MHz Crystal  #define __CLKSO               (32768UL)            // <<< External  32KHz Crystal  #define __CLKHC               (4000000UL)          // Internal   4MHz CR Oscillator  #define __CLKLC               (100000UL)           // Internal 100KHz CR Oscillator  #define SCM_CTL_Val           0x00000052           // <<< Define SCM_CTL here  #define BSC_PSR_Val           0x00000000           // <<< Define BSC_PSR here     #define APBC0_PSR_Val         0x00000001           // <<< Define APBC0_PSR here  #define APBC1_PSR_Val         0x00000082           // <<< Define APBC1_PSR here  #define APBC2_PSR_Val         0x00000082           // <<< Define APBC2_PSR here     #define SWC_PSR_Val           0x00000003           // <<< Define SWC_PSR here  #define TTC_PSR_Val           0x00000000           // <<< Define TTC_PSR here  #define CSW_TMR_Val           0x0000005C           // <<< Define CSW_TMR here  #define PSW_TMR_Val           0x00000000           // <<< Define PSW_TMR here  #define PLL_CTL1_Val          0x00000001           // <<< Define PLL_CTL1 here. Now K=1, M=2  #define PLL_CTL2_Val          0x00000011           // <<< Define PLL_CTL2 here. Now N=18  #define __PLLK         (((PLL_CTL1_Val >> 4)   0x0F) + 1)  #define __PLLN         (((PLL_CTL2_Val     )   0x3F) + 1)  #define __PLLM         (((PLL_CTL1_Val     )   0x0Ful) + 1ul)





                                                                                                                                                                                                                                                                                                                                                                                               

回帖(1)

张亮

2024-2-1 17:08:21
从您提供的代码片段来看,程序一直停在SystemInit函数的while循环中,等待FM_CRG寄存器中的SCM_STR位(第1位)设置为1。导致该问题的可能原因有:
1. FM_CRG寄存器的设置错误
2. 外部晶振没有正确启动
3. 硬件故障


要解决这个问题,请按照以下步骤进行排查:

1. 检查FM_CRG寄存器的设置是否正确。确保BSC_PSR寄存器和APBC0_PSR寄存器的值正确地被写入。您可以参考PDL的文档来确认正确的寄存器值。

2. 确保外部晶振电路正确连接并启动。检查晶振引脚的连接是否正确,确保电路中的晶振元件工作正常。您可以使用示波器或其他工具来检查晶振的振荡情况。

3. 检查硬件是否存在任何故障。检查电源和地线连接是否良好,检查其他外部组件是否正确连接和工作。

如果您已经确认了以上步骤,并且仍然遇到问题,您可以尝试以下方法:

1. 确保您使用的PDL版本与您的硬件兼容。有时,不正确的软件配置可能会导致系统无法启动。

2. 根据您的硬件平台,查找其他开发人员或技术支持,以获得更多的帮助和建议。

3. 尝试使用其他的调试方法,如打印调试信息到串口或使用调试器等。这样,您可以更详细地了解程序中的执行情况,以确定问题所在。


举报

更多回帖

发帖
×
20
完善资料,
赚取积分