From 8e00c7bb7f49fdb54235588d092deafcddd5d6e0 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 20 Apr 2023 21:11:04 +0200 Subject: [PATCH 01/11] mimxrt/WLAN: Support external NINA10 modules for WLAN. Using the network.WLAN module with Pin settings defined in mpconfigboard.h. To allow for port specific WiFi configurations, the functions in drivers/ninaw10/nina_wifi_bsp.c are declared as MP_WEAK. Signed-off-by: robert-hh --- drivers/ninaw10/nina_wifi_bsp.c | 53 +++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/drivers/ninaw10/nina_wifi_bsp.c b/drivers/ninaw10/nina_wifi_bsp.c index dc71c8260c61..04a20b2efb28 100644 --- a/drivers/ninaw10/nina_wifi_bsp.c +++ b/drivers/ninaw10/nina_wifi_bsp.c @@ -46,15 +46,22 @@ #define debug_printf(...) #endif -int nina_bsp_init(void) { - mp_hal_pin_output(MICROPY_HW_NINA_GPIO1); +// Use the name CS instead of GPIO1 +#ifndef MICROPY_HW_NINA_CS +#define MICROPY_HW_NINA_CS MICROPY_HW_NINA_GPIO1 +#endif + +MP_WEAK int nina_bsp_init(void) { + mp_hal_pin_output(MICROPY_HW_NINA_CS); mp_hal_pin_input(MICROPY_HW_NINA_ACK); mp_hal_pin_output(MICROPY_HW_NINA_RESET); + #ifdef MICROPY_HW_NINA_GPIO0 mp_hal_pin_output(MICROPY_HW_NINA_GPIO0); + mp_hal_pin_write(MICROPY_HW_NINA_GPIO0, 1); + #endif // Reset module in WiFi mode - mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 1); - mp_hal_pin_write(MICROPY_HW_NINA_GPIO0, 1); + mp_hal_pin_write(MICROPY_HW_NINA_CS, 1); mp_hal_pin_write(MICROPY_HW_NINA_RESET, 0); mp_hal_delay_ms(100); @@ -62,51 +69,59 @@ int nina_bsp_init(void) { mp_hal_pin_write(MICROPY_HW_NINA_RESET, 1); mp_hal_delay_ms(750); - mp_hal_pin_write(MICROPY_HW_NINA_GPIO0, 0); + #ifdef MICROPY_HW_NINA_GPIO0 mp_hal_pin_input(MICROPY_HW_NINA_GPIO0); + #endif // Initialize SPI. mp_obj_t args[] = { MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIFI_SPI_ID), MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIFI_SPI_BAUDRATE), }; - - MP_STATE_PORT(mp_wifi_spi) = MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, make_new)((mp_obj_t)&machine_spi_type, 2, 0, args); + MP_STATE_PORT(mp_wifi_spi) = MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, make_new)( + (mp_obj_t)&machine_spi_type, 2, 0, args); return 0; } -int nina_bsp_deinit(void) { - mp_hal_pin_output(MICROPY_HW_NINA_GPIO1); - mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 1); +MP_WEAK int nina_bsp_deinit(void) { + mp_hal_pin_output(MICROPY_HW_NINA_CS); + mp_hal_pin_write(MICROPY_HW_NINA_CS, 1); mp_hal_pin_output(MICROPY_HW_NINA_RESET); mp_hal_pin_write(MICROPY_HW_NINA_RESET, 0); mp_hal_delay_ms(100); + #ifdef MICROPY_HW_NINA_GPIO0 mp_hal_pin_output(MICROPY_HW_NINA_GPIO0); mp_hal_pin_write(MICROPY_HW_NINA_GPIO0, 1); + #endif + return 0; } -int nina_bsp_atomic_enter(void) { +MP_WEAK int nina_bsp_atomic_enter(void) { #if MICROPY_ENABLE_SCHEDULER mp_sched_lock(); #endif return 0; } -int nina_bsp_atomic_exit(void) { +MP_WEAK int nina_bsp_atomic_exit(void) { #if MICROPY_ENABLE_SCHEDULER mp_sched_unlock(); #endif return 0; } -int nina_bsp_read_irq(void) { +MP_WEAK int nina_bsp_read_irq(void) { + #ifdef MICROPY_HW_NINA_GPIO0 return mp_hal_pin_read(MICROPY_HW_NINA_GPIO0); + #else + return 1; + #endif } -int nina_bsp_spi_slave_select(uint32_t timeout) { +MP_WEAK int nina_bsp_spi_slave_select(uint32_t timeout) { // Wait for ACK to go low. for (mp_uint_t start = mp_hal_ticks_ms(); mp_hal_pin_read(MICROPY_HW_NINA_ACK) == 1; mp_hal_delay_ms(1)) { if (timeout && ((mp_hal_ticks_ms() - start) >= timeout)) { @@ -115,12 +130,12 @@ int nina_bsp_spi_slave_select(uint32_t timeout) { } // Chip select. - mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 0); + mp_hal_pin_write(MICROPY_HW_NINA_CS, 0); // Wait for ACK to go high. for (mp_uint_t start = mp_hal_ticks_ms(); mp_hal_pin_read(MICROPY_HW_NINA_ACK) == 0; mp_hal_delay_ms(1)) { if ((mp_hal_ticks_ms() - start) >= 100) { - mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 1); + mp_hal_pin_write(MICROPY_HW_NINA_CS, 1); return -1; } } @@ -128,12 +143,12 @@ int nina_bsp_spi_slave_select(uint32_t timeout) { return 0; } -int nina_bsp_spi_slave_deselect(void) { - mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 1); +MP_WEAK int nina_bsp_spi_slave_deselect(void) { + mp_hal_pin_write(MICROPY_HW_NINA_CS, 1); return 0; } -int nina_bsp_spi_transfer(const uint8_t *tx_buf, uint8_t *rx_buf, uint32_t size) { +MP_WEAK int nina_bsp_spi_transfer(const uint8_t *tx_buf, uint8_t *rx_buf, uint32_t size) { mp_obj_t mp_wifi_spi = MP_STATE_PORT(mp_wifi_spi); ((mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, protocol))->transfer(mp_wifi_spi, size, tx_buf, rx_buf); #if NINA_DEBUG From ff872dec2e548c579b133f8f5cf88e8e36003f8d Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 20 Apr 2023 21:13:12 +0200 Subject: [PATCH 02/11] mimxrt/WLAN: Adapt the mimxrt port files. Change Makefile and mpconfigport.h. Add a port specific nina_wifi_bsp.c file, which just increases the poll rate. The flag for enabling NinaW10 is MICROPY_PY_NETWORK_NINAW10. Signed-off-by: robert-hh --- ports/mimxrt/Makefile | 12 ++++++ ports/mimxrt/mpconfigport.h | 27 ++++++++++++-- ports/mimxrt/nina_wifi_bsp.c | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 ports/mimxrt/nina_wifi_bsp.c diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index 7788b54ca57f..b5d97399a993 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -120,6 +120,17 @@ SRC_ETH_C += \ hal/phy/mdio/enet/fsl_enet_mdio.c endif +ifeq ($(MICROPY_PY_NETWORK_NINAW10),1) +CFLAGS += -DMICROPY_PY_NETWORK_NINAW10=1 +INC += -I$(TOP)/drivers/ninaw10 + +SRC_C += \ + drivers/ninaw10/nina_bt_hci.c \ + drivers/ninaw10/nina_wifi_drv.c \ + drivers/ninaw10/nina_wifi_bsp.c \ + drivers/ninaw10/machine_pin_nina.c +endif + # NXP SDK sources SRC_HAL_IMX_C += \ $(MCU_DIR)/drivers/fsl_clock.c \ @@ -219,6 +230,7 @@ SRC_C += \ mpnetworkport.c \ msc_disk.c \ network_lan.c \ + nina_wifi_bsp.c \ pendsv.c \ pin.c \ sdcard.c \ diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 9a7dfc630f32..dfb7380b2f2c 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -57,6 +57,7 @@ uint32_t trng_random_u32(void); #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_SCHEDULER_DEPTH (8) +#define MICROPY_ENABLE_SCHEDULER (1) #define MICROPY_SCHEDULER_STATIC_NODES (1) #define MICROPY_VFS (1) @@ -135,9 +136,14 @@ uint32_t trng_random_u32(void); #ifndef MICROPY_PY_SOCKET #define MICROPY_PY_SOCKET (1) #endif -#define MICROPY_PY_WEBSOCKET (MICROPY_PY_LWIP) -#define MICROPY_PY_WEBREPL (MICROPY_PY_LWIP) + +#ifndef MICROPY_PY_SSL +#define MICROPY_PY_SSL (1) +#endif +#define MICROPY_PY_WEBSOCKET (MICROPY_PY_LWIP || MICROPY_PY_NETWORK_NINAW10) +#define MICROPY_PY_WEBREPL (MICROPY_PY_LWIP || MICROPY_PY_NETWORK_NINAW10) #define MICROPY_PY_LWIP_SOCK_RAW (MICROPY_PY_LWIP) +#define MICROPY_PY_SSL_FINALISER (MICROPY_PY_SSL) #define MICROPY_PY_HASHLIB_MD5 (MICROPY_PY_SSL) #define MICROPY_PY_HASHLIB_SHA1 (MICROPY_PY_SSL) #define MICROPY_PY_CRYPTOLIB (MICROPY_PY_SSL) @@ -178,6 +184,20 @@ extern const struct _mp_obj_type_t network_lan_type; #define MICROPY_HW_NIC_ETH #endif +#if MICROPY_PY_NETWORK_NINAW10 +// This Network interface requires the extended socket state. +#ifndef MICROPY_PY_SOCKET_EXTENDED_STATE +#define MICROPY_PY_SOCKET_EXTENDED_STATE (1) +#endif +extern const struct _mp_obj_type_t mod_network_nic_type_nina; +#define MICROPY_HW_NIC_NINAW10 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_nina) }, + +#else + +#define MICROPY_HW_NIC_NINAW10 + +#endif // MICROPY_PY_NETWORK_NINAW10 + #if MICROPY_PY_NETWORK_CYW43 extern const struct _mp_obj_type_t mp_network_cyw43_type; #define MICROPY_HW_NIC_CYW43 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) }, @@ -192,7 +212,8 @@ extern const struct _mp_obj_type_t mp_network_cyw43_type; #define MICROPY_PORT_NETWORK_INTERFACES \ MICROPY_HW_NIC_ETH \ MICROPY_HW_NIC_CYW43 \ - MICROPY_BOARD_NETWORK_INTERFACES \ + MICROPY_HW_NIC_NINAW10 \ + MICROPY_BOARD_NETWORK_INTERFACES #ifndef MICROPY_BOARD_ROOT_POINTERS #define MICROPY_BOARD_ROOT_POINTERS diff --git a/ports/mimxrt/nina_wifi_bsp.c b/ports/mimxrt/nina_wifi_bsp.c new file mode 100644 index 000000000000..3adc437c624f --- /dev/null +++ b/ports/mimxrt/nina_wifi_bsp.c @@ -0,0 +1,72 @@ +/* + * This file is part of the OpenMV project, https://openmv.io. + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2021 Ibrahim Abdelkader + * Copyright (c) 2013-2021 Kwabena W. Agyeman + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * NINA-W10 driver BSP implementation. + */ + +#include "py/mphal.h" + +#if MICROPY_PY_NETWORK_NINAW10 + +#include +#include + +#include "py/runtime.h" +#include "modmachine.h" +#include "mpconfigboard.h" + +#include "nina_bsp.h" +#include "nina_wifi_drv.h" + +#if NINA_DEBUG +#define debug_printf(...) mp_printf(&mp_plat_print, __VA_ARGS__) +#else +#define debug_printf(...) +#endif + +int nina_bsp_spi_slave_select(uint32_t timeout) { + // Wait for ACK to go low. + for (mp_uint_t start = mp_hal_ticks_ms(); mp_hal_pin_read(MICROPY_HW_NINA_ACK) == 1; mp_hal_delay_us(100)) { + if (timeout && ((mp_hal_ticks_ms() - start) >= timeout)) { + return -1; + } + } + + // Chip select. + mp_hal_pin_write(MICROPY_HW_NINA_CS, 0); + + // Wait for ACK to go high. + for (mp_uint_t start = mp_hal_ticks_ms(); mp_hal_pin_read(MICROPY_HW_NINA_ACK) == 0; mp_hal_delay_us(100)) { + if ((mp_hal_ticks_ms() - start) >= 100) { + mp_hal_pin_write(MICROPY_HW_NINA_CS, 1); + return -1; + } + } + + return 0; +} + +#endif // MICROPY_PY_NETWORK_NINAW10 From bfbdbd7e2e6fcf92f209e59627b6122b018340ef Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 20 Apr 2023 21:14:50 +0200 Subject: [PATCH 03/11] mimxrt/WLAN: Add Pin definitions for MIMXRT Boards. - MIMXRT1010_EVK - MIMXRT1015_EVK - ADAFRUIT Metro M7 For the *_EVK boards the pins are those used by the Adafruit Airlift shield. Signed-off-by: robert-hh --- .../mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h | 13 +++++++++---- ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h | 10 ++++++++++ ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk | 4 ++++ ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h | 10 ++++++++++ ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk | 3 +++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h index 1ce06e7f408d..da4534acb558 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h @@ -58,9 +58,12 @@ #define MICROPY_HW_WIFI_SPI_ID (0) #define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) -#define MICROPY_HW_NINA_ACK pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_ESP_BUSY)) -#define MICROPY_HW_NINA_CS pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_ESP_CS)) -#define MICROPY_HW_NINA_RESET pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_ESP_RESET)) +// ESP_BUSY: GPIO_AD_11 +#define MICROPY_HW_NINA_ACK (&pin_GPIO_AD_11) +// ESP_CS: GPIO_AD_14 +#define MICROPY_HW_NINA_CS (&pin_GPIO_AD_14) +// ESP_RESET: GPIO_AD_07 +#define MICROPY_HW_NINA_RESET (&pin_GPIO_AD_07) // BLE definitions #define MICROPY_PY_BLUETOOTH_NINAW10 (1) @@ -68,5 +71,7 @@ #define MICROPY_HW_BLE_UART_ID (1) #define MICROPY_HW_BLE_UART_BAUDRATE (115200) -#define MICROPY_HW_NINA_RTS pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_MOSI)) +// MOSI == RTS: GPIO_AD_04 +#define MICROPY_HW_NINA_RTS (&pin_GPIO_AD_04) +// CTS == NINA_ACK: GPIO_AD_11 #define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h index a616fbec64a5..bce1cf175910 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h @@ -82,3 +82,13 @@ I2S_GPIO(1, WS, TX, GPIO_07, IOMUXC_GPIO_07_SAI1_TX_SYNC), \ I2S_GPIO(1, SD, TX, GPIO_04, IOMUXC_GPIO_04_SAI1_TX_DATA00), \ } + +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) + +// NINA_ACK: D7 = GPIO_AD_02 +#define MICROPY_HW_NINA_ACK (&pin_GPIO_AD_02) +// NINA_CS: D10 = GPIO_AD_05 +#define MICROPY_HW_NINA_CS (&pin_GPIO_AD_05) +// Adafruit shield: NINA_RESET: D5 = GPIO_01 +#define MICROPY_HW_NINA_RESET (&pin_GPIO_01) diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk index 592b89c68ecf..a6736b26c9bb 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk @@ -10,6 +10,10 @@ MICROPY_HW_FLASH_QE_ARG = 0x02 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK_NINAW10 ?= 1 +MICROPY_PY_SSL ?= 1 +MICROPY_SSL_MBEDTLS ?= 1 + JLINK_PATH ?= /media/RT1010-EVK/ JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink diff --git a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h index f47bbf4fa138..404b1f90093a 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h @@ -87,3 +87,13 @@ I2S_GPIO(1, WS, TX, GPIO_EMC_27, IOMUXC_GPIO_EMC_27_SAI1_TX_SYNC), \ I2S_GPIO(1, SD, TX, GPIO_EMC_25, IOMUXC_GPIO_EMC_25_SAI1_TX_DATA00), \ } + +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) + +// NINA_ACK: D7 = GPIO_AD_B0_15 +#define MICROPY_HW_NINA_ACK (&pin_GPIO_AD_B0_15) +// NINA_CS: D10 = GPIO_AD_B0_11 +#define MICROPY_HW_NINA_CS (&pin_GPIO_AD_B0_11) +// Adafruit shield: NINA_RESET: D5 = GPIO_EMC_27 +#define MICROPY_HW_NINA_RESET (&pin_GPIO_EMC_27) diff --git a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk index c5d02294bc3d..9422633fcc37 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk @@ -11,3 +11,6 @@ MICROPY_HW_FLASH_QE_ARG = 0x02 MICROPY_BOOT_BUFFER_SIZE = (32 * 1024) USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK_NINAW10 ?= 1 +MICROPY_PY_SSL ?= 1 +MICROPY_SSL_MBEDTLS ?= 1 From c85d7e71e6258fa29ca9aaf167c8b40a3334403a Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 20 Apr 2023 15:18:39 +0200 Subject: [PATCH 04/11] mimxrt/BLE: Change nina_bt_hci.c to support RTS and CTS. RTS must be low for operation. Allow CS as alias for GPIO1. Signed-off-by: robert-hh --- drivers/ninaw10/nina_bthci_uart.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/ninaw10/nina_bthci_uart.c b/drivers/ninaw10/nina_bthci_uart.c index 50631711097f..11a4ce573a26 100644 --- a/drivers/ninaw10/nina_bthci_uart.c +++ b/drivers/ninaw10/nina_bthci_uart.c @@ -5,6 +5,7 @@ * * Copyright (c) 2013-2021 Ibrahim Abdelkader * Copyright (c) 2013-2021 Kwabena W. Agyeman + * Copyright (c) 2023 Robert Hammelrath * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -53,12 +54,23 @@ #define error_printf(...) // mp_printf(&mp_plat_print, "nina_bthci_uart.c: " __VA_ARGS__) #define debug_printf(...) // mp_printf(&mp_plat_print, "nina_bthci_uart.c: " __VA_ARGS__) +// Use the name CS instead of GPIO1 +#ifndef MICROPY_HW_NINA_CS +#define MICROPY_HW_NINA_CS MICROPY_HW_NINA_GPIO1 +#endif + // Provided by the port, and also possibly shared with the stack. extern uint8_t mp_bluetooth_hci_cmd_buf[4 + 256]; static int nina_hci_cmd(int ogf, int ocf, size_t param_len, const uint8_t *param_buf) { uint8_t *buf = mp_bluetooth_hci_cmd_buf; + // Clear the UART input buffer before sending the reset command. + // The ESP32 reset message may stick in it. + while (mp_bluetooth_hci_uart_any()) { + mp_bluetooth_hci_uart_readchar(); + } + buf[0] = HCI_COMMAND_PACKET; buf[1] = ocf; buf[2] = ogf << 2 | ocf >> 8; @@ -125,8 +137,17 @@ int mp_bluetooth_hci_controller_init(void) { mp_hal_pin_output(MICROPY_HW_NINA_RESET); mp_hal_pin_write(MICROPY_HW_NINA_RESET, 0); - mp_hal_pin_output(MICROPY_HW_NINA_GPIO1); - mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 0); + // care for dedicated setting of RTS/CTS + #ifdef MICROPY_HW_NINA_RTS + mp_hal_pin_output(MICROPY_HW_NINA_RTS); + mp_hal_pin_write(MICROPY_HW_NINA_RTS, 0); + #endif + #ifdef MICROPY_HW_NINA_CTS + mp_hal_pin_input(MICROPY_HW_NINA_CTS); + #endif + + mp_hal_pin_output(MICROPY_HW_NINA_CS); + mp_hal_pin_write(MICROPY_HW_NINA_CS, 0); mp_hal_delay_ms(150); mp_hal_pin_write(MICROPY_HW_NINA_RESET, 1); From 300b262d667089acfa0e31fecd7f2c3d3f3aecfe Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 23 Apr 2023 11:15:42 +0200 Subject: [PATCH 05/11] mimxrt/BLE: Change main.c, pendsv.h, mpconfigport.h, Makefile for BLE. And reduce the stack size for BLE. Nibmle uses 13k of static data, increasing the .bss section. Moving the stack or bss to OCRM is possible, but reduces the Python heap size. Signed-off-by: robert-hh --- ports/mimxrt/Makefile | 16 +++++++++ .../boards/ADAFRUIT_METRO_M7/mpconfigboard.h | 19 ++++++++++ ports/mimxrt/boards/MIMXRT1011.ld | 4 +-- ports/mimxrt/boards/MIMXRT1015.ld | 4 +-- ports/mimxrt/boards/manifest.py | 7 ++++ ports/mimxrt/main.c | 36 ++++++++++++++++--- ports/mimxrt/mpconfigport.h | 14 ++++++-- ports/mimxrt/pendsv.h | 3 ++ 8 files changed, 92 insertions(+), 11 deletions(-) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index b5d97399a993..e55182ca143e 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -50,6 +50,7 @@ FROZEN_MANIFEST ?= boards/manifest.py # Include py core make definitions include $(TOP)/py/py.mk include $(TOP)/extmod/extmod.mk +include ${TOP}/extmod/nimble/nimble.mk # Set SDK directory based on MCU_SERIES MCU_DIR = lib/nxp_driver/sdk/devices/$(MCU_SERIES) @@ -83,6 +84,14 @@ INC += -I$(TOP)/shared/tinyusb INC += -I. INC += -Ihal +ifeq ($(MICROPY_PY_BLUETOOTH),1) +INC += \ + -I$(TOP)/extmod/nimble \ + -I$(TOP)/lib/mynewt-nimble/nimble/host/include \ + -I$(TOP)/lib/mynewt-nimble/nimble/include \ + -I$(TOP)/lib/mynewt-nimble/porting/nimble/include +endif + # All settings for Ethernet support are controller by the value of MICROPY_PY_LWIP ifeq ($(MICROPY_PY_LWIP),1) INC += -Ilwip_inc @@ -239,6 +248,13 @@ SRC_C += \ ticks.c \ usbd.c \ +ifeq ($(MICROPY_PY_BLUETOOTH),1) +SRC_C += \ + drivers/ninaw10/nina_bt_hci.c \ + mpbthciport.c \ + mpnimbleport.c +endif + SHARED_SRC_C += \ shared/libc/printf.c \ shared/libc/string0.c \ diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h index da4534acb558..81d172ae135c 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h @@ -75,3 +75,22 @@ #define MICROPY_HW_NINA_RTS (&pin_GPIO_AD_04) // CTS == NINA_ACK: GPIO_AD_11 #define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK +<<<<<<< Updated upstream +======= + +#else + +// ESP_BUSY: GPIO_11 +#define MICROPY_HW_NINA_ACK (pin_GPIO_11) +// ESP_CS: GPIO_06 +#define MICROPY_HW_NINA_CS (pin_GPIO_06) +// ESP_RESET: GPIO_SD_01 +#define MICROPY_HW_NINA_RESET (pin_GPIO_SD_01) + +// MOSI == RTS: GPIO_AD_04 +#define MICROPY_HW_NINA_RTS (pin_GPIO_AD_04) +// CTS == NINA_ACK: GPIO_11 +#define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK + +#endif +>>>>>>> Stashed changes diff --git a/ports/mimxrt/boards/MIMXRT1011.ld b/ports/mimxrt/boards/MIMXRT1011.ld index 0e961a49433f..ef9269adef7b 100644 --- a/ports/mimxrt/boards/MIMXRT1011.ld +++ b/ports/mimxrt/boards/MIMXRT1011.ld @@ -27,8 +27,8 @@ dtcm_size = 0x00008000; ocrm_start = 0x20200000; ocrm_size = 0x00010000; -/* 16kiB stack. */ -__stack_size__ = 0x4000; +/* 10kiB stack. */ +__stack_size__ = 0x2800; _estack = __StackTop; _sstack = __StackLimit; diff --git a/ports/mimxrt/boards/MIMXRT1015.ld b/ports/mimxrt/boards/MIMXRT1015.ld index 58b88e0fe308..3ae405e483bc 100644 --- a/ports/mimxrt/boards/MIMXRT1015.ld +++ b/ports/mimxrt/boards/MIMXRT1015.ld @@ -27,8 +27,8 @@ dtcm_size = 0x00008000; ocrm_start = 0x20200000; ocrm_size = 0x00010000; -/* 16kiB stack. */ -__stack_size__ = 0x4000; +/* 10kiB stack. */ +__stack_size__ = 0x2800; _estack = __StackTop; _sstack = __StackLimit; diff --git a/ports/mimxrt/boards/manifest.py b/ports/mimxrt/boards/manifest.py index d7acab38373f..018a9b91f735 100644 --- a/ports/mimxrt/boards/manifest.py +++ b/ports/mimxrt/boards/manifest.py @@ -3,3 +3,10 @@ require("onewire") require("ds18x20") require("dht") +include( + "$(MPY_LIB_DIR)/micropython/bluetooth/aioble/manifest.py", + client=True, + central=True, + l2cap=True, + security=True, +) diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index 6b9d4fa17afe..e37d467f17d2 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -57,6 +57,10 @@ #include "systick.h" #include "extmod/modnetwork.h" #include "extmod/vfs.h" +#if MICROPY_PY_BLUETOOTH +#include "extmod/modbluetooth.h" +#include "mpbthciport.h" +#endif extern uint8_t _sstack, _estack, _gc_heap_start, _gc_heap_end; @@ -67,6 +71,10 @@ int main(void) { ticks_init(); pendsv_init(); + #if MICROPY_PY_BLUETOOTH + mp_bluetooth_hci_init(); + #endif + #if MICROPY_PY_LWIP // lwIP doesn't allow to reinitialise itself by subsequent calls to this function // because the system timeout list (next_timeout) is only ever reset by BSS clearing. @@ -75,9 +83,8 @@ int main(void) { #if LWIP_MDNS_RESPONDER mdns_resp_init(); #endif - - systick_enable_dispatch(SYSTICK_DISPATCH_LWIP, mod_network_lwip_poll_wrapper); #endif + #if MICROPY_PY_BLUETOOTH mp_bluetooth_hci_init(); #endif @@ -108,6 +115,15 @@ int main(void) { #if MICROPY_PY_NETWORK mod_network_init(); #endif + #if MICROPY_PY_BLUETOOTH + mp_bluetooth_hci_init(); + #endif + + #if MICROPY_PY_LWIP + // mod_network_lwip_init(); + systick_enable_dispatch(SYSTICK_DISPATCH_LWIP, mod_network_lwip_poll_wrapper); + #endif + // Initialise sub-systems. readline_init0(); @@ -165,12 +181,19 @@ int main(void) { #if MICROPY_PY_MACHINE_I2S machine_i2s_deinit_all(); #endif - #if MICROPY_PY_BLUETOOTH - mp_bluetooth_deinit(); + #if MICROPY_PY_LWIP + systick_disable_dispatch(SYSTICK_DISPATCH_LWIP); + #endif + #if MICROPY_PY_NETWORK_ESP_HOSTED + int esp_hosted_wifi_deinit(void); + esp_hosted_wifi_deinit(); #endif #if MICROPY_PY_NETWORK mod_network_deinit(); #endif + #if MICROPY_PY_BLUETOOTH + mp_bluetooth_deinit(); + #endif machine_uart_deinit_all(); machine_pwm_deinit_all(); soft_timer_deinit(); @@ -192,6 +215,11 @@ void nlr_jump_fail(void *val) { } } +void abort(void) { + for (;;) { + } +} + #ifndef NDEBUG void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) { mp_printf(MP_PYTHON_PRINTER, "Assertion '%s' failed, at file %s:%d\n", expr, file, line); diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index dfb7380b2f2c..6e52ad8af28a 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -56,6 +56,7 @@ uint32_t trng_random_u32(void); #define MICROPY_ENABLE_GC (1) #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) +#define MICROPY_SCHEDULER (1) #define MICROPY_SCHEDULER_DEPTH (8) #define MICROPY_ENABLE_SCHEDULER (1) #define MICROPY_SCHEDULER_STATIC_NODES (1) @@ -138,7 +139,7 @@ uint32_t trng_random_u32(void); #endif #ifndef MICROPY_PY_SSL -#define MICROPY_PY_SSL (1) +#define MICROPY_PY_SSL (0) #endif #define MICROPY_PY_WEBSOCKET (MICROPY_PY_LWIP || MICROPY_PY_NETWORK_NINAW10) #define MICROPY_PY_WEBREPL (MICROPY_PY_LWIP || MICROPY_PY_NETWORK_NINAW10) @@ -152,6 +153,12 @@ uint32_t trng_random_u32(void); #endif #define MICROPY_PY_LWIP_PPP (MICROPY_PY_NETWORK_PPP_LWIP) +#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT +#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-mimxrt" +#endif + +#if MICROPY_PY_BLUETOOTH + #ifndef MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE #define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1) #endif @@ -160,8 +167,9 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS (MICROPY_BLUETOOTH_NIMBLE) #endif -#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT -#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-mimxrt" +// Bluetooth code only runs in the scheduler, no locking/mutex required. +#define MICROPY_PY_BLUETOOTH_ENTER uint32_t atomic_state = 0; +#define MICROPY_PY_BLUETOOTH_EXIT (void)atomic_state; #endif #define MICROPY_HW_ENABLE_USBDEV (1) diff --git a/ports/mimxrt/pendsv.h b/ports/mimxrt/pendsv.h index d68c5aa2d5d5..6aa218aed8f6 100644 --- a/ports/mimxrt/pendsv.h +++ b/ports/mimxrt/pendsv.h @@ -34,6 +34,9 @@ enum { #if MICROPY_PY_NETWORK_CYW43 PENDSV_DISPATCH_CYW43, #endif + #if MICROPY_PY_BLUETOOTH && !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS + PENDSV_DISPATCH_BLUETOOTH_HCI, + #endif MICROPY_BOARD_PENDSV_ENTRIES PENDSV_DISPATCH_MAX }; From 28263fc4f7553a6e3186833d608db03b373109a6 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 23 Apr 2023 12:08:23 +0200 Subject: [PATCH 06/11] mimxrt/NINAW10: Add or change board configuration files. For: MIMXRT1010_EVK MIMXRT1015_EVK ADAFRUIT Metro M7 OLIMEX RT1010 Adafruit Metro M7 board: Add the SD variant of the Adafruit Metro M7 board. It supports WIFI/BLE as well, but at pins matching the Airlift UNO breakout. Olimex 1010 board: The pins are selected in a way that they are accessible at the UEXT1 connector of the Dev board. There is no free Pin for GPIO0. So GPIO0 must be connected with a resistor to a Pin which is not used for FW upload and is used as output during normal operation, e.g. SPI SCL. The NINA FW configures GPIO0 as output during normal operation. Signed-off-by: robert-hh --- ports/mimxrt/Makefile | 7 ++++++ .../boards/ADAFRUIT_METRO_M7/board.json | 3 +++ .../boards/ADAFRUIT_METRO_M7/mpconfigboard.h | 22 ++++++++--------- .../boards/ADAFRUIT_METRO_M7/mpconfigboard.mk | 8 +++++++ .../boards/MIMXRT1010_EVK/mpconfigboard.h | 17 ++++++++++--- .../boards/MIMXRT1010_EVK/mpconfigboard.mk | 3 +++ .../boards/MIMXRT1015_EVK/mpconfigboard.h | 17 ++++++++++--- .../boards/MIMXRT1015_EVK/mpconfigboard.mk | 3 +++ .../boards/OLIMEX_RT1010/mpconfigboard.h | 24 ++++++++++++++++++- .../boards/OLIMEX_RT1010/mpconfigboard.mk | 7 ++++++ ports/mimxrt/boards/manifest.py | 1 + 11 files changed, 94 insertions(+), 18 deletions(-) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index e55182ca143e..74669a3b6382 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -17,7 +17,14 @@ ifeq ($(wildcard $(BOARD_DIR)/.),) $(error Invalid BOARD specified: $(BOARD_DIR)) endif +# If the build directory is not given, make it reflect the board name (and +# optionally the board variant). +ifneq ($(BOARD_VARIANT),) +BUILD ?= build-$(BOARD)-$(BOARD_VARIANT) +else BUILD ?= build-$(BOARD) +endif + PORT ?= /dev/ttyACM0 CROSS_COMPILE ?= arm-none-eabi- GIT_SUBMODULES += lib/tinyusb lib/nxp_driver diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json index 9f260b3a00f9..ae001b873efa 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json @@ -18,5 +18,8 @@ "product": "Adafruit Metro M7", "thumbnail": "", "url": "https://www.adafruit.com/product/4950", + "variants": { + "SD": "Metro M7 board without the airlift module" + }, "vendor": "Adafruit" } diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h index 81d172ae135c..60f189ac137f 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h @@ -58,25 +58,26 @@ #define MICROPY_HW_WIFI_SPI_ID (0) #define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) -// ESP_BUSY: GPIO_AD_11 -#define MICROPY_HW_NINA_ACK (&pin_GPIO_AD_11) -// ESP_CS: GPIO_AD_14 -#define MICROPY_HW_NINA_CS (&pin_GPIO_AD_14) -// ESP_RESET: GPIO_AD_07 -#define MICROPY_HW_NINA_RESET (&pin_GPIO_AD_07) - // BLE definitions #define MICROPY_PY_BLUETOOTH_NINAW10 (1) #define MICROPY_HW_BLE_UART_ID (1) #define MICROPY_HW_BLE_UART_BAUDRATE (115200) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) + +#if MICROPY_HW_WIFI_AIRLIFT + +// ESP_BUSY: GPIO_AD_11 +#define MICROPY_HW_NINA_ACK (pin_GPIO_AD_11) +// ESP_CS: GPIO_AD_14 +#define MICROPY_HW_NINA_CS (pin_GPIO_AD_14) +// ESP_RESET: GPIO_AD_07 +#define MICROPY_HW_NINA_RESET (pin_GPIO_AD_07) // MOSI == RTS: GPIO_AD_04 -#define MICROPY_HW_NINA_RTS (&pin_GPIO_AD_04) +#define MICROPY_HW_NINA_RTS (pin_GPIO_AD_04) // CTS == NINA_ACK: GPIO_AD_11 #define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK -<<<<<<< Updated upstream -======= #else @@ -93,4 +94,3 @@ #define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK #endif ->>>>>>> Stashed changes diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk index 520cea063fb7..0fd08b2d664f 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk @@ -13,3 +13,11 @@ MICROPY_PY_SSL ?= 1 MICROPY_SSL_MBEDTLS ?= 1 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_BLUETOOTH ?= 1 +MICROPY_BLUETOOTH_NIMBLE ?= 1 + +ifeq ($(BOARD_VARIANT),) +CFLAGS += -DMICROPY_HW_WIFI_AIRLIFT=1 +else +CFLAGS += -DMICROPY_HW_WIFI_AIRLIFT=0 +endif diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h index bce1cf175910..ea9d1666c881 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h @@ -87,8 +87,19 @@ #define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) // NINA_ACK: D7 = GPIO_AD_02 -#define MICROPY_HW_NINA_ACK (&pin_GPIO_AD_02) +#define MICROPY_HW_NINA_ACK (pin_GPIO_AD_02) // NINA_CS: D10 = GPIO_AD_05 -#define MICROPY_HW_NINA_CS (&pin_GPIO_AD_05) +#define MICROPY_HW_NINA_CS (pin_GPIO_AD_05) // Adafruit shield: NINA_RESET: D5 = GPIO_01 -#define MICROPY_HW_NINA_RESET (&pin_GPIO_01) +#define MICROPY_HW_NINA_RESET (pin_GPIO_01) + +#define MICROPY_PY_BLUETOOTH_NINAW10 (1) + +#define MICROPY_HW_BLE_UART_ID (1) +#define MICROPY_HW_BLE_UART_BAUDRATE (115200) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) + +// NINA_RTS: D11 = GPIO_AD_04 +#define MICROPY_HW_NINA_RTS (pin_GPIO_AD_04) +// NINA_CTS: D7 = GPIO_AD_02 +#define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk index a6736b26c9bb..302233a8585f 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk @@ -14,6 +14,9 @@ MICROPY_PY_NETWORK_NINAW10 ?= 1 MICROPY_PY_SSL ?= 1 MICROPY_SSL_MBEDTLS ?= 1 +MICROPY_PY_BLUETOOTH ?= 1 +MICROPY_BLUETOOTH_NIMBLE ?= 1 + JLINK_PATH ?= /media/RT1010-EVK/ JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink diff --git a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h index 404b1f90093a..d1b29ea90510 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h @@ -92,8 +92,19 @@ #define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) // NINA_ACK: D7 = GPIO_AD_B0_15 -#define MICROPY_HW_NINA_ACK (&pin_GPIO_AD_B0_15) +#define MICROPY_HW_NINA_ACK (pin_GPIO_AD_B0_15) // NINA_CS: D10 = GPIO_AD_B0_11 -#define MICROPY_HW_NINA_CS (&pin_GPIO_AD_B0_11) +#define MICROPY_HW_NINA_CS (pin_GPIO_AD_B0_11) // Adafruit shield: NINA_RESET: D5 = GPIO_EMC_27 -#define MICROPY_HW_NINA_RESET (&pin_GPIO_EMC_27) +#define MICROPY_HW_NINA_RESET (pin_GPIO_EMC_27) + +#define MICROPY_PY_BLUETOOTH_NINAW10 (1) + +#define MICROPY_HW_BLE_UART_ID (1) +#define MICROPY_HW_BLE_UART_BAUDRATE (115200) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) + +// NINA_CS: D11 = GPIO_AD_B0_12 +#define MICROPY_HW_NINA_RTS (pin_GPIO_AD_B0_12) +// NINA_CTS: D7 = GPIO_AD_B0_15 +#define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK diff --git a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk index 9422633fcc37..bdbd9ea45b64 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk @@ -8,6 +8,9 @@ MICROPY_HW_FLASH_CLK = kFlexSpiSerialClk_100MHz MICROPY_HW_FLASH_QE_CMD = 0x31 MICROPY_HW_FLASH_QE_ARG = 0x02 +MICROPY_PY_BLUETOOTH ?= 1 +MICROPY_BLUETOOTH_NIMBLE ?= 1 + MICROPY_BOOT_BUFFER_SIZE = (32 * 1024) USE_UF2_BOOTLOADER = 1 diff --git a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h index 1ad2e9df5eba..84ebd9b48a20 100644 --- a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h +++ b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h @@ -15,7 +15,8 @@ // Define mapping logical UART # to hardware UART # // LPUART1 on RX/TX -> 1 -// LPUART4 on D5/D6 -> 2 +// LPUART3 on D7/D8 -> 2 +// LPUART4 on D5/D6 -> 3 #define MICROPY_HW_UART_NUM (sizeof(uart_index_table) / sizeof(uart_index_table)[0]) #define MICROPY_HW_UART_INDEX { 0, 1, 3, 4 } @@ -88,3 +89,24 @@ I2S_GPIO(3, WS, TX, GPIO_SD_00, IOMUXC_GPIO_SD_00_SAI3_TX_SYNC), /* pin D9 */ \ I2S_GPIO(3, SD, TX, GPIO_SD_02, IOMUXC_GPIO_SD_02_SAI3_TX_DATA) /* pin D11 */ \ } + +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) + +// NINA_ACK: I2C2_SCL = GPIO_AD_08 +#define MICROPY_HW_NINA_ACK (pin_GPIO_AD_08) +// NINA_CS: LPSPI1_PCS0 = GPIO_AD_05 +#define MICROPY_HW_NINA_CS (pin_GPIO_AD_05) +// Adafruit shield: NINA_RESET: I2C2_SDA = GPIO_AD_07 +#define MICROPY_HW_NINA_RESET (pin_GPIO_AD_07) + +#define MICROPY_PY_BLUETOOTH_NINAW10 (1) + +#define MICROPY_HW_BLE_UART_ID (2) +#define MICROPY_HW_BLE_UART_BAUDRATE (115200) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) + +// NINA_RTS: D11 = GPIO_AD_04 +#define MICROPY_HW_NINA_RTS (pin_GPIO_AD_04) +// NINA_CTS: I2C2_SCL = GPIO_AD_08 +#define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK diff --git a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk index 7e9987de0cfe..96329ca8b387 100644 --- a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk +++ b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk @@ -15,3 +15,10 @@ CFLAGS += -DMICROPY_HW_FLASH_DQS=kFlexSPIReadSampleClk_LoopbackInternally SRC_C += \ hal/flexspi_nor_flash.c \ + +MICROPY_PY_NETWORK_NINAW10 ?= 1 +MICROPY_PY_SSL ?= 1 +MICROPY_SSL_MBEDTLS ?= 1 + +MICROPY_PY_BLUETOOTH ?= 1 +MICROPY_BLUETOOTH_NIMBLE ?= 1 diff --git a/ports/mimxrt/boards/manifest.py b/ports/mimxrt/boards/manifest.py index 018a9b91f735..a3393c4a9f66 100644 --- a/ports/mimxrt/boards/manifest.py +++ b/ports/mimxrt/boards/manifest.py @@ -3,6 +3,7 @@ require("onewire") require("ds18x20") require("dht") +require("neopixel") include( "$(MPY_LIB_DIR)/micropython/bluetooth/aioble/manifest.py", client=True, From dd932f24ebd14e1fb2b2de0f42824d20ee068f6b Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 18 Jul 2023 12:58:17 +0200 Subject: [PATCH 07/11] mimxrt: Combined files and changes for using the esp_hosted driver. At first with the board files for MIMXRT1020 only. MIMXRT1010 and MIMXRT1015 do not build due to insufficient RAM size. Signed-off-by: robert-hh --- ports/mimxrt/Makefile | 12 ++++++++- .../mimxrt/boards/MIMXRT1020_EVK/manifest.py | 2 ++ .../MIMXRT1020_EVK/mbedtls_config_board.h | 8 ++++++ .../boards/MIMXRT1020_EVK/mpconfigboard.h | 27 +++++++++++++++++++ .../boards/MIMXRT1020_EVK/mpconfigboard.mk | 10 +++++++ ports/mimxrt/mpbthciport.c | 8 ++++++ ports/mimxrt/mpconfigport.h | 8 ++++++ ports/mimxrt/mpnetworkport.c | 15 ++++++++++- 8 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 ports/mimxrt/boards/MIMXRT1020_EVK/mbedtls_config_board.h diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index 74669a3b6382..6702aafe53e0 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -124,8 +124,9 @@ SRC_TINYUSB_C += \ lib/tinyusb/src/portable/chipidea/ci_hs/dcd_ci_hs.c \ lib/tinyusb/src/tusb.c -# All settings for Ethernet support are controller by the value of MICROPY_PY_LWIP +# All settings for Ethernet support are controller by the value of MICROPY_PY_LWIP and the supported MCUs ifeq ($(MICROPY_PY_LWIP),1) +ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES), MIMXRT1021 MIMXRT1052 MIMXRT1062 MIMXRT1064 MIMXRT1176)) SRC_ETH_C += \ $(MCU_DIR)/drivers/fsl_enet.c \ hal/phy/device/phydp83825/fsl_phydp83825.c \ @@ -135,6 +136,7 @@ SRC_ETH_C += \ hal/phy/device/phyrtl8211f/fsl_phyrtl8211f.c \ hal/phy/mdio/enet/fsl_enet_mdio.c endif +endif ifeq ($(MICROPY_PY_NETWORK_NINAW10),1) CFLAGS += -DMICROPY_PY_NETWORK_NINAW10=1 @@ -281,6 +283,14 @@ SHARED_SRC_C += \ shared/tinyusb/mp_usbd_cdc.c \ shared/tinyusb/mp_usbd_descriptor.c \ +ifeq ($(MICROPY_PY_BLUETOOTH),1) +SRC_C += mpbthciport.c +endif + +ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) +SRC_C += mpnimbleport.c +endif + # Set flash driver name, base address and internal flash flag, based on the flash type. ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_nor_flash)) MICROPY_HW_FLASH_BASE = 0x60000000 diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py b/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py index 107181c31ca7..acaf5d0eac64 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py @@ -1,3 +1,5 @@ include("../manifest.py") require("bundle-networking") +# Bluetooth +require("aioble") diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mbedtls_config_board.h b/ports/mimxrt/boards/MIMXRT1020_EVK/mbedtls_config_board.h new file mode 100644 index 000000000000..4bca8ea0c040 --- /dev/null +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mbedtls_config_board.h @@ -0,0 +1,8 @@ +#ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H +#define MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H + +#define MBEDTLS_ECP_NIST_OPTIM + +#include "ports/mimxrt/mbedtls/mbedtls_config.h" + +#endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H */ diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h index b4f777cf93b0..33760d85b521 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h @@ -181,3 +181,30 @@ { IOMUXC_GPIO_AD_B0_15_ENET_TDATA01, 0, 0xB0E9u }, \ { IOMUXC_GPIO_EMC_40_ENET_MDIO, 0, 0xB0E9u }, \ { IOMUXC_GPIO_EMC_41_ENET_MDC, 0, 0xB0E9u }, + + +// Bluetooth config. +#define MICROPY_HW_BLE_UART_ID (1) +// D11 pin_GPIO_AD_B0_12 +#define MICROPY_HW_BLE_UART_RTS (&pin_GPIO_AD_B0_12) +#define MICROPY_HW_BLE_UART_BAUDRATE (460800) +#define MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY (460800) + +// WiFi config. +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (8 * 1000 * 1000) +// D10 pin_GPIO_AD_B0_11 +#define MICROPY_HW_WIFI_SPI_CS (&pin_GPIO_AD_B0_11) +// D6 pin_GPIO_AD_B0_14 +#define MICROPY_HW_WIFI_DATAREADY (&pin_GPIO_AD_B0_14) +// D7 pin_GPIO_AD_B1_06 +#define MICROPY_HW_WIFI_HANDSHAKE (&pin_GPIO_AD_B1_06) +#define MICROPY_HW_WIFI_IRQ_PIN (MICROPY_HW_WIFI_DATAREADY) + +// ESP hosted control pins +// D5 pin_GPIO_AD_B0_06 +#define MICROPY_HW_ESP_HOSTED_RESET (&pin_GPIO_AD_B0_06) +// D6 pin_GPIO_AD_B0_14 +#define MICROPY_HW_ESP_HOSTED_GPIO0 (&pin_GPIO_AD_B0_14) + +#define MICROPY_HW_ESP_HOSTED_SHARED_PINS (1) diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk index 5ef078210a2a..ef37a75a6ea9 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk @@ -16,6 +16,16 @@ MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK = 1 +MICROPY_PY_NETWORK_ESP_HOSTED = 1 +CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) + +MICROPY_PY_BLUETOOTH = 1 +CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) +MICROPY_BLUETOOTH_NIMBLE = 1 +MICROPY_BLUETOOTH_BTSTACK = 0 + +MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"' FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/mpbthciport.c b/ports/mimxrt/mpbthciport.c index 45f729671728..dc262b57b9e6 100644 --- a/ports/mimxrt/mpbthciport.c +++ b/ports/mimxrt/mpbthciport.c @@ -100,6 +100,14 @@ int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate) { mp_bthci_uart = MP_OBJ_TYPE_GET_SLOT(&machine_uart_type, make_new)((mp_obj_t)&machine_uart_type, 1, 6, args); MP_STATE_PORT(mp_bthci_uart) = mp_bthci_uart; + #if MICROPY_PY_NETWORK_NINAW10 + mp_hal_pin_output(MICROPY_HW_NINA_CS); + mp_hal_pin_write(MICROPY_HW_NINA_CS, 0); + #else + mp_hal_pin_output(MICROPY_HW_WIFI_SPI_CS); + mp_hal_pin_write(MICROPY_HW_WIFI_SPI_CS, 0); + #endif + // Start the HCI polling to process any initial events/packets. mp_bluetooth_hci_start_polling(); return 0; diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 6e52ad8af28a..678cf5a155c8 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -213,11 +213,19 @@ extern const struct _mp_obj_type_t mp_network_cyw43_type; #define MICROPY_HW_NIC_CYW43 #endif +#if MICROPY_PY_NETWORK_ESP_HOSTED +extern const struct _mp_obj_type_t mod_network_esp_hosted_type; +#define MICROPY_HW_NIC_ESP_HOSTED { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_esp_hosted_type) }, +#else +#define MICROPY_HW_NIC_ESP_HOSTED +#endif + #ifndef MICROPY_BOARD_NETWORK_INTERFACES #define MICROPY_BOARD_NETWORK_INTERFACES #endif #define MICROPY_PORT_NETWORK_INTERFACES \ + MICROPY_HW_NIC_ESP_HOSTED \ MICROPY_HW_NIC_ETH \ MICROPY_HW_NIC_CYW43 \ MICROPY_HW_NIC_NINAW10 \ diff --git a/ports/mimxrt/mpnetworkport.c b/ports/mimxrt/mpnetworkport.c index aa8eef3ee239..413ff11d14a8 100644 --- a/ports/mimxrt/mpnetworkport.c +++ b/ports/mimxrt/mpnetworkport.c @@ -58,11 +58,20 @@ u32_t sys_now(void) { static void pyb_lwip_poll(void) { // Run the lwIP internal updates sys_check_timeouts(); + + #if MICROPY_PY_NETWORK_ESP_HOSTED + extern int esp_hosted_wifi_poll(void); + // Poll the NIC for incoming data + esp_hosted_wifi_poll(); + #endif } +static bool network_poll_now_flag = false; + void mod_network_lwip_poll_wrapper(uint32_t ticks_ms) { - if (LWIP_TICK(ticks_ms)) { + if (LWIP_TICK(ticks_ms) || network_poll_now_flag) { pendsv_schedule_dispatch(PENDSV_DISPATCH_LWIP, pyb_lwip_poll); + network_poll_now_flag = false; } #if MICROPY_PY_NETWORK_CYW43 @@ -76,4 +85,8 @@ void mod_network_lwip_poll_wrapper(uint32_t ticks_ms) { #endif } +void mod_network_poll_events(void) { + network_poll_now_flag = true; +} + #endif // MICROPY_PY_LWIP From 5c62eb846f5d010b3ca219428da228a63bcb1ed2 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 28 Sep 2023 22:08:39 +0200 Subject: [PATCH 08/11] mimxrt/esp_hosted: Add more esp_hosted boards files. - Teensy 4.0 - Teensy 4.1 - MIMXRT1050_EVK - SEEED Arch Mix WiFi & BLE work for Teensy 4.x and SEEED Arch Mix with the given wiring. The Teensy 4.x wiring matches the combination of a Adafruit Feather Airlift module with Teensy - Feather adapter. Limited activity for MIMXRT1050, since the SPI wires are not connected. BLE on MIMXRT1050EVK worked, with CS and MOSI of the airlift shield hardwired to GND. Signed-off-by: robert-hh --- .../boards/MIMXRT1020_EVK/mpconfigboard.h | 13 ++++---- .../mimxrt/boards/MIMXRT1050_EVK/manifest.py | 2 ++ .../boards/MIMXRT1050_EVK/mpconfigboard.h | 27 +++++++++++++++ .../boards/MIMXRT1050_EVK/mpconfigboard.mk | 9 +++++ .../boards/OLIMEX_RT1010/mpconfigboard.h | 10 +++--- .../boards/SEEED_ARCH_MIX/mpconfigboard.h | 27 +++++++++++++++ .../boards/SEEED_ARCH_MIX/mpconfigboard.mk | 8 +++++ ports/mimxrt/boards/TEENSY40/mpconfigboard.h | 33 +++++++++++++++++++ ports/mimxrt/boards/TEENSY40/mpconfigboard.mk | 15 +++++++++ ports/mimxrt/boards/TEENSY41/manifest.py | 2 ++ ports/mimxrt/boards/TEENSY41/mpconfigboard.h | 32 ++++++++++++++++++ ports/mimxrt/boards/TEENSY41/mpconfigboard.mk | 8 +++++ 12 files changed, 175 insertions(+), 11 deletions(-) diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h index 33760d85b521..6bf601d645ae 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h @@ -186,25 +186,26 @@ // Bluetooth config. #define MICROPY_HW_BLE_UART_ID (1) // D11 pin_GPIO_AD_B0_12 -#define MICROPY_HW_BLE_UART_RTS (&pin_GPIO_AD_B0_12) +#define MICROPY_HW_BLE_UART_RTS (pin_GPIO_AD_B0_12) #define MICROPY_HW_BLE_UART_BAUDRATE (460800) #define MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY (460800) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) // WiFi config. #define MICROPY_HW_WIFI_SPI_ID (0) #define MICROPY_HW_WIFI_SPI_BAUDRATE (8 * 1000 * 1000) // D10 pin_GPIO_AD_B0_11 -#define MICROPY_HW_WIFI_SPI_CS (&pin_GPIO_AD_B0_11) +#define MICROPY_HW_WIFI_SPI_CS (pin_GPIO_AD_B0_11) // D6 pin_GPIO_AD_B0_14 -#define MICROPY_HW_WIFI_DATAREADY (&pin_GPIO_AD_B0_14) +#define MICROPY_HW_WIFI_DATAREADY (pin_GPIO_AD_B0_14) // D7 pin_GPIO_AD_B1_06 -#define MICROPY_HW_WIFI_HANDSHAKE (&pin_GPIO_AD_B1_06) +#define MICROPY_HW_WIFI_HANDSHAKE (pin_GPIO_AD_B1_06) #define MICROPY_HW_WIFI_IRQ_PIN (MICROPY_HW_WIFI_DATAREADY) // ESP hosted control pins // D5 pin_GPIO_AD_B0_06 -#define MICROPY_HW_ESP_HOSTED_RESET (&pin_GPIO_AD_B0_06) +#define MICROPY_HW_ESP_HOSTED_RESET (pin_GPIO_AD_B0_06) // D6 pin_GPIO_AD_B0_14 -#define MICROPY_HW_ESP_HOSTED_GPIO0 (&pin_GPIO_AD_B0_14) +#define MICROPY_HW_ESP_HOSTED_GPIO0 (pin_GPIO_AD_B0_14) #define MICROPY_HW_ESP_HOSTED_SHARED_PINS (1) diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py b/ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py index 107181c31ca7..acaf5d0eac64 100644 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py +++ b/ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py @@ -1,3 +1,5 @@ include("../manifest.py") require("bundle-networking") +# Bluetooth +require("aioble") diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.h index 59a5c4fa69f8..b7a23f089e44 100644 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.h @@ -171,3 +171,30 @@ { IOMUXC_GPIO_B1_11_ENET_RX_ER, 0, 0xB0E9u }, \ { IOMUXC_GPIO_EMC_41_ENET_MDIO, 0, 0xB0E9u }, \ { IOMUXC_GPIO_EMC_40_ENET_MDC, 0, 0xB0E9u }, + +// Bluetooth config. +#define MICROPY_HW_BLE_UART_ID (1) +// D11 pin_GPIO_SD_B0_02 +#define MICROPY_HW_BLE_UART_RTS (pin_GPIO_SD_B0_02) +#define MICROPY_HW_BLE_UART_BAUDRATE (115200) +#define MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY (460800) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) + +// WiFi config. +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (8 * 1000 * 1000) +// D10 pin_GPIO_SD_B0_01 +#define MICROPY_HW_WIFI_SPI_CS (pin_GPIO_SD_B0_01) +// D6 pin_GPIO_AD_B1_02 +#define MICROPY_HW_WIFI_DATAREADY (pin_GPIO_AD_B1_02) +// D7 pin_GPIO_AD_B1_03 +#define MICROPY_HW_WIFI_HANDSHAKE (pin_GPIO_AD_B1_03) +#define MICROPY_HW_WIFI_IRQ_PIN (MICROPY_HW_WIFI_DATAREADY) + +// ESP hosted control pins +// D5 pin_GPIO_AD_B0_10 +#define MICROPY_HW_ESP_HOSTED_RESET (pin_GPIO_AD_B0_10) +// D6 pin_GPIO_AD_B1_02 +#define MICROPY_HW_ESP_HOSTED_GPIO0 (pin_GPIO_AD_B1_02) + +#define MICROPY_HW_ESP_HOSTED_SHARED_PINS (1) diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk index 8b048c85eaa9..7fd335429b69 100644 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk @@ -15,4 +15,13 @@ MICROPY_PY_LWIP = 1 MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 +MICROPY_PY_NETWORK = 1 +MICROPY_PY_NETWORK_ESP_HOSTED = 1 +CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) + +MICROPY_PY_BLUETOOTH = 1 +CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) +MICROPY_BLUETOOTH_NIMBLE = 1 +MICROPY_BLUETOOTH_BTSTACK = 0 + FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h index 84ebd9b48a20..8f70b691b59f 100644 --- a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h +++ b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h @@ -93,11 +93,11 @@ #define MICROPY_HW_WIFI_SPI_ID (0) #define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) -// NINA_ACK: I2C2_SCL = GPIO_AD_08 +// NINA_ACK: SCL2 = GPIO_AD_08 #define MICROPY_HW_NINA_ACK (pin_GPIO_AD_08) -// NINA_CS: LPSPI1_PCS0 = GPIO_AD_05 +// NINA_CS: A3 = GPIO_AD_05 #define MICROPY_HW_NINA_CS (pin_GPIO_AD_05) -// Adafruit shield: NINA_RESET: I2C2_SDA = GPIO_AD_07 +// NINA_RESET: SDA2 = GPIO_AD_07 #define MICROPY_HW_NINA_RESET (pin_GPIO_AD_07) #define MICROPY_PY_BLUETOOTH_NINAW10 (1) @@ -106,7 +106,7 @@ #define MICROPY_HW_BLE_UART_BAUDRATE (115200) #define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) -// NINA_RTS: D11 = GPIO_AD_04 +// NINA_RTS: A2 = GPIO_AD_04 #define MICROPY_HW_NINA_RTS (pin_GPIO_AD_04) -// NINA_CTS: I2C2_SCL = GPIO_AD_08 +// NINA_CTS: SCL2 = GPIO_AD_08 #define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK diff --git a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.h b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.h index 627b1aa3b131..9941b86ab2b2 100644 --- a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.h +++ b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.h @@ -183,3 +183,30 @@ #define MIMXRT_IOMUXC_SEMC_WE IOMUXC_GPIO_EMC_28_SEMC_WE #define MIMXRT_IOMUXC_SEMC_CS0 IOMUXC_GPIO_EMC_29_SEMC_CS0 + +// Bluetooth config. +#define MICROPY_HW_BLE_UART_ID (3) +// RTS = MOSI: J4-14 pin_GPIO_AD_B1_14 +#define MICROPY_HW_BLE_UART_RTS (pin_GPIO_AD_B1_14) +#define MICROPY_HW_BLE_UART_BAUDRATE (460800) +#define MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY (460800) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) + +// WiFi config. +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (8 * 1000 * 1000) +// CS: J4-12 pin_GPIO_AD_B1_12 +#define MICROPY_HW_WIFI_SPI_CS (pin_GPIO_AD_B1_12) +// HANDSHAKE: J4-11 pin_GPIO_AD_B1_11 +#define MICROPY_HW_WIFI_HANDSHAKE (pin_GPIO_AD_B1_11) +// DATAREADY: J4-09 pin_GPIO_AD_B1_09 +#define MICROPY_HW_WIFI_DATAREADY (pin_GPIO_AD_B1_09) +#define MICROPY_HW_WIFI_IRQ_PIN (MICROPY_HW_WIFI_DATAREADY) + +// ESP hosted control pins +// RESET: J4-10 pin_GPIO_AD_B1_10 +#define MICROPY_HW_ESP_HOSTED_RESET (pin_GPIO_AD_B1_10) +// D6 pin_GPIO_AD_B0_14 +#define MICROPY_HW_ESP_HOSTED_GPIO0 (MICROPY_HW_WIFI_DATAREADY) + +#define MICROPY_HW_ESP_HOSTED_SHARED_PINS (1) diff --git a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk index 7ea107b00df8..de2f37005a4a 100644 --- a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk +++ b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk @@ -16,6 +16,14 @@ MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK = 1 +MICROPY_PY_NETWORK_ESP_HOSTED = 1 +CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) + +MICROPY_PY_BLUETOOTH = 1 +CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) +MICROPY_BLUETOOTH_NIMBLE = 1 +MICROPY_BLUETOOTH_BTSTACK = 0 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/TEENSY40/mpconfigboard.h b/ports/mimxrt/boards/TEENSY40/mpconfigboard.h index 1a6227a60e07..e981bf6c2793 100644 --- a/ports/mimxrt/boards/TEENSY40/mpconfigboard.h +++ b/ports/mimxrt/boards/TEENSY40/mpconfigboard.h @@ -1,6 +1,8 @@ #define MICROPY_HW_BOARD_NAME "Teensy 4.0" #define MICROPY_HW_MCU_NAME "MIMXRT1062DVJ6A" +#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-teensy41" + // Teensy 4.0 has 1 board LED #define MICROPY_HW_LED1_PIN (pin_GPIO_B0_03) #define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin)) @@ -115,3 +117,34 @@ .data2 = { GPIO_SD_B0_04_USDHC1_DATA2 }, \ .data3 = { GPIO_SD_B0_05_USDHC1_DATA3 }, \ } + +// WiFi config. +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (9000000) +// Do not use the default CS pin. +#define MICROPY_HW_WIFI_CS_NUMBER (-1) +// CS: D5 = pin_GPIO_EMC_08 +#define MICROPY_HW_WIFI_SPI_CS (pin_GPIO_EMC_08) +// HANDSHAKE: D9 = GPIO_B0_11 +#define MICROPY_HW_WIFI_HANDSHAKE (pin_GPIO_B0_11) +// DATREADY: D10 = GPIO_B0_00 +#define MICROPY_HW_WIFI_DATAREADY (pin_GPIO_B0_00) +#define MICROPY_HW_WIFI_IRQ_PIN (MICROPY_HW_WIFI_DATAREADY) + +// Bluetooth config. +#define MICROPY_HW_BLE_UART_ID (1) +#define MICROPY_HW_BLE_UART_BAUDRATE (460800) +#define MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY (460800) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) +// RTS: MOSI = D11 pin_GPIO_B0_02 +#define MICROPY_HW_BLE_UART_RTS (pin_GPIO_B0_02) +// CTS: MISO = D12 pin_GPIO_B0_01 +#define MICROPY_HW_BLE_UART_CTS (pin_GPIO_B0_01) + +// ESP hosted control pins +// MICROPY_HW_ESP_HOSTED_RESET: D6 = GPIO_B0_10 +#define MICROPY_HW_ESP_HOSTED_RESET (pin_GPIO_B0_10) +// GPIO0 = DATAREADY: D5 = pin_GPIO_EMC_08 +#define MICROPY_HW_ESP_HOSTED_GPIO0 (MICROPY_HW_WIFI_DATAREADY) + +#define MICROPY_HW_ESP_HOSTED_SHARED_PINS (1) diff --git a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk index 9393252d1a86..9408ed2fa700 100644 --- a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk @@ -11,5 +11,20 @@ MICROPY_HW_FLASH_QE_ARG = 0x02 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_LWIP = 1 +MICROPY_PY_SSL = 1 +MICROPY_SSL_MBEDTLS = 1 + +MICROPY_PY_NETWORK = 1 +MICROPY_PY_NETWORK_ESP_HOSTED = 1 +CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) + +MICROPY_PY_BLUETOOTH = 1 +CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) +MICROPY_BLUETOOTH_NIMBLE = 1 +MICROPY_BLUETOOTH_BTSTACK = 0 + +FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py + deploy: $(BUILD)/firmware.hex teensy_loader_cli --mcu=imxrt1062 -v -w $< diff --git a/ports/mimxrt/boards/TEENSY41/manifest.py b/ports/mimxrt/boards/TEENSY41/manifest.py index 107181c31ca7..acaf5d0eac64 100644 --- a/ports/mimxrt/boards/TEENSY41/manifest.py +++ b/ports/mimxrt/boards/TEENSY41/manifest.py @@ -1,3 +1,5 @@ include("../manifest.py") require("bundle-networking") +# Bluetooth +require("aioble") diff --git a/ports/mimxrt/boards/TEENSY41/mpconfigboard.h b/ports/mimxrt/boards/TEENSY41/mpconfigboard.h index bff319c6d157..7bc56f84bc87 100644 --- a/ports/mimxrt/boards/TEENSY41/mpconfigboard.h +++ b/ports/mimxrt/boards/TEENSY41/mpconfigboard.h @@ -136,3 +136,35 @@ { IOMUXC_GPIO_B1_11_ENET_RX_ER, 0, 0xB0E9u }, \ { IOMUXC_GPIO_B1_15_ENET_MDIO, 0, 0xB0E9u }, \ { IOMUXC_GPIO_B1_14_ENET_MDC, 0, 0xB0E9u }, + + +// WiFi config. +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (9000000) +// Do not use the default CS pin. +#define MICROPY_HW_WIFI_CS_NUMBER (-1) +// CS: D5 = pin_GPIO_EMC_08 +#define MICROPY_HW_WIFI_SPI_CS (pin_GPIO_EMC_08) +// HANDSHAKE: D9 = GPIO_B0_11 +#define MICROPY_HW_WIFI_HANDSHAKE (pin_GPIO_B0_11) +// DATREADY: D10 = GPIO_B0_00 +#define MICROPY_HW_WIFI_DATAREADY (pin_GPIO_B0_00) +#define MICROPY_HW_WIFI_IRQ_PIN (MICROPY_HW_WIFI_DATAREADY) + +// Bluetooth config. +#define MICROPY_HW_BLE_UART_ID (1) +#define MICROPY_HW_BLE_UART_BAUDRATE (460800) +#define MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY (460800) +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (0) +// RTS: MOSI = D11 pin_GPIO_B0_02 +#define MICROPY_HW_BLE_UART_RTS (pin_GPIO_B0_02) +// CTS: MISO = D12 pin_GPIO_B0_01 +#define MICROPY_HW_BLE_UART_CTS (pin_GPIO_B0_01) + +// ESP hosted control pins +// MICROPY_HW_ESP_HOSTED_RESET: D6 = GPIO_B0_10 +#define MICROPY_HW_ESP_HOSTED_RESET (pin_GPIO_B0_10) +// GPIO0 = DATAREADY: D5 = pin_GPIO_EMC_08 +#define MICROPY_HW_ESP_HOSTED_GPIO0 (MICROPY_HW_WIFI_DATAREADY) + +#define MICROPY_HW_ESP_HOSTED_SHARED_PINS (1) diff --git a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk index 6bb9e607f652..cb0022c8ad1c 100755 --- a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk @@ -14,6 +14,14 @@ MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK = 1 +MICROPY_PY_NETWORK_ESP_HOSTED = 1 +CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) + +MICROPY_PY_BLUETOOTH = 1 +CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) +MICROPY_BLUETOOTH_NIMBLE = 1 +MICROPY_BLUETOOTH_BTSTACK = 0 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py From b1e3eba835ba1b05012bf1af4bbc2aaaa8694d43 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 30 Sep 2023 22:09:11 +0200 Subject: [PATCH 09/11] drivers/esp_hosted: Shorten the start-up time for BLE. Instead of waiting a fixed long time for absorbing ESP32 boot messages, just wait a shorter time for no more data to arrive Signed-off-by: robert-hh --- drivers/esp-hosted/esp_hosted_bthci_uart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/esp-hosted/esp_hosted_bthci_uart.c b/drivers/esp-hosted/esp_hosted_bthci_uart.c index 003054460d9a..25876f039180 100644 --- a/drivers/esp-hosted/esp_hosted_bthci_uart.c +++ b/drivers/esp-hosted/esp_hosted_bthci_uart.c @@ -122,9 +122,10 @@ int mp_bluetooth_hci_controller_init(void) { mp_uint_t start = mp_hal_ticks_ms(); // Skip bootloader messages. - while ((mp_hal_ticks_ms() - start) < 2500) { + while ((mp_hal_ticks_ms() - start) < 500) { if (mp_bluetooth_hci_uart_any()) { mp_bluetooth_hci_uart_readchar(); + start = mp_hal_ticks_ms(); } MICROPY_EVENT_POLL_HOOK } From 08286b772f7a8984117cbf482f475bd5bd275dc7 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 11 Nov 2023 20:46:29 +0100 Subject: [PATCH 10/11] mimxrt/docs: Extend the documentation for WLAN and BLE. Inluding instructions for connecting external modules and uploading the WLAN/BLE firmware. Signed-off-by: robert-hh --- docs/mimxrt/general.rst | 10 +- docs/mimxrt/quickref.rst | 61 +++++++++++- docs/mimxrt/wlan_pinout.rst | 190 ++++++++++++++++++++++++++++++++++++ 3 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 docs/mimxrt/wlan_pinout.rst diff --git a/docs/mimxrt/general.rst b/docs/mimxrt/general.rst index 35cf8e50eca2..3b482a64b6e5 100644 --- a/docs/mimxrt/general.rst +++ b/docs/mimxrt/general.rst @@ -25,8 +25,12 @@ The following boards are supported by the port: - MIMXRT1050-EVK - MIMXRT1060-EVK - MIMXRT1064-EVK +- MIMXRT1170-EVK - Teensy 4.0 - Teensy 4.1 +- Olimex RT1010py +- Seeed Arch Mix +- Adafruit Metro M7 Supported MCUs -------------- @@ -34,6 +38,8 @@ Supported MCUs +-------------+--------------------+-------------------------+ | Product | CPU | Memory | +=============+====================+=========================+ +| i.MX RT1171 | Cortex-M7 @960 MHz | 2 MB SRAM | ++-------------+--------------------+-------------------------+ | i.MX RT1064 | Cortex-M7 @600 MHz | 1 MB SRAM, 4 MB Flash | +-------------+--------------------+-------------------------+ | i.MX RT1061 | Cortex-M7 @600 MHz | 1 MB SRAM | @@ -71,8 +77,8 @@ operating modes, internal functioning, etc. For your convenience, a few technical specifications are provided below: * Architecture: ARM Cortex M7 -* CPU frequency: up to 600MHz -* Total RAM available: up to 1 MByte (see table) +* CPU frequency: up to 960MHz +* Total RAM available: up to 2 MByte (see table) * BootROM: 96KB * External FlashROM: code and data, via SPI Flash; usual size 2 - 16 MB Some boards provide additional external RAM and SPI flash. diff --git a/docs/mimxrt/quickref.rst b/docs/mimxrt/quickref.rst index 9f1efd4ffcad..b0d3824aa058 100644 --- a/docs/mimxrt/quickref.rst +++ b/docs/mimxrt/quickref.rst @@ -18,6 +18,7 @@ working with this board it may be useful to get an overview of the microcontroll general.rst tutorial/intro.rst pinout.rst + wlan_pinout.rst Installing MicroPython @@ -535,8 +536,8 @@ DHT modules may already have one. Ethernet driver --------------- -All MIMXRT boards except the MIMXRT1011 based boards and Teensy 4.0 support -Ethernet. Example usage:: +All MIMXRT boards except the MIMXRT101x based boards and Teensy 4.0 support +Ethernet. Example usage:: import network @@ -556,6 +557,62 @@ port and LAN(1) for the 1G port. For details of the network interface refer to the class :ref:`network.LAN `. +WLAN +---- + +In addition to Ethernet, some boards can be combined with an ESP32 based +WLAN module to support WLAN connectivity. WLAN is then another class +of the the :mod:`network` module:: + + import network + + wlan = network.WLAN(network.STA_IF) # create station interface + wlan.active(True) # activate the interface + wlan.scan() # scan for access points + wlan.isconnected() # check if the station is connected to an AP + wlan.connect('ssid', 'key') # connect to an AP + wlan.config('mac') # get the interface's MAC address + wlan.ifconfig() # get the interface's IP/netmask/gw/DNS addresses + + ap = network.WLAN(network.AP_IF) # create access-point interface + ap.active(True) # activate the interface + ap.config(ssid='ESP-AP') # set the SSID of the access point + +A useful function for connecting to your local WiFi network is:: + + def do_connect(): + import network + wlan = network.WLAN(network.STA_IF) + wlan.active(True) + if not wlan.isconnected(): + print('connecting to network...') + wlan.connect('ssid', 'key') + while not wlan.isconnected(): + pass + print('network config:', wlan.ifconfig()) + +Once the network is established the :mod:`socket ` module can be used +to create and use TCP/UDP sockets as usual, and the ``requests`` module for +convenient HTTP requests. + +Supported boards are: + +- ADAFRUIT_METRO_M7_AIRLIFT: WLAN adapter built-in +- MIMXRT1010_EVK with e.g. the Adafruit Airlift Uno board +- MIMXRT1015_EVK with e.g. the Adafruit Airlift Uno board +- OLIMEX RT1010py +- MIMXRT1020_EVK with e.g. the Adafruit Airlift Uno board +- MIMXRT1050_EVK with e.g. the Adafruit Airlift Uno board +- Seeed Arch Mix +- Teensy 4.0 with e.g. Adafruit Feather Airlift + Teensy/Feather adapter +- Teensy 4.1 with e.g. Adafruit Feather Airlift + Teensy/Feather adapter + +More boards may support it, but could not be tested yet. As external +WLAN module, any ESP32 based breakout can be used. It has to be loaded +with the proper firmware and wired up accordingly. For the wiring +scheme, see the :ref:`WLAN connection scheme `. + + Transferring files ------------------ diff --git a/docs/mimxrt/wlan_pinout.rst b/docs/mimxrt/wlan_pinout.rst new file mode 100644 index 000000000000..f7d566c7a71a --- /dev/null +++ b/docs/mimxrt/wlan_pinout.rst @@ -0,0 +1,190 @@ +.. _mimxrt_wlan_pinout: + +Managing external WLAN/BLE adapters +=================================== + +Connection scheme for the i.MXRT WLAN adapters +---------------------------------------------- + +Mapping between the NINA/esp_hosted signals and board pins by name. + +======== ========== ======= ======== ====== ====== ======= ======== +NINAW10 esp_hosted Airlift MIMXRT Teensy OLIMEX Seeed METRO M7 + Name Name Name 10xx_EVK 4.x RT1010 ArchMix Airlift +======== ========== ======= ======== ====== ====== ======= ======== +MOSI/RTS MOSI MOSI D11 D11 A2 J4-14 MOSI +MISO MISO MISO D12 D12 A1 J4-13 MISO +SCK SCK SCK D13 D13 A4 J4-15 SCK +CS CS CS D10 D5 A3 J4-12 ESP_CS +ACK/CTS HANDSHAKE Busy D7 D9 SCL2 J4-11 ESP_BUSY +RESET RESET Reset D5 D6 SDA2 J4-10 ESP_RESET +GPIO0 DATAREADY GP0 D6 D10 (*) J4-09 ESP_GP0 +SPI# 0 0 0 0 0 +TX TX TX D0 D0 D8 J4-06 D0 +RX RX RX D1 D1 D7 J4-07 D1 +RTS MOSI/RTS RTS D11 D11 A2 J4-14 MOSI +CTS CTS CTS D12 D12 SCL2 J4-13 ESP_BUSY +UART# 1 1 2 3 1 +======== ========== ======= ======== ====== ====== ======= ======== + +(*) GPIO0 of the WiFi module can be shared e.g. with SCK if they are + decoupled with a resistor from SCK (Host) to the GPIO input module. + +Mapping between firmware signal names and ESP32 pins for the NINA firmware +and esp_hosted firmware + +======== ========== ======== ======= ======= +NINAW10 esp_hosted NINA Airlift Airlift +Name Name W102 pin Name pin +======== ========== ======== ======= ======= +MOSI MOSI 12 MOSI 14 +MISO MISO 23 MISO 23 +SCK SCK 18 SCK 18 +GPIO1/CS CS 5 CS 5 +ACK HANDSHAKE 33 Busy 33 +RESET RESET EN Reset EN +GPIO0 DATAREADY 0 GP0 0 +TX TX 1 TX 1 +RX TX 3 RX 3 +RTS MOSI/RTS 12 - 14 +CTS CTS 33 - 33 +======== ========== ======== ======= ======= + +Mapping between the NINA/esp_hosted signals and adapter pins by name. + +======== ========== ======= ========= ======== ========= ========== +NINAW10 esp_hosted Airlift ItsyBitsy Feather METRO M7 Airlift +Name Name Name Add-on Add-on Airlift Uno Shield +======== ========== ======= ========= ======== ========= ========== +MOSI MOSI MOSI MOSI MOSI MOSI MOSI +MISO MISO MISO MISO MISO MISO MISO +SCK SCK SCK SCK SCK SCK SCK +GPIO1/CS CS CS ECS ESPCS ESP_CS CS +ACK HANDSHAKE Busy EBSY ESPBUSY ESP_BUSY BUSY +RESET RESET Reset RST ESPRESET ESP_RESET RST +GPIO0 DATAREADY GP0 GPIO0 ESPGPIO0 ESP_GP0 G0 +TX TX TX ETX ESPTX ESP_TX TX +RX RX RX ERX ESPRX ESP_RX RX +======== ========== ======= ========= ======== ========= ========== + +Signals required for WiFi: + +- NinaW10: MISO/MOSI/SCK (SPI), CS, Busy (ACK), Reset +- esp_hosted: MISO/MOSI/SCK (SPI), CS, Handshake, Dataready, Reset + +Signals required for Bluetooth: + +- NinaW10: RX/TX (UART), RTS (MOSI), CS, RESET +- esp_hosted: RX/TX (UART), RTS (MOSI), CS, RESET + +CTS seems not to be used, but specified. + +Signals required for NINA/esp_hosted firmware upload: + +- RX/TX (UART), GPIO0, Reset. + +If the hardware supports it, pull RESET low (!). That keeps the +ESP32 with the NINA/esp_hosted firmware silent and at low power +when not being used. + + +.. _mimxrt_wlan_firmware_upload: + +Instructions for WLAN/BLE firmware upload ESP32 module +------------------------------------------------------ + +The NINA firmware in the NINA module has to be updated for use with MicroPython. That can be done +using MicroPython and two small Python scripts. + +The firmware binaries are available at +https://github.com/micropython/micropython-lib/tree/master/micropython/espflash +There are the firmware files available for different esp32 modules. + +1. Adafruit Airlift modules with NINA firmware: NINA_FW_v1.5.0_Airlift.bin. +2. Adafruit Airlift modules with esp_hosted firmware: esp_hosted_airlift.bin +3. Arduino Nano RP2040 connect: NINA_FW_v1.5.0_W102.bin + +For the mimxrt boards with i.MX RT 101x MCU, you need the file NINA_FW_v1.5.0_Airlift.bin, for +all other boards esp_hosted_airlift.bin. + +For firmware upload, the following connections to the WiFi module are required: + +- Pin Reset (as above) +- Pin GPIO0 +- UART RX +- UART TX + +The GPIO pins and UART device id varies between boards. See the tables above. +At the Adafruit Metro M7 board, the UART is UART(1), and the Pin names +for reset and GPIO0 are ESP_RESET and ESP_GPIO0. +The firmware can be uploaded, using the espflash.py module, a short script +using espflash.py and mpremote. espflash.py is available at +https://github.com/micropython/micropython-lib/tree/master/micropython/espflash. +This place also holds the example script.:: + + import espflash + from machine import Pin + from machine import UART + import sys + sys.path.append("/flash") + + reset = Pin("ESP_RESET", Pin.OUT) + gpio0 = Pin("ESP_GPIO0", Pin.OUT) + uart = UART(0, 115200, timeout=350) + + md5sum = b"b0b9ab23da820a469e597c41364acb3a" + path = "/remote/NINA_FW_v1.5.0_Airlift.bin" + + esp = espflash.ESPFlash(reset, gpio0, uart) + # Enter bootloader download mode, at 115200 + esp.bootloader() + # Can now change to higher/lower baud rate + esp.set_baudrate(921600) + # Must call this first before any flash functions. + esp.flash_attach() + # Read flash size + size = esp.flash_read_size() + # Configure flash parameters. + esp.flash_config(size) + # Write firmware image from internal storage. + esp.flash_write_file(path) + # Compares file and flash MD5 checksum. + esp.flash_verify_file(path, md5sum) + # Resets the ESP32 chip. + esp.reboot() + +The script shows the set-up for the Metro M7 board. +The md5sum is the one of the WiFi firmware. It may change and +can be recalculated using e.g. the Linux *md5sum* command. It is used to +verify the firmware upload. To upload the firmware, place the firmware +and the above script (let's call it ninaflash.py) into the same directory +on your PC, and run the command:: + + mpremote connect mount . run ninaflash.py + +After a while, the upload will start. A typical start sequence looks like:: + + Local directory . is mounted at /remote + Failed to read response to command 8. + Failed to read response to command 8. + Changing baudrate => 921600 + Flash attached + Flash size 2.0 MBytes + Flash write size: 1310720 total_blocks: 320 block size: 4096 + Writing sequence number 0/320... + Writing sequence number 1/320... + Writing sequence number 2/320... + Writing sequence number 3/320... + Writing sequence number 4/320... + .... + .... + Writing sequence number 317/320... + Writing sequence number 318/320... + Writing sequence number 319/320... + Flash write finished + Flash verify: File MD5 b'b0b9ab23da820a469e597c41364acb3a' + Flash verify: Flash MD5 b'b0b9ab23da820a469e597c41364acb3a' + Firmware verified. + +The initial messages *Failed to read response to command 8.* +can be ignored. From 5f10e4907a4487b5e1595364260272e9c060467a Mon Sep 17 00:00:00 2001 From: robert-hh Date: Mon, 13 Nov 2023 18:48:14 +0100 Subject: [PATCH 11/11] mimxrt: Clean up Makefile, MIMXRT1015.ld and board files. - Makefile, main.c: Remove duplicated code and settings, which were added through combining several branches. - Install the proto-c compiler in ci.sh. - Move _dcd_data to the start of the .bss segment. This data item has to be 2k aligned. Moving it to the start of the segment avoids wasting memory. - Remove the board's manifest.py, now that many boards support networking. - Remove obsolete settings from mpconfigboard.mk files. Signed-off-by: robert-hh --- ports/mimxrt/Makefile | 17 +---------------- ports/mimxrt/boards/MIMXRT1015.ld | 4 ++-- .../boards/MIMXRT1015_EVK/mpconfigboard.mk | 2 -- ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py | 5 ----- .../MIMXRT1020_EVK/mbedtls_config_board.h | 8 -------- .../boards/MIMXRT1020_EVK/mpconfigboard.mk | 7 ------- ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py | 5 ----- .../boards/MIMXRT1050_EVK/mpconfigboard.mk | 6 ------ ports/mimxrt/boards/MIMXRT1060_EVK/manifest.py | 3 --- .../boards/MIMXRT1060_EVK/mpconfigboard.mk | 2 -- ports/mimxrt/boards/MIMXRT1064_EVK/manifest.py | 3 --- .../boards/MIMXRT1064_EVK/mpconfigboard.mk | 2 -- .../boards/MIMXRT1170_EVK/mpconfigboard.mk | 2 -- ports/mimxrt/boards/SEEED_ARCH_MIX/manifest.py | 3 --- .../boards/SEEED_ARCH_MIX/mpconfigboard.mk | 5 ----- ports/mimxrt/boards/TEENSY40/mpconfigboard.mk | 6 ------ ports/mimxrt/boards/TEENSY41/manifest.py | 5 ----- ports/mimxrt/boards/TEENSY41/mpconfigboard.mk | 5 ----- ports/mimxrt/boards/common.ld | 1 + ports/mimxrt/boards/manifest.py | 1 + ports/mimxrt/main.c | 8 -------- ports/mimxrt/mbedtls/mbedtls_config_port.h | 2 ++ tools/ci.sh | 1 + 23 files changed, 8 insertions(+), 95 deletions(-) delete mode 100644 ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py delete mode 100644 ports/mimxrt/boards/MIMXRT1020_EVK/mbedtls_config_board.h delete mode 100644 ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py delete mode 100644 ports/mimxrt/boards/MIMXRT1060_EVK/manifest.py delete mode 100644 ports/mimxrt/boards/MIMXRT1064_EVK/manifest.py delete mode 100644 ports/mimxrt/boards/SEEED_ARCH_MIX/manifest.py delete mode 100644 ports/mimxrt/boards/TEENSY41/manifest.py diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index 6702aafe53e0..4341c9aec307 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -91,14 +91,6 @@ INC += -I$(TOP)/shared/tinyusb INC += -I. INC += -Ihal -ifeq ($(MICROPY_PY_BLUETOOTH),1) -INC += \ - -I$(TOP)/extmod/nimble \ - -I$(TOP)/lib/mynewt-nimble/nimble/host/include \ - -I$(TOP)/lib/mynewt-nimble/nimble/include \ - -I$(TOP)/lib/mynewt-nimble/porting/nimble/include -endif - # All settings for Ethernet support are controller by the value of MICROPY_PY_LWIP ifeq ($(MICROPY_PY_LWIP),1) INC += -Ilwip_inc @@ -143,7 +135,7 @@ CFLAGS += -DMICROPY_PY_NETWORK_NINAW10=1 INC += -I$(TOP)/drivers/ninaw10 SRC_C += \ - drivers/ninaw10/nina_bt_hci.c \ + drivers/ninaw10/nina_bthci_uart.c \ drivers/ninaw10/nina_wifi_drv.c \ drivers/ninaw10/nina_wifi_bsp.c \ drivers/ninaw10/machine_pin_nina.c @@ -257,13 +249,6 @@ SRC_C += \ ticks.c \ usbd.c \ -ifeq ($(MICROPY_PY_BLUETOOTH),1) -SRC_C += \ - drivers/ninaw10/nina_bt_hci.c \ - mpbthciport.c \ - mpnimbleport.c -endif - SHARED_SRC_C += \ shared/libc/printf.c \ shared/libc/string0.c \ diff --git a/ports/mimxrt/boards/MIMXRT1015.ld b/ports/mimxrt/boards/MIMXRT1015.ld index 3ae405e483bc..6f8a42264070 100644 --- a/ports/mimxrt/boards/MIMXRT1015.ld +++ b/ports/mimxrt/boards/MIMXRT1015.ld @@ -27,8 +27,8 @@ dtcm_size = 0x00008000; ocrm_start = 0x20200000; ocrm_size = 0x00010000; -/* 10kiB stack. */ -__stack_size__ = 0x2800; +/* 8kiB stack. */ +__stack_size__ = 0x2000; _estack = __StackTop; _sstack = __StackLimit; diff --git a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk index bdbd9ea45b64..86c87bdbfa31 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk @@ -11,8 +11,6 @@ MICROPY_HW_FLASH_QE_ARG = 0x02 MICROPY_PY_BLUETOOTH ?= 1 MICROPY_BLUETOOTH_NIMBLE ?= 1 -MICROPY_BOOT_BUFFER_SIZE = (32 * 1024) - USE_UF2_BOOTLOADER = 1 MICROPY_PY_NETWORK_NINAW10 ?= 1 MICROPY_PY_SSL ?= 1 diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py b/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py deleted file mode 100644 index acaf5d0eac64..000000000000 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py +++ /dev/null @@ -1,5 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") -# Bluetooth -require("aioble") diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mbedtls_config_board.h b/ports/mimxrt/boards/MIMXRT1020_EVK/mbedtls_config_board.h deleted file mode 100644 index 4bca8ea0c040..000000000000 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mbedtls_config_board.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H -#define MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H - -#define MBEDTLS_ECP_NIST_OPTIM - -#include "ports/mimxrt/mbedtls/mbedtls_config.h" - -#endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H */ diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk index ef37a75a6ea9..801f458d739b 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk @@ -18,16 +18,9 @@ MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 MICROPY_PY_NETWORK = 1 MICROPY_PY_NETWORK_ESP_HOSTED = 1 -CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) MICROPY_PY_BLUETOOTH = 1 -CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) MICROPY_BLUETOOTH_NIMBLE = 1 -MICROPY_BLUETOOTH_BTSTACK = 0 - -MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"' - -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py JLINK_PATH ?= /media/RT1020-EVK/ JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py b/ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py deleted file mode 100644 index acaf5d0eac64..000000000000 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py +++ /dev/null @@ -1,5 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") -# Bluetooth -require("aioble") diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk index 7fd335429b69..c0bd33270d5f 100644 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk @@ -15,13 +15,7 @@ MICROPY_PY_LWIP = 1 MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 -MICROPY_PY_NETWORK = 1 MICROPY_PY_NETWORK_ESP_HOSTED = 1 -CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) MICROPY_PY_BLUETOOTH = 1 -CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) MICROPY_BLUETOOTH_NIMBLE = 1 -MICROPY_BLUETOOTH_BTSTACK = 0 - -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/MIMXRT1060_EVK/manifest.py b/ports/mimxrt/boards/MIMXRT1060_EVK/manifest.py deleted file mode 100644 index 107181c31ca7..000000000000 --- a/ports/mimxrt/boards/MIMXRT1060_EVK/manifest.py +++ /dev/null @@ -1,3 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") diff --git a/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk index 54539952fb4f..b150c35795bc 100644 --- a/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk @@ -17,8 +17,6 @@ MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py - JLINK_PATH ?= /media/RT1060-EVK/ JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink diff --git a/ports/mimxrt/boards/MIMXRT1064_EVK/manifest.py b/ports/mimxrt/boards/MIMXRT1064_EVK/manifest.py deleted file mode 100644 index 107181c31ca7..000000000000 --- a/ports/mimxrt/boards/MIMXRT1064_EVK/manifest.py +++ /dev/null @@ -1,3 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") diff --git a/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk index b393d7ed9f2c..ad521f72fc45 100644 --- a/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk @@ -17,8 +17,6 @@ MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py - JLINK_PATH ?= /media/RT1064-EVK/ deploy: $(BUILD)/firmware.bin diff --git a/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk index ef4ab683a215..9c95f0a8203b 100644 --- a/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk @@ -19,8 +19,6 @@ MICROPY_SSL_MBEDTLS = 1 MICROPY_PY_OPENAMP = 1 MICROPY_PY_OPENAMP_REMOTEPROC = 1 -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py - CFLAGS += -DCPU_MIMXRT1176DVMAA_cm7 \ -DMIMXRT117x_SERIES \ -DENET_ENHANCEDBUFFERDESCRIPTOR_MODE=1 \ diff --git a/ports/mimxrt/boards/SEEED_ARCH_MIX/manifest.py b/ports/mimxrt/boards/SEEED_ARCH_MIX/manifest.py deleted file mode 100644 index 107181c31ca7..000000000000 --- a/ports/mimxrt/boards/SEEED_ARCH_MIX/manifest.py +++ /dev/null @@ -1,3 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") diff --git a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk index de2f37005a4a..ffa2007e427a 100644 --- a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk +++ b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk @@ -18,13 +18,8 @@ MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 MICROPY_PY_NETWORK = 1 MICROPY_PY_NETWORK_ESP_HOSTED = 1 -CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) MICROPY_PY_BLUETOOTH = 1 -CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) MICROPY_BLUETOOTH_NIMBLE = 1 -MICROPY_BLUETOOTH_BTSTACK = 0 - -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py CFLAGS += -DSPI_RETRY_TIMES=1000000 diff --git a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk index 9408ed2fa700..80932c831cb6 100644 --- a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk @@ -15,16 +15,10 @@ MICROPY_PY_LWIP = 1 MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 -MICROPY_PY_NETWORK = 1 MICROPY_PY_NETWORK_ESP_HOSTED = 1 -CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) MICROPY_PY_BLUETOOTH = 1 -CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) MICROPY_BLUETOOTH_NIMBLE = 1 -MICROPY_BLUETOOTH_BTSTACK = 0 - -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py deploy: $(BUILD)/firmware.hex teensy_loader_cli --mcu=imxrt1062 -v -w $< diff --git a/ports/mimxrt/boards/TEENSY41/manifest.py b/ports/mimxrt/boards/TEENSY41/manifest.py deleted file mode 100644 index acaf5d0eac64..000000000000 --- a/ports/mimxrt/boards/TEENSY41/manifest.py +++ /dev/null @@ -1,5 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") -# Bluetooth -require("aioble") diff --git a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk index cb0022c8ad1c..232d4af53c3d 100755 --- a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk @@ -16,14 +16,9 @@ MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 MICROPY_PY_NETWORK = 1 MICROPY_PY_NETWORK_ESP_HOSTED = 1 -CFLAGS += -DMICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) MICROPY_PY_BLUETOOTH = 1 -CFLAGS += -DMICROPY_PY_BLUETOOTH=$(MICROPY_PY_BLUETOOTH) MICROPY_BLUETOOTH_NIMBLE = 1 -MICROPY_BLUETOOTH_BTSTACK = 0 - -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py deploy: $(BUILD)/firmware.hex teensy_loader_cli --mcu=imxrt1062 -v -w $< diff --git a/ports/mimxrt/boards/common.ld b/ports/mimxrt/boards/common.ld index 477ba38bc89a..4f82140942f0 100644 --- a/ports/mimxrt/boards/common.ld +++ b/ports/mimxrt/boards/common.ld @@ -238,6 +238,7 @@ SECTIONS __START_BSS = .; __bss_start__ = .; __bss_section_table = .; + *(.bss._dcd_data) *(m_usb_dma_noninit_data) *(.bss) *(.bss*) diff --git a/ports/mimxrt/boards/manifest.py b/ports/mimxrt/boards/manifest.py index a3393c4a9f66..eff7013842bb 100644 --- a/ports/mimxrt/boards/manifest.py +++ b/ports/mimxrt/boards/manifest.py @@ -4,6 +4,7 @@ require("ds18x20") require("dht") require("neopixel") +require("bundle-networking") include( "$(MPY_LIB_DIR)/micropython/bluetooth/aioble/manifest.py", client=True, diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index e37d467f17d2..3b6ee6190296 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -71,10 +71,6 @@ int main(void) { ticks_init(); pendsv_init(); - #if MICROPY_PY_BLUETOOTH - mp_bluetooth_hci_init(); - #endif - #if MICROPY_PY_LWIP // lwIP doesn't allow to reinitialise itself by subsequent calls to this function // because the system timeout list (next_timeout) is only ever reset by BSS clearing. @@ -85,10 +81,6 @@ int main(void) { #endif #endif - #if MICROPY_PY_BLUETOOTH - mp_bluetooth_hci_init(); - #endif - #if MICROPY_PY_NETWORK_CYW43 { cyw43_init(&cyw43_state); diff --git a/ports/mimxrt/mbedtls/mbedtls_config_port.h b/ports/mimxrt/mbedtls/mbedtls_config_port.h index 414f30527852..84919a1ae37e 100644 --- a/ports/mimxrt/mbedtls/mbedtls_config_port.h +++ b/ports/mimxrt/mbedtls/mbedtls_config_port.h @@ -26,6 +26,8 @@ #ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_H #define MICROPY_INCLUDED_MBEDTLS_CONFIG_H +#define MBEDTLS_ECP_NIST_OPTIM + // Time hook. #include extern time_t mimxrt_rtctime_seconds(time_t *timer); diff --git a/tools/ci.sh b/tools/ci.sh index cfc9754837f7..59d4fa61284a 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -254,6 +254,7 @@ function ci_webassembly_run_tests { function ci_mimxrt_setup { ci_gcc_arm_setup + sudo apt-get install protobuf-c-compiler } function ci_mimxrt_build {