Tracing STM32 firmware with DMA SPI
In a previous article, I showed how to trace high speed firmware in real-time by writing to SPI protocol. Even though the STM32F4 CPU runs fast (168 MHz), the peripheral bus runs much slower (90 MHz), so that the maximum baud rate I achieved is ~2.5 MHz. If SPI peripheral is available on the accessible pins, then I can speed up the SPI messaging. On the ST motor eval board x-nucleo-ihm08m1, the pins are freely available, so I found SPI3 pins in the upper right corner of the pinout diagram below.
The STM32 CubeMX configuration window removes a lot of low level configuration.
Similarly, STM32 Hal API takes care of the low level detail of writing the contents onto the SPI bus. See my previous article for how the local variable "log" is filled in. The header is 4 bytes, and each argument is 2 bytes, so note the length of the buffer given to the API is the number of words (rather than bytes).
if (HAL_SPI_Transmit_DMA(&hspi3, (uint8_t*)&log, 2 + log.n) != HAL_OK) { (void)hspi3.State; }
The SPI elapsed time is 1.6 μs, but you have to wait a lot longer to actually use the DMA peripheral again; the title picture shows that it takes roughly 5 μs from when you handed off the buffer to HAL.