SPI Overrun when using the DMA
Hi,
I've run into an interesting problem when doing two simultaneous SPI transfers using the DMA.
I'm using the STM32F103ZFH6 where I am simultaneously reading a bitstream (in large chunks) from and external SPI flash device and writing in out to another device over SPI.
The 'n+1' chunk is clocked in on SPI1 (APB2) using DMA channels 2&3 (need the Tx channel to provide the SPI clock) and is moved to SRAM.
The 'nth' chunk is moved from SRAM and clocked out on SPI2 (APB1) using DMA channel 5.
They system clock is running at 72MHz.
APB2/APB1 clocks are running at 72/36MHz respectively.
The SPI peripherals are clocking at 18 MHz.
The SPI/DMA are working with 8bit data sizes.
This operation seems to work flawlessly when the CPU is 'idle' during the DMA operations. However, the problem I run into is when the CPU goes off to do other thing in the meantime. For example, if I continually read from the USART2 status register (APB1) while the transfer is in progress, the SPI1 transfer will fail where I see an OVR (overrun) in the SPI1 status register.
This suggests to me that the DMA did not have enough time to service the RXNE flag before the last byte was clocked out.
To me, it seems like the I'm exceeding the maximum throughput of the AHB/APB buses. But I can't figure out why that would be this case. I've read AN2548 but my understanding of the internal AHB/APB busses is still a bit weak. At a system clock of 72MHz and an SPI clock of 18MHz, the DMA should need to move 3 bytes every 32 AHB cycles. If I interleave some CPU instructions (that access the APB busses as well), I could see things getting congested. However what I don't get is that the RX DMA channel which services the SPI1 Rx (channel 2) should have the highest priority, an therefore should take precedence if bus access starts to get congested and the flow of data slows down. i.e. I would expect to see gaps in the SPI clocks when observed on a scope, but never an overrun.
Am I on the right track here? Is this a bus contention issue, or am I looking in the wrong place.
Any ideas would be helpful. Thanks,
-Steven