Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.27 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.  
  46. /* USER CODE BEGIN PV */
  47.  
  48. /* USER CODE END PV */
  49.  
  50. /* Private function prototypes -----------------------------------------------*/
  51. void SystemClock_Config(void);
  52. static void MX_GPIO_Init(void);
  53. /* USER CODE BEGIN PFP */
  54.  
  55. /* USER CODE END PFP */
  56.  
  57. /* Private user code ---------------------------------------------------------*/
  58. /* USER CODE BEGIN 0 */
  59.  
  60. /* USER CODE END 0 */
  61.  
  62. /**
  63. * @brief The application entry point.
  64. * @retval int
  65. */
  66. int main(void)
  67. {
  68. /* USER CODE BEGIN 1 */
  69.  
  70. /* USER CODE END 1 */
  71.  
  72.  
  73. /* MCU Configuration--------------------------------------------------------*/
  74.  
  75. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  76. HAL_Init();
  77.  
  78. /* USER CODE BEGIN Init */
  79.  
  80. /* USER CODE END Init */
  81.  
  82. /* Configure the system clock */
  83. SystemClock_Config();
  84.  
  85. /* USER CODE BEGIN SysInit */
  86.  
  87. /* USER CODE END SysInit */
  88.  
  89. /* Initialize all configured peripherals */
  90. MX_GPIO_Init();
  91. /* USER CODE BEGIN 2 */
  92.  
  93. /* USER CODE END 2 */
  94.  
  95.  
  96.  
  97. //vklop gumba in ledic
  98. __HAL_RCC_GPIOD_CLK_ENABLE();
  99. __HAL_RCC_GPIOB_CLK_ENABLE();
  100. //inicializacija gumba
  101.  
  102.  
  103. //inicializacija ledic
  104.  
  105. GPIO_InitTypeDef init_structure1;
  106. init_structure1.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  107. init_structure1.Mode = GPIO_MODE_OUTPUT_PP;
  108. init_structure1.Pull = GPIO_NOPULL;
  109. init_structure1.Speed = GPIO_SPEED_FREQ_LOW;
  110.  
  111. HAL_GPIO_Init(GPIOD, &init_structure1);
  112.  
  113. //inicializacija naprave B
  114. GPIO_InitTypeDef init_structure2;
  115. init_structure2.Pin = GPIO_PIN_1;
  116. init_structure2.Mode = GPIO_MODE_IT_RISING;
  117. init_structure2.Pull = GPIO_NOPULL;
  118. init_structure2.Speed = GPIO_SPEED_FREQ_LOW;
  119.  
  120. HAL_GPIO_Init(GPIOB, &init_structure2);
  121.  
  122. //uint32_t bit_position = (uint32_t) ((uint32_t) GPIO_addr - (uint32_t) GPIOAd) / 0x400;
  123.  
  124. //inicializacija NVIC
  125. HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
  126. HAL_NVIC_EnableIRQ(EXTI1_IRQn);
  127. /* Infinite loop */
  128. /* USER CODE BEGIN WHILE */
  129. while (1)
  130. {
  131. /* USER CODE END WHILE */
  132.  
  133. /* USER CODE BEGIN 3 */
  134. }
  135. /* USER CODE END 3 */
  136. }
  137.  
  138. /**
  139. * @brief System Clock Configuration
  140. * @retval None
  141. */
  142. void SystemClock_Config(void)
  143. {
  144. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  145. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  146.  
  147. /** Configure the main internal regulator output voltage
  148. */
  149. __HAL_RCC_PWR_CLK_ENABLE();
  150. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  151. /** Initializes the CPU, AHB and APB busses clocks
  152. */
  153. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  154. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  155. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  156. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  157. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  158. RCC_OscInitStruct.PLL.PLLM = 8;
  159. RCC_OscInitStruct.PLL.PLLN = 50;
  160. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  161. RCC_OscInitStruct.PLL.PLLQ = 7;
  162. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  163. {
  164. Error_Handler();
  165. }
  166. /** Initializes the CPU, AHB and APB busses clocks
  167. */
  168. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  169. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  170. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  171. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  172. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
  173. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
  174.  
  175. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  176. {
  177. Error_Handler();
  178. }
  179. }
  180.  
  181. /**
  182. * @brief GPIO Initialization Function
  183. * @param None
  184. * @retval None
  185. */
  186. static void MX_GPIO_Init(void)
  187. {
  188. GPIO_InitTypeDef GPIO_InitStruct = {0};
  189.  
  190. /* GPIO Ports Clock Enable */
  191. __HAL_RCC_GPIOE_CLK_ENABLE();
  192. __HAL_RCC_GPIOC_CLK_ENABLE();
  193. __HAL_RCC_GPIOH_CLK_ENABLE();
  194. __HAL_RCC_GPIOA_CLK_ENABLE();
  195. __HAL_RCC_GPIOB_CLK_ENABLE();
  196. __HAL_RCC_GPIOD_CLK_ENABLE();
  197.  
  198. /*Configure GPIO pin Output Level */
  199. HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin, GPIO_PIN_RESET);
  200.  
  201. /*Configure GPIO pin Output Level */
  202. HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET);
  203.  
  204. /*Configure GPIO pin Output Level */
  205. HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
  206. |Audio_RST_Pin, GPIO_PIN_RESET);
  207.  
  208. /*Configure GPIO pin : CS_I2C_SPI_Pin */
  209. GPIO_InitStruct.Pin = CS_I2C_SPI_Pin;
  210. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  211. GPIO_InitStruct.Pull = GPIO_NOPULL;
  212. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  213. HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct);
  214.  
  215. /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
  216. GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
  217. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  218. GPIO_InitStruct.Pull = GPIO_NOPULL;
  219. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  220. HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);
  221.  
  222. /*Configure GPIO pin : PDM_OUT_Pin */
  223. GPIO_InitStruct.Pin = PDM_OUT_Pin;
  224. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  225. GPIO_InitStruct.Pull = GPIO_NOPULL;
  226. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  227. GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  228. HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct);
  229.  
  230. /*Configure GPIO pin : B1_Pin */
  231. GPIO_InitStruct.Pin = B1_Pin;
  232. GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  233. GPIO_InitStruct.Pull = GPIO_NOPULL;
  234. HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
  235.  
  236. /*Configure GPIO pin : I2S3_WS_Pin */
  237. GPIO_InitStruct.Pin = I2S3_WS_Pin;
  238. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  239. GPIO_InitStruct.Pull = GPIO_NOPULL;
  240. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  241. GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  242. HAL_GPIO_Init(I2S3_WS_GPIO_Port, &GPIO_InitStruct);
  243.  
  244. /*Configure GPIO pins : SPI1_SCK_Pin SPI1_MISO_Pin SPI1_MOSI_Pin */
  245. GPIO_InitStruct.Pin = SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin;
  246. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  247. GPIO_InitStruct.Pull = GPIO_NOPULL;
  248. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  249. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  250. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  251.  
  252. /*Configure GPIO pin : BOOT1_Pin */
  253. GPIO_InitStruct.Pin = BOOT1_Pin;
  254. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  255. GPIO_InitStruct.Pull = GPIO_NOPULL;
  256. HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
  257.  
  258. /*Configure GPIO pin : CLK_IN_Pin */
  259. GPIO_InitStruct.Pin = CLK_IN_Pin;
  260. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  261. GPIO_InitStruct.Pull = GPIO_NOPULL;
  262. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  263. GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  264. HAL_GPIO_Init(CLK_IN_GPIO_Port, &GPIO_InitStruct);
  265.  
  266. /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin
  267. Audio_RST_Pin */
  268. GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
  269. |Audio_RST_Pin;
  270. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  271. GPIO_InitStruct.Pull = GPIO_NOPULL;
  272. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  273. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  274.  
  275. /*Configure GPIO pins : I2S3_MCK_Pin I2S3_SCK_Pin I2S3_SD_Pin */
  276. GPIO_InitStruct.Pin = I2S3_MCK_Pin|I2S3_SCK_Pin|I2S3_SD_Pin;
  277. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  278. GPIO_InitStruct.Pull = GPIO_NOPULL;
  279. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  280. GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  281. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  282.  
  283. /*Configure GPIO pin : VBUS_FS_Pin */
  284. GPIO_InitStruct.Pin = VBUS_FS_Pin;
  285. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  286. GPIO_InitStruct.Pull = GPIO_NOPULL;
  287. HAL_GPIO_Init(VBUS_FS_GPIO_Port, &GPIO_InitStruct);
  288.  
  289. /*Configure GPIO pins : OTG_FS_ID_Pin OTG_FS_DM_Pin OTG_FS_DP_Pin */
  290. GPIO_InitStruct.Pin = OTG_FS_ID_Pin|OTG_FS_DM_Pin|OTG_FS_DP_Pin;
  291. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  292. GPIO_InitStruct.Pull = GPIO_NOPULL;
  293. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  294. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  295. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  296.  
  297. /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
  298. GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
  299. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  300. GPIO_InitStruct.Pull = GPIO_NOPULL;
  301. HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  302.  
  303. /*Configure GPIO pins : Audio_SCL_Pin Audio_SDA_Pin */
  304. GPIO_InitStruct.Pin = Audio_SCL_Pin|Audio_SDA_Pin;
  305. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  306. GPIO_InitStruct.Pull = GPIO_PULLUP;
  307. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  308. GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
  309. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  310.  
  311. /*Configure GPIO pin : MEMS_INT2_Pin */
  312. GPIO_InitStruct.Pin = MEMS_INT2_Pin;
  313. GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  314. GPIO_InitStruct.Pull = GPIO_NOPULL;
  315. HAL_GPIO_Init(MEMS_INT2_GPIO_Port, &GPIO_InitStruct);
  316.  
  317. }
  318.  
  319. /* USER CODE BEGIN 4 */
  320.  
  321. /* USER CODE END 4 */
  322.  
  323. /**
  324. * @brief This function is executed in case of error occurrence.
  325. * @retval None
  326. */
  327. void Error_Handler(void)
  328. {
  329. /* USER CODE BEGIN Error_Handler_Debug */
  330. /* User can add his own implementation to report the HAL error return state */
  331.  
  332. /* USER CODE END Error_Handler_Debug */
  333. }
  334.  
  335. #ifdef USE_FULL_ASSERT
  336. /**
  337. * @brief Reports the name of the source file and the source line number
  338. * where the assert_param error has occurred.
  339. * @param file: pointer to the source file name
  340. * @param line: assert_param error line source number
  341. * @retval None
  342. */
  343. void assert_failed(uint8_t *file, uint32_t line)
  344. {
  345. /* USER CODE BEGIN 6 */
  346. /* User can add his own implementation to report the file name and line number,
  347. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  348. /* USER CODE END 6 */
  349. }
  350. #endif /* USE_FULL_ASSERT */
  351.  
  352. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement