RT~真是,昨天搞了一天的STLINK,终于能在线仿真了,但是我程序中的高级定时器设置函数会引起STLINK仿真失败,真是奇葩问题。论坛里的大侠有遇到过这个情况吗,TIM1设置函数如下,纠结,将这个函数在
主程序中的调用注释掉就能正常仿真了,不注释掉的话,单步调试执行完该函数后就跳出“内部命令错误”等调试异常信息。不注释掉的话,在全速仿真下,我看变量一次更新后没法再次更新就被迫退出调试模式。
void Tim1_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 9000-1; //8k //PWMƵÂÊΪ8K
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
//ÇåÖжÏ
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
//TIM1ÖжÏÔ´ÉèÖ㬿ªÆôÏàӦͨµÀµÄÏòÉÏÒç³öÖжÏ
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
/* Channel 3 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Êä³öÅäÖÃΪPWM2ģʽ
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //ʹÄÜÊä³ö±È½Ï״̬
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; //ʹÄÜ»¥²¹Êä³ö
TIM_OCInitStructure.TIM_Pulse = 2250; //Âö³å¿í¶È
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Set;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
/* Channel 2 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 2250;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Set;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
/* Channel 1 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 2250;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Set;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
/* Automatic Output enable, Break, dead time and lock configuration*/ //ËÀÇøÉèÖÃ
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM_BDTRInitStructure.TIM_DeadTime = 0xAC; //ÕâÀïµ÷ÕûËÀÇø´óС0-0xff ËÀÇø3US
//TIM_BDTRInitStructure.TIM_DeadTime = 0xCD; //5us
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable; //ɲ³µ£¬Ê§ÄÜ
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable); //¿ªÆôԤװÔØ
TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* Main Output Disnable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
} |