Rev 2 | Rev 4 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 3 | ||
|---|---|---|---|
| Line 20... | Line 20... | ||
| 20 | /* Includes ------------------------------------------------------------------*/ |
20 | /* Includes ------------------------------------------------------------------*/ |
| 21 | #include "main.h" |
21 | #include "main.h" |
| 22 | 22 | ||
| 23 | /* Private includes ----------------------------------------------------------*/ |
23 | /* Private includes ----------------------------------------------------------*/ |
| 24 | /* USER CODE BEGIN Includes */ |
24 | /* USER CODE BEGIN Includes */ |
| - | 25 | #include "display.h" |
|
| - | 26 | ||
| 25 | #include "string.h" |
27 | #include "string.h" |
| 26 | #include "base64.h" |
28 | #include "base64.h" |
| 27 | #include "libSerial/serial.H" |
29 | #include "libSerial/serial.H" |
| - | 30 | #include "libSerial/serialUtils.H" |
|
| 28 | #include "libSmallPrintf/small_printf.h" |
31 | #include "libSmallPrintf/small_printf.h" |
| 29 | 32 | ||
| 30 | /* USER CODE END Includes */ |
33 | /* USER CODE END Includes */ |
| 31 | 34 | ||
| 32 | /* Private typedef -----------------------------------------------------------*/ |
35 | /* Private typedef -----------------------------------------------------------*/ |
| Line 65... | Line 68... | ||
| 65 | /* USER CODE END PM */ |
68 | /* USER CODE END PM */ |
| 66 | 69 | ||
| 67 | /* Private variables ---------------------------------------------------------*/ |
70 | /* Private variables ---------------------------------------------------------*/ |
| 68 | CAN_HandleTypeDef hcan; |
71 | CAN_HandleTypeDef hcan; |
| 69 | 72 | ||
| - | 73 | SPI_HandleTypeDef hspi1; |
|
| - | 74 | ||
| 70 | UART_HandleTypeDef huart1; |
75 | UART_HandleTypeDef huart1; |
| 71 | 76 | ||
| 72 | /* USER CODE BEGIN PV */ |
77 | /* USER CODE BEGIN PV */ |
| 73 | 78 | ||
| 74 | /* USER CODE END PV */ |
79 | /* USER CODE END PV */ |
| Line 76... | Line 81... | ||
| 76 | /* Private function prototypes -----------------------------------------------*/ |
81 | /* Private function prototypes -----------------------------------------------*/ |
| 77 | void SystemClock_Config(void); |
82 | void SystemClock_Config(void); |
| 78 | static void MX_GPIO_Init(void); |
83 | static void MX_GPIO_Init(void); |
| 79 | static void MX_CAN_Init(void); |
84 | static void MX_CAN_Init(void); |
| 80 | static void MX_USART1_UART_Init(void); |
85 | static void MX_USART1_UART_Init(void); |
| - | 86 | static void MX_SPI1_Init(void); |
|
| 81 | /* USER CODE BEGIN PFP */ |
87 | /* USER CODE BEGIN PFP */ |
| 82 | 88 | ||
| 83 | /* USER CODE END PFP */ |
89 | /* USER CODE END PFP */ |
| 84 | 90 | ||
| 85 | /* Private user code ---------------------------------------------------------*/ |
91 | /* Private user code ---------------------------------------------------------*/ |
| Line 293... | Line 299... | ||
| 293 | 299 | ||
| 294 | /* Configure the system clock */ |
300 | /* Configure the system clock */ |
| 295 | SystemClock_Config(); |
301 | SystemClock_Config(); |
| 296 | 302 | ||
| 297 | /* USER CODE BEGIN SysInit */ |
303 | /* USER CODE BEGIN SysInit */ |
| - | 304 | cc_init(); |
|
| 298 | 305 | ||
| 299 | /* USER CODE END SysInit */ |
306 | /* USER CODE END SysInit */ |
| 300 | 307 | ||
| 301 | /* Initialize all configured peripherals */ |
308 | /* Initialize all configured peripherals */ |
| 302 | MX_GPIO_Init(); |
309 | MX_GPIO_Init(); |
| 303 | MX_CAN_Init(); |
310 | MX_CAN_Init(); |
| 304 | MX_USART1_UART_Init(); |
311 | MX_USART1_UART_Init(); |
| - | 312 | MX_SPI1_Init(); |
|
| 305 | /* USER CODE BEGIN 2 */ |
313 | /* USER CODE BEGIN 2 */ |
| 306 | 314 | ||
| 307 | HAL_CAN_Start(&hcan); |
315 | HAL_CAN_Start(&hcan); |
| 308 | 316 | ||
| 309 | init_usart_ctl(&uc1, &huart1); |
317 | init_usart_ctl(&uc1, &huart1); |
| Line 316... | Line 324... | ||
| 316 | // send out a version string on the serial port |
324 | // send out a version string on the serial port |
| 317 | sendString(&uc1, (char *)version, sizeof(version)); |
325 | sendString(&uc1, (char *)version, sizeof(version)); |
| 318 | 326 | ||
| 319 | uint32_t sendTime = HAL_GetTick() + 1000; |
327 | uint32_t sendTime = HAL_GetTick() + 1000; |
| 320 | char cmdBuff[100]; |
328 | char cmdBuff[100]; |
| - | 329 | ||
| - | 330 | // serial utils library command editor |
|
| 321 | int cmdPos = 0; |
331 | editBuffer cmdEdit; |
| - | 332 | ||
| - | 333 | initReadLine( &cmdEdit, cmdBuff, 100, READLINES_CR); |
|
| 322 | 334 | ||
| 323 | for (int i = 0; i < CONTEXTS; ++i) |
335 | for (int i = 0; i < CONTEXTS; ++i) |
| 324 | resetContext(&contexts[i]); |
336 | resetContext(&contexts[i]); |
| 325 | 337 | ||
| 326 | /* USER CODE END 2 */ |
338 | /* USER CODE END 2 */ |
| Line 330... | Line 342... | ||
| 330 | while (1) |
342 | while (1) |
| 331 | { |
343 | { |
| 332 | /* USER CODE END WHILE */ |
344 | /* USER CODE END WHILE */ |
| 333 | 345 | ||
| 334 | /* USER CODE BEGIN 3 */ |
346 | /* USER CODE BEGIN 3 */ |
| 335 | if (SerialCharsReceived(&uc1)) |
- | |
| 336 | { |
347 | |
| 337 | cmdBuff[cmdPos] = GetCharSerial(&uc1); |
348 | editBufferReturn ret = readLine(&uc1, &cmdEdit); |
| - | 349 | ||
| 338 | if (cmdBuff[cmdPos] == '\n') |
350 | if (ret == EDIT_CR) |
| 339 | { |
351 | { |
| 340 | processCmd(cmdBuff, cmdPos); |
352 | processCmd (cmdBuff,charCount(&cmdEdit)); |
| 341 | cmdPos = 0; |
- | |
| 342 | } |
- | |
| 343 | else |
- | |
| 344 | cmdPos++; |
- | |
| 345 | } |
353 | } |
| 346 | 354 | ||
| 347 | if (HAL_GetTick() > sendTime) |
355 | if (HAL_GetTick() > sendTime) |
| 348 | { |
356 | { |
| 349 | sendTime += 1000; |
357 | sendTime += 1000; |
| 350 | heartBeat(); |
358 | heartBeat(); |
| - | 359 | cc_display(2); |
|
| 351 | } |
360 | } |
| 352 | 361 | ||
| 353 | uint32_t old = HAL_GetTick() - 750; |
- | |
| 354 | for (int i = 0; i < CONTEXTS; ++i) |
362 | for (int i = 0; i < CONTEXTS; ++i) |
| 355 | { |
363 | { |
| 356 | contextType *ctx = &contexts[i]; |
364 | contextType *ctx = &contexts[i]; |
| 357 | /// check for too old |
365 | /// check for too old |
| 358 | // if (ctx->status == ACCEPT && ctx->payloadTimestamp < old) |
366 | // if (ctx->status == ACCEPT && ctx->payloadTimestamp < old) |
| Line 498... | Line 506... | ||
| 498 | 506 | ||
| 499 | /* USER CODE END CAN_Init 2 */ |
507 | /* USER CODE END CAN_Init 2 */ |
| 500 | } |
508 | } |
| 501 | 509 | ||
| 502 | /** |
510 | /** |
| - | 511 | * @brief SPI1 Initialization Function |
|
| - | 512 | * @param None |
|
| - | 513 | * @retval None |
|
| - | 514 | */ |
|
| - | 515 | static void MX_SPI1_Init(void) |
|
| - | 516 | { |
|
| - | 517 | ||
| - | 518 | /* USER CODE BEGIN SPI1_Init 0 */ |
|
| - | 519 | ||
| - | 520 | /* USER CODE END SPI1_Init 0 */ |
|
| - | 521 | ||
| - | 522 | /* USER CODE BEGIN SPI1_Init 1 */ |
|
| - | 523 | ||
| - | 524 | /* USER CODE END SPI1_Init 1 */ |
|
| - | 525 | /* SPI1 parameter configuration*/ |
|
| - | 526 | hspi1.Instance = SPI1; |
|
| - | 527 | hspi1.Init.Mode = SPI_MODE_MASTER; |
|
| - | 528 | hspi1.Init.Direction = SPI_DIRECTION_2LINES; |
|
| - | 529 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
|
| - | 530 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; |
|
| - | 531 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
|
| - | 532 | hspi1.Init.NSS = SPI_NSS_SOFT; |
|
| - | 533 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
|
| - | 534 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
|
| - | 535 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
|
| - | 536 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
|
| - | 537 | hspi1.Init.CRCPolynomial = 10; |
|
| - | 538 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
|
| - | 539 | { |
|
| - | 540 | Error_Handler(); |
|
| - | 541 | } |
|
| - | 542 | /* USER CODE BEGIN SPI1_Init 2 */ |
|
| - | 543 | ||
| - | 544 | /* USER CODE END SPI1_Init 2 */ |
|
| - | 545 | } |
|
| - | 546 | ||
| - | 547 | /** |
|
| 503 | * @brief USART1 Initialization Function |
548 | * @brief USART1 Initialization Function |
| 504 | * @param None |
549 | * @param None |
| 505 | * @retval None |
550 | * @retval None |
| 506 | */ |
551 | */ |
| 507 | static void MX_USART1_UART_Init(void) |
552 | static void MX_USART1_UART_Init(void) |
| Line 537... | Line 582... | ||
| 537 | * @retval None |
582 | * @retval None |
| 538 | */ |
583 | */ |
| 539 | static void MX_GPIO_Init(void) |
584 | static void MX_GPIO_Init(void) |
| 540 | { |
585 | { |
| 541 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
586 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| - | 587 | /* USER CODE BEGIN MX_GPIO_Init_1 */ |
|
| - | 588 | /* USER CODE END MX_GPIO_Init_1 */ |
|
| 542 | 589 | ||
| 543 | /* GPIO Ports Clock Enable */ |
590 | /* GPIO Ports Clock Enable */ |
| 544 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
591 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
| 545 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
592 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
| 546 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
593 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 547 | 594 | ||
| 548 | /*Configure GPIO pin Output Level */ |
595 | /*Configure GPIO pin Output Level */ |
| 549 | HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); |
596 | HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); |
| 550 | 597 | ||
| - | 598 | /*Configure GPIO pin Output Level */ |
|
| - | 599 | HAL_GPIO_WritePin(GPIOA, SPI1_CS_Pin | SPI1_CD_Pin | SPI1_RESET_Pin, GPIO_PIN_RESET); |
|
| - | 600 | ||
| 551 | /*Configure GPIO pin : LED_Pin */ |
601 | /*Configure GPIO pin : LED_Pin */ |
| 552 | GPIO_InitStruct.Pin = LED_Pin; |
602 | GPIO_InitStruct.Pin = LED_Pin; |
| 553 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
603 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 554 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
604 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 555 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
605 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
| 556 | HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct); |
606 | HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct); |
| - | 607 | ||
| - | 608 | /*Configure GPIO pins : SPI1_CS_Pin SPI1_CD_Pin SPI1_RESET_Pin */ |
|
| - | 609 | GPIO_InitStruct.Pin = SPI1_CS_Pin | SPI1_CD_Pin | SPI1_RESET_Pin; |
|
| - | 610 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
|
| - | 611 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
|
| - | 612 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
|
| - | 613 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
| - | 614 | ||
| - | 615 | /* USER CODE BEGIN MX_GPIO_Init_2 */ |
|
| - | 616 | /* USER CODE END MX_GPIO_Init_2 */ |
|
| 557 | } |
617 | } |
| 558 | 618 | ||
| 559 | /* USER CODE BEGIN 4 */ |
619 | /* USER CODE BEGIN 4 */ |
| 560 | 620 | ||
| 561 | /* USER CODE END 4 */ |
621 | /* USER CODE END 4 */ |