Skip to content

Commit

Permalink
drv/bluetooth_stm32_cc2640: retry on bleMemAllocError
Browse files Browse the repository at this point in the history
Apparently we are starting to run out of RAM on the CC2640 chips and we
are now occasionally getting bleMemAllocError when trying to send
notifications.

This adds bleMemAllocError to the retry test cases. It also adds
handling of cancellation so we can't get stuck in an infinite retry
loop.

Fixes: pybricks/support#736
  • Loading branch information
dlech committed Oct 17, 2022
1 parent 4494a27 commit 38d8d2b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,13 @@ static PT_THREAD(send_value_notification(struct pt *pt, pbio_task_t *task))
PT_WAIT_UNTIL(pt, hci_command_status);

HCI_StatusCodes_t status = read_buf[8];
if (status == blePending) {

if (status == blePending || status == bleMemAllocError) {
if (task->cancel) {
task->status = PBIO_ERROR_CANCELED;
goto done;
}

goto retry;
}

Expand Down Expand Up @@ -604,7 +610,12 @@ static PT_THREAD(scan_and_connect_task(struct pt *pt, pbio_task_t *task)) {

HCI_StatusCodes_t status = read_buf[8];

if (status == blePending) {
if (status == blePending || status == bleMemAllocError) {
if (task->cancel) {
task->status = PBIO_ERROR_CANCELED;
goto disconnect;
}

goto retry;
}

Expand Down Expand Up @@ -667,11 +678,11 @@ static PT_THREAD(write_remote_task(struct pt *pt, pbio_task_t *task)) {
HCI_StatusCodes_t status = read_buf[8];

if (status != bleSUCCESS) {
if (task->cancel) {
goto cancel;
}
if (status == blePending || status == bleMemAllocError) {
if (task->cancel) {
goto cancel;
}

if (status == blePending) {
goto retry;
}

Expand Down

0 comments on commit 38d8d2b

Please sign in to comment.