diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ceb691a15b..e54bbb84b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -410,6 +410,7 @@ jobs: board: - "espressif_saola_1_wroom" - "espressif_saola_1_wrover" + - "microdev_micro_s2" - "unexpectedmaker_feathers2" steps: diff --git a/conf.py b/conf.py index bd9e31d7f9..1d4c420481 100644 --- a/conf.py +++ b/conf.py @@ -42,6 +42,9 @@ master_doc = 'docs/index' # Grab the JSON values to use while building the module support matrix # in 'shared-bindings/index.rst' +# The stubs must be built before we calculate the shared bindings matrix +subprocess.check_output(["make", "stubs"]) + #modules_support_matrix = shared_bindings_matrix.support_matrix_excluded_boards() modules_support_matrix = shared_bindings_matrix.support_matrix_by_board() @@ -77,7 +80,6 @@ source_suffix = { '.md': 'markdown', } -subprocess.check_output(["make", "stubs"]) extensions.append('autoapi.extension') autoapi_type = 'python' diff --git a/docs/porting.rst b/docs/porting.rst index db4ae76262..6cd59fefb1 100644 --- a/docs/porting.rst +++ b/docs/porting.rst @@ -51,10 +51,15 @@ as a natural "TODO" list. An example minimal build list is shown below: .. code-block:: makefile # These modules are implemented in ports//common-hal: - CIRCUITPY_MICROCONTROLLER = 0 # Typically the first module to create - CIRCUITPY_DIGITALIO = 0 # Typically the second module to create + + # Typically the first module to create + CIRCUITPY_MICROCONTROLLER = 0 + # Typically the second module to create + CIRCUITPY_DIGITALIO = 0 + # Other modules: CIRCUITPY_ANALOGIO = 0 CIRCUITPY_BUSIO = 0 + CIRCUITPY_COUNTIO = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_PULSEIO = 0 CIRCUITPY_OS = 0 @@ -63,22 +68,34 @@ as a natural "TODO" list. An example minimal build list is shown below: CIRCUITPY_AUDIOIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 + CIRCUITPY_SDCARDIO = 0 + CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_I2CPERIPHERAL = 0 - CIRCUITPY_DISPLAYIO = 0 # Requires SPI, PulseIO (stub ok) + # Requires SPI, PulseIO (stub ok): + CIRCUITPY_DISPLAYIO = 0 # These modules are implemented in shared-module/ - they can be included in # any port once their prerequisites in common-hal are complete. - CIRCUITPY_BITBANGIO = 0 # Requires DigitalIO - CIRCUITPY_GAMEPAD = 0 # Requires DigitalIO - CIRCUITPY_PIXELBUF = 0 # Requires neopixel_write or SPI (dotstar) - CIRCUITPY_RANDOM = 0 # Requires OS - CIRCUITPY_STORAGE = 0 # Requires OS, filesystem - CIRCUITPY_TOUCHIO = 0 # Requires Microcontroller - CIRCUITPY_USB_HID = 0 # Requires USB - CIRCUITPY_USB_MIDI = 0 # Requires USB - CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 # Does nothing without I2C - CIRCUITPY_ULAB = 0 # No requirements, but takes extra flash + # Requires DigitalIO: + CIRCUITPY_BITBANGIO = 0 + # Requires DigitalIO + CIRCUITPY_GAMEPAD = 0 + # Requires neopixel_write or SPI (dotstar) + CIRCUITPY_PIXELBUF = 0 + # Requires OS + CIRCUITPY_RANDOM = 0 + # Requires OS, filesystem + CIRCUITPY_STORAGE = 0 + # Requires Microcontroller + CIRCUITPY_TOUCHIO = 0 + # Requires USB + CIRCUITPY_USB_HID = 0 + CIRCUITPY_USB_MIDI = 0 + # Does nothing without I2C + CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 + # No requirements, but takes extra flash + CIRCUITPY_ULAB = 0 Step 2: Init -------------- diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index 7b96c14f29..e81ae188c2 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -28,6 +28,7 @@ import re import subprocess import sys +from concurrent.futures import ThreadPoolExecutor SUPPORTED_PORTS = ['atmel-samd', 'esp32s2', 'litex', 'mimxrt10xx', 'nrf', 'stm'] @@ -42,7 +43,7 @@ def get_circuitpython_root_dir(): def get_shared_bindings(): """ Get a list of modules in shared-bindings based on folder names """ - shared_bindings_dir = get_circuitpython_root_dir() / "shared-bindings" + shared_bindings_dir = get_circuitpython_root_dir() / "circuitpython-stubs" return [item.name for item in shared_bindings_dir.iterdir()] @@ -131,38 +132,44 @@ def lookup_setting(settings, key, default=''): key = value[2:-1] return value +def all_ports_all_boards(ports=SUPPORTED_PORTS): + for port in ports: + + port_dir = get_circuitpython_root_dir() / "ports" / port + for entry in (port_dir / "boards").iterdir(): + if not entry.is_dir(): + continue + yield (port, entry) + def support_matrix_by_board(use_branded_name=True): """ Compiles a list of the available core modules available for each board. """ base = build_module_map() - boards = dict() - for port in SUPPORTED_PORTS: - + def support_matrix(arg): + port, entry = arg port_dir = get_circuitpython_root_dir() / "ports" / port - for entry in (port_dir / "boards").iterdir(): - if not entry.is_dir(): - continue - board_modules = [] - board_name = entry.name + settings = get_settings_from_makefile(str(port_dir), entry.name) - settings = get_settings_from_makefile(str(port_dir), entry.name) + if use_branded_name: + with open(entry / "mpconfigboard.h") as get_name: + board_contents = get_name.read() + board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", + board_contents) + if board_name_re: + board_name = board_name_re.group(1).strip('"') - if use_branded_name: - with open(entry / "mpconfigboard.h") as get_name: - board_contents = get_name.read() - board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", - board_contents) - if board_name_re: - board_name = board_name_re.group(1).strip('"') + board_modules = [] + for module in base: + key = f'CIRCUITPY_{module.upper()}' + if int(lookup_setting(settings, key, '0')): + board_modules.append(base[module]['name']) - board_modules = [] - for module in base: - key = f'CIRCUITPY_{module.upper()}' - if int(lookup_setting(settings, key, '0')): - board_modules.append(base[module]['name']) - boards[board_name] = sorted(board_modules) + return (board_name, sorted(board_modules)) + + executor = ThreadPoolExecutor(max_workers=os.cpu_count()) + boards = dict(sorted(executor.map(support_matrix, all_ports_all_boards()))) #print(json.dumps(boards, indent=2)) return boards diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c index 8e99bc2099..378fb6267d 100755 --- a/lib/utils/pyexec.c +++ b/lib/utils/pyexec.c @@ -113,6 +113,8 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input start = mp_hal_ticks_ms(); mp_call_function_0(module_fun); mp_hal_set_interrupt_char(-1); // disable interrupt + // Handle any ctrl-c interrupt that arrived just in time + mp_handle_pending(); nlr_pop(); ret = 0; if (exec_flags & EXEC_FLAG_PRINT_EOF) { diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index b7b442414b..2ba112d00e 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-25 16:39-0700\n" +"POT-Creation-Date: 2020-08-27 11:21-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1349,8 +1349,8 @@ msgstr "" #: ports/nrf/common-hal/pulseio/PulseOut.c #: ports/stm/common-hal/pulseio/PulseOut.c msgid "" -"Port does not accept pins or frequency. " -"Construct and pass a PWMOut Carrier instead" +"Port does not accept pins or frequency. Construct and pass a PWMOut Carrier " +"instead" msgstr "" #: shared-bindings/_bleio/Adapter.c @@ -1365,6 +1365,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "" +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" diff --git a/ports/atmel-samd/common-hal/pulseio/PulseOut.c b/ports/atmel-samd/common-hal/pulseio/PulseOut.c index 3463bb5e20..086052a973 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseOut.c @@ -101,8 +101,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint32_t frequency, uint16_t duty_cycle) { if (!carrier || pin || frequency) { - mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. \ - Construct and pass a PWMOut Carrier instead")); + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } if (refcount == 0) { diff --git a/ports/cxd56/common-hal/pulseio/PulseOut.c b/ports/cxd56/common-hal/pulseio/PulseOut.c index 764a5860a9..f08e7cd7a0 100644 --- a/ports/cxd56/common-hal/pulseio/PulseOut.c +++ b/ports/cxd56/common-hal/pulseio/PulseOut.c @@ -64,8 +64,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint32_t frequency, uint16_t duty_cycle) { if (!carrier || pin || frequency) { - mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. \ - Construct and pass a PWMOut Carrier instead")); + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } if (pulse_fd < 0) { diff --git a/ports/esp32s2/boards/espressif_saola_1_wrover/sdkconfig b/ports/esp32s2/boards/espressif_saola_1_wrover/sdkconfig index e69de29bb2..9d8bbde967 100644 --- a/ports/esp32s2/boards/espressif_saola_1_wrover/sdkconfig +++ b/ports/esp32s2/boards/espressif_saola_1_wrover/sdkconfig @@ -0,0 +1,33 @@ +CONFIG_ESP32S2_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_TYPE_AUTO is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM16=y +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set +CONFIG_SPIRAM_SIZE=2097152 + +# +# PSRAM clock and cs IO for ESP32S2 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM clock and cs IO for ESP32S2 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_SPEED_80M is not set +CONFIG_SPIRAM_SPEED_40M=y +# CONFIG_SPIRAM_SPEED_26M is not set +# CONFIG_SPIRAM_SPEED_20M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set +# end of SPI RAM config diff --git a/ports/esp32s2/boards/microdev_micro_s2/board.c b/ports/esp32s2/boards/microdev_micro_s2/board.c new file mode 100644 index 0000000000..1dc30b5af8 --- /dev/null +++ b/ports/esp32s2/boards/microdev_micro_s2/board.c @@ -0,0 +1,56 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +#include "boards/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // USB + common_hal_never_reset_pin(&pin_GPIO19); + common_hal_never_reset_pin(&pin_GPIO20); + + // Debug UART + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + + // SPI Flash and RAM + common_hal_never_reset_pin(&pin_GPIO26); + common_hal_never_reset_pin(&pin_GPIO27); + common_hal_never_reset_pin(&pin_GPIO28); + common_hal_never_reset_pin(&pin_GPIO29); + common_hal_never_reset_pin(&pin_GPIO30); + common_hal_never_reset_pin(&pin_GPIO31); + common_hal_never_reset_pin(&pin_GPIO32); +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} diff --git a/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h b/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h new file mode 100644 index 0000000000..bb28fe16ad --- /dev/null +++ b/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h @@ -0,0 +1,35 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +//Micropython setup + +#define MICROPY_HW_BOARD_NAME "microDev microS2" +#define MICROPY_HW_MCU_NAME "ESP32S2" + +#define MICROPY_HW_LED (&pin_GPIO21) +#define MICROPY_HW_NEOPIXEL (&pin_GPIO33) + +#define AUTORESET_DELAY_MS 500 diff --git a/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.mk b/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.mk new file mode 100644 index 0000000000..783e7ad4c7 --- /dev/null +++ b/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.mk @@ -0,0 +1,15 @@ +USB_VID = 0x239A +USB_PID = 0x80C6 +USB_PRODUCT = "microS2" +USB_MANUFACTURER = "microDev" + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = MPZ + +# The default queue depth of 16 overflows on release builds, +# so increase it to 32. +CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32 + +CIRCUITPY_ESP_FLASH_MODE=qio +CIRCUITPY_ESP_FLASH_FREQ=40m +CIRCUITPY_ESP_FLASH_SIZE=16MB diff --git a/ports/esp32s2/boards/microdev_micro_s2/pins.c b/ports/esp32s2/boards/microdev_micro_s2/pins.c new file mode 100644 index 0000000000..25300b5c3c --- /dev/null +++ b/ports/esp32s2/boards/microdev_micro_s2/pins.c @@ -0,0 +1,49 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO33) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/esp32s2/boards/microdev_micro_s2/sdkconfig b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig new file mode 100644 index 0000000000..b73c4a8c20 --- /dev/null +++ b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig @@ -0,0 +1,35 @@ +CONFIG_ESP32S2_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_TYPE_AUTO is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 + +# +# PSRAM clock and cs IO for ESP32S2 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM clock and cs IO for ESP32S2 + +CONFIG_SPIRAM_SPIWP_SD3_PIN=28 +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_USE_AHB_DBUS3 is not set +# CONFIG_SPIRAM_SPEED_80M is not set +CONFIG_SPIRAM_SPEED_40M=y +# CONFIG_SPIRAM_SPEED_26M is not set +# CONFIG_SPIRAM_SPEED_20M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set +# end of SPI RAM config diff --git a/ports/esp32s2/boards/unexpectedmaker_feathers2/sdkconfig b/ports/esp32s2/boards/unexpectedmaker_feathers2/sdkconfig index e69de29bb2..b73c4a8c20 100644 --- a/ports/esp32s2/boards/unexpectedmaker_feathers2/sdkconfig +++ b/ports/esp32s2/boards/unexpectedmaker_feathers2/sdkconfig @@ -0,0 +1,35 @@ +CONFIG_ESP32S2_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_TYPE_AUTO is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 + +# +# PSRAM clock and cs IO for ESP32S2 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM clock and cs IO for ESP32S2 + +CONFIG_SPIRAM_SPIWP_SD3_PIN=28 +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_USE_AHB_DBUS3 is not set +# CONFIG_SPIRAM_SPEED_80M is not set +CONFIG_SPIRAM_SPEED_40M=y +# CONFIG_SPIRAM_SPEED_26M is not set +# CONFIG_SPIRAM_SPEED_20M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set +# end of SPI RAM config diff --git a/ports/esp32s2/common-hal/os/__init__.c b/ports/esp32s2/common-hal/os/__init__.c index 17bda75ad3..4d6a6a2bfc 100644 --- a/ports/esp32s2/common-hal/os/__init__.c +++ b/ports/esp32s2/common-hal/os/__init__.c @@ -30,6 +30,8 @@ #include "py/objtuple.h" #include "py/qstr.h" +#include "esp_system.h" + STATIC const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine @@ -57,5 +59,15 @@ mp_obj_t common_hal_os_uname(void) { } bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) { - return false; + uint32_t i = 0; + while (i < length) { + uint32_t new_random = esp_random(); + for (int j = 0; j < 4 && i < length; j++) { + buffer[i] = new_random & 0xff; + i++; + new_random >>= 8; + } + } + + return true; } diff --git a/ports/esp32s2/common-hal/pulseio/PulseOut.c b/ports/esp32s2/common-hal/pulseio/PulseOut.c index cfe750732b..e45492a893 100644 --- a/ports/esp32s2/common-hal/pulseio/PulseOut.c +++ b/ports/esp32s2/common-hal/pulseio/PulseOut.c @@ -37,8 +37,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint32_t frequency, uint16_t duty_cycle) { if (carrier || !pin || !frequency) { - mp_raise_NotImplementedError(translate("Port does not accept PWM carrier. \ - Pass a pin, frequency and duty cycle instead")); + mp_raise_NotImplementedError(translate("Port does not accept PWM carrier. Pass a pin, frequency and duty cycle instead")); } rmt_channel_t channel = esp32s2_peripherals_find_and_reserve_rmt(); diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index c039b14477..89ab166d51 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -44,11 +44,15 @@ #include "supervisor/memory.h" #include "supervisor/shared/tick.h" +#include "peripherals/rmt.h" #include "esp-idf/components/heap/include/esp_heap_caps.h" -#include "rmt.h" +#include "esp-idf/components/soc/soc/esp32s2/include/soc/cache_memory.h" #define HEAP_SIZE (48 * 1024) +uint32_t* heap; +uint32_t heap_size; + STATIC esp_timer_handle_t _tick_timer; void tick_timer_cb(void* arg) { @@ -67,6 +71,16 @@ safe_mode_t port_init(void) { heap = malloc(HEAP_SIZE); never_reset_module_internal_pins(); + + #ifdef CONFIG_SPIRAM + heap = (uint32_t*) (DRAM0_CACHE_ADDRESS_HIGH - CONFIG_SPIRAM_SIZE); + heap_size = CONFIG_SPIRAM_SIZE / sizeof(uint32_t); + #endif + + if (heap == NULL) { + heap = malloc(HEAP_SIZE); + heap_size = HEAP_SIZE / sizeof(uint32_t); + } return NO_SAFE_MODE; } @@ -106,7 +120,7 @@ uint32_t *port_heap_get_bottom(void) { } uint32_t *port_heap_get_top(void) { - return heap + (HEAP_SIZE / sizeof(uint32_t)); + return heap + heap_size; } uint32_t *port_stack_get_limit(void) { diff --git a/ports/nrf/common-hal/pulseio/PulseOut.c b/ports/nrf/common-hal/pulseio/PulseOut.c index 9f301a7306..f40dbea5c8 100644 --- a/ports/nrf/common-hal/pulseio/PulseOut.c +++ b/ports/nrf/common-hal/pulseio/PulseOut.c @@ -105,8 +105,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint32_t frequency, uint16_t duty_cycle) { if (!carrier || pin || frequency) { - mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. \ - Construct and pass a PWMOut Carrier instead")); + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } if (refcount == 0) { diff --git a/ports/stm/boards/espruino_pico/mpconfigboard.mk b/ports/stm/boards/espruino_pico/mpconfigboard.mk index 201237c9d6..b1b023dd58 100644 --- a/ports/stm/boards/espruino_pico/mpconfigboard.mk +++ b/ports/stm/boards/espruino_pico/mpconfigboard.mk @@ -10,7 +10,8 @@ MCU_VARIANT = STM32F401xE MCU_PACKAGE = UFQFPN48 LD_COMMON = boards/common_default.ld -LD_FILE = boards/STM32F401xd_fs.ld # use for internal flash +# use for internal flash +LD_FILE = boards/STM32F401xd_fs.ld # Disable ulab as we're nearly out of space on this board due to # INTERNAL_FLASH_FILESYSTEM. It can probably be reenabled if we enable diff --git a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk index 2b2c0d6db5..4d0bd4598d 100644 --- a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk +++ b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk @@ -13,5 +13,6 @@ MCU_PACKAGE = LQFP64 LD_COMMON = boards/common_default.ld LD_DEFAULT = boards/STM32F405_default.ld -LD_BOOT = boards/STM32F405_boot.ld # UF2 boot option +# UF2 boot option +LD_BOOT = boards/STM32F405_boot.ld UF2_OFFSET = 0x8010000 diff --git a/ports/stm/boards/meowbit_v121/mpconfigboard.mk b/ports/stm/boards/meowbit_v121/mpconfigboard.mk index 852836ef8f..a638183019 100644 --- a/ports/stm/boards/meowbit_v121/mpconfigboard.mk +++ b/ports/stm/boards/meowbit_v121/mpconfigboard.mk @@ -18,4 +18,5 @@ OPTIMIZATION_FLAGS = -Os LD_COMMON = boards/common_default.ld LD_FILE = boards/STM32F401xe_boot.ld -# LD_FILE = boards/STM32F401xe_fs.ld # use for internal flash +# use for internal flash +# LD_FILE = boards/STM32F401xe_fs.ld diff --git a/ports/stm/common-hal/os/__init__.c b/ports/stm/common-hal/os/__init__.c index 84deb81759..8da7243a30 100644 --- a/ports/stm/common-hal/os/__init__.c +++ b/ports/stm/common-hal/os/__init__.c @@ -72,16 +72,20 @@ bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { if (HAL_RNG_Init(&handle) != HAL_OK) mp_raise_ValueError(translate("RNG Init Error")); //Assign bytes - for (uint i = 0; i < length; i++) { - uint32_t temp; + uint32_t i = 0; + while (i < length) { + uint32_t new_random; uint32_t start = HAL_GetTick(); //the HAL function has a timeout, but it isn't long enough, and isn't adjustable while(!(__HAL_RNG_GET_FLAG(&handle,RNG_FLAG_DRDY)) && ((HAL_GetTick() - start) < RNG_TIMEOUT)); - // - if (HAL_RNG_GenerateRandomNumber(&handle, &temp) != HAL_OK) { + if (HAL_RNG_GenerateRandomNumber(&handle, &new_random) != HAL_OK) { mp_raise_ValueError(translate("Random number generation error")); } - *buffer = (uint8_t)temp; + for (int j = 0; j < 4 && i < length; j++) { + buffer[i] = new_random & 0xff; + i++; + new_random >>= 8; + } } //shut down the peripheral diff --git a/ports/stm/common-hal/pulseio/PulseOut.c b/ports/stm/common-hal/pulseio/PulseOut.c index 3bf23ad14b..963aee721a 100644 --- a/ports/stm/common-hal/pulseio/PulseOut.c +++ b/ports/stm/common-hal/pulseio/PulseOut.c @@ -118,8 +118,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint32_t frequency, uint16_t duty_cycle) { if (!carrier || pin || frequency) { - mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. \ - Construct and pass a PWMOut Carrier instead")); + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } // Add to active PulseOuts diff --git a/py/obj.c b/py/obj.c index 0cff2f1a4b..9dc0cf4749 100644 --- a/py/obj.c +++ b/py/obj.c @@ -67,6 +67,8 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t #ifdef RUN_BACKGROUND_TASKS RUN_BACKGROUND_TASKS; #endif + mp_handle_pending(); + #ifndef NDEBUG if (o_in == MP_OBJ_NULL) { mp_print_str(print, "(nil)"); diff --git a/supervisor/shared/micropython.c b/supervisor/shared/micropython.c index 245db11d42..bbc4807f97 100644 --- a/supervisor/shared/micropython.c +++ b/supervisor/shared/micropython.c @@ -29,14 +29,24 @@ #include "supervisor/serial.h" #include "lib/oofatfs/ff.h" #include "py/mpconfig.h" +#include "py/mpstate.h" +#include "py/runtime.h" #include "supervisor/shared/status_leds.h" +#if CIRCUITPY_WATCHDOG +#include "shared-bindings/watchdog/__init__.h" +#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception) +#else +#define WATCHDOG_EXCEPTION_CHECK() 0 +#endif + int mp_hal_stdin_rx_chr(void) { for (;;) { #ifdef MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_LOOP #endif + mp_handle_pending(); if (serial_bytes_available()) { toggle_rx_led(); return serial_read(); diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c index 4af59f78e3..f26e1e79d1 100644 --- a/supervisor/shared/tick.c +++ b/supervisor/shared/tick.c @@ -27,6 +27,7 @@ #include "supervisor/shared/tick.h" #include "py/mpstate.h" +#include "py/runtime.h" #include "supervisor/linker.h" #include "supervisor/filesystem.h" #include "supervisor/background_callback.h" @@ -149,17 +150,7 @@ void mp_hal_delay_ms(mp_uint_t delay) { while (remaining > 0) { RUN_BACKGROUND_TASKS; // Check to see if we've been CTRL-Ced by autoreload or the user. - if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) - { - // clear exception and generate stacktrace - MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; - nlr_raise(&MP_STATE_VM(mp_kbd_exception)); - } - if( MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)) || - WATCHDOG_EXCEPTION_CHECK()) { - // stop sleeping immediately - break; - } + mp_handle_pending(); remaining = end_tick - port_get_raw_ticks(NULL); // We break a bit early so we don't risk setting the alarm before the time when we call // sleep. diff --git a/tools/mpconfig_category_reader.py b/tools/mpconfig_category_reader.py new file mode 100644 index 0000000000..2f813931e8 --- /dev/null +++ b/tools/mpconfig_category_reader.py @@ -0,0 +1,31 @@ +filepath = '../py/circuitpy_mpconfig.mk' +with open(filepath) as fp: + line = fp.readline() + cnt = 1 + fullbuild = [] + defon = [] + defoff = [] + while line: + wordlist = line.split() + if wordlist: + if wordlist[-1] == "$(CIRCUITPY_FULL_BUILD)": + fullbuild.append(wordlist[0]) + elif wordlist[-1] == "0": + defoff.append(wordlist[0]) + elif wordlist[-1] == "1": + defon.append(wordlist[0]) + line = fp.readline() + cnt += 1 + + print(str(cnt) + " Lines Read\n") + print("\nFULL BUILDS ------------------------") + for string in fullbuild: + print(string) + + print("\nON BUILDS ------------------------") + for string in defon: + print(string) + + print("\nOFF BUILDS ------------------------") + for string in defoff: + print(string)