Skip to content

Fix Setting of the BLE Name.#57

Open
mikeller wants to merge 62 commits intodevelopmentfrom
fix_ble_name
Open

Fix Setting of the BLE Name.#57
mikeller wants to merge 62 commits intodevelopmentfrom
fix_ble_name

Conversation

@mikeller
Copy link
Copy Markdown
Owner

@mikeller mikeller commented Feb 16, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Corrected "bluetooth disconnected" typo in UI text.
  • Improvements

    • Broader detection of uninitialized/corrupted Bluetooth name during init.
    • Clarified Bluetooth status messaging ("bt init", "bt ready", "bt reset") and appended version display.
    • Streamlined loader UI text and button labels (e.g., "load extra data", "reboot"/"BT Reset").
    • Simplified device initialization flow to use reset-driven restart and UART cleanup instead of power cycling.
  • Documentation

    • Manufacturing data display now shows Bluetooth name set values for primary and secondary records.

Copilot AI review requested due to automatic review settings February 16, 2026 09:11
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

Refactors bootloader Bluetooth initialization to treat 0xFF and 0xF0 as uninitialized/corrupted, updates UI labels/messages, consolidates button handling into switch-case logic, changes OSTC4 init from power-cycling to AT+RESET with UART drain, and exposes Bluetooth name-set flags in manufacturing-data tooling.

Changes

Cohort / File(s) Summary
Bootloader Bluetooth & UI
BootLoader/Src/base_bootlader.c
Treat production_bluetooth_name_set values 0xFF or 0xF0 as uninitialized/corrupted; update status messages to "bt init"/"bt ready"/"bt reset"; change UI labels ("load extra data", "reboot", "BT Reset"); write textVersion after BT handling; fix "bluetooth disconnected" spelling.
Button/EXTI Handling
BootLoader/Src/base_bootlader.c
Replace nested if/else with switch-case for BaseComm and non-BaseComm EXTI callbacks; explicit cases for ACTION_BUTTON_BACK/ENTER/NEXT (and CUSTOM); consolidate sleep and button behavior with clearer control flow/gotoSleep path.
OSTC4 Module Init Flow
BootLoader/Src/tComm_mini.c
Change OSTC4 BM_INIT_RESTART to perform AT+RESET and advance to BM_INIT_DONE; replace power-cycle reinit with 3s delay, RTS assert, drain of boot UART text, then continue with normal config (ATE0, etc.).
Manufacturing Data Tooling
Documentations/set_manufacturing_data.py
Read and display production_bluetooth_name_set (data[7]) and secondary_bluetooth_name_set (data[59]) with hex output; no interface changes.

Sequence Diagram(s)

sequenceDiagram
    participant BL as Bootloader
    participant BT as Bluetooth Module
    participant UI as Display/UI
    participant TInfo as tInfo_write
    
    BL->>UI: show "bt init"
    BL->>BT: check name flag (data[...] == 0xFF/0xF0?)
    alt name flag uninitialized/corrupt
        BL->>BT: perform init sequence (reset/config)
        BT-->>BL: responds (boot text)
        BL->>BT: drain UART boot text
    else name valid
        BL->>BT: normal init/config
    end
    BL->>TInfo: tInfo_write(textVersion)
    BL->>UI: show "bt ready" / updated status
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 A rabbit nibbles bits of code,
Sees 0xFF and 0xF0 on the road.
AT+RESET hums a gentle tune,
UART drains beneath the moon.
Buttons click — reboot, hop, and go!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix Setting of the BLE Name' directly and concisely describes the main objective of the changeset, which involves updating Bluetooth name handling logic, initialization flow, and related messaging across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_ble_name

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Artifacts:
OSTC4_update-1.7.6-beta-57-fix-ble-name-10cfa18
WARNING: Use at your own risk.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to ensure the BLE module picks up a newly saved Bluetooth name by adjusting the bootloader’s Bluetooth init/config flow and by exposing the “Bluetooth name set” flags in manufacturing-data tooling.

Changes:

  • Bootloader: issue a software reset (AT+RESET) for the Stollmann module after saving config so advertising reflects the stored name.
  • Bootloader UI/flow: tweak BT init/config prompts and button actions; update boot decision logic tied to production_bluetooth_name_set.
  • Manufacturing data script: parse and display the primary/secondary “Bluetooth name set” bytes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
Documentations/set_manufacturing_data.py Reads and prints manufacturing-data bytes for BT name-set flags.
BootLoader/Src/tComm_mini.c Adds Stollmann AT+RESET step and adjusts post-reset handling.
BootLoader/Src/base_bootlader.c Updates BT init/config decision logic and bootloader UI/button handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +450 to +451
|| (HardwareData->production_bluetooth_name_set == 0xFF)
|| (HardwareData->production_bluetooth_name_set == 0xF0))
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new checks treat production_bluetooth_name_set == 0xF0 as a condition to stay in the bootloader / force BT init. But elsewhere in the codebase 0xF0 is explicitly written by hardware_programmPrimaryBluetoothNameSet() to mark the Bluetooth name as programmed (0xFF is the uninitialized value). With this change, devices that have already been initialized (flag == 0xF0) will repeatedly enter the bootloader instead of jumping to the application.

