Advertisement
Guest User

asd

a guest
Oct 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.24 KB | None | 0 0
  1.  
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. ** This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * COPYRIGHT(c) 2018 STMicroelectronics
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "main.h"
  41. #include "stm32f4xx_hal.h"
  42.  
  43. /* USER CODE BEGIN Includes */
  44.  
  45. /* USER CODE END Includes */
  46.  
  47. /* Private variables ---------------------------------------------------------*/
  48.  
  49. /* USER CODE BEGIN PV */
  50. /* Private variables ---------------------------------------------------------*/
  51.  
  52. /* USER CODE END PV */
  53.  
  54. /* Private function prototypes -----------------------------------------------*/
  55. void SystemClock_Config(void);
  56. static void MX_GPIO_Init(void);
  57.  
  58. /* USER CODE BEGIN PFP */
  59. /* Private function prototypes -----------------------------------------------*/
  60.  
  61. /* USER CODE END PFP */
  62.  
  63. /* USER CODE BEGIN 0 */
  64.  
  65. /* USER CODE END 0 */
  66.  
  67. /**
  68. * @brief The application entry point.
  69. *
  70. * @retval None
  71. */
  72. int main(void)
  73. {
  74. /* USER CODE BEGIN 1 */
  75.  
  76. /* USER CODE END 1 */
  77.  
  78. /* MCU Configuration----------------------------------------------------------*/
  79.  
  80. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  81. HAL_Init();
  82.  
  83. /* USER CODE BEGIN Init */
  84.  
  85. /* USER CODE END Init */
  86.  
  87. /* Configure the system clock */
  88. SystemClock_Config();
  89.  
  90. /* USER CODE BEGIN SysInit */
  91.  
  92. /* USER CODE END SysInit */
  93.  
  94. /* Initialize all configured peripherals */
  95. MX_GPIO_Init();
  96. /* USER CODE BEGIN 2 */
  97. HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_SET);
  98.  
  99. /* USER CODE END 2 */
  100.  
  101. /* Infinite loop */
  102. /* USER CODE BEGIN WHILE */
  103. while (1)
  104. {
  105.  
  106. /* USER CODE END WHILE */
  107.  
  108. /* USER CODE BEGIN 3 */
  109.  
  110. }
  111. /* USER CODE END 3 */
  112.  
  113. }
  114.  
  115. /**
  116. * @brief System Clock Configuration
  117. * @retval None
  118. */
  119. void SystemClock_Config(void)
  120. {
  121.  
  122. RCC_OscInitTypeDef RCC_OscInitStruct;
  123. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  124.  
  125. /**Configure the main internal regulator output voltage
  126. */
  127. __HAL_RCC_PWR_CLK_ENABLE();
  128.  
  129. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  130.  
  131. /**Initializes the CPU, AHB and APB busses clocks
  132. */
  133. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  134. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  135. RCC_OscInitStruct.HSICalibrationValue = 16;
  136. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  137. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  138. RCC_OscInitStruct.PLL.PLLM = 16;
  139. RCC_OscInitStruct.PLL.PLLN = 336;
  140. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  141. RCC_OscInitStruct.PLL.PLLQ = 4;
  142. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  143. {
  144. _Error_Handler(__FILE__, __LINE__);
  145. }
  146.  
  147. /**Initializes the CPU, AHB and APB busses clocks
  148. */
  149. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  150. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  151. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  152. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  153. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  154. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  155.  
  156. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  157. {
  158. _Error_Handler(__FILE__, __LINE__);
  159. }
  160.  
  161. /**Configure the Systick interrupt time
  162. */
  163. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  164.  
  165. /**Configure the Systick
  166. */
  167. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  168.  
  169. /* SysTick_IRQn interrupt configuration */
  170. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  171. }
  172.  
  173. /** Configure pins as
  174. * Analog
  175. * Input
  176. * Output
  177. * EVENT_OUT
  178. * EXTI
  179. */
  180. static void MX_GPIO_Init(void)
  181. {
  182.  
  183. GPIO_InitTypeDef GPIO_InitStruct;
  184.  
  185. /* GPIO Ports Clock Enable */
  186. __HAL_RCC_GPIOC_CLK_ENABLE();
  187. __HAL_RCC_GPIOH_CLK_ENABLE();
  188. __HAL_RCC_GPIOA_CLK_ENABLE();
  189. __HAL_RCC_GPIOB_CLK_ENABLE();
  190.  
  191. /*Configure GPIO pin Output Level */
  192. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2|GPIO_PIN_3|LD2_Pin|GPIO_PIN_8
  193. |GPIO_PIN_10, GPIO_PIN_RESET);
  194.  
  195. /*Configure GPIO pin Output Level */
  196. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5, GPIO_PIN_RESET);
  197.  
  198. /*Configure GPIO pin : B1_Pin */
  199. GPIO_InitStruct.Pin = B1_Pin;
  200. GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  201. GPIO_InitStruct.Pull = GPIO_NOPULL;
  202. HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
  203.  
  204. /*Configure GPIO pins : PA2 PA3 LD2_Pin PA8
  205. PA10 */
  206. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|LD2_Pin|GPIO_PIN_8
  207. |GPIO_PIN_10;
  208. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  209. GPIO_InitStruct.Pull = GPIO_NOPULL;
  210. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  211. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  212.  
  213. /*Configure GPIO pins : PB10 PB3 PB4 PB5 */
  214. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
  215. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  216. GPIO_InitStruct.Pull = GPIO_NOPULL;
  217. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  218. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  219.  
  220. }
  221.  
  222. /* USER CODE BEGIN 4 */
  223.  
  224. /* USER CODE END 4 */
  225.  
  226. /**
  227. * @brief This function is executed in case of error occurrence.
  228. * @param file: The file name as string.
  229. * @param line: The line in file as a number.
  230. * @retval None
  231. */
  232. void _Error_Handler(char *file, int line)
  233. {
  234. /* USER CODE BEGIN Error_Handler_Debug */
  235. /* User can add his own implementation to report the HAL error return state */
  236. while(1)
  237. {
  238. }
  239. /* USER CODE END Error_Handler_Debug */
  240. }
  241.  
  242. #ifdef USE_FULL_ASSERT
  243. /**
  244. * @brief Reports the name of the source file and the source line number
  245. * where the assert_param error has occurred.
  246. * @param file: pointer to the source file name
  247. * @param line: assert_param error line source number
  248. * @retval None
  249. */
  250. void assert_failed(uint8_t* file, uint32_t line)
  251. {
  252. /* USER CODE BEGIN 6 */
  253. /* User can add his own implementation to report the file name and line number,
  254. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  255. /* USER CODE END 6 */
  256. }
  257. #endif /* USE_FULL_ASSERT */
  258.  
  259. /**
  260. * @}
  261. */
  262.  
  263. /**
  264. * @}
  265. */
  266.  
  267. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement