summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/mimxrt/machine_i2c.c2
-rw-r--r--ports/mimxrt/machine_spi.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/ports/mimxrt/machine_i2c.c b/ports/mimxrt/machine_i2c.c
index 618d0a258..58dd82449 100644
--- a/ports/mimxrt/machine_i2c.c
+++ b/ports/mimxrt/machine_i2c.c
@@ -109,7 +109,7 @@ mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
// Get I2C bus.
int i2c_id = mp_obj_get_int(args[ARG_id].u_obj);
- if (i2c_id < 0 || i2c_id >= MICROPY_HW_I2C_NUM) {
+ if (i2c_id < 0 || i2c_id >= MICROPY_HW_I2C_NUM || i2c_index_table[i2c_id] == 0) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
}
diff --git a/ports/mimxrt/machine_spi.c b/ports/mimxrt/machine_spi.c
index 41843b06d..c7ee226bf 100644
--- a/ports/mimxrt/machine_spi.c
+++ b/ports/mimxrt/machine_spi.c
@@ -137,7 +137,7 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
// Get the SPI bus id.
int spi_id = mp_obj_get_int(args[ARG_id].u_obj);
- if (spi_id < 0 || spi_id >= MP_ARRAY_SIZE(spi_index_table)) {
+ if (spi_id < 0 || spi_id >= MP_ARRAY_SIZE(spi_index_table) || spi_index_table[spi_id] == 0) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SPI(%d) doesn't exist"), spi_id);
}