Suggested change
|| (HardwareData->production_bluetooth_name_set == 0xFF)
|| (HardwareData->production_bluetooth_name_set == 0xF0))
|| (HardwareData->production_bluetooth_name_set == 0xFF))

Copilot uses AI. Check for mistakes.
Comment on lines +691 to +695
* 0xFF = uninitialized, 0xF0 = corrupted/partial initialization (e.g., device 428)
* Anything other than these values = fully initialized (0x00, etc.)
*/
if((hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF) ||
(hardwareDataGetPointer()->production_bluetooth_name_set == 0xF0))
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic/comment redefines 0xF0 as "corrupted/partial initialization", but 0xF0 is the value written by hardware_programmPrimaryBluetoothNameSet() when BT name programming succeeds. Unless the flag-writing logic is also changed, this will cause perpetual "bt init" on every boot for already-configured devices. Consider keeping 0xFF as the only uninitialized value here (or change the writer to a different 'done' sentinel and update all readers consistently).

Suggested change
* 0xFF = uninitialized, 0xF0 = corrupted/partial initialization (e.g., device 428)
* Anything other than these values = fully initialized (0x00, etc.)
*/
if((hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF) ||
(hardwareDataGetPointer()->production_bluetooth_name_set == 0xF0))
* 0xFF = uninitialized (flash default, BT name not programmed yet)
* Any other value (including 0xF0 written by hardware_programmPrimaryBluetoothNameSet)
* = initialized.
*/
if(hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF)

Copilot uses AI. Check for mistakes.
Comment on lines +2262 to +2267
sprintf(TxBuffer,"AT+RESET\r");
HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer, strlen(TxBuffer), 500);
TxBuffer[0] = 0; /* Don't re-send in the normal path below */
BmTmpConfig = BM_INIT_DONE;
return result;
}
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BM_INIT_RESTART sends AT+RESET but ignores the return status of HAL_UART_Transmit, then forces BmTmpConfig forward. If the transmit fails/busy, the state machine will still proceed as if the module rebooted. Capture the HAL_UART_Transmit return value into result and handle failures consistently with the rest of the config flow (e.g., retry or fall back to BM_CONFIG_RETRY).

Copilot uses AI. Check for mistakes.
* Send the command directly and advance to BM_INIT_DONE. */
sprintf(TxBuffer,"AT+RESET\r");
HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer, strlen(TxBuffer), 500);
TxBuffer[0] = 0; /* Don't re-send in the normal path below */
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In BM_INIT_RESTART, TxBuffer[0] is set to 0 with a comment about avoiding re-send in the normal path, but this case returns immediately afterward, so that assignment/comment are currently ineffective. Either remove the dead assignment/comment or avoid the early return and rely on TxBuffer[0]==0 to skip the common transmit path.

