123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "stm32f0xx_hal.h"
- #include "logic.h"
- #include "pwm_in.h"
- #include "gpio.h"
- #include "pwm_out.h"
- static uint8_t step_number = 0;
- //
- void logic_main(void)
- {
- IWDG->KR = 0xAAAA;
-
- if (get_button())
- {
- logic_set_out_pwm();
- set_button(false);
- }
- }
- //
- void logic_set_out_pwm(void)
- {
- switch (step_number)
- {
- case 0:
- tim_pwm_out_set_pulse(PWM_OUT_CH_1, 1760);
- break;
-
- case 1:
- tim_pwm_out_set_pulse(PWM_OUT_CH_2, 1760);
- break;
-
- case 2:
- tim_pwm_out_set_pulse(PWM_OUT_CH_3, 1760);
- break;
-
- case 3:
- tim_pwm_out_set_pulse(PWM_OUT_CH_4, 1760);
- break;
-
- default : break;
- }
-
- step_number = step_number == 3 ? 0 : step_number + 1;
- }
- //
- void wdt_init(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct;
-
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
- RCC_OscInitStruct.LSIState = RCC_LSI_ON;
- HAL_RCC_OscConfig(&RCC_OscInitStruct);
-
- // 1. Enable the IWDG by writing 0x0000 CCCC in the IWDG_KR register.
- IWDG->KR = 0xCCCC;
- // 2. Enable register access by writing 0x0000 5555 in the IWDG_KR register.
- IWDG->KR = 0x5555;
- // 3. Write the IWDG prescaler by programming IWDG_PR from 0 to 7.
- IWDG->PR = 4;
- // 4. Write the reload register (IWDG_RLR).
- IWDG->RLR = 1000;
- // 5. Wait for the registers to be updated (IWDG_SR = 0x0000 0000).
- while (IWDG->SR);
- // 6. Refresh the counter value with IWDG_RLR (IWDG_KR = 0x0000 AAAA)
- IWDG->KR = 0xAAAA;
- }
|