Use DMA in custom C module without breaking Micropython DMA definitions #16386
-
Does anybody know how I can use DMA for a SPI peripheral inside a custom C module without interfering with the micropython dma implementation? I am working on a stm32h743 nucleo board and the goal is to have a non-blocking write/send SPI function. Apparently the SPI call in micropython is blocking until the transfer is complete (for that part of the application I really need the speed to update the peripheral very frequently driven by a timer interrupt so micropython for this part is a no-go). Building my own c code for the SPI using DMA (using the ST examples) interferes with the already defined DMA definitions/handles/streams etc in dma.c of the stm32 port. Completely deleting the dma.c here is not what I want, as 80% of the application is running micropython code which works great. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
You can configure and use the DMA in a user C module, I've done this recently to work with timer capture units. You do need to choose channels that aren't already in use on the particular chip you're using. I had to use a mix of the microypthon dma init functions (to ensure the correct handles are configured that the interrupts expect) as well as the HAL functions (to configure settings not exposed by the micropython functions). Here's some snippets from my C code, hopefully they help #include "py/runtime.h"
#include "py/mphal.h"
#include "ports/stm32/dma.h"
#include "ports/stm32/pin.h"
#include "ports/stm32/timer.h"
#define SIGGEN_DMA_CHANNEL DMA2_Channel1
#define SIGGEN_DMA_CHANNEL_IRQ DMA2_Channel1_IRQn
// Look at <SIGGEN_DMA_CHANNEL>_IRQHandler in src/micropython/ports/stm32/dma.c
// Set the matching dma_id_x used there here
#define SIGGEN_DMA_CHANNEL_ID dma_id_7
|
Beta Was this translation helpful? Give feedback.
You can configure and use the DMA in a user C module, I've done this recently to work with timer capture units. You do need to choose channels that aren't already in use on the particular chip you're using.
I had to use a mix of the microypthon dma init functions (to ensure the correct handles are configured that the interrupts expect) as well as the HAL functions (to configure settings not exposed by the micropython functions).
Here's some snippets from my C code, hopefully they help