summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal
diff options
context:
space:
mode:
Diffstat (limited to 'stmhal')
-rw-r--r--stmhal/boards/STM32F429DISC/mpconfigboard.h4
-rw-r--r--stmhal/mpconfigport.h6
-rw-r--r--stmhal/spi.c15
3 files changed, 19 insertions, 6 deletions
diff --git a/stmhal/boards/STM32F429DISC/mpconfigboard.h b/stmhal/boards/STM32F429DISC/mpconfigboard.h
index e6c2fc9ef6..f2cf6c1422 100644
--- a/stmhal/boards/STM32F429DISC/mpconfigboard.h
+++ b/stmhal/boards/STM32F429DISC/mpconfigboard.h
@@ -29,8 +29,8 @@
#define MICROPY_HW_UART2_PINS (GPIO_PIN_8 | GPIO_PIN_9)
// I2C busses
-#define MICROPY_HW_I2C1_SCL (pin_A8)
-#define MICROPY_HW_I2C1_SDA (pin_C9)
+#define MICROPY_HW_I2C3_SCL (pin_A8)
+#define MICROPY_HW_I2C3_SDA (pin_C9)
// SPI busses
//#define MICROPY_HW_SPI1_NSS (pin_A4)
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h
index 29e4bd8d87..c2a2cbc1f1 100644
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -235,9 +235,9 @@ static inline mp_uint_t disable_irq(void) {
// garbage-collected heap. For completeness, emulate C heap via
// GC heap. Note that MicroPython core never uses malloc() and friends,
// so these defines are mostly to help extension module writers.
-#define malloc gc_alloc
-#define free gc_free
-#define realloc gc_realloc
+#define malloc(n) m_malloc(n)
+#define free(p) m_free(p)
+#define realloc(p, n) m_realloc(p, n)
// see stm32f4XX_hal_conf.h USE_USB_FS & USE_USB_HS
// at the moment only USB_FS is supported
diff --git a/stmhal/spi.c b/stmhal/spi.c
index 387fc174c4..fbc5f9aa48 100644
--- a/stmhal/spi.c
+++ b/stmhal/spi.c
@@ -172,12 +172,15 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
const pyb_spi_obj_t *self;
const pin_obj_t *pins[4];
+ pins[0] = NULL;
if (0) {
#if defined(MICROPY_HW_SPI1_SCK)
} else if (spi->Instance == SPI1) {
self = &pyb_spi_obj[0];
+ #if defined(MICROPY_HW_SPI1_NSS)
pins[0] = &MICROPY_HW_SPI1_NSS;
+ #endif
pins[1] = &MICROPY_HW_SPI1_SCK;
pins[2] = &MICROPY_HW_SPI1_MISO;
pins[3] = &MICROPY_HW_SPI1_MOSI;
@@ -187,7 +190,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
#if defined(MICROPY_HW_SPI2_SCK)
} else if (spi->Instance == SPI2) {
self = &pyb_spi_obj[1];
+ #if defined(MICROPY_HW_SPI2_NSS)
pins[0] = &MICROPY_HW_SPI2_NSS;
+ #endif
pins[1] = &MICROPY_HW_SPI2_SCK;
pins[2] = &MICROPY_HW_SPI2_MISO;
pins[3] = &MICROPY_HW_SPI2_MOSI;
@@ -197,7 +202,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
#if defined(MICROPY_HW_SPI3_SCK)
} else if (spi->Instance == SPI3) {
self = &pyb_spi_obj[2];
+ #if defined(MICROPY_HW_SPI3_NSS)
pins[0] = &MICROPY_HW_SPI3_NSS;
+ #endif
pins[1] = &MICROPY_HW_SPI3_SCK;
pins[2] = &MICROPY_HW_SPI3_MISO;
pins[3] = &MICROPY_HW_SPI3_MOSI;
@@ -207,7 +214,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
#if defined(MICROPY_HW_SPI4_SCK)
} else if (spi->Instance == SPI4) {
self = &pyb_spi_obj[3];
+ #if defined(MICROPY_HW_SPI4_NSS)
pins[0] = &MICROPY_HW_SPI4_NSS;
+ #endif
pins[1] = &MICROPY_HW_SPI4_SCK;
pins[2] = &MICROPY_HW_SPI4_MISO;
pins[3] = &MICROPY_HW_SPI4_MOSI;
@@ -217,7 +226,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
#if defined(MICROPY_HW_SPI5_SCK)
} else if (spi->Instance == SPI5) {
self = &pyb_spi_obj[4];
+ #if defined(MICROPY_HW_SPI5_NSS)
pins[0] = &MICROPY_HW_SPI5_NSS;
+ #endif
pins[1] = &MICROPY_HW_SPI5_SCK;
pins[2] = &MICROPY_HW_SPI5_MISO;
pins[3] = &MICROPY_HW_SPI5_MOSI;
@@ -227,7 +238,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
#if defined(MICROPY_HW_SPI6_SCK)
} else if (spi->Instance == SPI6) {
self = &pyb_spi_obj[5];
+ #if defined(MICROPY_HW_SPI6_NSS)
pins[0] = &MICROPY_HW_SPI6_NSS;
+ #endif
pins[1] = &MICROPY_HW_SPI6_SCK;
pins[2] = &MICROPY_HW_SPI6_MISO;
pins[3] = &MICROPY_HW_SPI6_MOSI;
@@ -239,7 +252,7 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
return;
}
- for (uint i = (enable_nss_pin ? 0 : 1); i < 4; i++) {
+ for (uint i = (enable_nss_pin && pins[0] ? 0 : 1); i < 4; i++) {
mp_hal_gpio_set_af(pins[i], &GPIO_InitStructure, AF_FN_SPI, (self - &pyb_spi_obj[0]) + 1);
}