Rev 5 | Rev 7 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /** |
6 | mjames | 2 | ****************************************************************************** |
3 | * File Name : main.c |
||
4 | * Description : Main program body |
||
5 | ****************************************************************************** |
||
6 | * |
||
7 | * COPYRIGHT(c) 2016 STMicroelectronics |
||
8 | * |
||
9 | * Redistribution and use in source and binary forms, with or without modification, |
||
10 | * are permitted provided that the following conditions are met: |
||
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. |
||
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 |
||
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 | * |
||
31 | ****************************************************************************** |
||
32 | */ |
||
2 | mjames | 33 | /* Includes ------------------------------------------------------------------*/ |
34 | #include "stm32f1xx_hal.h" |
||
35 | |||
36 | /* USER CODE BEGIN Includes */ |
||
37 | #include "ap_math.h" |
||
38 | #include "serial.h" |
||
39 | #include "SSD1306.h" |
||
40 | #include "dials.h" |
||
4 | mjames | 41 | #include "switches.h" |
2 | mjames | 42 | #include <math.h> |
4 | mjames | 43 | #include "plx.h" |
2 | mjames | 44 | |
45 | /* USER CODE END Includes */ |
||
46 | |||
47 | /* Private variables ---------------------------------------------------------*/ |
||
48 | ADC_HandleTypeDef hadc1; |
||
49 | |||
50 | SPI_HandleTypeDef hspi1; |
||
51 | |||
3 | mjames | 52 | UART_HandleTypeDef huart1; |
2 | mjames | 53 | UART_HandleTypeDef huart2; |
54 | |||
55 | /* USER CODE BEGIN PV */ |
||
56 | /* Private variables ---------------------------------------------------------*/ |
||
57 | |||
58 | /* USER CODE END PV */ |
||
59 | |||
60 | /* Private function prototypes -----------------------------------------------*/ |
||
6 | mjames | 61 | void |
62 | SystemClock_Config (void); |
||
63 | void |
||
64 | Error_Handler (void); |
||
65 | static void |
||
66 | MX_GPIO_Init (void); |
||
67 | static void |
||
68 | MX_ADC1_Init (void); |
||
69 | static void |
||
70 | MX_SPI1_Init (void); |
||
71 | static void |
||
72 | MX_USART2_UART_Init (void); |
||
73 | static void |
||
74 | MX_USART1_UART_Init (void); |
||
2 | mjames | 75 | |
76 | /* USER CODE BEGIN PFP */ |
||
77 | /* Private function prototypes -----------------------------------------------*/ |
||
78 | |||
79 | /* USER CODE END PFP */ |
||
80 | |||
81 | /* USER CODE BEGIN 0 */ |
||
82 | /* dummy function */ |
||
6 | mjames | 83 | void |
84 | _init (void) |
||
85 | { |
||
2 | mjames | 86 | |
87 | } |
||
88 | |||
89 | /* USER CODE END 0 */ |
||
90 | |||
6 | mjames | 91 | int |
92 | main (void) |
||
5 | mjames | 93 | { |
2 | mjames | 94 | |
5 | mjames | 95 | /* USER CODE BEGIN 1 */ |
2 | mjames | 96 | |
6 | mjames | 97 | GPIO_InitTypeDef GPIO_InitStruct; |
2 | mjames | 98 | |
6 | mjames | 99 | __HAL_RCC_SPI1_CLK_ENABLE() |
100 | ; |
||
101 | __HAL_RCC_USART1_CLK_ENABLE() |
||
102 | ; // PLX main port |
||
103 | __HAL_RCC_USART2_CLK_ENABLE() |
||
104 | ; // debug port |
||
5 | mjames | 105 | /* USER CODE END 1 */ |
2 | mjames | 106 | |
5 | mjames | 107 | /* MCU Configuration----------------------------------------------------------*/ |
2 | mjames | 108 | |
5 | mjames | 109 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
6 | mjames | 110 | HAL_Init (); |
2 | mjames | 111 | |
5 | mjames | 112 | /* Configure the system clock */ |
6 | mjames | 113 | SystemClock_Config (); |
2 | mjames | 114 | |
5 | mjames | 115 | /* Initialize all configured peripherals */ |
6 | mjames | 116 | MX_GPIO_Init (); |
117 | // MX_ADC1_Init(); |
||
118 | MX_SPI1_Init (); |
||
119 | MX_USART2_UART_Init (); |
||
120 | MX_USART1_UART_Init (); |
||
2 | mjames | 121 | |
5 | mjames | 122 | /* USER CODE BEGIN 2 */ |
6 | mjames | 123 | /* Need to set AF mode for output pins DURR. */ |
124 | /* SPI bus AF pin selects */ |
||
125 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
||
2 | mjames | 126 | |
6 | mjames | 127 | GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7; |
128 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
129 | HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); |
||
2 | mjames | 130 | |
6 | mjames | 131 | /* USART2 AF pin selects */ |
132 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
||
133 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
134 | HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); |
||
2 | mjames | 135 | |
6 | mjames | 136 | /* USART1 AF pin selects */ |
137 | GPIO_InitStruct.Pin = GPIO_PIN_9; |
||
138 | HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); |
||
2 | mjames | 139 | |
6 | mjames | 140 | /* Turn on USART2 IRQ */ |
141 | HAL_NVIC_SetPriority (USART2_IRQn, 4, 0); |
||
142 | HAL_NVIC_EnableIRQ (USART2_IRQn); |
||
2 | mjames | 143 | |
6 | mjames | 144 | /* Turn on USART1 IRQ */ |
145 | HAL_NVIC_SetPriority (USART1_IRQn, 2, 0); |
||
146 | HAL_NVIC_EnableIRQ (USART1_IRQn); |
||
2 | mjames | 147 | |
6 | mjames | 148 | /* setup the USART control blocks */ |
149 | init_usart_ctl (&uc1, huart1.Instance); |
||
150 | init_usart_ctl (&uc2, huart2.Instance); |
||
2 | mjames | 151 | |
6 | mjames | 152 | EnableSerialRxInterrupt (&uc1); |
153 | EnableSerialRxInterrupt (&uc2); |
||
2 | mjames | 154 | |
6 | mjames | 155 | ap_init (); // set up the approximate math library |
2 | mjames | 156 | |
6 | mjames | 157 | int disp; |
158 | |||
159 | ssd1306_begin (1, 0); |
||
160 | // static const int xp = 128 - 42; |
||
161 | for (disp = 0; disp < 2; disp++) |
||
5 | mjames | 162 | { |
6 | mjames | 163 | select_display (disp); |
164 | clearDisplay (); |
||
165 | dim (0); |
||
166 | //font_puts( |
||
167 | // "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font"); |
||
2 | mjames | 168 | |
6 | mjames | 169 | dial_origin (64, 60); |
170 | dial_size (60); |
||
171 | dial_draw_scale (10, 16, 16, 2); |
||
2 | mjames | 172 | |
6 | mjames | 173 | display (); |
2 | mjames | 174 | |
5 | mjames | 175 | } |
6 | mjames | 176 | InitSwitches (); |
2 | mjames | 177 | |
6 | mjames | 178 | select_display (0); |
5 | mjames | 179 | /* USER CODE END 2 */ |
4 | mjames | 180 | |
5 | mjames | 181 | /* Infinite loop */ |
182 | /* USER CODE BEGIN WHILE */ |
||
6 | mjames | 183 | uint32_t Ticks = HAL_GetTick () + 100; |
184 | int16_t dial0 = 0; |
||
185 | int16_t dial1 = -1; |
||
2 | mjames | 186 | |
6 | mjames | 187 | int c = 0; |
188 | int i; |
||
189 | char buff[10]; |
||
2 | mjames | 190 | |
6 | mjames | 191 | // PLX decoder protocol |
4 | mjames | 192 | #define MAXRDG 10 |
6 | mjames | 193 | char PLXPacket = 0; |
194 | union |
||
195 | { |
||
196 | PLX_SensorInfo Sensor[MAXRDG]; |
||
197 | char Bytes[MAXRDG * sizeof(PLX_SensorInfo)]; |
||
198 | } Data; |
||
199 | int Max[MAXRDG]; |
||
200 | int Min[MAXRDG]; |
||
201 | for (i = 0; i < MAXRDG; i++) |
||
202 | { |
||
203 | Max[i] = 0; |
||
204 | Min[i] = 0xFFF; // 12 bit max value |
||
205 | } |
||
2 | mjames | 206 | |
6 | mjames | 207 | int PLXPtr; |
208 | int PLXItems; |
||
4 | mjames | 209 | |
6 | mjames | 210 | int OldObservation = -1; // illegal initial value |
211 | int OldObservationIndex = -1; // if more than one sensor this will be printed |
||
212 | while (1) |
||
213 | { |
||
4 | mjames | 214 | // poll switches |
6 | mjames | 215 | HandleSwitches (); |
216 | int ItemIndex = dial_pos[0]; |
||
2 | mjames | 217 | |
6 | mjames | 218 | uint16_t cc = SerialCharsReceived (&uc1); |
219 | for (i = 0; i < cc; i++) |
||
220 | { |
||
221 | char c = GetCharSerial (&uc1); |
||
222 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
||
223 | { |
||
224 | PLXPtr = 0; // reset the pointer |
||
225 | PLXPacket = 1; |
||
226 | continue; |
||
227 | } |
||
4 | mjames | 228 | |
6 | mjames | 229 | if (c == PLX_Stop) |
230 | { |
||
231 | // we can now decode the selected parameter |
||
232 | PLXPacket = 0; |
||
233 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
||
234 | // saturate the rotary switch position |
||
235 | if (ItemIndex > PLXItems) |
||
236 | { |
||
237 | dial_pos[0] = PLXItems; |
||
238 | ItemIndex = PLXItems; |
||
239 | } |
||
4 | mjames | 240 | |
6 | mjames | 241 | int DataVal; |
242 | // process min/max |
||
243 | for (i = 0; i < PLXItems; i++) |
||
244 | { |
||
245 | DataVal = ConvPLX (Data.Sensor[i].ObsH, Data.Sensor[i].ObsL); |
||
246 | if (DataVal > Max[i]) |
||
247 | { |
||
248 | Max[i] = DataVal; |
||
249 | } |
||
250 | if (DataVal < Min[i]) |
||
251 | { |
||
252 | Min[i] = DataVal; |
||
253 | } |
||
254 | } |
||
4 | mjames | 255 | |
6 | mjames | 256 | DataVal = ConvPLX (Data.Sensor[ItemIndex].ObsH, |
257 | Data.Sensor[ItemIndex].ObsL); // data reading |
||
258 | int Observation = ConvPLX (Data.Sensor[ItemIndex].ObsH, |
||
259 | Data.Sensor[ItemIndex].ObsL); |
||
260 | int ObservationIndex = ConvPLX (0, |
||
261 | Data.Sensor[ItemIndex].ObsIndex); |
||
262 | // now to convert the readings and format strings |
||
263 | // find out limits |
||
264 | char * msg; |
||
265 | int len; |
||
4 | mjames | 266 | |
6 | mjames | 267 | if (Observation < PLX_MAX_OBS) |
268 | { |
||
269 | if (Observation != OldObservation |
||
270 | || ObservationIndex != OldObservationIndex) |
||
271 | { |
||
272 | dial1 = -1; |
||
273 | clearDisplay(); |
||
4 | mjames | 274 | |
6 | mjames | 275 | dial_draw_scale ( |
276 | DisplayInfo[Observation].Low |
||
277 | / DisplayInfo[Observation].TickScale, |
||
278 | DisplayInfo[Observation].High |
||
279 | / DisplayInfo[Observation].TickScale, |
||
280 | 16, 1); |
||
281 | if (ObservationIndex > 0) |
||
282 | { |
||
283 | len = 5; |
||
284 | buff[6] = ObservationIndex + '1'; |
||
4 | mjames | 285 | } |
6 | mjames | 286 | else |
287 | { |
||
288 | len = 6; |
||
4 | mjames | 289 | } |
6 | mjames | 290 | { |
291 | msg = DisplayInfo[Observation].name; |
||
4 | mjames | 292 | } |
6 | mjames | 293 | for (i = 0; i < len; i++) |
294 | { |
||
295 | buff[i] = msg[i]; |
||
296 | } |
||
297 | print_large_string (buff, 32, 48, 6); // this prints spaces for \0 at end of string |
||
4 | mjames | 298 | |
6 | mjames | 299 | OldObservation = Observation; |
300 | OldObservationIndex = ObservationIndex; |
||
301 | // |
||
302 | } |
||
2 | mjames | 303 | |
6 | mjames | 304 | double max_rdg; |
305 | double min_rdg; |
||
306 | double cur_rdg; |
||
4 | mjames | 307 | |
6 | mjames | 308 | max_rdg = ConveriMFDRaw2Data (Observation, |
309 | DisplayInfo[Observation].Units, |
||
310 | Max[ItemIndex]); |
||
311 | min_rdg = ConveriMFDRaw2Data (Observation, |
||
312 | DisplayInfo[Observation].Units, |
||
313 | Min[ItemIndex]); |
||
314 | cur_rdg = ConveriMFDRaw2Data (Observation, |
||
315 | DisplayInfo[Observation].Units, |
||
316 | DataVal); |
||
317 | } |
||
318 | } |
||
319 | if (c > PLX_Stop) // illegal char, restart reading |
||
320 | { |
||
321 | PLXPacket = 0; |
||
322 | } |
||
323 | if (PLXPtr < sizeof(Data.Bytes)) |
||
324 | { |
||
325 | Data.Bytes[PLXPtr++] = c; |
||
326 | } |
||
327 | } |
||
4 | mjames | 328 | |
6 | mjames | 329 | HAL_Delay (1); |
4 | mjames | 330 | |
6 | mjames | 331 | /* now scale and decode the dial position etc . |
332 | * |
||
333 | */ |
||
334 | uint32_t CurrTicks = HAL_GetTick (); |
||
335 | if (CurrTicks > Ticks) |
||
336 | { |
||
337 | /* Lookup the dial etc . */ |
||
2 | mjames | 338 | |
6 | mjames | 339 | Ticks = CurrTicks + 100; |
340 | /* old needle un-draw */ |
||
341 | if (dial1 >= 0) |
||
342 | { |
||
343 | dial_draw_needle (dial1); |
||
344 | } |
||
345 | dial0 = c % 100; |
||
346 | dial_draw_needle (dial0); |
||
347 | // print value overlaid by needle |
||
348 | // this is actual reading |
||
349 | print_digits (64 - 16, 30, 4, 3, c); |
||
2 | mjames | 350 | |
6 | mjames | 351 | dial1 = dial0; |
2 | mjames | 352 | |
6 | mjames | 353 | c++; |
354 | //font_gotoxy(0, 2); |
||
355 | //font_puts("baud\r\n"); |
||
356 | //char buff[10]; |
||
357 | //itoa(hirda3.Init.BaudRate, buff, 10); |
||
358 | //char l = 6 - strlen(buff); |
||
359 | /* pad with leading spaces */ |
||
360 | //while (l > 0) { |
||
361 | // font_putchar(' '); |
||
362 | // l--; |
||
363 | //} |
||
364 | //font_puts(itoa(hirda3.Init.BaudRate, buff, 10)); |
||
365 | display (); |
||
366 | } |
||
367 | /* USER CODE END WHILE */ |
||
2 | mjames | 368 | |
6 | mjames | 369 | /* USER CODE BEGIN 3 */ |
370 | |||
371 | } |
||
5 | mjames | 372 | /* USER CODE END 3 */ |
2 | mjames | 373 | |
374 | } |
||
375 | |||
376 | /** System Clock Configuration |
||
6 | mjames | 377 | */ |
378 | void |
||
379 | SystemClock_Config (void) |
||
5 | mjames | 380 | { |
2 | mjames | 381 | |
5 | mjames | 382 | RCC_OscInitTypeDef RCC_OscInitStruct; |
383 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
||
384 | RCC_PeriphCLKInitTypeDef PeriphClkInit; |
||
2 | mjames | 385 | |
5 | mjames | 386 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
387 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
||
388 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
||
389 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
||
390 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
||
391 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
||
6 | mjames | 392 | if (HAL_RCC_OscConfig (&RCC_OscInitStruct) != HAL_OK) |
393 | { |
||
394 | Error_Handler (); |
||
395 | } |
||
2 | mjames | 396 | |
6 | mjames | 397 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
398 | | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
||
5 | mjames | 399 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
400 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||
401 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
||
402 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
||
6 | mjames | 403 | if (HAL_RCC_ClockConfig (&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
404 | { |
||
405 | Error_Handler (); |
||
406 | } |
||
2 | mjames | 407 | |
5 | mjames | 408 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; |
409 | PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; |
||
6 | mjames | 410 | if (HAL_RCCEx_PeriphCLKConfig (&PeriphClkInit) != HAL_OK) |
411 | { |
||
412 | Error_Handler (); |
||
413 | } |
||
2 | mjames | 414 | |
6 | mjames | 415 | HAL_SYSTICK_Config (HAL_RCC_GetHCLKFreq () / 1000); |
2 | mjames | 416 | |
6 | mjames | 417 | HAL_SYSTICK_CLKSourceConfig (SYSTICK_CLKSOURCE_HCLK); |
2 | mjames | 418 | |
5 | mjames | 419 | /* SysTick_IRQn interrupt configuration */ |
6 | mjames | 420 | HAL_NVIC_SetPriority (SysTick_IRQn, 0, 0); |
2 | mjames | 421 | } |
422 | |||
423 | /* ADC1 init function */ |
||
6 | mjames | 424 | static void |
425 | MX_ADC1_Init (void) |
||
5 | mjames | 426 | { |
2 | mjames | 427 | |
5 | mjames | 428 | ADC_ChannelConfTypeDef sConfig; |
2 | mjames | 429 | |
6 | mjames | 430 | /**Common config |
431 | */ |
||
5 | mjames | 432 | hadc1.Instance = ADC1; |
433 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; |
||
434 | hadc1.Init.ContinuousConvMode = DISABLE; |
||
435 | hadc1.Init.DiscontinuousConvMode = DISABLE; |
||
436 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; |
||
437 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
||
438 | hadc1.Init.NbrOfConversion = 1; |
||
6 | mjames | 439 | if (HAL_ADC_Init (&hadc1) != HAL_OK) |
440 | { |
||
441 | Error_Handler (); |
||
442 | } |
||
2 | mjames | 443 | |
6 | mjames | 444 | /**Configure Regular Channel |
445 | */ |
||
5 | mjames | 446 | sConfig.Channel = ADC_CHANNEL_0; |
447 | sConfig.Rank = 1; |
||
448 | sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; |
||
6 | mjames | 449 | if (HAL_ADC_ConfigChannel (&hadc1, &sConfig) != HAL_OK) |
450 | { |
||
451 | Error_Handler (); |
||
452 | } |
||
2 | mjames | 453 | |
454 | } |
||
455 | |||
456 | /* SPI1 init function */ |
||
6 | mjames | 457 | static void |
458 | MX_SPI1_Init (void) |
||
5 | mjames | 459 | { |
2 | mjames | 460 | |
5 | mjames | 461 | hspi1.Instance = SPI1; |
462 | hspi1.Init.Mode = SPI_MODE_MASTER; |
||
463 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
||
464 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
||
465 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
||
466 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
||
467 | hspi1.Init.NSS = SPI_NSS_SOFT; |
||
468 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
||
469 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
||
470 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||
471 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||
472 | hspi1.Init.CRCPolynomial = 10; |
||
6 | mjames | 473 | if (HAL_SPI_Init (&hspi1) != HAL_OK) |
474 | { |
||
475 | Error_Handler (); |
||
476 | } |
||
2 | mjames | 477 | |
478 | } |
||
479 | |||
3 | mjames | 480 | /* USART1 init function */ |
6 | mjames | 481 | static void |
482 | MX_USART1_UART_Init (void) |
||
5 | mjames | 483 | { |
3 | mjames | 484 | |
5 | mjames | 485 | huart1.Instance = USART1; |
486 | huart1.Init.BaudRate = 115200; |
||
487 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
||
488 | huart1.Init.StopBits = UART_STOPBITS_1; |
||
489 | huart1.Init.Parity = UART_PARITY_NONE; |
||
490 | huart1.Init.Mode = UART_MODE_TX_RX; |
||
491 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
492 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
||
6 | mjames | 493 | if (HAL_UART_Init (&huart1) != HAL_OK) |
494 | { |
||
495 | Error_Handler (); |
||
496 | } |
||
3 | mjames | 497 | |
498 | } |
||
499 | |||
2 | mjames | 500 | /* USART2 init function */ |
6 | mjames | 501 | static void |
502 | MX_USART2_UART_Init (void) |
||
5 | mjames | 503 | { |
2 | mjames | 504 | |
5 | mjames | 505 | huart2.Instance = USART2; |
506 | huart2.Init.BaudRate = 115200; |
||
507 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
||
508 | huart2.Init.StopBits = UART_STOPBITS_1; |
||
509 | huart2.Init.Parity = UART_PARITY_NONE; |
||
510 | huart2.Init.Mode = UART_MODE_TX_RX; |
||
511 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
512 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
||
6 | mjames | 513 | if (HAL_UART_Init (&huart2) != HAL_OK) |
514 | { |
||
515 | Error_Handler (); |
||
516 | } |
||
2 | mjames | 517 | |
518 | } |
||
519 | |||
6 | mjames | 520 | /** Configure pins as |
521 | * Analog |
||
522 | * Input |
||
523 | * Output |
||
524 | * EVENT_OUT |
||
525 | * EXTI |
||
526 | */ |
||
527 | static void |
||
528 | MX_GPIO_Init (void) |
||
5 | mjames | 529 | { |
2 | mjames | 530 | |
5 | mjames | 531 | GPIO_InitTypeDef GPIO_InitStruct; |
2 | mjames | 532 | |
5 | mjames | 533 | /* GPIO Ports Clock Enable */ |
6 | mjames | 534 | __HAL_RCC_GPIOD_CLK_ENABLE() |
535 | ; |
||
536 | __HAL_RCC_GPIOA_CLK_ENABLE() |
||
537 | ; |
||
538 | __HAL_RCC_GPIOC_CLK_ENABLE() |
||
539 | ; |
||
540 | __HAL_RCC_GPIOB_CLK_ENABLE() |
||
541 | ; |
||
2 | mjames | 542 | |
5 | mjames | 543 | /*Configure GPIO pin Output Level */ |
6 | mjames | 544 | HAL_GPIO_WritePin (SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
2 | mjames | 545 | |
5 | mjames | 546 | /*Configure GPIO pin Output Level */ |
6 | mjames | 547 | HAL_GPIO_WritePin (SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET); |
2 | mjames | 548 | |
5 | mjames | 549 | /*Configure GPIO pin Output Level */ |
6 | mjames | 550 | HAL_GPIO_WritePin (GPIOC, SPI_RESET_Pin | USART3_INVERT_Pin | USB_PWR_Pin, |
551 | GPIO_PIN_RESET); |
||
2 | mjames | 552 | |
5 | mjames | 553 | /*Configure GPIO pin Output Level */ |
6 | mjames | 554 | HAL_GPIO_WritePin (SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
2 | mjames | 555 | |
5 | mjames | 556 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
6 | mjames | 557 | GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI1CD_Pin; |
5 | mjames | 558 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
559 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
6 | mjames | 560 | HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); |
2 | mjames | 561 | |
5 | mjames | 562 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */ |
6 | mjames | 563 | GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin |
564 | | USB_PWR_Pin; |
||
5 | mjames | 565 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
566 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
6 | mjames | 567 | HAL_GPIO_Init (GPIOC, &GPIO_InitStruct); |
2 | mjames | 568 | |
5 | mjames | 569 | /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */ |
6 | mjames | 570 | GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin; |
5 | mjames | 571 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
572 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
||
6 | mjames | 573 | HAL_GPIO_Init (GPIOB, &GPIO_InitStruct); |
5 | mjames | 574 | |
575 | /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */ |
||
6 | mjames | 576 | GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin; |
5 | mjames | 577 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
578 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
||
6 | mjames | 579 | HAL_GPIO_Init (GPIOC, &GPIO_InitStruct); |
5 | mjames | 580 | |
2 | mjames | 581 | } |
582 | |||
583 | /* USER CODE BEGIN 4 */ |
||
584 | |||
585 | /* USER CODE END 4 */ |
||
586 | |||
5 | mjames | 587 | /** |
6 | mjames | 588 | * @brief This function is executed in case of error occurrence. |
589 | * @param None |
||
590 | * @retval None |
||
591 | */ |
||
592 | void |
||
593 | Error_Handler (void) |
||
5 | mjames | 594 | { |
595 | /* USER CODE BEGIN Error_Handler */ |
||
596 | /* User can add his own implementation to report the HAL error return state */ |
||
6 | mjames | 597 | while (1) |
598 | { |
||
599 | } |
||
600 | /* USER CODE END Error_Handler */ |
||
5 | mjames | 601 | } |
602 | |||
2 | mjames | 603 | #ifdef USE_FULL_ASSERT |
604 | |||
605 | /** |
||
6 | mjames | 606 | * @brief Reports the name of the source file and the source line number |
607 | * where the assert_param error has occurred. |
||
608 | * @param file: pointer to the source file name |
||
609 | * @param line: assert_param error line source number |
||
610 | * @retval None |
||
611 | */ |
||
2 | mjames | 612 | void assert_failed(uint8_t* file, uint32_t line) |
6 | mjames | 613 | { |
614 | /* USER CODE BEGIN 6 */ |
||
615 | /* User can add his own implementation to report the file name and line number, |
||
616 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||
617 | /* USER CODE END 6 */ |
||
2 | mjames | 618 | |
6 | mjames | 619 | } |
2 | mjames | 620 | |
621 | #endif |
||
622 | |||
623 | /** |
||
6 | mjames | 624 | * @} |
625 | */ |
||
2 | mjames | 626 | |
627 | /** |
||
6 | mjames | 628 | * @} |
629 | */ |
||
2 | mjames | 630 | |
631 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |