/****************************************Copyright (c)**************************************************** ** ** **--------------File Info--------------------------------------------------------------------------------- ** File name: main.c ** Descriptions: ** **-------------------------------------------------------------------------------------------------------- ** Created by: ** Created date: ** Version: ** Descriptions: ** **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: ** Version: ** Descriptions: ** *********************************************************************************************************/ #define THIS_FILE_ID 1 /* Includes ------------------------------------------------------------------*/ #include #include "includes.h" void MY_NVIC_Init() { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //选择中断分组2 RunMake(THIS_FILE_ID); //串口1 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RunMake(THIS_FILE_ID); //串口2 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RunMake(THIS_FILE_ID); //串口3 NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RunMake(THIS_FILE_ID); // //DMA中断设置 NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RunMake(THIS_FILE_ID); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //外部中断 NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); } void IWDG_Configuration(void) { RCC->CSR|=0x01; while(!((RCC->CSR>>1)&0x01)); if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)RCC_ClearFlag(); //写入0x5555,用于允许狗狗寄存器写入功能 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //狗狗时钟分频,40K/256=156HZ(6.4ms) IWDG_SetPrescaler(IWDG_Prescaler_256); //喂狗时间 //IWDG_SetReload(200);1.28s/6.4MS=200 .注意不能大于0xfff IWDG_SetReload(500);//3.2s/6.4MS=500 .注意不能大于0xfff //使能狗狗 IWDG_Enable(); } //void DelayMs(unsigned short t) //{ // unsigned short ct; // while(t--){ // for(ct=0;ct<6800;ct++); // } //} /********************************************************************************************************** main() **********************************************************************************************************/ int main (void) { IWDG_Configuration(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//复用功能IO 时钟使能 这里必须先使能复用IO的时钟,再关闭JTAG功能 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // JTAG-DP Disabled and SW-DP Enabled ExtWatchDogInit(); FEED_EXTWATCHDOG();//喂狗 IWDG_ReloadCounter();//喂狗 FEED_EXTWATCHDOG();//喂狗 MY_NVIC_Init(); /* Initialize RTX and start init */ os_sys_init_user(MainTask,1,stkMainTask,sizeof(stkMainTask)); while(1){} return (0); } /********************************************************************************************************* END FILE *********************************************************************************************************/