diff --git a/docs/mimxrt/general.rst b/docs/mimxrt/general.rst index 35cf8e50eca2a..3b482a64b6e55 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 9f1efd4ffcad2..b0d3824aa0587 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 0000000000000..f7d566c7a71a4 --- /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. diff --git a/drivers/esp-hosted/esp_hosted_bthci_uart.c b/drivers/esp-hosted/esp_hosted_bthci_uart.c index 069509edde77e..649135e9f0a9d 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(); } mp_event_wait_ms(1); } diff --git a/drivers/ninaw10/nina_bthci_uart.c b/drivers/ninaw10/nina_bthci_uart.c index 50631711097f2..11a4ce573a269 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); diff --git a/drivers/ninaw10/nina_wifi_bsp.c b/drivers/ninaw10/nina_wifi_bsp.c index dc71c8260c61f..f42381f73797b 100644 --- a/drivers/ninaw10/nina_wifi_bsp.c +++ b/drivers/ninaw10/nina_wifi_bsp.c @@ -46,15 +46,22 @@ #define debug_printf(...) #endif +// Use the name CS instead of GPIO1 +#ifndef MICROPY_HW_NINA_CS +#define MICROPY_HW_NINA_CS MICROPY_HW_NINA_GPIO1 +#endif + int nina_bsp_init(void) { - mp_hal_pin_output(MICROPY_HW_NINA_GPIO1); + 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,29 +69,33 @@ 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_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; } @@ -103,10 +114,14 @@ int nina_bsp_atomic_exit(void) { } 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; } } @@ -129,7 +144,7 @@ int nina_bsp_spi_slave_select(uint32_t timeout) { } int nina_bsp_spi_slave_deselect(void) { - mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 1); + mp_hal_pin_write(MICROPY_HW_NINA_CS, 1); return 0; } diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index 7788b54ca57ff..4341c9aec3078 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 @@ -50,6 +57,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) @@ -108,8 +116,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 \ @@ -119,6 +128,18 @@ 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 +INC += -I$(TOP)/drivers/ninaw10 + +SRC_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 +endif # NXP SDK sources SRC_HAL_IMX_C += \ @@ -219,6 +240,7 @@ SRC_C += \ mpnetworkport.c \ msc_disk.c \ network_lan.c \ + nina_wifi_bsp.c \ pendsv.c \ pin.c \ sdcard.c \ @@ -246,6 +268,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/ADAFRUIT_METRO_M7/board.json b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json index 804b4fd734373..2e0e94d7ea75a 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json @@ -18,5 +18,8 @@ "product": "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 1ce06e7f408d7..60f189ac137f1 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h @@ -58,15 +58,39 @@ #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)) - // 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) +// CTS == NINA_ACK: GPIO_AD_11 +#define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK + +#else -#define MICROPY_HW_NINA_RTS pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_MOSI)) +// 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 diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk index 520cea063fb7e..0fd08b2d664f2 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 a616fbec64a59..ea9d1666c881d 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h @@ -82,3 +82,24 @@ 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) + +#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 592b89c68ecf7..302233a8585f8 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk @@ -10,6 +10,13 @@ MICROPY_HW_FLASH_QE_ARG = 0x02 USE_UF2_BOOTLOADER = 1 +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/MIMXRT1011.ld b/ports/mimxrt/boards/MIMXRT1011.ld index 0e961a49433f2..ef9269adef7bc 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 58b88e0fe3084..6f8a422640709 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; +/* 8kiB stack. */ +__stack_size__ = 0x2000; _estack = __StackTop; _sstack = __StackLimit; diff --git a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h index f47bbf4fa138b..d1b29ea905100 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h @@ -87,3 +87,24 @@ 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) + +#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 c5d02294bc3df..86c87bdbfa314 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk @@ -8,6 +8,10 @@ MICROPY_HW_FLASH_CLK = kFlexSpiSerialClk_100MHz MICROPY_HW_FLASH_QE_CMD = 0x31 MICROPY_HW_FLASH_QE_ARG = 0x02 -MICROPY_BOOT_BUFFER_SIZE = (32 * 1024) +MICROPY_PY_BLUETOOTH ?= 1 +MICROPY_BLUETOOTH_NIMBLE ?= 1 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK_NINAW10 ?= 1 +MICROPY_PY_SSL ?= 1 +MICROPY_SSL_MBEDTLS ?= 1 diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py b/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py deleted file mode 100644 index 107181c31ca7c..0000000000000 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/manifest.py +++ /dev/null @@ -1,3 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h index b4f777cf93b00..6bf601d645aec 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.h @@ -181,3 +181,31 @@ { 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) +#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) +// 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 5ef078210a2a2..801f458d739b3 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk @@ -16,8 +16,11 @@ MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK = 1 +MICROPY_PY_NETWORK_ESP_HOSTED = 1 -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py +MICROPY_PY_BLUETOOTH = 1 +MICROPY_BLUETOOTH_NIMBLE = 1 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 107181c31ca7c..0000000000000 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/manifest.py +++ /dev/null @@ -1,3 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.h index 59a5c4fa69f84..b7a23f089e44e 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 8b048c85eaa98..c0bd33270d5f2 100644 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk @@ -15,4 +15,7 @@ MICROPY_PY_LWIP = 1 MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py +MICROPY_PY_NETWORK_ESP_HOSTED = 1 + +MICROPY_PY_BLUETOOTH = 1 +MICROPY_BLUETOOTH_NIMBLE = 1 diff --git a/ports/mimxrt/boards/MIMXRT1060_EVK/manifest.py b/ports/mimxrt/boards/MIMXRT1060_EVK/manifest.py deleted file mode 100644 index 107181c31ca7c..0000000000000 --- 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 54539952fb4f9..b150c35795bc2 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 107181c31ca7c..0000000000000 --- 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 b393d7ed9f2c6..ad521f72fc458 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 ef4ab683a215c..9c95f0a8203b5 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/OLIMEX_RT1010/mpconfigboard.h b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h index 1ad2e9df5ebad..8f70b691b59f4 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: SCL2 = GPIO_AD_08 +#define MICROPY_HW_NINA_ACK (pin_GPIO_AD_08) +// NINA_CS: A3 = GPIO_AD_05 +#define MICROPY_HW_NINA_CS (pin_GPIO_AD_05) +// NINA_RESET: SDA2 = 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: A2 = GPIO_AD_04 +#define MICROPY_HW_NINA_RTS (pin_GPIO_AD_04) +// NINA_CTS: SCL2 = 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 7e9987de0cfe3..96329ca8b387e 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/SEEED_ARCH_MIX/manifest.py b/ports/mimxrt/boards/SEEED_ARCH_MIX/manifest.py deleted file mode 100644 index 107181c31ca7c..0000000000000 --- 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.h b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.h index 627b1aa3b1311..9941b86ab2b2f 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 7ea107b00df86..ffa2007e427a3 100644 --- a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk +++ b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk @@ -16,7 +16,10 @@ MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK = 1 +MICROPY_PY_NETWORK_ESP_HOSTED = 1 -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py +MICROPY_PY_BLUETOOTH = 1 +MICROPY_BLUETOOTH_NIMBLE = 1 CFLAGS += -DSPI_RETRY_TIMES=1000000 diff --git a/ports/mimxrt/boards/TEENSY40/mpconfigboard.h b/ports/mimxrt/boards/TEENSY40/mpconfigboard.h index 1a6227a60e074..e981bf6c27939 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 9393252d1a863..80932c831cb6e 100644 --- a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk @@ -11,5 +11,14 @@ 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_ESP_HOSTED = 1 + +MICROPY_PY_BLUETOOTH = 1 +MICROPY_BLUETOOTH_NIMBLE = 1 + 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 107181c31ca7c..0000000000000 --- a/ports/mimxrt/boards/TEENSY41/manifest.py +++ /dev/null @@ -1,3 +0,0 @@ -include("../manifest.py") - -require("bundle-networking") diff --git a/ports/mimxrt/boards/TEENSY41/mpconfigboard.h b/ports/mimxrt/boards/TEENSY41/mpconfigboard.h index bff319c6d1576..7bc56f84bc878 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 6bb9e607f6522..232d4af53c3dc 100755 --- a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk @@ -14,8 +14,11 @@ MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 USE_UF2_BOOTLOADER = 1 +MICROPY_PY_NETWORK = 1 +MICROPY_PY_NETWORK_ESP_HOSTED = 1 -FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py +MICROPY_PY_BLUETOOTH = 1 +MICROPY_BLUETOOTH_NIMBLE = 1 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 477ba38bc89a3..4f82140942f08 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 d7acab38373f0..eff7013842bb8 100644 --- a/ports/mimxrt/boards/manifest.py +++ b/ports/mimxrt/boards/manifest.py @@ -3,3 +3,12 @@ require("onewire") require("ds18x20") require("dht") +require("neopixel") +require("bundle-networking") +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 6b9d4fa17afe4..3b6ee6190296e 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; @@ -75,11 +79,6 @@ 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 #if MICROPY_PY_NETWORK_CYW43 @@ -108,6 +107,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 +173,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 +207,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/mbedtls/mbedtls_config_port.h b/ports/mimxrt/mbedtls/mbedtls_config_port.h index 414f30527852a..84919a1ae37e9 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/ports/mimxrt/mpbthciport.c b/ports/mimxrt/mpbthciport.c index 45f729671728d..dc262b57b9e6b 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 e1c605f452a32..678cf5a155c8a 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -56,7 +56,9 @@ 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) #define MICROPY_VFS (1) @@ -135,9 +137,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 (0) +#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) @@ -146,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 @@ -154,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) @@ -178,13 +192,44 @@ 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) }, +#else +#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_BOARD_NETWORK_INTERFACES \ + MICROPY_HW_NIC_CYW43 \ + MICROPY_HW_NIC_NINAW10 \ + MICROPY_BOARD_NETWORK_INTERFACES #ifndef MICROPY_BOARD_ROOT_POINTERS #define MICROPY_BOARD_ROOT_POINTERS diff --git a/ports/mimxrt/mpnetworkport.c b/ports/mimxrt/mpnetworkport.c index aa8eef3ee2390..413ff11d14a88 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 diff --git a/ports/mimxrt/nina_wifi_bsp.c b/ports/mimxrt/nina_wifi_bsp.c new file mode 100644 index 0000000000000..3adc437c624fb --- /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 diff --git a/ports/mimxrt/pendsv.h b/ports/mimxrt/pendsv.h index d68c5aa2d5d58..6aa218aed8f62 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 }; diff --git a/tools/ci.sh b/tools/ci.sh index 518eb7449713b..327f22e1d92b4 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -264,6 +264,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 { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy