Timer triggered SPI read with circular DMA
Posted: Sun Dec 31, 2017 1:37 am
Sampling an external ADC using is a common usage of the SPI bus. At high sample rates, you need to use a hardware timer to trigger a DMA write to SPI TX register, and setup a DMA request on SPI RX in circular mode with half transfer and transfer complete interrupts enabled. That is really the only feasible way to sample the ADC at high sample rates (the same thing applies to the internal ADC).
I'm currently working on writing a driver for an external SPI ADC (AD7980), and would like to reuse the hal_adc, hal_spi, and hal_pwm to make it portable. See below:
There are a couple of issues I've discovered so far, and probably more. I think the HAL - or at least the STM32 implementation should be updated to at the very least allow this sort of usage.
The spi driver doesn't expose the half transfer interrupt. It also disables the interrupts after the dma transfer is complete, thus not supporting 'continuous' mode. A couple of other changes probably need to happen as well to have the rights hooks to be able to use the SPI driver as part of a more complex composite device driver.
Have anyone of you already done this? Any idea for how to do this cleanly?
I'm currently working on writing a driver for an external SPI ADC (AD7980), and would like to reuse the hal_adc, hal_spi, and hal_pwm to make it portable. See below:
Code: Select all
+---------------+
| hal_adc.c |
+---------------+
|
+-------|-------+
| ad7980.c |
+-------|-------+
|
|---------------------|------------------|
+-------|-------+ +-------|-------+ +-------|-------+
| hal_pwm.c | | hal_spi.c | | stm32_dma.c |
+---------------+ +---------------+ +-------+-------+
There are a couple of issues I've discovered so far, and probably more. I think the HAL - or at least the STM32 implementation should be updated to at the very least allow this sort of usage.
The spi driver doesn't expose the half transfer interrupt. It also disables the interrupts after the dma transfer is complete, thus not supporting 'continuous' mode. A couple of other changes probably need to happen as well to have the rights hooks to be able to use the SPI driver as part of a more complex composite device driver.
Have anyone of you already done this? Any idea for how to do this cleanly?