ADC half complete callback bug
Posted: Wed Jun 13, 2012 4:47 am
In 2.4.1 (and possibly later), it looks like the ADC conversion callback's buffer parameter is passed the wrong pointer when using a circular double buffer (circular = true, depth > 1) and the second half of the buffer is converted. The callback invocation code adds half the number of rows to the sample buffer pointer, which becomes an issue when there's more than one channel in the conversion group.
Here's my patch:
Code: Select all
size_t half = (adcp)->depth / 2;
(adcp)->grpp->end_cb(adcp, (adcp)->samples + half, half);Here's my patch:
Code: Select all
diff --git a/os/hal/include/adc.h b/os/hal/include/adc.h
index 54fc8a9..25e1151 100644
--- a/os/hal/include/adc.h
+++ b/os/hal/include/adc.h
@@ -217,7 +217,8 @@ typedef enum {
if ((adcp)->depth > 1) { \
/* Invokes the callback passing the 2nd half of the buffer.*/ \
size_t half = (adcp)->depth / 2; \
- (adcp)->grpp->end_cb(adcp, (adcp)->samples + half, half); \
+ size_t half_index = half * (adcp)->grpp->num_channels; \
+ (adcp)->grpp->end_cb(adcp, (adcp)->samples + half_index, half); \
} \
else { \
/* Invokes the callback passing the whole buffer.*/ \
@@ -233,7 +234,8 @@ typedef enum {
if ((adcp)->depth > 1) { \
/* Invokes the callback passing the 2nd half of the buffer.*/ \
size_t half = (adcp)->depth / 2; \
- (adcp)->grpp->end_cb(adcp, (adcp)->samples + half, half); \
+ size_t half_index = half * (adcp)->grpp->num_channels; \
+ (adcp)->grpp->end_cb(adcp, (adcp)->samples + half_index, half); \
} \
else { \
/* Invokes the callback passing the whole buffer.*/ \