I'm trying to set up a simple project that does the following:
-
Enter sleep mode and in the main loop, it waits for interrupt – __WFI().
-
Transmits data from a buffer[4] to the PC, via UART.
The second point of the program would ideally be done via DMA, so that the MCU wouldn't wake up from sleep.
To that effect, I was thinking of hooking up a DMA transfer in circular mode. So every time a timer (say timer1) overflows, it automatically triggers a UART transfer. When the DMA transfers the 4th byte of buffer, it would start over from the beginning.
Can I trigger a DMA when the CPU is in sleep mode?
Best Answer
So, I generated a standard CubeMX project. I used USART1 & TIMER1.
In the main function, after the initialization of the peripherals, I simply call
testPWM is a 4 byte array {0, 1, 2, 3}
The main loop is empty, no callbacks are used in code. The DMA controller sends 0 1 2 3 to the PC via UART, on each timer overflow event. When it reaches 3, it wraps back to 0.