Suggested change
TxBuffer[0] = 0; /* Don't re-send in the normal path below */

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@BootLoader/Src/tComm_mini.c`:
- Around line 2258-2267: In the BM_INIT_RESTART case, check the return value of
HAL_UART_Transmit when sending TxBuffer ("AT+RESET\r"); if the call returns
anything other than HAL_OK, do not advance BmTmpConfig to BM_INIT_DONE and
return that error result to the caller (preserve or clear TxBuffer as
appropriate), otherwise on HAL_OK proceed to set TxBuffer[0]=0, set
BmTmpConfig=BM_INIT_DONE and return result; reference the BM_INIT_RESTART case,
HAL_UART_Transmit call, TxBuffer, BmTmpConfig and BM_INIT_DONE when making the
change.
🧹 Nitpick comments (2)
BootLoader/Src/base_bootlader.c (2)

694-695: Use the existing local HardwareData pointer for consistency.

Lines 450–451 already access HardwareData->production_bluetooth_name_set via the local const SHardwareData* HardwareData declared at line 426. Here, hardwareDataGetPointer() is called again instead. Both resolve to the same address, but using the local variable is more consistent and avoids a redundant function call.

♻️ Suggested diff
-	if((hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF) ||
-	   (hardwareDataGetPointer()->production_bluetooth_name_set == 0xF0))
+	if((HardwareData->production_bluetooth_name_set == 0xFF) ||
+	   (HardwareData->production_bluetooth_name_set == 0xF0))

848-868: Near-duplicate switch blocks — consider extracting shared logic.

The BaseComm (lines 830–846) and non-BaseComm (lines 850–867) switch blocks are nearly identical. The only difference is the get_globalState() == StS guard on gotoSleep(). A small helper or a single switch with the conditional sleep check would reduce duplication, but given the embedded context and readability of the current structure, this is a minor nit.

♻️ One way to consolidate
-	if(status.base == BaseComm)
-	{
-		switch (action)
-		{
-			case ACTION_BUTTON_BACK:
-				reset_to_firmware_using_Watchdog();
-				break;
-			case ACTION_BUTTON_ENTER:
-				tComm_StartBlueModBaseInit(); /* factory reset bluetooth */
-				break;
-			case ACTION_BUTTON_NEXT: /* right button: sleep */
-#ifdef BUTTON_CUSTOM_PIN
-			case ACTION_BUTTON_CUSTOM:
-#endif
-				gotoSleep();
-				break;
-			default:
-				break;
-		}
-	}
-	else
-	{
-		switch (action)
-		{
-			case ACTION_BUTTON_BACK:
-				reset_to_firmware_using_Watchdog();
-				break;
-			case ACTION_BUTTON_ENTER:
-				tComm_StartBlueModBaseInit(); /* factory reset bluetooth */
-				break;
-			case ACTION_BUTTON_NEXT: /* right button: sleep */
-#ifdef BUTTON_CUSTOM_PIN
-			case ACTION_BUTTON_CUSTOM:
-#endif
-				if(get_globalState() == StS)
-					gotoSleep();
-				break;
-			default:
-				break;
-		}
-	}
+	switch (action)
+	{
+		case ACTION_BUTTON_BACK:
+			reset_to_firmware_using_Watchdog();
+			break;
+		case ACTION_BUTTON_ENTER:
+			tComm_StartBlueModBaseInit(); /* factory reset bluetooth */
+			break;
+		case ACTION_BUTTON_NEXT: /* right button: sleep */
+#ifdef BUTTON_CUSTOM_PIN
+		case ACTION_BUTTON_CUSTOM:
+#endif
+			if(status.base == BaseComm || get_globalState() == StS)
+				gotoSleep();
+			break;
+		default:
+			break;
+	}

Comment on lines +2258 to +2267
case BM_INIT_RESTART: {
/* Stollmann: Software reboot so BLE advertising picks up saved name.
* The module reboots immediately — no OK response expected.
* Send the command directly and advance to BM_INIT_DONE. */
sprintf(TxBuffer,"AT+RESET\r");
HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer, strlen(TxBuffer), 500);
TxBuffer[0] = 0; /* Don't re-send in the normal path below */
BmTmpConfig = BM_INIT_DONE;
return result;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

HAL_UART_Transmit return value is unchecked on Line 2263.

If the transmit fails, BmTmpConfig is still advanced to BM_INIT_DONE and result (still HAL_OK) is returned, so the caller never sees the failure. The subsequent BM_INIT_DONE handler will wait 3 s and try to configure a module that was never actually reset.

The existing retry/fallback logic further down should eventually recover, so this isn't critical, but explicitly handling the error would be more robust.

Suggested fix
 			case BM_INIT_RESTART:		{
 										/* Stollmann: Software reboot so BLE advertising picks up saved name.
 										 * The module reboots immediately — no OK response expected.
 										 * Send the command directly and advance to BM_INIT_DONE. */
 										sprintf(TxBuffer,"AT+RESET\r");
-										HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer, strlen(TxBuffer), 500);
+										result = HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer, strlen(TxBuffer), 500);
 										TxBuffer[0] = 0;		/* Don't re-send in the normal path below */
-										BmTmpConfig = BM_INIT_DONE;
+										if (result == HAL_OK)
+										{
+											BmTmpConfig = BM_INIT_DONE;
+										}
 										return result;
 									}
🤖 Prompt for AI Agents
In `@BootLoader/Src/tComm_mini.c` around lines 2258 - 2267, In the BM_INIT_RESTART
case, check the return value of HAL_UART_Transmit when sending TxBuffer
("AT+RESET\r"); if the call returns anything other than HAL_OK, do not advance
BmTmpConfig to BM_INIT_DONE and return that error result to the caller (preserve
or clear TxBuffer as appropriate), otherwise on HAL_OK proceed to set
TxBuffer[0]=0, set BmTmpConfig=BM_INIT_DONE and return result; reference the
BM_INIT_RESTART case, HAL_UART_Transmit call, TxBuffer, BmTmpConfig and
BM_INIT_DONE when making the change.

mikeller and others added 24 commits February 18, 2026 02:50
Made release build build cleanly.

Updated build setup.

Switched to using the original project files.

Undo fix for linker script.

Updated build configuration.

Re-added printing of memory usage.

Fixed warnings.
Fix building of firmware that does not contain all parts of (firmware, fonts, RTE).

Added the option to only build parts to the un*x build script.

Added external builder for Firmware and RTE.

Fix RTE packaging.

Added builder for fonts, updated packaging script to build Release (required for fonts).

Added builders for packaging.
Improve CICD.

Add artifact links.

Fix tooling caching.

Add releases.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

Artifacts:
OSTC4_update-1.7.6-beta-57-fix-ble-name-6604e9b
WARNING: Use at your own risk.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
BootLoader/Src/base_bootlader.c (2)

564-564: Nit: Label updated from "load fontpack data" to "load extra data".

Slightly more generic. Fine if the upper firmware region can contain non-font data; otherwise "load extra data" could be confusing to someone debugging the boot sequence.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@BootLoader/Src/base_bootlader.c` at line 564, The log string passed to
tInfo_newpage was changed to the generic "load extra data" which may be
misleading if the upper firmware region only contains a font pack; either revert
it to the original "load fontpack data" or make the message more specific (e.g.,
"load fontpack / extra data" or "load upper-region extra data (fontpack)") so
the boot sequence remains clear when debugging; update the argument to
tInfo_newpage accordingly.

