From 680120a4e14facd80e864b599ebc69c74649a571 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 15 Feb 2023 15:14:02 +0100 Subject: [PATCH] Fix DMA buffer release in ADC/DAC. * Release buffers before deallocing pool. --- src/AdvancedADC.cpp | 14 +++++++------- src/AdvancedDAC.cpp | 15 ++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index df88a18..b97e930 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -60,19 +60,19 @@ static void dac_descr_deinit(adc_descr_t *descr, bool dealloc_pool) { HAL_TIM_Base_Stop(&descr->tim); HAL_ADC_Stop_DMA(&descr->adc); - if (dealloc_pool) { - if (descr->pool) { - delete descr->pool; - } - descr->pool = nullptr; - } - for (size_t i=0; idmabuf); i++) { if (descr->dmabuf[i]) { descr->dmabuf[i]->release(); descr->dmabuf[i] = nullptr; } } + + if (dealloc_pool) { + if (descr->pool) { + delete descr->pool; + } + descr->pool = nullptr; + } } } diff --git a/src/AdvancedDAC.cpp b/src/AdvancedDAC.cpp index 5f3cf5f..290c363 100644 --- a/src/AdvancedDAC.cpp +++ b/src/AdvancedDAC.cpp @@ -58,6 +58,13 @@ static void dac_descr_deinit(dac_descr_t *descr, bool dealloc_pool) { HAL_TIM_Base_Stop(&descr->tim); HAL_DAC_Stop_DMA(descr->dac, descr->channel); + for (size_t i=0; idmabuf); i++) { + if (descr->dmabuf[i]) { + descr->dmabuf[i]->release(); + descr->dmabuf[i] = nullptr; + } + } + if (dealloc_pool) { if (descr->pool) { delete descr->pool; @@ -65,12 +72,6 @@ static void dac_descr_deinit(dac_descr_t *descr, bool dealloc_pool) { descr->pool = nullptr; } - for (size_t i=0; idmabuf); i++) { - if (descr->dmabuf[i]) { - descr->dmabuf[i]->release(); - descr->dmabuf[i] = nullptr; - } - } } } @@ -158,7 +159,7 @@ int AdvancedDAC::begin(uint32_t resolution, uint32_t frequency, size_t n_samples int AdvancedDAC::stop() { - dac_descr_deinit(descr, false); + dac_descr_deinit(descr, true); return 1; }