Pico W flash bank large values

26 views
Skip to first unread message

Stéphane Lenclud

unread,
Feb 1, 2025, 8:57:42 AMFeb 1
to btstack-dev
Hi,

Can I store values larger than a flash sector (4K) on Pico W using the tlv flash bank?

Cheers,
S.

Matthias Ringwald

unread,
Feb 3, 2025, 2:46:35 AMFeb 3
to btsta...@googlegroups.com
Hi Stéphane

BTstack APIs allows for larger buffers. I don't know if there are any limits in the Pico SDK implementtation.
Please have a look at the TLV implementation in Pico SDK to see which Pico SDK lib it is using and if that has any limits and let us knkow.

In general, if you use TLV to store the HID descriptors, I would suggest to store them individually together with any meta data you might have per device.
By this, each item will be much smaller.

Best
Matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/btstack-dev/688124ad-6724-4bec-bc6c-1a87e8f14911n%40googlegroups.com.

Stéphane Lenclud

unread,
Feb 3, 2025, 3:05:59 PMFeb 3
to btstack-dev
So far I used pico-vfs to store the devices configurations including HID report descriptors.
However I now realize I could just have used btstack's TLV instead.
You are correct I most certainly never need to store one chunk of more than 4K so even if the Pico SDK has such a limitation it should not be a problem anyway.
I think I will attempt to switch to TLV sooner or later. Removing the dependency on pico-vfs will make my life easier when it comes to switching branches of SDK or other sub-modules.


Stéphane Lenclud

unread,
Feb 11, 2025, 12:14:39 PMFeb 11
to btstack-dev
For the record I believe this is the pico SDK btstack flash bank implementation:

That pico_flash_bank_write function has a for loop capable of writing n pages but I'm still not sure how they handle sectors.
I also have very limited understanding of the btstack flash bank interface itself.
Is there only always two of them banks? I ought to read some more about it really.

Stéphane Lenclud

unread,
Feb 11, 2025, 12:44:23 PMFeb 11
to btstack-dev
How do I make sure the tags used by the application do not overlap with the tags used by btstack itself?

Matthias Ringwald

unread,
Feb 12, 2025, 12:45:54 PMFeb 12
to btsta...@googlegroups.com
Hi Stéphane

BTstack's TLV implementation is documented in our blog: https://bluekitchen-gmbh.com/storing-link-keys-in-flash-memory/

Good point about the potential overlap between application and BTstack's use of TLV.
I have added a @TLV tag to the header files for implementations that use TLV and added the script tool/list_tlv.py to list currently used tags on the develop branch.

Cheers
Matthias
> To view this discussion visit https://groups.google.com/d/msgid/btstack-dev/e26ecbaa-ae16-4bb3-b305-1b6d1c00026dn%40googlegroups.com.


Stéphane Lenclud

unread,
Feb 12, 2025, 2:23:20 PMFeb 12
to btstack-dev
Would it make sense to define a range of tags used internally by btstack and the rest is for the app?

Something like:

#define BTSTACK_MIN_APP_TLV_TAG 0x10000000

Everything below is for btstack internally the rest is for the app.

Matthias Ringwald

unread,
Feb 24, 2025, 5:10:23 AMFeb 24
to btsta...@googlegroups.com
Hi Stéphane

As you might have seen, BTstack uses 'FourCC' style tags from letters. We could reserve all tags starting with 'z" and above to the users. Or you could start all from 0x80000000

Cheers
Matthias
> To view this discussion visit https://groups.google.com/d/msgid/btstack-dev/6582ec5a-c71b-40e1-bf33-74ff55a41d0cn%40googlegroups.com.

Stéphane Lenclud

unread,
Feb 24, 2025, 12:00:44 PMFeb 24
to btstack-dev
Here is how I did it so far:
#define DEVICE_KEY(a) ((((uint32_t) 'A') << 24 ) | (((uint32_t) 'P') << 16) | (((uint32_t) 'D') << 8) | a)
#define SETTINGS_KEY ((((uint32_t) 'A') << 24 ) | (((uint32_t) 'P') << 16) | (((uint32_t) 'S') << 8) | 'E')

One key/tag to store the settings and one key per device for up to 256 devices which is way more than enough.

Stéphane Lenclud

unread,
Feb 24, 2025, 12:02:34 PMFeb 24
to btstack-dev
Is there a way to tell how much memory we already use from our store and how much is left?

Matthias Ringwald

unread,
Feb 25, 2025, 3:27:30 AMFeb 25
to btsta...@googlegroups.com
Hi Stéphane

The TLV Design only allows to store / retrieve values - and assumes that there's sufficient space. It was intended mainly for bonding information.

Depending on the implementation, you might be able to get those values. For the Flash Bank version, there's a current writing pointer, which indicates how much of that bank has been used.
How much of that is "live", i.e. not deleted, it's a different story. For others, you need to check them directly.

Cheers
Matthias
> To view this discussion visit https://groups.google.com/d/msgid/btstack-dev/8455d2e4-a2ea-4466-bed4-8ad1f5685668n%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages