From 38d8d2b7a8e2611f0b7e6c725102a842fff3bcdc Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 17 Oct 2022 11:50:15 -0500 Subject: [PATCH] drv/bluetooth_stm32_cc2640: retry on bleMemAllocError 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: https://github.com/pybricks/support/issues/736 --- .../drv/bluetooth/bluetooth_stm32_cc2640.c | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c index bb530b8ad..692d16e66 100644 --- a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c +++ b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c @@ -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; } @@ -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; } @@ -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; }