Skip to content

Commit 4977a99

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_alloc / free macros.
1 parent 7f72325 commit 4977a99

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
@@ -62,14 +62,14 @@ static cybt_result_t cybt_fw_download_prepare(uint8_t **p_write_buf, uint8_t **p
6262
*p_write_buf = NULL;
6363
*p_hex_buf = NULL;
6464

65-
*p_write_buf = malloc(BTFW_DOWNLOAD_BLK_SIZE + BTFW_SD_ALIGN);
65+
*p_write_buf = cyw43_alloc(BTFW_DOWNLOAD_BLK_SIZE + BTFW_SD_ALIGN);
6666
if (NULL == *p_write_buf) {
6767
return CYBT_ERR_OUT_OF_MEMORY;
6868
}
6969

70-
*p_hex_buf = malloc(BTFW_MAX_STR_LEN);
70+
*p_hex_buf = cyw43_alloc(BTFW_MAX_STR_LEN);
7171
if (NULL == *p_hex_buf) {
72-
free(*p_write_buf);
72+
cyw43_free(*p_write_buf);
7373
return CYBT_ERR_OUT_OF_MEMORY;
7474
}
7575

@@ -78,11 +78,11 @@ static cybt_result_t cybt_fw_download_prepare(uint8_t **p_write_buf, uint8_t **p
7878

7979
static cybt_result_t cybt_fw_download_finish(uint8_t *p_write_buf, uint8_t *p_hex_buf) {
8080
if (p_write_buf) {
81-
free(p_write_buf);
81+
cyw43_free(p_write_buf);
8282
}
8383

8484
if (p_hex_buf) {
85-
free(p_hex_buf);
85+
cyw43_free(p_hex_buf);
8686
}
8787

8888
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
@@ -157,6 +157,10 @@ void cyw43_post_poll_hook(void);
157157

158158
#define CYW43_POST_POLL_HOOK cyw43_post_poll_hook();
159159

160+
// Allow malloc and free to be changed
161+
#define cyw43_alloc malloc
162+
#define cyw43_free free
163+
160164
#ifdef __cplusplus
161165
}
162166
#endif

0 commit comments

Comments
 (0)