pico_multicore breaks BTstack TLV persistence #2725
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#2725
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I think I’ve found a reproducible combination that breaks TLV persistence in BTstack on RP2040 when using pico-sdk 2.2.0.
This can make developers struggle to locate the root cause, so I’m documenting it here.
The key point: just linking
pico_multicoreis enough to break TLV persistence, even if no multicore functions are called.How to reproduce
In
CMakeLists.txt:To ensure the TLV does not overlap with other flash sections (only
BT_TLVmatters here):I’m using the Bluepad32 library, but the issue is reproducible using the BTstack included in pico-sdk.
Observed behavior
With this setup, any BTstack API call that must persist data in the TLV fails silently.
Nothing is stored.
A clear symptom: link keys are not persisted after pairing a Bluetooth keyboard/mouse, so the device cannot reconnect after a power cycle.
Key findings
pico_multicore, TLV persistence works as expected.pico_multicorebut also launch code on Core 1 usingmulticore_launch_core1(), TLV persistence also works.So the failure only occurs in the specific situation where:
This suggests initialization side effects in
pico_multicorethat interfere with flash operations BTstack depends on.My project (still WIP): https://github.com/sidecartridge/rp2-atarist-rpikb
Hope this helps identify the root cause, or at least warns other developers about this combination.
What's VLT? pico_btstack uses flash_safe_execute. There's some advice in the SDK about using pico_multicore. You might need to set PICO_FLASH_ASSUME_CORE0_SAFE=1
See https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_flash/include/pico/flash.h#L12
Sorry, TLV (fixed): https://bluekitchen-gmbh.com/storing-link-keys-in-flash-memory/
I use the PICO_FLASH_ASSUME_COREx_SAFE in my code for Core 1, and I previously tested the following combinations (I chased the issue for a while):
The problem comes from just linking the library. PICO_FLASH_ASSUME_COREx_SAFE does not affect the outcome in this case.
Thanks. Did you try setting PICO_FLASH_SAFE_EXECUTE_PICO_SUPPORT_MULTICORE_LOCKOUT to zero?
Yes. No luck.
I can confirm this issue. On debug build I get
assertion "false" failed: file ".../pico-sdk/src/rp2_common/pico_flash/flash.c", line 190, function: default_enter_safe_zone_timeout_msusing multicore (It works fine without it). On release build, it fails to store device using TLV persistence using multicore too.I came across this issue too.
Linking pico_multicore but not calling multicore_launch_core1() before starting BTstack code resulted in authentication errors when trying to connect over bluetooth to the pico w.
Starting core1 with some dummy code before running BTstack code and connecting over bluetooth works fine.
Thanks diegoparrilla for pointing me in the right direction.
This is quite extensively discussed here https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_flash/include/pico/flash.h#L17
Maybe we need to add a note pico_btstack to take notice of this when using freertos?
You can set PICO_FLASH_ASSUME_CORE1_SAFE=1 if nothing is running on core 1. Otherwise, it's more complicated...
I don't understand how you could hit the assert mentioned above if the correct PICO_FLASH_ASSUME_COREx_SAFE is 1, as it should never go down that code path. I just want to double check that regardless of everything else
I had the same experience as @Loc15, same assertion failed. I'm using FreeRTOS and btstack on SDK 2.2.0 but for me the workarounds don't work. On debug build it gives
assertion "false" failed: file ".../Apps/pico/old-sdk/pico-sdk/src/rp2_common/pico_flash/flash.c", line 179, function: default_enter_safe_zone_timeout_msand on release it just silently fails. With the new SDK, the 2.3.0 version, and the same code, it works fine but I cannot authenticate correctly with my phone or other device and the keys are the same through the flashing of old and new firmware because the TLV memory section is not touched. As I mentioned in #3106.I'm going to assume this is fixed by https://github.com/raspberrypi/pico-sdk/pull/3019
i.e. you will not see an assert in 2.3.0. There are other unrelated issues covered in https://github.com/raspberrypi/pico-sdk/issues/3106
I will add some logging if flash_safe_execute fails so it's a bit more obvious, and add a test for this.