Mercurial > public > ostc4
comparison Discovery/Src/tComm.c @ 970:3123aa8723fd Evo_2_23
Old / new BT module communication:
The old / new BT module do have a sligthly different command set. To keep them compatible a function has been added which returns, based on the HW identification, the command string which matches to the module. In case a command is not supported the value 0 is returned and the calling function may react. E.g. with skipping of configuration steps like it is done now for the new module.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 19 Jan 2025 20:55:30 +0100 |
| parents | 90edc237d60f |
| children | 5924a2d1d3ba |
comparison
equal
deleted
inserted
replaced
| 969:81049905d829 | 970:3123aa8723fd |
|---|---|
| 137 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); |
| 138 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); |
| 139 static uint8_t openComm(uint8_t aRxByte); | 139 static uint8_t openComm(uint8_t aRxByte); |
| 140 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); |
| 141 uint8_t prompt4D4C(uint8_t mode); | 141 uint8_t prompt4D4C(uint8_t mode); |
| 142 uint8_t tComm_GetBTCmdStr(BTCmd cmdId, char* pCmdStr); | |
| 142 | 143 |
| 143 #ifdef BOOTLOADER_STANDALONE | 144 #ifdef BOOTLOADER_STANDALONE |
| 144 static uint8_t receive_update_data_cpu2(void); | 145 static uint8_t receive_update_data_cpu2(void); |
| 145 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer); | 146 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer); |
| 146 #endif | 147 #endif |
| 383 | 384 |
| 384 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) |
| 385 { | 386 { |
| 386 uint8_t answer = HAL_OK; | 387 uint8_t answer = HAL_OK; |
| 387 uint8_t aRxBuffer[50]; | 388 uint8_t aRxBuffer[50]; |
| 389 char aTxBufferName[50]; | |
| 388 | 390 |
| 389 // char aTxFactoryDefaults[50] = "AT&F1\r"; | 391 // char aTxFactoryDefaults[50] = "AT&F1\r"; |
| 390 | 392 |
| 391 char aTxBufferEscapeSequence[50] = "+++"; /* factory default */ | 393 char aTxBufferEscapeSequence[50] = "+++"; /* factory default */ |
| 392 // 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 |
| 393 //________________________123456789012345678901 | 395 //________________________123456789012345678901 |
| 394 | 396 |
| 395 #ifndef BOOTLOADER_STANDALONE | 397 tComm_GetBTCmdStr(BT_CMD_NAME, aTxBufferName); |
| 396 char aTxBufferName[50] = "AT+BNAME=OSTC4-12345\r"; | 398 |
| 397 #else | |
| 398 char aTxBufferName[50] = "AT+UBTLN=OSTC4-12345\r"; | |
| 399 #endif | |
| 400 char answerOkay[6] = "\r\nOK\r\n"; | 399 char answerOkay[6] = "\r\nOK\r\n"; |
| 401 | 400 |
| 402 gfx_number_to_string(5,1,&aTxBufferName[15],serial); | 401 gfx_number_to_string(5,1,&aTxBufferName[15],serial); |
| 403 | 402 |
| 404 // store active configuration in non-volatile memory | 403 // store active configuration in non-volatile memory |
| 455 void tComm_Disconnect() | 454 void tComm_Disconnect() |
| 456 { | 455 { |
| 457 uint8_t answer; | 456 uint8_t answer; |
| 458 uint8_t retrycnt = 3; | 457 uint8_t retrycnt = 3; |
| 459 char aTxDisconnect[] ="ATH\r"; | 458 char aTxDisconnect[] ="ATH\r"; |
| 460 char aTxBufferEnd[] = "ATO\r"; | 459 char aTxBufferEnd[10]; |
| 461 char aTxBufferEscapeSequence[] = "+++"; | 460 char aTxBufferEscapeSequence[] = "+++"; |
| 462 | 461 |
| 463 uint8_t sizeDisconnect = sizeof(aTxDisconnect) -1; | 462 uint8_t sizeDisconnect = sizeof(aTxDisconnect) -1; |
| 464 | 463 |
| 464 tComm_GetBTCmdStr(BT_CMD_EXIT_CMD, aTxBufferEnd); | |
| 465 HAL_UART_AbortReceive_IT(&UartHandle); | 465 HAL_UART_AbortReceive_IT(&UartHandle); |
| 466 do | 466 do |
| 467 { | 467 { |
| 468 HAL_Delay(200); | 468 HAL_Delay(200); |
| 469 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) |
| 2160 { | 2160 { |
| 2161 BmTmpConfig = BM_INIT_TRIGGER_ON; | 2161 BmTmpConfig = BM_INIT_TRIGGER_ON; |
| 2162 } | 2162 } |
| 2163 #endif | 2163 #endif |
| 2164 | 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 | |
| 2165 void tComm_StartBlueModConfig() | 2246 void tComm_StartBlueModConfig() |
| 2166 { | 2247 { |
| 2167 uint8_t answer = HAL_OK; | 2248 uint8_t answer = HAL_OK; |
| 2168 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; | 2249 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; |
| 2169 uint8_t index = 0; | 2250 uint8_t index = 0; |
| 2184 char TxBuffer[UART_CMD_BUF_SIZE]; | 2265 char TxBuffer[UART_CMD_BUF_SIZE]; |
| 2185 uint8_t CmdSize = 0; | 2266 uint8_t CmdSize = 0; |
| 2186 | 2267 |
| 2187 uint8_t result = HAL_OK; | 2268 uint8_t result = HAL_OK; |
| 2188 | 2269 |
| 2189 TxBuffer[0] = 0; | 2270 memset(TxBuffer, 0, sizeof(TxBuffer)); |
| 2190 | 2271 |
| 2191 switch (BmTmpConfig) | 2272 switch (BmTmpConfig) |
| 2192 { | 2273 { |
| 2193 case BM_CONFIG_ECHO: sprintf(TxBuffer,"ATE0\r"); | 2274 case BM_CONFIG_ECHO: tComm_GetBTCmdStr (BT_CMD_ECHO, TxBuffer); |
| 2194 break; | 2275 break; |
| 2195 case BM_CONFIG_SILENCE: | 2276 case BM_CONFIG_SILENCE: tComm_GetBTCmdStr (BT_CMD_SILENCE, TxBuffer); |
| 2196 #ifndef BOOTLOADER_STANDALONE | |
| 2197 sprintf(TxBuffer,"ATS30=0\r"); | |
| 2198 #else | |
| 2199 BmTmpConfig++; | |
| 2200 #endif | |
| 2201 break; | 2277 break; |
| 2202 case BM_CONFIG_ESCAPE_DELAY: | 2278 case BM_CONFIG_ESCAPE_DELAY: tComm_GetBTCmdStr (BT_CMD_ESCAPE_DELAY, TxBuffer); |
| 2203 #ifndef BOOTLOADER_STANDALONE | |
| 2204 sprintf(TxBuffer,"ATS12=10\r"); | |
| 2205 #else | |
| 2206 BmTmpConfig++; | |
| 2207 #endif | |
| 2208 break; | 2279 break; |
| 2209 case BM_CONFIG_SIGNAL_POLL: | 2280 case BM_CONFIG_SIGNAL_POLL: tComm_GetBTCmdStr(BT_CMD_SIGNAL_POLL, TxBuffer); |
| 2210 #ifndef BOOTLOADER_STANDALONE | |
| 2211 sprintf(TxBuffer,"AT+BSTPOLL=100\r"); | |
| 2212 #else | |
| 2213 BmTmpConfig++; | |
| 2214 #endif | |
| 2215 break; | 2281 break; |
| 2216 case BM_CONFIG_BAUD: | 2282 case BM_CONFIG_BAUD: |
| 2217 #ifdef ENABLE_FAST_COMM | 2283 #ifdef ENABLE_FAST_COMM |
| 2218 #ifndef BOOTLOADER_STANDALONE | 2284 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_460, TxBuffer); |
| 2219 sprintf(TxBuffer,"AT%%B22\r"); | |
| 2220 #else | |
| 2221 sprintf(TxBuffer,"AT+UMRS=460800,1,8,1,1,1\r"); | |
| 2222 #endif | |
| 2223 #else | 2285 #else |
| 2224 BmTmpConfig = BM_CONFIG_DONE; | 2286 BmTmpConfig = BM_CONFIG_DONE; |
| 2225 #endif | 2287 #endif |
| 2226 break; | 2288 break; |
| 2227 case BM_CONFIG_RETRY: ConfigRetryCnt--; | 2289 case BM_CONFIG_RETRY: ConfigRetryCnt--; |
| 2235 case BM_CONFIG_DONE: | 2297 case BM_CONFIG_DONE: |
| 2236 case BM_CONFIG_OFF: | 2298 case BM_CONFIG_OFF: |
| 2237 ConfigRetryCnt = 0; | 2299 ConfigRetryCnt = 0; |
| 2238 RestartModule = 1; | 2300 RestartModule = 1; |
| 2239 break; | 2301 break; |
| 2240 #ifdef BOOTLOADER_STANDALONE | 2302 #ifdef BOOTLOADER_STANDALONE /* the procedure below is just needed for the initial bluetooth module initialization */ |
| 2241 case BM_INIT_TRIGGER_ON: HAL_Delay(2000); | 2303 case BM_INIT_TRIGGER_ON: HAL_Delay(2000); |
| 2242 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); | 2304 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); |
| 2243 BmTmpConfig++; | 2305 BmTmpConfig++; |
| 2244 break; | 2306 break; |
| 2245 case BM_INIT_TRIGGER_OFF: HAL_Delay(1); | 2307 case BM_INIT_TRIGGER_OFF: HAL_Delay(1); |
| 2253 break; | 2315 break; |
| 2254 case BM_INIT_MODE: sprintf(TxBuffer,"AT+UMSM=1\r"); /* start in Data mode */ | 2316 case BM_INIT_MODE: sprintf(TxBuffer,"AT+UMSM=1\r"); /* start in Data mode */ |
| 2255 break; | 2317 break; |
| 2256 case BM_INIT_BLE: sprintf(TxBuffer,"AT+UBTLE=2\r"); /* Bluetooth low energy Peripheral */ | 2318 case BM_INIT_BLE: sprintf(TxBuffer,"AT+UBTLE=2\r"); /* Bluetooth low energy Peripheral */ |
| 2257 break; | 2319 break; |
| 2258 case BM_INIT_NAME: sprintf(TxBuffer,"AT+UBTLN=OSTC4-12345\r"); /* Bluetooth name */ | 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 } | |
| 2259 break; | 2325 break; |
| 2260 case BM_INIT_SSP_IDO_OFF: sprintf(TxBuffer,"AT+UDSC=0,0\r"); /* Disable SPP Server on ID0 */ | 2326 case BM_INIT_SSP_IDO_OFF: sprintf(TxBuffer,"AT+UDSC=0,0\r"); /* Disable SPP Server on ID0 */ |
| 2261 break; | 2327 break; |
| 2262 case BM_INIT_SSP_IDO_ON: sprintf(TxBuffer,"AT+UDSC=0,3\r"); /* SPP Server on ID0 */ | 2328 case BM_INIT_SSP_IDO_ON: sprintf(TxBuffer,"AT+UDSC=0,3\r"); /* SPP Server on ID0 */ |
| 2263 break; | 2329 break; |
| 2289 UartHandle.Init.BaudRate = 460800; | 2355 UartHandle.Init.BaudRate = 460800; |
| 2290 HAL_UART_Init(&UartHandle); | 2356 HAL_UART_Init(&UartHandle); |
| 2291 } | 2357 } |
| 2292 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 */ | 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 */ |
| 2293 { | 2359 { |
| 2294 #ifndef BOOTLOADER_STANDALONE | 2360 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_115, TxBuffer); |
| 2295 sprintf(TxBuffer,"AT%%B8\r"); /* set default baudrate */ | 2361 |
| 2296 #else | |
| 2297 sprintf(TxBuffer,"AT+UMRS=115200,1,8,1,1,1\r"); | |
| 2298 #endif | |
| 2299 CmdSize = strlen(TxBuffer); | 2362 CmdSize = strlen(TxBuffer); |
| 2300 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | 2363 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); |
| 2301 HAL_UART_DeInit(&UartHandle); | 2364 HAL_UART_DeInit(&UartHandle); |
| 2302 HAL_Delay(10); | 2365 HAL_Delay(10); |
| 2303 UartHandle.Init.BaudRate = 115200; | 2366 UartHandle.Init.BaudRate = 115200; |
| 2320 ConfigRetryCnt = 0; | 2383 ConfigRetryCnt = 0; |
| 2321 RestartModule = 1; | 2384 RestartModule = 1; |
| 2322 } | 2385 } |
| 2323 } | 2386 } |
| 2324 } | 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++; | |
| 2393 } | |
| 2394 } | |
| 2325 if(result != HAL_OK) | 2395 if(result != HAL_OK) |
| 2326 { | 2396 { |
| 2327 ConfigRetryCnt++; | 2397 ConfigRetryCnt++; |
| 2328 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ | 2398 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ |
| 2329 { | 2399 { |
| 2331 if(RestartModule) | 2401 if(RestartModule) |
| 2332 { | 2402 { |
| 2333 RestartModule = 0; /* only one try */ | 2403 RestartModule = 0; /* only one try */ |
| 2334 ConfigRetryCnt = 200; /* used for delay to startup module again */ | 2404 ConfigRetryCnt = 200; /* used for delay to startup module again */ |
| 2335 | 2405 |
| 2336 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 */ |
| 2337 { | 2407 { |
| 2338 HAL_UART_DeInit(&UartHandle); | 2408 HAL_UART_DeInit(&UartHandle); |
| 2339 HAL_Delay(1); | 2409 HAL_Delay(1); |
| 2340 UartHandle.Init.BaudRate = 460800; | 2410 UartHandle.Init.BaudRate = 460800; |
| 2341 HAL_UART_Init(&UartHandle); | 2411 HAL_UART_Init(&UartHandle); |
