diff options
| author | Dave Hylands <dhylands@gmail.com> | 2015-08-04 22:50:56 -0700 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2015-08-05 23:38:49 +0100 |
| commit | 5e11d2b349bffe92c539649799b27c946c2ff17b (patch) | |
| tree | d52d090c3269eb29535bba009d2375f59e0f5b41 /stmhal/spi.c | |
| parent | 34fe5a30c6b9ec4ff5d9b10ef9b2e39ec5fd778f (diff) | |
stmhal: Enable SPI support for F7 MCUs.
Diffstat (limited to 'stmhal/spi.c')
| -rw-r--r-- | stmhal/spi.c | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/stmhal/spi.c b/stmhal/spi.c index c318d923c..311f176b3 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -37,9 +37,29 @@ #include "spi.h" #include MICROPY_HAL_H -#if !defined(STM32F7) -// The STM32F7 has the SPI pins mapped differently. Need to figure this out -// before enabling SPI for the F7 +// The following defines are for compatability with the '405 +#if !defined(MICROPY_HW_SPI1_NSS) +// X-skin: X5=PA4=SPI1_NSS, X6=PA5=SPI1_SCK, X7=PA6=SPI1_MISO, X8=PA7=SPI1_MOSI +#define MICROPY_HW_SPI1_NSS (pin_A4) +#define MICROPY_HW_SPI1_SCK (pin_A5) +#define MICROPY_HW_SPI1_MISO (pin_A6) +#define MICROPY_HW_SPI1_MOSI (pin_A7) +#endif + +#if !defined(MICROPY_HW_SPI2_NSS) +// Y-skin: Y5=PB12=SPI2_NSS, Y6=PB13=SPI2_SCK, Y7=PB14=SPI2_MISO, Y8=PB15=SPI2_MOSI +#define MICROPY_HW_SPI2_NSS (pin_B12) +#define MICROPY_HW_SPI2_SCK (pin_B13) +#define MICROPY_HW_SPI2_MISO (pin_B14) +#define MICROPY_HW_SPI2_MOSI (pin_B15) +#endif + +#if !defined(MICROPY_HW_SPI3_NSS) +#define MICROPY_HW_SPI3_NSS (pin_A4) +#define MICROPY_HW_SPI3_SCK (pin_B3) +#define MICROPY_HW_SPI3_MISO (pin_B4) +#define MICROPY_HW_SPI3_MOSI (pin_B5) +#endif /// \moduleref pyb /// \class SPI - a master-driven serial protocol @@ -140,24 +160,22 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) { if (0) { #if MICROPY_HW_ENABLE_SPI1 } else if (spi->Instance == SPI1) { - // X-skin: X5=PA4=SPI1_NSS, X6=PA5=SPI1_SCK, X7=PA6=SPI1_MISO, X8=PA7=SPI1_MOSI self = &pyb_spi_obj[0]; - pins[0] = &pin_A4; - pins[1] = &pin_A5; - pins[2] = &pin_A6; - pins[3] = &pin_A7; + pins[0] = &MICROPY_HW_SPI1_NSS; + pins[1] = &MICROPY_HW_SPI1_SCK; + pins[2] = &MICROPY_HW_SPI1_MISO; + pins[3] = &MICROPY_HW_SPI1_MOSI; GPIO_InitStructure.Alternate = GPIO_AF5_SPI1; // enable the SPI clock __SPI1_CLK_ENABLE(); #endif #if MICROPY_HW_ENABLE_SPI2 } else if (spi->Instance == SPI2) { - // Y-skin: Y5=PB12=SPI2_NSS, Y6=PB13=SPI2_SCK, Y7=PB14=SPI2_MISO, Y8=PB15=SPI2_MOSI self = &pyb_spi_obj[1]; - pins[0] = &pin_B12; - pins[1] = &pin_B13; - pins[2] = &pin_B14; - pins[3] = &pin_B15; + pins[0] = &MICROPY_HW_SPI2_NSS; + pins[1] = &MICROPY_HW_SPI2_SCK; + pins[2] = &MICROPY_HW_SPI2_MISO; + pins[3] = &MICROPY_HW_SPI2_MOSI; GPIO_InitStructure.Alternate = GPIO_AF5_SPI2; // enable the SPI clock __SPI2_CLK_ENABLE(); @@ -165,10 +183,10 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) { #if MICROPY_HW_ENABLE_SPI3 } else if (spi->Instance == SPI3) { self = &pyb_spi_obj[2]; - pins[0] = &pin_A4; - pins[1] = &pin_B3; - pins[2] = &pin_B4; - pins[3] = &pin_B5; + pins[0] = &MICROPY_HW_SPI3_NSS; + pins[1] = &MICROPY_HW_SPI3_SCK; + pins[2] = &MICROPY_HW_SPI3_MISO; + pins[3] = &MICROPY_HW_SPI3_MOSI; GPIO_InitStructure.Alternate = GPIO_AF6_SPI3; // enable the SPI clock __SPI3_CLK_ENABLE(); @@ -670,5 +688,3 @@ const mp_obj_type_t pyb_spi_type = { .make_new = pyb_spi_make_new, .locals_dict = (mp_obj_t)&pyb_spi_locals_dict, }; - -#endif // STM32F7 |
