main.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. //led_togle();
  34. timer_Main();
  35. }
  36. }
  37. void SystemClock_Config(void)
  38. {
  39. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  40. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  41. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
  42. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  43. RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
  44. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  45. RCC_OscInitStruct.HSI14CalibrationValue = 16;
  46. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  47. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  48. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
  49. RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  50. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  51. {
  52. Error_Handler();
  53. }
  54. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  55. |RCC_CLOCKTYPE_PCLK1;
  56. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  57. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  58. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  59. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  60. {
  61. Error_Handler();
  62. }
  63. }
  64. void Error_Handler(void)
  65. {
  66. __disable_irq();
  67. while (1) {}
  68. }