SPI Asynchronous DMA
Posted: Wed Jul 06, 2022 10:44 am
Hi all,
I'm writing a piece of code for an STM32F4x to sample four channels of an external ADC (ADS8167) chip via SPI. The desired sampling frequency is 1kHz and ideally the four channels should be sampled as closely as possible in time. The external ADC samples on the slave select edges thus requiring this to be toggled. This would lead to four SPI bursts at the start of the period after which the system would remain idle until the cycle repeats. My preferred way of doing this would be to completely offload this to hardware timers and DMA, however, there is a hardware bug on our board such that I have to assert the slave select pin via software. After doing so I start a DMA transfer to read out the channel. On first glance this worked perfectly fine, however to be sure I checked the timing by toggling several GPIO pins. The result is shown below. Channel 2 shows the 'main' frequency of 1kHz. Each low-level pulse indicates a new period. Channel 0, indicates the DMA receive ISR at work for each pulse. As you see, these pulses are spaced at 100us, which is exactly equal to my system tick period. This observation has led to two questions:
I checked the SPI IRQ priority and it is currently at 10. Tinkering with this did not change the behavior in any way. Is it at all possible to do what I want with ChibiOS or should I write my own code for it?
Thanks for your help in advance!
Remi
I'm writing a piece of code for an STM32F4x to sample four channels of an external ADC (ADS8167) chip via SPI. The desired sampling frequency is 1kHz and ideally the four channels should be sampled as closely as possible in time. The external ADC samples on the slave select edges thus requiring this to be toggled. This would lead to four SPI bursts at the start of the period after which the system would remain idle until the cycle repeats. My preferred way of doing this would be to completely offload this to hardware timers and DMA, however, there is a hardware bug on our board such that I have to assert the slave select pin via software. After doing so I start a DMA transfer to read out the channel. On first glance this worked perfectly fine, however to be sure I checked the timing by toggling several GPIO pins. The result is shown below. Channel 2 shows the 'main' frequency of 1kHz. Each low-level pulse indicates a new period. Channel 0, indicates the DMA receive ISR at work for each pulse. As you see, these pulses are spaced at 100us, which is exactly equal to my system tick period. This observation has led to two questions:
- How can I decrease the burst period with ChibiOS? Is it possible to have the SPI low-level-driver callback run asynchronous to the ChibiOS system tick? This so I can decrease the burst period to 25us instead of 100us.
- Does this also mean the SPI interrupt uses 400us of system time? Or are other tasks handled in between the interrupts?
I checked the SPI IRQ priority and it is currently at 10. Tinkering with this did not change the behavior in any way. Is it at all possible to do what I want with ChibiOS or should I write my own code for it?
Thanks for your help in advance!
Remi