Skip to content

Conversation

@peterharperuk
Copy link
Contributor

Bluetooth needs a tempoarary buffer to load firmware. Micropython won't work safely with malloc and free so allow these calls to be changed by using cyw43_alloc / free macros.

@peterharperuk
Copy link
Contributor Author

This MP change prevents us using malloc and free micropython/micropython@c80e7c1

@kilograham kilograham changed the title Allow malloc and free to be changed. Use cyw43_malloc/free macro instead of malloc/free to allow alternative implementations Mar 13, 2023
@dpgeorge
Copy link
Contributor

This MP change prevents us using malloc and free

Oh yes! Before making that change I did check to see if pico-sdk used malloc/free at all and came to the conclusion that it was not needed (I looked through the firmware.elf file of MicroPython). But I did not check with BT enabled...

An alternative is that in MicroPython we could leave a little space for the C heap. The downside with that approach is that C heap will be mostly unused and hence wasted. So adding a cyw43_malloc hook seems like a better approach.

Another alternative: add an argument to cyw43_btbus_init() which is a temporary buffer that the caller must supply. And also a constant (eg #define CYW43_BT_BUF_SIZE 1024) so the caller knows how much buffer space needs to be passed in. Then the caller (eg MicroPython bindings) can allocate this, eg statically, on the C stack, on the GC heap.

@peterharperuk
Copy link
Contributor Author

Updated to rename cyw43_alloc to cyw43_malloc

dpgeorge
dpgeorge previously approved these changes Mar 20, 2023
Bluetooth needs a tempoarary buffer to load firmware. Micropython won't
work safely with malloc and free so allow these calls to be changed by
using cyw43_malloc / cyw43_free macros.
@kilograham kilograham merged commit 4000c9f into raspberrypi:develop Mar 20, 2023
@kilograham kilograham added this to the 1.5.1 milestone Mar 20, 2023
andygpz11 pushed a commit to andygpz11/pico-sdk that referenced this pull request May 31, 2023
Bluetooth needs a tempoarary buffer to load firmware. Micropython won't
work safely with malloc and free so allow these calls to be changed by
using cyw43_malloc / cyw43_free macros.
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