Skip to content

Conversation

@laurensvalk
Copy link
Member

This the follow up to #445 to enable more peripherals. This is only done for BTstack.

I think we can keep Technic/City/Move hub at one peripheral given their limitations.

The first commits are basically just replacing the peripheral_singleton with a pointer to an instance. The logic to make this possible was already done in #445.

Perhaps the more interesting part for reviewing in this PR is this:

 #define HCI_ACL_PAYLOAD_SIZE (1691 + 4)
 #define MAX_ATT_DB_SIZE 512
 #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES  0
-#define MAX_NR_GATT_CLIENTS 1
-#define MAX_NR_HCI_CONNECTIONS 2 // CC2564C can have up to 10 connections
+#define MAX_NR_GATT_CLIENTS 2
+#define MAX_NR_HCI_CONNECTIONS 3 // CC2564C can have up to 10 connections
 #define MAX_NR_HFP_CONNECTIONS 0
 #define MAX_NR_L2CAP_CHANNELS  0
 #define MAX_NR_L2CAP_SERVICES  0
@@ -30,9 +30,9 @@
 #define MAX_NR_RFCOMM_MULTIPLEXERS 0
 #define MAX_NR_RFCOMM_SERVICES 0
 #define MAX_NR_SERVICE_RECORD_ITEMS 0
-#define MAX_NR_SM_LOOKUP_ENTRIES 0
+#define MAX_NR_SM_LOOKUP_ENTRIES 3
 #define MAX_NR_WHITELIST_ENTRIES 0
-#define MAX_NR_LE_DEVICE_DB_ENTRIES 1
+#define MAX_NR_LE_DEVICE_DB_ENTRIES 3

We are deleting the bonds every time so it's probably not necessary to have the lookup entries, but this isn't too expensive.

Bumping the HCI connections and GATT clients does need a fair bit of RAM, so this also does this:

diff --git a/lib/pbio/platform/prime_hub/platform.ld b/lib/pbio/platform/prime_hub/platform.ld
index ba433b5b2..3fb07d7aa 100644
--- a/lib/pbio/platform/prime_hub/platform.ld
+++ b/lib/pbio/platform/prime_hub/platform.ld
@@ -19,4 +19,4 @@ MEMORY
 
 /* Minimal stack size to allow the build to proceed. The actual stack size is whatever is left after
    statically allocated memory. It can be tuned by setting PBDRV_CONFIG_BLOCK_DEVICE_RAM_SIZE. */
-_minimal_stack_size = 16K;
+_minimal_stack_size = 12K;

14K works fine too. I picked 12K because we have that on Essential Hub too and it should still be far more than necessary. This should give us some room for static memory in future developments. (We could also reduce heap instead. We did increase it recently after all to have some heap left even if all slots are full.)

The Virtual Hub as an actual Bluetooth implementation now, and we can use the USB mock for stdio, so we can drop this one.
@laurensvalk laurensvalk changed the title Peripheral Support two peripherals on F4 hubs Jan 8, 2026
Start getting rid of the singleton instance so we
can eventually support more than one.
This completes the recent overhaul to clean up references to peripheral singletons.

We keep supporting only one on Move Hub, City Hub, and Technic Hub due to hardware limitations with their Bluetooth chips.
@coveralls
Copy link

Coverage Status

coverage: 50.339% (-0.07%) from 50.406%
when pulling 076ca37 on peripheral
into 136126d on btstack-scan-connect-bond.

@laurensvalk
Copy link
Member Author

Merged into 076ca37 without changes, but GitHub won't register it due to the different base branch.

@laurensvalk laurensvalk closed this Jan 9, 2026
@laurensvalk laurensvalk deleted the peripheral branch January 9, 2026 19:23
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.

3 participants