Arduino_Core_STM32 icon indicating copy to clipboard operation
Arduino_Core_STM32 copied to clipboard

add the STM32WL SUGGHZSPI to the SPI library

Open majbthrd opened this issue 3 years ago • 1 comments

The raison d'être for the STM32WL series is its internal SUBGHZSPI peripheral. SUBGHZSPI may have its own chapter in the Reference Manual separate from other SPI peripherals, but SUBGHZSPI is identical in operation to other SPI peripherals:

#define SUBGHZSPI               ((SPI_TypeDef *) SUBGHZSPI_BASE)

However, despite this, the SPI implementation of Arduino_Core_STM32 does not presently support SUBGHZSPI. This PR tweaks the existing implementation to make this possible.

The Arduino Way (tm) of implementing SPI is to insist that the user provides the pin names of the peripheral. Using a database of all possible peripherals stored as part of the firmware, Arduino then evaluates these at run time to map them back to the peripheral. (Chacun à son goût)

To make that method work with SUBGHZSPI, this PR creates three virtual digital pins: SUBGHZSPI_MOSI, SUBGHZSPI_MISO, and SUBGHZSPI_SCLK. These pins are added to the pin databases for the STM32WL variants.

The only difference between SUBGHZSPI and other SPI peripherals is that its pins are hard-wired to the internal peripheral, rather than using the GPIO Alternate Function multiplexer. This condition is signaled by having the "int function" member of the PinMap struct be negative. Then, .libraries/SrcWrapper/src/stm32/pinmap.c detects this in pin_function() and omits the inappropriate GPIO AF code.

majbthrd avatar Aug 14 '22 17:08 majbthrd

Hi @majbthrd Thanks for this PR. We are currently working on LoRa support internally. As a first feedback of this PR is it change file generated automatically and also add support in the pinmap of "virtual" port and pins. I don't think it is the good way.

fpistm avatar Aug 30 '22 08:08 fpistm

Hi @majbthrd,

I've made a new PR based on your one. See #1839 so I close this one.

fpistm avatar Sep 29 '22 16:09 fpistm