Mercurial > public > ostc4
annotate Discovery/Src/ostc.c @ 1046:1d7c7a36df15 GasConsumption
Bugfix OSTC5 BT and enabling fast mode:
The OSTC5 BT was operating at default speed of 115200. To enable the faster communication some init steps have been added to set speed to 460800. Having the UART enabled while the module was shut down caused problems during initialisation. To avoid these the BT UART is now initialized after the the module is powered on and deinitialized while the module is switched off.
| author | Ideenmodellierer |
|---|---|
| date | Fri, 14 Nov 2025 18:54:20 +0100 |
| parents | 5865f0aeb438 |
| children |
| rev | line source |
|---|---|
| 38 | 1 /////////////////////////////////////////////////////////////////////////////// |
| 2 /// -*- coding: UTF-8 -*- | |
| 3 /// | |
| 4 /// \file Discovery/Src/ostc.c | |
| 5 /// \brief Hardware specific configuration | |
| 6 /// \author Heinrichs Weikamp gmbh | |
| 7 /// \date 05-Dec-2014 | |
| 8 /// | |
| 9 /// \details | |
| 10 /// | |
| 11 /// $Id$ | |
| 12 /////////////////////////////////////////////////////////////////////////////// | |
| 13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
| 14 /// | |
| 15 /// This program is free software: you can redistribute it and/or modify | |
| 16 /// it under the terms of the GNU General Public License as published by | |
| 17 /// the Free Software Foundation, either version 3 of the License, or | |
| 18 /// (at your option) any later version. | |
| 19 /// | |
| 20 /// This program is distributed in the hope that it will be useful, | |
| 21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 23 /// GNU General Public License for more details. | |
| 24 /// | |
| 25 /// You should have received a copy of the GNU General Public License | |
| 26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 27 ////////////////////////////////////////////////////////////////////////////// | |
| 28 | |
| 29 /* Includes ------------------------------------------------------------------*/ | |
| 1032 | 30 #include "configuration.h" |
| 38 | 31 #include "ostc.h" |
| 32 #include "stm32f4xx_hal.h" | |
| 1032 | 33 #include "cv_heartbeat.h" |
| 38 | 34 |
| 35 #ifndef BOOTLOADER_STANDALONE | |
| 36 #include "tCCR.h" | |
| 37 #endif | |
| 38 | |
| 39 /* Exported variables --------------------------------------------------------*/ | |
| 40 SPI_HandleTypeDef hspiDisplay; | |
| 41 SPI_HandleTypeDef cpu2DmaSpi; | |
| 42 | |
| 43 | |
| 44 UART_HandleTypeDef UartHandle; | |
|
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
140
diff
changeset
|
45 #ifdef USART_PIEZO |
| 38 | 46 UART_HandleTypeDef UartPiezoTxHandle; |
|
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
140
diff
changeset
|
47 #endif |
| 38 | 48 UART_HandleTypeDef UartIR_HUD_Handle; |
| 49 | |
| 1036 | 50 #ifdef ENABLE_USART_RADIO |
| 51 UART_HandleTypeDef UartRadio_Handle; | |
| 52 #endif | |
| 53 | |
| 38 | 54 __IO ITStatus UartReady = RESET; |
| 870 | 55 __IO ITStatus UartReadyHUD = RESET; |
| 38 | 56 |
| 57 /* Private types -------------------------------------------------------------*/ | |
| 58 | |
| 59 /* Private variables ---------------------------------------------------------*/ | |
| 60 | |
| 61 /* Private variables with external access via get_xxx() function -------------*/ | |
|
885
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
62 static uint8_t hardwareDisplay = 0; //< either OSTC4 LCD (=0) or new Screen (=1) |
| 1032 | 63 |
| 1036 | 64 #ifdef ENABLE_PULSE_SENSOR_BT |
| 65 static DMA_HandleTypeDef hdma_uart_BT_rx; | |
| 66 #endif | |
| 67 | |
| 68 #ifdef ENABLE_USART_RADIO | |
| 69 static DMA_HandleTypeDef hdma_uart_radio_rx; | |
| 70 #endif | |
| 71 | |
| 1032 | 72 static uint16_t rxBufRead = 0; |
| 73 static uint16_t rxBufWrite = 0; | |
| 74 static uint8_t rxBufferUart[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow variations in buffer read time */ | |
| 75 | |
| 38 | 76 /* Private function prototypes -----------------------------------------------*/ |
| 77 | |
| 78 /* Exported functions --------------------------------------------------------*/ | |
| 79 | |
| 80 /** SPI init function | |
| 81 * called from HAL | |
| 82 */ | |
| 83 void MX_SPI_Init(void) | |
| 84 { | |
| 85 hspiDisplay.Instance = SPI5; | |
| 86 hspiDisplay.Init.Mode = SPI_MODE_MASTER; | |
| 87 hspiDisplay.Init.Direction = SPI_DIRECTION_2LINES; | |
| 88 hspiDisplay.Init.DataSize = SPI_DATASIZE_8BIT; | |
| 89 hspiDisplay.Init.CLKPolarity = SPI_POLARITY_LOW; | |
| 90 hspiDisplay.Init.CLKPhase = SPI_PHASE_1EDGE; | |
| 91 hspiDisplay.Init.NSS = SPI_NSS_SOFT; | |
| 92 hspiDisplay.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;//SPI_BAUDRATEPRESCALER_4;//SPI_BAUDRATEPRESCALER_256; | |
| 93 hspiDisplay.Init.FirstBit = SPI_FIRSTBIT_MSB; | |
| 94 hspiDisplay.Init.TIMode = SPI_TIMODE_DISABLED; | |
| 95 hspiDisplay.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; | |
| 96 HAL_SPI_Init(&hspiDisplay); | |
| 97 | |
| 98 cpu2DmaSpi.Instance = SPI1; | |
| 99 cpu2DmaSpi.Init.Mode = SPI_MODE_MASTER; | |
| 100 cpu2DmaSpi.Init.Direction = SPI_DIRECTION_2LINES; | |
| 101 cpu2DmaSpi.Init.DataSize = SPI_DATASIZE_8BIT; | |
| 102 cpu2DmaSpi.Init.CLKPolarity = SPI_POLARITY_LOW; | |
| 103 cpu2DmaSpi.Init.CLKPhase = SPI_PHASE_1EDGE; | |
| 104 cpu2DmaSpi.Init.NSS = SPI_NSS_SOFT;//SPI_NSS_HARD_OUTPUT;//SPI_NSS_SOFT; | |
|
140
f6c52eb0e25d
Increase prescalar => frame takes about 4ms.
Ideenmodellierer
parents:
104
diff
changeset
|
105 cpu2DmaSpi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; |
| 38 | 106 cpu2DmaSpi.Init.FirstBit = SPI_FIRSTBIT_MSB; |
| 107 cpu2DmaSpi.Init.TIMode = SPI_TIMODE_DISABLED; | |
| 108 cpu2DmaSpi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; | |
| 109 cpu2DmaSpi.Init.CRCPolynomial = 7; | |
| 110 | |
| 111 HAL_SPI_Init(&cpu2DmaSpi); | |
| 112 } | |
| 113 | |
| 870 | 114 |
| 115 void MX_GPIO_Backlight_max_static_only_Init(void) | |
| 116 { | |
| 117 GPIO_InitTypeDef GPIO_InitStruct; | |
| 118 TIM_BACKLIGHT_GPIO_ENABLE(); | |
| 119 | |
| 120 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 121 GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; /* should be normally high */ | |
| 122 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 123 | |
| 124 GPIO_InitStruct.Pin = TIM_BACKLIGHT_PIN; | |
| 125 HAL_GPIO_Init(TIM_BACKLIGHT_GPIO_PORT, &GPIO_InitStruct); | |
| 126 | |
| 127 HAL_GPIO_WritePin(TIM_BACKLIGHT_GPIO_PORT,TIM_BACKLIGHT_PIN,GPIO_PIN_SET); | |
| 128 } | |
| 129 | |
| 130 | |
| 131 void MX_GPIO_One_Button_only_Init(void) | |
| 132 { | |
| 133 GPIO_InitTypeDef GPIO_InitStruct; | |
| 134 BUTTON_NEXT_GPIO_ENABLE(); | |
| 135 | |
| 136 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 137 GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; /* should be normally high */ | |
| 138 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 139 | |
| 140 GPIO_InitStruct.Pin = BUTTON_NEXT_PIN; | |
| 141 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStruct); | |
| 142 } | |
| 143 | |
| 144 | |
| 145 GPIO_PinState MX_GPIO_Read_The_One_Button(void) | |
| 146 { | |
| 147 return HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN); | |
| 148 } | |
| 149 | |
| 38 | 150 void MX_GPIO_Init(void) |
| 151 { | |
| 152 GPIO_InitTypeDef GPIO_InitStruct; | |
| 153 | |
| 154 DISPLAY_CSB_GPIO_ENABLE(); | |
| 155 DISPLAY_RESETB_GPIO_ENABLE(); | |
| 156 EXTFLASH_CSB_GPIO_ENABLE(); | |
| 157 SMALLCPU_CSB_GPIO_ENABLE(); | |
| 158 OSCILLOSCOPE_GPIO_ENABLE(); | |
| 159 OSCILLOSCOPE2_GPIO_ENABLE(); | |
| 1046 | 160 if(isNewDisplay()) |
| 161 { | |
| 162 BLE_UBLOX_DSR_GPIO_ENABLE(); | |
| 163 } | |
| 38 | 164 |
| 165 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 166 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 167 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 168 | |
| 169 GPIO_InitStruct.Pin = DISPLAY_CSB_PIN; | |
| 170 HAL_GPIO_Init(DISPLAY_CSB_GPIO_PORT, &GPIO_InitStruct); | |
| 171 | |
| 172 GPIO_InitStruct.Pin = DISPLAY_RESETB_PIN; | |
| 173 HAL_GPIO_Init(DISPLAY_RESETB_GPIO_PORT, &GPIO_InitStruct); | |
| 174 | |
| 175 GPIO_InitStruct.Pin = EXTFLASH_CSB_PIN; | |
| 176 HAL_GPIO_Init(EXTFLASH_CSB_GPIO_PORT, &GPIO_InitStruct); | |
| 177 | |
| 178 GPIO_InitStruct.Pin = OSCILLOSCOPE_PIN; | |
| 179 HAL_GPIO_Init(OSCILLOSCOPE_GPIO_PORT, &GPIO_InitStruct); | |
| 180 | |
| 181 GPIO_InitStruct.Pin = OSCILLOSCOPE2_PIN; | |
| 182 HAL_GPIO_Init(OSCILLOSCOPE2_GPIO_PORT, &GPIO_InitStruct); | |
| 183 | |
| 184 #ifdef DISPLAY_BACKLIGHT_PIN | |
| 185 DISPLAY_BACKLIGHT_GPIO_ENABLE(); | |
| 186 GPIO_InitStruct.Pin = DISPLAY_BACKLIGHT_PIN; | |
| 187 HAL_GPIO_Init(DISPLAY_BACKLIGHT_GPIO_PORT, &GPIO_InitStruct); | |
| 188 HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_PORT,DISPLAY_BACKLIGHT_PIN,GPIO_PIN_SET); | |
| 189 #endif | |
| 190 | |
| 191 #ifdef SMALLCPU_CSB_PIN | |
| 192 SMALLCPU_CSB_GPIO_ENABLE(); | |
| 193 GPIO_InitStruct.Pin = SMALLCPU_CSB_PIN; | |
| 194 HAL_GPIO_Init(SMALLCPU_CSB_GPIO_PORT, &GPIO_InitStruct); | |
| 195 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); | |
| 196 #endif | |
| 197 | |
| 198 #ifdef SMALLCPU_BOOT0_PIN | |
| 199 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 200 SMALLCPU_BOOT0_GPIO_ENABLE(); | |
| 201 GPIO_InitStruct.Pin = SMALLCPU_BOOT0_PIN; | |
| 202 HAL_GPIO_Init(SMALLCPU_BOOT0_GPIO_PORT, &GPIO_InitStruct); | |
| 203 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
| 204 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 205 #endif | |
| 206 | |
| 207 #ifdef IR_HUD_ENABLE_PIN | |
| 208 IR_HUD_ENABLE_GPIO_ENABLE(); | |
| 209 GPIO_InitStruct.Pin = IR_HUD_ENABLE_PIN; | |
| 210 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 211 HAL_GPIO_Init(IR_HUD_ENABLE_GPIO_PORT, &GPIO_InitStruct); | |
| 212 HAL_GPIO_WritePin(IR_HUD_ENABLE_GPIO_PORT,IR_HUD_ENABLE_PIN,GPIO_PIN_SET); | |
| 213 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 214 #endif | |
| 215 | |
| 216 #ifdef BLE_NENABLE_PIN | |
| 217 BLE_NENABLE_GPIO_ENABLE(); | |
| 218 MX_Bluetooth_PowerOff(); | |
| 219 #endif | |
| 220 | |
| 221 #ifdef TESTPIN | |
| 222 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 223 TEST_GPIO_ENABLE(); | |
| 224 GPIO_InitStruct.Pin = TEST_PIN; | |
| 225 HAL_GPIO_Init(TEST_GPIO_PORT, &GPIO_InitStruct); | |
| 226 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_SET); | |
| 227 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 228 #endif | |
| 229 } | |
| 230 | |
| 231 | |
| 232 void MX_TestPin_High(void) | |
| 233 { | |
| 234 #ifdef TESTPIN | |
| 235 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_SET); | |
| 236 #endif | |
| 237 } | |
| 238 | |
| 239 | |
| 240 void MX_TestPin_Low(void) | |
| 241 { | |
| 242 #ifdef TESTPIN | |
| 243 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_RESET); | |
| 244 #endif | |
| 245 } | |
| 246 | |
| 247 void MX_Bluetooth_PowerOn(void) | |
| 248 { | |
| 249 GPIO_InitTypeDef GPIO_InitStruct; | |
| 250 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 251 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 252 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 253 GPIO_InitStruct.Pin = BLE_NENABLE_PIN; | |
| 254 HAL_GPIO_Init(BLE_NENABLE_GPIO_PORT, &GPIO_InitStruct); | |
| 255 HAL_GPIO_WritePin(BLE_NENABLE_GPIO_PORT,BLE_NENABLE_PIN,GPIO_PIN_RESET); | |
| 879 | 256 |
| 1046 | 257 if(isNewDisplay()) |
| 258 { | |
| 259 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 260 GPIO_InitStruct.Pull = GPIO_PULLDOWN; | |
| 261 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 262 GPIO_InitStruct.Pin = BLE_UBLOX_DSR_PIN; | |
| 263 HAL_GPIO_Init(BLE_UBLOX_DSR_GPIO_PORT, &GPIO_InitStruct); | |
| 264 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); | |
| 265 } | |
| 38 | 266 } |
| 267 | |
| 268 | |
| 269 void MX_Bluetooth_PowerOff(void) | |
| 270 { | |
| 271 GPIO_InitTypeDef GPIO_InitStruct; | |
| 272 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 273 GPIO_InitStruct.Pin = BLE_NENABLE_PIN; | |
| 274 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 275 HAL_GPIO_Init(BLE_NENABLE_GPIO_PORT, &GPIO_InitStruct); | |
| 1046 | 276 |
| 277 if(isNewDisplay()) | |
| 278 { | |
| 279 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); | |
| 280 } | |
| 38 | 281 } |
| 282 | |
| 283 | |
| 284 void MX_SmallCPU_Reset_To_Boot(void) | |
| 285 { | |
| 286 #ifdef SMALLCPU_NRESET_PIN | |
| 287 GPIO_InitTypeDef GPIO_InitStruct; | |
| 288 | |
| 289 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 290 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 291 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 292 | |
| 293 SMALLCPU_NRESET_GPIO_ENABLE(); | |
| 294 GPIO_InitStruct.Pin = SMALLCPU_NRESET_PIN; | |
| 295 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 296 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_RESET); | |
| 297 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_SET); | |
| 298 HAL_Delay(2); | |
| 299 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 300 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 301 HAL_Delay(100); | |
| 302 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
| 303 #endif | |
| 304 } | |
| 305 | |
| 870 | 306 |
| 307 void MX_SmallCPU_NO_Reset_Helper(void) | |
| 308 { | |
| 309 #ifdef SMALLCPU_NRESET_PIN | |
| 310 GPIO_InitTypeDef GPIO_InitStruct; | |
| 311 | |
| 312 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 313 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 314 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 315 | |
| 316 SMALLCPU_NRESET_GPIO_ENABLE(); | |
| 317 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 318 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_SET); | |
| 319 // HAL_Delay(100); | |
| 320 // GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 321 // HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 322 #endif | |
| 323 } | |
| 324 | |
| 325 | |
| 38 | 326 void MX_SmallCPU_Reset_To_Standard(void) |
| 327 { | |
| 328 #ifdef SMALLCPU_NRESET_PIN | |
| 329 GPIO_InitTypeDef GPIO_InitStruct; | |
| 330 | |
| 331 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 332 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 333 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 334 | |
| 335 SMALLCPU_NRESET_GPIO_ENABLE(); | |
| 336 GPIO_InitStruct.Pin = SMALLCPU_NRESET_PIN; | |
| 337 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 338 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_RESET); | |
| 339 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
| 340 HAL_Delay(2); | |
| 341 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 342 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 343 #endif | |
| 344 } | |
| 345 | |
| 870 | 346 |
| 347 uint8_t MX_UART_ButtonAdjust(uint8_t *array) | |
| 348 { | |
| 349 #ifdef USART_PIEZO | |
| 350 uint8_t answer[4]; | |
| 351 HAL_UART_Transmit(&UartPiezoTxHandle,array,4,1000); | |
| 352 HAL_UART_Receive(&UartPiezoTxHandle,answer,4,2000); | |
| 353 if( (answer[0] == array[0]) | |
| 354 &&(answer[1] == array[1]) | |
| 355 &&(answer[2] == array[2]) | |
| 356 &&(answer[3] == array[3])) | |
| 357 return 1; | |
| 358 #endif | |
| 359 return 0; | |
| 360 } | |
| 361 | |
| 362 | |
| 38 | 363 void MX_UART_Init(void) |
| 364 { | |
| 365 /*##-1- Configure the UART peripheral ######################################*/ | |
| 366 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */ | |
| 367 /* UART1 configured as follow: | |
| 368 - Word Length = 8 Bits | |
| 369 - Stop Bit = One Stop bit | |
| 370 - Parity = None | |
| 371 - BaudRate = 9600 baud | |
| 372 - Hardware flow control disabled (RTS and CTS signals) */ | |
| 373 | |
| 374 #ifdef USARTx_CTS_PIN | |
| 375 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; | |
| 376 #else | |
| 377 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 378 #endif | |
| 379 UartHandle.Instance = USARTx; | |
| 380 UartHandle.Init.BaudRate = 115200; | |
| 381 UartHandle.Init.WordLength = UART_WORDLENGTH_8B; | |
| 382 UartHandle.Init.StopBits = UART_STOPBITS_1; | |
| 383 UartHandle.Init.Parity = UART_PARITY_NONE; | |
| 384 UartHandle.Init.Mode = UART_MODE_TX_RX; | |
| 1046 | 385 /* HAL_UART_Init(&UartHandle); moved final init step into BT config function to avoid problems while module power is off */ |
| 38 | 386 |
| 387 #ifdef USART_PIEZO | |
| 388 UartPiezoTxHandle.Instance = USART_PIEZO; | |
| 389 UartPiezoTxHandle.Init.BaudRate = 1200; | |
| 390 UartPiezoTxHandle.Init.WordLength = UART_WORDLENGTH_8B; | |
| 391 UartPiezoTxHandle.Init.StopBits = UART_STOPBITS_1; | |
| 392 UartPiezoTxHandle.Init.Parity = UART_PARITY_NONE; | |
| 393 UartPiezoTxHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 394 UartPiezoTxHandle.Init.Mode = UART_MODE_TX_RX; | |
| 395 | |
| 396 HAL_UART_Init(&UartPiezoTxHandle); | |
| 397 #endif | |
| 398 | |
| 399 #ifdef USART_IR_HUD | |
| 400 UartIR_HUD_Handle.Instance = USART_IR_HUD; | |
| 401 UartIR_HUD_Handle.Init.BaudRate = 2400; | |
| 402 UartIR_HUD_Handle.Init.WordLength = UART_WORDLENGTH_8B; | |
| 403 UartIR_HUD_Handle.Init.StopBits = UART_STOPBITS_1; | |
| 404 UartIR_HUD_Handle.Init.Parity = UART_PARITY_NONE; | |
| 405 UartIR_HUD_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 406 UartIR_HUD_Handle.Init.Mode = UART_MODE_TX_RX; | |
| 407 | |
| 408 HAL_UART_Init(&UartIR_HUD_Handle); | |
| 409 #endif | |
| 1036 | 410 |
| 411 #ifdef ENABLE_USART_RADIO | |
| 412 UartRadio_Handle.Instance = USART_RADIO; | |
| 413 UartRadio_Handle.Init.BaudRate = 9600; | |
| 414 UartRadio_Handle.Init.WordLength = UART_WORDLENGTH_8B; | |
| 415 UartRadio_Handle.Init.StopBits = UART_STOPBITS_1; | |
| 416 UartRadio_Handle.Init.Parity = UART_PARITY_NONE; | |
| 417 UartRadio_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 418 UartRadio_Handle.Init.Mode = UART_MODE_RX; | |
| 419 | |
| 420 HAL_UART_Init(&UartRadio_Handle); | |
| 421 #endif | |
| 422 | |
| 38 | 423 } |
| 424 | |
| 1036 | 425 #ifdef ENABLE_PULSE_SENSOR_BT |
| 1032 | 426 void MX_UART_BT_Init_DMA() |
| 427 { | |
| 428 | |
| 429 __DMA2_CLK_ENABLE(); | |
| 430 __HAL_RCC_DMA2_CLK_ENABLE(); | |
| 431 | |
| 432 hdma_uart_BT_rx.Instance = DMA2_Stream2; | |
| 433 hdma_uart_BT_rx.Init.Channel = DMA_CHANNEL_4; | |
| 434 hdma_uart_BT_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; | |
| 435 hdma_uart_BT_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
| 436 hdma_uart_BT_rx.Init.MemInc = DMA_MINC_ENABLE; | |
| 437 hdma_uart_BT_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 438 hdma_uart_BT_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 439 hdma_uart_BT_rx.Init.Mode = DMA_NORMAL; | |
| 440 hdma_uart_BT_rx.Init.Priority = DMA_PRIORITY_LOW; | |
| 441 hdma_uart_BT_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
| 442 HAL_DMA_Init(&hdma_uart_BT_rx); | |
| 443 | |
| 444 __HAL_LINKDMA(&UartHandle, hdmarx, hdma_uart_BT_rx); | |
| 445 | |
| 446 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0); | |
| 447 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); | |
| 448 } | |
| 1036 | 449 #endif |
| 450 | |
| 451 #ifdef ENABLE_USART_RADIO | |
| 452 void MX_UART_RADIO_Init_DMA() | |
| 453 { | |
| 454 | |
| 455 __DMA2_CLK_ENABLE(); | |
| 456 __HAL_RCC_DMA2_CLK_ENABLE(); | |
| 457 | |
| 458 hdma_uart_radio_rx.Instance = DMA2_Stream1; | |
| 459 hdma_uart_radio_rx.Init.Channel = DMA_CHANNEL_4; | |
| 460 hdma_uart_radio_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; | |
| 461 hdma_uart_radio_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
| 462 hdma_uart_radio_rx.Init.MemInc = DMA_MINC_ENABLE; | |
| 463 hdma_uart_radio_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 464 hdma_uart_radio_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 465 hdma_uart_radio_rx.Init.Mode = DMA_NORMAL; | |
| 466 hdma_uart_radio_rx.Init.Priority = DMA_PRIORITY_LOW; | |
| 467 hdma_uart_radio_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
| 468 HAL_DMA_Init(&hdma_uart_radio_rx); | |
| 469 | |
| 470 __HAL_LINKDMA(&UartRadio_Handle, hdmarx, hdma_uart_radio_rx); | |
| 471 | |
| 472 HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0); | |
| 473 HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn); | |
| 474 } | |
| 475 #endif | |
| 1032 | 476 |
| 477 | |
| 478 uint8_t UART_getChar() | |
| 479 { | |
| 480 uint8_t retChar = 0; | |
| 481 | |
| 482 if((rxBufRead != rxBufWrite) && (rxBufferUart[rxBufRead] != 0)) | |
| 483 { | |
| 484 retChar = rxBufferUart[rxBufRead]; | |
| 485 rxBufferUart[rxBufRead++] = 0; | |
| 486 if(rxBufRead == CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 487 { | |
| 488 rxBufRead = 0; | |
| 489 } | |
| 490 } | |
| 491 return retChar; | |
| 492 } | |
| 1036 | 493 #ifdef ENABLE_PULSE_SENSOR_BT |
| 1032 | 494 void UART_StartDMARx() |
| 495 { | |
| 496 HAL_UART_Receive_DMA (&UartHandle, &rxBufferUart[rxBufWrite], CHUNK_SIZE); | |
| 497 rxBufWrite += CHUNK_SIZE; | |
| 498 if(rxBufWrite >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 499 { | |
| 500 rxBufWrite = 0; | |
| 501 } | |
| 502 } | |
| 503 void DMA2_Stream2_IRQHandler(void) | |
| 504 { | |
| 505 HAL_DMA_IRQHandler(&hdma_uart_BT_rx); | |
| 506 } | |
| 1036 | 507 #endif |
| 508 | |
| 509 #ifdef ENABLE_USART_RADIO | |
| 510 void UART_StartDMARxRadio() | |
| 511 { | |
| 512 HAL_UART_Receive_DMA (&UartRadio_Handle, &rxBufferUart[rxBufWrite], CHUNK_SIZE); | |
| 513 rxBufWrite += CHUNK_SIZE; | |
| 514 if(rxBufWrite >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 515 { | |
| 516 rxBufWrite = 0; | |
| 517 } | |
| 518 } | |
| 519 | |
| 520 void DMA2_Stream2_IRQHandler(void) | |
| 521 { | |
| 522 HAL_DMA_IRQHandler(&hdma_uart_radio_rx); | |
| 523 } | |
| 524 #endif | |
| 1032 | 525 |
| 38 | 526 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) |
| 527 { | |
| 528 if(huart == &UartHandle) | |
| 529 UartReady = SET; | |
| 530 } | |
| 531 | |
|
321
37ee61f93124
Moved indication variable for received HUD data to tCCR file.
ideenmodellierer
parents:
300
diff
changeset
|
532 |
| 38 | 533 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
| 534 { | |
| 535 if(huart == &UartHandle) | |
| 1032 | 536 { |
| 537 #ifdef ENABLE_PULSE_SENSOR_BT | |
| 538 if(cv_heartbeat_getState() != SENSOR_HB_OFFLINE) | |
| 539 { | |
| 540 UART_StartDMARx(); | |
| 541 } | |
| 542 else | |
| 543 { | |
| 544 UartReady = SET; | |
| 545 } | |
| 546 #else | |
| 547 UartReady = SET; | |
| 548 #endif | |
| 549 } | |
| 38 | 550 else |
| 551 if(huart == &UartIR_HUD_Handle) | |
| 552 { | |
| 870 | 553 #ifndef BOOTLOADER_STANDALONE |
|
321
37ee61f93124
Moved indication variable for received HUD data to tCCR file.
ideenmodellierer
parents:
300
diff
changeset
|
554 tCCR_SetRXIndication(); |
| 870 | 555 #endif |
| 556 UartReadyHUD = SET; | |
| 38 | 557 } |
| 558 } | |
| 559 | |
| 560 void MX_tell_reset_logik_alles_ok(void) | |
| 561 { | |
| 562 #ifdef RESET_LOGIC_ALLES_OK_PIN | |
| 563 GPIO_InitTypeDef GPIO_InitStruct; | |
| 564 | |
| 565 RESET_LOGIC_ALLES_OK_GPIO_ENABLE(); | |
| 566 | |
| 567 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 568 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 569 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 570 GPIO_InitStruct.Pin = RESET_LOGIC_ALLES_OK_PIN; | |
| 571 HAL_GPIO_Init(RESET_LOGIC_ALLES_OK_GPIO_PORT, &GPIO_InitStruct); | |
| 572 | |
| 573 HAL_GPIO_WritePin(RESET_LOGIC_ALLES_OK_GPIO_PORT,RESET_LOGIC_ALLES_OK_PIN,GPIO_PIN_RESET); | |
| 574 HAL_Delay(1); | |
| 575 HAL_GPIO_WritePin(RESET_LOGIC_ALLES_OK_GPIO_PORT,RESET_LOGIC_ALLES_OK_PIN,GPIO_PIN_SET); | |
| 576 | |
| 577 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 578 HAL_GPIO_Init(RESET_LOGIC_ALLES_OK_GPIO_PORT, &GPIO_InitStruct); | |
| 579 #endif | |
| 580 } | |
|
885
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
581 void SetDisplayVersion(uint8_t version) |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
582 { |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
583 if(version < 2) |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
584 { |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
585 hardwareDisplay = version; |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
586 } |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
587 } |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
588 uint8_t isNewDisplay() |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
589 { |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
590 uint8_t ret = 0; |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
591 if(hardwareDisplay == DISPLAY_VERSION_NEW) |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
592 { |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
593 ret = 1; |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
594 } |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
595 return ret; |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
596 } |
| 38 | 597 |
| 598 #ifndef BOOTLOADER_STANDALONE | |
| 599 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) | |
| 600 { | |
| 601 if(huart == &UartIR_HUD_Handle) | |
| 602 tCCR_restart(); | |
| 603 } | |
| 604 #endif |
