wdg.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /********************************* (C) РОТЕК ***********************************
  2. * @module wdg
  3. * @file wdg.c
  4. * @version 1.0.0
  5. * @date XX.XX.XXXX
  6. * $brief External watchdog (pin PE11)
  7. *******************************************************************************
  8. * @history Version Author Comment
  9. * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
  10. *******************************************************************************
  11. */
  12. #include "stm32f4xx.h"
  13. #include "wdg.h"
  14. #include "gpio.h"
  15. /**
  16. * @brief
  17. * @retval
  18. */
  19. void WDG_Init(void)
  20. {
  21. // GPIO_InitTypeDef GPIO_InitStructure;
  22. NVIC_InitTypeDef NVIC_InitStructure;
  23. TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  24. // RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  25. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM13, ENABLE);
  26. /* Port initialization done in "gpio_init" */
  27. /* GPIO_InitStructure.GPIO_Pin = WDT_PIN;
  28. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  29. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  30. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  31. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  32. GPIO_Init(GPIOE, &GPIO_InitStructure);*/
  33. NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
  34. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x6;
  35. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
  36. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  37. NVIC_Init(&NVIC_InitStructure);
  38. NVIC_SetPriority(TIM8_UP_TIM13_IRQn, 2);
  39. /* APB1 Timer clock is 60Mhz, configure timer clock to 10khz (1 update event per 100 us) */
  40. TIM_TimeBaseStructure.TIM_Prescaler = 6000 - 1;
  41. /* Configure timer period to 100ms */
  42. TIM_TimeBaseStructure.TIM_Period = 1000;
  43. TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  44. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  45. TIM_TimeBaseInit(TIM13, &TIM_TimeBaseStructure);
  46. TIM_Cmd(TIM13, ENABLE);
  47. TIM_ITConfig(TIM13, TIM_IT_Update, ENABLE);
  48. }
  49. /**
  50. * @brief Дергаем пином (сброс внешнего WDT)
  51. * @retval
  52. */
  53. void TIM8_UP_TIM13_IRQHandler(void)
  54. {
  55. TIM_ClearITPendingBit(TIM13, TIM_IT_Update);
  56. gpio_invert_output(_WDG);
  57. }
  58. /********************************* (C) РОТЕК **********************************/