687-713: Address inconsistency in Bluetooth initialization status checking.

The "bt init" / "bt ready" messages with module type annotations and the textVersion output are good improvements for diagnostics.

However, there is a design inconsistency worth addressing: The bootloader code (lines 450-451, 687-713) treats both 0xFF and 0xF0 as requiring Bluetooth initialization, but tComm_Set_Bluetooth_Name() in tComm_mini.c (lines 567, 575) only checks for 0xFF:

if(force || (hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF))

This means if tComm_Set_Bluetooth_Name(0) is ever called when the status is 0xF0, name programming would be skipped, despite 0xF0 being documented as "corrupted/partial initialization (e.g., device 428)". The bootloader doesn't currently call this function with force=0, but the inconsistency is fragile. Consider updating the condition to also check 0xF0, or explicitly document why only 0xFF requires name re-programming.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@BootLoader/Src/base_bootlader.c` around lines 687 - 713, The bootloader
treats production_bluetooth_name_set == 0xF0 as needing re-initialization but
tComm_Set_Bluetooth_Name(...) only checks for 0xFF, creating a fragile
inconsistency; update the logic in tComm_Set_Bluetooth_Name (in tComm_mini.c) to
treat 0xF0 the same as 0xFF (e.g., change the conditional that currently reads
production_bluetooth_name_set == 0xFF to also include == 0xF0), or alternatively
add/propagate a force parameter usage to callers like the bootloader so
corrupted states are always reprogrammed—ensure the change aligns with the
bootloader checks around production_bluetooth_name_set and keep
tComm_StartBlueModBaseInit/StartBlueModConfig flows consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@BootLoader/Src/tComm_mini.c`:
- Around line 2258-2267: The HAL_UART_Transmit call in the BM_INIT_RESTART
branch must have its return value checked so we don't advance BmTmpConfig to
BM_INIT_DONE when the transmit fails; after calling
HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer, strlen(TxBuffer), 500) check
the HAL_StatusTypeDef (or int) result, and on failure do not clear TxBuffer[0]
or set BmTmpConfig = BM_INIT_DONE — instead restore/keep BM_INIT_RESTART, log or
set an error status, and return an error/result indicating the transmit failed
so the reset command can be retried; ensure the success path still clears
TxBuffer[0], sets BmTmpConfig = BM_INIT_DONE and returns result.

---

Nitpick comments:
In `@BootLoader/Src/base_bootlader.c`:
- Line 564: The log string passed to tInfo_newpage was changed to the generic
"load extra data" which may be misleading if the upper firmware region only
contains a font pack; either revert it to the original "load fontpack data" or
make the message more specific (e.g., "load fontpack / extra data" or "load
upper-region extra data (fontpack)") so the boot sequence remains clear when
debugging; update the argument to tInfo_newpage accordingly.
- Around line 687-713: The bootloader treats production_bluetooth_name_set ==
0xF0 as needing re-initialization but tComm_Set_Bluetooth_Name(...) only checks
for 0xFF, creating a fragile inconsistency; update the logic in
tComm_Set_Bluetooth_Name (in tComm_mini.c) to treat 0xF0 the same as 0xFF (e.g.,
change the conditional that currently reads production_bluetooth_name_set ==
0xFF to also include == 0xF0), or alternatively add/propagate a force parameter
usage to callers like the bootloader so corrupted states are always
reprogrammed—ensure the change aligns with the bootloader checks around
production_bluetooth_name_set and keep
tComm_StartBlueModBaseInit/StartBlueModConfig flows consistent.

@mikeller mikeller force-pushed the development branch 2 times, most recently from 198eea4 to fa70217 Compare February 23, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants