小华HC32F460JETA无法进入主函数问题
使用HC32F460JETA这款芯片做了一个六步方波的电机驱动程序,程序写完之后进debug调试,单不运行发现启动文件运行完systeminit函数后进_main函数,无法正常执行程序,直接跳转到hard_fault。请教一下有没有遇到过相同问题的或者大神有想法的
一般这种情况是因为堆栈被冲掉了。 返回的pc被干掉了?跟踪调试一把,去掉运行到main,从汇编启动处开始运行。 while(1)
{
KEY = key_scan(0);
if (KEY == KEY2_PRES)
{
pwm_duty_temp += 500; //°´ÏÂkey2¼üÉèÖñȽÏֵΪ+500
if(pwm_duty_temp > 0) //ÅжÏÕý¸ººÅÉèÖÃÐýת·½Ïò
{
g_bldc_motor1.pwm_duty = pwm_duty_temp;
g_bldc_motor1.dir = CW; //˳ʱÕë Õýת
}
else
{
g_bldc_motor1.pwm_duty = -pwm_duty_temp;
g_bldc_motor1.dir = CCW;
}
g_bldc_motor1.run_flag = RUN;
start_motor();
}
else if(KEY == KEY3_PRES)
{
pwm_duty_temp -=500;
if(pwm_duty_temp <= -MAX_PWM_DUTY/2)
pwm_duty_temp = -MAX_PWM_DUTY/2;
if(pwm_duty_temp < 0)
{
g_bldc_motor1.pwm_duty = -pwm_duty_temp;
g_bldc_motor1.dir = CCW;
}
else
{
g_bldc_motor1.pwm_duty = pwm_duty_temp;
g_bldc_motor1.dir =CW;
}
g_bldc_motor1.run_flag = RUN;
start_motor();
}
else if((pwm_duty_temp > MAX_PWM_DUTY/2)&&(pwm_duty_temp < -MAX_PWM_DUTY/2)) //Èç¹ûÕ¼¿Õ±È´óÓÚ»òСÓÚÉ趨µÄÖµ£¬¾ÍÖ±½Ó¹Ø±Õµç»ú
{
stop_motor();
g_bldc_motor1.pwm_duty = 0;
g_bldc_motor1.run_flag = STOP;
pwm_duty_temp = 0;
}
Ddl_Delay1ms(10);
}
}
标红的代码注释掉之后就可以正常进主函数了,但是无法跳转到循环里面的按键扫描函数 估计是没有开启FPU吧 systeminit里面的内容有修改过吗?检查下晶振的频率,有没有可能是时钟配置超频了?
页:
[1]