Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 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 "stm32f4xx_hal.h"
  35. #include <string.h>
  36.  
  37. /* USER CODE BEGIN Includes */
  38.  
  39. /* USER CODE END Includes */
  40.  
  41. /* Private variables ---------------------------------------------------------*/
  42. UART_HandleTypeDef huart2;
  43. GPIO_InitTypeDef GPIO_InitStruct;
  44.  
  45. /* USER CODE BEGIN PV */
  46. /* Private variables ---------------------------------------------------------*/
  47.  
  48. /* USER CODE END PV */
  49.  
  50. /* Private function prototypes -----------------------------------------------*/
  51. void SystemClock_Config(void);
  52. static void MX_GPIO_Init(void);
  53. static void MX_USART2_UART_Init(void);
  54.  
  55. /* USER CODE BEGIN PFP */
  56. /* Private function prototypes -----------------------------------------------*/
  57.  
  58. /* USER CODE END PFP */
  59.  
  60. /* USER CODE BEGIN 0 */
  61.  
  62. /* USER CODE END 0 */
  63.  
  64. int main(void)
  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. MX_USART2_UART_Init();
  82.  
  83. /* USER CODE BEGIN 2 */
  84.  
  85. /* USER CODE END 2 */
  86.  
  87. /* Infinite loop */
  88. /* USER CODE BEGIN WHILE */
  89. while (1)
  90. {
  91. /* USER CODE END WHILE */
  92. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
  93. HAL_UART_Transmit(&huart2, (uint8_t*)"Z", strlen("Z"), HAL_MAX_DELAY);
  94. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
  95. /* USER CODE BEGIN 3 */
  96.  
  97. }
  98. /* USER CODE END 3 */
  99.  
  100. }
  101.  
  102. /** System Clock Configuration
  103. */
  104. void SystemClock_Config(void)
  105. {
  106.  
  107. RCC_OscInitTypeDef RCC_OscInitStruct;
  108. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  109.  
  110. __HAL_RCC_PWR_CLK_ENABLE();
  111.  
  112. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  113.  
  114. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  115. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  116. RCC_OscInitStruct.HSICalibrationValue = 16;
  117. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  118. HAL_RCC_OscConfig(&RCC_OscInitStruct);
  119.  
  120. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  121. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  122. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  123. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  124. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  125. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  126. HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
  127.  
  128. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  129.  
  130. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  131.  
  132. /* SysTick_IRQn interrupt configuration */
  133. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  134. }
  135.  
  136. /* USART2 init function */
  137. void MX_USART2_UART_Init(void)
  138. {
  139.  
  140. huart2.Instance = USART2;
  141. huart2.Init.BaudRate = 9600;
  142. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  143. huart2.Init.StopBits = UART_STOPBITS_1;
  144. huart2.Init.Parity = UART_PARITY_NONE;
  145. huart2.Init.Mode = UART_MODE_TX_RX;
  146. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  147. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  148. HAL_UART_Init(&huart2);
  149.  
  150. }
  151.  
  152. /** Pinout Configuration
  153. */
  154. void MX_GPIO_Init(void)
  155. {
  156.  
  157. /* GPIO Ports Clock Enable */
  158. __HAL_RCC_GPIOA_CLK_ENABLE();
  159. __HAL_RCC_GPIOD_CLK_ENABLE();
  160. //
  161. /*Configure GPIO pin : PD13 */
  162. GPIO_InitStruct.Pin = GPIO_PIN_13 ;
  163. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  164. GPIO_InitStruct.Pull = GPIO_NOPULL;
  165. GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  166. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  167.  
  168. }
  169.  
  170. /* USER CODE BEGIN 4 */
  171.  
  172. /* USER CODE END 4 */
  173.  
  174. #ifdef USE_FULL_ASSERT
  175.  
  176. /**
  177. * @brief Reports the name of the source file and the source line number
  178. * where the assert_param error has occurred.
  179. * @param file: pointer to the source file name
  180. * @param line: assert_param error line source number
  181. * @retval None
  182. */
  183. void assert_failed(uint8_t* file, uint32_t line)
  184. {
  185. /* USER CODE BEGIN 6 */
  186. /* User can add his own implementation to report the file name and line number,
  187. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  188. /* USER CODE END 6 */
  189.  
  190. }
  191.  
  192. #endif
  193.  
  194. /**
  195. * @}
  196. */
  197.  
  198. /**
  199. * @}
  200. */
  201.  
  202. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement