Rev 49 | Rev 52 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 49 | Rev 50 | ||
|---|---|---|---|
| Line -... | Line 1... | ||
| - | 1 | /* USER CODE BEGIN Header */ |
|
| 1 | /** |
2 | /** |
| 2 | ****************************************************************************** |
3 | ****************************************************************************** |
| 3 | * File Name : main.c |
4 | * @file : main.c |
| 4 | * Description : Main program body |
5 | * @brief : Main program body |
| 5 | ****************************************************************************** |
6 | ****************************************************************************** |
| - | 7 | * @attention |
|
| 6 | * |
8 | * |
| 7 | * COPYRIGHT(c) 2018 STMicroelectronics |
9 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
| - | 10 | * All rights reserved.</center></h2> |
|
| 8 | * |
11 | * |
| 9 | * Redistribution and use in source and binary forms, with or without modification, |
12 | * This software component is licensed by ST under BSD 3-Clause license, |
| 10 | * are permitted provided that the following conditions are met: |
13 | * the "License"; You may not use this file except in compliance with the |
| 11 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
| 12 | * this list of conditions and the following disclaimer. |
- | |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
| 14 | * this list of conditions and the following disclaimer in the documentation |
- | |
| 15 | * and/or other materials provided with the distribution. |
14 | * License. You may obtain a copy of the License at: |
| 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 |
15 | * opensource.org/licenses/BSD-3-Clause |
| 18 | * without specific prior written permission. |
- | |
| 19 | * |
- | |
| 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 |
- | |
| 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 |
- | |
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
- | |
| 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, |
- | |
| 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. |
- | |
| 30 | * |
16 | * |
| 31 | ****************************************************************************** |
17 | ****************************************************************************** |
| 32 | */ |
18 | */ |
| - | 19 | /* USER CODE END Header */ |
|
| 33 | /* Includes ------------------------------------------------------------------*/ |
20 | /* Includes ------------------------------------------------------------------*/ |
| 34 | #include "stm32l1xx_hal.h" |
21 | #include "main.h" |
| 35 | 22 | ||
| - | 23 | /* Private includes ----------------------------------------------------------*/ |
|
| 36 | /* USER CODE BEGIN Includes */ |
24 | /* USER CODE BEGIN Includes */ |
| - | 25 | ||
| - | 26 | ||
| 37 | #include "ap_math.h" |
27 | #include "libPLX/plx.h" |
| 38 | #include "serial.h" |
28 | #include "libSerial/serial.H" |
| 39 | #include "SSD1306.h" |
- | |
| 40 | #include "Font.h" |
- | |
| 41 | #include "dials.h" |
29 | #include "libSmallPrintf/small_printf.h" |
| 42 | #include "switches.h" |
30 | #include "switches.h" |
| 43 | #include <math.h> |
- | |
| 44 | #include "plx.h" |
- | |
| 45 | #include "displayinfo.h" |
- | |
| 46 | #include "small_printf.h" |
- | |
| 47 | #include "nvram.h" |
- | |
| 48 | 31 | ||
| 49 | /* USER CODE END Includes */ |
32 | /* USER CODE END Includes */ |
| 50 | 33 | ||
| - | 34 | /* Private typedef -----------------------------------------------------------*/ |
|
| - | 35 | /* USER CODE BEGIN PTD */ |
|
| - | 36 | ||
| - | 37 | /* USER CODE END PTD */ |
|
| - | 38 | ||
| - | 39 | /* Private define ------------------------------------------------------------*/ |
|
| - | 40 | /* USER CODE BEGIN PD */ |
|
| - | 41 | /* USER CODE END PD */ |
|
| - | 42 | ||
| - | 43 | /* Private macro -------------------------------------------------------------*/ |
|
| - | 44 | /* USER CODE BEGIN PM */ |
|
| - | 45 | ||
| - | 46 | /* USER CODE END PM */ |
|
| - | 47 | ||
| 51 | /* Private variables ---------------------------------------------------------*/ |
48 | /* Private variables ---------------------------------------------------------*/ |
| 52 | SPI_HandleTypeDef hspi1; |
49 | SPI_HandleTypeDef hspi1; |
| 53 | 50 | ||
| - | 51 | TIM_HandleTypeDef htim2; |
|
| 54 | TIM_HandleTypeDef htim3; |
52 | TIM_HandleTypeDef htim3; |
| 55 | TIM_HandleTypeDef htim9; |
53 | TIM_HandleTypeDef htim9; |
| 56 | 54 | ||
| 57 | UART_HandleTypeDef huart1; |
55 | UART_HandleTypeDef huart1; |
| 58 | UART_HandleTypeDef huart2; |
56 | UART_HandleTypeDef huart2; |
| 59 | UART_HandleTypeDef huart3; |
57 | UART_HandleTypeDef huart3; |
| 60 | 58 | ||
| 61 | /* USER CODE BEGIN PV */ |
59 | /* USER CODE BEGIN PV */ |
| 62 | /* Private variables ---------------------------------------------------------*/ |
60 | /* Private variables ---------------------------------------------------------*/ |
| - | 61 | ||
| 63 | #define MAXRDG 32 |
62 | context_t contexts[MAX_DISPLAYS]; |
| 64 | 63 | ||
| 65 | /* timeout when the ignition is switched off */ |
64 | /* timeout when the ignition is switched off */ |
| 66 | #define IGNITION_OFF_TIMEOUT 30000UL |
65 | #define IGNITION_OFF_TIMEOUT 30000UL |
| 67 | 66 | ||
| 68 | int OldObservation[2] = |
- | |
| 69 | { -1, -1 }; // illegal initial value |
- | |
| 70 | int OldObservationIndex[2] = |
- | |
| 71 | { -1, -1 }; // if more than one sensor this will be printed |
- | |
| 72 | int16_t dial0[2] = |
- | |
| 73 | { 0, 0 }; |
- | |
| 74 | int16_t dial1[2] = |
- | |
| 75 | { -1, -1 }; |
- | |
| 76 | 67 | ||
| 77 | uint16_t dial_timer[2] = |
- | |
| 78 | { 0, 0 }; |
- | |
| 79 | 68 | ||
| 80 | static const int DialTimeout = 50; // about 20 seconds after twiddle, save the dial position. |
69 | const int DialTimeout = 50; // about 20 seconds after twiddle, save the dial position. |
| 81 | 70 | ||
| 82 | uint16_t dial_nvram[2] __attribute__((section(".NVRAM_Data"))); |
71 | uint16_t dial_nvram[MAX_DISPLAYS] __attribute__((section(".NVRAM_Data"))); |
| 83 | 72 | ||
| 84 | union |
73 | |
| 85 | { |
74 | |
| 86 | PLX_SensorInfo Sensor[MAXRDG]; |
- | |
| 87 | char Bytes[MAXRDG * sizeof(PLX_SensorInfo)]; |
- | |
| 88 | } Data; |
75 | data_t Data; |
| 89 | int Max[MAXRDG]; |
76 | int Max[MAXRDG]; |
| 90 | int Min[MAXRDG]; |
77 | int Min[MAXRDG]; |
| 91 | int PLXItems; |
78 | int PLXItems; |
| 92 | 79 | ||
| 93 | uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT; |
80 | uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT; |
| 94 | 81 | ||
| 95 | /* USER CODE END PV */ |
82 | /* USER CODE END PV */ |
| 96 | 83 | ||
| 97 | /* Private function prototypes -----------------------------------------------*/ |
84 | /* Private function prototypes -----------------------------------------------*/ |
| 98 | void SystemClock_Config(void); |
85 | void SystemClock_Config(void); |
| 99 | void Error_Handler(void); |
- | |
| 100 | static void MX_GPIO_Init(void); |
86 | static void MX_GPIO_Init(void); |
| 101 | static void MX_SPI1_Init(void); |
87 | static void MX_SPI1_Init(void); |
| 102 | static void MX_USART1_UART_Init(void); |
88 | static void MX_USART1_UART_Init(void); |
| 103 | static void MX_USART2_UART_Init(void); |
89 | static void MX_USART2_UART_Init(void); |
| 104 | static void MX_USART3_UART_Init(void); |
90 | static void MX_USART3_UART_Init(void); |
| 105 | static void MX_TIM3_Init(void); |
91 | static void MX_TIM3_Init(void); |
| 106 | static void MX_TIM9_Init(void); |
92 | static void MX_TIM9_Init(void); |
| 107 | - | ||
| - | 93 | static void MX_TIM2_Init(void); |
|
| 108 | /* USER CODE BEGIN PFP */ |
94 | /* USER CODE BEGIN PFP */ |
| 109 | /* Private function prototypes -----------------------------------------------*/ |
- | |
| 110 | - | ||
| 111 | /* USER CODE END PFP */ |
- | |
| 112 | - | ||
| 113 | /* USER CODE BEGIN 0 */ |
- | |
| 114 | /* dummy function */ |
- | |
| 115 | void _init(void) |
- | |
| 116 | { |
- | |
| 117 | 95 | ||
| 118 | } |
- | |
| 119 | // the dial is the switch number we are using. |
96 | // the dial is the switch number we are using. |
| 120 | // suppress is the ItemIndex we wish to suppress on this display |
97 | // suppress is the ItemIndex we wish to suppress on this display |
| 121 | int DisplayCurrent(int dial, int suppress) |
98 | int DisplayCurrent(int dial, int suppress) |
| 122 | { |
99 | { |
| 123 | char buff[10]; |
- | |
| 124 | int i; |
- | |
| 125 | int rc; |
- | |
| 126 | select_display(dial); // pick the display we are using |
- | |
| 127 | int ItemIndex = dial_pos[dial] % PLXItems; |
- | |
| 128 | - | ||
| 129 | #if 0 |
- | |
| 130 | // wrap around count if dial too far to the right |
- | |
| 131 | if (ItemIndex >= PLXItems) |
- | |
| 132 | { |
- | |
| 133 | dial_pos[dial] = 0; |
- | |
| 134 | ItemIndex = 0; |
- | |
| 135 | } |
- | |
| 136 | if (ItemIndex < 0) |
- | |
| 137 | { |
- | |
| 138 | ItemIndex = PLXItems - 1; |
- | |
| 139 | dial_pos[dial] = (PLXItems - 1) * 4; |
- | |
| 140 | } |
- | |
| 141 | #endif |
- | |
| 142 | // check for item suppression |
- | |
| 143 | if (ItemIndex == suppress) |
- | |
| 144 | { |
- | |
| 145 | dial1[dial] = -1; |
- | |
| 146 | OldObservation[dial] = -1; |
- | |
| 147 | OldObservationIndex[dial] = -1; |
- | |
| 148 | - | ||
| 149 | clearDisplay(); |
- | |
| 150 | display(); |
- | |
| 151 | return -1; // we suppressed this display |
- | |
| 152 | } |
- | |
| 153 | // do not try to convert if no items in buffer |
- | |
| 154 | if (PLXItems > 0) |
100 | if (PLXItems == 0) |
| 155 | { |
- | |
| 156 | int DataVal = ConvPLX(Data.Sensor[ItemIndex].ReadingH, |
- | |
| 157 | Data.Sensor[ItemIndex].ReadingL); // data reading |
- | |
| 158 | int Observation = ConvPLX(Data.Sensor[ItemIndex].AddrH, |
- | |
| 159 | Data.Sensor[ItemIndex].AddrL); |
- | |
| 160 | int ObservationIndex = ConvPLX(0, Data.Sensor[ItemIndex].Instance); |
- | |
| 161 | // now to convert the readings and format strings |
- | |
| 162 | // find out limits |
- | |
| 163 | char * msg; |
- | |
| 164 | int len; |
- | |
| 165 | - | ||
| 166 | // if the user presses the dial then reset min/max to current value |
- | |
| 167 | if (push_pos[dial] == 1) |
- | |
| 168 | { |
- | |
| 169 | Max[ItemIndex] = DataVal; |
- | |
| 170 | Min[ItemIndex] = DataVal; // 12 bit max value |
- | |
| 171 | } |
- | |
| 172 | - | ||
| 173 | if (Observation < PLX_MAX_OBS) |
- | |
| 174 | { |
- | |
| 175 | if (Observation != OldObservation[dial] |
- | |
| 176 | || ObservationIndex != OldObservationIndex[dial]) |
- | |
| 177 | { |
- | |
| 178 | - | ||
| 179 | dial_timer[dial] = DialTimeout; |
- | |
| 180 | - | ||
| 181 | dial1[dial] = -1; |
- | |
| 182 | clearDisplay(); |
- | |
| 183 | dial_draw_scale(DisplayInfo[Observation].Low, |
- | |
| 184 | DisplayInfo[Observation].High, 12, 1, |
- | |
| 185 | DisplayInfo[Observation].TickScale); |
- | |
| 186 | - | ||
| 187 | msg = DisplayInfo[Observation].name; |
- | |
| 188 | len = 7; |
101 | return -1; |
| 189 | int len1 = ObservationIndex > 0 ? len - 1 : len; |
- | |
| 190 | for (i = 0; i < len1 && msg[i]; i++) |
- | |
| 191 | { |
- | |
| 192 | buff[i] = msg[i]; |
- | |
| 193 | } |
- | |
| 194 | if (ObservationIndex > 0 && i < len) |
- | |
| 195 | { |
- | |
| 196 | buff[i++] = ObservationIndex + '1'; |
- | |
| 197 | } |
- | |
| 198 | - | ||
| 199 | print_large_string(buff, 64 - i * 4, 48, i); // this prints spaces for \0 at end of string |
- | |
| 200 | - | ||
| 201 | // print suffix if present. |
- | |
| 202 | font_gotoxy(15, 4); |
- | |
| 203 | int i = 0; |
- | |
| 204 | while (DisplayInfo[Observation].suffix[i]) |
- | |
| 205 | { |
- | |
| 206 | font_putchar(DisplayInfo[Observation].suffix[i++]); |
- | |
| 207 | } |
- | |
| 208 | - | ||
| 209 | OldObservation[dial] = Observation; |
- | |
| 210 | OldObservationIndex[dial] = ObservationIndex; |
- | |
| 211 | // |
- | |
| 212 | display(); |
- | |
| 213 | - | ||
| 214 | } |
- | |
| 215 | else |
- | |
| 216 | { |
- | |
| 217 | // check for timer timeout on consistent timer |
- | |
| 218 | if (dial_timer[dial]) |
- | |
| 219 | { |
- | |
| 220 | dial_timer[dial]--; |
- | |
| 221 | - | ||
| 222 | if (dial_timer[dial] == 0) |
- | |
| 223 | { |
- | |
| 224 | uint16_t curr_val = dial_pos[dial]; |
- | |
| 225 | - | ||
| 226 | uint32_t addr = (uint32_t) (&dial_nvram[dial]); |
- | |
| 227 | WriteUint16NVRAM(addr, curr_val ); |
- | |
| 228 | - | ||
| 229 | } |
- | |
| 230 | } |
- | |
| 231 | } |
- | |
| 232 | - | ||
| 233 | } |
- | |
| 234 | - | ||
| 235 | double max_rdg; |
- | |
| 236 | double min_rdg; |
- | |
| 237 | double cur_rdg; |
- | |
| 238 | int int_rdg; |
- | |
| 239 | int int_max; |
- | |
| 240 | int int_min; |
- | |
| 241 | - | ||
| 242 | max_rdg = ConveriMFDRaw2Data(Observation, |
- | |
| 243 | DisplayInfo[Observation].Units, Max[ItemIndex]); |
- | |
| 244 | min_rdg = ConveriMFDRaw2Data(Observation, |
- | |
| 245 | DisplayInfo[Observation].Units, Min[ItemIndex]); |
- | |
| 246 | cur_rdg = ConveriMFDRaw2Data(Observation, |
- | |
| 247 | DisplayInfo[Observation].Units, DataVal); |
- | |
| 248 | - | ||
| 249 | int dp_pos; // where to print the decimal place |
- | |
| 250 | float scale = 1.0; |
- | |
| 251 | switch (DisplayInfo[Observation].DP) |
- | |
| 252 | { |
- | |
| 253 | case 0: |
- | |
| 254 | scale = 1.0; |
- | |
| 255 | dp_pos = 100; |
- | |
| 256 | break; |
- | |
| 257 | case 1: |
- | |
| 258 | scale = 10.0; |
- | |
| 259 | dp_pos = 1; |
- | |
| 260 | break; |
- | |
| 261 | case 2: |
- | |
| 262 | scale = 100.0; |
- | |
| 263 | dp_pos = 2; |
- | |
| 264 | break; |
- | |
| 265 | } |
- | |
| 266 | int_rdg = (int) (cur_rdg * scale); |
- | |
| 267 | int_max = (int) (max_rdg * scale); |
- | |
| 268 | int_min = (int) (min_rdg * scale); |
- | |
| 269 | - | ||
| 270 | cur_rdg -= DisplayInfo[Observation].Low; |
- | |
| 271 | cur_rdg = SINE_STEPS * cur_rdg |
- | |
| 272 | / (DisplayInfo[Observation].High |
- | |
| 273 | - DisplayInfo[Observation].Low); |
- | |
| 274 | - | ||
| 275 | dial0[dial] = (int) cur_rdg; |
- | |
| 276 | - | ||
| 277 | /* old needle un-draw */ |
- | |
| 278 | if (dial1[dial] >= 0) |
- | |
| 279 | { |
- | |
| 280 | dial_draw_needle(dial1[dial]); |
- | |
| 281 | } |
- | |
| 282 | dial_draw_needle(dial0[dial]); |
- | |
| 283 | // print value overlaid by needle |
- | |
| 284 | // this is actual reading |
- | |
| 285 | print_digits(30, 30, 5, dp_pos, int_rdg); |
- | |
| 286 | font_gotoxy(0, 0); |
- | |
| 287 | font_digits(5, dp_pos, int_min); |
- | |
| 288 | - | ||
| 289 | font_gotoxy(0, 1); |
- | |
| 290 | font_puts("Min"); |
- | |
| 291 | - | ||
| 292 | font_gotoxy(15, 0); |
- | |
| 293 | font_digits(5, dp_pos, int_max); |
- | |
| 294 | font_gotoxy(18, 1); |
- | |
| 295 | font_puts("Max"); |
- | |
| 296 | 102 | ||
| 297 | dial1[dial] = dial0[dial]; |
103 | int itemIndex = dial_pos[dial] % PLXItems; |
| 298 | 104 | ||
| 299 | display(); |
- | |
| 300 | 105 | ||
| 301 | } |
- | |
| 302 | return ItemIndex; |
106 | return cc_display(dial, itemIndex, suppress); |
| 303 | } |
107 | } |
| - | 108 | ||
| - | 109 | ||
| - | 110 | ||
| - | 111 | ||
| - | 112 | /* USER CODE END PFP */ |
|
| - | 113 | ||
| - | 114 | /* Private user code ---------------------------------------------------------*/ |
|
| - | 115 | /* USER CODE BEGIN 0 */ |
|
| - | 116 | ||
| 304 | /* USER CODE END 0 */ |
117 | /* USER CODE END 0 */ |
| 305 | 118 | ||
| - | 119 | /** |
|
| - | 120 | * @brief The application entry point. |
|
| - | 121 | * @retval int |
|
| - | 122 | */ |
|
| 306 | int main(void) |
123 | int main(void) |
| 307 | { |
124 | { |
| 308 | - | ||
| 309 | /* USER CODE BEGIN 1 */ |
125 | /* USER CODE BEGIN 1 */ |
| - | 126 | __HAL_RCC_SPI1_CLK_ENABLE() |
|
| - | 127 | ; |
|
| - | 128 | __HAL_RCC_USART1_CLK_ENABLE() |
|
| - | 129 | ; // PLX main port |
|
| - | 130 | __HAL_RCC_USART2_CLK_ENABLE() |
|
| - | 131 | ; // debug port |
|
| - | 132 | __HAL_RCC_USART3_CLK_ENABLE () |
|
| - | 133 | ; // Bluetooth port |
|
| 310 | 134 | ||
| 311 | GPIO_InitTypeDef GPIO_InitStruct; |
- | |
| 312 | - | ||
| 313 | __HAL_RCC_SPI1_CLK_ENABLE() |
135 | __HAL_RCC_TIM3_CLK_ENABLE(); |
| 314 | ; |
- | |
| 315 | __HAL_RCC_USART1_CLK_ENABLE() |
- | |
| 316 | ; // PLX main port |
- | |
| 317 | __HAL_RCC_USART2_CLK_ENABLE() |
- | |
| 318 | ; // debug port |
- | |
| 319 | __HAL_RCC_USART3_CLK_ENABLE () |
- | |
| 320 | ; // Bluetooth port |
- | |
| 321 | 136 | ||
| 322 | __HAL_RCC_TIM3_CLK_ENABLE(); |
137 | __HAL_RCC_TIM9_CLK_ENABLE(); |
| 323 | 138 | ||
| 324 | __HAL_RCC_TIM9_CLK_ENABLE(); |
- | |
| 325 | /* USER CODE END 1 */ |
139 | /* USER CODE END 1 */ |
| 326 | 140 | ||
| 327 | /* MCU Configuration----------------------------------------------------------*/ |
141 | /* MCU Configuration--------------------------------------------------------*/ |
| 328 | 142 | ||
| 329 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
143 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
| 330 | HAL_Init(); |
144 | HAL_Init(); |
| 331 | 145 | ||
| - | 146 | /* USER CODE BEGIN Init */ |
|
| - | 147 | ||
| - | 148 | /* USER CODE END Init */ |
|
| - | 149 | ||
| 332 | /* Configure the system clock */ |
150 | /* Configure the system clock */ |
| 333 | SystemClock_Config(); |
151 | SystemClock_Config(); |
| 334 | 152 | ||
| - | 153 | /* USER CODE BEGIN SysInit */ |
|
| - | 154 | ||
| - | 155 | /* USER CODE END SysInit */ |
|
| - | 156 | ||
| 335 | /* Initialize all configured peripherals */ |
157 | /* Initialize all configured peripherals */ |
| 336 | MX_GPIO_Init(); |
158 | MX_GPIO_Init(); |
| 337 | MX_SPI1_Init(); |
159 | MX_SPI1_Init(); |
| 338 | MX_USART1_UART_Init(); |
160 | MX_USART1_UART_Init(); |
| 339 | MX_USART2_UART_Init(); |
161 | MX_USART2_UART_Init(); |
| 340 | MX_USART3_UART_Init(); |
162 | MX_USART3_UART_Init(); |
| 341 | MX_TIM3_Init(); |
163 | MX_TIM3_Init(); |
| 342 | MX_TIM9_Init(); |
164 | MX_TIM9_Init(); |
| 343 | - | ||
| - | 165 | MX_TIM2_Init(); |
|
| 344 | /* USER CODE BEGIN 2 */ |
166 | /* USER CODE BEGIN 2 */ |
| 345 | 167 | ||
| 346 | /* Turn on USART1 IRQ */ |
168 | /* Turn on USART1 IRQ */ |
| 347 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
169 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
| 348 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
170 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
| 349 | - | ||
| 350 | /* Turn on USART2 IRQ */ |
- | |
| 351 | HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); |
- | |
| 352 | HAL_NVIC_EnableIRQ(USART2_IRQn); |
- | |
| 353 | 171 | ||
| 354 | /* turn on USART3 IRQ */ |
172 | /* Turn on USART2 IRQ */ |
| 355 | HAL_NVIC_SetPriority(USART3_IRQn, 4, 0); |
173 | HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); |
| 356 | HAL_NVIC_EnableIRQ(USART3_IRQn); |
174 | HAL_NVIC_EnableIRQ(USART2_IRQn); |
| 357 | 175 | ||
| 358 | /* setup the USART control blocks */ |
176 | /* turn on USART3 IRQ */ |
| 359 | init_usart_ctl(&uc1, huart1.Instance); |
177 | HAL_NVIC_SetPriority(USART3_IRQn, 4, 0); |
| 360 | init_usart_ctl(&uc2, huart2.Instance); |
- | |
| 361 | init_usart_ctl(&uc3, huart3.Instance); |
178 | HAL_NVIC_EnableIRQ(USART3_IRQn); |
| 362 | 179 | ||
| - | 180 | /* setup the USART control blocks */ |
|
| 363 | EnableSerialRxInterrupt(&uc1); |
181 | init_usart_ctl(&uc1, huart1.Instance); |
| 364 | EnableSerialRxInterrupt(&uc2); |
182 | init_usart_ctl(&uc2, huart2.Instance); |
| 365 | EnableSerialRxInterrupt(&uc3); |
183 | init_usart_ctl(&uc3, huart3.Instance); |
| 366 | 184 | ||
| - | 185 | EnableSerialRxInterrupt(&uc1); |
|
| - | 186 | EnableSerialRxInterrupt(&uc2); |
|
| 367 | HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); |
187 | EnableSerialRxInterrupt(&uc3); |
| 368 | 188 | ||
| 369 | HAL_TIM_Encoder_Start(&htim9, TIM_CHANNEL_ALL); |
189 | HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); |
| 370 | 190 | ||
| 371 | InitSwitches(); |
191 | HAL_TIM_Encoder_Start(&htim9, TIM_CHANNEL_ALL); |
| 372 | 192 | ||
| 373 | int i; |
- | |
| 374 | uint16_t rc; |
- | |
| 375 | for (i = 0; i < 2; i++) |
- | |
| 376 | { |
- | |
| 377 | dial_pos[i] = dial_nvram[i]; |
- | |
| 378 | } |
- | |
| 379 | 193 | ||
| 380 | ap_init(); // set up the approximate math library |
194 | // Switch handler called on sysTick interrupt. |
| - | 195 | InitSwitches(); |
|
| 381 | 196 | ||
| 382 | int disp; |
197 | cc_init(); |
| 383 | 198 | ||
| 384 | ssd1306_begin(1, 0); |
199 | int i; |
| 385 | dial_origin(64, 60); |
200 | for (i = 0; i < 2; i++) |
| - | 201 | { |
|
| 386 | dial_size(60); |
202 | dial_pos[i] = dial_nvram[i]; |
| - | 203 | } |
|
| 387 | 204 | ||
| 388 | /* reset the display timeout, latch on power from accessories */ |
205 | /* reset the display timeout, latch on power from accessories */ |
| 389 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
206 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
| 390 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
207 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
| 391 | 208 | ||
| 392 | for (disp = 0; disp < 2; disp++) |
209 | /* USER CODE END 2 */ |
| 393 | { |
- | |
| 394 | select_display(disp); |
- | |
| 395 | clearDisplay(); |
- | |
| 396 | dim(0); |
- | |
| 397 | //font_puts( |
- | |
| 398 | // "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font"); |
- | |
| 399 | 210 | ||
| 400 | dial_draw_scale(0, 10, 12, 5, 1); |
211 | /* Infinite loop */ |
| 401 | char buffer[] = "Unit is "; |
212 | /* USER CODE BEGIN WHILE */ |
| 402 | buffer[8] = disp + '1'; |
213 | while(1){ |
| 403 | print_large_string(buffer, 20, 30, 9); |
- | |
| 404 | 214 | ||
| - | 215 | /* while ignition is on, keep resetting power latch timer */ |
|
| - | 216 | if (HAL_GPIO_ReadPin(IGNITION_GPIO_Port, IGNITION_Pin) == GPIO_PIN_RESET) |
|
| - | 217 | { |
|
| - | 218 | Latch_Timer = HAL_GetTick() + IGNITION_OFF_TIMEOUT; |
|
| - | 219 | } |
|
| 405 | display(); |
220 | else |
| - | 221 | { |
|
| - | 222 | /* if the ignition has been off for a while, then turn off power */ |
|
| - | 223 | if (HAL_GetTick() > Latch_Timer) |
|
| - | 224 | { |
|
| - | 225 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, |
|
| - | 226 | GPIO_PIN_RESET); |
|
| - | 227 | } |
|
| - | 228 | } |
|
| 406 | 229 | ||
| - | 230 | uint32_t timeout = 0; // |
|
| - | 231 | // PLX decoder protocols |
|
| - | 232 | char PLXPacket = 0; |
|
| - | 233 | for (i = 0; i < MAXRDG; i++) |
|
| - | 234 | { |
|
| - | 235 | Max[i] = 0; |
|
| - | 236 | Min[i] = 0xFFF; // 12 bit max value |
|
| 407 | } |
237 | } |
| 408 | 238 | ||
| 409 | /* USER CODE END 2 */ |
239 | int PLXPtr = 0; |
| 410 | 240 | ||
| - | 241 | while (1) |
|
| - | 242 | { |
|
| - | 243 | // Handle the bluetooth pairing function by pressing both buttons. |
|
| - | 244 | if ((push_pos[0] == 1) && (push_pos[1] == 1)) |
|
| - | 245 | { |
|
| - | 246 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET); |
|
| - | 247 | } |
|
| - | 248 | else |
|
| - | 249 | { |
|
| - | 250 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_RESET); |
|
| - | 251 | } |
|
| - | 252 | ||
| - | 253 | uint16_t cc = SerialCharsReceived(&uc1); |
|
| - | 254 | int chr; |
|
| - | 255 | if (cc == 0) |
|
| - | 256 | { |
|
| - | 257 | timeout++; |
|
| - | 258 | if (timeout % 1000 == 0) |
|
| - | 259 | { |
|
| - | 260 | const char msg[] = "Timeout\r\n"; |
|
| - | 261 | char * p = msg; |
|
| - | 262 | while(*p) |
|
| - | 263 | { |
|
| - | 264 | PutCharSerial(&uc3,*p++); |
|
| - | 265 | } |
|
| - | 266 | ||
| - | 267 | } |
|
| - | 268 | ||
| - | 269 | if (timeout > 60000) |
|
| - | 270 | { |
|
| - | 271 | ||
| - | 272 | // do turn off screen |
|
| - | 273 | } |
|
| - | 274 | ||
| - | 275 | } |
|
| - | 276 | for (chr = 0; chr < cc; chr++) |
|
| - | 277 | { |
|
| - | 278 | char c = GetCharSerial(&uc1); |
|
| - | 279 | ||
| - | 280 | ||
| - | 281 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
|
| - | 282 | { |
|
| - | 283 | PLXPtr = 0; // reset the pointer |
|
| - | 284 | PLXPacket = 1; |
|
| - | 285 | timeout = 0; // Reset the timer |
|
| - | 286 | } |
|
| - | 287 | else if (c == PLX_Stop) |
|
| - | 288 | { |
|
| - | 289 | if (PLXPacket) |
|
| - | 290 | { |
|
| - | 291 | // we can now decode the selected parameter |
|
| - | 292 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
|
| - | 293 | // saturate the rotary switch position |
|
| - | 294 | ||
| 411 | /* Infinite loop */ |
295 | int DataVal; |
| - | 296 | // process min/max |
|
| - | 297 | for (i = 0; i < PLXItems; i++) |
|
| - | 298 | { |
|
| 412 | /* USER CODE BEGIN WHILE */ |
299 | // Send item to BT |
| - | 300 | uint16_t addr = ConvPLX(Data.Sensor[i].AddrH, |
|
| - | 301 | Data.Sensor[i].AddrL); |
|
| 413 | uint32_t Ticks = HAL_GetTick() + 100; |
302 | uint8_t inst = Data.Sensor[i].Instance; |
| - | 303 | uint16_t reading = ConvPLX(Data.Sensor[i].ReadingH, |
|
| - | 304 | Data.Sensor[i].ReadingL); |
|
| - | 305 | ||
| - | 306 | char outbuff[100]; |
|
| - | 307 | small_sprintf(outbuff, "%d,%d,%d\n\r", addr, inst, |
|
| - | 308 | reading); |
|
| - | 309 | int ck=0; |
|
| - | 310 | while(outbuff[ck] && ck < 100) |
|
| - | 311 | ||
| - | 312 | { |
|
| - | 313 | PutCharSerial(&uc2, outbuff[ck++]); |
|
| - | 314 | } |
|
| - | 315 | DataVal = ConvPLX(Data.Sensor[i].ReadingH, |
|
| - | 316 | Data.Sensor[i].ReadingL); |
|
| - | 317 | if (DataVal > Max[i]) |
|
| - | 318 | { |
|
| - | 319 | Max[i] = DataVal; |
|
| - | 320 | } |
|
| - | 321 | if (DataVal < Min[i]) |
|
| - | 322 | { |
|
| - | 323 | Min[i] = DataVal; |
|
| - | 324 | } |
|
| - | 325 | } |
|
| - | 326 | ||
| - | 327 | // now to display the information |
|
| - | 328 | int suppress = DisplayCurrent(0, -1); |
|
| - | 329 | DisplayCurrent(1, suppress); |
|
| - | 330 | } |
|
| - | 331 | PLXPtr = 0; |
|
| - | 332 | PLXPacket = 0; |
|
| - | 333 | } |
|
| - | 334 | else if (c > PLX_Stop) // illegal char, restart reading |
|
| - | 335 | { |
|
| - | 336 | PLXPacket = 0; |
|
| - | 337 | PLXPtr = 0; |
|
| - | 338 | } |
|
| - | 339 | else if (PLXPacket && PLXPtr < sizeof(Data.Bytes)) |
|
| - | 340 | { |
|
| - | 341 | Data.Bytes[PLXPtr++] = c; |
|
| - | 342 | } |
|
| 414 | 343 | ||
| 415 | /* while ignition is on, keep resetting power latch timer */ |
- | |
| 416 | if (HAL_GPIO_ReadPin(IGNITION_GPIO_Port, IGNITION_Pin) == GPIO_PIN_RESET) |
- | |
| 417 | { |
- | |
| 418 | Latch_Timer = HAL_GetTick() + IGNITION_OFF_TIMEOUT; |
- | |
| 419 | } |
- | |
| 420 | else |
- | |
| 421 | { |
- | |
| 422 | /* if the ignition has been off for a while, then turn off power */ |
- | |
| 423 | if (HAL_GetTick() > Latch_Timer) |
- | |
| 424 | { |
- | |
| 425 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, |
- | |
| 426 | GPIO_PIN_RESET); |
- | |
| 427 | } |
- | |
| 428 | } |
- | |
| 429 | - | ||
| 430 | uint32_t timeout = 0; // |
- | |
| 431 | // PLX decoder protocols |
- | |
| 432 | char PLXPacket = 0; |
- | |
| 433 | for (i = 0; i < MAXRDG; i++) |
- | |
| 434 | { |
- | |
| 435 | Max[i] = 0; |
- | |
| 436 | Min[i] = 0xFFF; // 12 bit max value |
- | |
| 437 | } |
- | |
| 438 | - | ||
| 439 | int PLXPtr = 0; |
- | |
| 440 | - | ||
| 441 | while (1) |
- | |
| 442 | { |
- | |
| 443 | // poll switche |
- | |
| 444 | HandleSwitches(); |
- | |
| 445 | // Handle the bluetooth pairing function by pressing both buttons. |
- | |
| 446 | if ((push_pos[0] == 1) && (push_pos[1] == 1)) |
- | |
| 447 | { |
- | |
| 448 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET); |
- | |
| 449 | } |
- | |
| 450 | else |
- | |
| 451 | { |
- | |
| 452 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_RESET); |
- | |
| 453 | - | ||
| 454 | } |
- | |
| 455 | - | ||
| 456 | uint16_t cc = SerialCharsReceived(&uc1); |
- | |
| 457 | int chr; |
- | |
| 458 | if (cc == 0) |
- | |
| 459 | { |
- | |
| 460 | timeout++; |
- | |
| 461 | if (timeout % 1000 == 0) |
- | |
| 462 | { |
- | |
| 463 | const char msg[] = "No data\r\n"; |
- | |
| 464 | char * p = msg; |
- | |
| 465 | while(*p) |
- | |
| 466 | { |
- | |
| 467 | PutCharSerial(&uc2,*p++); |
- | |
| 468 | } |
- | |
| 469 | - | ||
| 470 | } |
- | |
| 471 | - | ||
| 472 | if (timeout > 60000) |
- | |
| 473 | { |
- | |
| 474 | // do turn off screen |
- | |
| 475 | } |
- | |
| 476 | - | ||
| 477 | } |
- | |
| 478 | for (chr = 0; chr < cc; chr++) |
- | |
| 479 | { |
- | |
| 480 | char c = GetCharSerial(&uc1); |
- | |
| 481 | timeout = 0; |
- | |
| 482 | - | ||
| 483 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
- | |
| 484 | { |
- | |
| 485 | PLXPtr = 0; // reset the pointer |
- | |
| 486 | PLXPacket = 1; |
- | |
| 487 | } |
- | |
| 488 | else if (c == PLX_Stop) |
- | |
| 489 | { |
- | |
| 490 | if (PLXPacket) |
- | |
| 491 | { |
- | |
| 492 | // we can now decode the selected parameter |
- | |
| 493 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
- | |
| 494 | // saturate the rotary switch position |
- | |
| 495 | - | ||
| 496 | int DataVal; |
- | |
| 497 | // process min/max |
- | |
| 498 | for (i = 0; i < PLXItems; i++) |
- | |
| 499 | { |
- | |
| 500 | // Send item to BT |
- | |
| 501 | uint16_t addr = ConvPLX(Data.Sensor[i].AddrH, |
- | |
| 502 | Data.Sensor[i].AddrL); |
- | |
| 503 | uint8_t inst = Data.Sensor[i].Instance; |
- | |
| 504 | uint16_t reading = ConvPLX(Data.Sensor[i].ReadingH, |
- | |
| 505 | Data.Sensor[i].ReadingL); |
- | |
| 506 | - | ||
| 507 | char outbuff[100]; |
- | |
| 508 | int cnt = small_sprintf(outbuff, "%d,%d,%d\n\r", addr, inst, |
- | |
| 509 | reading); |
- | |
| 510 | int ck=0; |
- | |
| 511 | while(outbuff[ck] && ck < 100) |
- | |
| 512 | - | ||
| 513 | { |
- | |
| 514 | PutCharSerial(&uc2, outbuff[ck++]); |
- | |
| 515 | } |
- | |
| 516 | DataVal = ConvPLX(Data.Sensor[i].ReadingH, |
- | |
| 517 | Data.Sensor[i].ReadingL); |
- | |
| 518 | if (DataVal > Max[i]) |
- | |
| 519 | { |
- | |
| 520 | Max[i] = DataVal; |
- | |
| 521 | } |
- | |
| 522 | if (DataVal < Min[i]) |
- | |
| 523 | { |
- | |
| 524 | Min[i] = DataVal; |
- | |
| 525 | } |
- | |
| 526 | } |
- | |
| 527 | - | ||
| 528 | // now to display the information |
- | |
| 529 | int suppress = DisplayCurrent(0, -1); |
- | |
| 530 | DisplayCurrent(1, suppress); |
- | |
| 531 | } |
344 | } |
| 532 | PLXPtr = 0; |
- | |
| 533 | PLXPacket = 0; |
- | |
| 534 | } |
- | |
| 535 | else if (c > PLX_Stop) // illegal char, restart reading |
- | |
| 536 | { |
- | |
| 537 | PLXPacket = 0; |
- | |
| 538 | PLXPtr = 0; |
- | |
| 539 | } |
- | |
| 540 | else if (PLXPtr < sizeof(Data.Bytes)) |
- | |
| 541 | { |
- | |
| 542 | Data.Bytes[PLXPtr++] = c; |
- | |
| 543 | } |
- | |
| 544 | } |
- | |
| 545 | 345 | ||
| 546 | HAL_Delay(1); |
346 | HAL_Delay(1); |
| 547 | } |
347 | } |
| 548 | /* USER CODE END WHILE */ |
- | |
| 549 | 348 | ||
| 550 | /* USER CODE BEGIN 3 */ |
349 | /* USER CODE END WHILE */ |
| 551 | 350 | ||
| - | 351 | /* USER CODE BEGIN 3 */ |
|
| - | 352 | } |
|
| 552 | /* USER CODE END 3 */ |
353 | /* USER CODE END 3 */ |
| 553 | - | ||
| 554 | } |
354 | } |
| 555 | 355 | ||
| - | 356 | /** |
|
| 556 | /** System Clock Configuration |
357 | * @brief System Clock Configuration |
| - | 358 | * @retval None |
|
| 557 | */ |
359 | */ |
| 558 | void SystemClock_Config(void) |
360 | void SystemClock_Config(void) |
| 559 | { |
361 | { |
| - | 362 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
|
| - | 363 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
|
| 560 | 364 | ||
| 561 | RCC_OscInitTypeDef RCC_OscInitStruct; |
- | |
| 562 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
365 | /** Configure the main internal regulator output voltage |
| 563 | 366 | */ |
|
| 564 | __HAL_RCC_PWR_CLK_ENABLE(); |
- | |
| 565 | - | ||
| 566 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
367 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
| - | 368 | /** Initializes the RCC Oscillators according to the specified parameters |
|
| - | 369 | * in the RCC_OscInitTypeDef structure. |
|
| 567 | 370 | */ |
|
| 568 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
371 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
| 569 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
372 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
| 570 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
373 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 571 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
374 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 572 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; |
375 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; |
| 573 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
376 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
| 574 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
377 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| 575 | { |
378 | { |
| 576 | Error_Handler(); |
379 | Error_Handler(); |
| 577 | } |
380 | } |
| - | 381 | /** Initializes the CPU, AHB and APB buses clocks |
|
| 578 | 382 | */ |
|
| 579 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
383 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
| 580 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
384 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
| 581 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
385 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 582 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
386 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
| 583 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
387 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
| 584 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
388 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
| - | 389 | ||
| 585 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
390 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
| 586 | { |
391 | { |
| 587 | Error_Handler(); |
392 | Error_Handler(); |
| 588 | } |
393 | } |
| 589 | - | ||
| 590 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
- | |
| 591 | - | ||
| 592 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
- | |
| 593 | - | ||
| 594 | /* SysTick_IRQn interrupt configuration */ |
- | |
| 595 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
- | |
| 596 | } |
394 | } |
| 597 | 395 | ||
| - | 396 | /** |
|
| 598 | /* SPI1 init function */ |
397 | * @brief SPI1 Initialization Function |
| - | 398 | * @param None |
|
| - | 399 | * @retval None |
|
| - | 400 | */ |
|
| 599 | static void MX_SPI1_Init(void) |
401 | static void MX_SPI1_Init(void) |
| 600 | { |
402 | { |
| 601 | 403 | ||
| - | 404 | /* USER CODE BEGIN SPI1_Init 0 */ |
|
| - | 405 | ||
| - | 406 | /* USER CODE END SPI1_Init 0 */ |
|
| - | 407 | ||
| - | 408 | /* USER CODE BEGIN SPI1_Init 1 */ |
|
| - | 409 | ||
| - | 410 | /* USER CODE END SPI1_Init 1 */ |
|
| - | 411 | /* SPI1 parameter configuration*/ |
|
| 602 | hspi1.Instance = SPI1; |
412 | hspi1.Instance = SPI1; |
| 603 | hspi1.Init.Mode = SPI_MODE_MASTER; |
413 | hspi1.Init.Mode = SPI_MODE_MASTER; |
| 604 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
414 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
| 605 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
415 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
| 606 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
416 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
| 607 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
417 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
| 608 | hspi1.Init.NSS = SPI_NSS_SOFT; |
418 | hspi1.Init.NSS = SPI_NSS_SOFT; |
| 609 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; |
419 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
| 610 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
420 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
| 611 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
421 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
| 612 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
422 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
| 613 | hspi1.Init.CRCPolynomial = 10; |
423 | hspi1.Init.CRCPolynomial = 10; |
| 614 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
424 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
| 615 | { |
425 | { |
| 616 | Error_Handler(); |
426 | Error_Handler(); |
| 617 | } |
427 | } |
| - | 428 | /* USER CODE BEGIN SPI1_Init 2 */ |
|
| - | 429 | ||
| - | 430 | /* USER CODE END SPI1_Init 2 */ |
|
| 618 | 431 | ||
| 619 | } |
432 | } |
| 620 | 433 | ||
| - | 434 | /** |
|
| - | 435 | * @brief TIM2 Initialization Function |
|
| - | 436 | * @param None |
|
| - | 437 | * @retval None |
|
| - | 438 | */ |
|
| - | 439 | static void MX_TIM2_Init(void) |
|
| - | 440 | { |
|
| - | 441 | ||
| - | 442 | /* USER CODE BEGIN TIM2_Init 0 */ |
|
| - | 443 | ||
| - | 444 | /* USER CODE END TIM2_Init 0 */ |
|
| - | 445 | ||
| - | 446 | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
|
| - | 447 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
|
| - | 448 | ||
| - | 449 | /* USER CODE BEGIN TIM2_Init 1 */ |
|
| - | 450 | ||
| - | 451 | /* USER CODE END TIM2_Init 1 */ |
|
| - | 452 | htim2.Instance = TIM2; |
|
| - | 453 | htim2.Init.Prescaler = 0; |
|
| - | 454 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
|
| - | 455 | htim2.Init.Period = 65535; |
|
| - | 456 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
|
| - | 457 | htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
|
| - | 458 | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) |
|
| - | 459 | { |
|
| - | 460 | Error_Handler(); |
|
| - | 461 | } |
|
| - | 462 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
|
| - | 463 | if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) |
|
| - | 464 | { |
|
| - | 465 | Error_Handler(); |
|
| - | 466 | } |
|
| - | 467 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
|
| - | 468 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
|
| - | 469 | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
|
| - | 470 | { |
|
| - | 471 | Error_Handler(); |
|
| - | 472 | } |
|
| - | 473 | /* USER CODE BEGIN TIM2_Init 2 */ |
|
| - | 474 | ||
| - | 475 | /* USER CODE END TIM2_Init 2 */ |
|
| - | 476 | ||
| - | 477 | } |
|
| - | 478 | ||
| - | 479 | /** |
|
| 621 | /* TIM3 init function */ |
480 | * @brief TIM3 Initialization Function |
| - | 481 | * @param None |
|
| - | 482 | * @retval None |
|
| - | 483 | */ |
|
| 622 | static void MX_TIM3_Init(void) |
484 | static void MX_TIM3_Init(void) |
| 623 | { |
485 | { |
| 624 | 486 | ||
| - | 487 | /* USER CODE BEGIN TIM3_Init 0 */ |
|
| - | 488 | ||
| - | 489 | /* USER CODE END TIM3_Init 0 */ |
|
| - | 490 | ||
| 625 | TIM_Encoder_InitTypeDef sConfig; |
491 | TIM_Encoder_InitTypeDef sConfig = {0}; |
| 626 | TIM_MasterConfigTypeDef sMasterConfig; |
492 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
| - | 493 | ||
| - | 494 | /* USER CODE BEGIN TIM3_Init 1 */ |
|
| 627 | 495 | ||
| - | 496 | /* USER CODE END TIM3_Init 1 */ |
|
| 628 | htim3.Instance = TIM3; |
497 | htim3.Instance = TIM3; |
| 629 | htim3.Init.Prescaler = 0; |
498 | htim3.Init.Prescaler = 0; |
| 630 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
499 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
| 631 | htim3.Init.Period = 0xffff; |
500 | htim3.Init.Period = 65535; |
| 632 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; |
501 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
| - | 502 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
|
| 633 | sConfig.EncoderMode = TIM_ENCODERMODE_TI1; |
503 | sConfig.EncoderMode = TIM_ENCODERMODE_TI1; |
| 634 | sConfig.IC1Polarity = TIM_ICPOLARITY_FALLING; |
504 | sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; |
| 635 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
505 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
| 636 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
506 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
| 637 | sConfig.IC1Filter = 15; |
507 | sConfig.IC1Filter = 15; |
| 638 | sConfig.IC2Polarity = TIM_ICPOLARITY_FALLING; |
508 | sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; |
| 639 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
509 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
| 640 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
510 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
| 641 | sConfig.IC2Filter = 15; |
511 | sConfig.IC2Filter = 15; |
| 642 | if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK) |
512 | if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK) |
| 643 | { |
513 | { |
| 644 | Error_Handler(); |
514 | Error_Handler(); |
| 645 | } |
515 | } |
| 646 | - | ||
| 647 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
516 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
| 648 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
517 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
| 649 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) |
518 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) |
| 650 | { |
519 | { |
| 651 | Error_Handler(); |
520 | Error_Handler(); |
| 652 | } |
521 | } |
| - | 522 | /* USER CODE BEGIN TIM3_Init 2 */ |
|
| - | 523 | ||
| - | 524 | /* USER CODE END TIM3_Init 2 */ |
|
| 653 | 525 | ||
| 654 | } |
526 | } |
| 655 | 527 | ||
| - | 528 | /** |
|
| 656 | /* TIM9 init function */ |
529 | * @brief TIM9 Initialization Function |
| - | 530 | * @param None |
|
| - | 531 | * @retval None |
|
| - | 532 | */ |
|
| 657 | static void MX_TIM9_Init(void) |
533 | static void MX_TIM9_Init(void) |
| 658 | { |
534 | { |
| 659 | 535 | ||
| 660 | TIM_Encoder_InitTypeDef sConfig; |
536 | /* USER CODE BEGIN TIM9_Init 0 */ |
| 661 | TIM_MasterConfigTypeDef sMasterConfig; |
- | |
| 662 | 537 | ||
| - | 538 | /* USER CODE END TIM9_Init 0 */ |
|
| - | 539 | ||
| - | 540 | TIM_Encoder_InitTypeDef sConfig = {0}; |
|
| - | 541 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
|
| - | 542 | ||
| - | 543 | /* USER CODE BEGIN TIM9_Init 1 */ |
|
| - | 544 | ||
| - | 545 | /* USER CODE END TIM9_Init 1 */ |
|
| 663 | htim9.Instance = TIM9; |
546 | htim9.Instance = TIM9; |
| 664 | htim9.Init.Prescaler = 0; |
547 | htim9.Init.Prescaler = 0; |
| 665 | htim9.Init.CounterMode = TIM_COUNTERMODE_UP; |
548 | htim9.Init.CounterMode = TIM_COUNTERMODE_UP; |
| 666 | htim9.Init.Period = 0xffff; |
549 | htim9.Init.Period = 65535; |
| 667 | htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; |
550 | htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
| - | 551 | htim9.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
|
| 668 | sConfig.EncoderMode = TIM_ENCODERMODE_TI1; |
552 | sConfig.EncoderMode = TIM_ENCODERMODE_TI1; |
| 669 | sConfig.IC1Polarity = TIM_ICPOLARITY_FALLING; |
553 | sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; |
| 670 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
554 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
| 671 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
555 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
| 672 | sConfig.IC1Filter = 15; |
556 | sConfig.IC1Filter = 15; |
| 673 | sConfig.IC2Polarity = TIM_ICPOLARITY_FALLING; |
557 | sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; |
| 674 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
558 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
| 675 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
559 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
| 676 | sConfig.IC2Filter = 15; |
560 | sConfig.IC2Filter = 0; |
| 677 | if (HAL_TIM_Encoder_Init(&htim9, &sConfig) != HAL_OK) |
561 | if (HAL_TIM_Encoder_Init(&htim9, &sConfig) != HAL_OK) |
| 678 | { |
562 | { |
| 679 | Error_Handler(); |
563 | Error_Handler(); |
| 680 | } |
564 | } |
| 681 | - | ||
| 682 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
565 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
| 683 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
566 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
| 684 | if (HAL_TIMEx_MasterConfigSynchronization(&htim9, &sMasterConfig) != HAL_OK) |
567 | if (HAL_TIMEx_MasterConfigSynchronization(&htim9, &sMasterConfig) != HAL_OK) |
| 685 | { |
568 | { |
| 686 | Error_Handler(); |
569 | Error_Handler(); |
| 687 | } |
570 | } |
| - | 571 | /* USER CODE BEGIN TIM9_Init 2 */ |
|
| - | 572 | ||
| - | 573 | /* USER CODE END TIM9_Init 2 */ |
|
| 688 | 574 | ||
| 689 | } |
575 | } |
| 690 | 576 | ||
| - | 577 | /** |
|
| 691 | /* USART1 init function */ |
578 | * @brief USART1 Initialization Function |
| - | 579 | * @param None |
|
| - | 580 | * @retval None |
|
| - | 581 | */ |
|
| 692 | static void MX_USART1_UART_Init(void) |
582 | static void MX_USART1_UART_Init(void) |
| 693 | { |
583 | { |
| 694 | 584 | ||
| - | 585 | /* USER CODE BEGIN USART1_Init 0 */ |
|
| - | 586 | ||
| - | 587 | /* USER CODE END USART1_Init 0 */ |
|
| - | 588 | ||
| - | 589 | /* USER CODE BEGIN USART1_Init 1 */ |
|
| - | 590 | ||
| - | 591 | /* USER CODE END USART1_Init 1 */ |
|
| 695 | huart1.Instance = USART1; |
592 | huart1.Instance = USART1; |
| 696 | huart1.Init.BaudRate = 19200; |
593 | huart1.Init.BaudRate = 19200; |
| 697 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
594 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
| 698 | huart1.Init.StopBits = UART_STOPBITS_1; |
595 | huart1.Init.StopBits = UART_STOPBITS_1; |
| 699 | huart1.Init.Parity = UART_PARITY_NONE; |
596 | huart1.Init.Parity = UART_PARITY_NONE; |
| Line 702... | Line 599... | ||
| 702 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
599 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
| 703 | if (HAL_UART_Init(&huart1) != HAL_OK) |
600 | if (HAL_UART_Init(&huart1) != HAL_OK) |
| 704 | { |
601 | { |
| 705 | Error_Handler(); |
602 | Error_Handler(); |
| 706 | } |
603 | } |
| - | 604 | /* USER CODE BEGIN USART1_Init 2 */ |
|
| - | 605 | ||
| - | 606 | /* USER CODE END USART1_Init 2 */ |
|
| 707 | 607 | ||
| 708 | } |
608 | } |
| 709 | 609 | ||
| - | 610 | /** |
|
| 710 | /* USART2 init function */ |
611 | * @brief USART2 Initialization Function |
| - | 612 | * @param None |
|
| - | 613 | * @retval None |
|
| - | 614 | */ |
|
| 711 | static void MX_USART2_UART_Init(void) |
615 | static void MX_USART2_UART_Init(void) |
| 712 | { |
616 | { |
| 713 | 617 | ||
| - | 618 | /* USER CODE BEGIN USART2_Init 0 */ |
|
| - | 619 | ||
| - | 620 | /* USER CODE END USART2_Init 0 */ |
|
| - | 621 | ||
| - | 622 | /* USER CODE BEGIN USART2_Init 1 */ |
|
| - | 623 | ||
| - | 624 | /* USER CODE END USART2_Init 1 */ |
|
| 714 | huart2.Instance = USART2; |
625 | huart2.Instance = USART2; |
| 715 | huart2.Init.BaudRate = 115200; |
626 | huart2.Init.BaudRate = 115200; |
| 716 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
627 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
| 717 | huart2.Init.StopBits = UART_STOPBITS_1; |
628 | huart2.Init.StopBits = UART_STOPBITS_1; |
| 718 | huart2.Init.Parity = UART_PARITY_NONE; |
629 | huart2.Init.Parity = UART_PARITY_NONE; |
| Line 721... | Line 632... | ||
| 721 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
632 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
| 722 | if (HAL_UART_Init(&huart2) != HAL_OK) |
633 | if (HAL_UART_Init(&huart2) != HAL_OK) |
| 723 | { |
634 | { |
| 724 | Error_Handler(); |
635 | Error_Handler(); |
| 725 | } |
636 | } |
| - | 637 | /* USER CODE BEGIN USART2_Init 2 */ |
|
| - | 638 | ||
| - | 639 | /* USER CODE END USART2_Init 2 */ |
|
| 726 | 640 | ||
| 727 | } |
641 | } |
| 728 | 642 | ||
| - | 643 | /** |
|
| 729 | /* USART3 init function */ |
644 | * @brief USART3 Initialization Function |
| - | 645 | * @param None |
|
| - | 646 | * @retval None |
|
| - | 647 | */ |
|
| 730 | static void MX_USART3_UART_Init(void) |
648 | static void MX_USART3_UART_Init(void) |
| 731 | { |
649 | { |
| 732 | 650 | ||
| - | 651 | /* USER CODE BEGIN USART3_Init 0 */ |
|
| - | 652 | ||
| - | 653 | /* USER CODE END USART3_Init 0 */ |
|
| - | 654 | ||
| - | 655 | /* USER CODE BEGIN USART3_Init 1 */ |
|
| - | 656 | ||
| - | 657 | /* USER CODE END USART3_Init 1 */ |
|
| 733 | huart3.Instance = USART3; |
658 | huart3.Instance = USART3; |
| 734 | huart3.Init.BaudRate = 19200; |
659 | huart3.Init.BaudRate = 19200; |
| 735 | huart3.Init.WordLength = UART_WORDLENGTH_8B; |
660 | huart3.Init.WordLength = UART_WORDLENGTH_8B; |
| 736 | huart3.Init.StopBits = UART_STOPBITS_2; |
661 | huart3.Init.StopBits = UART_STOPBITS_1; |
| 737 | huart3.Init.Parity = UART_PARITY_NONE; |
662 | huart3.Init.Parity = UART_PARITY_NONE; |
| 738 | huart3.Init.Mode = UART_MODE_TX_RX; |
663 | huart3.Init.Mode = UART_MODE_TX_RX; |
| 739 | huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
664 | huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
| 740 | huart3.Init.OverSampling = UART_OVERSAMPLING_16; |
665 | huart3.Init.OverSampling = UART_OVERSAMPLING_16; |
| 741 | if (HAL_UART_Init(&huart3) != HAL_OK) |
666 | if (HAL_UART_Init(&huart3) != HAL_OK) |
| 742 | { |
667 | { |
| 743 | Error_Handler(); |
668 | Error_Handler(); |
| 744 | } |
669 | } |
| - | 670 | /* USER CODE BEGIN USART3_Init 2 */ |
|
| - | 671 | ||
| - | 672 | /* USER CODE END USART3_Init 2 */ |
|
| 745 | 673 | ||
| 746 | } |
674 | } |
| 747 | 675 | ||
| 748 | /** Configure pins as |
676 | /** |
| 749 | * Analog |
677 | * @brief GPIO Initialization Function |
| 750 | * Input |
678 | * @param None |
| 751 | * Output |
- | |
| 752 | * EVENT_OUT |
- | |
| 753 | * EXTI |
679 | * @retval None |
| 754 | */ |
680 | */ |
| 755 | static void MX_GPIO_Init(void) |
681 | static void MX_GPIO_Init(void) |
| 756 | { |
682 | { |
| 757 | - | ||
| 758 | GPIO_InitTypeDef GPIO_InitStruct; |
683 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| 759 | 684 | ||
| 760 | /* GPIO Ports Clock Enable */ |
685 | /* GPIO Ports Clock Enable */ |
| 761 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
686 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
| 762 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
687 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 763 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
688 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
| 764 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
689 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| 765 | 690 | ||
| 766 | /*Configure GPIO pin Output Level */ |
691 | /*Configure GPIO pin Output Level */ |
| 767 | HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin|SPI1CD_Pin|BT_BUTTON_Pin, GPIO_PIN_RESET); |
692 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
| 768 | 693 | ||
| 769 | /*Configure GPIO pin Output Level */ |
694 | /*Configure GPIO pin Output Level */ |
| 770 | HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|SPI_NSS2_Pin|POWER_LATCH_Pin|USB_PWR_Pin, GPIO_PIN_RESET); |
695 | HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin|BT_BUTTON_Pin, GPIO_PIN_RESET); |
| 771 | 696 | ||
| - | 697 | /*Configure GPIO pin Output Level */ |
|
| - | 698 | HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|POWER_LATCH_Pin|USB_PWR_Pin, GPIO_PIN_RESET); |
|
| - | 699 | ||
| - | 700 | /*Configure GPIO pin Output Level */ |
|
| - | 701 | HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
|
| - | 702 | ||
| 772 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
703 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */ |
| 773 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin; |
704 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_CD_Pin; |
| 774 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
705 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 775 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
706 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 776 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
707 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 777 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
708 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 778 | 709 | ||
| Line 808... | Line 739... | ||
| 808 | 739 | ||
| 809 | /* USER CODE END 4 */ |
740 | /* USER CODE END 4 */ |
| 810 | 741 | ||
| 811 | /** |
742 | /** |
| 812 | * @brief This function is executed in case of error occurrence. |
743 | * @brief This function is executed in case of error occurrence. |
| 813 | * @param None |
- | |
| 814 | * @retval None |
744 | * @retval None |
| 815 | */ |
745 | */ |
| 816 | void Error_Handler(void) |
746 | void Error_Handler(void) |
| 817 | { |
747 | { |
| 818 | /* USER CODE BEGIN Error_Handler */ |
748 | /* USER CODE BEGIN Error_Handler_Debug */ |
| 819 | /* User can add his own implementation to report the HAL error return state */ |
749 | /* User can add his own implementation to report the HAL error return state */ |
| 820 | while (1) |
- | |
| 821 | { |
- | |
| 822 | } |
- | |
| 823 | /* USER CODE END Error_Handler */ |
- | |
| 824 | } |
- | |
| 825 | 750 | ||
| 826 | #ifdef USE_FULL_ASSERT |
751 | /* USER CODE END Error_Handler_Debug */ |
| - | 752 | } |
|
| 827 | 753 | ||
| - | 754 | #ifdef USE_FULL_ASSERT |
|
| 828 | /** |
755 | /** |
| 829 | * @brief Reports the name of the source file and the source line number |
756 | * @brief Reports the name of the source file and the source line number |
| 830 | * where the assert_param error has occurred. |
757 | * where the assert_param error has occurred. |
| 831 | * @param file: pointer to the source file name |
758 | * @param file: pointer to the source file name |
| 832 | * @param line: assert_param error line source number |
759 | * @param line: assert_param error line source number |
| 833 | * @retval None |
760 | * @retval None |
| 834 | */ |
761 | */ |
| 835 | void assert_failed(uint8_t* file, uint32_t line) |
762 | void assert_failed(uint8_t *file, uint32_t line) |
| 836 | { |
763 | { |
| 837 | /* USER CODE BEGIN 6 */ |
764 | /* USER CODE BEGIN 6 */ |
| 838 | /* User can add his own implementation to report the file name and line number, |
765 | /* User can add his own implementation to report the file name and line number, |
| 839 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
766 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
| 840 | /* USER CODE END 6 */ |
767 | /* USER CODE END 6 */ |
| 841 | - | ||
| 842 | } |
768 | } |
| 843 | - | ||
| 844 | #endif |
769 | #endif /* USE_FULL_ASSERT */ |
| 845 | - | ||
| 846 | /** |
- | |
| 847 | * @} |
- | |
| 848 | */ |
- | |
| 849 | - | ||
| 850 | /** |
- | |
| 851 | * @} |
- | |
| 852 | */ |
- | |
| 853 | 770 | ||
| 854 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
771 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |