From f7c4f9a64048bcbeaf36be8590b352bbef72aa08 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 12 Dec 2015 15:02:02 +0000 Subject: [PATCH] stmhal: For SPI config, use HW_SPIx_SCK instead of HW_ENABLE_SPIx. Previously, SPI was configured by a board defining MICROPY_HW_ENABLE_SPIx to 0 or 1. Now, the board should define MICROPY_HW_SPIx_SCK, MISO, MOSI and NSS. This makes it the same as how I2C is configured. --- stmhal/boards/CERB40/mpconfigboard.h | 13 ++- stmhal/boards/ESPRUINO_PICO/mpconfigboard.h | 13 ++- stmhal/boards/HYDRABUS/mpconfigboard.h | 17 +++- stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h | 9 +- stmhal/boards/PYBLITEV10/mpconfigboard.h | 11 ++- stmhal/boards/PYBV10/mpconfigboard.h | 11 ++- stmhal/boards/PYBV11/mpconfigboard.h | 11 ++- stmhal/boards/PYBV3/mpconfigboard.h | 15 +++- stmhal/boards/PYBV4/mpconfigboard.h | 11 ++- stmhal/boards/STM32F411DISC/mpconfigboard.h | 13 ++- stmhal/boards/STM32F429DISC/mpconfigboard.h | 3 - stmhal/boards/STM32F4DISC/mpconfigboard.h | 13 ++- stmhal/boards/STM32F7DISC/mpconfigboard.h | 3 - stmhal/boards/make-pins.py | 2 +- stmhal/spi.c | 84 +++++++------------ 15 files changed, 135 insertions(+), 94 deletions(-) diff --git a/stmhal/boards/CERB40/mpconfigboard.h b/stmhal/boards/CERB40/mpconfigboard.h index 71844d06f1..ac3560905b 100644 --- a/stmhal/boards/CERB40/mpconfigboard.h +++ b/stmhal/boards/CERB40/mpconfigboard.h @@ -14,9 +14,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (0) #define MICROPY_HW_ENABLE_DAC (1) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (0) -#define MICROPY_HW_ENABLE_SPI3 (1) #define MICROPY_HW_ENABLE_CAN (1) // HSE is 12MHz @@ -51,6 +48,16 @@ #define MICROPY_HW_I2C2_SCL (pin_B10) #define MICROPY_HW_I2C2_SDA (pin_B11) +// SPI busses +#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) +#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) + // The Cerb40 has No LEDs // The Cerb40 has No SDCard diff --git a/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h b/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h index 221c0ab1fb..e7a338d3e1 100644 --- a/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h +++ b/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h @@ -12,9 +12,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (0) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (0) // Pico has an 8 MHz HSE and the F401 does 84 MHz max @@ -44,6 +41,16 @@ #define MICROPY_HW_I2C3_SCL (pin_A8) #define MICROPY_HW_I2C3_SDA (pin_B4) +// SPI busses +#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) +#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) + // BTN1 has no pullup or pulldown; it is active high and broken out on a header #define MICROPY_HW_USRSW_PIN (pin_C13) #define MICROPY_HW_USRSW_PULL (GPIO_PULLDOWN) diff --git a/stmhal/boards/HYDRABUS/mpconfigboard.h b/stmhal/boards/HYDRABUS/mpconfigboard.h index 79c4203793..b63974e806 100644 --- a/stmhal/boards/HYDRABUS/mpconfigboard.h +++ b/stmhal/boards/HYDRABUS/mpconfigboard.h @@ -13,9 +13,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (0) #define MICROPY_HW_ENABLE_DAC (1) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (1) #define MICROPY_HW_ENABLE_CAN (0) // HSE is 8MHz @@ -46,6 +43,20 @@ #define MICROPY_HW_I2C2_SCL (pin_B10) #define MICROPY_HW_I2C2_SDA (pin_B11) +// SPI busses +#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) +#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) +#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) + // USRSW/UBTN (Needs Jumper UBTN) is pulled low. Pressing the button makes the input go high. #define MICROPY_HW_USRSW_PIN (pin_A0) #define MICROPY_HW_USRSW_PULL (GPIO_NOPULL) diff --git a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h b/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h index fba726596b..a609869272 100644 --- a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h +++ b/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h @@ -17,9 +17,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (0) -#define MICROPY_HW_ENABLE_SPI1 (0) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (0) // HSE is 25MHz @@ -48,6 +45,12 @@ #define MICROPY_HW_I2C2_SCL (pin_B10) #define MICROPY_HW_I2C2_SDA (pin_B11) +// SPI busses +#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) + // USRSW is pulled low. Pressing the button makes the input go high. #define MICROPY_HW_USRSW_PIN (pin_B11) #define MICROPY_HW_USRSW_PULL (GPIO_NOPULL) diff --git a/stmhal/boards/PYBLITEV10/mpconfigboard.h b/stmhal/boards/PYBLITEV10/mpconfigboard.h index 27988cad93..037302c6ba 100644 --- a/stmhal/boards/PYBLITEV10/mpconfigboard.h +++ b/stmhal/boards/PYBLITEV10/mpconfigboard.h @@ -12,9 +12,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (0) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (0) // HSE is 12MHz @@ -52,7 +49,15 @@ // SPI busses #define MICROPY_HW_SPI1_NAME "X" +#define MICROPY_HW_SPI1_NSS (pin_A4) // X5 +#define MICROPY_HW_SPI1_SCK (pin_A5) // X6 +#define MICROPY_HW_SPI1_MISO (pin_A6) // X7 +#define MICROPY_HW_SPI1_MOSI (pin_A7) // X8 #define MICROPY_HW_SPI2_NAME "Y" +#define MICROPY_HW_SPI2_NSS (pin_B12) // Y5 +#define MICROPY_HW_SPI2_SCK (pin_B13) // Y6 +#define MICROPY_HW_SPI2_MISO (pin_B14) // Y7 +#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8 // USRSW has no pullup or pulldown, and pressing the switch makes the input go low #define MICROPY_HW_USRSW_PIN (pin_B3) diff --git a/stmhal/boards/PYBV10/mpconfigboard.h b/stmhal/boards/PYBV10/mpconfigboard.h index fece733308..34207be560 100644 --- a/stmhal/boards/PYBV10/mpconfigboard.h +++ b/stmhal/boards/PYBV10/mpconfigboard.h @@ -12,9 +12,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (1) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) // HSE is 8MHz @@ -59,7 +56,15 @@ // SPI busses #define MICROPY_HW_SPI1_NAME "X" +#define MICROPY_HW_SPI1_NSS (pin_A4) // X5 +#define MICROPY_HW_SPI1_SCK (pin_A5) // X6 +#define MICROPY_HW_SPI1_MISO (pin_A6) // X7 +#define MICROPY_HW_SPI1_MOSI (pin_A7) // X8 #define MICROPY_HW_SPI2_NAME "Y" +#define MICROPY_HW_SPI2_NSS (pin_B12) // Y5 +#define MICROPY_HW_SPI2_SCK (pin_B13) // Y6 +#define MICROPY_HW_SPI2_MISO (pin_B14) // Y7 +#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8 // CAN busses #define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9 diff --git a/stmhal/boards/PYBV11/mpconfigboard.h b/stmhal/boards/PYBV11/mpconfigboard.h index 2951a9dbd9..7bc48e8b8a 100644 --- a/stmhal/boards/PYBV11/mpconfigboard.h +++ b/stmhal/boards/PYBV11/mpconfigboard.h @@ -12,9 +12,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (1) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) // HSE is 12MHz @@ -59,7 +56,15 @@ // SPI busses #define MICROPY_HW_SPI1_NAME "X" +#define MICROPY_HW_SPI1_NSS (pin_A4) // X5 +#define MICROPY_HW_SPI1_SCK (pin_A5) // X6 +#define MICROPY_HW_SPI1_MISO (pin_A6) // X7 +#define MICROPY_HW_SPI1_MOSI (pin_A7) // X8 #define MICROPY_HW_SPI2_NAME "Y" +#define MICROPY_HW_SPI2_NSS (pin_B12) // Y5 +#define MICROPY_HW_SPI2_SCK (pin_B13) // Y6 +#define MICROPY_HW_SPI2_MISO (pin_B14) // Y7 +#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8 // CAN busses #define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9 diff --git a/stmhal/boards/PYBV3/mpconfigboard.h b/stmhal/boards/PYBV3/mpconfigboard.h index 12f68aae39..34c6a596f4 100644 --- a/stmhal/boards/PYBV3/mpconfigboard.h +++ b/stmhal/boards/PYBV3/mpconfigboard.h @@ -11,9 +11,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (1) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) // HSE is 8MHz @@ -49,6 +46,18 @@ #define MICROPY_HW_I2C2_SCL (pin_B10) #define MICROPY_HW_I2C2_SDA (pin_B11) +// SPI busses +#define MICROPY_HW_SPI1_NAME "X" +#define MICROPY_HW_SPI1_NSS (pin_A4) // X5 +#define MICROPY_HW_SPI1_SCK (pin_A5) // X6 +#define MICROPY_HW_SPI1_MISO (pin_A6) // X7 +#define MICROPY_HW_SPI1_MOSI (pin_A7) // X8 +#define MICROPY_HW_SPI2_NAME "Y" +#define MICROPY_HW_SPI2_NSS (pin_B12) // Y5 +#define MICROPY_HW_SPI2_SCK (pin_B13) // Y6 +#define MICROPY_HW_SPI2_MISO (pin_B14) // Y7 +#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8 + // USRSW has no pullup or pulldown, and pressing the switch makes the input go low #define MICROPY_HW_USRSW_PIN (pin_A13) #define MICROPY_HW_USRSW_PULL (GPIO_PULLUP) diff --git a/stmhal/boards/PYBV4/mpconfigboard.h b/stmhal/boards/PYBV4/mpconfigboard.h index 7ec31403f1..48e328604d 100644 --- a/stmhal/boards/PYBV4/mpconfigboard.h +++ b/stmhal/boards/PYBV4/mpconfigboard.h @@ -12,9 +12,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (1) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) // HSE is 8MHz @@ -56,7 +53,15 @@ // SPI busses #define MICROPY_HW_SPI1_NAME "X" +#define MICROPY_HW_SPI1_NSS (pin_A4) // X5 +#define MICROPY_HW_SPI1_SCK (pin_A5) // X6 +#define MICROPY_HW_SPI1_MISO (pin_A6) // X7 +#define MICROPY_HW_SPI1_MOSI (pin_A7) // X8 #define MICROPY_HW_SPI2_NAME "Y" +#define MICROPY_HW_SPI2_NSS (pin_B12) // Y5 +#define MICROPY_HW_SPI2_SCK (pin_B13) // Y6 +#define MICROPY_HW_SPI2_MISO (pin_B14) // Y7 +#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8 // CAN busses #define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9 diff --git a/stmhal/boards/STM32F411DISC/mpconfigboard.h b/stmhal/boards/STM32F411DISC/mpconfigboard.h index e1293dfc7b..57ae542df1 100644 --- a/stmhal/boards/STM32F411DISC/mpconfigboard.h +++ b/stmhal/boards/STM32F411DISC/mpconfigboard.h @@ -12,9 +12,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (0) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (0) // HSE is 8MHz @@ -44,6 +41,16 @@ #define MICROPY_HW_I2C3_SCL (pin_A8) #define MICROPY_HW_I2C3_SDA (pin_A9) +// SPI busses +#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) +#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) + // USRSW is pulled low. Pressing the button makes the input go high. #define MICROPY_HW_USRSW_PIN (pin_A0) #define MICROPY_HW_USRSW_PULL (GPIO_NOPULL) diff --git a/stmhal/boards/STM32F429DISC/mpconfigboard.h b/stmhal/boards/STM32F429DISC/mpconfigboard.h index cbf5674031..dc4059d030 100644 --- a/stmhal/boards/STM32F429DISC/mpconfigboard.h +++ b/stmhal/boards/STM32F429DISC/mpconfigboard.h @@ -11,9 +11,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (0) #define MICROPY_HW_ENABLE_DAC (0) -#define MICROPY_HW_ENABLE_SPI1 (0) -#define MICROPY_HW_ENABLE_SPI2 (0) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) // HSE is 8MHz diff --git a/stmhal/boards/STM32F4DISC/mpconfigboard.h b/stmhal/boards/STM32F4DISC/mpconfigboard.h index 30a05ef972..edfca36704 100644 --- a/stmhal/boards/STM32F4DISC/mpconfigboard.h +++ b/stmhal/boards/STM32F4DISC/mpconfigboard.h @@ -13,9 +13,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (0) #define MICROPY_HW_ENABLE_DAC (1) -#define MICROPY_HW_ENABLE_SPI1 (1) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) // HSE is 8MHz @@ -46,6 +43,16 @@ #define MICROPY_HW_I2C2_SCL (pin_B10) #define MICROPY_HW_I2C2_SDA (pin_B11) +// SPI busses +#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) +#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) + // USRSW is pulled low. Pressing the button makes the input go high. #define MICROPY_HW_USRSW_PIN (pin_A0) #define MICROPY_HW_USRSW_PULL (GPIO_NOPULL) diff --git a/stmhal/boards/STM32F7DISC/mpconfigboard.h b/stmhal/boards/STM32F7DISC/mpconfigboard.h index b6e8cfafbc..bc2f3fdc74 100644 --- a/stmhal/boards/STM32F7DISC/mpconfigboard.h +++ b/stmhal/boards/STM32F7DISC/mpconfigboard.h @@ -13,9 +13,6 @@ #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (0) #define MICROPY_HW_ENABLE_DAC (0) -#define MICROPY_HW_ENABLE_SPI1 (0) -#define MICROPY_HW_ENABLE_SPI2 (1) -#define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) #define MICROPY_BOARD_EARLY_INIT STM32F7DISC_board_early_init diff --git a/stmhal/boards/make-pins.py b/stmhal/boards/make-pins.py index 822a093406..b7f4842144 100755 --- a/stmhal/boards/make-pins.py +++ b/stmhal/boards/make-pins.py @@ -20,7 +20,7 @@ SUPPORTED_FN = { CONDITIONAL_VAR = { 'I2C' : 'MICROPY_HW_I2C{num}_SCL', 'I2S' : 'MICROPY_HW_ENABLE_I2S{num}', - 'SPI' : 'MICROPY_HW_ENABLE_SPI{num}', + 'SPI' : 'MICROPY_HW_SPI{num}_SCK', 'UART' : 'MICROPY_HW_UART{num}_PORT', 'UART5' : 'MICROPY_HW_UART5_TX_PORT', 'USART' : 'MICROPY_HW_UART{num}_PORT', diff --git a/stmhal/spi.c b/stmhal/spi.c index 01b9665b53..f2036aadd7 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -37,30 +37,6 @@ #include "dma.h" #include "spi.h" -// 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 /// @@ -102,48 +78,48 @@ typedef struct _pyb_spi_obj_t { uint32_t rx_dma_channel; } pyb_spi_obj_t; -#if MICROPY_HW_ENABLE_SPI1 +#if defined(MICROPY_HW_SPI1_SCK) SPI_HandleTypeDef SPIHandle1 = {.Instance = NULL}; #endif -#if MICROPY_HW_ENABLE_SPI2 +#if defined(MICROPY_HW_SPI2_SCK) SPI_HandleTypeDef SPIHandle2 = {.Instance = NULL}; #endif -#if MICROPY_HW_ENABLE_SPI3 +#if defined(MICROPY_HW_SPI3_SCK) SPI_HandleTypeDef SPIHandle3 = {.Instance = NULL}; #endif STATIC const pyb_spi_obj_t pyb_spi_obj[] = { -#if MICROPY_HW_ENABLE_SPI1 + #if defined(MICROPY_HW_SPI1_SCK) {{&pyb_spi_type}, &SPIHandle1, DMA_STREAM_SPI1_TX, DMA_CHANNEL_SPI1_TX, DMA_STREAM_SPI1_RX, DMA_CHANNEL_SPI1_RX}, -#else + #else {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0}, -#endif -#if MICROPY_HW_ENABLE_SPI2 + #endif + #if defined(MICROPY_HW_SPI2_SCK) {{&pyb_spi_type}, &SPIHandle2, DMA_STREAM_SPI2_TX, DMA_CHANNEL_SPI2_TX, DMA_STREAM_SPI2_RX, DMA_CHANNEL_SPI2_RX}, -#else + #else {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0}, -#endif -#if MICROPY_HW_ENABLE_SPI3 + #endif + #if defined(MICROPY_HW_SPI3_SCK) {{&pyb_spi_type}, &SPIHandle3, DMA_STREAM_SPI3_TX, DMA_CHANNEL_SPI3_TX, DMA_STREAM_SPI3_RX, DMA_CHANNEL_SPI3_RX}, -#else + #else {{&pyb_spi_type}, NULL, NULL, 0, NULL, 0}, -#endif + #endif }; void spi_init0(void) { // reset the SPI handles -#if MICROPY_HW_ENABLE_SPI1 + #if defined(MICROPY_HW_SPI1_SCK) memset(&SPIHandle1, 0, sizeof(SPI_HandleTypeDef)); SPIHandle1.Instance = SPI1; -#endif -#if MICROPY_HW_ENABLE_SPI2 + #endif + #if defined(MICROPY_HW_SPI2_SCK) memset(&SPIHandle2, 0, sizeof(SPI_HandleTypeDef)); SPIHandle2.Instance = SPI2; -#endif -#if MICROPY_HW_ENABLE_SPI3 + #endif + #if defined(MICROPY_HW_SPI3_SCK) memset(&SPIHandle3, 0, sizeof(SPI_HandleTypeDef)); SPIHandle3.Instance = SPI3; -#endif + #endif } // TODO allow to take a list of pins to use @@ -158,7 +134,7 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) { const pin_obj_t *pins[4]; if (0) { -#if MICROPY_HW_ENABLE_SPI1 + #if defined(MICROPY_HW_SPI1_SCK) } else if (spi->Instance == SPI1) { self = &pyb_spi_obj[0]; pins[0] = &MICROPY_HW_SPI1_NSS; @@ -168,8 +144,8 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) { GPIO_InitStructure.Alternate = GPIO_AF5_SPI1; // enable the SPI clock __SPI1_CLK_ENABLE(); -#endif -#if MICROPY_HW_ENABLE_SPI2 + #endif + #if defined(MICROPY_HW_SPI2_SCK) } else if (spi->Instance == SPI2) { self = &pyb_spi_obj[1]; pins[0] = &MICROPY_HW_SPI2_NSS; @@ -179,8 +155,8 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) { GPIO_InitStructure.Alternate = GPIO_AF5_SPI2; // enable the SPI clock __SPI2_CLK_ENABLE(); -#endif -#if MICROPY_HW_ENABLE_SPI3 + #endif + #if defined(MICROPY_HW_SPI3_SCK) } else if (spi->Instance == SPI3) { self = &pyb_spi_obj[2]; pins[0] = &MICROPY_HW_SPI3_NSS; @@ -190,7 +166,7 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) { GPIO_InitStructure.Alternate = GPIO_AF6_SPI3; // enable the SPI clock __SPI3_CLK_ENABLE(); -#endif + #endif } else { // SPI does not exist for this board (shouldn't get here, should be checked by caller) return; @@ -221,24 +197,24 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) { void spi_deinit(SPI_HandleTypeDef *spi) { HAL_SPI_DeInit(spi); if (0) { -#if MICROPY_HW_ENABLE_SPI1 + #if defined(MICROPY_HW_SPI1_SCK) } else if (spi->Instance == SPI1) { __SPI1_FORCE_RESET(); __SPI1_RELEASE_RESET(); __SPI1_CLK_DISABLE(); -#endif -#if MICROPY_HW_ENABLE_SPI2 + #endif + #if defined(MICROPY_HW_SPI2_SCK) } else if (spi->Instance == SPI2) { __SPI2_FORCE_RESET(); __SPI2_RELEASE_RESET(); __SPI2_CLK_DISABLE(); -#endif -#if MICROPY_HW_ENABLE_SPI3 + #endif + #if defined(MICROPY_HW_SPI3_SCK) } else if (spi->Instance == SPI3) { __SPI3_FORCE_RESET(); __SPI3_RELEASE_RESET(); __SPI3_CLK_DISABLE(); -#endif + #endif } }