main.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /****************************************Copyright (c)****************************************************
  2. **
  3. **
  4. **--------------File Info---------------------------------------------------------------------------------
  5. ** File name: main.c
  6. ** Descriptions:
  7. **
  8. **--------------------------------------------------------------------------------------------------------
  9. ** Created by:
  10. ** Created date:
  11. ** Version:
  12. ** Descriptions:
  13. **
  14. **--------------------------------------------------------------------------------------------------------
  15. ** Modified by:
  16. ** Modified date:
  17. ** Version:
  18. ** Descriptions:
  19. **
  20. *********************************************************************************************************/
  21. #define THIS_FILE_ID 1
  22. /* Includes ------------------------------------------------------------------*/
  23. #include <stm32f10x.h>
  24. #include "includes.h"
  25. void MY_NVIC_Init()
  26. {
  27. NVIC_InitTypeDef NVIC_InitStructure;
  28. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //选择中断分组2
  29. RunMake(THIS_FILE_ID);
  30. //串口1
  31. NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  32. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  33. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  34. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  35. NVIC_Init(&NVIC_InitStructure);
  36. RunMake(THIS_FILE_ID);
  37. //串口2
  38. NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  39. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  40. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  41. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  42. NVIC_Init(&NVIC_InitStructure);
  43. RunMake(THIS_FILE_ID);
  44. //串口3
  45. NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  46. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  47. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  48. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  49. NVIC_Init(&NVIC_InitStructure);
  50. RunMake(THIS_FILE_ID);
  51. // //DMA中断设置
  52. NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
  53. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  54. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  55. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  56. NVIC_Init(&NVIC_InitStructure);
  57. RunMake(THIS_FILE_ID);
  58. NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn;
  59. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  60. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  61. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  62. NVIC_Init(&NVIC_InitStructure);
  63. NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
  64. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
  65. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  66. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  67. NVIC_Init(&NVIC_InitStructure);
  68. NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  69. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
  70. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  71. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  72. NVIC_Init(&NVIC_InitStructure);
  73. NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  74. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
  75. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  76. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  77. NVIC_Init(&NVIC_InitStructure);
  78. //外部中断
  79. NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
  80. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  81. NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  82. NVIC_Init(&NVIC_InitStructure);
  83. }
  84. void IWDG_Configuration(void)
  85. {
  86. RCC->CSR|=0x01;
  87. while(!((RCC->CSR>>1)&0x01));
  88. if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)RCC_ClearFlag();
  89. //写入0x5555,用于允许狗狗寄存器写入功能
  90. IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  91. //狗狗时钟分频,40K/256=156HZ(6.4ms)
  92. IWDG_SetPrescaler(IWDG_Prescaler_256);
  93. //喂狗时间
  94. //IWDG_SetReload(200);1.28s/6.4MS=200 .注意不能大于0xfff
  95. IWDG_SetReload(500);//3.2s/6.4MS=500 .注意不能大于0xfff
  96. //使能狗狗
  97. IWDG_Enable();
  98. }
  99. //void DelayMs(unsigned short t)
  100. //{
  101. // unsigned short ct;
  102. // while(t--){
  103. // for(ct=0;ct<6800;ct++);
  104. // }
  105. //}
  106. /**********************************************************************************************************
  107. main()
  108. **********************************************************************************************************/
  109. int main (void)
  110. {
  111. IWDG_Configuration();
  112. RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//复用功能IO 时钟使能 这里必须先使能复用IO的时钟,再关闭JTAG功能
  113. GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // JTAG-DP Disabled and SW-DP Enabled
  114. ExtWatchDogInit();
  115. FEED_EXTWATCHDOG();//喂狗
  116. IWDG_ReloadCounter();//喂狗
  117. FEED_EXTWATCHDOG();//喂狗
  118. MY_NVIC_Init();
  119. /* Initialize RTX and start init */
  120. os_sys_init_user(MainTask,1,stkMainTask,sizeof(stkMainTask));
  121. while(1){}
  122. return (0);
  123. }
  124. /*********************************************************************************************************
  125. END FILE
  126. *********************************************************************************************************/