Mercurial > public > ostc4
comparison Discovery/Src/tComm.c @ 981:c6c781a2e85b default
Merge into default
| author | heinrichsweikamp |
|---|---|
| date | Tue, 11 Feb 2025 18:12:00 +0100 |
| parents | 3123aa8723fd |
| children | 5924a2d1d3ba |
comparison
equal
deleted
inserted
replaced
| 871:f7318457df4d | 981:c6c781a2e85b |
|---|---|
| 77 # include "logbook.h" | 77 # include "logbook.h" |
| 78 # include "tMenu.h" | 78 # include "tMenu.h" |
| 79 #else | 79 #else |
| 80 # include "base_bootloader.h" | 80 # include "base_bootloader.h" |
| 81 # include "firmwareEraseProgram.h" | 81 # include "firmwareEraseProgram.h" |
| 82 # include "text_multilanguage.h" | |
| 82 #endif | 83 #endif |
| 83 | 84 |
| 84 #ifdef SPECIALPROGRAMM | 85 #ifdef SPECIALPROGRAMM |
| 85 # include "firmwareEraseProgram.h" | 86 # include "firmwareEraseProgram.h" |
| 86 #endif | 87 #endif |
| 108 | 109 |
| 109 #define UART_OPERATION_TIMEOUT (500u) /* Timeout for common read / write operations (ms) */ | 110 #define UART_OPERATION_TIMEOUT (500u) /* Timeout for common read / write operations (ms) */ |
| 110 #define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */ | 111 #define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */ |
| 111 #define UART_TIMEOUT_LARGE_BLOCK (6000u) /* Timeout (ms) for reception of an 16K data block (typical RX time ~4,5seconds) */ | 112 #define UART_TIMEOUT_LARGE_BLOCK (6000u) /* Timeout (ms) for reception of an 16K data block (typical RX time ~4,5seconds) */ |
| 112 | 113 |
| 113 #define UART_CMD_BUF_SIZE (20u) /* size of buffer for command exchange */ | 114 #define UART_CMD_BUF_SIZE (30u) /* size of buffer for command exchange */ |
| 114 | 115 |
| 115 const uint8_t id_Region1_firmware = 0xFF; | 116 const uint8_t id_Region1_firmware = 0xFF; |
| 116 const uint8_t id_RTE = 0xFE; | 117 const uint8_t id_RTE = 0xFE; |
| 117 const uint8_t id_FONT = 0x10; | 118 const uint8_t id_FONT = 0x10; |
| 118 const uint8_t id_FONT_OLD = 0x00; | 119 const uint8_t id_FONT_OLD = 0x00; |
| 119 | 120 |
| 120 static BlueModTmpConfig_t BmTmpConfig = BM_CONFIG_OFF; /* Config BlueMod without storing the changes */ | 121 static BlueModTmpConfig_t BmTmpConfig = BM_CONFIG_OFF; /* Config BlueMod without storing the changes */ |
| 121 static uint8_t EvaluateBluetoothSignalStrength = 0; | 122 static uint8_t EvaluateBluetoothSignalStrength = 0; |
| 123 #ifndef BOOTLOADER_STANDALONE | |
| 122 static uint8_t RequestDisconnection = 0; /* Disconnection from remote device requested */ | 124 static uint8_t RequestDisconnection = 0; /* Disconnection from remote device requested */ |
| 125 static void tComm_Disconnect(void); | |
| 126 #endif | |
| 123 /* Private function prototypes -----------------------------------------------*/ | 127 /* Private function prototypes -----------------------------------------------*/ |
| 124 static void tComm_Disconnect(void); | |
| 125 static void tComm_Error_Handler(void); | 128 static void tComm_Error_Handler(void); |
| 126 static uint8_t select_mode(uint8_t aRxByte); | 129 static uint8_t select_mode(uint8_t aRxByte); |
| 127 static uint8_t tComm_CheckAnswerOK(void); | 130 static uint8_t tComm_CheckAnswerOK(void); |
| 128 static uint8_t tComm_HandleBlueModConfig(void); | 131 static uint8_t tComm_HandleBlueModConfig(void); |
| 129 static void tComm_EvaluateBluetoothStrength(void); | 132 static void tComm_EvaluateBluetoothStrength(void); |
| 134 uint8_t receive_update_data_mainCPU_firmware_subroutine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2); | 137 uint8_t receive_update_data_mainCPU_firmware_subroutine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2); |
| 135 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size); | 138 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size); |
| 136 static uint8_t openComm(uint8_t aRxByte); | 139 static uint8_t openComm(uint8_t aRxByte); |
| 137 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence); | 140 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence); |
| 138 uint8_t prompt4D4C(uint8_t mode); | 141 uint8_t prompt4D4C(uint8_t mode); |
| 142 uint8_t tComm_GetBTCmdStr(BTCmd cmdId, char* pCmdStr); | |
| 139 | 143 |
| 140 #ifdef BOOTLOADER_STANDALONE | 144 #ifdef BOOTLOADER_STANDALONE |
| 141 static uint8_t receive_update_data_cpu2(void); | 145 static uint8_t receive_update_data_cpu2(void); |
| 142 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer); | 146 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer); |
| 143 #endif | 147 #endif |
| 365 #ifdef BOOTLOADER_STANDALONE | 369 #ifdef BOOTLOADER_STANDALONE |
| 366 if(answer == HAL_OK) | 370 if(answer == HAL_OK) |
| 367 hardware_programmPrimaryBluetoothNameSet(); | 371 hardware_programmPrimaryBluetoothNameSet(); |
| 368 #endif | 372 #endif |
| 369 } | 373 } |
| 374 else /* no serial set at all => do default configuration of the module */ | |
| 375 { | |
| 376 #define NINAB22103B00 | |
| 377 #ifdef NINAB22103B00 | |
| 378 answer = 0xFF; | |
| 379 #endif | |
| 380 } | |
| 370 return answer; | 381 return answer; |
| 371 } | 382 } |
| 372 | 383 |
| 373 | 384 |
| 374 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence) | 385 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence) |
| 375 { | 386 { |
| 376 uint8_t answer = HAL_OK; | 387 uint8_t answer = HAL_OK; |
| 377 uint8_t aRxBuffer[50]; | 388 uint8_t aRxBuffer[50]; |
| 389 char aTxBufferName[50]; | |
| 378 | 390 |
| 379 // char aTxFactoryDefaults[50] = "AT&F1\r"; | 391 // char aTxFactoryDefaults[50] = "AT&F1\r"; |
| 380 | 392 |
| 381 char aTxBufferEscapeSequence[50] = "+++"; | 393 char aTxBufferEscapeSequence[50] = "+++"; /* factory default */ |
| 382 // limit is 19 chars, with 7 chars shown in BLE advertising mode | 394 // limit is 19 chars, with 7 chars shown in BLE advertising mode |
| 383 //________________________123456789012345678901 | 395 //________________________123456789012345678901 |
| 384 char aTxBufferName[50] = "AT+BNAME=OSTC4-12345\r"; | 396 |
| 397 tComm_GetBTCmdStr(BT_CMD_NAME, aTxBufferName); | |
| 398 | |
| 385 char answerOkay[6] = "\r\nOK\r\n"; | 399 char answerOkay[6] = "\r\nOK\r\n"; |
| 386 | 400 |
| 387 gfx_number_to_string(5,1,&aTxBufferName[15],serial); | 401 gfx_number_to_string(5,1,&aTxBufferName[15],serial); |
| 388 | 402 |
| 389 // store active configuration in non-volatile memory | 403 // store active configuration in non-volatile memory |
| 434 answer = HAL_ERROR; | 448 answer = HAL_ERROR; |
| 435 | 449 |
| 436 answer = HAL_OK; | 450 answer = HAL_OK; |
| 437 return answer; | 451 return answer; |
| 438 } | 452 } |
| 439 | 453 #ifndef BOOTLOADER_STANDALONE |
| 440 void tComm_Disconnect() | 454 void tComm_Disconnect() |
| 441 { | 455 { |
| 442 uint8_t answer; | 456 uint8_t answer; |
| 443 uint8_t retrycnt = 3; | 457 uint8_t retrycnt = 3; |
| 444 char aTxDisconnect[] ="ATH\r"; | 458 char aTxDisconnect[] ="ATH\r"; |
| 445 char aTxBufferEnd[] = "ATO\r"; | 459 char aTxBufferEnd[10]; |
| 446 char aTxBufferEscapeSequence[] = "+++"; | 460 char aTxBufferEscapeSequence[] = "+++"; |
| 447 | 461 |
| 448 uint8_t sizeDisconnect = sizeof(aTxDisconnect) -1; | 462 uint8_t sizeDisconnect = sizeof(aTxDisconnect) -1; |
| 449 | 463 |
| 464 tComm_GetBTCmdStr(BT_CMD_EXIT_CMD, aTxBufferEnd); | |
| 450 HAL_UART_AbortReceive_IT(&UartHandle); | 465 HAL_UART_AbortReceive_IT(&UartHandle); |
| 451 do | 466 do |
| 452 { | 467 { |
| 453 HAL_Delay(200); | 468 HAL_Delay(200); |
| 454 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, UART_OPERATION_TIMEOUT)== HAL_OK) | 469 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, UART_OPERATION_TIMEOUT)== HAL_OK) |
| 480 { | 495 { |
| 481 settingsGetPointer()->bluetoothActive = 0; | 496 settingsGetPointer()->bluetoothActive = 0; |
| 482 MX_Bluetooth_PowerOff(); | 497 MX_Bluetooth_PowerOff(); |
| 483 } | 498 } |
| 484 } | 499 } |
| 485 | 500 #endif |
| 486 | 501 |
| 487 uint8_t openComm(uint8_t aRxByte) | 502 uint8_t openComm(uint8_t aRxByte) |
| 488 { | 503 { |
| 489 SStateList status; | 504 SStateList status; |
| 490 uint8_t localRx; | 505 uint8_t localRx; |
| 584 SLogbookHeaderOSTC3compact * plogbookHeaderOSTC3compact; | 599 SLogbookHeaderOSTC3compact * plogbookHeaderOSTC3compact; |
| 585 uint32_t sampleTotalLength; | 600 uint32_t sampleTotalLength; |
| 586 SSettings* pSettings = settingsGetPointer(); | 601 SSettings* pSettings = settingsGetPointer(); |
| 587 RTC_DateTypeDef sdatestructure; | 602 RTC_DateTypeDef sdatestructure; |
| 588 RTC_TimeTypeDef stimestructure; | 603 RTC_TimeTypeDef stimestructure; |
| 604 uint16_t index; | |
| 605 uint32_t header_profileLength, OSTC3_profileLength; | |
| 589 #else | 606 #else |
| 590 uint8_t dummyForBootloader[256] = {0}; | 607 uint8_t dummyForBootloader[256] = {0}; |
| 591 #endif | 608 #endif |
| 592 uint8_t count; | 609 uint8_t count; |
| 593 uint8_t aTxBuffer[128]; | 610 uint8_t aTxBuffer[128]; |
| 594 uint8_t aRxBuffer[68]; | 611 uint8_t aRxBuffer[68]; |
| 595 uint8_t answer; | 612 uint8_t answer; |
| 596 uint16_t index; | |
| 597 uint32_t header_profileLength, OSTC3_profileLength; | |
| 598 aTxBuffer[0] = type; | 613 aTxBuffer[0] = type; |
| 599 aTxBuffer[1] = prompt4D4C(receiveStartByteUart); | 614 aTxBuffer[1] = prompt4D4C(receiveStartByteUart); |
| 600 uint8_t tempHigh, tempLow; | 615 uint8_t tempHigh, tempLow; |
| 601 count = 0; | 616 count = 0; |
| 602 | 617 |
| 1449 //get Checksum | 1464 //get Checksum |
| 1450 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 580000 | 1465 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 580000 |
| 1451 { | 1466 { |
| 1452 return 0; | 1467 return 0; |
| 1453 } | 1468 } |
| 1454 uint32_t checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | 1469 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; |
| 1455 // uint32_t checksumCalc = crc32c_checksum(pBuffer, length,0,0); | 1470 // uint32_t checksumCalc = crc32c_checksum(pBuffer, length,0,0); |
| 1456 uint32_t checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer, length/4); | 1471 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer, length/4); |
| 1457 | 1472 |
| 1458 if(checksum != checksumCalc) | 1473 if(checksum != checksumCalc) |
| 1459 { | 1474 { |
| 1460 return 0; | 1475 return 0; |
| 1461 } | 1476 } |
| 2026 | 2041 |
| 2027 if(indexRef != sizeAnswer) /* unexpected answer => there might be characters left in RX que => read and check all rx bytes */ | 2042 if(indexRef != sizeAnswer) /* unexpected answer => there might be characters left in RX que => read and check all rx bytes */ |
| 2028 { | 2043 { |
| 2029 do | 2044 do |
| 2030 { | 2045 { |
| 2031 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[indexBuf], 1, 10); | 2046 answer = HAL_ERROR; |
| 2032 if (indexBuf < UART_CMD_BUF_SIZE) | 2047 if (indexBuf < UART_CMD_BUF_SIZE) |
| 2033 { | 2048 { |
| 2049 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[indexBuf], 1, 10); | |
| 2050 | |
| 2034 if(answerOkay[indexRef] == aRxBuffer[indexBuf]) | 2051 if(answerOkay[indexRef] == aRxBuffer[indexBuf]) |
| 2035 { | 2052 { |
| 2036 indexRef++; | 2053 indexRef++; |
| 2037 } | 2054 } |
| 2038 else | 2055 else |
| 2042 indexRef = 0; | 2059 indexRef = 0; |
| 2043 } | 2060 } |
| 2044 } | 2061 } |
| 2045 indexBuf++; | 2062 indexBuf++; |
| 2046 } | 2063 } |
| 2047 }while(answer == HAL_OK); | 2064 }while((answer == HAL_OK) && (indexRef != sizeAnswer)); |
| 2048 if(indexRef != sizeAnswer) | 2065 if(indexRef != sizeAnswer) |
| 2049 { | 2066 { |
| 2050 result = HAL_ERROR; | 2067 result = HAL_ERROR; |
| 2051 } | 2068 } |
| 2052 } | 2069 } |
| 2136 }while(answer == HAL_OK); | 2153 }while(answer == HAL_OK); |
| 2137 } | 2154 } |
| 2138 } | 2155 } |
| 2139 } | 2156 } |
| 2140 | 2157 |
| 2158 #ifdef BOOTLOADER_STANDALONE | |
| 2159 void tComm_StartBlueModBaseInit() | |
| 2160 { | |
| 2161 BmTmpConfig = BM_INIT_TRIGGER_ON; | |
| 2162 } | |
| 2163 #endif | |
| 2164 | |
| 2165 | |
| 2166 uint8_t tComm_GetBTCmdStr(BTCmd cmdId, char* pCmdStr) | |
| 2167 { | |
| 2168 uint8_t ret = 0; | |
| 2169 uint8_t oldModule = 1; | |
| 2170 | |
| 2171 if(isNewDisplay()) | |
| 2172 { | |
| 2173 oldModule = 0; | |
| 2174 } | |
| 2175 | |
| 2176 switch (cmdId) | |
| 2177 { | |
| 2178 case BT_CMD_ECHO: sprintf(pCmdStr,"ATE0\r"); | |
| 2179 ret = 1; | |
| 2180 break; | |
| 2181 case BT_CMD_SILENCE: if(oldModule) | |
| 2182 { | |
| 2183 strcpy(pCmdStr,"ATS30=0\r"); | |
| 2184 ret = 1; | |
| 2185 } | |
| 2186 break; | |
| 2187 case BT_CMD_ESCAPE_DELAY: if(oldModule) | |
| 2188 { | |
| 2189 strcpy(pCmdStr,"ATS12=10\r"); | |
| 2190 ret = 1; | |
| 2191 } | |
| 2192 break; | |
| 2193 case BT_CMD_SIGNAL_POLL: if(oldModule) | |
| 2194 { | |
| 2195 strcpy(pCmdStr,"AT+BSTPOLL=100\r"); | |
| 2196 ret = 1; | |
| 2197 } | |
| 2198 break; | |
| 2199 case BT_CMD_BAUDRATE_115: if(oldModule) | |
| 2200 { | |
| 2201 strcpy(pCmdStr,"AT%B8\r"); | |
| 2202 } | |
| 2203 else | |
| 2204 { | |
| 2205 strcpy(pCmdStr,"AT+UMRS=115200,1,8,1,1,1\r"); | |
| 2206 } | |
| 2207 ret = 1; | |
| 2208 break; | |
| 2209 | |
| 2210 case BT_CMD_BAUDRATE_460: if(oldModule) | |
| 2211 { | |
| 2212 strcpy(pCmdStr,"AT%B22\r"); | |
| 2213 } | |
| 2214 else | |
| 2215 { | |
| 2216 strcpy(pCmdStr,"AT+UMRS=460800,1,8,1,1,1\r"); | |
| 2217 } | |
| 2218 ret = 1; | |
| 2219 break; | |
| 2220 case BT_CMD_NAME: if(oldModule) | |
| 2221 { | |
| 2222 strcpy(pCmdStr,"AT+BNAME=OSTC4-12345\r"); | |
| 2223 } | |
| 2224 else | |
| 2225 { | |
| 2226 strcpy(pCmdStr,"AT+UBTLN=OSTC5-12345\r"); | |
| 2227 } | |
| 2228 ret = 1; | |
| 2229 break; | |
| 2230 case BT_CMD_EXIT_CMD: if(oldModule) | |
| 2231 { | |
| 2232 strcpy(pCmdStr,"ATO\r"); | |
| 2233 } | |
| 2234 else | |
| 2235 { | |
| 2236 strcpy(pCmdStr,"ATO1\r"); | |
| 2237 } | |
| 2238 ret = 1; | |
| 2239 break; | |
| 2240 default: | |
| 2241 break; | |
| 2242 } | |
| 2243 return ret; | |
| 2244 } | |
| 2245 | |
| 2141 void tComm_StartBlueModConfig() | 2246 void tComm_StartBlueModConfig() |
| 2142 { | 2247 { |
| 2143 uint8_t answer = HAL_OK; | 2248 uint8_t answer = HAL_OK; |
| 2144 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; | 2249 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; |
| 2145 uint8_t index = 0; | 2250 uint8_t index = 0; |
| 2160 char TxBuffer[UART_CMD_BUF_SIZE]; | 2265 char TxBuffer[UART_CMD_BUF_SIZE]; |
| 2161 uint8_t CmdSize = 0; | 2266 uint8_t CmdSize = 0; |
| 2162 | 2267 |
| 2163 uint8_t result = HAL_OK; | 2268 uint8_t result = HAL_OK; |
| 2164 | 2269 |
| 2165 TxBuffer[0] = 0; | 2270 memset(TxBuffer, 0, sizeof(TxBuffer)); |
| 2166 | 2271 |
| 2167 switch (BmTmpConfig) | 2272 switch (BmTmpConfig) |
| 2168 { | 2273 { |
| 2169 case BM_CONFIG_ECHO: sprintf(TxBuffer,"ATE0\r"); | 2274 case BM_CONFIG_ECHO: tComm_GetBTCmdStr (BT_CMD_ECHO, TxBuffer); |
| 2170 break; | 2275 break; |
| 2171 case BM_CONFIG_SILENCE: sprintf(TxBuffer,"ATS30=0\r"); | 2276 case BM_CONFIG_SILENCE: tComm_GetBTCmdStr (BT_CMD_SILENCE, TxBuffer); |
| 2172 break; | 2277 break; |
| 2173 case BM_CONFIG_ESCAPE_DELAY: sprintf(TxBuffer,"ATS12=10\r"); | 2278 case BM_CONFIG_ESCAPE_DELAY: tComm_GetBTCmdStr (BT_CMD_ESCAPE_DELAY, TxBuffer); |
| 2174 break; | 2279 break; |
| 2175 case BM_CONFIG_SIGNAL_POLL: sprintf(TxBuffer,"AT+BSTPOLL=100\r"); | 2280 case BM_CONFIG_SIGNAL_POLL: tComm_GetBTCmdStr(BT_CMD_SIGNAL_POLL, TxBuffer); |
| 2176 break; | 2281 break; |
| 2177 case BM_CONFIG_BAUD: sprintf(TxBuffer,"AT%%B22\r"); | 2282 case BM_CONFIG_BAUD: |
| 2283 #ifdef ENABLE_FAST_COMM | |
| 2284 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_460, TxBuffer); | |
| 2285 #else | |
| 2286 BmTmpConfig = BM_CONFIG_DONE; | |
| 2287 #endif | |
| 2178 break; | 2288 break; |
| 2179 case BM_CONFIG_RETRY: ConfigRetryCnt--; | 2289 case BM_CONFIG_RETRY: ConfigRetryCnt--; |
| 2180 HAL_Delay(1); | 2290 HAL_Delay(1); |
| 2181 if(ConfigRetryCnt == 0) | 2291 if(ConfigRetryCnt == 0) |
| 2182 { | 2292 { |
| 2187 case BM_CONFIG_DONE: | 2297 case BM_CONFIG_DONE: |
| 2188 case BM_CONFIG_OFF: | 2298 case BM_CONFIG_OFF: |
| 2189 ConfigRetryCnt = 0; | 2299 ConfigRetryCnt = 0; |
| 2190 RestartModule = 1; | 2300 RestartModule = 1; |
| 2191 break; | 2301 break; |
| 2302 #ifdef BOOTLOADER_STANDALONE /* the procedure below is just needed for the initial bluetooth module initialization */ | |
| 2303 case BM_INIT_TRIGGER_ON: HAL_Delay(2000); | |
| 2304 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); | |
| 2305 BmTmpConfig++; | |
| 2306 break; | |
| 2307 case BM_INIT_TRIGGER_OFF: HAL_Delay(1); | |
| 2308 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_SET); | |
| 2309 HAL_Delay(2000); | |
| 2310 BmTmpConfig++; | |
| 2311 break; | |
| 2312 case BM_INIT_ECHO: sprintf(TxBuffer,"ATE0\r"); | |
| 2313 break; | |
| 2314 case BM_INIT_FACTORY: sprintf(TxBuffer,"AT+UFACTORY\r"); /*Set to factory defined configuration */ | |
| 2315 break; | |
| 2316 case BM_INIT_MODE: sprintf(TxBuffer,"AT+UMSM=1\r"); /* start in Data mode */ | |
| 2317 break; | |
| 2318 case BM_INIT_BLE: sprintf(TxBuffer,"AT+UBTLE=2\r"); /* Bluetooth low energy Peripheral */ | |
| 2319 break; | |
| 2320 case BM_INIT_NAME: sprintf(TxBuffer,"AT+UBTLN=OSTC5-12345\r"); /* Bluetooth name */ | |
| 2321 if(hardwareDataGetPointer()->primarySerial != 0xFFFF) /* module reinit? => restore old name */ | |
| 2322 { | |
| 2323 gfx_number_to_string(5,1,&TxBuffer[15],hardwareDataGetPointer()->primarySerial); | |
| 2324 } | |
| 2325 break; | |
| 2326 case BM_INIT_SSP_IDO_OFF: sprintf(TxBuffer,"AT+UDSC=0,0\r"); /* Disable SPP Server on ID0 */ | |
| 2327 break; | |
| 2328 case BM_INIT_SSP_IDO_ON: sprintf(TxBuffer,"AT+UDSC=0,3\r"); /* SPP Server on ID0 */ | |
| 2329 break; | |
| 2330 case BM_INIT_SSP_ID1_OFF: sprintf(TxBuffer,"AT+UDSC=1,0\r"); /* Disable SPS Server on ID1 */ | |
| 2331 break; | |
| 2332 case BM_INIT_SSP_ID1_ON: sprintf(TxBuffer,"AT+UDSC=1,6\r"); /* SPS Server on ID1 */ | |
| 2333 break; | |
| 2334 case BM_INIT_STORE: sprintf(TxBuffer,"AT&W\r"); /* write settings into eeprom */ | |
| 2335 break; | |
| 2336 case BM_INIT_RESTART: sprintf(TxBuffer,"AT+CPWROFF\r"); /* reboot module */ | |
| 2337 break; | |
| 2338 case BM_INIT_DONE: BmTmpConfig = BM_CONFIG_ECHO; | |
| 2339 break; | |
| 2340 #endif | |
| 2192 default: | 2341 default: |
| 2193 break; | 2342 break; |
| 2194 } | 2343 } |
| 2195 if(TxBuffer[0] != 0) /* forward command to module */ | 2344 if(TxBuffer[0] != 0) /* forward command to module */ |
| 2196 { | 2345 { |
| 2204 HAL_UART_DeInit(&UartHandle); | 2353 HAL_UART_DeInit(&UartHandle); |
| 2205 HAL_Delay(1); | 2354 HAL_Delay(1); |
| 2206 UartHandle.Init.BaudRate = 460800; | 2355 UartHandle.Init.BaudRate = 460800; |
| 2207 HAL_UART_Init(&UartHandle); | 2356 HAL_UART_Init(&UartHandle); |
| 2208 } | 2357 } |
| 2209 if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate == 460800)) /* This shut not happen because default speed is 115200 => update module configuration */ | 2358 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 */ |
| 2210 { | 2359 { |
| 2211 sprintf(TxBuffer,"AT%%B8\r"); /* set default baudrate */ | 2360 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_115, TxBuffer); |
| 2361 | |
| 2212 CmdSize = strlen(TxBuffer); | 2362 CmdSize = strlen(TxBuffer); |
| 2213 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | 2363 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); |
| 2214 HAL_UART_DeInit(&UartHandle); | 2364 HAL_UART_DeInit(&UartHandle); |
| 2215 HAL_Delay(10); | 2365 HAL_Delay(10); |
| 2216 UartHandle.Init.BaudRate = 115200; | 2366 UartHandle.Init.BaudRate = 115200; |
| 2220 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | 2370 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); |
| 2221 } | 2371 } |
| 2222 if(result == HAL_OK) | 2372 if(result == HAL_OK) |
| 2223 { | 2373 { |
| 2224 BmTmpConfig++; | 2374 BmTmpConfig++; |
| 2375 if(BmTmpConfig == BM_CONFIG_RETRY) | |
| 2376 { | |
| 2377 BmTmpConfig = BM_CONFIG_DONE; | |
| 2378 } | |
| 2225 } | 2379 } |
| 2226 if(BmTmpConfig == BM_CONFIG_DONE) | 2380 if(BmTmpConfig == BM_CONFIG_ECHO) |
| 2227 { | 2381 { |
| 2382 BmTmpConfig = BM_CONFIG_DONE; | |
| 2228 ConfigRetryCnt = 0; | 2383 ConfigRetryCnt = 0; |
| 2229 RestartModule = 1; | 2384 RestartModule = 1; |
| 2230 } | 2385 } |
| 2386 } | |
| 2387 } | |
| 2388 else /* no command for the configuration step found => skip step */ | |
| 2389 { | |
| 2390 if((BmTmpConfig > BM_CONFIG_OFF) && (BmTmpConfig < BM_CONFIG_DONE)) | |
| 2391 { | |
| 2392 BmTmpConfig++; | |
| 2231 } | 2393 } |
| 2232 } | 2394 } |
| 2233 if(result != HAL_OK) | 2395 if(result != HAL_OK) |
| 2234 { | 2396 { |
| 2235 ConfigRetryCnt++; | 2397 ConfigRetryCnt++; |
| 2239 if(RestartModule) | 2401 if(RestartModule) |
| 2240 { | 2402 { |
| 2241 RestartModule = 0; /* only one try */ | 2403 RestartModule = 0; /* only one try */ |
| 2242 ConfigRetryCnt = 200; /* used for delay to startup module again */ | 2404 ConfigRetryCnt = 200; /* used for delay to startup module again */ |
| 2243 | 2405 |
| 2244 if(BmTmpConfig == BM_CONFIG_ECHO) /* the module did not answer even once => try again with alternative baud rate */ | 2406 if((BmTmpConfig == BM_CONFIG_ECHO) || (BmTmpConfig == BM_INIT_ECHO)) /* the module did not answer even once => try again with alternative baud rate */ |
| 2245 { | 2407 { |
| 2246 HAL_UART_DeInit(&UartHandle); | 2408 HAL_UART_DeInit(&UartHandle); |
| 2247 HAL_Delay(1); | 2409 HAL_Delay(1); |
| 2248 UartHandle.Init.BaudRate = 460800; | 2410 UartHandle.Init.BaudRate = 460800; |
| 2249 HAL_UART_Init(&UartHandle); | 2411 HAL_UART_Init(&UartHandle); |
