Mercurial > public > ostc4
comparison Discovery/Src/tComm.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 | b018e1f3082e |
| children |
comparison
equal
deleted
inserted
replaced
| 1045:b018e1f3082e | 1046:1d7c7a36df15 |
|---|---|
| 186 if( settingsGetPointer()->bluetoothActive == 0) | 186 if( settingsGetPointer()->bluetoothActive == 0) |
| 187 { | 187 { |
| 188 if(bluetoothActiveLastTime) | 188 if(bluetoothActiveLastTime) |
| 189 { | 189 { |
| 190 HAL_UART_AbortReceive_IT(&UartHandle); | 190 HAL_UART_AbortReceive_IT(&UartHandle); |
| 191 HAL_UART_DeInit(&UartHandle); | 191 HAL_UART_DeInit(&UartHandle); |
| 192 HAL_Delay(1); | 192 HAL_Delay(1); |
| 193 UartHandle.Init.BaudRate = 115200; /* Module will be operating at default baud rate if powered again */ | 193 UartHandle.Init.BaudRate = 115200; /* Module will be operating at default baud rate if powered again */ |
| 194 BmTmpConfig = BM_CONFIG_OFF; /* Restart configuration if powered again */ | 194 BmTmpConfig = BM_CONFIG_OFF; /* Restart configuration if powered again */ |
| 195 HAL_UART_Init(&UartHandle); | |
| 196 HAL_Delay(1); | 195 HAL_Delay(1); |
| 197 UartReady = RESET; | 196 UartReady = RESET; |
| 198 StartListeningToUART = 1; | 197 StartListeningToUART = 1; |
| 199 bluetoothActiveLastTime = 0; | 198 bluetoothActiveLastTime = 0; |
| 200 receiveStartByteUart = 0; | 199 receiveStartByteUart = 0; |
| 203 return 0; | 202 return 0; |
| 204 } | 203 } |
| 205 else | 204 else |
| 206 { | 205 { |
| 207 bluetoothActiveLastTime = 1; | 206 bluetoothActiveLastTime = 1; |
| 208 if(RequestDisconnection) | 207 if(RequestDisconnection) /* at the moment disconnection does not seem to be in use. */ |
| 209 { | 208 { /* Instead the modul id usually powered off for disconnection */ |
| 210 RequestDisconnection = 0; | 209 RequestDisconnection = 0; |
| 211 tComm_Disconnect(); | 210 tComm_Disconnect(); |
| 212 } | 211 } |
| 213 } | 212 } |
| 214 | 213 |
| 223 /*##-2- Put UART peripheral in reception process ###########################*/ | 222 /*##-2- Put UART peripheral in reception process ###########################*/ |
| 224 | 223 |
| 225 if((UartReady == RESET) && StartListeningToUART) | 224 if((UartReady == RESET) && StartListeningToUART) |
| 226 { | 225 { |
| 227 StartListeningToUART = 0; | 226 StartListeningToUART = 0; |
| 227 receiveStartByteUart = 0; | |
| 228 if(HAL_UART_Receive_IT(&UartHandle, &receiveStartByteUart, 1) != HAL_OK) | 228 if(HAL_UART_Receive_IT(&UartHandle, &receiveStartByteUart, 1) != HAL_OK) |
| 229 tComm_Error_Handler(); | 229 tComm_Error_Handler(); |
| 230 } | 230 } |
| 231 /* Reset transmission flag */ | 231 /* Reset transmission flag */ |
| 232 if(UartReady == SET) | 232 if(UartReady == SET) |
| 451 return answer; | 451 return answer; |
| 452 } | 452 } |
| 453 #ifndef BOOTLOADER_STANDALONE | 453 #ifndef BOOTLOADER_STANDALONE |
| 454 void tComm_Disconnect() | 454 void tComm_Disconnect() |
| 455 { | 455 { |
| 456 uint8_t answer; | 456 uint8_t answer = HAL_ERROR; |
| 457 uint8_t retrycnt = 3; | 457 uint8_t retrycnt = 3; |
| 458 char aTxDisconnect[] ="ATH\r"; | 458 char aTxDisconnect[] ="ATH\r"; |
| 459 char aTxBufferEnd[10]; | 459 char aTxBufferEnd[10]; |
| 460 char aTxBufferEscapeSequence[] = "+++"; | 460 char aTxBufferEscapeSequence[] = "+++"; |
| 461 | 461 |
| 462 uint8_t sizeDisconnect = sizeof(aTxDisconnect) -1; | 462 uint8_t sizeDisconnect = sizeof(aTxDisconnect) -1; |
| 463 | 463 |
| 464 tComm_GetBTCmdStr(BT_CMD_EXIT_CMD, aTxBufferEnd); | 464 if (isNewDisplay()) /* disconnect for OSTC5 BT is a little bit more complicated and not implemented yet, because function is not used */ |
| 465 HAL_UART_AbortReceive_IT(&UartHandle); | |
| 466 do | |
| 467 { | 465 { |
| 468 HAL_Delay(200); | 466 tComm_GetBTCmdStr(BT_CMD_EXIT_CMD, aTxBufferEnd); |
| 469 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, UART_OPERATION_TIMEOUT)== HAL_OK) | 467 HAL_UART_AbortReceive_IT(&UartHandle); |
| 468 do | |
| 470 { | 469 { |
| 471 answer = tComm_CheckAnswerOK(); | 470 HAL_Delay(200); |
| 471 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, UART_OPERATION_TIMEOUT)== HAL_OK) | |
| 472 { | |
| 473 answer = tComm_CheckAnswerOK(); | |
| 474 } | |
| 475 retrycnt--; | |
| 472 } | 476 } |
| 473 retrycnt--; | 477 while((answer != HAL_OK) && (retrycnt > 0)); |
| 474 } | 478 |
| 475 while((answer != HAL_OK) && (retrycnt > 0)); | 479 if(answer == HAL_OK) |
| 476 | |
| 477 if(answer == HAL_OK) | |
| 478 { | |
| 479 answer = HAL_ERROR; | |
| 480 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxDisconnect,sizeDisconnect , UART_OPERATION_TIMEOUT)== HAL_OK) | |
| 481 { | 480 { |
| 482 answer = HAL_ERROR; | 481 answer = HAL_ERROR; |
| 483 if(tComm_CheckAnswerOK() == HAL_OK) | 482 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxDisconnect,sizeDisconnect , UART_OPERATION_TIMEOUT)== HAL_OK) |
| 484 { | 483 { |
| 485 answer = HAL_ERROR; | 484 answer = HAL_ERROR; |
| 486 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, UART_OPERATION_TIMEOUT) == HAL_OK) /* exit terminal mode */ | 485 if(tComm_CheckAnswerOK() == HAL_OK) |
| 487 { | 486 { |
| 488 answer = tComm_CheckAnswerOK(); | 487 answer = HAL_ERROR; |
| 488 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, UART_OPERATION_TIMEOUT) == HAL_OK) /* exit terminal mode */ | |
| 489 { | |
| 490 answer = tComm_CheckAnswerOK(); | |
| 491 } | |
| 489 } | 492 } |
| 490 } | 493 } |
| 491 } | 494 } |
| 492 } | 495 } |
| 493 | 496 |
| 2039 } | 2042 } |
| 2040 else | 2043 else |
| 2041 { | 2044 { |
| 2042 if(indexRef != 0) | 2045 if(indexRef != 0) |
| 2043 { | 2046 { |
| 2044 indexRef = 0; | 2047 if((answerOkay[0] == aRxBuffer[indexBuf])) |
| 2048 { | |
| 2049 indexRef = 1; | |
| 2050 } | |
| 2051 else | |
| 2052 { | |
| 2053 indexRef = 0; | |
| 2054 } | |
| 2045 } | 2055 } |
| 2046 } | 2056 } |
| 2047 indexBuf++; | 2057 indexBuf++; |
| 2048 }while(indexBuf < sizeAnswer); | 2058 }while(indexBuf < sizeAnswer); |
| 2049 | 2059 |
| 2251 return ret; | 2261 return ret; |
| 2252 } | 2262 } |
| 2253 | 2263 |
| 2254 void tComm_StartBlueModConfig() | 2264 void tComm_StartBlueModConfig() |
| 2255 { | 2265 { |
| 2256 uint8_t answer = HAL_OK; | 2266 HAL_UART_Init(&UartHandle); |
| 2257 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; | |
| 2258 uint8_t index = 0; | |
| 2259 | |
| 2260 do /* flush RX buffer */ | |
| 2261 { | |
| 2262 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&RxBuffer[index], 1, 10); | |
| 2263 if(index < UART_CMD_BUF_SIZE) index++; | |
| 2264 }while(answer == HAL_OK); | |
| 2265 | 2267 |
| 2266 if (isNewDisplay()) | 2268 if (isNewDisplay()) |
| 2267 { | 2269 { |
| 2270 #ifdef ENABLE_FAST_COMM | |
| 2271 BmTmpConfig = BM_CONFIG5_ESCAPE1; | |
| 2272 #else | |
| 2268 BmTmpConfig = BM_CONFIG_DONE; /* Configuration is stored in BT module => no configuration needed */ | 2273 BmTmpConfig = BM_CONFIG_DONE; /* Configuration is stored in BT module => no configuration needed */ |
| 2274 #endif | |
| 2269 } | 2275 } |
| 2270 else | 2276 else |
| 2271 { | 2277 { |
| 2272 BmTmpConfig = BM_CONFIG_ECHO; | 2278 BmTmpConfig = BM_CONFIG_ECHO; |
| 2273 } | 2279 } |
| 2275 | 2281 |
| 2276 uint8_t tComm_HandleBlueModConfig() | 2282 uint8_t tComm_HandleBlueModConfig() |
| 2277 { | 2283 { |
| 2278 static uint8_t RestartModule = 1; /* used to do power off / on cycle */ | 2284 static uint8_t RestartModule = 1; /* used to do power off / on cycle */ |
| 2279 static uint8_t ConfigRetryCnt = 0; /* Retry count without power cycle */ | 2285 static uint8_t ConfigRetryCnt = 0; /* Retry count without power cycle */ |
| 2286 static uint32_t cmdTick = 0; | |
| 2287 #ifdef ENABLE_FAST_COMM | |
| 2288 static uint32_t configTick = 0; | |
| 2289 #endif | |
| 2280 | 2290 |
| 2281 char TxBuffer[UART_CMD_BUF_SIZE]; | 2291 char TxBuffer[UART_CMD_BUF_SIZE]; |
| 2282 uint8_t CmdSize = 0; | 2292 uint8_t CmdSize = 0; |
| 2283 | 2293 |
| 2284 uint8_t result = HAL_OK; | 2294 uint8_t result = HAL_OK; |
| 2285 | 2295 |
| 2286 memset(TxBuffer, 0, sizeof(TxBuffer)); | 2296 if(time_elapsed_ms(cmdTick, HAL_GetTick()) > 100) /* do config in 100ms steps */ |
| 2287 | |
| 2288 switch (BmTmpConfig) | |
| 2289 { | 2297 { |
| 2290 case BM_CONFIG_ECHO: tComm_GetBTCmdStr (BT_CMD_ECHO, TxBuffer); | 2298 cmdTick = HAL_GetTick(); |
| 2291 break; | 2299 memset(TxBuffer, 0, sizeof(TxBuffer)); |
| 2292 case BM_CONFIG_SILENCE: tComm_GetBTCmdStr (BT_CMD_SILENCE, TxBuffer); | 2300 |
| 2293 break; | 2301 switch (BmTmpConfig) |
| 2294 case BM_CONFIG_ESCAPE_DELAY: tComm_GetBTCmdStr (BT_CMD_ESCAPE_DELAY, TxBuffer); | 2302 { |
| 2295 break; | 2303 case BM_CONFIG_ECHO: tComm_GetBTCmdStr (BT_CMD_ECHO, TxBuffer); |
| 2296 case BM_CONFIG_SIGNAL_POLL: tComm_GetBTCmdStr(BT_CMD_SIGNAL_POLL, TxBuffer); | 2304 break; |
| 2297 break; | 2305 case BM_CONFIG_SILENCE: tComm_GetBTCmdStr (BT_CMD_SILENCE, TxBuffer); |
| 2298 case BM_CONFIG_BAUD: | 2306 break; |
| 2299 #ifdef ENABLE_FAST_COMM | 2307 case BM_CONFIG_ESCAPE_DELAY: tComm_GetBTCmdStr (BT_CMD_ESCAPE_DELAY, TxBuffer); |
| 2300 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_460, TxBuffer); | 2308 break; |
| 2301 #else | 2309 case BM_CONFIG_SIGNAL_POLL: tComm_GetBTCmdStr(BT_CMD_SIGNAL_POLL, TxBuffer); |
| 2302 BmTmpConfig = BM_CONFIG_DONE; | 2310 break; |
| 2303 #endif | 2311 case BM_CONFIG_BAUD: |
| 2304 break; | 2312 #ifdef ENABLE_FAST_COMM |
| 2305 case BM_CONFIG_RETRY: ConfigRetryCnt--; | 2313 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_460, TxBuffer); |
| 2306 HAL_Delay(1); | 2314 #else |
| 2307 if(ConfigRetryCnt == 0) | 2315 BmTmpConfig = BM_CONFIG_DONE; |
| 2316 #endif | |
| 2317 break; | |
| 2318 case BM_CONFIG_RETRY: ConfigRetryCnt--; | |
| 2319 HAL_Delay(1); | |
| 2320 if(ConfigRetryCnt == 0) | |
| 2321 { | |
| 2322 MX_Bluetooth_PowerOn(); | |
| 2323 tComm_StartBlueModConfig(); | |
| 2324 } | |
| 2325 break; | |
| 2326 case BM_CONFIG_DONE: | |
| 2327 case BM_CONFIG_OFF: | |
| 2328 ConfigRetryCnt = 0; | |
| 2329 RestartModule = 1; | |
| 2330 break; | |
| 2331 | |
| 2332 case BM_CONFIG5_ESCAPE1: configTick = HAL_GetTick(); | |
| 2333 BmTmpConfig++; | |
| 2334 break; | |
| 2335 case BM_CONFIG5_ESCAPE2: if(time_elapsed_ms(configTick, HAL_GetTick()) > 2600) | |
| 2308 { | 2336 { |
| 2309 MX_Bluetooth_PowerOn(); | 2337 configTick = HAL_GetTick(); |
| 2310 tComm_StartBlueModConfig(); | 2338 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_SET); |
| 2339 BmTmpConfig++; | |
| 2311 } | 2340 } |
| 2312 break; | 2341 break; |
| 2313 case BM_CONFIG_DONE: | 2342 case BM_CONFIG5_BAUD: if(time_elapsed_ms(configTick, HAL_GetTick()) > 1100) |
| 2314 case BM_CONFIG_OFF: | 2343 { |
| 2315 ConfigRetryCnt = 0; | 2344 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_460, TxBuffer); |
| 2316 RestartModule = 1; | 2345 } |
| 2317 break; | 2346 break; |
| 2318 #ifdef BOOTLOADER_STANDALONE /* the procedure below is just needed for the initial bluetooth module initialization */ | 2347 case BM_CONFIG5_DATAMODE: tComm_GetBTCmdStr(BT_CMD_EXIT_CMD, TxBuffer); |
| 2319 case BM_INIT_TRIGGER_ON: HAL_Delay(2000); | 2348 break; |
| 2320 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); | 2349 |
| 2321 BmTmpConfig++; | 2350 default: |
| 2322 break; | 2351 break; |
| 2323 case BM_INIT_TRIGGER_OFF: HAL_Delay(1); | 2352 } |
| 2324 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_SET); | 2353 if(TxBuffer[0] != 0) /* forward command to module */ |
| 2325 HAL_Delay(2000); | |
| 2326 BmTmpConfig++; | |
| 2327 break; | |
| 2328 case BM_INIT_ECHO: sprintf(TxBuffer,"ATE0\r"); | |
| 2329 break; | |
| 2330 case BM_INIT_FACTORY: sprintf(TxBuffer,"AT+UFACTORY\r"); /*Set to factory defined configuration */ | |
| 2331 break; | |
| 2332 case BM_INIT_MODE: sprintf(TxBuffer,"AT+UMSM=1\r"); /* start in Data mode */ | |
| 2333 break; | |
| 2334 case BM_INIT_BLE: sprintf(TxBuffer,"AT+UBTLE=2\r"); /* Bluetooth low energy Peripheral */ | |
| 2335 break; | |
| 2336 case BM_INIT_NAME: sprintf(TxBuffer,"AT+UBTLN=OSTC5-12345\r"); /* Bluetooth name */ | |
| 2337 if(hardwareDataGetPointer()->primarySerial != 0xFFFF) /* module reinit? => restore old name */ | |
| 2338 { | |
| 2339 gfx_number_to_string(5,1,&TxBuffer[15],hardwareDataGetPointer()->primarySerial); | |
| 2340 } | |
| 2341 break; | |
| 2342 case BM_INIT_SSP_IDO_OFF: sprintf(TxBuffer,"AT+UDSC=0,0\r"); /* Disable SPP Server on ID0 */ | |
| 2343 break; | |
| 2344 case BM_INIT_SSP_IDO_ON: sprintf(TxBuffer,"AT+UDSC=0,3\r"); /* SPP Server on ID0 */ | |
| 2345 break; | |
| 2346 case BM_INIT_SSP_ID1_OFF: sprintf(TxBuffer,"AT+UDSC=1,0\r"); /* Disable SPS Server on ID1 */ | |
| 2347 break; | |
| 2348 case BM_INIT_SSP_ID1_ON: sprintf(TxBuffer,"AT+UDSC=1,6\r"); /* SPS Server on ID1 */ | |
| 2349 break; | |
| 2350 case BM_INIT_STORE: sprintf(TxBuffer,"AT&W\r"); /* write settings into eeprom */ | |
| 2351 break; | |
| 2352 case BM_INIT_RESTART: sprintf(TxBuffer,"AT+CPWROFF\r"); /* reboot module */ | |
| 2353 break; | |
| 2354 case BM_INIT_DONE: BmTmpConfig = BM_CONFIG_ECHO; | |
| 2355 break; | |
| 2356 #endif | |
| 2357 default: | |
| 2358 break; | |
| 2359 } | |
| 2360 if(TxBuffer[0] != 0) /* forward command to module */ | |
| 2361 { | |
| 2362 CmdSize = strlen(TxBuffer); | |
| 2363 result = HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 500); | |
| 2364 if(result == HAL_OK) | |
| 2365 { | 2354 { |
| 2366 result = tComm_CheckAnswerOK(); | 2355 CmdSize = strlen(TxBuffer); |
| 2367 | 2356 result = HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 500); |
| 2368 if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate != 460800)) /* is com already switched to fast speed? */ | |
| 2369 { | |
| 2370 HAL_UART_DeInit(&UartHandle); | |
| 2371 HAL_Delay(1); | |
| 2372 UartHandle.Init.BaudRate = 460800; | |
| 2373 HAL_UART_Init(&UartHandle); | |
| 2374 } | |
| 2375 else if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate == 460800)) /* This shut not happen because default speed is 115200 => update module configuration */ | |
| 2376 { | |
| 2377 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_115, TxBuffer); | |
| 2378 | |
| 2379 CmdSize = strlen(TxBuffer); | |
| 2380 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | |
| 2381 HAL_UART_DeInit(&UartHandle); | |
| 2382 HAL_Delay(10); | |
| 2383 UartHandle.Init.BaudRate = 115200; | |
| 2384 HAL_UART_Init(&UartHandle); | |
| 2385 sprintf(TxBuffer,"AT&W\r"); /* write configuration */ | |
| 2386 CmdSize = strlen(TxBuffer); | |
| 2387 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | |
| 2388 } | |
| 2389 if(result == HAL_OK) | 2357 if(result == HAL_OK) |
| 2390 { | 2358 { |
| 2391 BmTmpConfig++; | 2359 result = tComm_CheckAnswerOK(); |
| 2392 if(BmTmpConfig == BM_CONFIG_RETRY) | 2360 |
| 2393 { | 2361 if(((BmTmpConfig == BM_CONFIG_BAUD) || (BmTmpConfig == BM_CONFIG5_BAUD)) && (result == HAL_OK) && (UartHandle.Init.BaudRate != 460800)) /* is com already switched to fast speed? */ |
| 2394 BmTmpConfig = BM_CONFIG_DONE; | |
| 2395 } | |
| 2396 } | |
| 2397 #if 0 | |
| 2398 if(BmTmpConfig == BM_CONFIG_ECHO) | |
| 2399 { | |
| 2400 BmTmpConfig = BM_CONFIG_DONE; | |
| 2401 ConfigRetryCnt = 0; | |
| 2402 RestartModule = 1; | |
| 2403 } | |
| 2404 #endif | |
| 2405 } | |
| 2406 } | |
| 2407 else /* no command for the configuration step found => skip step */ | |
| 2408 { | |
| 2409 if((BmTmpConfig > BM_CONFIG_OFF) && (BmTmpConfig < BM_CONFIG_DONE)) | |
| 2410 { | |
| 2411 BmTmpConfig++; | |
| 2412 } | |
| 2413 } | |
| 2414 if(result != HAL_OK) | |
| 2415 { | |
| 2416 ConfigRetryCnt++; | |
| 2417 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ | |
| 2418 { | |
| 2419 MX_Bluetooth_PowerOff(); | |
| 2420 if(RestartModule) | |
| 2421 { | |
| 2422 RestartModule = 0; /* only one try */ | |
| 2423 ConfigRetryCnt = 200; /* used for delay to startup module again */ | |
| 2424 | |
| 2425 if((BmTmpConfig == BM_CONFIG_ECHO) || (BmTmpConfig == BM_INIT_ECHO)) /* the module did not answer even once => try again with alternative baud rate */ | |
| 2426 { | 2362 { |
| 2427 HAL_UART_DeInit(&UartHandle); | 2363 HAL_UART_DeInit(&UartHandle); |
| 2428 HAL_Delay(1); | 2364 HAL_Delay(1); |
| 2429 UartHandle.Init.BaudRate = 460800; | 2365 UartHandle.Init.BaudRate = 460800; |
| 2430 HAL_UART_Init(&UartHandle); | 2366 HAL_UART_Init(&UartHandle); |
| 2431 } | 2367 } |
| 2432 BmTmpConfig = BM_CONFIG_RETRY; | 2368 else if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate == 460800)) /* This shut not happen because default speed is 115200 => update module configuration */ |
| 2369 { | |
| 2370 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_115, TxBuffer); | |
| 2371 | |
| 2372 CmdSize = strlen(TxBuffer); | |
| 2373 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | |
| 2374 HAL_UART_DeInit(&UartHandle); | |
| 2375 HAL_Delay(10); | |
| 2376 UartHandle.Init.BaudRate = 115200; | |
| 2377 HAL_UART_Init(&UartHandle); | |
| 2378 sprintf(TxBuffer,"AT&W\r"); /* write configuration */ | |
| 2379 CmdSize = strlen(TxBuffer); | |
| 2380 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | |
| 2381 } | |
| 2382 if(result == HAL_OK) | |
| 2383 { | |
| 2384 if((BmTmpConfig != BM_CONFIG5_DATAMODE) && (BmTmpConfig != BM_CONFIG_DONE)) | |
| 2385 { | |
| 2386 BmTmpConfig++; | |
| 2387 } | |
| 2388 else | |
| 2389 { | |
| 2390 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); | |
| 2391 BmTmpConfig = BM_CONFIG_DONE; | |
| 2392 } | |
| 2393 } | |
| 2433 } | 2394 } |
| 2434 else /* even restarting module failed => switch bluetooth off */ | 2395 } |
| 2396 else /* no command for the configuration step found => skip step */ | |
| 2397 { | |
| 2398 if((BmTmpConfig > BM_CONFIG_OFF) && (BmTmpConfig < BM_CONFIG_DONE)) | |
| 2435 { | 2399 { |
| 2436 ConfigRetryCnt = 0; | 2400 BmTmpConfig++; |
| 2437 BmTmpConfig = BM_CONFIG_OFF; | 2401 } |
| 2438 settingsGetPointer()->bluetoothActive = 0; | 2402 } |
| 2403 if(result != HAL_OK) | |
| 2404 { | |
| 2405 ConfigRetryCnt++; | |
| 2406 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ | |
| 2407 { | |
| 2408 MX_Bluetooth_PowerOff(); | |
| 2409 if(RestartModule) | |
| 2410 { | |
| 2411 RestartModule = 0; /* only one try */ | |
| 2412 ConfigRetryCnt = 200; /* used for delay to startup module again */ | |
| 2413 | |
| 2414 if((BmTmpConfig == BM_CONFIG_ECHO) || (BmTmpConfig == BM_INIT_ECHO)) /* the module did not answer even once => try again with alternative baud rate */ | |
| 2415 { | |
| 2416 HAL_UART_DeInit(&UartHandle); | |
| 2417 HAL_Delay(1); | |
| 2418 UartHandle.Init.BaudRate = 460800; | |
| 2419 HAL_UART_Init(&UartHandle); | |
| 2420 } | |
| 2421 BmTmpConfig = BM_CONFIG_RETRY; | |
| 2422 } | |
| 2423 else /* even restarting module failed => switch bluetooth off */ | |
| 2424 { | |
| 2425 ConfigRetryCnt = 0; | |
| 2426 BmTmpConfig = BM_CONFIG_OFF; | |
| 2427 settingsGetPointer()->bluetoothActive = 0; | |
| 2428 } | |
| 2439 } | 2429 } |
| 2440 } | 2430 } |
| 2441 } | 2431 } |
| 2442 return result; | 2432 return result; |
| 2443 } | 2433 } |
