main.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. *
  7. * Copyright (c) 2017 STMicroelectronics International N.V.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted, provided that the following conditions are met:
  12. *
  13. * 1. Redistribution of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of other
  19. * contributors to this software may be used to endorse or promote products
  20. * derived from this software without specific written permission.
  21. * 4. This software, including modifications and/or derivative works of this
  22. * software, must execute solely and exclusively on microcontroller or
  23. * microprocessor devices manufactured by or for STMicroelectronics.
  24. * 5. Redistribution and use of this software other than as permitted under
  25. * this license is void and will automatically terminate your rights under
  26. * this license.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  29. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  31. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  32. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  33. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  34. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  36. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  37. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  39. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ******************************************************************************
  42. */
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "main.h"
  45. #include "stm32f0xx_hal.h"
  46. #include "cmsis_os.h"
  47. #include "i2c.h"
  48. #include "gpio.h"
  49. /* USER CODE BEGIN Includes */
  50. /* USER CODE END Includes */
  51. /* Private variables ---------------------------------------------------------*/
  52. /* USER CODE BEGIN PV */
  53. /* Private variables ---------------------------------------------------------*/
  54. /* USER CODE END PV */
  55. /* Private function prototypes -----------------------------------------------*/
  56. void SystemClock_Config(void);
  57. void Error_Handler(void);
  58. void MX_FREERTOS_Init(void);
  59. /* USER CODE BEGIN PFP */
  60. /* Private function prototypes -----------------------------------------------*/
  61. /* USER CODE END PFP */
  62. /* USER CODE BEGIN 0 */
  63. /* USER CODE END 0 */
  64. int main(void)
  65. {
  66. /* USER CODE BEGIN 1 */
  67. /* USER CODE END 1 */
  68. /* MCU Configuration----------------------------------------------------------*/
  69. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  70. HAL_Init();
  71. /* Configure the system clock */
  72. SystemClock_Config();
  73. /* Initialize all configured peripherals */
  74. MX_GPIO_Init();
  75. MX_I2C2_Init();
  76. /* USER CODE BEGIN 2 */
  77. /* USER CODE END 2 */
  78. /* Call init function for freertos objects (in freertos.c) */
  79. MX_FREERTOS_Init();
  80. /* Start scheduler */
  81. osKernelStart();
  82. /* We should never get here as control is now taken by the scheduler */
  83. /* Infinite loop */
  84. /* USER CODE BEGIN WHILE */
  85. while (1) {
  86. /* USER CODE END WHILE */
  87. /* USER CODE BEGIN 3 */
  88. }
  89. /* USER CODE END 3 */
  90. }
  91. /** System Clock Configuration
  92. */
  93. void SystemClock_Config(void)
  94. {
  95. RCC_OscInitTypeDef RCC_OscInitStruct;
  96. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  97. /**Initializes the CPU, AHB and APB busses clocks
  98. */
  99. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  100. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  101. RCC_OscInitStruct.HSICalibrationValue = 16;
  102. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  103. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  104. {
  105. Error_Handler();
  106. }
  107. /**Initializes the CPU, AHB and APB busses clocks
  108. */
  109. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  110. |RCC_CLOCKTYPE_PCLK1;
  111. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  112. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  113. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  114. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  115. {
  116. Error_Handler();
  117. }
  118. /**Configure the Systick interrupt time
  119. */
  120. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  121. /**Configure the Systick
  122. */
  123. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  124. /* SysTick_IRQn interrupt configuration */
  125. HAL_NVIC_SetPriority(SysTick_IRQn, 3, 0);
  126. }
  127. /* USER CODE BEGIN 4 */
  128. /* USER CODE END 4 */
  129. /**
  130. * @brief Period elapsed callback in non blocking mode
  131. * @note This function is called when TIM1 interrupt took place, inside
  132. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  133. * a global variable "uwTick" used as application time base.
  134. * @param htim : TIM handle
  135. * @retval None
  136. */
  137. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  138. {
  139. /* USER CODE BEGIN Callback 0 */
  140. /* USER CODE END Callback 0 */
  141. if (htim->Instance == TIM1) {
  142. HAL_IncTick();
  143. }
  144. /* USER CODE BEGIN Callback 1 */
  145. /* USER CODE END Callback 1 */
  146. }
  147. /**
  148. * @brief This function is executed in case of error occurrence.
  149. * @param None
  150. * @retval None
  151. */
  152. void Error_Handler(void)
  153. {
  154. /* USER CODE BEGIN Error_Handler */
  155. /* User can add his own implementation to report the HAL error return state */
  156. while (1) {
  157. }
  158. /* USER CODE END Error_Handler */
  159. }
  160. #ifdef USE_FULL_ASSERT
  161. /**
  162. * @brief Reports the name of the source file and the source line number
  163. * where the assert_param error has occurred.
  164. * @param file: pointer to the source file name
  165. * @param line: assert_param error line source number
  166. * @retval None
  167. */
  168. void assert_failed(uint8_t* file, uint32_t line)
  169. {
  170. /* USER CODE BEGIN 6 */
  171. /* User can add his own implementation to report the file name and line number,
  172. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  173. /* USER CODE END 6 */
  174. }
  175. #endif
  176. /**
  177. * @}
  178. */
  179. /**
  180. * @}
  181. */
  182. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/