Rev 12 | Rev 14 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 12 | Rev 13 | ||
|---|---|---|---|
| Line 17... | Line 17... | ||
| 17 | ****************************************************************************** |
17 | ****************************************************************************** |
| 18 | */ |
18 | */ |
| 19 | /* USER CODE END Header */ |
19 | /* USER CODE END Header */ |
| 20 | /* Includes ------------------------------------------------------------------*/ |
20 | /* Includes ------------------------------------------------------------------*/ |
| 21 | #include "main.h" |
21 | #include "main.h" |
| - | 22 | #include "usb_device.h" |
|
| 22 | 23 | ||
| 23 | /* Private includes ----------------------------------------------------------*/ |
24 | /* Private includes ----------------------------------------------------------*/ |
| 24 | /* USER CODE BEGIN Includes */ |
25 | /* USER CODE BEGIN Includes */ |
| 25 | #include "libSerial/serial.h" |
26 | #include "libSerial/serial.h" |
| 26 | #include "libBMP280/bmp280.h" |
27 | #include "libBMP280/bmp280.h" |
| Line 40... | Line 41... | ||
| 40 | /* USER CODE BEGIN PM */ |
41 | /* USER CODE BEGIN PM */ |
| 41 | 42 | ||
| 42 | /* USER CODE END PM */ |
43 | /* USER CODE END PM */ |
| 43 | 44 | ||
| 44 | /* Private variables ---------------------------------------------------------*/ |
45 | /* Private variables ---------------------------------------------------------*/ |
| 45 | CAN_HandleTypeDef hcan; |
- | |
| 46 | - | ||
| 47 | I2C_HandleTypeDef hi2c2; |
46 | I2C_HandleTypeDef hi2c2; |
| 48 | 47 | ||
| - | 48 | RTC_HandleTypeDef hrtc; |
|
| - | 49 | ||
| 49 | SPI_HandleTypeDef hspi1; |
50 | SPI_HandleTypeDef hspi1; |
| 50 | 51 | ||
| 51 | TIM_HandleTypeDef htim3; |
52 | TIM_HandleTypeDef htim3; |
| 52 | TIM_HandleTypeDef htim4; |
53 | TIM_HandleTypeDef htim4; |
| 53 | 54 | ||
| Line 102... | Line 103... | ||
| 102 | /* USER CODE END PV */ |
103 | /* USER CODE END PV */ |
| 103 | 104 | ||
| 104 | /* Private function prototypes -----------------------------------------------*/ |
105 | /* Private function prototypes -----------------------------------------------*/ |
| 105 | void SystemClock_Config(void); |
106 | void SystemClock_Config(void); |
| 106 | static void MX_GPIO_Init(void); |
107 | static void MX_GPIO_Init(void); |
| 107 | static void MX_CAN_Init(void); |
- | |
| 108 | static void MX_SPI1_Init(void); |
108 | static void MX_SPI1_Init(void); |
| 109 | static void MX_TIM4_Init(void); |
109 | static void MX_TIM4_Init(void); |
| 110 | static void MX_USART1_UART_Init(void); |
110 | static void MX_USART1_UART_Init(void); |
| 111 | static void MX_TIM3_Init(void); |
111 | static void MX_TIM3_Init(void); |
| 112 | static void MX_I2C2_Init(void); |
112 | static void MX_I2C2_Init(void); |
| - | 113 | static void MX_RTC_Init(void); |
|
| 113 | /* USER CODE BEGIN PFP */ |
114 | /* USER CODE BEGIN PFP */ |
| 114 | 115 | ||
| 115 | /* USER CODE END PFP */ |
116 | /* USER CODE END PFP */ |
| 116 | 117 | ||
| 117 | /* Private user code ---------------------------------------------------------*/ |
118 | /* Private user code ---------------------------------------------------------*/ |
| Line 145... | Line 146... | ||
| 145 | 146 | ||
| 146 | /* USER CODE END SysInit */ |
147 | /* USER CODE END SysInit */ |
| 147 | 148 | ||
| 148 | /* Initialize all configured peripherals */ |
149 | /* Initialize all configured peripherals */ |
| 149 | MX_GPIO_Init(); |
150 | MX_GPIO_Init(); |
| 150 | MX_CAN_Init(); |
- | |
| 151 | MX_SPI1_Init(); |
151 | MX_SPI1_Init(); |
| 152 | MX_TIM4_Init(); |
152 | MX_TIM4_Init(); |
| 153 | MX_USART1_UART_Init(); |
153 | MX_USART1_UART_Init(); |
| 154 | MX_TIM3_Init(); |
154 | MX_TIM3_Init(); |
| 155 | MX_I2C2_Init(); |
155 | MX_I2C2_Init(); |
| - | 156 | MX_RTC_Init(); |
|
| - | 157 | MX_USB_DEVICE_Init(); |
|
| 156 | /* USER CODE BEGIN 2 */ |
158 | /* USER CODE BEGIN 2 */ |
| 157 | __HAL_RCC_USART1_CLK_ENABLE(); |
159 | __HAL_RCC_USART1_CLK_ENABLE(); |
| 158 | /* setup the USART control blocks */ |
160 | /* setup the USART control blocks */ |
| 159 | init_usart_ctl (&uc1, &huart1); |
161 | init_usart_ctl (&uc1, &huart1); |
| 160 | 162 | ||
| Line 216... | Line 218... | ||
| 216 | */ |
218 | */ |
| 217 | void SystemClock_Config(void) |
219 | void SystemClock_Config(void) |
| 218 | { |
220 | { |
| 219 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
221 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| 220 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
222 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| - | 223 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
|
| 221 | 224 | ||
| 222 | /** Initializes the RCC Oscillators according to the specified parameters |
225 | /** Initializes the RCC Oscillators according to the specified parameters |
| 223 | * in the RCC_OscInitTypeDef structure. |
226 | * in the RCC_OscInitTypeDef structure. |
| 224 | */ |
227 | */ |
| 225 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
228 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE; |
| 226 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
229 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 227 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
230 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
| - | 231 | RCC_OscInitStruct.LSEState = RCC_LSE_ON; |
|
| 228 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
232 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
| 229 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
233 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 230 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
234 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 231 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL8; |
235 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
| 232 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
236 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| 233 | { |
237 | { |
| 234 | Error_Handler(); |
238 | Error_Handler(); |
| 235 | } |
239 | } |
| 236 | /** Initializes the CPU, AHB and APB buses clocks |
240 | /** Initializes the CPU, AHB and APB buses clocks |
| Line 244... | Line 248... | ||
| 244 | 248 | ||
| 245 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
249 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
| 246 | { |
250 | { |
| 247 | Error_Handler(); |
251 | Error_Handler(); |
| 248 | } |
252 | } |
| 249 | } |
- | |
| 250 | - | ||
| 251 | /** |
- | |
| 252 | * @brief CAN Initialization Function |
- | |
| 253 | * @param None |
- | |
| 254 | * @retval None |
- | |
| 255 | */ |
- | |
| 256 | static void MX_CAN_Init(void) |
- | |
| 257 | { |
- | |
| 258 | - | ||
| 259 | /* USER CODE BEGIN CAN_Init 0 */ |
- | |
| 260 | - | ||
| 261 | /* USER CODE END CAN_Init 0 */ |
- | |
| 262 | - | ||
| 263 | /* USER CODE BEGIN CAN_Init 1 */ |
- | |
| 264 | - | ||
| 265 | /* USER CODE END CAN_Init 1 */ |
- | |
| 266 | hcan.Instance = CAN1; |
- | |
| 267 | hcan.Init.Prescaler = 16; |
- | |
| 268 | hcan.Init.Mode = CAN_MODE_NORMAL; |
253 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USB; |
| 269 | hcan.Init.SyncJumpWidth = CAN_SJW_1TQ; |
- | |
| 270 | hcan.Init.TimeSeg1 = CAN_BS1_1TQ; |
- | |
| 271 | hcan.Init.TimeSeg2 = CAN_BS2_1TQ; |
- | |
| 272 | hcan.Init.TimeTriggeredMode = DISABLE; |
254 | PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; |
| 273 | hcan.Init.AutoBusOff = DISABLE; |
- | |
| 274 | hcan.Init.AutoWakeUp = DISABLE; |
- | |
| 275 | hcan.Init.AutoRetransmission = DISABLE; |
255 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; |
| 276 | hcan.Init.ReceiveFifoLocked = DISABLE; |
- | |
| 277 | hcan.Init.TransmitFifoPriority = DISABLE; |
- | |
| 278 | if (HAL_CAN_Init(&hcan) != HAL_OK) |
256 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
| 279 | { |
257 | { |
| 280 | Error_Handler(); |
258 | Error_Handler(); |
| 281 | } |
259 | } |
| 282 | /* USER CODE BEGIN CAN_Init 2 */ |
- | |
| 283 | - | ||
| 284 | /* USER CODE END CAN_Init 2 */ |
- | |
| 285 | - | ||
| 286 | } |
260 | } |
| 287 | 261 | ||
| 288 | /** |
262 | /** |
| 289 | * @brief I2C2 Initialization Function |
263 | * @brief I2C2 Initialization Function |
| 290 | * @param None |
264 | * @param None |
| Line 318... | Line 292... | ||
| 318 | /* USER CODE END I2C2_Init 2 */ |
292 | /* USER CODE END I2C2_Init 2 */ |
| 319 | 293 | ||
| 320 | } |
294 | } |
| 321 | 295 | ||
| 322 | /** |
296 | /** |
| - | 297 | * @brief RTC Initialization Function |
|
| - | 298 | * @param None |
|
| - | 299 | * @retval None |
|
| - | 300 | */ |
|
| - | 301 | static void MX_RTC_Init(void) |
|
| - | 302 | { |
|
| - | 303 | ||
| - | 304 | /* USER CODE BEGIN RTC_Init 0 */ |
|
| - | 305 | ||
| - | 306 | /* USER CODE END RTC_Init 0 */ |
|
| - | 307 | ||
| - | 308 | RTC_TimeTypeDef sTime = {0}; |
|
| - | 309 | RTC_DateTypeDef DateToUpdate = {0}; |
|
| - | 310 | ||
| - | 311 | /* USER CODE BEGIN RTC_Init 1 */ |
|
| - | 312 | ||
| - | 313 | /* USER CODE END RTC_Init 1 */ |
|
| - | 314 | /** Initialize RTC Only |
|
| - | 315 | */ |
|
| - | 316 | hrtc.Instance = RTC; |
|
| - | 317 | hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND; |
|
| - | 318 | hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM; |
|
| - | 319 | if (HAL_RTC_Init(&hrtc) != HAL_OK) |
|
| - | 320 | { |
|
| - | 321 | Error_Handler(); |
|
| - | 322 | } |
|
| - | 323 | ||
| - | 324 | /* USER CODE BEGIN Check_RTC_BKUP */ |
|
| - | 325 | ||
| - | 326 | /* USER CODE END Check_RTC_BKUP */ |
|
| - | 327 | ||
| - | 328 | /** Initialize RTC and set the Time and Date |
|
| - | 329 | */ |
|
| - | 330 | sTime.Hours = 0x0; |
|
| - | 331 | sTime.Minutes = 0x0; |
|
| - | 332 | sTime.Seconds = 0x0; |
|
| - | 333 | ||
| - | 334 | if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) |
|
| - | 335 | { |
|
| - | 336 | Error_Handler(); |
|
| - | 337 | } |
|
| - | 338 | DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY; |
|
| - | 339 | DateToUpdate.Month = RTC_MONTH_JANUARY; |
|
| - | 340 | DateToUpdate.Date = 0x1; |
|
| - | 341 | DateToUpdate.Year = 0x0; |
|
| - | 342 | ||
| - | 343 | if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK) |
|
| - | 344 | { |
|
| - | 345 | Error_Handler(); |
|
| - | 346 | } |
|
| - | 347 | /* USER CODE BEGIN RTC_Init 2 */ |
|
| - | 348 | ||
| - | 349 | /* USER CODE END RTC_Init 2 */ |
|
| - | 350 | ||
| - | 351 | } |
|
| - | 352 | ||
| - | 353 | /** |
|
| 323 | * @brief SPI1 Initialization Function |
354 | * @brief SPI1 Initialization Function |
| 324 | * @param None |
355 | * @param None |
| 325 | * @retval None |
356 | * @retval None |
| 326 | */ |
357 | */ |
| 327 | static void MX_SPI1_Init(void) |
358 | static void MX_SPI1_Init(void) |
| Line 505... | Line 536... | ||
| 505 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
536 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
| 506 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
537 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 507 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
538 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| 508 | 539 | ||
| 509 | /*Configure GPIO pin Output Level */ |
540 | /*Configure GPIO pin Output Level */ |
| 510 | HAL_GPIO_WritePin(GPIOC, SPI_CD_Pin|SPI_RESET_Pin, GPIO_PIN_RESET); |
541 | HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin|SPI_RESET_Pin|SPI_NSS1_Pin, GPIO_PIN_RESET); |
| 511 | - | ||
| 512 | /*Configure GPIO pin Output Level */ |
- | |
| 513 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_RESET); |
- | |
| 514 | - | ||
| 515 | /*Configure GPIO pins : SPI_CD_Pin SPI_RESET_Pin */ |
- | |
| 516 | GPIO_InitStruct.Pin = SPI_CD_Pin|SPI_RESET_Pin; |
- | |
| 517 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
- | |
| 518 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
- | |
| 519 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
- | |
| 520 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
- | |
| 521 | 542 | ||
| 522 | /*Configure GPIO pin : SPI_NSS1_Pin */ |
543 | /*Configure GPIO pins : SPI_CD_Pin SPI_RESET_Pin SPI_NSS1_Pin */ |
| 523 | GPIO_InitStruct.Pin = SPI_NSS1_Pin; |
544 | GPIO_InitStruct.Pin = SPI_CD_Pin|SPI_RESET_Pin|SPI_NSS1_Pin; |
| 524 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
545 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 525 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
546 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 526 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
547 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 527 | HAL_GPIO_Init(SPI_NSS1_GPIO_Port, &GPIO_InitStruct); |
548 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 528 | 549 | ||
| 529 | } |
550 | } |
| 530 | 551 | ||
| 531 | /* USER CODE BEGIN 4 */ |
552 | /* USER CODE BEGIN 4 */ |
| 532 | 553 | ||