|
37 | 37 | #include "spi.h" |
38 | 38 | #include MICROPY_HAL_H |
39 | 39 |
|
40 | | -#if !defined(STM32F7) |
41 | | -// The STM32F7 has the SPI pins mapped differently. Need to figure this out |
42 | | -// before enabling SPI for the F7 |
| 40 | +// The following defines are for compatability with the '405 |
| 41 | +#if !defined(MICROPY_HW_SPI1_NSS) |
| 42 | +// X-skin: X5=PA4=SPI1_NSS, X6=PA5=SPI1_SCK, X7=PA6=SPI1_MISO, X8=PA7=SPI1_MOSI |
| 43 | +#define MICROPY_HW_SPI1_NSS (pin_A4) |
| 44 | +#define MICROPY_HW_SPI1_SCK (pin_A5) |
| 45 | +#define MICROPY_HW_SPI1_MISO (pin_A6) |
| 46 | +#define MICROPY_HW_SPI1_MOSI (pin_A7) |
| 47 | +#endif |
| 48 | + |
| 49 | +#if !defined(MICROPY_HW_SPI2_NSS) |
| 50 | +// Y-skin: Y5=PB12=SPI2_NSS, Y6=PB13=SPI2_SCK, Y7=PB14=SPI2_MISO, Y8=PB15=SPI2_MOSI |
| 51 | +#define MICROPY_HW_SPI2_NSS (pin_B12) |
| 52 | +#define MICROPY_HW_SPI2_SCK (pin_B13) |
| 53 | +#define MICROPY_HW_SPI2_MISO (pin_B14) |
| 54 | +#define MICROPY_HW_SPI2_MOSI (pin_B15) |
| 55 | +#endif |
| 56 | + |
| 57 | +#if !defined(MICROPY_HW_SPI3_NSS) |
| 58 | +#define MICROPY_HW_SPI3_NSS (pin_A4) |
| 59 | +#define MICROPY_HW_SPI3_SCK (pin_B3) |
| 60 | +#define MICROPY_HW_SPI3_MISO (pin_B4) |
| 61 | +#define MICROPY_HW_SPI3_MOSI (pin_B5) |
| 62 | +#endif |
43 | 63 |
|
44 | 64 | /// \moduleref pyb |
45 | 65 | /// \class SPI - a master-driven serial protocol |
@@ -140,35 +160,33 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) { |
140 | 160 | if (0) { |
141 | 161 | #if MICROPY_HW_ENABLE_SPI1 |
142 | 162 | } else if (spi->Instance == SPI1) { |
143 | | - // X-skin: X5=PA4=SPI1_NSS, X6=PA5=SPI1_SCK, X7=PA6=SPI1_MISO, X8=PA7=SPI1_MOSI |
144 | 163 | self = &pyb_spi_obj[0]; |
145 | | - pins[0] = &pin_A4; |
146 | | - pins[1] = &pin_A5; |
147 | | - pins[2] = &pin_A6; |
148 | | - pins[3] = &pin_A7; |
| 164 | + pins[0] = &MICROPY_HW_SPI1_NSS; |
| 165 | + pins[1] = &MICROPY_HW_SPI1_SCK; |
| 166 | + pins[2] = &MICROPY_HW_SPI1_MISO; |
| 167 | + pins[3] = &MICROPY_HW_SPI1_MOSI; |
149 | 168 | GPIO_InitStructure.Alternate = GPIO_AF5_SPI1; |
150 | 169 | // enable the SPI clock |
151 | 170 | __SPI1_CLK_ENABLE(); |
152 | 171 | #endif |
153 | 172 | #if MICROPY_HW_ENABLE_SPI2 |
154 | 173 | } else if (spi->Instance == SPI2) { |
155 | | - // Y-skin: Y5=PB12=SPI2_NSS, Y6=PB13=SPI2_SCK, Y7=PB14=SPI2_MISO, Y8=PB15=SPI2_MOSI |
156 | 174 | self = &pyb_spi_obj[1]; |
157 | | - pins[0] = &pin_B12; |
158 | | - pins[1] = &pin_B13; |
159 | | - pins[2] = &pin_B14; |
160 | | - pins[3] = &pin_B15; |
| 175 | + pins[0] = &MICROPY_HW_SPI2_NSS; |
| 176 | + pins[1] = &MICROPY_HW_SPI2_SCK; |
| 177 | + pins[2] = &MICROPY_HW_SPI2_MISO; |
| 178 | + pins[3] = &MICROPY_HW_SPI2_MOSI; |
161 | 179 | GPIO_InitStructure.Alternate = GPIO_AF5_SPI2; |
162 | 180 | // enable the SPI clock |
163 | 181 | __SPI2_CLK_ENABLE(); |
164 | 182 | #endif |
165 | 183 | #if MICROPY_HW_ENABLE_SPI3 |
166 | 184 | } else if (spi->Instance == SPI3) { |
167 | 185 | self = &pyb_spi_obj[2]; |
168 | | - pins[0] = &pin_A4; |
169 | | - pins[1] = &pin_B3; |
170 | | - pins[2] = &pin_B4; |
171 | | - pins[3] = &pin_B5; |
| 186 | + pins[0] = &MICROPY_HW_SPI3_NSS; |
| 187 | + pins[1] = &MICROPY_HW_SPI3_SCK; |
| 188 | + pins[2] = &MICROPY_HW_SPI3_MISO; |
| 189 | + pins[3] = &MICROPY_HW_SPI3_MOSI; |
172 | 190 | GPIO_InitStructure.Alternate = GPIO_AF6_SPI3; |
173 | 191 | // enable the SPI clock |
174 | 192 | __SPI3_CLK_ENABLE(); |
@@ -670,5 +688,3 @@ const mp_obj_type_t pyb_spi_type = { |
670 | 688 | .make_new = pyb_spi_make_new, |
671 | 689 | .locals_dict = (mp_obj_t)&pyb_spi_locals_dict, |
672 | 690 | }; |
673 | | - |
674 | | -#endif // STM32F7 |
|
0 commit comments