From 8b1db792eed177d0b241833b4fe43a560f26769f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 1 Jun 2018 08:35:09 +1000 Subject: [PATCH] HAL_ChibiOS: ensure ADC memory is aligned for DMA access --- libraries/AP_HAL_ChibiOS/AnalogIn.cpp | 5 ++++- libraries/AP_HAL_ChibiOS/AnalogIn.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/AnalogIn.cpp b/libraries/AP_HAL_ChibiOS/AnalogIn.cpp index 9f2991e9c5..04af06352e 100644 --- a/libraries/AP_HAL_ChibiOS/AnalogIn.cpp +++ b/libraries/AP_HAL_ChibiOS/AnalogIn.cpp @@ -60,7 +60,7 @@ const AnalogIn::pin_info AnalogIn::pin_config[] = HAL_ANALOG_PINS; #define ADC_GRP1_NUM_CHANNELS ARRAY_SIZE_SIMPLE(AnalogIn::pin_config) // samples filled in by ADC DMA engine -adcsample_t AnalogIn::samples[ADC_DMA_BUF_DEPTH*ADC_GRP1_NUM_CHANNELS]; +adcsample_t *AnalogIn::samples; uint32_t AnalogIn::sample_sum[ADC_GRP1_NUM_CHANNELS]; uint32_t AnalogIn::sample_count; @@ -204,6 +204,9 @@ void AnalogIn::init() if (ADC_GRP1_NUM_CHANNELS == 0) { return; } + + samples = (adcsample_t *)hal.util->malloc_type(sizeof(adcsample_t)*ADC_DMA_BUF_DEPTH*ADC_GRP1_NUM_CHANNELS, AP_HAL::Util::MEM_DMA_SAFE); + adcStart(&ADCD1, NULL); memset(&adcgrpcfg, 0, sizeof(adcgrpcfg)); adcgrpcfg.circular = true; diff --git a/libraries/AP_HAL_ChibiOS/AnalogIn.h b/libraries/AP_HAL_ChibiOS/AnalogIn.h index 1292c8112f..2de93dd2ca 100644 --- a/libraries/AP_HAL_ChibiOS/AnalogIn.h +++ b/libraries/AP_HAL_ChibiOS/AnalogIn.h @@ -88,7 +88,7 @@ private: }; static const pin_info pin_config[]; - static adcsample_t samples[]; + static adcsample_t *samples; static uint32_t sample_sum[]; static uint32_t sample_count; };