Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20.  
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "main.h"
  23.  
  24. /* Private includes ----------------------------------------------------------*/
  25. /* USER CODE BEGIN Includes */
  26.  
  27. /* USER CODE END Includes */
  28.  
  29. /* Private typedef -----------------------------------------------------------*/
  30. /* USER CODE BEGIN PTD */
  31.  
  32. /* USER CODE END PTD */
  33.  
  34. /* Private define ------------------------------------------------------------*/
  35. /* USER CODE BEGIN PD */
  36.  
  37. /* USER CODE END PD */
  38.  
  39. /* Private macro -------------------------------------------------------------*/
  40. /* USER CODE BEGIN PM */
  41.  
  42. /* USER CODE END PM */
  43.  
  44. /* Private variables ---------------------------------------------------------*/
  45. TIM_HandleTypeDef htim7;
  46.  
  47. /* USER CODE BEGIN PV */
  48.  
  49. /* USER CODE END PV */
  50.  
  51. /* Private function prototypes -----------------------------------------------*/
  52. void SystemClock_Config(void);
  53. static void MX_GPIO_Init(void);
  54. static void MX_TIM7_Init(void);
  55. /* USER CODE BEGIN PFP */
  56.  
  57. /* USER CODE END PFP */
  58.  
  59. /* Private user code ---------------------------------------------------------*/
  60. /* USER CODE BEGIN 0 */
  61. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  62. {
  63. if(htim->Instance == htim7.Instance) {
  64. HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);
  65. }
  66. }
  67. /* USER CODE END 0 */
  68.  
  69. /**
  70. * @brief The application entry point.
  71. * @retval int
  72. */
  73. int main(void)
  74. {
  75. /* USER CODE BEGIN 1 */
  76.  
  77. /* USER CODE END 1 */
  78.  
  79.  
  80. /* MCU Configuration--------------------------------------------------------*/
  81.  
  82. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  83. HAL_Init();
  84.  
  85. /* USER CODE BEGIN Init */
  86.  
  87. /* USER CODE END Init */
  88.  
  89. /* Configure the system clock */
  90. SystemClock_Config();
  91.  
  92. /* USER CODE BEGIN SysInit */
  93.  
  94. /* USER CODE END SysInit */
  95.  
  96. /* Initialize all configured peripherals */
  97. MX_GPIO_Init();
  98. MX_TIM7_Init();
  99. /* USER CODE BEGIN 2 */
  100. HAL_TIM_Base_Start_IT(&htim7);
  101. /* USER CODE END 2 */
  102.  
  103. /* Infinite loop */
  104. /* USER CODE BEGIN WHILE */
  105. while (1)
  106. {
  107. /* USER CODE END WHILE */
  108.  
  109. /* USER CODE BEGIN 3 */
  110. }
  111. /* USER CODE END 3 */
  112. }
  113.  
  114. /**
  115. * @brief System Clock Configuration
  116. * @retval None
  117. */
  118. void SystemClock_Config(void)
  119. {
  120. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  121. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  122.  
  123. /** Configure the main internal regulator output voltage
  124. */
  125. __HAL_RCC_PWR_CLK_ENABLE();
  126. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  127. /** Initializes the CPU, AHB and APB busses clocks
  128. */
  129. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  130. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  131. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  132. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  133. RCC_OscInitStruct.PLL.PLLM = 4;
  134. RCC_OscInitStruct.PLL.PLLN = 168;
  135. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  136. RCC_OscInitStruct.PLL.PLLQ = 4;
  137. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  138. {
  139. Error_Handler();
  140. }
  141. /** Initializes the CPU, AHB and APB busses clocks
  142. */
  143. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  144. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  145. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  146. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  147. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  148. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  149.  
  150. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  151. {
  152. Error_Handler();
  153. }
  154. }
  155.  
  156. /**
  157. * @brief TIM7 Initialization Function
  158. * @param None
  159. * @retval None
  160. */
  161. static void MX_TIM7_Init(void)
  162. {
  163.  
  164. /* USER CODE BEGIN TIM7_Init 0 */
  165.  
  166. /* USER CODE END TIM7_Init 0 */
  167.  
  168. TIM_MasterConfigTypeDef sMasterConfig = {0};
  169.  
  170. /* USER CODE BEGIN TIM7_Init 1 */
  171.  
  172. /* USER CODE END TIM7_Init 1 */
  173. htim7.Instance = TIM7;
  174. htim7.Init.Prescaler = 9999;
  175. htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
  176. htim7.Init.Period = 8399;
  177. htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  178. if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
  179. {
  180. Error_Handler();
  181. }
  182. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  183. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  184. if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
  185. {
  186. Error_Handler();
  187. }
  188. /* USER CODE BEGIN TIM7_Init 2 */
  189.  
  190. /* USER CODE END TIM7_Init 2 */
  191.  
  192. }
  193.  
  194. /**
  195. * @brief GPIO Initialization Function
  196. * @param None
  197. * @retval None
  198. */
  199. static void MX_GPIO_Init(void)
  200. {
  201. GPIO_InitTypeDef GPIO_InitStruct = {0};
  202.  
  203. /* GPIO Ports Clock Enable */
  204. __HAL_RCC_GPIOH_CLK_ENABLE();
  205. __HAL_RCC_GPIOG_CLK_ENABLE();
  206.  
  207. /*Configure GPIO pin Output Level */
  208. HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_RESET);
  209.  
  210. /*Configure GPIO pin : PG13 */
  211. GPIO_InitStruct.Pin = GPIO_PIN_13;
  212. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  213. GPIO_InitStruct.Pull = GPIO_NOPULL;
  214. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  215. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  216.  
  217. }
  218.  
  219. /* USER CODE BEGIN 4 */
  220.  
  221. /* USER CODE END 4 */
  222.  
  223. /**
  224. * @brief This function is executed in case of error occurrence.
  225. * @retval None
  226. */
  227. void Error_Handler(void)
  228. {
  229. /* USER CODE BEGIN Error_Handler_Debug */
  230. /* User can add his own implementation to report the HAL error return state */
  231.  
  232. /* USER CODE END Error_Handler_Debug */
  233. }
  234.  
  235. #ifdef USE_FULL_ASSERT
  236. /**
  237. * @brief Reports the name of the source file and the source line number
  238. * where the assert_param error has occurred.
  239. * @param file: pointer to the source file name
  240. * @param line: assert_param error line source number
  241. * @retval None
  242. */
  243. void assert_failed(uint8_t *file, uint32_t line)
  244. {
  245. /* USER CODE BEGIN 6 */
  246. /* User can add his own implementation to report the file name and line number,
  247. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  248. /* USER CODE END 6 */
  249. }
  250. #endif /* USE_FULL_ASSERT */
  251.  
  252. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement