Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 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. #include "usb_device.h"
  24.  
  25. /* Private includes ----------------------------------------------------------*/
  26. /* USER CODE BEGIN Includes */
  27. #include "usbd_cdc_if.h" // If I don't include this, I get an error of implicit declaration of function CDC_Transmit_FS
  28. /* USER CODE END Includes */
  29.  
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* USER CODE BEGIN PTD */
  32.  
  33. /* USER CODE END PTD */
  34.  
  35. /* Private define ------------------------------------------------------------*/
  36. /* USER CODE BEGIN PD */
  37.  
  38. /* USER CODE END PD */
  39.  
  40. /* Private macro -------------------------------------------------------------*/
  41. /* USER CODE BEGIN PM */
  42.  
  43. /* USER CODE END PM */
  44.  
  45. /* Private variables ---------------------------------------------------------*/
  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. /* USER CODE BEGIN PFP */
  55.  
  56. /* USER CODE END PFP */
  57.  
  58. /* Private user code ---------------------------------------------------------*/
  59. /* USER CODE BEGIN 0 */
  60.  
  61. /* USER CODE END 0 */
  62.  
  63. /**
  64. * @brief The application entry point.
  65. * @retval int
  66. */
  67. int main(void)
  68. {
  69. /* USER CODE BEGIN 1 */
  70.  
  71. /* USER CODE END 1 */
  72.  
  73.  
  74. /* MCU Configuration--------------------------------------------------------*/
  75.  
  76. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  77. HAL_Init();
  78.  
  79. /* USER CODE BEGIN Init */
  80.  
  81. /* USER CODE END Init */
  82.  
  83. /* Configure the system clock */
  84. SystemClock_Config();
  85.  
  86. /* USER CODE BEGIN SysInit */
  87.  
  88. /* USER CODE END SysInit */
  89.  
  90. /* Initialize all configured peripherals */
  91. MX_GPIO_Init();
  92. MX_USB_DEVICE_Init();
  93. /* USER CODE BEGIN 2 */
  94.  
  95. /* USER CODE END 2 */
  96.  
  97. /* Infinite loop */
  98. /* USER CODE BEGIN WHILE */
  99. while (1)
  100. {
  101. unsigned char msg[] = "Hello world!n";
  102. uint8_t returnValue = CDC_Transmit_FS(msg, sizeof(msg));
  103. HAL_Delay(1000);
  104. /* USER CODE END WHILE */
  105.  
  106. /* USER CODE BEGIN 3 */
  107. }
  108. /* USER CODE END 3 */
  109. }
  110.  
  111. /**
  112. * @brief System Clock Configuration
  113. * @retval None
  114. */
  115. void SystemClock_Config(void)
  116. {
  117. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  118. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  119. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  120.  
  121. /** Initializes the CPU, AHB and APB busses clocks
  122. */
  123. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  124. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  125. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  126. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  127. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  128. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  129. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  130. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  131. {
  132. Error_Handler();
  133. }
  134. /** Initializes the CPU, AHB and APB busses clocks
  135. */
  136. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  137. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  138. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  139. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  140. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  141. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  142.  
  143. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  144. {
  145. Error_Handler();
  146. }
  147. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
  148. PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
  149. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  150. {
  151. Error_Handler();
  152. }
  153. }
  154.  
  155. /**
  156. * @brief GPIO Initialization Function
  157. * @param None
  158. * @retval None
  159. */
  160. static void MX_GPIO_Init(void)
  161. {
  162. GPIO_InitTypeDef GPIO_InitStruct = {0};
  163.  
  164. /* GPIO Ports Clock Enable */
  165. __HAL_RCC_GPIOD_CLK_ENABLE();
  166. __HAL_RCC_GPIOB_CLK_ENABLE();
  167. __HAL_RCC_GPIOA_CLK_ENABLE();
  168.  
  169. /*Configure GPIO pin Output Level */
  170. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
  171.  
  172. /*Configure GPIO pin : PB1 */
  173. GPIO_InitStruct.Pin = GPIO_PIN_1;
  174. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  175. GPIO_InitStruct.Pull = GPIO_NOPULL;
  176. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  177. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  178.  
  179. }
  180.  
  181. /* USER CODE BEGIN 4 */
  182.  
  183. /* USER CODE END 4 */
  184.  
  185. /**
  186. * @brief This function is executed in case of error occurrence.
  187. * @retval None
  188. */
  189. void Error_Handler(void)
  190. {
  191. /* USER CODE BEGIN Error_Handler_Debug */
  192. /* User can add his own implementation to report the HAL error return state */
  193.  
  194. /* USER CODE END Error_Handler_Debug */
  195. }
  196.  
  197. #ifdef USE_FULL_ASSERT
  198. /**
  199. * @brief Reports the name of the source file and the source line number
  200. * where the assert_param error has occurred.
  201. * @param file: pointer to the source file name
  202. * @param line: assert_param error line source number
  203. * @retval None
  204. */
  205. void assert_failed(uint8_t *file, uint32_t line)
  206. {
  207. /* USER CODE BEGIN 6 */
  208. /* User can add his own implementation to report the file name and line number,
  209. tex: printf("Wrong parameters value: file %s on line %drn", file, line) */
  210. /* USER CODE END 6 */
  211. }
  212. #endif /* USE_FULL_ASSERT */
  213.  
  214. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement