From 708f7fe1ac57cddac641c6760729021a66aac53c Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 10 Dec 2021 02:08:54 +0200 Subject: [PATCH] Update to MicroPython 1.17 --- src/hal/stm32/h7/include/stm32h7xx_hal_conf.h | 1 + src/micropython | 2 +- src/omv/boards/NANO33/manifest.py | 1 + src/omv/boards/NANO33/omv_boardconfig.h | 30 +++++---- src/omv/boards/PORTENTA/imlib_config.h | 2 +- src/omv/ports/nrf/main.c | 61 ++++++++++++++++--- src/omv/ports/nrf/nrf52xxx.ld.S | 5 +- src/omv/ports/nrf/omv_portconfig.mk | 27 +++++--- src/omv/ports/rp2/main.c | 6 +- src/omv/ports/rp2/modules/py_nina.c | 2 +- src/omv/ports/stm32/main.c | 14 +++-- src/omv/ports/stm32/modules/py_fir_lepton.c | 4 +- src/omv/ports/stm32/modules/py_winc.c | 2 +- src/omv/ports/stm32/omv_portconfig.mk | 27 ++++---- 14 files changed, 130 insertions(+), 54 deletions(-) diff --git a/src/hal/stm32/h7/include/stm32h7xx_hal_conf.h b/src/hal/stm32/h7/include/stm32h7xx_hal_conf.h index 7b2aff7b3..4931395e1 100644 --- a/src/hal/stm32/h7/include/stm32h7xx_hal_conf.h +++ b/src/hal/stm32/h7/include/stm32h7xx_hal_conf.h @@ -458,6 +458,7 @@ #ifdef HAL_UART_MODULE_ENABLED #include "stm32h7xx_hal_uart.h" + #include "stm32h7xx_ll_lpuart.h" #endif /* HAL_UART_MODULE_ENABLED */ #ifdef HAL_USART_MODULE_ENABLED diff --git a/src/micropython b/src/micropython index 2bbe0bcb7..7138a47a2 160000 --- a/src/micropython +++ b/src/micropython @@ -1 +1 @@ -Subproject commit 2bbe0bcb7ed7103fdd808d1332aaeef10a44064e +Subproject commit 7138a47a265cda2dd8b75ad96f489e51120b65f8 diff --git a/src/omv/boards/NANO33/manifest.py b/src/omv/boards/NANO33/manifest.py index 674838c3a..ea188bf1a 100644 --- a/src/omv/boards/NANO33/manifest.py +++ b/src/omv/boards/NANO33/manifest.py @@ -2,3 +2,4 @@ freeze ("$(MPY_LIB_DIR)/", "hts221.py") freeze ("$(MPY_LIB_DIR)/", "lps22h.py") freeze ("$(MPY_LIB_DIR)/", "lsm9ds1.py") freeze ("$(MPY_LIB_DIR)/apds9960/", "apds9960") +freeze("$(PORT_DIR)/modules/scripts", "_mkfs.py") diff --git a/src/omv/boards/NANO33/omv_boardconfig.h b/src/omv/boards/NANO33/omv_boardconfig.h index 7d25cf26a..44b2301ed 100644 --- a/src/omv/boards/NANO33/omv_boardconfig.h +++ b/src/omv/boards/NANO33/omv_boardconfig.h @@ -76,23 +76,27 @@ #define OMV_CORE_VBAT "3.3" // USB IRQn. -#define OMV_USB_IRQN (USBD_IRQn) +#define OMV_USB_IRQN (USBD_IRQn) // Linker script constants (see the linker script template port/x.ld.S). -#define OMV_FB_MEMORY SRAM // Framebuffer, fb_alloc -#define OMV_MAIN_MEMORY SRAM // data, bss and heap memory -#define OMV_STACK_MEMORY SRAM // stack memory +#define OMV_FB_MEMORY SRAM // Framebuffer, fb_alloc +#define OMV_MAIN_MEMORY SRAM // data, bss and heap memory +#define OMV_STACK_MEMORY SRAM // stack memory -#define OMV_FB_SIZE (128K) // FB memory: header + QVGA/GS image -#define OMV_FB_ALLOC_SIZE (16K) // minimum fb alloc size -#define OMV_STACK_SIZE (8K) -#define OMV_HEAP_SIZE (64K) -#define OMV_JPEG_BUF_SIZE (16 * 1024) // IDE JPEG buffer (header + data). +#define OMV_FB_SIZE (128K) // FB memory: header + QVGA/GS image +#define OMV_FB_ALLOC_SIZE (16K) // minimum fb alloc size +#define OMV_STACK_SIZE (8K) +#define OMV_HEAP_SIZE (64K) +#define OMV_JPEG_BUF_SIZE (16 * 1024) // IDE JPEG buffer (header + data). -#define OMV_TEXT_ORIGIN 0x00026000 -#define OMV_TEXT_LENGTH 744K // Arduino bootloader starts at (0xE0000) - SD_SIZE (152K) -#define OMV_SRAM_ORIGIN 0x20004000 // Reserve 16K for SD memory. -#define OMV_SRAM_LENGTH 240K // RAM_SIZE - SD_RAM_SIZE +#define OMV_TEXT_ORIGIN 0x00026000 +#define OMV_FFS_LENGTH 64K +#define OMV_TEXT_LENGTH 680K // 0x00000 -> 0x26000 Soft device (152K) + // 0x26000 -> 0xD0000 OpenMV firmware (680K). + // 0xD0000 -> 0xE0000 Flash filesystem (64K). + // 0xE0000 -> 0x100000 Arduino bootloader +#define OMV_SRAM_ORIGIN 0x20004000 // Reserve 16K for SD memory. +#define OMV_SRAM_LENGTH 240K // RAM_SIZE - SD_RAM_SIZE // FIR I2C #define FIR_I2C_ID (0) diff --git a/src/omv/boards/PORTENTA/imlib_config.h b/src/omv/boards/PORTENTA/imlib_config.h index 304de382c..60d735dc8 100644 --- a/src/omv/boards/PORTENTA/imlib_config.h +++ b/src/omv/boards/PORTENTA/imlib_config.h @@ -60,7 +60,7 @@ #define IMLIB_ENABLE_LAPLACIAN // Enable bilateral() -#define IMLIB_ENABLE_BILATERAL +//#define IMLIB_ENABLE_BILATERAL // Enable cartoon() // #define IMLIB_ENABLE_CARTOON diff --git a/src/omv/ports/nrf/main.c b/src/omv/ports/nrf/main.c index 8efcc0a86..20e8fd227 100644 --- a/src/omv/ports/nrf/main.c +++ b/src/omv/ports/nrf/main.c @@ -38,8 +38,8 @@ #include "py/stackctrl.h" #include "py/gc.h" #include "py/compile.h" -#include "lib/utils/pyexec.h" -#include "readline.h" +#include "shared/runtime/pyexec.h" +#include "shared/readline/readline.h" #include "gccollect.h" #include "modmachine.h" #include "modmusic.h" @@ -77,6 +77,13 @@ #include "usb_cdc.h" #endif +#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE +#include "extmod/vfs_fat.h" +#include "lib/oofatfs/ff.h" +#include "extmod/vfs.h" +#include "modules/nrf/flashbdev.h" +#endif + #include "usbdbg.h" #include "py_audio.h" #include "framebuffer.h" @@ -93,6 +100,28 @@ uint32_t HAL_GetHalVersion() extern uint32_t _heap_start; extern uint32_t _heap_end; +#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE +STATIC int vfs_mount_and_chdir(mp_obj_t bdev, mp_obj_t mount_point) { + nlr_buf_t nlr; + mp_int_t ret = -MP_EIO; + if (nlr_push(&nlr) == 0) { + mp_obj_t args[] = { bdev, mount_point }; + mp_vfs_mount(2, args, (mp_map_t *)&mp_const_empty_map); + mp_vfs_chdir(mount_point); + ret = 0; // success + nlr_pop(); + } else { + mp_obj_base_t *exc = nlr.ret_val; + if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(exc->type), MP_OBJ_FROM_PTR(&mp_type_OSError))) { + mp_obj_t v = mp_obj_exception_get_value(MP_OBJ_FROM_PTR(exc)); + mp_obj_get_int_maybe(v, &ret); // get errno value + ret = -ret; + } + } + return ret; +} +#endif + int main(int argc, char **argv) { soft_reset: @@ -125,6 +154,7 @@ soft_reset: readline_init0(); + #if MICROPY_PY_MACHINE_HW_SPI spi_init0(); #endif @@ -166,13 +196,30 @@ soft_reset: MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_NEW_SMALL_INT(115200), }; - MP_STATE_PORT(board_stdio_uart) = - machine_hard_uart_type.make_new((mp_obj_t)&machine_hard_uart_type, MP_ARRAY_SIZE(args), 0, args); + MP_STATE_PORT(board_stdio_uart) = machine_hard_uart_type.make_new( + (mp_obj_t)&machine_hard_uart_type, MP_ARRAY_SIZE(args), 0, args); } #endif pin_init0(); + #if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE + flashbdev_init(); + + // Try to mount the flash on "/flash" and chdir to it for the boot-up directory. + mp_obj_t mount_point = MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash); + int ret = vfs_mount_and_chdir((mp_obj_t)&nrf_flash_obj, mount_point); + + if ((ret == -MP_ENODEV) || (ret == -MP_EIO)) { + pyexec_frozen_module("_mkfs.py"); // Frozen script for formatting flash filesystem. + ret = vfs_mount_and_chdir((mp_obj_t)&nrf_flash_obj, mount_point); + } + + if (ret != 0) { + printf("MPY: can't mount flash\n"); + } + #endif + #if MICROPY_MBFS microbit_filesystem_init(); #endif @@ -320,10 +367,10 @@ mp_import_stat_t mp_import_stat(const char *path) { return uos_mbfs_import_stat(path); } -STATIC mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args) { +mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { return uos_mbfs_open(n_args, args); } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open); +MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); #else // use dummy functions - no filesystem available @@ -335,7 +382,7 @@ mp_import_stat_t mp_import_stat(const char *path) { return MP_IMPORT_STAT_NO_EXIST; } -STATIC mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { mp_raise_OSError(MP_EPERM); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); diff --git a/src/omv/ports/nrf/nrf52xxx.ld.S b/src/omv/ports/nrf/nrf52xxx.ld.S index 1a0143923..89178d2ad 100644 --- a/src/omv/ports/nrf/nrf52xxx.ld.S +++ b/src/omv/ports/nrf/nrf52xxx.ld.S @@ -24,7 +24,7 @@ MEMORY _heap_size = OMV_HEAP_SIZE; /* required amount of heap */ _stack_size = OMV_STACK_SIZE; /* minimum amount of stack */ _fs_start = OMV_TEXT_ORIGIN + OMV_TEXT_LENGTH; -_fs_end = OMV_TEXT_ORIGIN + OMV_TEXT_LENGTH + 64K; +_fs_end = OMV_TEXT_ORIGIN + OMV_TEXT_LENGTH + OMV_FFS_LENGTH; /* define output sections */ SECTIONS @@ -40,6 +40,7 @@ SECTIONS *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ . = ALIGN(4); _etext = .; /* define a global symbol at end of code */ + _unused_flash_start = .; } >FLASH_TEXT /* used by the startup to initialize data */ @@ -118,3 +119,5 @@ SECTIONS .ARM.attributes 0 : { *(.ARM.attributes) } } + +_unused_flash_len = (ORIGIN(FLASH_TEXT) + LENGTH(FLASH_TEXT)) - _unused_flash_start; diff --git a/src/omv/ports/nrf/omv_portconfig.mk b/src/omv/ports/nrf/omv_portconfig.mk index 1d49aae73..a8085f0e0 100644 --- a/src/omv/ports/nrf/omv_portconfig.mk +++ b/src/omv/ports/nrf/omv_portconfig.mk @@ -178,6 +178,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/imlib/, \ FIRM_OBJ += $(wildcard $(BUILD)/$(OMV_DIR)/ports/$(PORT)/*.o) FIRM_OBJ += $(wildcard $(BUILD)/$(MICROPY_DIR)/modules/*.o) +FIRM_OBJ += $(wildcard $(BUILD)/$(MICROPY_DIR)/modules/nrf/*.o) FIRM_OBJ += $(wildcard $(BUILD)/$(MICROPY_DIR)/ports/$(PORT)/modules/*.o) #------------- MicroPy Objects -------------------# @@ -209,16 +210,18 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/extmod/,\ modutimeq.o \ machine_i2c.o \ utime_mphal.o \ + vfs.o \ + vfs_fat.o \ + vfs_lfs.o \ + vfs_fat_file.o \ + vfs_fat_diskio.o \ + vfs_reader.o \ + vfs_blockdev.o \ + machine_mem.o \ ) FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/lib/,\ - utils/pyexec.o \ - utils/printf.o \ - utils/sys_stdio_mphal.o \ - utils/interrupt_char.o \ - libc/string0.o \ - timeutils/timeutils.o \ - mp-readline/readline.o \ + littlefs/*.o \ tinyusb/src/common/tusb_fifo.o \ tinyusb/src/device/usbd.o \ tinyusb/src/device/usbd_control.o \ @@ -227,6 +230,16 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/lib/,\ tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.o \ ) +FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/shared/,\ + libc/printf.o \ + libc/string0.o \ + runtime/pyexec.o \ + runtime/interrupt_char.o \ + runtime/sys_stdio_mphal.o \ + timeutils/timeutils.o \ + readline/readline.o \ + ) + FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/lib/libm/,\ math.o \ fmodf.o \ diff --git a/src/omv/ports/rp2/main.c b/src/omv/ports/rp2/main.c index c6e0ccb7e..1d028d1fc 100644 --- a/src/omv/ports/rp2/main.c +++ b/src/omv/ports/rp2/main.c @@ -32,9 +32,9 @@ #include "py/mperrno.h" #include "py/mphal.h" #include "py/stackctrl.h" -#include "lib/mp-readline/readline.h" -#include "lib/utils/gchelper.h" -#include "lib/utils/pyexec.h" +#include "shared/readline/readline.h" +#include "shared/runtime/gchelper.h" +#include "shared/runtime/pyexec.h" #include "tusb.h" #include "uart.h" #include "modmachine.h" diff --git a/src/omv/ports/rp2/modules/py_nina.c b/src/omv/ports/rp2/modules/py_nina.c index 297b36709..188dfeb4f 100644 --- a/src/omv/ports/rp2/modules/py_nina.c +++ b/src/omv/ports/rp2/modules/py_nina.c @@ -22,7 +22,7 @@ #include "py/runtime.h" #include "mperrno.h" -#include "lib/netutils/netutils.h" +#include "shared/netutils/netutils.h" #include "modnetwork.h" #include "nina.h" diff --git a/src/omv/ports/stm32/main.c b/src/omv/ports/stm32/main.c index 722503756..0c60b7f30 100644 --- a/src/omv/ports/stm32/main.c +++ b/src/omv/ports/stm32/main.c @@ -27,7 +27,6 @@ #include "gc.h" #include "stackctrl.h" #include "gccollect.h" -#include "readline.h" #include "timer.h" #include "pin.h" #include "usb.h" @@ -40,7 +39,8 @@ #include "extmod/vfs.h" #include "extmod/vfs_fat.h" -#include "lib/utils/pyexec.h" +#include "shared/runtime/pyexec.h" +#include "shared/readline/readline.h" #include "irq.h" #include "rng.h" @@ -88,6 +88,7 @@ #if MICROPY_PY_BLUETOOTH #include "extmod/modbluetooth.h" +#include "mpbthciport.h" #endif int errno; @@ -234,7 +235,8 @@ void NORETURN __fatal_error(const char *msg) { storage_flush(); // Initialize the USB device if it's not already initialize to allow // the host to mount the filesystem and access the error log. - pyb_usb_dev_init(pyb_usb_dev_detect(), USBD_VID, USBD_PID_CDC_MSC, USBD_MODE_CDC_MSC, 0, NULL, NULL); + pyb_usb_dev_init(pyb_usb_dev_detect(), MICROPY_HW_USB_VID, + MICROPY_HW_USB_PID_CDC_MSC, USBD_MODE_CDC_MSC, 0, NULL, NULL); } } for (uint i = 0;;) { @@ -555,8 +557,7 @@ soft_reset: systick_enable_dispatch(SYSTICK_DISPATCH_LWIP, mod_network_lwip_poll_wrapper); #endif #if MICROPY_PY_BLUETOOTH - extern void mp_bluetooth_hci_systick(uint32_t ticks_ms); - systick_enable_dispatch(SYSTICK_DISPATCH_BLUETOOTH_HCI, mp_bluetooth_hci_systick); + mp_bluetooth_hci_init(); #endif #if MICROPY_PY_NETWORK_CYW43 @@ -686,7 +687,8 @@ soft_reset: // Init USB device to default setting if it was not already configured if (!(pyb_usb_flags & PYB_USB_FLAG_USB_MODE_CALLED)) { - pyb_usb_dev_init(pyb_usb_dev_detect(), USBD_VID, USBD_PID_CDC_MSC, USBD_MODE_CDC_MSC, 0, NULL, NULL); + pyb_usb_dev_init(pyb_usb_dev_detect(), MICROPY_HW_USB_VID, + MICROPY_HW_USB_PID_CDC_MSC, USBD_MODE_CDC_MSC, 0, NULL, NULL); } // report if SDRAM failed diff --git a/src/omv/ports/stm32/modules/py_fir_lepton.c b/src/omv/ports/stm32/modules/py_fir_lepton.c index f4de713bc..48063b6a7 100644 --- a/src/omv/ports/stm32/modules/py_fir_lepton.c +++ b/src/omv/ports/stm32/modules/py_fir_lepton.c @@ -87,8 +87,8 @@ static void fir_lepton_spi_resync() flir_lepton_spi_rx_timer.mode = SOFT_TIMER_MODE_ONE_SHOT; flir_lepton_spi_rx_timer.expiry_ms = VOSPI_SYNC_MS + mp_hal_ticks_ms(); flir_lepton_spi_rx_timer.delta_ms = VOSPI_SYNC_MS; - flir_lepton_spi_rx_timer.callback = (mp_obj_t) &fir_lepton_spi_resync_callback_obj; - soft_timer_insert(&flir_lepton_spi_rx_timer); + flir_lepton_spi_rx_timer.py_callback = (mp_obj_t) &fir_lepton_spi_resync_callback_obj; + soft_timer_insert(&flir_lepton_spi_rx_timer, VOSPI_SYNC_MS); } #if defined(OMV_FIR_LEPTON_CHECK_CRC) diff --git a/src/omv/ports/stm32/modules/py_winc.c b/src/omv/ports/stm32/modules/py_winc.c index 492c65968..525426041 100644 --- a/src/omv/ports/stm32/modules/py_winc.c +++ b/src/omv/ports/stm32/modules/py_winc.c @@ -18,7 +18,7 @@ #include "py/objlist.h" #include "py/stream.h" #include "py/runtime.h" -#include "lib/netutils/netutils.h" +#include "shared/netutils/netutils.h" #include "modnetwork.h" #include "pin.h" #include "genhdr/pins.h" diff --git a/src/omv/ports/stm32/omv_portconfig.mk b/src/omv/ports/stm32/omv_portconfig.mk index 200ffb7d2..c6861b4c9 100644 --- a/src/omv/ports/stm32/omv_portconfig.mk +++ b/src/omv/ports/stm32/omv_portconfig.mk @@ -20,7 +20,6 @@ MPY_CFLAGS += -I$(MP_BOARD_CONFIG_DIR) MPY_CFLAGS += -I$(BUILD)/$(MICROPY_DIR)/ MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/ MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/py/ -MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/lib/mp-readline MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/lib/oofatfs MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/lib/lwip/src/include/ MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/ports/stm32/ @@ -281,6 +280,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\ machine_uart.o \ machine_adc.o \ machine_timer.o \ + machine_bitstream.o \ pybthread.o \ mpthreadport.o \ posix_helpers.o \ @@ -290,21 +290,25 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\ ) #------------- MicroPy Objects ----------------# -FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/lib/,\ - utils/mpirq.o \ - utils/pyexec.o \ - utils/printf.o \ - utils/interrupt_char.o \ - utils/sys_stdio_mphal.o \ - utils/gchelper_m3.o \ - utils/gchelper_native.o \ +FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/shared/,\ + libc/printf.o \ libc/string0.o \ + libc/abort_.o \ + runtime/mpirq.o \ + runtime/pyexec.o \ + runtime/interrupt_char.o \ + runtime/sys_stdio_mphal.o \ + runtime/gchelper_m3.o \ + runtime/gchelper_native.o \ + runtime/stdout_helpers.o \ netutils/*.o \ timeutils/timeutils.o \ + readline/readline.o \ + ) + +FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/lib/,\ berkeley-db-1.xx/btree/*.o \ berkeley-db-1.xx/mpool/*.o \ - embed/abort_.o \ - mp-readline/readline.o \ ) FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/lib/libm/,\ @@ -374,6 +378,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/extmod/,\ machine_pulse.o \ machine_signal.o \ machine_pinbase.o \ + machine_bitstream.o \ utime_mphal.o \ modonewire.o \ uos_dupterm.o \