Skip to content

Commit 326d6e8

Browse files
committed
Allow malloc and free to be changed.
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.
1 parent 92dfa73 commit 326d6e8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ static cybt_result_t cybt_fw_download_prepare(uint8_t **p_write_buf, uint8_t **p
6161
*p_write_buf = NULL;
6262
*p_hex_buf = NULL;
6363

64-
*p_write_buf = malloc(BTFW_DOWNLOAD_BLK_SIZE + BTFW_SD_ALIGN);
64+
*p_write_buf = cyw43_malloc(BTFW_DOWNLOAD_BLK_SIZE + BTFW_SD_ALIGN);
6565
if (NULL == *p_write_buf) {
6666
return CYBT_ERR_OUT_OF_MEMORY;
6767
}
6868

69-
*p_hex_buf = malloc(BTFW_MAX_STR_LEN);
69+
*p_hex_buf = cyw43_malloc(BTFW_MAX_STR_LEN);
7070
if (NULL == *p_hex_buf) {
71-
free(*p_write_buf);
71+
cyw43_free(*p_write_buf);
7272
return CYBT_ERR_OUT_OF_MEMORY;
7373
}
7474

@@ -77,11 +77,11 @@ static cybt_result_t cybt_fw_download_prepare(uint8_t **p_write_buf, uint8_t **p
7777

7878
static cybt_result_t cybt_fw_download_finish(uint8_t *p_write_buf, uint8_t *p_hex_buf) {
7979
if (p_write_buf) {
80-
free(p_write_buf);
80+
cyw43_free(p_write_buf);
8181
}
8282

8383
if (p_hex_buf) {
84-
free(p_hex_buf);
84+
cyw43_free(p_hex_buf);
8585
}
8686

8787
return CYBT_SUCCESS;

src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ void cyw43_post_poll_hook(void);
179179

180180
#define CYW43_POST_POLL_HOOK cyw43_post_poll_hook();
181181

182+
// Allow malloc and free to be changed
183+
#define cyw43_malloc malloc
184+
#define cyw43_free free
185+
182186
#ifdef __cplusplus
183187
}
184188
#endif

0 commit comments

Comments
 (0)