--- tags: [entity] type: entity topic: stm32-lower note: 16 created: 2026-07-16 updated: 2026-07-16 --- # Note 16: BLE (lower/stm32/12) ## Projects | # | Directory | Description | |---|---|---| | 12 | `12_ble_server_hal` | BLE Server (ESP32-C3) | ## Code Accuracy Audit ### Path Audit | Claimed Path | Actual Path | Status | |---|---|---| | `stm32/12_ble_server_hal/Core/Src/main.c` | `12_ble_server_hal/Core/Src/main.c` | ✅ Correct | | `stm32/12_ble_server_hal/App/BLE/ble.h` | `12_ble_server_hal/App/BLE/ble.h` | ✅ Correct | | `stm32/12_ble_server_hal/App/BLE/ble.c` | `12_ble_server_hal/App/BLE/ble.c` | ✅ Correct | ### BLE Init Sequence (ble.c) Note claims exact AT command sequence: | AT Command | Actual Code Line | Match? | |---|---|---| | `AT+BLEINIT=2\r\n` | Line 18 | ✅ Match | | `AT+BLEGATTSSRVCRE\r\n` | Line 23 | ✅ Match | | `AT+BLEGATTSSRVSTART\r\n` | Line 28 | ✅ Match | | `AT+BLEADDR?\r\n` | Line 33 | ✅ Match | | `AT+BLEADVPARAM=50,50,0,0,7,0\r\n` | Line 38 | ✅ Match | | `AT+BLEADVDATAEX=\"atguigu-ble\",\"A123\",\"0102030405\",1\r\n` | Line 43 | ✅ Match | | `AT+BLEADVSTART\r\n` | Line 48 | ✅ Match | | `AT+BLESPPCFG=1,1,7,1,5\r\n` | Line 53 | ✅ Match | | `AT+SYSMSG=4\r\n` | Line 58 | ✅ Match | ### BLE Data Functions | Claimed by Note | Actual Code | Match? | |---|---|---| | `BLE_SendData`: `HAL_UART_Transmit(&huart2, txBuff, txLen, 1000)` | Line 66 | ✅ Match | | `BLE_ReadData`: `HAL_UARTEx_ReceiveToIdle(&huart2, rxBuff, 1024, rxLen, 1000)` | Line 76 | ✅ Match | | If `*rxLen == 0` return immediately | Lines 79-82 | ✅ Match | | Call `BLE_IsConnChanged(rxBuff)`; if true, set `*rxLen = 0` | Lines 85-88 | ✅ Match | ### Connection Detection (BLE_IsConnChanged) | Claimed by Note | Actual Code | Match? | |---|---|---| | `strstr((char *)msg, "+BLECONN:") != NULL` → send `AT+BLESPP\r\n` | Lines 94-98 | ✅ Match | | `strstr((char *)msg, "+BLEDISCONN:") != NULL` → send `+++` and delay 2000ms | Lines 104-109, 112 | ✅ Match | | `strstr(... "WIFI CONNECTED" ...)` → return 1 | Line 118 | ✅ Match | | `strstr(... "WIFI GOT IP" ...)` → return 1 | Line 119 | ✅ Match | | `strstr(... "+DIST_STA_IP:" ...)` → return 1 | Line 120 | ✅ Match | ### BLE main.c Note does not detail main.c, but actual code shows: - `BLE_Init()` called once - Infinite loop: `BLE_ReadData()`, if data received, `BLE_SendData()` to echo back - Standard echo server pattern ## Summary **Overall Accuracy**: Excellent (99%+) **Issues Found**: None significant. All AT commands, data functions, and connection detection logic match the actual source code perfectly. This is the most accurate note among the 8 reviewed.