Skip to content

ports/stm32: Extend STM32H5 DMA use. #17587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mattytrentini
Copy link
Contributor

Summary

Attempting to configure SPI3 and SPI4 for the STM32H5 used to fail with a linker error, something like:

[snip]
...undefined reference to `dma_SPI_4_TX'

An example of valid configuration that was failing:

diff --git a/ports/stm32/boards/NUCLEO_H563ZI/mpconfigboard.h b/ports/stm32/boards/NUCLEO_H563ZI/mpconfigboard.h
index 1e802eda5..9585ade03 100644
--- a/ports/stm32/boards/NUCLEO_H563ZI/mpconfigboard.h
+++ b/ports/stm32/boards/NUCLEO_H563ZI/mpconfigboard.h
@@ -62,6 +62,10 @@
 #define MICROPY_HW_SPI1_MISO                (pin_G9) // Arduino Connector CN7-Pin12 (D12)
 #define MICROPY_HW_SPI1_MOSI                (pin_B5) // Arduino Connector CN7-Pin14 (D11)

+#define MICROPY_HW_SPI4_SCK
+#define MICROPY_HW_SPI4_MISO
+#define MICROPY_HW_SPI4_MOSI
+
 // USRSW is pulled low. Pressing the button makes the input go high.
 #define MICROPY_HW_USRSW_PIN                (pin_C13)
 #define MICROPY_HW_USRSW_PULL               (GPIO_NOPULL)

This patch resolves that, ensuring that appropriate DMA channels are assigned to those SPI resources.

Testing

Tested SPI3 and SPI4 against a SPI peripheral (MAX14915). Also validated correct pin behaviour under a DSO.

I haven't tested if power use is higher due to more channels being employed.

Trade-offs and Alternatives

This patch does use more DMA channels. The H5 has two DMA resources, each with 8 channels. Two are needed for a bidirectional SPI channel (one each for Rx and Tx) so a whole DMA resource - 8 channels - are used to cover SPI1-4. An additional 2x channels of the second DMA resource may also be used if DAC is used.

Currently the DMA channels are statically assigned in MicroPython; an alternative would be to provide an abstraction for DMA channels and allow them to be assigned more dynamically. However, that would be a more complex implementation and difficult to provide a cross-port design.

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant