本帖最后由 yinlb1987 于 2012-9-13 22:20 编辑
非常奇怪的问题,STM32 IAP之后,LCD显示 按键 AD等其它功能都正常,就是蜂鸣器不发声,蜂鸣器是靠TIMER1 产生PWM输出的,后来在main函数的死循环前初始化TIMER1之后 IAP 蜂鸣器也有声音了,奇怪的是TIMER1已经在前面初始化了,单独烧录是没有问题的,部分代码如下:
application
int main(void)
{
u8
test=0;
u8
tmp=0,i=0;
SysInit();
UserSetRead();
UserSetRead();
CalDataRead();
CalDataRead();
DebugCalData();
for(i=0;i<=PB;i++)
{
PgmSetRead(i,0);
}
Delayms(40);
menu.menu_layer=MAIN_LAYER;
bat_type=LIPO;
ni_pgm_index[0]=1;
ni_pgm_index[1]=1;
li_pgm_index[0]=1;
li_pgm_index[1]=1;
li_pgm_index[2]=1;
pb_pgm_index=1;
if((0x09)==GetKeyPin())
{
menu.menu_layer=PWRON_lAYER;
adc_para.is_calaribate_flag=1;
menu.lcd_in_cal_data=4200;
PgmSetDefault();
}
if(sys_para.temp_mode==0)
{
cut_off_temp_f=TempC2F(li_para[bat_type].cut_off_temp*10);
}
DEBUG_PRINTSTR("stm32 load\r\n");
UartSendStr("stm32 charger\r\n");
BeepTimerInit();//这句添加之后 IAP就正常了
SetBuzzer(BEEPER_TYPE_PWR_ON);
while(1)
{
}
}
void SysInit(void)
{
ControlPortInit();
LcdPortInit();
PWMPortInit();
PWMTimerInit();
BeepPortInit();
BeepTimerInit();
ADCPortInit();
I2CPortInit();
DMAInit();
ADC1Init();
LED_Init();
LcdInit();
Timer3Init();
UartInit();
BeepPortInit();
BeepTimerInit();
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0X3000);
NVICConfigure();
}
void BeepTimerInit(void)
{
TIM_TimeBaseInitTypeDef tim1={307,TIM_CounterMode_Up,39,TIM_CKD_DIV1,0};
TIM_OCInitTypeDef oc;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
TIM_DeInit(TIM1);
TIM_TimeBaseInit(TIM1,&tim1);
TIM_ClearITPendingBit(TIM1, TIM_FLAG_Update);
oc.TIM_OCMode = TIM_OCMode_PWM1;
oc.TIM_OutputState = TIM_OutputState_Enable;
oc.TIM_Pulse = 0;
oc.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM1,&oc);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
bootloader:
int main(void)
{
Uart1Init();
Timer4Init();
NVICConfigure();
FLASH_Unlock();
Delayms(50);
while(1)
{
if(timer4_over_flag==1)
//jump to app
{
if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
{
DisableAllNVIC();
JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
//
__set_PSP(*(volatile unsigned int*) ApplicationAddress);
//
__set_CONTROL(0);
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
Jump_To_Application();
}
}
}
}
bootloader 如果在开机的1s之内有接收到上位机的下载命令,开始下载(在UART中断中),否则进入APP
希望大家帮忙分析下是什么原因,谢谢! |