main.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <stdio.h>
  12. void SystemClock_Config(void);
  13. void Error_Handler(void);
  14. int main()
  15. {
  16. HAL_Init();
  17. SystemClock_Config();
  18. usart_init();
  19. printf("Hello world\r\n");
  20. //tim_pwm_out_init();
  21. tim_pwm_in_init();
  22. #if 0
  23. tim_init();
  24. led_init();
  25. pulse_gpio_init();
  26. button_init();
  27. adc_init();
  28. timer_AddFunction(100, &adc_task);
  29. #endif
  30. while(1)
  31. {
  32. HAL_Delay(1000);
  33. tim_print_out_pwm();
  34. //led_togle();
  35. timer_Main();
  36. }
  37. }
  38. void SystemClock_Config(void)
  39. {
  40. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  41. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  42. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
  43. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  44. RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
  45. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  46. RCC_OscInitStruct.HSI14CalibrationValue = 16;
  47. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  48. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  49. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
  50. RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  51. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  52. {
  53. Error_Handler();
  54. }
  55. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  56. |RCC_CLOCKTYPE_PCLK1;
  57. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  58. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  59. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  60. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  61. {
  62. Error_Handler();
  63. }
  64. }
  65. void Error_Handler(void)
  66. {
  67. __disable_irq();
  68. while (1) {}
  69. }