-
Notifications
You must be signed in to change notification settings - Fork 989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce new ADC API for DMA-based high sampling rate #231
Conversation
This layer is fully independant from the peripheral. Tested only with ADC peripheral. Signed-off-by: dhl <damien.helis@wi6labs.com>
Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
Hi @fprwi6labs, |
Hi @fpistm |
Currently not it seems ok. Thanks |
How to use? |
@ropa35, |
if (HAL_ADC_DeInit(AdcHandle) != HAL_OK) | ||
{ | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it pretty bothersome that for each call to adc_read_value_dma
the ADC gets deinitialized, then initialized, finally sampled, and then deinitialized again. Yes, this is amortized over lData
samples, but still... How lkong does all this de-init/init/de-init take? Why not create an API that lets the user init things, and then call a very lightweight function to collect a batch of samples?
IMHO this suffers from the same problems that the current analogRead implementation suffers, which is that the API only provides a single call which has to init everything from scratch, collect the samples, and then deinit everything. (What benefit does using the HAL give over using LL?) |
Yes you're right that's why this PR is not merged. |
I started an STM32ADC library here: https://github.com/tve/goobies/blob/master/libraries/STM32ADC/src/STM32ADC.h |
I will have a look soon. Thanks. Do not hesitate to provide a dedicated PR if you want. |
I can't do a PR until I have something that shows sign of life :-). I posted the link mainly to get feedback on the interface before I start coding too much and get attached to an implementation... |
@@ -56,6 +79,8 @@ void dac_stop(PinName pin); | |||
uint16_t adc_read_value(PinName pin); | |||
void pwm_start(PinName pin, uint32_t clock_freq, uint32_t period, uint32_t value, uint8_t do_init); | |||
void pwm_stop(PinName pin); | |||
bool adc_read_value_dma(PinName pin, uint32_t *pData, uint32_t lData, | |||
void (*callback)(void *user_data), void *functionParameter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can probably rename the last argument to user_data safely.
Can you allso add comment what happens if there is an error: does the CB get called? Do we need on_error callback?
{ | ||
void *DMAx_Instance = NULL; | ||
|
||
if((DMAx == NC) || (channelx == NC)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion add: || DMAx < 1 || DMAx > 2 || channelx < 0 || channelx > 7
DMAHandle[DMAx][channel].Init.Direction = DMA_PERIPH_TO_MEMORY; | ||
DMAHandle[DMAx][channel].Init.PeriphInc = DMA_PINC_DISABLE; | ||
DMAHandle[DMAx][channel].Init.MemInc = DMA_MINC_ENABLE; | ||
DMAHandle[DMAx][channel].Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;//DMA_PDATAALIGN_HALFWORD; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't ADC halfword?
Close this one as it will never merged as it is. |
Continuation of the PR #175
I had to open a new PR because @damienWi6labs is no longer on this project.
I followed @fpistm comments (see #175).
DMA layer is now fully independent of the peripheral.
DMA has been tested only with ADC peripheral.
Wiki page about this method available here.
Example provided here.