main.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. *
  7. * COPYRIGHT(c) 2016 STMicroelectronics
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. * 1. Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32f0xx_hal.h"
  35. #include "cmsis_os.h"
  36. #include "i2c.h"
  37. #include "tim.h"
  38. #include "gpio.h"
  39. /* USER CODE BEGIN Includes */
  40. /* USER CODE END Includes */
  41. /* Private variables ---------------------------------------------------------*/
  42. /* USER CODE BEGIN PV */
  43. /* Private variables ---------------------------------------------------------*/
  44. /* USER CODE END PV */
  45. /* Private function prototypes -----------------------------------------------*/
  46. void SystemClock_Config(void);
  47. void MX_FREERTOS_Init(void);
  48. /* USER CODE BEGIN PFP */
  49. /* Private function prototypes -----------------------------------------------*/
  50. /* USER CODE END PFP */
  51. /* USER CODE BEGIN 0 */
  52. /* USER CODE END 0 */
  53. int main(void)
  54. {
  55. /* USER CODE BEGIN 1 */
  56. /* USER CODE END 1 */
  57. /* MCU Configuration----------------------------------------------------------*/
  58. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  59. HAL_Init();
  60. /* Configure the system clock */
  61. SystemClock_Config();
  62. /* Initialize all configured peripherals */
  63. MX_GPIO_Init();
  64. MX_I2C1_Init();
  65. MX_TIM6_Init();
  66. /* USER CODE BEGIN 2 */
  67. /* USER CODE END 2 */
  68. /* Call init function for freertos objects (in freertos.c) */
  69. MX_FREERTOS_Init();
  70. /* Start scheduler */
  71. osKernelStart();
  72. /* We should never get here as control is now taken by the scheduler */
  73. /* Infinite loop */
  74. /* USER CODE BEGIN WHILE */
  75. while (1)
  76. {
  77. /* USER CODE END WHILE */
  78. /* USER CODE BEGIN 3 */
  79. }
  80. /* USER CODE END 3 */
  81. }
  82. /** System Clock Configuration
  83. */
  84. void SystemClock_Config(void)
  85. {
  86. RCC_OscInitTypeDef RCC_OscInitStruct;
  87. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  88. RCC_PeriphCLKInitTypeDef PeriphClkInit;
  89. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  90. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  91. RCC_OscInitStruct.HSICalibrationValue = 16;
  92. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  93. HAL_RCC_OscConfig(&RCC_OscInitStruct);
  94. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  95. |RCC_CLOCKTYPE_PCLK1;
  96. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  97. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  98. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  99. HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
  100. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
  101. PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
  102. HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
  103. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  104. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  105. /* SysTick_IRQn interrupt configuration */
  106. HAL_NVIC_SetPriority(SysTick_IRQn, 3, 0);
  107. }
  108. /* USER CODE BEGIN 4 */
  109. /* USER CODE END 4 */
  110. #ifdef USE_FULL_ASSERT
  111. /**
  112. * @brief Reports the name of the source file and the source line number
  113. * where the assert_param error has occurred.
  114. * @param file: pointer to the source file name
  115. * @param line: assert_param error line source number
  116. * @retval None
  117. */
  118. void assert_failed(uint8_t* file, uint32_t line)
  119. {
  120. /* USER CODE BEGIN 6 */
  121. /* User can add his own implementation to report the file name and line number,
  122. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  123. /* USER CODE END 6 */
  124. }
  125. #endif
  126. /**
  127. * @}
  128. */
  129. /**
  130. * @}
  131. */
  132. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/