I'm using an STM32H7 and looking to sample a digital signal at ~6MHz directly into memory with periodic interrupts? I've seen an approach using a DMA read from the GPIO ODR address but this would seem to sample as fast as the DMA can read from the peripheral. Using a timer interrupt its possible to achieve 2MHz+ but these interrupts are costly from the perspective of CPU time as they are occurring at the sampling rate.

Is there another approach I'm missing or not understanding, such as abusing I2S, that could permit a ~6MHz sampling frequency into a memory buffer in batches of hundreds of samples? This would permit the CPU to crunch on the bitstream while the hardware continued to fill the next samples buffer.

It's possible to change to other chips in the STM32 family or another SoC all together if it helps solve this problem.

  • 1
    \$\begingroup\$ My 1st guess would be to 'abuse' a SPI master module for this. Connect your signal to be sampled to the MISO pin and don't bother configuring the SCK pin. DMA from SPI over into RAM and configure the DMA to interrupt at convenient block sizes. \$\endgroup\$
    – brhans
    Dec 30, 2020 at 4:49
  • 2
    \$\begingroup\$ It should be possible to trigger a DMA transfer with a timer, isn't this exactly what you need? \$\endgroup\$
    – Justme
    Dec 30, 2020 at 6:22
  • \$\begingroup\$ See "AN4666 - Parallel synchronous transmission using GPIO and DMA" \$\endgroup\$
    – Tagli
    Dec 30, 2020 at 6:42
  • \$\begingroup\$ @Tagli I've looked at AN4666 and the corresponding example code. It's for the F4 and Lx series and I'm having trouble following how some things like __HAL_LINKDMA() map for the H7. Is there an example of this for the H7 series that you are aware of? \$\endgroup\$ Dec 30, 2020 at 22:55
  • 1
    \$\begingroup\$ With half buffer and full buffer interrupts? \$\endgroup\$
    – Justme
    Dec 31, 2020 at 13:13

1 Answer 1


Yes there is.

Set up a timer to trigger a DMA transfer from GPIO port to memory buffer at a rate of 6 MHz.

  • \$\begingroup\$ Would you have any pointers on how that triggering is configured? I see the use of __HAL_LINKDMA() which appears to be a bookkeeping thing and non-functional from what I read. I don't yet understand to trigger the dma from the timer. \$\endgroup\$ Jan 2, 2021 at 3:02
  • \$\begingroup\$ This isn't a reliable method. The DMA has a lower priority than the CPU core so there is no guarantee it will sample on each clock cycle, some samples may be delayed. \$\endgroup\$
    – user
    Nov 27, 2021 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.