Mercurial > public > ostc4
annotate Discovery/Src/ostc.c @ 1036:5865f0aeb438 Puls_Integration
Radio data integration:
Added functionality for displaying radio data as debug message. The USART3 has been configurated for receiption and a function for the visualization of the data has been added to the demo unit (draft implementation). For activation the radio as well as the logger functionality needs to be activated via compile switch. Note that at the moment bluetooth and radio DMA may not be operated in parallel.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 10 Aug 2025 15:28:59 +0200 |
| parents | 33b91584d827 |
| children | 1d7c7a36df15 |
| 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(); | |
| 879 | 160 BLE_UBLOX_DSR_GPIO_ENABLE(); |
| 38 | 161 |
| 162 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 163 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 164 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 165 | |
| 166 GPIO_InitStruct.Pin = DISPLAY_CSB_PIN; | |
| 167 HAL_GPIO_Init(DISPLAY_CSB_GPIO_PORT, &GPIO_InitStruct); | |
| 168 | |
| 169 GPIO_InitStruct.Pin = DISPLAY_RESETB_PIN; | |
| 170 HAL_GPIO_Init(DISPLAY_RESETB_GPIO_PORT, &GPIO_InitStruct); | |
| 171 | |
| 172 GPIO_InitStruct.Pin = EXTFLASH_CSB_PIN; | |
| 173 HAL_GPIO_Init(EXTFLASH_CSB_GPIO_PORT, &GPIO_InitStruct); | |
| 174 | |
| 175 GPIO_InitStruct.Pin = OSCILLOSCOPE_PIN; | |
| 176 HAL_GPIO_Init(OSCILLOSCOPE_GPIO_PORT, &GPIO_InitStruct); | |
| 177 | |
| 178 GPIO_InitStruct.Pin = OSCILLOSCOPE2_PIN; | |
| 179 HAL_GPIO_Init(OSCILLOSCOPE2_GPIO_PORT, &GPIO_InitStruct); | |
| 180 | |
| 181 #ifdef DISPLAY_BACKLIGHT_PIN | |
| 182 DISPLAY_BACKLIGHT_GPIO_ENABLE(); | |
| 183 GPIO_InitStruct.Pin = DISPLAY_BACKLIGHT_PIN; | |
| 184 HAL_GPIO_Init(DISPLAY_BACKLIGHT_GPIO_PORT, &GPIO_InitStruct); | |
| 185 HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_PORT,DISPLAY_BACKLIGHT_PIN,GPIO_PIN_SET); | |
| 186 #endif | |
| 187 | |
| 188 #ifdef SMALLCPU_CSB_PIN | |
| 189 SMALLCPU_CSB_GPIO_ENABLE(); | |
| 190 GPIO_InitStruct.Pin = SMALLCPU_CSB_PIN; | |
| 191 HAL_GPIO_Init(SMALLCPU_CSB_GPIO_PORT, &GPIO_InitStruct); | |
| 192 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); | |
| 193 #endif | |
| 194 | |
| 195 #ifdef SMALLCPU_BOOT0_PIN | |
| 196 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 197 SMALLCPU_BOOT0_GPIO_ENABLE(); | |
| 198 GPIO_InitStruct.Pin = SMALLCPU_BOOT0_PIN; | |
| 199 HAL_GPIO_Init(SMALLCPU_BOOT0_GPIO_PORT, &GPIO_InitStruct); | |
| 200 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
| 201 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 202 #endif | |
| 203 | |
| 204 #ifdef IR_HUD_ENABLE_PIN | |
| 205 IR_HUD_ENABLE_GPIO_ENABLE(); | |
| 206 GPIO_InitStruct.Pin = IR_HUD_ENABLE_PIN; | |
| 207 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 208 HAL_GPIO_Init(IR_HUD_ENABLE_GPIO_PORT, &GPIO_InitStruct); | |
| 209 HAL_GPIO_WritePin(IR_HUD_ENABLE_GPIO_PORT,IR_HUD_ENABLE_PIN,GPIO_PIN_SET); | |
| 210 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 211 #endif | |
| 212 | |
| 213 #ifdef BLE_NENABLE_PIN | |
| 214 BLE_NENABLE_GPIO_ENABLE(); | |
| 215 MX_Bluetooth_PowerOff(); | |
| 216 #endif | |
| 217 | |
| 218 #ifdef TESTPIN | |
| 219 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 220 TEST_GPIO_ENABLE(); | |
| 221 GPIO_InitStruct.Pin = TEST_PIN; | |
| 222 HAL_GPIO_Init(TEST_GPIO_PORT, &GPIO_InitStruct); | |
| 223 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_SET); | |
| 224 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
| 225 #endif | |
| 226 } | |
| 227 | |
| 228 | |
| 229 void MX_TestPin_High(void) | |
| 230 { | |
| 231 #ifdef TESTPIN | |
| 232 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_SET); | |
| 233 #endif | |
| 234 } | |
| 235 | |
| 236 | |
| 237 void MX_TestPin_Low(void) | |
| 238 { | |
| 239 #ifdef TESTPIN | |
| 240 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_RESET); | |
| 241 #endif | |
| 242 } | |
| 243 | |
| 244 void MX_Bluetooth_PowerOn(void) | |
| 245 { | |
| 246 GPIO_InitTypeDef GPIO_InitStruct; | |
| 247 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 248 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 249 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 250 GPIO_InitStruct.Pin = BLE_NENABLE_PIN; | |
| 251 HAL_GPIO_Init(BLE_NENABLE_GPIO_PORT, &GPIO_InitStruct); | |
| 252 HAL_GPIO_WritePin(BLE_NENABLE_GPIO_PORT,BLE_NENABLE_PIN,GPIO_PIN_RESET); | |
| 879 | 253 |
| 254 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 255 GPIO_InitStruct.Pull = GPIO_PULLDOWN; | |
| 256 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 257 GPIO_InitStruct.Pin = BLE_UBLOX_DSR_PIN; | |
| 258 HAL_GPIO_Init(BLE_UBLOX_DSR_GPIO_PORT, &GPIO_InitStruct); | |
| 259 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); | |
| 38 | 260 } |
| 261 | |
| 262 | |
| 263 void MX_Bluetooth_PowerOff(void) | |
| 264 { | |
| 265 GPIO_InitTypeDef GPIO_InitStruct; | |
| 266 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 267 GPIO_InitStruct.Pin = BLE_NENABLE_PIN; | |
| 268 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 269 HAL_GPIO_Init(BLE_NENABLE_GPIO_PORT, &GPIO_InitStruct); | |
| 879 | 270 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); |
| 38 | 271 } |
| 272 | |
| 273 | |
| 274 void MX_SmallCPU_Reset_To_Boot(void) | |
| 275 { | |
| 276 #ifdef SMALLCPU_NRESET_PIN | |
| 277 GPIO_InitTypeDef GPIO_InitStruct; | |
| 278 | |
| 279 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 280 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 281 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 282 | |
| 283 SMALLCPU_NRESET_GPIO_ENABLE(); | |
| 284 GPIO_InitStruct.Pin = SMALLCPU_NRESET_PIN; | |
| 285 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 286 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_RESET); | |
| 287 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_SET); | |
| 288 HAL_Delay(2); | |
| 289 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 290 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 291 HAL_Delay(100); | |
| 292 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
| 293 #endif | |
| 294 } | |
| 295 | |
| 870 | 296 |
| 297 void MX_SmallCPU_NO_Reset_Helper(void) | |
| 298 { | |
| 299 #ifdef SMALLCPU_NRESET_PIN | |
| 300 GPIO_InitTypeDef GPIO_InitStruct; | |
| 301 | |
| 302 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 303 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 304 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 305 | |
| 306 SMALLCPU_NRESET_GPIO_ENABLE(); | |
| 307 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 308 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_SET); | |
| 309 // HAL_Delay(100); | |
| 310 // GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 311 // HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 312 #endif | |
| 313 } | |
| 314 | |
| 315 | |
| 38 | 316 void MX_SmallCPU_Reset_To_Standard(void) |
| 317 { | |
| 318 #ifdef SMALLCPU_NRESET_PIN | |
| 319 GPIO_InitTypeDef GPIO_InitStruct; | |
| 320 | |
| 321 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 322 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 323 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 324 | |
| 325 SMALLCPU_NRESET_GPIO_ENABLE(); | |
| 326 GPIO_InitStruct.Pin = SMALLCPU_NRESET_PIN; | |
| 327 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 328 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_RESET); | |
| 329 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
| 330 HAL_Delay(2); | |
| 331 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 332 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
| 333 #endif | |
| 334 } | |
| 335 | |
| 870 | 336 |
| 337 uint8_t MX_UART_ButtonAdjust(uint8_t *array) | |
| 338 { | |
| 339 #ifdef USART_PIEZO | |
| 340 uint8_t answer[4]; | |
| 341 HAL_UART_Transmit(&UartPiezoTxHandle,array,4,1000); | |
| 342 HAL_UART_Receive(&UartPiezoTxHandle,answer,4,2000); | |
| 343 if( (answer[0] == array[0]) | |
| 344 &&(answer[1] == array[1]) | |
| 345 &&(answer[2] == array[2]) | |
| 346 &&(answer[3] == array[3])) | |
| 347 return 1; | |
| 348 #endif | |
| 349 return 0; | |
| 350 } | |
| 351 | |
| 352 | |
| 38 | 353 void MX_UART_Init(void) |
| 354 { | |
| 355 /*##-1- Configure the UART peripheral ######################################*/ | |
| 356 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */ | |
| 357 /* UART1 configured as follow: | |
| 358 - Word Length = 8 Bits | |
| 359 - Stop Bit = One Stop bit | |
| 360 - Parity = None | |
| 361 - BaudRate = 9600 baud | |
| 362 - Hardware flow control disabled (RTS and CTS signals) */ | |
| 363 | |
| 364 #ifdef USARTx_CTS_PIN | |
| 365 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; | |
| 366 #else | |
| 367 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 368 #endif | |
| 369 UartHandle.Instance = USARTx; | |
| 370 UartHandle.Init.BaudRate = 115200; | |
| 371 UartHandle.Init.WordLength = UART_WORDLENGTH_8B; | |
| 372 UartHandle.Init.StopBits = UART_STOPBITS_1; | |
| 373 UartHandle.Init.Parity = UART_PARITY_NONE; | |
| 374 UartHandle.Init.Mode = UART_MODE_TX_RX; | |
| 375 HAL_UART_Init(&UartHandle); | |
| 376 | |
| 377 #ifdef USART_PIEZO | |
| 378 UartPiezoTxHandle.Instance = USART_PIEZO; | |
| 379 UartPiezoTxHandle.Init.BaudRate = 1200; | |
| 380 UartPiezoTxHandle.Init.WordLength = UART_WORDLENGTH_8B; | |
| 381 UartPiezoTxHandle.Init.StopBits = UART_STOPBITS_1; | |
| 382 UartPiezoTxHandle.Init.Parity = UART_PARITY_NONE; | |
| 383 UartPiezoTxHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 384 UartPiezoTxHandle.Init.Mode = UART_MODE_TX_RX; | |
| 385 | |
| 386 HAL_UART_Init(&UartPiezoTxHandle); | |
| 387 #endif | |
| 388 | |
| 389 #ifdef USART_IR_HUD | |
| 390 UartIR_HUD_Handle.Instance = USART_IR_HUD; | |
| 391 UartIR_HUD_Handle.Init.BaudRate = 2400; | |
| 392 UartIR_HUD_Handle.Init.WordLength = UART_WORDLENGTH_8B; | |
| 393 UartIR_HUD_Handle.Init.StopBits = UART_STOPBITS_1; | |
| 394 UartIR_HUD_Handle.Init.Parity = UART_PARITY_NONE; | |
| 395 UartIR_HUD_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 396 UartIR_HUD_Handle.Init.Mode = UART_MODE_TX_RX; | |
| 397 | |
| 398 HAL_UART_Init(&UartIR_HUD_Handle); | |
| 399 #endif | |
| 1036 | 400 |
| 401 #ifdef ENABLE_USART_RADIO | |
| 402 UartRadio_Handle.Instance = USART_RADIO; | |
| 403 UartRadio_Handle.Init.BaudRate = 9600; | |
| 404 UartRadio_Handle.Init.WordLength = UART_WORDLENGTH_8B; | |
| 405 UartRadio_Handle.Init.StopBits = UART_STOPBITS_1; | |
| 406 UartRadio_Handle.Init.Parity = UART_PARITY_NONE; | |
| 407 UartRadio_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 408 UartRadio_Handle.Init.Mode = UART_MODE_RX; | |
| 409 | |
| 410 HAL_UART_Init(&UartRadio_Handle); | |
| 411 #endif | |
| 412 | |
| 38 | 413 } |
| 414 | |
| 1036 | 415 #ifdef ENABLE_PULSE_SENSOR_BT |
| 1032 | 416 void MX_UART_BT_Init_DMA() |
| 417 { | |
| 418 | |
| 419 __DMA2_CLK_ENABLE(); | |
| 420 __HAL_RCC_DMA2_CLK_ENABLE(); | |
| 421 | |
| 422 hdma_uart_BT_rx.Instance = DMA2_Stream2; | |
| 423 hdma_uart_BT_rx.Init.Channel = DMA_CHANNEL_4; | |
| 424 hdma_uart_BT_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; | |
| 425 hdma_uart_BT_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
| 426 hdma_uart_BT_rx.Init.MemInc = DMA_MINC_ENABLE; | |
| 427 hdma_uart_BT_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 428 hdma_uart_BT_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 429 hdma_uart_BT_rx.Init.Mode = DMA_NORMAL; | |
| 430 hdma_uart_BT_rx.Init.Priority = DMA_PRIORITY_LOW; | |
| 431 hdma_uart_BT_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
| 432 HAL_DMA_Init(&hdma_uart_BT_rx); | |
| 433 | |
| 434 __HAL_LINKDMA(&UartHandle, hdmarx, hdma_uart_BT_rx); | |
| 435 | |
| 436 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0); | |
| 437 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); | |
| 438 } | |
| 1036 | 439 #endif |
| 440 | |
| 441 #ifdef ENABLE_USART_RADIO | |
| 442 void MX_UART_RADIO_Init_DMA() | |
| 443 { | |
| 444 | |
| 445 __DMA2_CLK_ENABLE(); | |
| 446 __HAL_RCC_DMA2_CLK_ENABLE(); | |
| 447 | |
| 448 hdma_uart_radio_rx.Instance = DMA2_Stream1; | |
| 449 hdma_uart_radio_rx.Init.Channel = DMA_CHANNEL_4; | |
| 450 hdma_uart_radio_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; | |
| 451 hdma_uart_radio_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
| 452 hdma_uart_radio_rx.Init.MemInc = DMA_MINC_ENABLE; | |
| 453 hdma_uart_radio_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 454 hdma_uart_radio_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 455 hdma_uart_radio_rx.Init.Mode = DMA_NORMAL; | |
| 456 hdma_uart_radio_rx.Init.Priority = DMA_PRIORITY_LOW; | |
| 457 hdma_uart_radio_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
| 458 HAL_DMA_Init(&hdma_uart_radio_rx); | |
| 459 | |
| 460 __HAL_LINKDMA(&UartRadio_Handle, hdmarx, hdma_uart_radio_rx); | |
| 461 | |
| 462 HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0); | |
| 463 HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn); | |
| 464 } | |
| 465 #endif | |
| 1032 | 466 |
| 467 | |
| 468 uint8_t UART_getChar() | |
| 469 { | |
| 470 uint8_t retChar = 0; | |
| 471 | |
| 472 if((rxBufRead != rxBufWrite) && (rxBufferUart[rxBufRead] != 0)) | |
| 473 { | |
| 474 retChar = rxBufferUart[rxBufRead]; | |
| 475 rxBufferUart[rxBufRead++] = 0; | |
| 476 if(rxBufRead == CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 477 { | |
| 478 rxBufRead = 0; | |
| 479 } | |
| 480 } | |
| 481 return retChar; | |
| 482 } | |
| 1036 | 483 #ifdef ENABLE_PULSE_SENSOR_BT |
| 1032 | 484 void UART_StartDMARx() |
| 485 { | |
| 486 HAL_UART_Receive_DMA (&UartHandle, &rxBufferUart[rxBufWrite], CHUNK_SIZE); | |
| 487 rxBufWrite += CHUNK_SIZE; | |
| 488 if(rxBufWrite >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 489 { | |
| 490 rxBufWrite = 0; | |
| 491 } | |
| 492 } | |
| 493 void DMA2_Stream2_IRQHandler(void) | |
| 494 { | |
| 495 HAL_DMA_IRQHandler(&hdma_uart_BT_rx); | |
| 496 } | |
| 1036 | 497 #endif |
| 498 | |
| 499 #ifdef ENABLE_USART_RADIO | |
| 500 void UART_StartDMARxRadio() | |
| 501 { | |
| 502 HAL_UART_Receive_DMA (&UartRadio_Handle, &rxBufferUart[rxBufWrite], CHUNK_SIZE); | |
| 503 rxBufWrite += CHUNK_SIZE; | |
| 504 if(rxBufWrite >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 505 { | |
| 506 rxBufWrite = 0; | |
| 507 } | |
| 508 } | |
| 509 | |
| 510 void DMA2_Stream2_IRQHandler(void) | |
| 511 { | |
| 512 HAL_DMA_IRQHandler(&hdma_uart_radio_rx); | |
| 513 } | |
| 514 #endif | |
| 1032 | 515 |
| 38 | 516 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) |
| 517 { | |
| 518 if(huart == &UartHandle) | |
| 519 UartReady = SET; | |
| 520 } | |
| 521 | |
|
321
37ee61f93124
Moved indication variable for received HUD data to tCCR file.
ideenmodellierer
parents:
300
diff
changeset
|
522 |
| 38 | 523 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
| 524 { | |
| 525 if(huart == &UartHandle) | |
| 1032 | 526 { |
| 527 #ifdef ENABLE_PULSE_SENSOR_BT | |
| 528 if(cv_heartbeat_getState() != SENSOR_HB_OFFLINE) | |
| 529 { | |
| 530 UART_StartDMARx(); | |
| 531 } | |
| 532 else | |
| 533 { | |
| 534 UartReady = SET; | |
| 535 } | |
| 536 #else | |
| 537 UartReady = SET; | |
| 538 #endif | |
| 539 } | |
| 38 | 540 else |
| 541 if(huart == &UartIR_HUD_Handle) | |
| 542 { | |
| 870 | 543 #ifndef BOOTLOADER_STANDALONE |
|
321
37ee61f93124
Moved indication variable for received HUD data to tCCR file.
ideenmodellierer
parents:
300
diff
changeset
|
544 tCCR_SetRXIndication(); |
| 870 | 545 #endif |
| 546 UartReadyHUD = SET; | |
| 38 | 547 } |
| 548 } | |
| 549 | |
| 550 void MX_tell_reset_logik_alles_ok(void) | |
| 551 { | |
| 552 #ifdef RESET_LOGIC_ALLES_OK_PIN | |
| 553 GPIO_InitTypeDef GPIO_InitStruct; | |
| 554 | |
| 555 RESET_LOGIC_ALLES_OK_GPIO_ENABLE(); | |
| 556 | |
| 557 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
| 558 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 559 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 560 GPIO_InitStruct.Pin = RESET_LOGIC_ALLES_OK_PIN; | |
| 561 HAL_GPIO_Init(RESET_LOGIC_ALLES_OK_GPIO_PORT, &GPIO_InitStruct); | |
| 562 | |
| 563 HAL_GPIO_WritePin(RESET_LOGIC_ALLES_OK_GPIO_PORT,RESET_LOGIC_ALLES_OK_PIN,GPIO_PIN_RESET); | |
| 564 HAL_Delay(1); | |
| 565 HAL_GPIO_WritePin(RESET_LOGIC_ALLES_OK_GPIO_PORT,RESET_LOGIC_ALLES_OK_PIN,GPIO_PIN_SET); | |
| 566 | |
| 567 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
| 568 HAL_GPIO_Init(RESET_LOGIC_ALLES_OK_GPIO_PORT, &GPIO_InitStruct); | |
| 569 #endif | |
| 570 } | |
|
885
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
571 void SetDisplayVersion(uint8_t version) |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
572 { |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
573 if(version < 2) |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
574 { |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
575 hardwareDisplay = version; |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
576 } |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
577 } |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
578 uint8_t isNewDisplay() |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
579 { |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
580 uint8_t ret = 0; |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
581 if(hardwareDisplay == DISPLAY_VERSION_NEW) |
|
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 ret = 1; |
|
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 return ret; |
|
8d3f3a635397
Replaced global hardwareDisplay with unit access:
Ideenmodellierer
parents:
879
diff
changeset
|
586 } |
| 38 | 587 |
| 588 #ifndef BOOTLOADER_STANDALONE | |
| 589 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) | |
| 590 { | |
| 591 if(huart == &UartIR_HUD_Handle) | |
| 592 tCCR_restart(); | |
| 593 } | |
| 594 #endif |
