Subversion Repositories DashDisplay

Rev

Rev 28 | Rev 30 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28 Rev 29
Line 1... Line 1...
1
/**
1
/**
2
 ******************************************************************************
2
  ******************************************************************************
3
 * File Name          : main.c
3
  * File Name          : main.c
4
 * Description        : Main program body
4
  * Description        : Main program body
5
 ******************************************************************************
5
  ******************************************************************************
6
 *
6
  *
7
 * COPYRIGHT(c) 2017 STMicroelectronics
7
  * COPYRIGHT(c) 2017 STMicroelectronics
8
 *
8
  *
9
 * Redistribution and use in source and binary forms, with or without modification,
9
  * Redistribution and use in source and binary forms, with or without modification,
10
 * are permitted provided that the following conditions are met:
10
  * are permitted provided that the following conditions are met:
11
 *   1. Redistributions of source code must retain the above copyright notice,
11
  *   1. Redistributions of source code must retain the above copyright notice,
12
 *      this list of conditions and the following disclaimer.
12
  *      this list of conditions and the following disclaimer.
13
 *   2. Redistributions in binary form must reproduce the above copyright notice,
13
  *   2. Redistributions in binary form must reproduce the above copyright notice,
14
 *      this list of conditions and the following disclaimer in the documentation
14
  *      this list of conditions and the following disclaimer in the documentation
15
 *      and/or other materials provided with the distribution.
15
  *      and/or other materials provided with the distribution.
16
 *   3. Neither the name of STMicroelectronics nor the names of its contributors
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
17
  *      may be used to endorse or promote products derived from this software
18
 *      without specific prior written permission.
18
  *      without specific prior written permission.
19
 *
19
  *
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
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
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
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
23
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
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,
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
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.
29
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
 *
30
  *
31
 ******************************************************************************
31
  ******************************************************************************
32
 */
32
  */
33
/* Includes ------------------------------------------------------------------*/
33
/* Includes ------------------------------------------------------------------*/
34
#include "stm32f1xx_hal.h"
34
#include "stm32l1xx_hal.h"
35
 
35
 
36
/* USER CODE BEGIN Includes */
36
/* USER CODE BEGIN Includes */
37
#include "ap_math.h"
37
#include "ap_math.h"
38
#include "serial.h"
38
#include "serial.h"
39
#include "SSD1306.h"
39
#include "SSD1306.h"
Line 92... Line 92...
92
uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT;
92
uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT;
93
 
93
 
94
/* USER CODE END PV */
94
/* USER CODE END PV */
95
 
95
 
96
/* Private function prototypes -----------------------------------------------*/
96
/* Private function prototypes -----------------------------------------------*/
97
void
-
 
98
SystemClock_Config (void);
97
void SystemClock_Config(void);
99
void
-
 
100
Error_Handler (void);
98
void Error_Handler(void);
101
static void
-
 
102
MX_GPIO_Init (void);
99
static void MX_GPIO_Init(void);
103
static void
-
 
104
MX_SPI1_Init (void);
100
static void MX_SPI1_Init(void);
105
static void
-
 
106
MX_USART2_UART_Init (void);
101
static void MX_USART1_UART_Init(void);
107
static void
-
 
108
MX_USART1_UART_Init (void);
102
static void MX_USART2_UART_Init(void);
109
static void
-
 
110
MX_USART3_UART_Init (void);
103
static void MX_USART3_UART_Init(void);
111
 
104
 
112
/* USER CODE BEGIN PFP */
105
/* USER CODE BEGIN PFP */
113
/* Private function prototypes -----------------------------------------------*/
106
/* Private function prototypes -----------------------------------------------*/
114
 
107
 
115
/* USER CODE END PFP */
108
/* USER CODE END PFP */
Line 315... Line 308...
315
    }
308
    }
316
  return ItemIndex;
309
  return ItemIndex;
317
}
310
}
318
/* USER CODE END 0 */
311
/* USER CODE END 0 */
319
 
312
 
320
int
-
 
321
main (void)
313
int main(void)
322
{
314
{
323
 
315
 
324
  /* USER CODE BEGIN 1 */
316
  /* USER CODE BEGIN 1 */
325
 
317
 
326
  GPIO_InitTypeDef GPIO_InitStruct;
318
  GPIO_InitTypeDef GPIO_InitStruct;
Line 336... Line 328...
336
  /* USER CODE END 1 */
328
  /* USER CODE END 1 */
337
 
329
 
338
  /* MCU Configuration----------------------------------------------------------*/
330
  /* MCU Configuration----------------------------------------------------------*/
339
 
331
 
340
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
332
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
341
  HAL_Init ();
333
  HAL_Init();
342
 
334
 
343
  /* Configure the system clock */
335
  /* Configure the system clock */
344
  SystemClock_Config ();
336
  SystemClock_Config();
345
 
337
 
346
  /* Initialize all configured peripherals */
338
  /* Initialize all configured peripherals */
347
  MX_GPIO_Init ();
339
  MX_GPIO_Init();
348
  MX_SPI1_Init ();
340
  MX_SPI1_Init();
349
  MX_USART2_UART_Init ();
341
  MX_USART1_UART_Init();
350
  MX_USART1_UART_Init ();
342
  MX_USART2_UART_Init();
351
  MX_USART3_UART_Init ();
343
  MX_USART3_UART_Init();
352
 
344
 
353
  /* USER CODE BEGIN 2 */
345
  /* USER CODE BEGIN 2 */
354
 
346
 
355
  /* Turn on USART1 IRQ */
347
  /* Turn on USART1 IRQ */
356
  HAL_NVIC_SetPriority (USART1_IRQn, 2, 0);
348
  HAL_NVIC_SetPriority (USART1_IRQn, 2, 0);
Line 571... Line 563...
571
  /* USER CODE END 3 */
563
  /* USER CODE END 3 */
572
 
564
 
573
}
565
}
574
 
566
 
575
/** System Clock Configuration
567
/** System Clock Configuration
576
 */
568
*/
577
void
-
 
578
SystemClock_Config (void)
569
void SystemClock_Config(void)
579
{
570
{
580
 
571
 
581
  RCC_OscInitTypeDef RCC_OscInitStruct;
572
  RCC_OscInitTypeDef RCC_OscInitStruct;
582
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
573
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
583
 
574
 
-
 
575
  __HAL_RCC_PWR_CLK_ENABLE();
-
 
576
 
-
 
577
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
-
 
578
 
584
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
579
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
585
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
580
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
586
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
-
 
587
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
581
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
588
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
582
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
589
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
583
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
-
 
584
  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
590
  if (HAL_RCC_OscConfig (&RCC_OscInitStruct) != HAL_OK)
585
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
591
    {
586
  {
592
      Error_Handler ();
587
    Error_Handler();
593
    }
588
  }
594
 
589
 
595
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
590
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
596
      | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
591
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
597
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
592
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
598
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
593
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
599
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
594
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
600
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
595
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
601
  if (HAL_RCC_ClockConfig (&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
596
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
602
    {
597
  {
603
      Error_Handler ();
598
    Error_Handler();
604
    }
599
  }
605
 
600
 
606
  HAL_SYSTICK_Config (HAL_RCC_GetHCLKFreq () / 1000);
601
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
607
 
602
 
608
  HAL_SYSTICK_CLKSourceConfig (SYSTICK_CLKSOURCE_HCLK);
603
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
609
 
604
 
610
  /* SysTick_IRQn interrupt configuration */
605
  /* SysTick_IRQn interrupt configuration */
611
  HAL_NVIC_SetPriority (SysTick_IRQn, 0, 0);
606
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
612
}
607
}
613
 
608
 
614
/* SPI1 init function */
609
/* SPI1 init function */
615
static void
-
 
616
MX_SPI1_Init (void)
610
static void MX_SPI1_Init(void)
617
{
611
{
618
 
612
 
619
  hspi1.Instance = SPI1;
613
  hspi1.Instance = SPI1;
620
  hspi1.Init.Mode = SPI_MODE_MASTER;
614
  hspi1.Init.Mode = SPI_MODE_MASTER;
621
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
615
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
622
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
616
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
623
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
617
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
624
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
618
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
625
  hspi1.Init.NSS = SPI_NSS_SOFT;
619
  hspi1.Init.NSS = SPI_NSS_SOFT;
626
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
620
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
627
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
621
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
628
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
622
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
629
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
623
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
630
  hspi1.Init.CRCPolynomial = 10;
624
  hspi1.Init.CRCPolynomial = 10;
631
  if (HAL_SPI_Init (&hspi1) != HAL_OK)
625
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
632
    {
626
  {
633
      Error_Handler ();
627
    Error_Handler();
634
    }
628
  }
635
 
629
 
636
}
630
}
637
 
631
 
638
/* USART1 init function */
632
/* USART1 init function */
639
static void
-
 
640
MX_USART1_UART_Init (void)
633
static void MX_USART1_UART_Init(void)
641
{
634
{
642
 
635
 
643
  huart1.Instance = USART1;
636
  huart1.Instance = USART1;
644
  huart1.Init.BaudRate = 19200;
637
  huart1.Init.BaudRate = 19200;
645
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
638
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
646
  huart1.Init.StopBits = UART_STOPBITS_1;
639
  huart1.Init.StopBits = UART_STOPBITS_1;
647
  huart1.Init.Parity = UART_PARITY_NONE;
640
  huart1.Init.Parity = UART_PARITY_NONE;
648
  huart1.Init.Mode = UART_MODE_TX_RX;
641
  huart1.Init.Mode = UART_MODE_TX_RX;
649
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
642
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
650
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
643
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
651
  if (HAL_UART_Init (&huart1) != HAL_OK)
644
  if (HAL_UART_Init(&huart1) != HAL_OK)
652
    {
645
  {
653
      Error_Handler ();
646
    Error_Handler();
654
    }
647
  }
655
 
648
 
656
}
649
}
657
 
650
 
658
/* USART2 init function */
651
/* USART2 init function */
659
static void
-
 
660
MX_USART2_UART_Init (void)
652
static void MX_USART2_UART_Init(void)
661
{
653
{
662
 
654
 
663
  huart2.Instance = USART2;
655
  huart2.Instance = USART2;
664
  huart2.Init.BaudRate = 115200;
656
  huart2.Init.BaudRate = 115200;
665
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
657
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
666
  huart2.Init.StopBits = UART_STOPBITS_1;
658
  huart2.Init.StopBits = UART_STOPBITS_1;
667
  huart2.Init.Parity = UART_PARITY_NONE;
659
  huart2.Init.Parity = UART_PARITY_NONE;
668
  huart2.Init.Mode = UART_MODE_TX_RX;
660
  huart2.Init.Mode = UART_MODE_TX_RX;
669
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
661
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
670
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
662
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
671
  if (HAL_UART_Init (&huart2) != HAL_OK)
663
  if (HAL_UART_Init(&huart2) != HAL_OK)
672
    {
664
  {
673
      Error_Handler ();
665
    Error_Handler();
674
    }
666
  }
675
 
667
 
676
}
668
}
677
 
669
 
678
/* USART3 init function */
670
/* USART3 init function */
679
static void
-
 
680
MX_USART3_UART_Init (void)
671
static void MX_USART3_UART_Init(void)
681
{
672
{
682
 
673
 
683
  huart3.Instance = USART3;
674
  huart3.Instance = USART3;
684
  huart3.Init.BaudRate = 19200;
675
  huart3.Init.BaudRate = 19200;
685
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
676
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
686
  huart3.Init.StopBits = UART_STOPBITS_1;
677
  huart3.Init.StopBits = UART_STOPBITS_1;
687
  huart3.Init.Parity = UART_PARITY_NONE;
678
  huart3.Init.Parity = UART_PARITY_NONE;
688
  huart3.Init.Mode = UART_MODE_TX_RX;
679
  huart3.Init.Mode = UART_MODE_TX_RX;
689
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
680
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
690
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
681
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
691
  if (HAL_UART_Init (&huart3) != HAL_OK)
682
  if (HAL_UART_Init(&huart3) != HAL_OK)
692
    {
683
  {
693
      Error_Handler ();
684
    Error_Handler();
694
    }
685
  }
695
 
686
 
696
}
687
}
697
 
688
 
698
/** Configure pins as
689
/** Configure pins as
699
 * Analog
690
        * Analog
700
 * Input
691
        * Input
701
 * Output
692
        * Output
702
 * EVENT_OUT
693
        * EVENT_OUT
703
 * EXTI
694
        * EXTI
704
 */
695
*/
705
static void
-
 
706
MX_GPIO_Init (void)
696
static void MX_GPIO_Init(void)
707
{
697
{
708
 
698
 
709
  GPIO_InitTypeDef GPIO_InitStruct;
699
  GPIO_InitTypeDef GPIO_InitStruct;
710
 
700
 
711
  /* GPIO Ports Clock Enable */
701
  /* GPIO Ports Clock Enable */
712
  __HAL_RCC_GPIOD_CLK_ENABLE()
702
  __HAL_RCC_GPIOH_CLK_ENABLE();
713
  ;
-
 
714
  __HAL_RCC_GPIOA_CLK_ENABLE()
703
  __HAL_RCC_GPIOA_CLK_ENABLE();
715
  ;
-
 
716
  __HAL_RCC_GPIOC_CLK_ENABLE()
704
  __HAL_RCC_GPIOC_CLK_ENABLE();
717
  ;
-
 
718
  __HAL_RCC_GPIOB_CLK_ENABLE()
705
  __HAL_RCC_GPIOB_CLK_ENABLE();
719
  ;
-
 
720
 
-
 
721
  /*Configure GPIO pin Output Level */
-
 
722
  HAL_GPIO_WritePin (SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
-
 
723
 
706
 
724
  /*Configure GPIO pin Output Level */
707
  /*Configure GPIO pin Output Level */
725
  HAL_GPIO_WritePin (GPIOA, SPI1CD_Pin | BT_BUTTON_Pin, GPIO_PIN_RESET);
708
  HAL_GPIO_WritePin(GPIOA, SPI1_NSS1_Pin|SPI1CD_Pin|BT_BUTTON_Pin, GPIO_PIN_RESET);
726
 
709
 
727
  /*Configure GPIO pin Output Level */
710
  /*Configure GPIO pin Output Level */
728
  HAL_GPIO_WritePin (GPIOC, SPI_RESET_Pin | POWER_LATCH_Pin | USB_PWR_Pin,
711
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|SPI_NSS2_Pin|POWER_LATCH_Pin|USB_PWR_Pin, GPIO_PIN_RESET);
729
                     GPIO_PIN_RESET);
-
 
730
 
712
 
731
  /*Configure GPIO pin Output Level */
-
 
732
  HAL_GPIO_WritePin (SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
-
 
733
 
-
 
734
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin BT_BUTTON_Pin */
713
  /*Configure GPIO pins : SPI1_NSS1_Pin SPI1CD_Pin BT_BUTTON_Pin */
735
  GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI1CD_Pin | BT_BUTTON_Pin;
714
  GPIO_InitStruct.Pin = SPI1_NSS1_Pin|SPI1CD_Pin|BT_BUTTON_Pin;
736
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
715
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-
 
716
  GPIO_InitStruct.Pull = GPIO_NOPULL;
737
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
717
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
738
  HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
718
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
739
 
719
 
740
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin POWER_LATCH_Pin USB_PWR_Pin */
720
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin POWER_LATCH_Pin USB_PWR_Pin */
741
  GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | POWER_LATCH_Pin
721
  GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NSS2_Pin|POWER_LATCH_Pin|USB_PWR_Pin;
742
      | USB_PWR_Pin;
-
 
743
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
722
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-
 
723
  GPIO_InitStruct.Pull = GPIO_NOPULL;
744
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
724
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
745
  HAL_GPIO_Init (GPIOC, &GPIO_InitStruct);
725
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
746
 
726
 
747
  /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
727
  /*Configure GPIO pin : SW1_PUSH_Pin */
748
  GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin;
728
  GPIO_InitStruct.Pin = SW1_PUSH_Pin;
749
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
729
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
750
  GPIO_InitStruct.Pull = GPIO_PULLUP;
730
  GPIO_InitStruct.Pull = GPIO_NOPULL;
751
  HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
731
  HAL_GPIO_Init(SW1_PUSH_GPIO_Port, &GPIO_InitStruct);
752
 
732
 
753
  /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
733
  /*Configure GPIO pins : SW_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
754
  GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin;
734
  GPIO_InitStruct.Pin = SW_I_Pin|SW1_Q_Pin|SW2_PUSH_Pin;
755
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
735
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
756
  GPIO_InitStruct.Pull = GPIO_PULLUP;
736
  GPIO_InitStruct.Pull = GPIO_NOPULL;
757
  HAL_GPIO_Init (GPIOC, &GPIO_InitStruct);
737
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
758
 
738
 
759
  /*Configure GPIO pin : IGNITION_Pin */
739
  /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin IGNITION_Pin */
760
  GPIO_InitStruct.Pin = IGNITION_Pin;
740
  GPIO_InitStruct.Pin = SW2_I_Pin|SW2_Q_Pin|IGNITION_Pin;
761
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
741
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
762
  GPIO_InitStruct.Pull = GPIO_NOPULL;
742
  GPIO_InitStruct.Pull = GPIO_NOPULL;
763
  HAL_GPIO_Init (IGNITION_GPIO_Port, &GPIO_InitStruct);
743
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
764
 
744
 
765
}
745
}
766
 
746
 
767
/* USER CODE BEGIN 4 */
747
/* USER CODE BEGIN 4 */
768
 
748
 
769
/* USER CODE END 4 */
749
/* USER CODE END 4 */
770
 
750
 
771
/**
751
/**
772
 * @brief  This function is executed in case of error occurrence.
752
  * @brief  This function is executed in case of error occurrence.
773
 * @param  None
753
  * @param  None
774
 * @retval None
754
  * @retval None
775
 */
755
  */
776
void
-
 
777
Error_Handler (void)
756
void Error_Handler(void)
778
{
757
{
779
  /* USER CODE BEGIN Error_Handler */
758
  /* USER CODE BEGIN Error_Handler */
780
  /* User can add his own implementation to report the HAL error return state */
759
  /* User can add his own implementation to report the HAL error return state */
781
  while (1)
760
  while (1)
782
    {
761
    {
783
    }
762
    }
784
  /* USER CODE END Error_Handler */
763
  /* USER CODE END Error_Handler */
785
}
764
}
786
 
765
 
787
#ifdef USE_FULL_ASSERT
766
#ifdef USE_FULL_ASSERT
788
 
767
 
789
/**
768
/**
790
 * @brief Reports the name of the source file and the source line number
769
   * @brief Reports the name of the source file and the source line number
791
 * where the assert_param error has occurred.
770
   * where the assert_param error has occurred.
792
 * @param file: pointer to the source file name
771
   * @param file: pointer to the source file name
793
 * @param line: assert_param error line source number
772
   * @param line: assert_param error line source number
794
 * @retval None
773
   * @retval None
795
 */
774
   */
796
void assert_failed(uint8_t* file, uint32_t line)
775
void assert_failed(uint8_t* file, uint32_t line)
797
  {
776
{
798
    /* USER CODE BEGIN 6 */
777
  /* USER CODE BEGIN 6 */
799
    /* User can add his own implementation to report the file name and line number,
778
    /* User can add his own implementation to report the file name and line number,
800
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
779
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
801
    /* USER CODE END 6 */
780
  /* USER CODE END 6 */
802
 
781
 
803
  }
782
}
804
 
783
 
805
#endif
784
#endif
806
 
785
 
807
/**
786
/**
808
 * @}
787
  * @}
809
 */
788
  */
810
 
789
 
811
/**
790
/**
812
 * @}
791
  * @}
813
 */
792
*/
814
 
793
 
815
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
794
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/