本帖最后由 jiang633 于 2016-12-27 15:27 编辑
请问原子哥和各位大神,我的SD卡升级程序是用网上分享的代码修改的,BOOT是可以正常升级原子哥的代码的,现在出现我的APP单独烧进板子是可以正常运行的,如果是通过BOOT程序升级APP进入板子运行之后,就会出现无法执行APP里面定时器的中断处理函数,单独烧APP进去是没有这个现象的,APP运行过程中其他外设还是可以正常运行的,就是需要定时器的地方没法应,小弟一直找不到问题出现在那里,希望大神们帮忙解决一下
附上相关代码,主要是在BOOT里面运行APP无法运行到如下红 {MOD}字体的代码里面
BOOT的主代码
int main(void)
{
u32 sd_size;
u32 APP_Sector = 0;
u16 APP_Byte = 0;
u8 i;
u16 j;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2
delay_init(); //延时函数初始化
uart_init(19200); //串口初始化为9600
LED_Init(); //LED初始化
usmart_dev.init(72); //usmart初始化
mem_init(); //初始化内存池
exfuns_init(); //为fatfs相关变量申请内存
f_mount(fs[0],"0:",1); //挂载SD卡
while(1)
{
while(SD_Initialize()) //检测SD卡
{
for(i=0;i<5;i++)
{
printf("SD error
");
delay_ms(200);
}
break;
}
rest = f_open(&fdst,"0:/SD.bin",FA_OPEN_EXISTING|FA_READ); //打开或者创建文件
if ( rest == FR_OK ) //成功打开文件
{
/* 将缓冲区的数据写到文件中 */ //0:/STM32-DEMO.BIN
APP_Sector = fdst.fsize / 512;
APP_Byte = fdst.fsize % 512;
sd_size=SD_GetSectorCount();//得到扇区数
printf("APP_Sector = %d
",APP_Sector);
printf(" APP_Byte = %d
", APP_Byte);
printf(" sd_size = %d
", sd_size);
for(i = 0;i < APP_Sector;i++)
{
f_read (&fdst,ReadAppBuffer,512,(UINT *)&bw); //读SD卡内容
printf("ReadAppBuffer = %s
",ReadAppBuffer);
for(j = 0;j < 256;j++)
{
ChangeBuffer[j] = (ReadAppBuffer[j * 2 + 1] << 8) + ReadAppBuffer[j * 2];
}
STMFLASH_Write(FLASH_APP_ADDR + i * 512,ChangeBuffer,256); //将ChangeBuffer写进 flash 的 FLASH_APP_ADDR
printf("STMFLASH_Write = %d
",(FLASH_APP_ADDR + i * 512));
}
if(APP_Byte != 0)
{
f_read (&fdst,ReadAppBuffer,APP_Byte,(UINT *)&bw);
for(j = 0;j < (APP_Byte / 2);j++)
{
ChangeBuffer[j] = (ReadAppBuffer[j * 2 + 1] << 8) + ReadAppBuffer[j * 2];
}
STMFLASH_Write(FLASH_APP_ADDR + i * 512,ChangeBuffer,APP_Byte / 2);
}
f_close(&fdst);
}
__disable_irq(); //跳转前失能
iap_load_app(FLASH_APP_ADDR);//执行FLASH APP代码
while(1)
{
GPIO_SetBits(GPIOB,GPIO_Pin_7);
printf("Never stop
");
delay_ms(500);
GPIO_ResetBits(GPIOB,GPIO_Pin_7);
delay_ms(500);
}
}
}
APP的主代码
void RCC_Configuration(void);
void LED_Config(void);
void LED_ON5s(void);
void TIM2_Config(void);
unsigned char HDF4_FLAG;
unsigned char LED_ON_FLAG;
extern uint16_t MScount1S;
extern uint16_t MScount5S;
extern unsigned char Timer1S_FLAG;
extern unsigned char Timer5S_FLAG;
extern uint8_t Timer120MS_FLAG;
extern unsigned char HDF4Delay_FLAG;
extern unsigned MScount1MS;
extern unsigned char HDF4DelayOK;
int main(void)
{
SCB->VTOR = FLASH_BASE | 0x10000;
RCC_Configuration();
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
IWDG_SetPrescaler(IWDG_Prescaler_32);
IWDG_SetReload(200);
IWDG_ReloadCounter();
// IWDG_Enable();
LED_Config();
TIM2_Config();
LED_ON5s(); //定时5S后熄灭
// 串口配置
USART1_Configuration();
USART_Configuration();
CAN1_Config(CAN_BS1_1tq,CAN_BS1_5tq,CAN_BS1_4tq,0x08); //CC_APB1PeriphClock=8M SET_CAN_PRES=8 BaudRate =100K
Delay(10);//等待20MS
CAN2_Config(CAN_BS1_1tq,CAN_BS1_5tq,CAN_BS1_4tq,0x08); //CC_APB1PeriphClock=8M SET_CAN_PRES=8 BaudRate =100K
Delay(10);//等待20MS
while (1)
{
if((GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)==0))
{
HFD4_ON();
LED_ON();
CAN_SendData(CAN1,&test1);
}else {HFD4_OFF();LED_OFF();CAN_SendData(CAN2,&test2);}
if(Timer120MS_FLAG==1)
{
Comm_Send_Track_msg(TrankCar,&RxMsgBUF_Track);
Timer120MS_FLAG=0;
LED_OFF();
}
}
}
void RCC_Configuration(void)
{
SystemInit();
}
void Delay(__IO uint32_t nCount)
{
uint16_t x;
for(; nCount != 0; nCount--)
for(x=0;x<500;x++)IWDG_ReloadCounter();//喂狗
}
/* ---------------------------------------------------------------
TIM2 Configuration: Output Compare Toggle Mode:
TIM2CLK = 8 MHz, Prescaler = 0x2, TIM2 counter clock = 12 MHz
--------------------------------------------------------------- */
void TIM2_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Enable the TIM2 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0x0400; //1000
TIM_TimeBaseStructure.TIM_Prescaler = 0x08; // 8M/(8*1000)//1ms中断一次
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_RepetitionCounter=0x0; //0x400 1S
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM enable counter */
TIM_Cmd(TIM2, ENABLE);
/* TIM IT enable */
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif
定时器中断处理函数
void TIM2_IRQHandler(void)
{
MScount1S++;
MScount5S++;
MScount120MS++;
if(HDF4Delay_FLAG==1)
{
MScount1MS++;
if(MScount1MS>10)
{HDF4DelayOK=1;
MScount1MS=0;
}
}
LED_ON();
if(MScount120MS>120){Timer120MS_FLAG=1;MScount120MS=0;}
if(CheckCarListMODE)
{
if(MScount1S>500){LED_ON();}//1sμ½áË
if(MScount1S>1000){LED_OFF();}//1sμ½áË
}
if(MScount1S>1000){Timer1S_FLAG=1;MScount1S=0;}//1sμ½áË
if(MScount5S>5000)
{Timer5S_FLAG=1;
MScount5S=0;
LED_OFF();
}//5sμ½áË
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
一周热门 更多>