Rev 4 | Rev 6 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4 | Rev 5 | ||
|---|---|---|---|
| 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) 2016 STMicroelectronics |
7 | * COPYRIGHT(c) 2016 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 "stm32f1xx_hal.h" |
| 35 | 35 | ||
| 36 | /* USER CODE BEGIN Includes */ |
36 | /* USER CODE BEGIN Includes */ |
| 37 | #include "ap_math.h" |
37 | #include "ap_math.h" |
| Line 57... | Line 57... | ||
| 57 | 57 | ||
| 58 | /* USER CODE END PV */ |
58 | /* USER CODE END PV */ |
| 59 | 59 | ||
| 60 | /* Private function prototypes -----------------------------------------------*/ |
60 | /* Private function prototypes -----------------------------------------------*/ |
| 61 | void SystemClock_Config(void); |
61 | void SystemClock_Config(void); |
| - | 62 | void Error_Handler(void); |
|
| 62 | static void MX_GPIO_Init(void); |
63 | static void MX_GPIO_Init(void); |
| 63 | static void MX_ADC1_Init(void); |
64 | static void MX_ADC1_Init(void); |
| 64 | static void MX_SPI1_Init(void); |
65 | static void MX_SPI1_Init(void); |
| 65 | static void MX_USART2_UART_Init(void); |
66 | static void MX_USART2_UART_Init(void); |
| 66 | static void MX_USART1_UART_Init(void); |
67 | static void MX_USART1_UART_Init(void); |
| Line 76... | Line 77... | ||
| 76 | 77 | ||
| 77 | } |
78 | } |
| 78 | 79 | ||
| 79 | /* USER CODE END 0 */ |
80 | /* USER CODE END 0 */ |
| 80 | 81 | ||
| 81 | int main(void) { |
82 | int main(void) |
| - | 83 | { |
|
| 82 | 84 | ||
| 83 | /* USER CODE BEGIN 1 */ |
85 | /* USER CODE BEGIN 1 */ |
| 84 | 86 | ||
| 85 | GPIO_InitTypeDef GPIO_InitStruct; |
87 | GPIO_InitTypeDef GPIO_InitStruct; |
| 86 | 88 | ||
| 87 | __HAL_RCC_SPI1_CLK_ENABLE() |
89 | __HAL_RCC_SPI1_CLK_ENABLE() |
| 88 | ; |
90 | ; |
| 89 | __HAL_RCC_USART1_CLK_ENABLE() |
91 | __HAL_RCC_USART1_CLK_ENABLE() |
| 90 | ; // PLX main port |
92 | ; // PLX main port |
| 91 | __HAL_RCC_USART2_CLK_ENABLE() |
93 | __HAL_RCC_USART2_CLK_ENABLE() |
| 92 | ; // debug port |
94 | ; // debug port |
| 93 | /* USER CODE END 1 */ |
95 | /* USER CODE END 1 */ |
| 94 | 96 | ||
| 95 | /* MCU Configuration----------------------------------------------------------*/ |
97 | /* MCU Configuration----------------------------------------------------------*/ |
| 96 | 98 | ||
| 97 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
99 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
| 98 | HAL_Init(); |
100 | HAL_Init(); |
| 99 | 101 | ||
| 100 | /* Configure the system clock */ |
102 | /* Configure the system clock */ |
| 101 | SystemClock_Config(); |
103 | SystemClock_Config(); |
| 102 | 104 | ||
| 103 | /* Initialize all configured peripherals */ |
105 | /* Initialize all configured peripherals */ |
| 104 | MX_GPIO_Init(); |
106 | MX_GPIO_Init(); |
| 105 | MX_ADC1_Init(); |
107 | // MX_ADC1_Init(); |
| 106 | MX_SPI1_Init(); |
108 | MX_SPI1_Init(); |
| 107 | MX_USART2_UART_Init(); |
109 | MX_USART2_UART_Init(); |
| 108 | MX_USART1_UART_Init(); |
110 | MX_USART1_UART_Init(); |
| 109 | 111 | ||
| 110 | /* USER CODE BEGIN 2 */ |
112 | /* USER CODE BEGIN 2 */ |
| 111 | /* Need to set AF mode for output pins DURR. */ |
113 | /* Need to set AF mode for output pins DURR. */ |
| 112 | /* SPI bus AF pin selects */ |
114 | /* SPI bus AF pin selects */ |
| 113 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
115 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| 114 | 116 | ||
| 115 | GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7; |
117 | GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7; |
| Line 140... | Line 142... | ||
| 140 | EnableSerialRxInterrupt(&uc1); |
142 | EnableSerialRxInterrupt(&uc1); |
| 141 | EnableSerialRxInterrupt(&uc2); |
143 | EnableSerialRxInterrupt(&uc2); |
| 142 | 144 | ||
| 143 | ap_init(); // set up the approximate math library |
145 | ap_init(); // set up the approximate math library |
| 144 | 146 | ||
| - | 147 | int disp; |
|
| - | 148 | static const int xp = 128 - 42; |
|
| - | 149 | for(disp=0; disp< 2; disp++) |
|
| - | 150 | { |
|
| - | 151 | select_display(disp); |
|
| 145 | ssd1306_begin(1, 0); |
152 | ssd1306_begin(1, 0); |
| 146 | clearDisplay(); |
153 | clearDisplay(); |
| 147 | dim(0); |
154 | dim(0); |
| 148 | //font_puts( |
155 | //font_puts( |
| 149 | // "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font"); |
156 | // "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font"); |
| 150 | 157 | ||
| 151 | static const xp = 128 - 42; |
- | |
| 152 | dial_origin(xp, 40); |
158 | dial_origin(xp, 40); |
| 153 | dial_size(40); |
159 | dial_size(40); |
| 154 | dial_draw_scale(10, 20, 16, 2); |
160 | dial_draw_scale(10, 20, 16, 2); |
| 155 | 161 | ||
| 156 | display(); |
162 | display(); |
| 157 | 163 | ||
| - | 164 | } |
|
| 158 | InitSwitches(); |
165 | InitSwitches(); |
| 159 | 166 | ||
| - | 167 | select_display(0); |
|
| 160 | /* USER CODE END 2 */ |
168 | /* USER CODE END 2 */ |
| 161 | 169 | ||
| 162 | /* Infinite loop */ |
170 | /* Infinite loop */ |
| 163 | /* USER CODE BEGIN WHILE */ |
171 | /* USER CODE BEGIN WHILE */ |
| 164 | uint32_t Ticks = HAL_GetTick() + 100; |
172 | uint32_t Ticks = HAL_GetTick() + 100; |
| 165 | int16_t dial0 = 0; |
173 | int16_t dial0 = 0; |
| 166 | int16_t dial1 = -1; |
174 | int16_t dial1 = -1; |
| 167 | 175 | ||
| 168 | int c = 0; |
176 | int c = 0; |
| Line 229... | Line 237... | ||
| 229 | 237 | ||
| 230 | DataVal = ConvPLX(Data.Sensor[ItemIndex].ObsH, |
238 | DataVal = ConvPLX(Data.Sensor[ItemIndex].ObsH, |
| 231 | Data.Sensor[ItemIndex].ObsL); |
239 | Data.Sensor[ItemIndex].ObsL); |
| 232 | int Observation = ConvPLX(Data.Sensor[ItemIndex].ObsH, |
240 | int Observation = ConvPLX(Data.Sensor[ItemIndex].ObsH, |
| 233 | Data.Sensor[ItemIndex].ObsL); |
241 | Data.Sensor[ItemIndex].ObsL); |
| 234 | int ObservationIndex = ConvPLX(0, Data.Sensor[index].ObsIndex); |
242 | int ObservationIndex = ConvPLX(0, Data.Sensor[ItemIndex].ObsIndex); |
| 235 | // now to convert the readings and format strings |
243 | // now to convert the readings and format strings |
| 236 | // find out limits |
244 | // find out limits |
| 237 | if (Observation != OldObservation |
245 | if (Observation != OldObservation |
| 238 | || ObservationIndex != OldObservationIndex) { |
246 | || ObservationIndex != OldObservationIndex) { |
| 239 | 247 | ||
| Line 318... | Line 326... | ||
| 318 | // l--; |
326 | // l--; |
| 319 | //} |
327 | //} |
| 320 | //font_puts(itoa(hirda3.Init.BaudRate, buff, 10)); |
328 | //font_puts(itoa(hirda3.Init.BaudRate, buff, 10)); |
| 321 | display(); |
329 | display(); |
| 322 | } |
330 | } |
| 323 | /* USER CODE END WHILE */ |
331 | /* USER CODE END WHILE */ |
| 324 | 332 | ||
| 325 | /* USER CODE BEGIN 3 */ |
333 | /* USER CODE BEGIN 3 */ |
| 326 | 334 | ||
| 327 | } |
335 | } |
| 328 | /* USER CODE END 3 */ |
336 | /* USER CODE END 3 */ |
| 329 | 337 | ||
| 330 | } |
338 | } |
| 331 | 339 | ||
| 332 | /** System Clock Configuration |
340 | /** System Clock Configuration |
| 333 | */ |
341 | */ |
| 334 | void SystemClock_Config(void) { |
342 | void SystemClock_Config(void) |
| - | 343 | { |
|
| 335 | 344 | ||
| 336 | RCC_OscInitTypeDef RCC_OscInitStruct; |
345 | RCC_OscInitTypeDef RCC_OscInitStruct; |
| 337 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
346 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
| 338 | RCC_PeriphCLKInitTypeDef PeriphClkInit; |
347 | RCC_PeriphCLKInitTypeDef PeriphClkInit; |
| 339 | 348 | ||
| 340 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
349 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
| 341 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
350 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
| 342 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
351 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
| 343 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
352 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 344 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
353 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 345 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
354 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
| 346 | HAL_RCC_OscConfig(&RCC_OscInitStruct); |
355 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| - | 356 | { |
|
| - | 357 | Error_Handler(); |
|
| - | 358 | } |
|
| 347 | 359 | ||
| 348 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
360 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
| 349 | | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
361 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
| 350 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
362 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 351 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
363 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
| 352 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
364 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
| 353 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
365 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
| 354 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); |
366 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
| - | 367 | { |
|
| - | 368 | Error_Handler(); |
|
| - | 369 | } |
|
| 355 | 370 | ||
| 356 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; |
371 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; |
| 357 | PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; |
372 | PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; |
| 358 | HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); |
373 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
| - | 374 | { |
|
| - | 375 | Error_Handler(); |
|
| - | 376 | } |
|
| 359 | 377 | ||
| 360 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
378 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
| 361 | 379 | ||
| 362 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
380 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
| 363 | 381 | ||
| 364 | /* SysTick_IRQn interrupt configuration */ |
382 | /* SysTick_IRQn interrupt configuration */ |
| 365 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
383 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
| 366 | } |
384 | } |
| 367 | 385 | ||
| 368 | /* ADC1 init function */ |
386 | /* ADC1 init function */ |
| 369 | void MX_ADC1_Init(void) { |
387 | static void MX_ADC1_Init(void) |
| - | 388 | { |
|
| 370 | 389 | ||
| 371 | ADC_ChannelConfTypeDef sConfig; |
390 | ADC_ChannelConfTypeDef sConfig; |
| 372 | 391 | ||
| 373 | /**Common config |
392 | /**Common config |
| 374 | */ |
393 | */ |
| 375 | hadc1.Instance = ADC1; |
394 | hadc1.Instance = ADC1; |
| 376 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; |
395 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; |
| 377 | hadc1.Init.ContinuousConvMode = DISABLE; |
396 | hadc1.Init.ContinuousConvMode = DISABLE; |
| 378 | hadc1.Init.DiscontinuousConvMode = DISABLE; |
397 | hadc1.Init.DiscontinuousConvMode = DISABLE; |
| 379 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; |
398 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; |
| 380 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
399 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
| 381 | hadc1.Init.NbrOfConversion = 1; |
400 | hadc1.Init.NbrOfConversion = 1; |
| 382 | HAL_ADC_Init(&hadc1); |
401 | if (HAL_ADC_Init(&hadc1) != HAL_OK) |
| - | 402 | { |
|
| - | 403 | Error_Handler(); |
|
| - | 404 | } |
|
| 383 | 405 | ||
| 384 | /**Configure Regular Channel |
406 | /**Configure Regular Channel |
| 385 | */ |
407 | */ |
| 386 | sConfig.Channel = ADC_CHANNEL_0; |
408 | sConfig.Channel = ADC_CHANNEL_0; |
| 387 | sConfig.Rank = 1; |
409 | sConfig.Rank = 1; |
| 388 | sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; |
410 | sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; |
| 389 | HAL_ADC_ConfigChannel(&hadc1, &sConfig); |
411 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
| - | 412 | { |
|
| - | 413 | Error_Handler(); |
|
| - | 414 | } |
|
| 390 | 415 | ||
| 391 | } |
416 | } |
| 392 | 417 | ||
| 393 | /* SPI1 init function */ |
418 | /* SPI1 init function */ |
| 394 | void MX_SPI1_Init(void) { |
419 | static void MX_SPI1_Init(void) |
| - | 420 | { |
|
| 395 | 421 | ||
| 396 | hspi1.Instance = SPI1; |
422 | hspi1.Instance = SPI1; |
| 397 | hspi1.Init.Mode = SPI_MODE_MASTER; |
423 | hspi1.Init.Mode = SPI_MODE_MASTER; |
| 398 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
424 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
| 399 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
425 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
| 400 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
426 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
| 401 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
427 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
| 402 | hspi1.Init.NSS = SPI_NSS_SOFT; |
428 | hspi1.Init.NSS = SPI_NSS_SOFT; |
| 403 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
429 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
| 404 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
430 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
| 405 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
431 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
| 406 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
432 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
| 407 | hspi1.Init.CRCPolynomial = 10; |
433 | hspi1.Init.CRCPolynomial = 10; |
| 408 | HAL_SPI_Init(&hspi1); |
434 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
| - | 435 | { |
|
| - | 436 | Error_Handler(); |
|
| - | 437 | } |
|
| 409 | 438 | ||
| 410 | } |
439 | } |
| 411 | 440 | ||
| 412 | /* USART1 init function */ |
441 | /* USART1 init function */ |
| 413 | void MX_USART1_UART_Init(void) { |
442 | static void MX_USART1_UART_Init(void) |
| - | 443 | { |
|
| 414 | 444 | ||
| 415 | huart1.Instance = USART1; |
445 | huart1.Instance = USART1; |
| 416 | huart1.Init.BaudRate = 115200; |
446 | huart1.Init.BaudRate = 115200; |
| 417 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
447 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
| 418 | huart1.Init.StopBits = UART_STOPBITS_1; |
448 | huart1.Init.StopBits = UART_STOPBITS_1; |
| 419 | huart1.Init.Parity = UART_PARITY_NONE; |
449 | huart1.Init.Parity = UART_PARITY_NONE; |
| 420 | huart1.Init.Mode = UART_MODE_TX_RX; |
450 | huart1.Init.Mode = UART_MODE_TX_RX; |
| 421 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
451 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
| 422 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
452 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
| 423 | HAL_UART_Init(&huart1); |
453 | if (HAL_UART_Init(&huart1) != HAL_OK) |
| - | 454 | { |
|
| - | 455 | Error_Handler(); |
|
| - | 456 | } |
|
| 424 | 457 | ||
| 425 | } |
458 | } |
| 426 | 459 | ||
| 427 | /* USART2 init function */ |
460 | /* USART2 init function */ |
| 428 | void MX_USART2_UART_Init(void) { |
461 | static void MX_USART2_UART_Init(void) |
| - | 462 | { |
|
| 429 | 463 | ||
| 430 | huart2.Instance = USART2; |
464 | huart2.Instance = USART2; |
| 431 | huart2.Init.BaudRate = 115200; |
465 | huart2.Init.BaudRate = 115200; |
| 432 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
466 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
| 433 | huart2.Init.StopBits = UART_STOPBITS_1; |
467 | huart2.Init.StopBits = UART_STOPBITS_1; |
| 434 | huart2.Init.Parity = UART_PARITY_NONE; |
468 | huart2.Init.Parity = UART_PARITY_NONE; |
| 435 | huart2.Init.Mode = UART_MODE_TX_RX; |
469 | huart2.Init.Mode = UART_MODE_TX_RX; |
| 436 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
470 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
| 437 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
471 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
| 438 | HAL_UART_Init(&huart2); |
472 | if (HAL_UART_Init(&huart2) != HAL_OK) |
| - | 473 | { |
|
| - | 474 | Error_Handler(); |
|
| - | 475 | } |
|
| 439 | 476 | ||
| 440 | } |
477 | } |
| 441 | 478 | ||
| 442 | /** Configure pins as |
479 | /** Configure pins as |
| 443 | * Analog |
480 | * Analog |
| 444 | * Input |
481 | * Input |
| 445 | * Output |
482 | * Output |
| 446 | * EVENT_OUT |
483 | * EVENT_OUT |
| 447 | * EXTI |
484 | * EXTI |
| 448 | */ |
485 | */ |
| 449 | void MX_GPIO_Init(void) { |
486 | static void MX_GPIO_Init(void) |
| 450 | - | ||
| 451 | GPIO_InitTypeDef GPIO_InitStruct; |
- | |
| 452 | - | ||
| 453 | /* GPIO Ports Clock Enable */ |
- | |
| 454 | __HAL_RCC_GPIOD_CLK_ENABLE() |
- | |
| 455 | ; |
- | |
| 456 | __HAL_RCC_GPIOA_CLK_ENABLE() |
- | |
| 457 | ; |
- | |
| 458 | __HAL_RCC_GPIOC_CLK_ENABLE() |
- | |
| 459 | ; |
- | |
| 460 | __HAL_RCC_GPIOB_CLK_ENABLE() |
- | |
| 461 | ; |
- | |
| 462 | 487 | { |
|
| 463 | /*Configure GPIO pin Output Level */ |
- | |
| 464 | HAL_GPIO_WritePin(GPIOA, SPI1_NSS1_Pin | SPI1CD_Pin, GPIO_PIN_RESET); |
- | |
| 465 | 488 | ||
| 466 | /*Configure GPIO pin Output Level */ |
- | |
| 467 | HAL_GPIO_WritePin(GPIOC, |
- | |
| 468 | SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin | USB_PWR_Pin, |
- | |
| 469 | GPIO_PIN_RESET); |
- | |
| 470 | - | ||
| 471 | /*Configure GPIO pins : SPI1_NSS1_Pin SPI1CD_Pin */ |
- | |
| 472 | GPIO_InitStruct.Pin = SPI1_NSS1_Pin | SPI1CD_Pin; |
- | |
| 473 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
- | |
| 474 | GPIO_InitStruct.Speed = GPIO_SPEED_LOW; |
- | |
| 475 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
489 | GPIO_InitTypeDef GPIO_InitStruct; |
| 476 | 490 | ||
| - | 491 | /* GPIO Ports Clock Enable */ |
|
| - | 492 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
|
| - | 493 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
|
| - | 494 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
|
| - | 495 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
|
| - | 496 | ||
| - | 497 | /*Configure GPIO pin Output Level */ |
|
| - | 498 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
|
| - | 499 | ||
| - | 500 | /*Configure GPIO pin Output Level */ |
|
| - | 501 | HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET); |
|
| - | 502 | ||
| - | 503 | /*Configure GPIO pin Output Level */ |
|
| - | 504 | HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|USART3_INVERT_Pin|USB_PWR_Pin, GPIO_PIN_RESET); |
|
| - | 505 | ||
| - | 506 | /*Configure GPIO pin Output Level */ |
|
| - | 507 | HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
|
| - | 508 | ||
| - | 509 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
|
| - | 510 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin; |
|
| - | 511 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
|
| - | 512 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
|
| - | 513 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
| - | 514 | ||
| 477 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */ |
515 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */ |
| 478 | GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin |
516 | GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NSS2_Pin|USART3_INVERT_Pin|USB_PWR_Pin; |
| 479 | | USB_PWR_Pin; |
- | |
| 480 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
517 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 481 | GPIO_InitStruct.Speed = GPIO_SPEED_LOW; |
518 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 482 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
519 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
| 483 | 520 | ||
| 484 | /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */ |
521 | /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */ |
| 485 | GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin; |
522 | GPIO_InitStruct.Pin = SW1_PUSH_Pin|SW1_I_Pin|SW1_Q_Pin|SW2_PUSH_Pin; |
| 486 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
523 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| 487 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
524 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
| 488 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
525 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 489 | 526 | ||
| 490 | /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */ |
527 | /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */ |
| 491 | GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin; |
528 | GPIO_InitStruct.Pin = SW2_I_Pin|SW2_Q_Pin; |
| 492 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
529 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| 493 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
530 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
| 494 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
531 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
| 495 | 532 | ||
| 496 | } |
533 | } |
| 497 | 534 | ||
| 498 | /* USER CODE BEGIN 4 */ |
535 | /* USER CODE BEGIN 4 */ |
| 499 | 536 | ||
| 500 | /* USER CODE END 4 */ |
537 | /* USER CODE END 4 */ |
| 501 | 538 | ||
| - | 539 | /** |
|
| - | 540 | * @brief This function is executed in case of error occurrence. |
|
| - | 541 | * @param None |
|
| - | 542 | * @retval None |
|
| - | 543 | */ |
|
| - | 544 | void Error_Handler(void) |
|
| - | 545 | { |
|
| - | 546 | /* USER CODE BEGIN Error_Handler */ |
|
| - | 547 | /* User can add his own implementation to report the HAL error return state */ |
|
| - | 548 | while(1) |
|
| - | 549 | { |
|
| - | 550 | } |
|
| - | 551 | /* USER CODE END Error_Handler */ |
|
| - | 552 | } |
|
| - | 553 | ||
| 502 | #ifdef USE_FULL_ASSERT |
554 | #ifdef USE_FULL_ASSERT |
| 503 | 555 | ||
| 504 | /** |
556 | /** |
| 505 | * @brief Reports the name of the source file and the source line number |
557 | * @brief Reports the name of the source file and the source line number |
| 506 | * where the assert_param error has occurred. |
558 | * where the assert_param error has occurred. |
| 507 | * @param file: pointer to the source file name |
559 | * @param file: pointer to the source file name |
| 508 | * @param line: assert_param error line source number |
560 | * @param line: assert_param error line source number |
| 509 | * @retval None |
561 | * @retval None |
| 510 | */ |
562 | */ |
| 511 | void assert_failed(uint8_t* file, uint32_t line) |
563 | void assert_failed(uint8_t* file, uint32_t line) |
| 512 | { |
564 | { |
| 513 | /* USER CODE BEGIN 6 */ |
565 | /* USER CODE BEGIN 6 */ |
| 514 | /* User can add his own implementation to report the file name and line number, |
566 | /* User can add his own implementation to report the file name and line number, |
| 515 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
567 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
| 516 | /* USER CODE END 6 */ |
568 | /* USER CODE END 6 */ |
| 517 | 569 | ||
| 518 | } |
570 | } |
| 519 | 571 | ||
| 520 | #endif |
572 | #endif |
| 521 | 573 | ||
| 522 | /** |
574 | /** |
| 523 | * @} |
575 | * @} |
| 524 | */ |
576 | */ |
| 525 | 577 | ||
| 526 | /** |
578 | /** |
| 527 | * @} |
579 | * @} |
| 528 | */ |
580 | */ |
| 529 | 581 | ||
| 530 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
582 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |