main.c 2.2 KB

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