Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  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 "stm32f1xx_hal.h"
  35.  
  36. /* USER CODE BEGIN Includes */
  37.  
  38. /* USER CODE END Includes */
  39.  
  40. /* Private variables ---------------------------------------------------------*/
  41.  
  42. /* USER CODE BEGIN PV */
  43. /* Private variables ---------------------------------------------------------*/
  44.  
  45. /* USER CODE END PV */
  46.  
  47. /* Private function prototypes -----------------------------------------------*/
  48. void SystemClock_Config(void);
  49. void Error_Handler(void);
  50. void _exit(int);
  51. static void MX_GPIO_Init(void);
  52.  
  53. /* USER CODE BEGIN PFP */
  54. /* Private function prototypes -----------------------------------------------*/
  55.  
  56. /* USER CODE END PFP */
  57.  
  58. /* USER CODE BEGIN 0 */
  59.  
  60. /* USER CODE END 0 */
  61.  
  62. int main(void)
  63. {
  64.  
  65.  
  66.  
  67. /* USER CODE BEGIN 1 */
  68.  
  69. /* USER CODE END 1 */
  70.  
  71. /* MCU Configuration----------------------------------------------------------*/
  72.  
  73. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  74. HAL_Init();
  75.  
  76. /* Configure the system clock */
  77. SystemClock_Config();
  78.  
  79. /* Initialize all configured peripherals */
  80. MX_GPIO_Init();
  81.  
  82.  
  83. HAL_GPIO_WritePin(GPIOD,GPIO_PIN_0, GPIO_PIN_RESET);
  84. HAL_GPIO_WritePin(GPIOD,GPIO_PIN_1, GPIO_PIN_RESET);
  85. HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2, GPIO_PIN_RESET);
  86. HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3, GPIO_PIN_RESET);
  87.  
  88. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0, GPIO_PIN_RESET);
  89. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1, GPIO_PIN_RESET);
  90. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_2, GPIO_PIN_RESET);
  91. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_3, GPIO_PIN_RESET);
  92. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_4, GPIO_PIN_RESET);
  93. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5, GPIO_PIN_RESET);
  94. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6, GPIO_PIN_RESET);
  95. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7, GPIO_PIN_RESET);
  96.  
  97.  
  98. /* USER CODE BEGIN 2 */
  99.  
  100. /* USER CODE END 2 */
  101.  
  102. /* Infinite loop */
  103. /* USER CODE BEGIN WHILE */
  104. while (1)
  105. {
  106. /* USER CODE END WHILE */
  107.  
  108.  
  109.  
  110.  
  111. /* USER CODE BEGIN 3 */
  112.  
  113. }
  114. /* USER CODE END 3 */
  115.  
  116. }
  117.  
  118. void _exit(int status)
  119. {
  120. while (1);
  121. }
  122.  
  123. /** System Clock Configuration
  124. */
  125. void SystemClock_Config(void)
  126. {
  127.  
  128. RCC_OscInitTypeDef RCC_OscInitStruct;
  129. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  130.  
  131. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  132. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  133. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  134. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  135. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  136. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2;
  137. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  138. {
  139. Error_Handler();
  140. }
  141.  
  142. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  143. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  144. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  145. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  146. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  147. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  148. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  149. {
  150. Error_Handler();
  151. }
  152.  
  153. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  154.  
  155. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  156.  
  157. /* SysTick_IRQn interrupt configuration */
  158. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  159. }
  160.  
  161. /** Configure pins as
  162. * Analog
  163. * Input
  164. * Output
  165. * EVENT_OUT
  166. * EXTI
  167. */
  168. static void MX_GPIO_Init(void)
  169. {
  170.  
  171. GPIO_InitTypeDef GPIO_InitStruct;
  172.  
  173. /* GPIO Ports Clock Enable */
  174. __HAL_RCC_GPIOD_CLK_ENABLE();
  175. __HAL_RCC_GPIOA_CLK_ENABLE();
  176. __HAL_RCC_GPIOB_CLK_ENABLE();
  177.  
  178. /*Configure GPIO pin Output Level */
  179. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
  180. |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
  181.  
  182. /*Configure GPIO pins : PA0 PA1 PA2 PA3
  183. PA4 PA5 PA6 PA7 */
  184. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
  185. |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  186. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  187. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  188. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  189.  
  190. }
  191.  
  192. /* USER CODE BEGIN 4 */
  193.  
  194. /* USER CODE END 4 */
  195.  
  196. /**
  197. * @brief This function is executed in case of error occurrence.
  198. * @param None
  199. * @retval None
  200. */
  201. void Error_Handler(void)
  202. {
  203. /* USER CODE BEGIN Error_Handler */
  204. /* User can add his own implementation to report the HAL error return state */
  205. while(1)
  206. {
  207. }
  208. /* USER CODE END Error_Handler */
  209. }
  210.  
  211. #ifdef USE_FULL_ASSERT
  212.  
  213. /**
  214. * @brief Reports the name of the source file and the source line number
  215. * where the assert_param error has occurred.
  216. * @param file: pointer to the source file name
  217. * @param line: assert_param error line source number
  218. * @retval None
  219. */
  220. void assert_failed(uint8_t* file, uint32_t line)
  221. {
  222. /* USER CODE BEGIN 6 */
  223. /* User can add his own implementation to report the file name and line number,
  224. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  225. /* USER CODE END 6 */
  226.  
  227. }
  228.  
  229. #endif
  230.  
  231. /**
  232. * @}
  233. */
  234.  
  235. /**
  236. * @}
  237. */
  238.  
  239. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement