From 218930d18b5d6c4fbe67c87cec4771b39cc69d1f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 7 Jun 2018 21:37:09 -0400 Subject: [PATCH] Check for PDMIn DMA getting stuck. --- ports/atmel-samd/common-hal/audiobusio/PDMIn.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c index 5502fcd8125b2..f16b177707040 100644 --- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c +++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -392,7 +392,18 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se break; } // Wait for the next buffer to fill + uint32_t wait_counts = 0; + #ifdef SAMD21 + #define MAX_WAIT_COUNTS 1000 + #endif + #ifdef SAMD51 + #define MAX_WAIT_COUNTS 6000 + #endif while (!event_interrupt_active(event_channel)) { + if (wait_counts++ > MAX_WAIT_COUNTS) { + // Buffer has stopped filling; DMA may have missed an I2S trigger event. + break; + } #ifdef MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_LOOP #endif