main.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "stm32f0xx_hal.h"
  2. #include "led.h"
  3. #include "button.h"
  4. #include "adc.h"
  5. #include "tim.h"
  6. #include "misc.h"
  7. #include "systick.h"
  8. #include "usart.h"
  9. #include "pwm_out.h"
  10. #include "pwm_in.h"
  11. #include "gpio.h"
  12. #include "logic.h"
  13. #include <stdio.h>
  14. void SystemClock_Config(void);
  15. void Error_Handler(void);
  16. int main()
  17. {
  18. HAL_Init();
  19. SystemClock_Config();
  20. /*
  21. gpio_init();
  22. tim_pwm_out_init();
  23. tim_pwm_in_init();
  24. wdt_init();
  25. */
  26. channel_init();
  27. led_init();
  28. tim_init();
  29. tim_warmup();
  30. adc_init();
  31. but_init();
  32. #if 1
  33. usart_init();
  34. printf("FW started...\r\n");
  35. #endif
  36. HAL_Delay(1000);
  37. //tim_set_string_freq(1);
  38. timer_AddFunction(10, adc_task);
  39. timer_AddFunction(10, button_run);
  40. timer_AddFunction(10, logic_cnt_task);
  41. timer_AddFunction(100, logic_led_freq);
  42. timer_AddFunction(500, led_battery_task);
  43. //bool foo;
  44. //foo = but_is_string();
  45. while(1)
  46. {
  47. timer_Main();
  48. //adc_print_data();
  49. //adc_task();
  50. //adc_task();
  51. //printf("CNT: %u\r\n", counter++);
  52. //HAL_Delay(1000);
  53. //logic_main();
  54. }
  55. }
  56. void SystemClock_Config(void)
  57. {
  58. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  59. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  60. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
  61. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  62. RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
  63. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  64. RCC_OscInitStruct.HSI14CalibrationValue = 16;
  65. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  66. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  67. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
  68. RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  69. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  70. {
  71. Error_Handler();
  72. }
  73. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  74. |RCC_CLOCKTYPE_PCLK1;
  75. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  76. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  77. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  78. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  79. {
  80. Error_Handler();
  81. }
  82. }
  83. void Error_Handler(void)
  84. {
  85. __disable_irq();
  86. while (1) {}
  87. }