Page 1 of 1

[DONE] ADC driver issues

Posted: Tue Nov 26, 2013 8:50 am
by genosensor
The ADC driver API generates buffer half and full callbacks whenever the specified depth of the buffer is > 1
This turns out to be troublesome for applications trying to take a burst of samples at the beginning of each frame -- just oversampling to provide more effective resolution.

Control loops often look like:

1) Take a new burst of input samples
2) Update outputs derived from the previous frame
3) Compute outputs for the next frame

Working on the STM32L, when I tried configuring the ADC group as a linear buffer to support this sort of classical controls algorithm, the driver called my callback *twice* after each burst of input samples was acquired.

The low-level driver disables the half-full interrupt when the buffer is linear, but the interrupt pending flag still gets set, even if it is never serviced.
The driver code calls both the half and full callbacks for each frame, because, by the time the buffer is full, both interrupts are pending.
Since the application's callback starts a new conversion each time (ping-ponging between two buffers), the second callback panics due to the ADC's already being in the "ACTIVE" state.

The attached patch addresses both issues.
In general, the half-full callbacks only make sense for circular buffers, so they never enabled when the buffer is linear.
Specifically for the STM32L1xx, the half-full callback is only invoked if its interrupt is pending and the buffer full interrupt is not pending.

I've tested the patched code for both the circular streaming and linear "burst" cases.
I have not looked at other chips' ADC driver's to determine whether they are also affected. (But, I expect they are)

Re: [TODO] ADC driver issues

Posted: Mon Dec 09, 2013 12:31 pm
by Giovanni
Hi,

Thanks for the patch, fixed it as tickets #445 and #446 on all STM32 platforms and on all branches (2.4.6, 2.6.2, 2.7.0 and 3.0.0).

Giovanni