main.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. adc_init();
  29. tim_init();
  30. but_init();
  31. #if 1
  32. usart_init();
  33. printf("FW started...\r\n");
  34. #endif
  35. HAL_Delay(1000);
  36. //tim_set_string_freq(1);
  37. timer_AddFunction(10, adc_task);
  38. timer_AddFunction(10, button_run);
  39. timer_AddFunction(10, logic_cnt_task);
  40. timer_AddFunction(100, logic_led_freq);
  41. //bool foo;
  42. //foo = but_is_string();
  43. while(1)
  44. {
  45. timer_Main();
  46. //adc_print_data();
  47. //adc_task();
  48. //adc_task();
  49. //printf("CNT: %u\r\n", counter++);
  50. //HAL_Delay(1000);
  51. //logic_main();
  52. }
  53. }
  54. void SystemClock_Config(void)
  55. {
  56. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  57. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  58. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
  59. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  60. RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
  61. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  62. RCC_OscInitStruct.HSI14CalibrationValue = 16;
  63. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  64. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  65. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
  66. RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  67. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  68. {
  69. Error_Handler();
  70. }
  71. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  72. |RCC_CLOCKTYPE_PCLK1;
  73. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  74. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  75. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  76. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  77. {
  78. Error_Handler();
  79. }
  80. }
  81. void Error_Handler(void)
  82. {
  83. __disable_irq();
  84. while (1) {}
  85. }