From 016242aa26527adc99b762789b050cb2d2c26f72 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 14 May 2022 06:29:38 -0500 Subject: [PATCH 01/39] Get rid of a memset() for the case where finalisers are enabled This saves 24 bytes of flash on trinket m0 --- py/gc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/py/gc.c b/py/gc.c index 826540d353..5f959f3ed4 100644 --- a/py/gc.c +++ b/py/gc.c @@ -138,7 +138,6 @@ void gc_init(void *start, void *end) { MP_STATE_MEM(gc_alloc_table_start) = (byte *)start; #if MICROPY_ENABLE_FINALISER - size_t gc_finaliser_table_byte_len = (MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB + BLOCKS_PER_FTB - 1) / BLOCKS_PER_FTB; MP_STATE_MEM(gc_finaliser_table_start) = MP_STATE_MEM(gc_alloc_table_start) + MP_STATE_MEM(gc_alloc_table_byte_len) + 1; #endif @@ -150,15 +149,11 @@ void gc_init(void *start, void *end) { assert(MP_STATE_MEM(gc_pool_start) >= MP_STATE_MEM(gc_finaliser_table_start) + gc_finaliser_table_byte_len); #endif - // Clear ATBs plus one more byte. The extra byte might be read when we read the final ATB and - // then try to count its tail. Clearing the byte ensures it is 0 and ends the chain. Without an - // FTB, it'll just clear the pool byte early. - memset(MP_STATE_MEM(gc_alloc_table_start), 0, MP_STATE_MEM(gc_alloc_table_byte_len) + 1); - - #if MICROPY_ENABLE_FINALISER - // clear FTBs - memset(MP_STATE_MEM(gc_finaliser_table_start), 0, gc_finaliser_table_byte_len); - #endif + // Clear ATBs & finalisers (if enabled). This also clears the extra byte + // which appears between ATBs and finalisers that ensures every chain in + // the ATB terminates, rather than erroneously using bits from the + // finalisers. + memset(MP_STATE_MEM(gc_alloc_table_start), 0, MP_STATE_MEM(gc_pool_start) - MP_STATE_MEM(gc_alloc_table_start)); // Set first free ATB index to the start of the heap. for (size_t i = 0; i < MICROPY_ATB_INDICES; i++) { From cb331309c94663e7035dd4dd3b486b0af4515101 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 14 May 2022 07:34:38 -0500 Subject: [PATCH 02/39] skip optimized memcpy/memset for small builds This saves 100 bytes on trinket_m0 at the price of making many memset & memcpy calls slower. --- shared/libc/string0.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/shared/libc/string0.c b/shared/libc/string0.c index 86e7cc5960..92b063c552 100644 --- a/shared/libc/string0.c +++ b/shared/libc/string0.c @@ -28,6 +28,8 @@ #include #include +#include "py/mpconfig.h" + #ifndef likely #define likely(x) __builtin_expect((x), 1) #endif @@ -35,6 +37,7 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" void *memcpy(void *dst, const void *src, size_t n) { +#if CIRCUITPY_FULL_BUILD if (likely(!(((uintptr_t)dst) & 3) && !(((uintptr_t)src) & 3))) { // pointers aligned uint32_t *d = dst; @@ -56,7 +59,9 @@ void *memcpy(void *dst, const void *src, size_t n) { // copy byte *((uint8_t*)d) = *((const uint8_t*)s); } - } else { + } else +#endif + { // unaligned access, copy bytes uint8_t *d = dst; const uint8_t *s = src; @@ -93,6 +98,7 @@ void *memmove(void *dest, const void *src, size_t n) { } void *memset(void *s, int c, size_t n) { +#if CIRCUITPY_FULL_BUILD if (c == 0 && ((uintptr_t)s & 3) == 0) { // aligned store of 0 uint32_t *s32 = s; @@ -106,7 +112,9 @@ void *memset(void *s, int c, size_t n) { if (n & 1) { *((uint8_t*)s32) = 0; } - } else { + } else +#endif + { uint8_t *s2 = s; for (; n > 0; n--) { *s2++ = c; From d875eb2ff4c84d7c384ce7ce0bad86c66169d00e Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 19 May 2022 22:57:43 +0200 Subject: [PATCH 03/39] Add support for VCC-GND Studio YD-RP2040 --- .../boards/vcc_gnd_yd_rp2040/board.c | 40 +++++++++++++ .../boards/vcc_gnd_yd_rp2040/mpconfigboard.h | 2 + .../boards/vcc_gnd_yd_rp2040/mpconfigboard.mk | 15 +++++ .../vcc_gnd_yd_rp2040/pico-sdk-configboard.h | 1 + .../boards/vcc_gnd_yd_rp2040/pins.c | 56 +++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c create mode 100644 ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/vcc_gnd_yd_rp2040/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/vcc_gnd_yd_rp2040/pins.c diff --git a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c new file mode 100644 index 0000000000..e992ec063c --- /dev/null +++ b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Fabian Affolter + * + * 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 "supervisor/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} + +void board_deinit(void) { +} diff --git a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.h b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.h new file mode 100644 index 0000000000..01d74410e9 --- /dev/null +++ b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.h @@ -0,0 +1,2 @@ +#define MICROPY_HW_BOARD_NAME "VCC-GND Studio YD RP2040" +#define MICROPY_HW_MCU_NAME "rp2040" diff --git a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.mk b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.mk new file mode 100644 index 0000000000..5a478a49a1 --- /dev/null +++ b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.mk @@ -0,0 +1,15 @@ +USB_VID = 0x2E8A +USB_PID = 0x000B +USB_PRODUCT = "YD-RP2040" +USB_MANUFACTURER = "VCC-GND Studio" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" + +CIRCUITPY__EVE = 1 + +# Include these Python libraries in firmware +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SimpleIO diff --git a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/pico-sdk-configboard.h b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/pico-sdk-configboard.h new file mode 100644 index 0000000000..36da55d457 --- /dev/null +++ b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/pico-sdk-configboard.h @@ -0,0 +1 @@ +// Put board-specific pico-sdk definitions here. This file must exist. diff --git a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/pins.c b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/pins.c new file mode 100644 index 0000000000..c2b39dd740 --- /dev/null +++ b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/pins.c @@ -0,0 +1,56 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP29), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_GP29_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_GP23), MP_ROM_PTR(&pin_GPIO23) }, + + { MP_ROM_QSTR(MP_QSTR_RGB), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, + +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 91e15af84e42338e459a5cc784e17e4de55e13c8 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 27 Jun 2022 09:49:00 -0500 Subject: [PATCH 04/39] fix diagnostic when building unix port for tests --- py/gc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py/gc.c b/py/gc.c index 5f959f3ed4..fc6bc90b67 100644 --- a/py/gc.c +++ b/py/gc.c @@ -146,6 +146,8 @@ void gc_init(void *start, void *end) { MP_STATE_MEM(gc_pool_end) = end; #if MICROPY_ENABLE_FINALISER + size_t gc_finaliser_table_byte_len = (MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB + BLOCKS_PER_FTB - 1) / BLOCKS_PER_FTB; + (void)gc_finaliser_table_byte_len; // avoid unused variable diagnostic if asserts are disabled assert(MP_STATE_MEM(gc_pool_start) >= MP_STATE_MEM(gc_finaliser_table_start) + gc_finaliser_table_byte_len); #endif From e9b9cac2321654a8b62c1e6e798eee11b6d3c1b8 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 9 Sep 2022 15:11:35 -0700 Subject: [PATCH 05/39] Prevent folder from trying to move inside itself --- supervisor/shared/web_workflow/web_workflow.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index e09c87f624..3f2c924923 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -1080,7 +1080,19 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { destination[destinationlen - 1] = '\0'; } - FRESULT result = f_rename(fs, path, destination); + // Check to see if we're moving a directory into itself. + FILINFO file; + FRESULT result = f_stat(fs, path, &file); + if (result == FR_OK) { + if ((file.fattrib & AM_DIR) != 0 && + strlen(destination) > strlen(path) && + destination[strlen(path)] == '/' && + strncmp(path, destination, strlen(path)) == 0) { + result = FR_NO_PATH; + } else { + result = f_rename(fs, path, destination); + } + } #if CIRCUITPY_USB_MSC usb_msc_unlock(); #endif From 9e13e8e991f0c1731e041a2824ef6fc3701367e0 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 13 Sep 2022 08:42:35 -0700 Subject: [PATCH 06/39] Moved folder moving inside itself checks into f_rename --- extmod/vfs_fat.c | 19 +++---------------- lib/oofatfs/ff.c | 15 +++++++++++++++ supervisor/shared/web_workflow/web_workflow.c | 14 +------------- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index d19a53a9ef..64a3ce05f6 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -225,22 +225,7 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_ const char *old_path = mp_obj_str_get_str(path_in); const char *new_path = mp_obj_str_get_str(path_out); - // Check to see if we're moving a directory into itself. This occurs when we're moving a - // directory where the old path is a prefix of the new and the next character is a "/" and thus - // preserves the original directory name. - FILINFO fno; - FRESULT res = f_stat(&self->fatfs, old_path, &fno); - if (res != FR_OK) { - mp_raise_OSError_fresult(res); - } - if ((fno.fattrib & AM_DIR) != 0 && - strlen(new_path) > strlen(old_path) && - new_path[strlen(old_path)] == '/' && - strncmp(old_path, new_path, strlen(old_path)) == 0) { - mp_raise_OSError(MP_EINVAL); - } - - res = f_rename(&self->fatfs, old_path, new_path); + FRESULT res = f_rename(&self->fatfs, old_path, new_path); if (res == FR_EXIST) { // if new_path exists then try removing it (but only if it's a file) fat_vfs_remove_internal(vfs_in, path_out, 0); // 0 == file attribute @@ -249,6 +234,8 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_ } if (res == FR_OK) { return mp_const_none; + } else if (res == FR_NO_PATH) { + mp_raise_OSError(MP_EINVAL); } else { mp_raise_OSError_fresult(res); } diff --git a/lib/oofatfs/ff.c b/lib/oofatfs/ff.c index 6188aead2d..d6fc7ebcc2 100644 --- a/lib/oofatfs/ff.c +++ b/lib/oofatfs/ff.c @@ -4816,6 +4816,21 @@ FRESULT f_rename ( DEF_NAMBUF + // Check to see if we're moving a directory into itself. This occurs when we're moving a + // directory where the old path is a prefix of the new and the next character is a "/" and thus + // preserves the original directory name. + FILINFO fno; + res = f_stat(fs, path_old, &fno); + if (res != FR_OK) { + return res; + } + if ((fno.fattrib & AM_DIR) != 0 && + strlen(path_new) > strlen(path_old) && + path_new[strlen(path_old)] == '/' && + strncmp(path_old, path_new, strlen(path_old)) == 0) { + return FR_NO_PATH; + } + res = find_volume(fs, FA_WRITE); /* Get logical drive of the old object */ if (res == FR_OK) { djo.obj.fs = fs; diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index 3f2c924923..e09c87f624 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -1080,19 +1080,7 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { destination[destinationlen - 1] = '\0'; } - // Check to see if we're moving a directory into itself. - FILINFO file; - FRESULT result = f_stat(fs, path, &file); - if (result == FR_OK) { - if ((file.fattrib & AM_DIR) != 0 && - strlen(destination) > strlen(path) && - destination[strlen(path)] == '/' && - strncmp(path, destination, strlen(path)) == 0) { - result = FR_NO_PATH; - } else { - result = f_rename(fs, path, destination); - } - } + FRESULT result = f_rename(fs, path, destination); #if CIRCUITPY_USB_MSC usb_msc_unlock(); #endif From 7d8ff20dac8dfd030466610f9ed9a2afe29f07bc Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 4 Oct 2022 17:25:48 +0530 Subject: [PATCH 07/39] add initial storage extension support --- ports/espressif/supervisor/internal_flash.c | 59 +++++++++++++++------ 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/ports/espressif/supervisor/internal_flash.c b/ports/espressif/supervisor/internal_flash.c index 2f17b48f0c..b53af2a490 100644 --- a/ports/espressif/supervisor/internal_flash.c +++ b/ports/espressif/supervisor/internal_flash.c @@ -42,7 +42,7 @@ #include "supervisor/flash.h" #include "supervisor/usb.h" -STATIC const esp_partition_t *_partition; +STATIC const esp_partition_t *_partition[2]; // TODO: Split the caching out of supervisor/shared/external_flash so we can use it. #define SECTOR_SIZE 4096 @@ -50,9 +50,12 @@ STATIC uint8_t _cache[SECTOR_SIZE]; STATIC uint32_t _cache_lba = 0xffffffff; void supervisor_flash_init(void) { - _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, + _partition[0] = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + _partition[1] = esp_partition_find_first(ESP_PARTITION_TYPE_APP, + ESP_PARTITION_SUBTYPE_APP_OTA_1, + NULL); } uint32_t supervisor_flash_get_block_size(void) { @@ -60,7 +63,7 @@ uint32_t supervisor_flash_get_block_size(void) { } uint32_t supervisor_flash_get_block_count(void) { - return _partition->size / FILESYSTEM_BLOCK_SIZE; + return (_partition[0]->size + _partition[1]->size) / FILESYSTEM_BLOCK_SIZE; } void port_internal_flash_flush(void) { @@ -68,10 +71,23 @@ void port_internal_flash_flush(void) { } mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { - esp_partition_read(_partition, - block * FILESYSTEM_BLOCK_SIZE, - dest, - num_blocks * FILESYSTEM_BLOCK_SIZE); + uint32_t offset = block * FILESYSTEM_BLOCK_SIZE; + uint32_t read_total = num_blocks * FILESYSTEM_BLOCK_SIZE; + + if (offset > _partition[0]->size) { + // only read from partition 1 + esp_partition_read(_partition[1], (offset - _partition[0]->size), dest, read_total); + } else if ((offset + read_total) > _partition[0]->size) { + // first read from partition 0, then partition 1 + uint32_t read_0 = _partition[0]->size - offset; + uint32_t read_1 = read_total - read_0; + esp_partition_read(_partition[0], offset, dest, read_0); + esp_partition_read(_partition[1], 0, (dest + read_0), read_1); + } else { + // only read from partition 0 + esp_partition_read(_partition[0], offset, dest, read_total); + } + return 0; } @@ -84,12 +100,10 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 uint8_t block_offset = block_address % blocks_per_sector; if (_cache_lba != block_address) { - esp_partition_read(_partition, - sector_offset, - _cache, - SECTOR_SIZE); + supervisor_flash_read_blocks(_cache, sector_offset / FILESYSTEM_BLOCK_SIZE, blocks_per_sector); _cache_lba = sector_offset; } + for (uint8_t b = block_offset; b < blocks_per_sector; b++) { // Stop copying after the last block. if (block >= num_blocks) { @@ -100,11 +114,24 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 FILESYSTEM_BLOCK_SIZE); block++; } - esp_partition_erase_range(_partition, sector_offset, SECTOR_SIZE); - esp_partition_write(_partition, - sector_offset, - _cache, - SECTOR_SIZE); + + if (sector_offset > _partition[0]->size) { + // only write to partition 1 + esp_partition_erase_range(_partition[1], sector_offset - _partition[0]->size, SECTOR_SIZE); + esp_partition_write(_partition[1], sector_offset - _partition[0]->size, _cache, SECTOR_SIZE); + } else if ((sector_offset + SECTOR_SIZE) > _partition[0]->size) { + // first write to partition 0, then partition 1 + uint32_t write_0 = _partition[0]->size - sector_offset; + uint32_t write_1 = SECTOR_SIZE - write_0; + esp_partition_erase_range(_partition[0], sector_offset, write_0); + esp_partition_write(_partition[0], sector_offset, _cache, write_0); + esp_partition_erase_range(_partition[1], 0, write_1); + esp_partition_write(_partition[1], 0, _cache + write_0, write_1); + } else { + // only write to partition 0 + esp_partition_erase_range(_partition[0], sector_offset, SECTOR_SIZE); + esp_partition_write(_partition[0], sector_offset, _cache, SECTOR_SIZE); + } } return 0; // success From 9fe7308b88614b674b99161871be7bdeb4f0bcb1 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 4 Oct 2022 17:26:28 +0530 Subject: [PATCH 08/39] conditionally add storage extension --- ports/espressif/supervisor/internal_flash.c | 24 ++++++++++++++++++--- py/circuitpy_mpconfig.mk | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ports/espressif/supervisor/internal_flash.c b/ports/espressif/supervisor/internal_flash.c index b53af2a490..4c1400469b 100644 --- a/ports/espressif/supervisor/internal_flash.c +++ b/ports/espressif/supervisor/internal_flash.c @@ -42,7 +42,13 @@ #include "supervisor/flash.h" #include "supervisor/usb.h" -STATIC const esp_partition_t *_partition[2]; +#if CIRCUITPY_STORAGE_EXTEND +#define PARTITION_NUM (2) +#else +#define PARTITION_NUM (1) +#endif + +STATIC const esp_partition_t *_partition[PARTITION_NUM]; // TODO: Split the caching out of supervisor/shared/external_flash so we can use it. #define SECTOR_SIZE 4096 @@ -53,9 +59,11 @@ void supervisor_flash_init(void) { _partition[0] = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + #if CIRCUITPY_STORAGE_EXTEND _partition[1] = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); + #endif } uint32_t supervisor_flash_get_block_size(void) { @@ -63,7 +71,11 @@ uint32_t supervisor_flash_get_block_size(void) { } uint32_t supervisor_flash_get_block_count(void) { + #if CIRCUITPY_STORAGE_EXTEND return (_partition[0]->size + _partition[1]->size) / FILESYSTEM_BLOCK_SIZE; + #else + return _partition[0]->size / FILESYSTEM_BLOCK_SIZE; + #endif } void port_internal_flash_flush(void) { @@ -74,6 +86,7 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n uint32_t offset = block * FILESYSTEM_BLOCK_SIZE; uint32_t read_total = num_blocks * FILESYSTEM_BLOCK_SIZE; + #if CIRCUITPY_STORAGE_EXTEND if (offset > _partition[0]->size) { // only read from partition 1 esp_partition_read(_partition[1], (offset - _partition[0]->size), dest, read_total); @@ -83,7 +96,9 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n uint32_t read_1 = read_total - read_0; esp_partition_read(_partition[0], offset, dest, read_0); esp_partition_read(_partition[1], 0, (dest + read_0), read_1); - } else { + } else + #endif + { // only read from partition 0 esp_partition_read(_partition[0], offset, dest, read_total); } @@ -115,6 +130,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 block++; } + #if CIRCUITPY_STORAGE_EXTEND if (sector_offset > _partition[0]->size) { // only write to partition 1 esp_partition_erase_range(_partition[1], sector_offset - _partition[0]->size, SECTOR_SIZE); @@ -127,7 +143,9 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 esp_partition_write(_partition[0], sector_offset, _cache, write_0); esp_partition_erase_range(_partition[1], 0, write_1); esp_partition_write(_partition[1], 0, _cache + write_0, write_1); - } else { + } else + #endif + { // only write to partition 0 esp_partition_erase_range(_partition[0], sector_offset, SECTOR_SIZE); esp_partition_write(_partition[0], sector_offset, _cache, SECTOR_SIZE); diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index fc270f2c59..d66dd7011b 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -384,6 +384,9 @@ CFLAGS += -DCIRCUITPY_STATUS_BAR=$(CIRCUITPY_STATUS_BAR) CIRCUITPY_STORAGE ?= 1 CFLAGS += -DCIRCUITPY_STORAGE=$(CIRCUITPY_STORAGE) +CIRCUITPY_STORAGE_EXTEND ?= $(CIRCUITPY_DUALBANK) +CFLAGS += -DCIRCUITPY_STORAGE_EXTEND=$(CIRCUITPY_STORAGE_EXTEND) + CIRCUITPY_STRUCT ?= 1 CFLAGS += -DCIRCUITPY_STRUCT=$(CIRCUITPY_STRUCT) From 2618e11002d6306aa22073a70bd0151ad7acfc4c Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 4 Oct 2022 19:32:56 +0530 Subject: [PATCH 09/39] use next update partition --- ports/espressif/supervisor/internal_flash.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ports/espressif/supervisor/internal_flash.c b/ports/espressif/supervisor/internal_flash.c index 4c1400469b..3c136cc9fa 100644 --- a/ports/espressif/supervisor/internal_flash.c +++ b/ports/espressif/supervisor/internal_flash.c @@ -37,7 +37,8 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" -#include "components/spi_flash/include/esp_partition.h" +#include "esp_ota_ops.h" +#include "esp_partition.h" #include "supervisor/flash.h" #include "supervisor/usb.h" @@ -60,9 +61,7 @@ void supervisor_flash_init(void) { ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); #if CIRCUITPY_STORAGE_EXTEND - _partition[1] = esp_partition_find_first(ESP_PARTITION_TYPE_APP, - ESP_PARTITION_SUBTYPE_APP_OTA_1, - NULL); + _partition[1] = esp_ota_get_next_update_partition(NULL); #endif } From b0ef35d50ba99c73789f86498d68a45172aa587f Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 5 Oct 2022 20:05:47 +0530 Subject: [PATCH 10/39] update storage extension implementation --- ports/espressif/supervisor/internal_flash.c | 143 +++++++++++++------- supervisor/flash.h | 4 + supervisor/shared/filesystem.c | 6 + 3 files changed, 101 insertions(+), 52 deletions(-) diff --git a/ports/espressif/supervisor/internal_flash.c b/ports/espressif/supervisor/internal_flash.c index 3c136cc9fa..d6e96732ba 100644 --- a/ports/espressif/supervisor/internal_flash.c +++ b/ports/espressif/supervisor/internal_flash.c @@ -24,6 +24,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + #include "supervisor/internal_flash.h" #include @@ -32,31 +33,46 @@ #include "extmod/vfs.h" #include "extmod/vfs_fat.h" + #include "py/mphal.h" #include "py/obj.h" #include "py/runtime.h" -#include "lib/oofatfs/ff.h" #include "esp_ota_ops.h" #include "esp_partition.h" +#include "supervisor/filesystem.h" #include "supervisor/flash.h" #include "supervisor/usb.h" -#if CIRCUITPY_STORAGE_EXTEND -#define PARTITION_NUM (2) -#else -#define PARTITION_NUM (1) -#endif - -STATIC const esp_partition_t *_partition[PARTITION_NUM]; +#define OP_READ 0 +#define OP_WRITE 1 // TODO: Split the caching out of supervisor/shared/external_flash so we can use it. #define SECTOR_SIZE 4096 STATIC uint8_t _cache[SECTOR_SIZE]; STATIC uint32_t _cache_lba = 0xffffffff; +#if CIRCUITPY_STORAGE_EXTEND +#if FF_MAX_SS == FF_MIN_SS +#define SECSIZE(fs) (FF_MIN_SS) +#else +#define SECSIZE(fs) ((fs)->ssize) +#endif // FF_MAX_SS == FF_MIN_SS +STATIC DWORD fatfs_bytes(void) { + FATFS *fatfs = filesystem_circuitpy(); + return (fatfs->csize * SECSIZE(fatfs)) * (fatfs->n_fatent - 2); +} +STATIC bool storage_extended = true; +STATIC const esp_partition_t *_partition[2]; +#else +STATIC const esp_partition_t *_partition[1]; +#endif // CIRCUITPY_STORAGE_EXTEND + void supervisor_flash_init(void) { + if (_partition[0] != NULL) { + return; + } _partition[0] = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); @@ -71,38 +87,60 @@ uint32_t supervisor_flash_get_block_size(void) { uint32_t supervisor_flash_get_block_count(void) { #if CIRCUITPY_STORAGE_EXTEND - return (_partition[0]->size + _partition[1]->size) / FILESYSTEM_BLOCK_SIZE; + return ((storage_extended) ? (_partition[0]->size + _partition[1]->size) : _partition[0]->size) / FILESYSTEM_BLOCK_SIZE; #else return _partition[0]->size / FILESYSTEM_BLOCK_SIZE; #endif } void port_internal_flash_flush(void) { - } -mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { - uint32_t offset = block * FILESYSTEM_BLOCK_SIZE; - uint32_t read_total = num_blocks * FILESYSTEM_BLOCK_SIZE; - - #if CIRCUITPY_STORAGE_EXTEND - if (offset > _partition[0]->size) { - // only read from partition 1 - esp_partition_read(_partition[1], (offset - _partition[0]->size), dest, read_total); - } else if ((offset + read_total) > _partition[0]->size) { - // first read from partition 0, then partition 1 - uint32_t read_0 = _partition[0]->size - offset; - uint32_t read_1 = read_total - read_0; - esp_partition_read(_partition[0], offset, dest, read_0); - esp_partition_read(_partition[1], 0, (dest + read_0), read_1); - } else - #endif - { - // only read from partition 0 - esp_partition_read(_partition[0], offset, dest, read_total); +STATIC void single_partition_rw(const esp_partition_t *partition, uint8_t *data, + const uint32_t offset, const uint32_t size_total, const bool op) { + if (op == OP_READ) { + esp_partition_read(partition, offset, data, size_total); + } else { + esp_partition_erase_range(partition, offset, size_total); + esp_partition_write(partition, offset, _cache, size_total); } +} - return 0; +#if CIRCUITPY_STORAGE_EXTEND +STATIC void multi_partition_rw(uint8_t *data, + const uint32_t offset, const uint32_t size_total, const bool op) { + if (offset > _partition[0]->size) { + // only r/w partition 1 + single_partition_rw(_partition[1], data, (offset - _partition[0]->size), size_total, op); + } else if ((offset + size_total) > _partition[0]->size) { + // first r/w partition 0, then partition 1 + uint32_t size_0 = _partition[0]->size - offset; + uint32_t size_1 = size_total - size_0; + if (op == OP_READ) { + esp_partition_read(_partition[0], offset, data, size_0); + esp_partition_read(_partition[1], 0, (data + size_0), size_1); + } else { + esp_partition_erase_range(_partition[0], offset, size_0); + esp_partition_write(_partition[0], offset, _cache, size_0); + esp_partition_erase_range(_partition[1], 0, size_1); + esp_partition_write(_partition[1], 0, (_cache + size_0), size_1); + } + } else { + // only r/w partition 0 + single_partition_rw(_partition[0], data, offset, size_total, op); + } +} +#endif + +mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { + const uint32_t offset = block * FILESYSTEM_BLOCK_SIZE; + const uint32_t read_total = num_blocks * FILESYSTEM_BLOCK_SIZE; + #if CIRCUITPY_STORAGE_EXTEND + multi_partition_rw(dest, offset, read_total, OP_READ); + #else + single_partition_rw(_partition[0], dest, offset, read_total, OP_READ); + #endif + return 0; // success } mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32_t num_blocks) { @@ -112,12 +150,10 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 uint32_t block_address = lba + block; uint32_t sector_offset = block_address / blocks_per_sector * SECTOR_SIZE; uint8_t block_offset = block_address % blocks_per_sector; - if (_cache_lba != block_address) { supervisor_flash_read_blocks(_cache, sector_offset / FILESYSTEM_BLOCK_SIZE, blocks_per_sector); _cache_lba = sector_offset; } - for (uint8_t b = block_offset; b < blocks_per_sector; b++) { // Stop copying after the last block. if (block >= num_blocks) { @@ -128,31 +164,34 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 FILESYSTEM_BLOCK_SIZE); block++; } - #if CIRCUITPY_STORAGE_EXTEND - if (sector_offset > _partition[0]->size) { - // only write to partition 1 - esp_partition_erase_range(_partition[1], sector_offset - _partition[0]->size, SECTOR_SIZE); - esp_partition_write(_partition[1], sector_offset - _partition[0]->size, _cache, SECTOR_SIZE); - } else if ((sector_offset + SECTOR_SIZE) > _partition[0]->size) { - // first write to partition 0, then partition 1 - uint32_t write_0 = _partition[0]->size - sector_offset; - uint32_t write_1 = SECTOR_SIZE - write_0; - esp_partition_erase_range(_partition[0], sector_offset, write_0); - esp_partition_write(_partition[0], sector_offset, _cache, write_0); - esp_partition_erase_range(_partition[1], 0, write_1); - esp_partition_write(_partition[1], 0, _cache + write_0, write_1); - } else + multi_partition_rw(_cache, sector_offset, SECTOR_SIZE, OP_WRITE); + #else + single_partition_rw(_partition[0], _cache, sector_offset, SECTOR_SIZE, OP_READ); #endif - { - // only write to partition 0 - esp_partition_erase_range(_partition[0], sector_offset, SECTOR_SIZE); - esp_partition_write(_partition[0], sector_offset, _cache, SECTOR_SIZE); - } } - return 0; // success } void supervisor_flash_release_cache(void) { } + +void supervisor_flash_set_extended(bool extended) { + #if CIRCUITPY_STORAGE_EXTEND + storage_extended = extended; + #endif +} + +bool supervisor_flash_get_extended(void) { + #if CIRCUITPY_STORAGE_EXTEND + return storage_extended; + #else + return false; + #endif +} + +void supervisor_flash_update_extended(void) { + #if CIRCUITPY_STORAGE_EXTEND + storage_extended = (_partition[0]->size < fatfs_bytes()); + #endif +} diff --git a/supervisor/flash.h b/supervisor/flash.h index 21d76c9984..5154cb8598 100644 --- a/supervisor/flash.h +++ b/supervisor/flash.h @@ -50,4 +50,8 @@ void supervisor_flash_init_vfs(struct _fs_user_mount_t *vfs); void supervisor_flash_flush(void); void supervisor_flash_release_cache(void); +void supervisor_flash_set_extended(bool extended); +bool supervisor_flash_get_extended(void); +void supervisor_flash_update_extended(void); + #endif // MICROPY_INCLUDED_SUPERVISOR_FLASH_H diff --git a/supervisor/shared/filesystem.c b/supervisor/shared/filesystem.c index 283849adc3..01aba0a9ac 100644 --- a/supervisor/shared/filesystem.c +++ b/supervisor/shared/filesystem.c @@ -143,16 +143,22 @@ bool filesystem_init(bool create_allowed, bool force_create) { } else if (res != FR_OK) { return false; } + vfs->str = "/"; vfs->len = 1; vfs->obj = MP_OBJ_FROM_PTR(vfs_fat); vfs->next = NULL; + MP_STATE_VM(vfs_mount_table) = vfs; // The current directory is used as the boot up directory. // It is set to the internal flash filesystem by default. MP_STATE_PORT(vfs_cur) = vfs; + #if CIRCUITPY_STORAGE_EXTEND + supervisor_flash_update_extended(); + #endif + return true; } From 3a5eb31b4ecb958671e53c0517c99b61f51942be Mon Sep 17 00:00:00 2001 From: Boran Roni Date: Mon, 10 Oct 2022 14:00:12 +0000 Subject: [PATCH 11/39] Translated using Weblate (Turkish) Currently translated at 14.5% (145 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/tr/ --- locale/tr.po | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/locale/tr.po b/locale/tr.po index 0aa5284d36..60a4d83677 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2022-08-29 18:20+0000\n" +"PO-Revision-Date: 2022-10-10 18:23+0000\n" "Last-Translator: Boran Roni \n" "Language-Team: none\n" "Language: tr\n" @@ -15,7 +15,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.14.1-dev\n" +"X-Generator: Weblate 4.14.1\n" #: main.c msgid "" @@ -167,7 +167,7 @@ msgstr "%q >= %d olmalıdır" #: shared-bindings/analogbufio/BufferedIn.c #: shared-bindings/audiocore/RawSample.c msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'" -msgstr "" +msgstr "%q 'h', 'H', 'b' yada 'B' tipi bir bytearray /array olmalı" #: py/argcheck.c msgid "%q must be a string" @@ -375,7 +375,7 @@ msgstr "fonksiyon dışında 'yield'" #: py/compile.c msgid "*x must be assignment target" -msgstr "" +msgstr "*x atama hedefi olmalıdır" #: py/obj.c msgid ", in %q\n" @@ -486,7 +486,7 @@ msgstr "Halihazırda duyuruluyor." #: ports/atmel-samd/common-hal/canio/Listener.c msgid "Already have all-matches listener" -msgstr "" +msgstr "Tüm eşleşmelerle eşleşen dinleyiciniz var" #: shared-module/memorymonitor/AllocationAlarm.c #: shared-module/memorymonitor/AllocationSize.c @@ -605,15 +605,15 @@ msgstr "Parlaklık ayarlanabilir değil" #: shared-bindings/_bleio/UUID.c #, c-format msgid "Buffer + offset too small %d %d %d" -msgstr "" +msgstr "Buffer + offset çok küçük %d %d %d" #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "Buffer elements must be 4 bytes long or less" -msgstr "" +msgstr "Buffer elementleri 4 bit olmak zorunda" #: shared-bindings/framebufferio/FramebufferDisplay.c msgid "Buffer is not a bytearray." -msgstr "Arabellek bayt dizisi değil" +msgstr "Buffer bir bytearray değil." #: ports/cxd56/common-hal/camera/Camera.c shared-bindings/displayio/Display.c #: shared-bindings/framebufferio/FramebufferDisplay.c @@ -632,12 +632,12 @@ msgstr "Arabellek boyutu 512'nin katı olmalı" #: ports/stm/common-hal/sdioio/SDCard.c shared-bindings/floppyio/__init__.c msgid "Buffer must be a multiple of 512 bytes" -msgstr "" +msgstr "Buffer 512 bitin katı olmalı" #: shared-bindings/_bleio/PacketBuffer.c #, c-format msgid "Buffer too short by %d bytes" -msgstr "" +msgstr "Buffer bitten %d daha az" #: ports/espressif/common-hal/imagecapture/ParallelImageCapture.c msgid "Buffers must be same size" @@ -653,7 +653,7 @@ msgstr "Veriyolu pini %d kullanımda" #: shared-bindings/_bleio/UUID.c msgid "Byte buffer must be 16 bytes." -msgstr "" +msgstr "Bit buffer'ı 16bit olmalı." #: shared-bindings/aesio/aes.c msgid "CBC blocks must be multiples of 16 bytes" @@ -661,11 +661,11 @@ msgstr "CBC blokları 16 baytın katları şeklinde olmalı" #: supervisor/shared/safe_mode.c msgid "CIRCUITPY drive could not be found or created." -msgstr "CIRCUITPY sürücüsü bulunamadı veya oluşturulamadı" +msgstr "CIRCUITPY sürücüsü bulunamadı veya oluşturulamadı." #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "CRC or checksum was invalid" -msgstr "" +msgstr "CRC yada checksum geçersiz" #: py/objtype.c msgid "Call super().__init__() before accessing native object." @@ -712,15 +712,16 @@ msgstr "Değerler silinemez" #: ports/nrf/common-hal/digitalio/DigitalInOut.c #: ports/raspberrypi/common-hal/digitalio/DigitalInOut.c msgid "Cannot get pull while in output mode" -msgstr "" +msgstr "Çıkış modundayken çekme alınamıyor" #: ports/nrf/common-hal/microcontroller/Processor.c msgid "Cannot get temperature" -msgstr "" +msgstr "Isı okunamadı" #: shared-bindings/_bleio/Adapter.c +#, fuzzy msgid "Cannot have scan responses for extended, connectable advertisements." -msgstr "" +msgstr "Genişletilmiş, bağlanabilir reklamlar için tarama yanıtları yapılamaz." #: ports/espressif/common-hal/alarm/pin/PinAlarm.c msgid "Cannot pull on input-only pin." @@ -779,7 +780,7 @@ msgstr "" #: supervisor/shared/safe_mode.c msgid "CircuitPython core code crashed hard. Whoops!\n" -msgstr "" +msgstr "CircuitPython kor kodu patladı. Haydaaa!\n" #: supervisor/shared/safe_mode.c msgid "CircuitPython was unable to allocate the heap." @@ -791,17 +792,17 @@ msgstr "" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c msgid "Clock unit in use" -msgstr "" +msgstr "Saat ünitesi kullanımda" #: shared-bindings/_bleio/Connection.c msgid "" "Connection has been disconnected and can no longer be used. Create a new " "connection." -msgstr "" +msgstr "Bağlantı koparıldı ve tekrar kullanılamaz. Yeni bir bağlantı kurun." #: py/persistentcode.c msgid "Corrupt .mpy file" -msgstr "" +msgstr "Bozuk .mpy dosyası" #: ports/espressif/common-hal/neopixel_write/__init__.c msgid "Could not retrieve clock" @@ -813,7 +814,7 @@ msgstr "" #: shared-bindings/pwmio/PWMOut.c msgid "Could not start PWM" -msgstr "" +msgstr "PWM başlatılamadı" #: ports/stm/common-hal/busio/UART.c msgid "Could not start interrupt, RX busy" From ab1de66dd37cffcac5220251283738431d8a7ecd Mon Sep 17 00:00:00 2001 From: Florin Maticu Date: Tue, 4 Oct 2022 23:55:05 +0200 Subject: [PATCH 12/39] Remove redundant header files. --- ports/stm/common-hal/alarm/pin/PinAlarm.c | 2 -- ports/stm/common-hal/alarm/time/TimeAlarm.c | 1 - ports/stm/common-hal/analogio/AnalogOut.c | 3 +++ ports/stm/common-hal/busio/I2C.c | 1 - ports/stm/common-hal/busio/SPI.c | 3 --- ports/stm/common-hal/digitalio/DigitalInOut.c | 2 -- ports/stm/common-hal/microcontroller/Pin.c | 2 -- ports/stm/common-hal/pulseio/PulseIn.c | 1 - ports/stm/common-hal/pulseio/PulseOut.c | 4 ---- ports/stm/common-hal/pwmio/PWMOut.c | 1 - ports/stm/common-hal/rtc/RTC.c | 4 ---- ports/stm/mphalport.c | 3 --- ports/stm/peripherals/exti.c | 7 ++----- ports/stm/peripherals/rtc.c | 3 --- ports/stm/peripherals/timers.c | 1 - ports/stm/supervisor/internal_flash.c | 5 ----- ports/stm/supervisor/port.c | 1 - ports/stm/supervisor/usb.c | 2 -- 18 files changed, 5 insertions(+), 41 deletions(-) diff --git a/ports/stm/common-hal/alarm/pin/PinAlarm.c b/ports/stm/common-hal/alarm/pin/PinAlarm.c index 799922ae8f..0e5fa9e94d 100644 --- a/ports/stm/common-hal/alarm/pin/PinAlarm.c +++ b/ports/stm/common-hal/alarm/pin/PinAlarm.c @@ -27,8 +27,6 @@ #include "py/runtime.h" #include "shared-bindings/alarm/pin/PinAlarm.h" -#include "shared-bindings/microcontroller/__init__.h" -#include "shared-bindings/microcontroller/Pin.h" #include "peripherals/exti.h" diff --git a/ports/stm/common-hal/alarm/time/TimeAlarm.c b/ports/stm/common-hal/alarm/time/TimeAlarm.c index 2eb8ee4a81..6d508cd8cc 100644 --- a/ports/stm/common-hal/alarm/time/TimeAlarm.c +++ b/ports/stm/common-hal/alarm/time/TimeAlarm.c @@ -28,7 +28,6 @@ #include "shared-bindings/alarm/time/TimeAlarm.h" #include "shared-bindings/time/__init__.h" -#include "supervisor/port.h" #include "peripherals/rtc.h" #include STM32_HAL_H diff --git a/ports/stm/common-hal/analogio/AnalogOut.c b/ports/stm/common-hal/analogio/AnalogOut.c index 3c2860c9ad..4dd8783545 100644 --- a/ports/stm/common-hal/analogio/AnalogOut.c +++ b/ports/stm/common-hal/analogio/AnalogOut.c @@ -28,9 +28,12 @@ #include #include + #include "py/mperrno.h" #include "py/runtime.h" + + #include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/microcontroller/Pin.h" #include "supervisor/shared/translate/translate.h" diff --git a/ports/stm/common-hal/busio/I2C.c b/ports/stm/common-hal/busio/I2C.c index 4faa5ca2ef..259d678f2b 100644 --- a/ports/stm/common-hal/busio/I2C.c +++ b/ports/stm/common-hal/busio/I2C.c @@ -30,7 +30,6 @@ #include "py/mperrno.h" #include "py/runtime.h" -#include "shared-bindings/microcontroller/__init__.h" #include "supervisor/shared/translate/translate.h" #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index 7886e18a0c..89ec4b7cdc 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -28,11 +28,8 @@ #include #include "shared-bindings/busio/SPI.h" -#include "py/mperrno.h" #include "py/runtime.h" -#include "shared-bindings/microcontroller/__init__.h" -#include "supervisor/board.h" #include "supervisor/shared/translate/translate.h" #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/stm/common-hal/digitalio/DigitalInOut.c b/ports/stm/common-hal/digitalio/DigitalInOut.c index 58f81b43b6..51b05907f7 100644 --- a/ports/stm/common-hal/digitalio/DigitalInOut.c +++ b/ports/stm/common-hal/digitalio/DigitalInOut.c @@ -27,8 +27,6 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/microcontroller/Pin.h" -#include "py/runtime.h" -#include "supervisor/shared/translate/translate.h" // The HAL is sparse on obtaining register information, so we use the LLs here. #if (CPY_STM32H7) diff --git a/ports/stm/common-hal/microcontroller/Pin.c b/ports/stm/common-hal/microcontroller/Pin.c index 9d6c8ec71a..7c4f4511e7 100644 --- a/ports/stm/common-hal/microcontroller/Pin.c +++ b/ports/stm/common-hal/microcontroller/Pin.c @@ -26,9 +26,7 @@ */ #include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/digitalio/DigitalInOut.h" -#include "py/mphal.h" #include "pins.h" #if defined(TFBGA216) diff --git a/ports/stm/common-hal/pulseio/PulseIn.c b/ports/stm/common-hal/pulseio/PulseIn.c index 1c323ad711..4ed2600d55 100644 --- a/ports/stm/common-hal/pulseio/PulseIn.c +++ b/ports/stm/common-hal/pulseio/PulseIn.c @@ -28,7 +28,6 @@ #include #include #include "py/mpconfig.h" -#include "py/gc.h" #include "py/runtime.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/stm/common-hal/pulseio/PulseOut.c b/ports/stm/common-hal/pulseio/PulseOut.c index 7725d8cdde..f558c8f776 100644 --- a/ports/stm/common-hal/pulseio/PulseOut.c +++ b/ports/stm/common-hal/pulseio/PulseOut.c @@ -29,14 +29,10 @@ #include #include "py/mpconfig.h" -#include "py/gc.h" -#include "py/runtime.h" #include "shared-bindings/pulseio/PulseOut.h" #include "shared-bindings/pwmio/PWMOut.h" -#include "supervisor/shared/translate/translate.h" #include STM32_HAL_H -#include "shared-bindings/microcontroller/Pin.h" #include "timers.h" // A single timer is shared amongst all PulseOut objects under the assumption that diff --git a/ports/stm/common-hal/pwmio/PWMOut.c b/ports/stm/common-hal/pwmio/PWMOut.c index 45f00b901b..16d510b605 100644 --- a/ports/stm/common-hal/pwmio/PWMOut.c +++ b/ports/stm/common-hal/pwmio/PWMOut.c @@ -31,7 +31,6 @@ #include "shared-bindings/pwmio/PWMOut.h" #include "supervisor/shared/translate/translate.h" -#include "shared-bindings/microcontroller/__init__.h" #include STM32_HAL_H #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/stm/common-hal/rtc/RTC.c b/ports/stm/common-hal/rtc/RTC.c index 48c47fda8c..c9dc50d769 100644 --- a/ports/stm/common-hal/rtc/RTC.c +++ b/ports/stm/common-hal/rtc/RTC.c @@ -26,13 +26,9 @@ #include -#include "py/obj.h" #include "py/runtime.h" #include "shared/timeutils/timeutils.h" -#include "shared-bindings/rtc/__init__.h" -#include "common-hal/rtc/RTC.h" #include "shared-bindings/rtc/RTC.h" -#include "supervisor/port.h" #include "supervisor/shared/translate/translate.h" #include "peripherals/rtc.h" diff --git a/ports/stm/mphalport.c b/ports/stm/mphalport.c index bb62b07987..647798f6d5 100644 --- a/ports/stm/mphalport.c +++ b/ports/stm/mphalport.c @@ -28,11 +28,8 @@ #include #include "py/mphal.h" -#include "py/mpstate.h" -#include "py/gc.h" #include "shared-bindings/microcontroller/__init__.h" -#include "supervisor/shared/tick.h" void mp_hal_delay_us(mp_uint_t delay) { common_hal_mcu_delay_us(delay); diff --git a/ports/stm/peripherals/exti.c b/ports/stm/peripherals/exti.c index a161898491..a97de55531 100644 --- a/ports/stm/peripherals/exti.c +++ b/ports/stm/peripherals/exti.c @@ -26,9 +26,6 @@ #include #include "py/mpconfig.h" -#include "py/gc.h" -#include "py/obj.h" -#include "py/runtime.h" #include "peripherals/exti.h" @@ -128,7 +125,7 @@ void EXTI4_IRQHandler(void) { #endif void EXTI9_5_IRQHandler(void) { uint32_t pending = EXTI->PR; - for (uint i = 5; i <= 9; i++) { + for (uint8_t i = 5; i <= 9; i++) { if (pending & (1 << i)) { stm_exti_callback[i](i); } @@ -137,7 +134,7 @@ void EXTI9_5_IRQHandler(void) { void EXTI15_10_IRQHandler(void) { uint32_t pending = EXTI->PR; - for (uint i = 10; i <= 15; i++) { + for (uint8_t i = 10; i <= 15; i++) { if (pending & (1 << i)) { stm_exti_callback[i](i); } diff --git a/ports/stm/peripherals/rtc.c b/ports/stm/peripherals/rtc.c index bd65ccbf17..15f82ba78d 100644 --- a/ports/stm/peripherals/rtc.c +++ b/ports/stm/peripherals/rtc.c @@ -29,9 +29,6 @@ #include STM32_HAL_H #include "py/mpconfig.h" -#include "py/gc.h" -#include "py/obj.h" -#include "py/runtime.h" #include "shared/timeutils/timeutils.h" // Default period for ticks is 1/1024 second diff --git a/ports/stm/peripherals/timers.c b/ports/stm/peripherals/timers.c index 371b8f414b..ed0f2ec38a 100644 --- a/ports/stm/peripherals/timers.c +++ b/ports/stm/peripherals/timers.c @@ -26,7 +26,6 @@ #include "timers.h" #include "py/mpconfig.h" -#include "py/gc.h" #include "py/obj.h" #include "py/runtime.h" #include "supervisor/shared/translate/translate.h" diff --git a/ports/stm/supervisor/internal_flash.c b/ports/stm/supervisor/internal_flash.c index cd693d0c66..e0f4153cb1 100644 --- a/ports/stm/supervisor/internal_flash.c +++ b/ports/stm/supervisor/internal_flash.c @@ -29,12 +29,7 @@ #include #include -#include "extmod/vfs.h" -#include "extmod/vfs_fat.h" -#include "py/mphal.h" #include "py/obj.h" -#include "py/runtime.h" -#include "lib/oofatfs/ff.h" #include "supervisor/flash.h" #include "supervisor/shared/safe_mode.h" diff --git a/ports/stm/supervisor/port.c b/ports/stm/supervisor/port.c index 896d58b013..97bd1c4982 100644 --- a/ports/stm/supervisor/port.c +++ b/ports/stm/supervisor/port.c @@ -29,7 +29,6 @@ #include "supervisor/background_callback.h" #include "supervisor/board.h" #include "supervisor/port.h" -#include "shared/timeutils/timeutils.h" #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" diff --git a/ports/stm/supervisor/usb.c b/ports/stm/supervisor/usb.c index 168bacc569..cafa401bd4 100644 --- a/ports/stm/supervisor/usb.c +++ b/ports/stm/supervisor/usb.c @@ -27,9 +27,7 @@ #include "supervisor/usb.h" -#include "shared/runtime/interrupt_char.h" #include "shared/readline/readline.h" -#include "lib/tinyusb/src/device/usbd.h" #include "py/mpconfig.h" From 81d227de730dbcd3ea70df2b4be273e7e6aed1d7 Mon Sep 17 00:00:00 2001 From: flom84 Date: Mon, 10 Oct 2022 20:55:44 +0200 Subject: [PATCH 13/39] Use types from circuitpython. --- ports/stm/peripherals/exti.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ports/stm/peripherals/exti.c b/ports/stm/peripherals/exti.c index a97de55531..861e5de0a6 100644 --- a/ports/stm/peripherals/exti.c +++ b/ports/stm/peripherals/exti.c @@ -26,6 +26,7 @@ #include #include "py/mpconfig.h" +#include "py/misc.h" #include "peripherals/exti.h" @@ -125,7 +126,7 @@ void EXTI4_IRQHandler(void) { #endif void EXTI9_5_IRQHandler(void) { uint32_t pending = EXTI->PR; - for (uint8_t i = 5; i <= 9; i++) { + for (uint i = 5; i <= 9; i++) { if (pending & (1 << i)) { stm_exti_callback[i](i); } @@ -134,7 +135,7 @@ void EXTI9_5_IRQHandler(void) { void EXTI15_10_IRQHandler(void) { uint32_t pending = EXTI->PR; - for (uint8_t i = 10; i <= 15; i++) { + for (uint i = 10; i <= 15; i++) { if (pending & (1 << i)) { stm_exti_callback[i](i); } From 2ad5c11ca94ad600fee175fba798b8d2320d31ee Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Mon, 10 Oct 2022 21:13:35 +0200 Subject: [PATCH 14/39] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ --- locale/ID.po | 9 +++++++++ locale/cs.po | 9 +++++++++ locale/de_DE.po | 9 +++++++++ locale/el.po | 9 +++++++++ locale/en_GB.po | 9 +++++++++ locale/es.po | 9 +++++++++ locale/fil.po | 9 +++++++++ locale/fr.po | 9 +++++++++ locale/hi.po | 9 +++++++++ locale/it_IT.po | 9 +++++++++ locale/ja.po | 9 +++++++++ locale/ko.po | 9 +++++++++ locale/nl.po | 9 +++++++++ locale/pl.po | 9 +++++++++ locale/pt_BR.po | 9 +++++++++ locale/ru.po | 9 +++++++++ locale/sv.po | 9 +++++++++ locale/tr.po | 9 +++++++++ locale/zh_Latn_pinyin.po | 9 +++++++++ 19 files changed, 171 insertions(+) diff --git a/locale/ID.po b/locale/ID.po index 361bd234be..2dae1a04b4 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -65,6 +65,11 @@ msgstr "output:\n" msgid "%%c requires int or char" msgstr "%%c harus int atau char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2106,6 +2111,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/cs.po b/locale/cs.po index d98d718842..9bb05d77d0 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -67,6 +67,11 @@ msgstr " výstup:\n" msgid "%%c requires int or char" msgstr "%%c vyžaduje int nebo char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2095,6 +2100,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 6a85963efb..bec093fd7e 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -66,6 +66,11 @@ msgstr " Ausgabe:\n" msgid "%%c requires int or char" msgstr "%%c erwartet Int oder Char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2132,6 +2137,10 @@ msgstr "UART wird wieder Initialisiert" msgid "UART write" msgstr "UART wird geschrieben" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "USB beschäftigt" diff --git a/locale/el.po b/locale/el.po index eeb0c15b0f..d2ce8ed68d 100644 --- a/locale/el.po +++ b/locale/el.po @@ -71,6 +71,11 @@ msgstr " έξοδος:\n" msgid "%%c requires int or char" msgstr "%%c απαιτεί int ή char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2104,6 +2109,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index ef1e24c050..da587c2653 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -69,6 +69,11 @@ msgstr " output:\n" msgid "%%c requires int or char" msgstr "%%c requires int or char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2108,6 +2113,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "USB busy" diff --git a/locale/es.po b/locale/es.po index c16da030a3..2397b2947e 100644 --- a/locale/es.po +++ b/locale/es.po @@ -69,6 +69,11 @@ msgstr " salida:\n" msgid "%%c requires int or char" msgstr "%%c requiere int o char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2140,6 +2145,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "USB ocupado" diff --git a/locale/fil.po b/locale/fil.po index f32f8400c3..49f5eaef2c 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -61,6 +61,11 @@ msgstr " output:\n" msgid "%%c requires int or char" msgstr "%%c nangangailangan ng int o char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2094,6 +2099,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/fr.po b/locale/fr.po index be22f22d78..40bc8ec33b 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -70,6 +70,11 @@ msgstr " sortie :\n" msgid "%%c requires int or char" msgstr "%%c nécessite un chiffre entier 'int' ou un caractère 'char'" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2161,6 +2166,10 @@ msgstr "Ré-initialisation du UART" msgid "UART write" msgstr "Écriture UART" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "L'USB est occupé" diff --git a/locale/hi.po b/locale/hi.po index 53fb104e4c..82915d1a7a 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -60,6 +60,11 @@ msgstr "" msgid "%%c requires int or char" msgstr "" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2077,6 +2082,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index 95e0720d45..acb4273138 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -66,6 +66,11 @@ msgstr " output:\n" msgid "%%c requires int or char" msgstr "%%c necessita di int o char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2104,6 +2109,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/ja.po b/locale/ja.po index 824b9bdf1e..2db88128a2 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -65,6 +65,11 @@ msgstr " 出力:\n" msgid "%%c requires int or char" msgstr "%%c にはintまたはcharが必要" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2090,6 +2095,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/ko.po b/locale/ko.po index 1114d49092..2a99cf8cd4 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -61,6 +61,11 @@ msgstr " 산출:\n" msgid "%%c requires int or char" msgstr "%%c 전수(int)또는 캐릭터(char)필요합니다" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2080,6 +2085,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/nl.po b/locale/nl.po index fc68fd1c87..4baa1d28bc 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -63,6 +63,11 @@ msgstr " uitvoer:\n" msgid "%%c requires int or char" msgstr "%%c vereist een int of char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2101,6 +2106,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/pl.po b/locale/pl.po index f36f087339..23c42ffe92 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -65,6 +65,11 @@ msgstr " wyjście:\n" msgid "%%c requires int or char" msgstr "%%c wymaga int lub char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2088,6 +2093,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 810adda5e4..0db7637c32 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -67,6 +67,11 @@ msgstr " saída:\n" msgid "%%c requires int or char" msgstr "%%c requer int ou char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2146,6 +2151,10 @@ msgstr "Reinicialização do UART" msgid "UART write" msgstr "Escrita UART" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "USB ocupado" diff --git a/locale/ru.po b/locale/ru.po index 3b00aef2ad..93fcc2ba0b 100644 --- a/locale/ru.po +++ b/locale/ru.po @@ -68,6 +68,11 @@ msgstr " вывод:\n" msgid "%%c requires int or char" msgstr "%%c требует int или char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2126,6 +2131,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/sv.po b/locale/sv.po index 8be7b40d6c..a2feec3e7a 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -67,6 +67,11 @@ msgstr " utdata:\n" msgid "%%c requires int or char" msgstr "%%c kräver int eller char" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2122,6 +2127,10 @@ msgstr "UART omstart" msgid "UART write" msgstr "UART-skrivning" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "USB upptaget" diff --git a/locale/tr.po b/locale/tr.po index 60a4d83677..6380448b11 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -70,6 +70,11 @@ msgstr " çıktı:\n" msgid "%%c requires int or char" msgstr "%%c int veya char tipine ihtiyaç duyar" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2097,6 +2102,10 @@ msgstr "" msgid "UART write" msgstr "" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index c14aa43e49..c99d3a9625 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -69,6 +69,11 @@ msgstr " shūchū:\n" msgid "%%c requires int or char" msgstr "%%c xūyào zhěngshù huòzhě zìfú" +#: main.c +#, c-format +msgid "%02X" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" @@ -2125,6 +2130,10 @@ msgstr "UART chóngxīn qǐdòng" msgid "UART write" msgstr "UART xiě rù" +#: main.c +msgid "UID:" +msgstr "" + #: shared-module/usb_hid/Device.c msgid "USB busy" msgstr "USB fán máng" From c98174eea5e6869f0a337db972c8202ef25702f5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 10 Oct 2022 14:51:16 -0500 Subject: [PATCH 15/39] Add support for SSL client certificate (load_cert_chain) Tested with badssl.com: 1. Get client certificates from https://badssl.com/download/ 2. Convert public portion with `openssl x509 -in badssl.com-client.pem -out CIRCUITPY/cert.pem` 3. Convert private portion with `openssl rsa -in badssl.com-client.pem -out CIRCUITPY/privkey.pem` and the password `badssl.com` 4. Put wifi settings in CIRCUITPY/.env 5. Run the below Python script: ```py import os import wifi import socketpool import ssl import adafruit_requests TEXT_URL = "https://client.badssl.com/" wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD')) pool = socketpool.SocketPool(wifi.radio) context = ssl.create_default_context() requests = adafruit_requests.Session(pool, context) print(f"Fetching from {TEXT_URL} without certificate (should fail)") response = requests.get(TEXT_URL) print(f"{response.status_code=}, should be 400 Bad Request") input("hit enter to continue\r") print("Loading client certificate") context.load_cert_chain("/cert.pem", "privkey.pem") requests = adafruit_requests.Session(pool, context) print(f"Fetching from {TEXT_URL} with certificate (should succeed)") response = requests.get(TEXT_URL) print(f"{response.status_code=}, should be 200 OK") ``` --- ports/espressif/common-hal/ssl/SSLContext.c | 7 +++ ports/raspberrypi/common-hal/ssl/SSLContext.c | 15 ++++--- ports/raspberrypi/common-hal/ssl/SSLContext.h | 1 + ports/raspberrypi/common-hal/ssl/SSLSocket.c | 15 +++++++ ports/raspberrypi/mbedtls/mbedtls_config.h | 2 + shared-bindings/ssl/SSLContext.c | 43 +++++++++++++++++++ shared-bindings/ssl/SSLContext.h | 1 + 7 files changed, 78 insertions(+), 6 deletions(-) diff --git a/ports/espressif/common-hal/ssl/SSLContext.c b/ports/espressif/common-hal/ssl/SSLContext.c index 866024bf00..386986e6be 100644 --- a/ports/espressif/common-hal/ssl/SSLContext.c +++ b/ports/espressif/common-hal/ssl/SSLContext.c @@ -87,3 +87,10 @@ bool common_hal_ssl_sslcontext_get_check_hostname(ssl_sslcontext_obj_t *self) { void common_hal_ssl_sslcontext_set_check_hostname(ssl_sslcontext_obj_t *self, bool value) { self->ssl_config.skip_common_name = !value; } + +void common_hal_ssl_sslcontext_load_cert_chain(ssl_sslcontext_obj_t *self, mp_buffer_info_t *cert_buf, mp_buffer_info_t *key_buf) { + self->ssl_config.clientcert_buf = cert_buf->buf; + self->ssl_config.clientcert_bytes = cert_buf->len + 1; + self->ssl_config.clientkey_buf = key_buf->buf; + self->ssl_config.clientkey_bytes = key_buf->len + 1; +} diff --git a/ports/raspberrypi/common-hal/ssl/SSLContext.c b/ports/raspberrypi/common-hal/ssl/SSLContext.c index 22d26b2da3..da3bed5005 100644 --- a/ports/raspberrypi/common-hal/ssl/SSLContext.c +++ b/ports/raspberrypi/common-hal/ssl/SSLContext.c @@ -39,12 +39,10 @@ void common_hal_ssl_sslcontext_construct(ssl_sslcontext_obj_t *self) { void common_hal_ssl_sslcontext_load_verify_locations(ssl_sslcontext_obj_t *self, const char *cadata) { - mp_raise_NotImplementedError(NULL); - - // self->crt_bundle_attach = NULL; - // self->use_global_ca_store = false; - // self->cacert_buf = (const unsigned char *)cadata; - // self->cacert_bytes = strlen(cadata) + 1; + self->crt_bundle_attach = NULL; + self->use_global_ca_store = false; + self->cacert_buf = (const unsigned char *)cadata; + self->cacert_bytes = strlen(cadata) + 1; } void common_hal_ssl_sslcontext_set_default_verify_paths(ssl_sslcontext_obj_t *self) { @@ -61,3 +59,8 @@ bool common_hal_ssl_sslcontext_get_check_hostname(ssl_sslcontext_obj_t *self) { void common_hal_ssl_sslcontext_set_check_hostname(ssl_sslcontext_obj_t *self, bool value) { self->check_name = value; } + +void common_hal_ssl_sslcontext_load_cert_chain(ssl_sslcontext_obj_t *self, mp_buffer_info_t *cert_buf, mp_buffer_info_t *key_buf) { + self->cert_buf = *cert_buf; + self->key_buf = *key_buf; +} diff --git a/ports/raspberrypi/common-hal/ssl/SSLContext.h b/ports/raspberrypi/common-hal/ssl/SSLContext.h index 33c683951b..40840deeec 100644 --- a/ports/raspberrypi/common-hal/ssl/SSLContext.h +++ b/ports/raspberrypi/common-hal/ssl/SSLContext.h @@ -36,4 +36,5 @@ typedef struct { const unsigned char *cacert_buf; size_t cacert_bytes; int (*crt_bundle_attach)(mbedtls_ssl_config *conf); + mp_buffer_info_t cert_buf, key_buf; } ssl_sslcontext_obj_t; diff --git a/ports/raspberrypi/common-hal/ssl/SSLSocket.c b/ports/raspberrypi/common-hal/ssl/SSLSocket.c index 69ebcffb7e..72a5ba4fae 100644 --- a/ports/raspberrypi/common-hal/ssl/SSLSocket.c +++ b/ports/raspberrypi/common-hal/ssl/SSLSocket.c @@ -197,6 +197,21 @@ ssl_sslsocket_obj_t *common_hal_ssl_sslcontext_wrap_socket(ssl_sslcontext_obj_t mbedtls_ssl_set_bio(&o->ssl, &o->sock, _mbedtls_ssl_send, _mbedtls_ssl_recv, NULL); + if (self->cert_buf.buf != NULL) { + ret = mbedtls_pk_parse_key(&o->pkey, self->key_buf.buf, self->key_buf.len + 1, NULL, 0); + if (ret != 0) { + goto cleanup; + } + ret = mbedtls_x509_crt_parse(&o->cert, self->cert_buf.buf, self->cert_buf.len + 1); + if (ret != 0) { + goto cleanup; + } + + ret = mbedtls_ssl_conf_own_cert(&o->conf, &o->cert, &o->pkey); + if (ret != 0) { + goto cleanup; + } + } return o; cleanup: mbedtls_pk_free(&o->pkey); diff --git a/ports/raspberrypi/mbedtls/mbedtls_config.h b/ports/raspberrypi/mbedtls/mbedtls_config.h index 8c953c7072..3791924a13 100644 --- a/ports/raspberrypi/mbedtls/mbedtls_config.h +++ b/ports/raspberrypi/mbedtls/mbedtls_config.h @@ -77,6 +77,7 @@ #define MBEDTLS_AES_C #define MBEDTLS_ASN1_PARSE_C #define MBEDTLS_ASN1_WRITE_C +#define MBEDTLS_BASE64_C #define MBEDTLS_BIGNUM_C #define MBEDTLS_CIPHER_C #define MBEDTLS_CTR_DRBG_C @@ -90,6 +91,7 @@ #define MBEDTLS_MD5_C #define MBEDTLS_OID_C #define MBEDTLS_PKCS5_C +#define MBEDTLS_PEM_PARSE_C #define MBEDTLS_PK_C #define MBEDTLS_PK_PARSE_C #define MBEDTLS_PLATFORM_C diff --git a/shared-bindings/ssl/SSLContext.c b/shared-bindings/ssl/SSLContext.c index f0eb0e8c58..ac5f7ad42d 100644 --- a/shared-bindings/ssl/SSLContext.c +++ b/shared-bindings/ssl/SSLContext.c @@ -27,6 +27,7 @@ #include #include +#include "extmod/vfs.h" #include "py/objtuple.h" #include "py/objlist.h" #include "py/objproperty.h" @@ -52,6 +53,47 @@ STATIC mp_obj_t ssl_sslcontext_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(s); } +//| def load_cert_chain(self, certfile: str, keyfile: str) -> None: +//| """Load a private key and the corresponding certificate. +//| +//| The certfile string must be the path to a single file in PEM format +//| containing the certificate as well as any number of CA certificates +//| needed to establish the certificate's authenticity. The keyfile string +//| must point to a file containing the private key. +//| """ + +STATIC void get_file_contents(mp_obj_t name_obj, mp_buffer_info_t *bufinfo) { + mp_obj_t file = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), name_obj, MP_OBJ_NEW_QSTR(MP_QSTR_rb)); + mp_obj_t dest[2]; + mp_load_method(file, MP_QSTR_read, dest); + mp_obj_t result = mp_call_method_n_kw(0, 0, dest); + mp_get_buffer_raise(result, bufinfo, MP_BUFFER_READ); +} + +STATIC mp_obj_t ssl_sslcontext_load_cert_chain(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_certfile, ARG_keyfile }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_certfile, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_keyfile, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + }; + ssl_sslcontext_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_buffer_info_t cert_buf, key_buf; + get_file_contents(args[ARG_certfile].u_obj, &cert_buf); + if (args[ARG_keyfile].u_obj != mp_const_none) { + get_file_contents(args[ARG_keyfile].u_obj, &key_buf); + } else { + key_buf = cert_buf; + } + + common_hal_ssl_sslcontext_load_cert_chain(self, &cert_buf, &key_buf); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ssl_sslcontext_load_cert_chain_obj, 1, ssl_sslcontext_load_cert_chain); + //| def load_verify_locations(self, cadata: Optional[str] = None) -> None: //| """Load a set of certification authority (CA) certificates used to validate //| other peers' certificates.""" @@ -146,6 +188,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ssl_sslcontext_wrap_socket_obj, 1, ssl_sslcont STATIC const mp_rom_map_elem_t ssl_sslcontext_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&ssl_sslcontext_wrap_socket_obj) }, + { MP_ROM_QSTR(MP_QSTR_load_cert_chain), MP_ROM_PTR(&ssl_sslcontext_load_cert_chain_obj) }, { MP_ROM_QSTR(MP_QSTR_load_verify_locations), MP_ROM_PTR(&ssl_sslcontext_load_verify_locations_obj) }, { MP_ROM_QSTR(MP_QSTR_set_default_verify_paths), MP_ROM_PTR(&ssl_sslcontext_set_default_verify_paths_obj) }, { MP_ROM_QSTR(MP_QSTR_check_hostname), MP_ROM_PTR(&ssl_sslcontext_check_hostname_obj) }, diff --git a/shared-bindings/ssl/SSLContext.h b/shared-bindings/ssl/SSLContext.h index ef04f25d43..9f40badd85 100644 --- a/shared-bindings/ssl/SSLContext.h +++ b/shared-bindings/ssl/SSLContext.h @@ -46,5 +46,6 @@ void common_hal_ssl_sslcontext_set_default_verify_paths(ssl_sslcontext_obj_t *se bool common_hal_ssl_sslcontext_get_check_hostname(ssl_sslcontext_obj_t *self); void common_hal_ssl_sslcontext_set_check_hostname(ssl_sslcontext_obj_t *self, bool value); +void common_hal_ssl_sslcontext_load_cert_chain(ssl_sslcontext_obj_t *self, mp_buffer_info_t *cert_buf, mp_buffer_info_t *key_buf); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_SSL_SSLCONTEXT_H From 0c8b261ec9d8d657176d782228e58dc7e1ade76a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 10 Oct 2022 15:53:56 -0500 Subject: [PATCH 16/39] picow: Add support of self-signed certificates. ## Testing self-signed certificates and `load_verify_locations` Obtain the badssl "self-signed" certificate in the correct form: ```sh openssl s_client -servername self-signed.badssl.com -connect untrusted-root.badssl.com:443 < /dev/null | openssl x509 > self-signed.pem ``` Copy it and the script to CIRCUITPY: ```python import os import wifi import socketpool import ssl import adafruit_requests TEXT_URL = "https://self-signed.badssl.com/" if not wifi.radio.ipv4_address: wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD')) pool = socketpool.SocketPool(wifi.radio) context = ssl.create_default_context() requests = adafruit_requests.Session(pool, context) print(f"Fetching from {TEXT_URL} without certificate (should fail)") try: response = requests.get(TEXT_URL) except Exception as e: print(f"Failed: {e}") else: print(f"{response.status_code=}, should have failed with exception") print("Loading server certificate") with open("/self-signed.pem", "rb") as certfile: context.load_verify_locations(cadata=certfile.read()) requests = adafruit_requests.Session(pool, context) print(f"Fetching from {TEXT_URL} with certificate (should succeed)") try: response = requests.get(TEXT_URL) except Exception as e: print(f"Unexpected exception: {e}") else: print(f"{response.status_code=}, should be 200 OK") ``` --- ports/raspberrypi/common-hal/ssl/SSLSocket.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/ssl/SSLSocket.c b/ports/raspberrypi/common-hal/ssl/SSLSocket.c index 72a5ba4fae..dd1f50d29a 100644 --- a/ports/raspberrypi/common-hal/ssl/SSLSocket.c +++ b/ports/raspberrypi/common-hal/ssl/SSLSocket.c @@ -174,7 +174,14 @@ ssl_sslsocket_obj_t *common_hal_ssl_sslcontext_wrap_socket(ssl_sslcontext_obj_t if (self->crt_bundle_attach != NULL) { mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_REQUIRED); self->crt_bundle_attach(&o->conf); - // } else if(self->cacert_buf && self->cacert_bytes) { // TODO: user bundle + } else if (self->cacert_buf && self->cacert_bytes) { + ret = mbedtls_x509_crt_parse(&o->cacert, self->cacert_buf, self->cacert_bytes); + if (ret != 0) { + goto cleanup; + } + mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_REQUIRED); + mbedtls_ssl_conf_ca_chain(&o->conf, &o->cacert, NULL); + } else { mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_NONE); } From e5139e2040dcbab4bcdd75321cbb721b16f8aba4 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 11 Oct 2022 10:45:22 +0530 Subject: [PATCH 17/39] update to newer actions --- .github/workflows/build.yml | 56 ++++++++++++------------- .github/workflows/create_website_pr.yml | 4 +- .github/workflows/ports_windows.yml | 2 +- .github/workflows/pre-commit.yml | 10 ++--- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 84224a1c1a..8338528c42 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,12 +30,12 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 - name: Set up Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - name: Get CP deps @@ -92,25 +92,25 @@ jobs: working-directory: tests - name: Build mpy-cross.static-aarch64 run: make -C mpy-cross -j2 -f Makefile.static-aarch64 - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: mpy-cross.static-aarch64 path: mpy-cross/mpy-cross.static-aarch64 - name: Build mpy-cross.static-raspbian run: make -C mpy-cross -j2 -f Makefile.static-raspbian - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: mpy-cross.static-raspbian path: mpy-cross/mpy-cross.static-raspbian - name: Build mpy-cross.static run: make -C mpy-cross -j2 -f Makefile.static - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: mpy-cross.static-amd64-linux path: mpy-cross/mpy-cross.static - name: Build mpy-cross.static-mingw run: make -C mpy-cross -j2 -f Makefile.static-mingw - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: mpy-cross.static-x64-windows path: mpy-cross/mpy-cross.static.exe @@ -149,12 +149,12 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 - name: Set up Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - name: Get CP deps @@ -174,19 +174,19 @@ jobs: msgfmt --version - name: Build mpy-cross run: make -C mpy-cross -j2 - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: mpy-cross-macos-11-x64 path: mpy-cross/mpy-cross - name: Build mpy-cross (arm64) run: make -C mpy-cross -j2 -f Makefile.m1 V=2 - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: mpy-cross-macos-11-arm64 path: mpy-cross/mpy-cross-arm64 - name: Make universal binary run: lipo -create -output mpy-cross-macos-universal mpy-cross/mpy-cross mpy-cross/mpy-cross-arm64 - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: mpy-cross-macos-11-universal path: mpy-cross-macos-universal @@ -207,7 +207,7 @@ jobs: needs: test if: ${{ needs.test.outputs.build-doc == 'True' }} steps: - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 @@ -218,7 +218,7 @@ jobs: tools/describe || git log --parents HEAD~4.. echo >>$GITHUB_ENV CP_VERSION=$(tools/describe) - name: Set up Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - name: Install dependencies @@ -229,20 +229,20 @@ jobs: pip install -r requirements-ci.txt -r requirements-doc.txt - name: Build and Validate Stubs run: make check-stubs -j2 - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: stubs path: circuitpython-stubs/dist/* - name: Test Documentation Build (HTML) run: sphinx-build -E -W -b html -D version=${{ env.CP_VERSION }} -D release=${{ env.CP_VERSION }} . _build/html - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: docs path: _build/html - name: Test Documentation Build (LaTeX/PDF) run: | make latexpdf - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: docs path: _build/latex @@ -276,10 +276,10 @@ jobs: if: ${{ needs.test.outputs.boards-arm != '[]' }} steps: - name: Set up Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 @@ -306,7 +306,7 @@ jobs: working-directory: tools env: BOARDS: ${{ matrix.board }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: ${{ matrix.board }} path: bin/${{ matrix.board }} @@ -329,10 +329,10 @@ jobs: if: ${{ needs.test.outputs.boards-riscv != '[]' }} steps: - name: Set up Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 @@ -358,7 +358,7 @@ jobs: working-directory: tools env: BOARDS: ${{ matrix.board }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: ${{ matrix.board }} path: bin/${{ matrix.board }} @@ -385,7 +385,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3.x" - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 @@ -395,7 +395,7 @@ jobs: run: | tools/describe || git log --parents HEAD~4.. echo >>$GITHUB_ENV CP_VERSION=$(tools/describe) - - uses: actions/cache@v2 + - uses: actions/cache@v3 name: Fetch IDF tool cache id: idf-cache with: @@ -449,7 +449,7 @@ jobs: IDF_PATH: ${{ github.workspace }}/ports/espressif/esp-idf IDF_TOOLS_PATH: ${{ github.workspace }}/.idf_tools BOARDS: ${{ matrix.board }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: ${{ matrix.board }} path: bin/${{ matrix.board }} @@ -471,10 +471,10 @@ jobs: if: ${{ needs.test.outputs.boards-aarch != '[]' }} steps: - name: Set up Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 @@ -514,7 +514,7 @@ jobs: working-directory: tools env: BOARDS: ${{ matrix.board }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: ${{ matrix.board }} path: bin/${{ matrix.board }} diff --git a/.github/workflows/create_website_pr.yml b/.github/workflows/create_website_pr.yml index 2367b6c475..75de556c68 100644 --- a/.github/workflows/create_website_pr.yml +++ b/.github/workflows/create_website_pr.yml @@ -16,12 +16,12 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 - name: Set up Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - name: Get CP deps diff --git a/.github/workflows/ports_windows.yml b/.github/workflows/ports_windows.yml index bc5f837745..6d38f3b853 100644 --- a/.github/workflows/ports_windows.yml +++ b/.github/workflows/ports_windows.yml @@ -71,7 +71,7 @@ jobs: which python; python --version; python -c "import cascadetoml" which python3; python3 --version; python3 -c "import cascadetoml" - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 with: submodules: false fetch-depth: 1 diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 28f8ccb6f1..a23dcd1d11 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -16,9 +16,9 @@ jobs: pre-commit: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2.2.0 + - uses: actions/checkout@v3 - name: Set up Python 3 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - name: Install deps @@ -29,17 +29,17 @@ jobs: run: git submodule update --init extmod/ulab - name: Set PY run: echo >>$GITHUB_ENV PY="$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: ~/.cache/pre-commit key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} - - uses: pre-commit/action@v1.1.0 + - uses: pre-commit/action@v3.0.0 - name: Make patch if: failure() run: git diff > ~/pre-commit.patch - name: Upload patch if: failure() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: patch path: ~/pre-commit.patch From e19abef57ea2f440a96f64239a004a0544d20a39 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 11 Oct 2022 13:09:24 -0400 Subject: [PATCH 18/39] forgot to add these! --- ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c | 13 +------------ .../boards/vcc_gnd_yd_rp2040/mpconfigboard.h | 2 ++ .../boards/vcc_gnd_yd_rp2040/mpconfigboard.mk | 8 ++------ 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c index e992ec063c..76973aee30 100644 --- a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c +++ b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/board.c @@ -26,15 +26,4 @@ #include "supervisor/board.h" -void board_init(void) { -} - -bool board_requests_safe_mode(void) { - return false; -} - -void reset_board(void) { -} - -void board_deinit(void) { -} +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.h b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.h index 01d74410e9..83875289d5 100644 --- a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.h +++ b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.h @@ -1,2 +1,4 @@ #define MICROPY_HW_BOARD_NAME "VCC-GND Studio YD RP2040" #define MICROPY_HW_MCU_NAME "rp2040" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO23) diff --git a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.mk b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.mk index 5a478a49a1..a42b251903 100644 --- a/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.mk +++ b/ports/raspberrypi/boards/vcc_gnd_yd_rp2040/mpconfigboard.mk @@ -1,15 +1,11 @@ USB_VID = 0x2E8A -USB_PID = 0x000B +USB_PID = 0x102E USB_PRODUCT = "YD-RP2040" USB_MANUFACTURER = "VCC-GND Studio" CHIP_VARIANT = RP2040 CHIP_FAMILY = rp2 -EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ,W25Q32JVxQ,W25Q128JVxQ" CIRCUITPY__EVE = 1 - -# Include these Python libraries in firmware -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SimpleIO From 376df8ec7ecbd1ded4982df43d698a0874d897a2 Mon Sep 17 00:00:00 2001 From: Wind-stormger Date: Mon, 10 Oct 2022 18:11:20 +0800 Subject: [PATCH 19/39] Add BananaPi BPI-PicoW-S3 . Adds support for the BananaPi BPI-PicoW-S3 Boards. Based on esp32s3 chip. With one WS2812 LED, one monochrome LED, one ceramic antenna. Support double-reset to tinyUF2. --- ports/espressif/boards/bpi_picow_s3/board.c | 39 +++++++++++++ .../boards/bpi_picow_s3/mpconfigboard.h | 37 ++++++++++++ .../boards/bpi_picow_s3/mpconfigboard.mk | 20 +++++++ ports/espressif/boards/bpi_picow_s3/pins.c | 58 +++++++++++++++++++ ports/espressif/boards/bpi_picow_s3/sdkconfig | 47 +++++++++++++++ 5 files changed, 201 insertions(+) create mode 100644 ports/espressif/boards/bpi_picow_s3/board.c create mode 100644 ports/espressif/boards/bpi_picow_s3/mpconfigboard.h create mode 100644 ports/espressif/boards/bpi_picow_s3/mpconfigboard.mk create mode 100644 ports/espressif/boards/bpi_picow_s3/pins.c create mode 100644 ports/espressif/boards/bpi_picow_s3/sdkconfig diff --git a/ports/espressif/boards/bpi_picow_s3/board.c b/ports/espressif/boards/bpi_picow_s3/board.c new file mode 100644 index 0000000000..b3c8cb4191 --- /dev/null +++ b/ports/espressif/boards/bpi_picow_s3/board.c @@ -0,0 +1,39 @@ +/* + * 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 "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif /* DEBUG */ +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/bpi_picow_s3/mpconfigboard.h b/ports/espressif/boards/bpi_picow_s3/mpconfigboard.h new file mode 100644 index 0000000000..f7e7fde31b --- /dev/null +++ b/ports/espressif/boards/bpi_picow_s3/mpconfigboard.h @@ -0,0 +1,37 @@ +/* + * 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 "BPI-PicoW-S3" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO48) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO44) +#define DEFAULT_UART_BUS_TX (&pin_GPIO43) + +#define DOUBLE_TAP_PIN (&pin_GPIO34) diff --git a/ports/espressif/boards/bpi_picow_s3/mpconfigboard.mk b/ports/espressif/boards/bpi_picow_s3/mpconfigboard.mk new file mode 100644 index 0000000000..6d77a94b08 --- /dev/null +++ b/ports/espressif/boards/bpi_picow_s3/mpconfigboard.mk @@ -0,0 +1,20 @@ +USB_VID = 0x303A +USB_PID = 0x812C +USB_PRODUCT = "BPI-PicoW-S3" +USB_MANUFACTURER = "BananaPi" + +IDF_TARGET = esp32s3 + +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 = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/espressif/boards/bpi_picow_s3/pins.c b/ports/espressif/boards/bpi_picow_s3/pins.c new file mode 100644 index 0000000000..5e88a96b49 --- /dev/null +++ b/ports/espressif/boards/bpi_picow_s3/pins.c @@ -0,0 +1,58 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO46) }, + + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO8) }, + + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO10) }, + + { MP_ROM_QSTR(MP_QSTR_GP29), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP29_A3), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO11) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO48) }, + + { 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_BOOT0), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) } +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/bpi_picow_s3/sdkconfig b/ports/espressif/boards/bpi_picow_s3/sdkconfig new file mode 100644 index 0000000000..04ab118924 --- /dev/null +++ b/ports/espressif/boards/bpi_picow_s3/sdkconfig @@ -0,0 +1,47 @@ +# +# Component config +# +# +# ESP32S3-Specific +# +CONFIG_ESP32S3_SPIRAM_SUPPORT=y +# +# SPI RAM config +# +CONFIG_SPIRAM_MODE_QUAD=y +# CONFIG_SPIRAM_MODE_OCT is not set +# 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 ESP32S3 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM Clock and CS IO for ESP32S3 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_SPEED_120M is not set +CONFIG_SPIRAM_SPEED_80M=y +# CONFIG_SPIRAM_SPEED_40M 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 +# end of SPI RAM config + +# end of ESP32S3-Specific + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="BPI-PicoW-S3" +# end of LWIP + +# end of Component config From 844cd17f0364736ab18b023a014d020427815d33 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 11 Oct 2022 20:29:52 -0400 Subject: [PATCH 20/39] delay first serial write by 50ms --- supervisor/shared/serial.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 0326f15437..5680d8afe0 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -28,6 +28,7 @@ #include #include "py/mpconfig.h" +#include "py/mphal.h" #include "supervisor/shared/cpu.h" #include "supervisor/shared/display.h" @@ -62,6 +63,13 @@ byte console_uart_rx_buf[64]; #endif #endif +#if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART +// Flag to note whether this is the first write after connection. +// Delay slightly on the first write to allow time for the host to set up things, +// including turning off echo mode. +static bool _first_write_done = false; +#endif + #if CIRCUITPY_USB_VENDOR bool tud_vendor_connected(void); #endif @@ -144,6 +152,10 @@ void serial_early_init(void) { } void serial_init(void) { + #if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART + _first_write_done = false; + #endif + port_serial_init(); } @@ -301,8 +313,11 @@ void serial_write_substring(const char *text, uint32_t length) { #endif #if CIRCUITPY_CONSOLE_UART + if (!_first_write_done) { + mp_hal_delay_ms(50); + _first_write_done = true; + } int uart_errcode; - common_hal_busio_uart_write(&console_uart, (const uint8_t *)text, length, &uart_errcode); #endif @@ -321,6 +336,11 @@ void serial_write_substring(const char *text, uint32_t length) { #endif #if CIRCUITPY_USB + // Delay the very first write + if (tud_cdc_connected() && !_first_write_done) { + mp_hal_delay_ms(50); + _first_write_done = true; + } uint32_t count = 0; if (tud_cdc_connected()) { while (count < length) { From 62cbd3bcd8a6dae019d30a4557bc8d74210a70e6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 11:33:39 -0500 Subject: [PATCH 21/39] Pico w: socket: correctly track sockets generated by accept() --- ports/raspberrypi/common-hal/socketpool/Socket.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ports/raspberrypi/common-hal/socketpool/Socket.c b/ports/raspberrypi/common-hal/socketpool/Socket.c index 99b19ad694..4dd400522b 100644 --- a/ports/raspberrypi/common-hal/socketpool/Socket.c +++ b/ports/raspberrypi/common-hal/socketpool/Socket.c @@ -821,6 +821,16 @@ socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_o MICROPY_PY_LWIP_EXIT + DEBUG_printf("registering socket in socketpool_socket_accept()\n"); + if (!register_open_socket(socket2)) { + DEBUG_printf("collecting garbage to open socket\n"); + gc_collect(); + if (!register_open_socket(socket2)) { + mp_raise_RuntimeError(translate("Out of sockets")); + } + } + mark_user_socket(socket2); + // output values memcpy(ip, &(socket2->pcb.tcp->remote_ip), NETUTILS_IPV4ADDR_BUFSIZE); *port = (mp_uint_t)socket2->pcb.tcp->remote_port; From ca9523b814b6467ddf7626fa9cfe24d3a60d6e37 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 11:34:25 -0500 Subject: [PATCH 22/39] Pico w: socket: Correctly return negative error code from recv_into --- ports/raspberrypi/common-hal/socketpool/Socket.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/raspberrypi/common-hal/socketpool/Socket.c b/ports/raspberrypi/common-hal/socketpool/Socket.c index 4dd400522b..952f4ea7d8 100644 --- a/ports/raspberrypi/common-hal/socketpool/Socket.c +++ b/ports/raspberrypi/common-hal/socketpool/Socket.c @@ -1080,6 +1080,9 @@ int socketpool_socket_recv_into(socketpool_socket_obj_t *socket, ret = lwip_raw_udp_receive(socket, (byte *)buf, len, NULL, NULL, &_errno); break; } + if (ret < 0) { + return -_errno; + } return ret; } From b1f7940297464f65c703de2e7cc2c06965fd121a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 11:35:10 -0500 Subject: [PATCH 23/39] Pico W: Correctly treat empty cadata= as disabling host checking --- ports/raspberrypi/common-hal/ssl/SSLContext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/ssl/SSLContext.c b/ports/raspberrypi/common-hal/ssl/SSLContext.c index da3bed5005..67287128b0 100644 --- a/ports/raspberrypi/common-hal/ssl/SSLContext.c +++ b/ports/raspberrypi/common-hal/ssl/SSLContext.c @@ -42,7 +42,7 @@ void common_hal_ssl_sslcontext_load_verify_locations(ssl_sslcontext_obj_t *self, self->crt_bundle_attach = NULL; self->use_global_ca_store = false; self->cacert_buf = (const unsigned char *)cadata; - self->cacert_bytes = strlen(cadata) + 1; + self->cacert_bytes = *cadata ? strlen(cadata) + 1 : 0; } void common_hal_ssl_sslcontext_set_default_verify_paths(ssl_sslcontext_obj_t *self) { From 7c849fdadb2dfedefa16a480ff3ee262240b18d9 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 11:35:34 -0500 Subject: [PATCH 24/39] Pico W: ssl: Raise MemoryError for allocation errors --- ports/raspberrypi/common-hal/ssl/SSLSocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/common-hal/ssl/SSLSocket.c b/ports/raspberrypi/common-hal/ssl/SSLSocket.c index dd1f50d29a..8712fbb378 100644 --- a/ports/raspberrypi/common-hal/ssl/SSLSocket.c +++ b/ports/raspberrypi/common-hal/ssl/SSLSocket.c @@ -230,7 +230,7 @@ cleanup: mbedtls_entropy_free(&o->entropy); if (ret == MBEDTLS_ERR_SSL_ALLOC_FAILED) { - mp_raise_OSError(MP_ENOMEM); + mp_raise_type(&mp_type_MemoryError); } else if (ret == MBEDTLS_ERR_PK_BAD_INPUT_DATA) { mp_raise_ValueError(MP_ERROR_TEXT("invalid key")); } else if (ret == MBEDTLS_ERR_X509_BAD_INPUT_DATA) { @@ -326,7 +326,7 @@ cleanup: mbedtls_entropy_free(&self->entropy); if (ret == MBEDTLS_ERR_SSL_ALLOC_FAILED) { - mp_raise_OSError(MP_ENOMEM); + mp_raise_type(&mp_type_MemoryError); } else if (ret == MBEDTLS_ERR_PK_BAD_INPUT_DATA) { mp_raise_ValueError(MP_ERROR_TEXT("invalid key")); } else if (ret == MBEDTLS_ERR_X509_BAD_INPUT_DATA) { From 1641a7c0026c49816cc0f671227c68e004dc0d9d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 11:36:34 -0500 Subject: [PATCH 25/39] Pico W: ssl: Correctly handle errors in send/recv The prefixed versions raise Python exceptions, the un-prefixed return negative error values. We don't want to raise an exception from here, it leaves the SSL stack in an undefined state. --- ports/raspberrypi/common-hal/ssl/SSLSocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/common-hal/ssl/SSLSocket.c b/ports/raspberrypi/common-hal/ssl/SSLSocket.c index 8712fbb378..ba91e084cd 100644 --- a/ports/raspberrypi/common-hal/ssl/SSLSocket.c +++ b/ports/raspberrypi/common-hal/ssl/SSLSocket.c @@ -100,7 +100,7 @@ STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) { mp_obj_t sock = *(mp_obj_t *)ctx; // mp_uint_t out_sz = sock_stream->write(sock, buf, len, &err); - mp_int_t out_sz = common_hal_socketpool_socket_send(sock, buf, len); + mp_int_t out_sz = socketpool_socket_send(sock, buf, len); DEBUG("socket_send() -> %d", out_sz); if (out_sz < 0) { int err = -out_sz; @@ -118,7 +118,7 @@ STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) { STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) { mp_obj_t sock = *(mp_obj_t *)ctx; - mp_int_t out_sz = common_hal_socketpool_socket_recv_into(sock, buf, len); + mp_int_t out_sz = socketpool_socket_recv_into(sock, buf, len); DEBUG("socket_recv() -> %d", out_sz); if (out_sz < 0) { int err = -out_sz; From 874ddd67bfd1f30c56cd1d448ba28b4d813066a2 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 11:37:07 -0500 Subject: [PATCH 26/39] Pico W: ssl: factor out do_handshake --- ports/raspberrypi/common-hal/ssl/SSLSocket.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/common-hal/ssl/SSLSocket.c b/ports/raspberrypi/common-hal/ssl/SSLSocket.c index ba91e084cd..1d42a4b710 100644 --- a/ports/raspberrypi/common-hal/ssl/SSLSocket.c +++ b/ports/raspberrypi/common-hal/ssl/SSLSocket.c @@ -299,8 +299,7 @@ void common_hal_ssl_sslsocket_close(ssl_sslsocket_obj_t *self) { mbedtls_entropy_free(&self->entropy); } -void common_hal_ssl_sslsocket_connect(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) { - common_hal_socketpool_socket_connect(self->sock, host, hostlen, port); +STATIC void do_handshake(ssl_sslsocket_obj_t *self) { int ret; while ((ret = mbedtls_ssl_handshake(&self->ssl)) != 0) { if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { @@ -336,6 +335,11 @@ cleanup: } } +void common_hal_ssl_sslsocket_connect(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) { + common_hal_socketpool_socket_connect(self->sock, host, hostlen, port); + do_handshake(self); +} + bool common_hal_ssl_sslsocket_get_closed(ssl_sslsocket_obj_t *self) { return self->closed; } From a31ad57225028c46d22e45473df99cf0c03ffd25 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 13:45:30 -0500 Subject: [PATCH 27/39] Use non-deprecated way to set build outputs see https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ --- tools/ci_set_matrix.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/ci_set_matrix.py b/tools/ci_set_matrix.py index 90cf04cea6..0ae6010ac9 100644 --- a/tools/ci_set_matrix.py +++ b/tools/ci_set_matrix.py @@ -48,6 +48,14 @@ except json.decoder.JSONDecodeError as exc: raise +def set_output(name, value): + if "GITHUB_OUTPUT" in os.environ: + with open(os.environ["GITHUB_OUTPUT"], "at") as f: + print(f"{name}={value}", file=f) + else: + print("Would set GitHub actions output {name} to '{value}'") + + def set_boards_to_build(build_all): # Get boards in json format boards_info_json = build_board_info.get_board_mapping() @@ -161,7 +169,7 @@ def set_boards_to_build(build_all): # Set the step outputs for each architecture for arch in arch_to_boards: - print("::set-output name=boards-" + arch + "::" + json.dumps(sorted(arch_to_boards[arch]))) + set_output(f"boards-{arch}", json.dumps(sorted(arch_to_boards[arch]))) def set_docs_to_build(build_all): @@ -177,7 +185,7 @@ def set_docs_to_build(build_all): # Set the step outputs print("Building docs:", doc_match) - print("::set-output name=build-doc::" + str(doc_match)) + set_output(f"build-doc", doc_match) def check_changed_files(): From b251e78ac577bd44da4a1680cc083d6bde55c781 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 14:29:57 -0500 Subject: [PATCH 28/39] samd: size-optimize microcontroller temp calc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Perform most arithmetic with scaled integer values. For my calibration values ``` const uint32_t NVMCTRL_TEMP_LOG[]={0xfc05511e, 0xcc7ac0f7}; ``` the maximum difference between the old and new calculation is 0.50°C. The difference is smallest (0.13°) at 25.87°C in the old scale. This reduces mcu_processor_get_temperature from 568 bytes to 348 bytes (-220 bytes) --- .../common-hal/microcontroller/Processor.c | 85 ++++++++----------- 1 file changed, 34 insertions(+), 51 deletions(-) diff --git a/ports/atmel-samd/common-hal/microcontroller/Processor.c b/ports/atmel-samd/common-hal/microcontroller/Processor.c index 29d6612ad8..119b5631ad 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Processor.c +++ b/ports/atmel-samd/common-hal/microcontroller/Processor.c @@ -73,46 +73,26 @@ #include "peripheral_clk_config.h" #define ADC_TEMP_SAMPLE_LENGTH 4 -#define INT1V_VALUE_FLOAT 1.0 -#define INT1V_DIVIDER_1000 1000.0 -#define ADC_12BIT_FULL_SCALE_VALUE_FLOAT 4095.0 +#define INT1V_VALUE_FLOAT MICROPY_FLOAT_CONST(1.0) +#define INT1V_DIVIDER_1000 MICROPY_FLOAT_CONST(1000.0) +#define ADC_12BIT_FULL_SCALE_VALUE_FLOAT MICROPY_FLOAT_CONST(4095.0) // channel argument (ignored in calls below) #define IGNORED_CHANNEL 0 -// Decimal to fraction conversion. (adapted from ASF sample). -STATIC float convert_dec_to_frac(uint8_t val) { - float float_val = (float)val; - if (val < 10) { - return float_val / 10.0; - } else if (val < 100) { - return float_val / 100.0; - } else { - return float_val / 1000.0; - } -} // Extract the production calibration data information from NVM (adapted from ASF sample), // then calculate the temperature #ifdef SAMD21 STATIC float calculate_temperature(uint16_t raw_value) { - volatile uint32_t val1; /* Temperature Log Row Content first 32 bits */ - volatile uint32_t val2; /* Temperature Log Row Content another 32 bits */ - uint8_t room_temp_val_int; /* Integer part of room temperature in °C */ - uint8_t room_temp_val_dec; /* Decimal part of room temperature in °C */ - uint8_t hot_temp_val_int; /* Integer part of hot temperature in °C */ - uint8_t hot_temp_val_dec; /* Decimal part of hot temperature in °C */ - int8_t room_int1v_val; /* internal 1V reference drift at room temperature */ - int8_t hot_int1v_val; /* internal 1V reference drift at hot temperature*/ - - float tempR; // Production Room temperature - float tempH; // Production Hot temperature - float INT1VR; // Room temp 2's complement of the internal 1V reference value - float INT1VH; // Hot temp 2's complement of the internal 1V reference value - uint16_t ADCR; // Production Room temperature ADC value - uint16_t ADCH; // Production Hot temperature ADC value - float VADCR; // Room temperature ADC voltage - float VADCH; // Hot temperature ADC voltage + uint32_t val1; /* Temperature Log Row Content first 32 bits */ + uint32_t val2; /* Temperature Log Row Content another 32 bits */ + int room_temp_val_int; /* Integer part of room temperature in °C */ + int room_temp_val_dec; /* Decimal part of room temperature in °C */ + int hot_temp_val_int; /* Integer part of hot temperature in °C */ + int hot_temp_val_dec; /* Decimal part of hot temperature in °C */ + int room_int1v_val; /* internal 1V reference drift at room temperature */ + int hot_int1v_val; /* internal 1V reference drift at hot temperature*/ uint32_t *temp_log_row_ptr = (uint32_t *)NVMCTRL_TEMP_LOG; @@ -120,32 +100,31 @@ STATIC float calculate_temperature(uint16_t raw_value) { temp_log_row_ptr++; val2 = *temp_log_row_ptr; - room_temp_val_int = (uint8_t)((val1 & FUSES_ROOM_TEMP_VAL_INT_Msk) >> FUSES_ROOM_TEMP_VAL_INT_Pos); - room_temp_val_dec = (uint8_t)((val1 & FUSES_ROOM_TEMP_VAL_DEC_Msk) >> FUSES_ROOM_TEMP_VAL_DEC_Pos); + room_temp_val_int = ((val1 & FUSES_ROOM_TEMP_VAL_INT_Msk) >> FUSES_ROOM_TEMP_VAL_INT_Pos); + room_temp_val_dec = ((val1 & FUSES_ROOM_TEMP_VAL_DEC_Msk) >> FUSES_ROOM_TEMP_VAL_DEC_Pos); - hot_temp_val_int = (uint8_t)((val1 & FUSES_HOT_TEMP_VAL_INT_Msk) >> FUSES_HOT_TEMP_VAL_INT_Pos); - hot_temp_val_dec = (uint8_t)((val1 & FUSES_HOT_TEMP_VAL_DEC_Msk) >> FUSES_HOT_TEMP_VAL_DEC_Pos); + hot_temp_val_int = ((val1 & FUSES_HOT_TEMP_VAL_INT_Msk) >> FUSES_HOT_TEMP_VAL_INT_Pos); + hot_temp_val_dec = ((val1 & FUSES_HOT_TEMP_VAL_DEC_Msk) >> FUSES_HOT_TEMP_VAL_DEC_Pos); + // necessary casts: must interpret 8 bits as signed room_int1v_val = (int8_t)((val1 & FUSES_ROOM_INT1V_VAL_Msk) >> FUSES_ROOM_INT1V_VAL_Pos); hot_int1v_val = (int8_t)((val2 & FUSES_HOT_INT1V_VAL_Msk) >> FUSES_HOT_INT1V_VAL_Pos); - ADCR = (uint16_t)((val2 & FUSES_ROOM_ADC_VAL_Msk) >> FUSES_ROOM_ADC_VAL_Pos); - ADCH = (uint16_t)((val2 & FUSES_HOT_ADC_VAL_Msk) >> FUSES_HOT_ADC_VAL_Pos); + int ADCR = ((val2 & FUSES_ROOM_ADC_VAL_Msk) >> FUSES_ROOM_ADC_VAL_Pos); + int ADCH = ((val2 & FUSES_HOT_ADC_VAL_Msk) >> FUSES_HOT_ADC_VAL_Pos); - tempR = room_temp_val_int + convert_dec_to_frac(room_temp_val_dec); - tempH = hot_temp_val_int + convert_dec_to_frac(hot_temp_val_dec); + int tempR = 10 * room_temp_val_int + room_temp_val_dec; + int tempH = 10 * hot_temp_val_int + hot_temp_val_dec; - INT1VR = 1 - ((float)room_int1v_val / INT1V_DIVIDER_1000); - INT1VH = 1 - ((float)hot_int1v_val / INT1V_DIVIDER_1000); + int INT1VR = 1000 - room_int1v_val; + int INT1VH = 1000 - hot_int1v_val; - VADCR = ((float)ADCR * INT1VR) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT; - VADCH = ((float)ADCH * INT1VH) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT; + int VADCR = ADCR * INT1VR; + int VADCH = ADCH * INT1VH; - float VADC; /* Voltage calculation using ADC result for Coarse Temp calculation */ - float VADCM; /* Voltage calculation using ADC result for Fine Temp calculation. */ - float INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */ + int INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */ - VADC = ((float)raw_value * INT1V_VALUE_FLOAT) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT; + int VADC = raw_value * 1000; // Hopefully compiler will remove common subepxressions here. @@ -153,21 +132,25 @@ STATIC float calculate_temperature(uint16_t raw_value) { // 1b as mentioned in data sheet section "Temperature Sensor Characteristics" // of Electrical Characteristics. (adapted from ASF sample code). // Coarse Temp Calculation by assume INT1V=1V for this ADC conversion - float coarse_temp = tempR + (((tempH - tempR) / (VADCH - VADCR)) * (VADC - VADCR)); + int coarse_temp = tempR + (tempH - tempR) * (VADC - VADCR) / (VADCH - VADCR); // Calculation to find the real INT1V value during the ADC conversion INT1VM = INT1VR + (((INT1VH - INT1VR) * (coarse_temp - tempR)) / (tempH - tempR)); - VADCM = ((float)raw_value * INT1VM) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT; + int VADCM = raw_value * INT1VM; // Fine Temp Calculation by replace INT1V=1V by INT1V = INT1Vm for ADC conversion - float fine_temp = tempR + (((tempH - tempR) / (VADCH - VADCR)) * (VADCM - VADCR)); + float fine_temp = tempR + (((tempH - tempR) * (VADCM - VADCR)) / (VADCH - VADCR)); - return fine_temp; + return fine_temp / 10; } #endif // SAMD21 #ifdef SAM_D5X_E5X +// Decimal to fraction conversion. (adapted from ASF sample). +STATIC float convert_dec_to_frac(uint8_t val) { + return val / MICROPY_FLOAT_CONST(10.); +} STATIC float calculate_temperature(uint16_t TP, uint16_t TC) { uint32_t TLI = (*(uint32_t *)FUSES_ROOM_TEMP_VAL_INT_ADDR & FUSES_ROOM_TEMP_VAL_INT_Msk) >> FUSES_ROOM_TEMP_VAL_INT_Pos; uint32_t TLD = (*(uint32_t *)FUSES_ROOM_TEMP_VAL_DEC_ADDR & FUSES_ROOM_TEMP_VAL_DEC_Msk) >> FUSES_ROOM_TEMP_VAL_DEC_Pos; From 6ee45dde579d81028c6d323fc9fab0771384d0a4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 12 Oct 2022 16:52:22 -0400 Subject: [PATCH 29/39] f_rename return value; add a test for rename dir inside itself --- extmod/vfs_fat.c | 2 -- lib/oofatfs/ff.c | 2 +- tests/extmod/vfs_fat_fileio2.py | 5 +++++ tests/extmod/vfs_fat_fileio2.py.exp | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 64a3ce05f6..880eef7740 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -234,8 +234,6 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_ } if (res == FR_OK) { return mp_const_none; - } else if (res == FR_NO_PATH) { - mp_raise_OSError(MP_EINVAL); } else { mp_raise_OSError_fresult(res); } diff --git a/lib/oofatfs/ff.c b/lib/oofatfs/ff.c index d6fc7ebcc2..e6afd57800 100644 --- a/lib/oofatfs/ff.c +++ b/lib/oofatfs/ff.c @@ -4828,7 +4828,7 @@ FRESULT f_rename ( strlen(path_new) > strlen(path_old) && path_new[strlen(path_old)] == '/' && strncmp(path_old, path_new, strlen(path_old)) == 0) { - return FR_NO_PATH; + return FR_INVALID_NAME; } res = find_volume(fs, FA_WRITE); /* Get logical drive of the old object */ diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index 297d75a481..7c75a6d044 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -70,6 +70,11 @@ try: except OSError as e: print(e.errno == uerrno.ENOENT) +try: + vfs.rename("foo_dir", "foo_dir/inside_itself") +except OSError as e: + print(e.errno == uerrno.EINVAL) + # file in dir with open("foo_dir/file-in-dir.txt", "w+t") as f: f.write("data in file") diff --git a/tests/extmod/vfs_fat_fileio2.py.exp b/tests/extmod/vfs_fat_fileio2.py.exp index 2684053641..ed6e315328 100644 --- a/tests/extmod/vfs_fat_fileio2.py.exp +++ b/tests/extmod/vfs_fat_fileio2.py.exp @@ -1,6 +1,7 @@ True True True +True b'data in file' True [('sub_file.txt', 32768, 0, 11), ('file.txt', 32768, 0, 12)] From a943167d69ad1abfeffc3796ddda148a3f96bcb7 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 15:53:44 -0500 Subject: [PATCH 30/39] samd: Reduce a further 48 bytes for non-full builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Another reduction of -48 bytes can be had if the fine calculation step is skipped. The worst difference compared to the old reference code with my calibration values in the 0° to 60° was 2°C, and the difference at 25°C is 1°C. The final size decrease for non-full builds like Trinket M0 is 268 bytes. --- ports/atmel-samd/common-hal/microcontroller/Processor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/common-hal/microcontroller/Processor.c b/ports/atmel-samd/common-hal/microcontroller/Processor.c index 119b5631ad..e0642c158f 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Processor.c +++ b/ports/atmel-samd/common-hal/microcontroller/Processor.c @@ -122,8 +122,6 @@ STATIC float calculate_temperature(uint16_t raw_value) { int VADCR = ADCR * INT1VR; int VADCH = ADCH * INT1VH; - int INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */ - int VADC = raw_value * 1000; // Hopefully compiler will remove common subepxressions here. @@ -134,7 +132,10 @@ STATIC float calculate_temperature(uint16_t raw_value) { // Coarse Temp Calculation by assume INT1V=1V for this ADC conversion int coarse_temp = tempR + (tempH - tempR) * (VADC - VADCR) / (VADCH - VADCR); + #if CIRCUITPY_FULL_BUILD // Calculation to find the real INT1V value during the ADC conversion + int INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */ + INT1VM = INT1VR + (((INT1VH - INT1VR) * (coarse_temp - tempR)) / (tempH - tempR)); int VADCM = raw_value * INT1VM; @@ -143,6 +144,9 @@ STATIC float calculate_temperature(uint16_t raw_value) { float fine_temp = tempR + (((tempH - tempR) * (VADCM - VADCR)) / (VADCH - VADCR)); return fine_temp / 10; + #else + return coarse_temp / 10.; + #endif } #endif // SAMD21 From f7d39ceae449ebe0a56cdcc8eefdd7fee53c69bd Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Oct 2022 16:25:09 -0500 Subject: [PATCH 31/39] comment on the revised algorithm --- .../atmel-samd/common-hal/microcontroller/Processor.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ports/atmel-samd/common-hal/microcontroller/Processor.c b/ports/atmel-samd/common-hal/microcontroller/Processor.c index e0642c158f..d720399b98 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Processor.c +++ b/ports/atmel-samd/common-hal/microcontroller/Processor.c @@ -83,6 +83,17 @@ // Extract the production calibration data information from NVM (adapted from ASF sample), // then calculate the temperature +// +// This code performs almost all operations with scaled integers. For +// instance, tempR is in units of 1/10°C, INT1VR is in units of 1mV, etc, +// This is important to reduce the code size of the function. The effect on +// precision is a ~.9°C difference vs the floating point algorithm on an +// approximate 0..60°C range with a difference of ~.5°C at 25°C. When the fine +// calculation step is skipped, the additional error approximately doubles. +// +// To save code size, rounding is neglected. However, trying to add back rounding +// (by computing (a + b/2) / b instead of just a / b) actually didn't help +// accuracy anyway. #ifdef SAMD21 STATIC float calculate_temperature(uint16_t raw_value) { uint32_t val1; /* Temperature Log Row Content first 32 bits */ From 728fea4ca4f31cbe1d7d18e767bec3b62c8fd147 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 6 Oct 2022 09:20:54 +0530 Subject: [PATCH 32/39] add storage extension python api --- locale/circuitpython.pot | 30 ++++++------------ .../espressif/common-hal/dualbank/__init__.c | 2 ++ shared-bindings/dualbank/__init__.c | 19 ++++++++++++ shared-bindings/storage/__init__.c | 31 ++++++++++++++++--- shared-bindings/storage/__init__.h | 2 +- shared-module/storage/__init__.c | 5 ++- 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index ff943c9767..0a1d61185f 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -112,6 +112,10 @@ msgstr "" msgid "%q init failed" msgstr "" +#: shared-bindings/dualbank/__init__.c +msgid "%q is %q" +msgstr "" + #: py/argcheck.c msgid "%q length must be %d" msgstr "" @@ -152,14 +156,6 @@ msgstr "" msgid "%q must be >= %d" msgstr "" -#: py/argcheck.c -msgid "%q must be >= 0" -msgstr "" - -#: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c -msgid "%q must be >= 1" -msgstr "" - #: shared-bindings/analogbufio/BufferedIn.c #: shared-bindings/audiocore/RawSample.c msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'" @@ -214,7 +210,7 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "" -#: py/objint.c +#: py/objint.c shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "" @@ -910,8 +906,7 @@ msgstr "" msgid "Error: Failure to bind" msgstr "" -#: ports/raspberrypi/bindings/rp2pio/StateMachine.c py/enum.c -#: shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c +#: py/enum.c shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c #: shared-bindings/alarm/__init__.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c #: shared-bindings/neopixel_write/__init__.c @@ -1569,10 +1564,12 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #: ports/espressif/common-hal/wifi/__init__.c +#: ports/raspberrypi/common-hal/wifi/__init__.c msgid "Only IPv4 addresses supported" msgstr "" #: ports/espressif/common-hal/socketpool/Socket.c +#: ports/raspberrypi/common-hal/socketpool/Socket.c msgid "Only IPv4 sockets supported" msgstr "" @@ -1642,6 +1639,7 @@ msgid "Out of memory" msgstr "" #: ports/espressif/common-hal/socketpool/Socket.c +#: ports/raspberrypi/common-hal/socketpool/Socket.c msgid "Out of sockets" msgstr "" @@ -1696,7 +1694,6 @@ msgid "Pin interrupt already in use" msgstr "" #: shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c -#: shared-bindings/digitalio/DigitalInOut.c msgid "Pin is input only" msgstr "" @@ -1916,6 +1913,7 @@ msgid "Slices not supported" msgstr "" #: ports/espressif/common-hal/socketpool/SocketPool.c +#: ports/raspberrypi/common-hal/socketpool/SocketPool.c msgid "SocketPool can only be used with wifi.radio" msgstr "" @@ -2341,10 +2339,6 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: shared-bindings/i2ctarget/I2CTarget.c -msgid "address out of bounds" -msgstr "" - #: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2814,10 +2808,6 @@ msgstr "" msgid "destination buffer must be an array of type 'H' for bit_depth = 16" msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "destination_length must be an int >= 0" -msgstr "" - #: py/objdict.c msgid "dict update sequence has wrong length" msgstr "" diff --git a/ports/espressif/common-hal/dualbank/__init__.c b/ports/espressif/common-hal/dualbank/__init__.c index 91c7981dd9..29b15a3e30 100644 --- a/ports/espressif/common-hal/dualbank/__init__.c +++ b/ports/espressif/common-hal/dualbank/__init__.c @@ -32,6 +32,8 @@ #include "esp_log.h" #include "esp_ota_ops.h" +#include "supervisor/flash.h" + static const esp_partition_t *update_partition = NULL; static esp_ota_handle_t update_handle = 0; diff --git a/shared-bindings/dualbank/__init__.c b/shared-bindings/dualbank/__init__.c index 83933e889d..d3f75a4153 100644 --- a/shared-bindings/dualbank/__init__.c +++ b/shared-bindings/dualbank/__init__.c @@ -26,6 +26,10 @@ #include "shared-bindings/dualbank/__init__.h" +#if CIRCUITPY_STORAGE_EXTEND +#include "supervisor/flash.h" +#endif + //| """DUALBANK Module //| //| The `dualbank` module adds ability to update and switch @@ -55,6 +59,14 @@ //| """ //| ... +#if CIRCUITPY_STORAGE_EXTEND +STATIC void raise_error_if_storage_extended(void) { + if (supervisor_flash_get_extended()) { + mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q is %q"), MP_QSTR_storage, MP_QSTR_extended); + } +} +#endif + //| def flash(buffer: ReadableBuffer, offset: int = 0) -> None: //| """Writes one of two app partitions at the given offset. //| @@ -70,6 +82,10 @@ STATIC mp_obj_t dualbank_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; + #if CIRCUITPY_STORAGE_EXTEND + raise_error_if_storage_extended(); + #endif + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -94,6 +110,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dualbank_flash_obj, 0, dualbank_flash); //| ... //| STATIC mp_obj_t dualbank_switch(void) { + #if CIRCUITPY_STORAGE_EXTEND + raise_error_if_storage_extended(); + #endif common_hal_dualbank_switch(); return mp_const_none; } diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 3661b61973..838395efb3 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -34,6 +34,7 @@ #include "py/runtime.h" #include "shared-bindings/storage/__init__.h" #include "supervisor/shared/translate/translate.h" +#include "supervisor/flash.h" //| """Storage management //| @@ -150,7 +151,7 @@ STATIC mp_obj_t storage_getmount(const mp_obj_t mnt_in) { } MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount); -//| def erase_filesystem() -> None: +//| def erase_filesystem(extended: Optional[bool] = None) -> None: //| """Erase and re-create the ``CIRCUITPY`` filesystem. //| //| On boards that present USB-visible ``CIRCUITPY`` drive (e.g., SAMD21 and SAMD51), @@ -160,16 +161,38 @@ MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount); //| This function can be called from the REPL when ``CIRCUITPY`` //| has become corrupted. //| +//| :param bool extended: On boards that support ``dualbank`` module +//| and the ``extended`` parameter, the ``CIRCUITPY`` storage can be +//| extended by setting this to `True`. If this isn't provided or +//| set to `None` (default), the existing configuration will be used. +//| //| .. warning:: All the data on ``CIRCUITPY`` will be lost, and //| CircuitPython will restart on certain boards.""" //| ... //| -STATIC mp_obj_t storage_erase_filesystem(void) { - common_hal_storage_erase_filesystem(); +STATIC mp_obj_t storage_erase_filesystem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_extended }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_extended, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + #if CIRCUITPY_STORAGE_EXTEND + bool extended = (args[ARG_extended].u_obj == mp_const_none) ? supervisor_flash_get_extended() : mp_obj_is_true(args[ARG_extended].u_obj); + common_hal_storage_erase_filesystem(extended); + #else + if (mp_obj_is_true(args[ARG_extended].u_obj)) { + mp_raise_NotImplementedError_varg(translate("%q=%q"), MP_QSTR_extended, MP_QSTR_True); + } + common_hal_storage_erase_filesystem(false); + #endif + return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem); +MP_DEFINE_CONST_FUN_OBJ_KW(storage_erase_filesystem_obj, 0, storage_erase_filesystem); //| def disable_usb_drive() -> None: //| """Disable presenting ``CIRCUITPY`` as a USB mass storage device. diff --git a/shared-bindings/storage/__init__.h b/shared-bindings/storage/__init__.h index fbf492efab..ffe68c17c8 100644 --- a/shared-bindings/storage/__init__.h +++ b/shared-bindings/storage/__init__.h @@ -37,7 +37,7 @@ void common_hal_storage_umount_path(const char *path); void common_hal_storage_umount_object(mp_obj_t vfs_obj); void common_hal_storage_remount(const char *path, bool readonly, bool disable_concurrent_write_protection); mp_obj_t common_hal_storage_getmount(const char *path); -void common_hal_storage_erase_filesystem(void); +void common_hal_storage_erase_filesystem(bool extended); bool common_hal_storage_disable_usb_drive(void); bool common_hal_storage_enable_usb_drive(void); diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 8806b7c8c6..7b6eec7e1b 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -267,11 +267,14 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa filesystem_set_internal_concurrent_write_protection(!disable_concurrent_write_protection); } -void common_hal_storage_erase_filesystem(void) { +void common_hal_storage_erase_filesystem(bool extended) { #if CIRCUITPY_USB usb_disconnect(); #endif mp_hal_delay_ms(1000); + #if CIRCUITPY_STORAGE_EXTEND + supervisor_flash_set_extended(extended); + #endif (void)filesystem_init(false, true); // Force a re-format. Ignore failure. common_hal_mcu_reset(); // We won't actually get here, since we're resetting. From c6bbb0e4f6c356a17da0e43a17dd0eb491f27c14 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 13 Oct 2022 08:44:31 -0500 Subject: [PATCH 33/39] test format_exception too --- tests/circuitpython/traceback_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/circuitpython/traceback_test.py b/tests/circuitpython/traceback_test.py index 6ae73db6ae..6f51ceede8 100644 --- a/tests/circuitpython/traceback_test.py +++ b/tests/circuitpython/traceback_test.py @@ -21,7 +21,7 @@ except Exception as exc: print("\nLimit=0 Trace:") traceback.print_exception(None, exc, exc.__traceback__, limit=0) print("\nLimit=-1 Trace:") - traceback.print_exception(None, exc, exc.__traceback__, limit=-1) + print(traceback.format_exception(None, exc, exc.__traceback__, limit=-1), end="") class NonNativeException(Exception): From fc991c262c4a9ce5023e8a3552c7cef3539b1e93 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 13 Oct 2022 08:44:57 -0500 Subject: [PATCH 34/39] traceback: share more code between format & print exception --- shared-bindings/traceback/__init__.c | 76 ++++++++++++++-------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/shared-bindings/traceback/__init__.c b/shared-bindings/traceback/__init__.c index 566ac57218..08744d8009 100644 --- a/shared-bindings/traceback/__init__.c +++ b/shared-bindings/traceback/__init__.c @@ -38,7 +38,42 @@ //| """ //| ... -STATIC void traceback_exception_common(mp_print_t *print, mp_obj_t value, mp_obj_t tb_obj, mp_obj_t limit_obj) { +STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *print, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_etype, ARG_value, ARG_tb, ARG_limit, ARG_file, ARG_chain }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_etype, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_value, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_tb, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_limit, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_file, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_chain, MP_ARG_BOOL, {.u_bool = true} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_obj_t value = args[ARG_value].u_obj; + mp_obj_t tb_obj = args[ARG_tb].u_obj; + mp_obj_t limit_obj = args[ARG_limit].u_obj; + + if (args[ARG_file].u_obj != mp_const_none) { + if (!is_print_exception) { + #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE + mp_arg_error_terse_mismatch(); + #else + mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("unexpected keyword argument '%q'"), MP_QSTR_file); + #endif + + } + #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES + mp_get_stream_raise(args[ARG_file].u_obj, MP_STREAM_OP_WRITE); + print->data = MP_OBJ_TO_PTR(args[ARG_file].u_obj); + print->print_strn = mp_stream_write_adaptor; + #else + mp_raise_NotImplementedError(translate("file write is not available")); + #endif + } + if (!mp_obj_is_exception_instance(value)) { mp_raise_TypeError(translate("invalid exception")); } @@ -91,22 +126,10 @@ STATIC void traceback_exception_common(mp_print_t *print, mp_obj_t value, mp_obj //| ... //| STATIC mp_obj_t traceback_format_exception(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_etype, ARG_value, ARG_tb, ARG_limit, ARG_chain }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_etype, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_value, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_tb, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_limit, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_chain, MP_ARG_BOOL, {.u_bool = true} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_print_t print; vstr_t vstr; vstr_init_print(&vstr, 0, &print); - traceback_exception_common(&print, args[ARG_value].u_obj, args[ARG_tb].u_obj, args[ARG_limit].u_obj); + traceback_exception_common(false, &print, n_args, pos_args, kw_args); return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); } @@ -139,31 +162,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(traceback_format_exception_obj, 0, traceback_f //| STATIC mp_obj_t traceback_print_exception(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_etype, ARG_value, ARG_tb, ARG_limit, ARG_file, ARG_chain }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_etype, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_value, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_tb, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_limit, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_file, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_chain, MP_ARG_BOOL, {.u_bool = true} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_print_t print = mp_plat_print; - if (args[ARG_file].u_obj != mp_const_none) { - #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES - mp_get_stream_raise(args[ARG_file].u_obj, MP_STREAM_OP_WRITE); - print.data = MP_OBJ_TO_PTR(args[ARG_file].u_obj); - print.print_strn = mp_stream_write_adaptor; - #else - mp_raise_NotImplementedError(translate("file write is not available")); - #endif - } - - traceback_exception_common(&print, args[ARG_value].u_obj, args[ARG_tb].u_obj, args[ARG_limit].u_obj); + traceback_exception_common(true, &print, n_args, pos_args, kw_args); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(traceback_print_exception_obj, 0, traceback_print_exception); From 47759294e0ba9187ab6cf9a151d3ddb41a37e73a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 13 Oct 2022 08:51:41 -0500 Subject: [PATCH 35/39] code changes for supporting 1-arg print_exception --- shared-bindings/traceback/__init__.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/shared-bindings/traceback/__init__.c b/shared-bindings/traceback/__init__.c index 08744d8009..b2221a4c8e 100644 --- a/shared-bindings/traceback/__init__.c +++ b/shared-bindings/traceback/__init__.c @@ -39,11 +39,11 @@ //| ... STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *print, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_etype, ARG_value, ARG_tb, ARG_limit, ARG_file, ARG_chain }; + enum { ARG_exc, ARG_value, ARG_tb, ARG_limit, ARG_file, ARG_chain }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_etype, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_value, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_tb, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_value, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_tb, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_limit, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_file, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_chain, MP_ARG_BOOL, {.u_bool = true} }, @@ -53,6 +53,9 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t value = args[ARG_value].u_obj; + if (value == MP_OBJ_NULL) { + value = args[ARG_exc].u_obj; + } mp_obj_t tb_obj = args[ARG_tb].u_obj; mp_obj_t limit_obj = args[ARG_limit].u_obj; @@ -88,7 +91,9 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin mp_obj_exception_t *exc = mp_obj_exception_get_native(value); mp_obj_traceback_t *trace_backup = exc->traceback; - if (tb_obj != mp_const_none && print_tb) { + if (tb_obj == MP_OBJ_NULL) { + /* Print the traceback's exception as is */ + } else if (tb_obj != mp_const_none && print_tb) { exc->traceback = mp_arg_validate_type(tb_obj, &mp_type_traceback, MP_QSTR_tb); } else { exc->traceback = (mp_obj_traceback_t *)&mp_const_empty_traceback_obj; From 448eb1b70b93c35b611aefdff486cd12f1fc7570 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 13 Oct 2022 09:24:46 -0500 Subject: [PATCH 36/39] Document the 3.10-style calling pattern --- shared-bindings/traceback/__init__.c | 49 +++++++++++++++++++--------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/shared-bindings/traceback/__init__.c b/shared-bindings/traceback/__init__.c index b2221a4c8e..bc5776db2b 100644 --- a/shared-bindings/traceback/__init__.c +++ b/shared-bindings/traceback/__init__.c @@ -104,14 +104,24 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin } //| def format_exception( -//| etype: Type[BaseException], -//| value: BaseException, -//| tb: TracebackType, +//| exc: BaseException | Type[BaseException], +//| /, +//| value: Optional[BaseException] = None, +//| tb: Optional[TracebackType] = None, //| limit: Optional[int] = None, //| chain: Optional[bool] = True, -//| ) -> None: +//| ) -> str: //| """Format a stack trace and the exception information. //| +//| If the exception value is passed in ``exc``, then this exception value and its +//| associated traceback are used. This is compatible with CPython 3.10 and newer. +//| +//| If the exception value is passed in ``value``, then any value passed in for +//| ``exc`` is ignored. ``value`` is used as the exception value and the +//| traceback in the ``tb`` argument is used. In this case, if ``tb`` is None, +//| no traceback will be shown. This is compatible with CPython 3.5 and +//| newer. +//| //| The arguments have the same meaning as the corresponding arguments //| to print_exception(). The return value is a list of strings, each //| ending in a newline and some containing internal newlines. When @@ -120,15 +130,13 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin //| //| .. note:: Setting ``chain`` will have no effect as chained exceptions are not yet implemented. //| -//| :param Type[BaseException] etype: This is ignored and inferred from the type of ``value``. -//| :param BaseException value: The exception. Must be an instance of `BaseException`. -//| :param TracebackType tb: The traceback object. If `None`, the traceback will not be printed. +//| :param exc: The exception. Must be an instance of `BaseException`. Unused if value is specified. +//| :param value: If specified, is used in place of ``exc``. +//| :param TracebackType tb: When value is alsp specified, ``tb`` is used in place of the exception's own traceback. If `None`, the traceback will not be printed. //| :param int limit: Print up to limit stack trace entries (starting from the caller’s frame) if limit is positive. //| Otherwise, print the last ``abs(limit)`` entries. If limit is omitted or None, all entries are printed. //| :param bool chain: If `True` then chained exceptions will be printed (note: not yet implemented). -//| //| """ -//| ... //| STATIC mp_obj_t traceback_format_exception(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_print_t print; @@ -141,21 +149,30 @@ STATIC mp_obj_t traceback_format_exception(size_t n_args, const mp_obj_t *pos_ar STATIC MP_DEFINE_CONST_FUN_OBJ_KW(traceback_format_exception_obj, 0, traceback_format_exception); //| def print_exception( -//| etype: Type[BaseException], -//| value: BaseException, -//| tb: TracebackType, +//| exc: BaseException | Type[BaseException], +//| /, +//| value: Optional[BaseException] = None, +//| tb: Optional[TracebackType] = None, //| limit: Optional[int] = None, //| file: Optional[io.FileIO] = None, //| chain: Optional[bool] = True, //| ) -> None: -//| //| """Prints exception information and stack trace entries. //| +//| If the exception value is passed in ``exc``, then this exception value and its +//| associated traceback are used. This is compatible with CPython 3.10 and newer. +//| +//| If the exception value is passed in ``value``, then any value passed in for +//| ``exc`` is ignored. ``value`` is used as the exception value and the +//| traceback in the ``tb`` argument is used. In this case, if ``tb`` is None, +//| no traceback will be shown. This is compatible with CPython 3.5 and +//| newer. +//| //| .. note:: Setting ``chain`` will have no effect as chained exceptions are not yet implemented. //| -//| :param Type[BaseException] etype: This is ignored and inferred from the type of ``value``. -//| :param BaseException value: The exception. Must be an instance of `BaseException`. -//| :param TracebackType tb: The traceback object. If `None`, the traceback will not be printed. +//| :param exc: The exception. Must be an instance of `BaseException`. Unused if value is specified. +//| :param value: If specified, is used in place of ``exc``. +//| :param tb: When value is alsp specified, ``tb`` is used in place of the exception's own traceback. If `None`, the traceback will not be printed. //| :param int limit: Print up to limit stack trace entries (starting from the caller’s frame) if limit is positive. //| Otherwise, print the last ``abs(limit)`` entries. If limit is omitted or None, all entries are printed. //| :param io.FileIO file: If file is omitted or `None`, the output goes to `sys.stderr`; otherwise it should be an open From 9ecb905061c1d5864009029098b485280015c937 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 13 Oct 2022 09:24:56 -0500 Subject: [PATCH 37/39] Test new-style exception printing --- tests/circuitpython/traceback_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/circuitpython/traceback_test.py b/tests/circuitpython/traceback_test.py index 6f51ceede8..5377f1dca4 100644 --- a/tests/circuitpython/traceback_test.py +++ b/tests/circuitpython/traceback_test.py @@ -15,7 +15,7 @@ except Exception as exc: print("\nNo Trace:") traceback.print_exception(None, exc, None) print("\nDefault Trace:") - traceback.print_exception(None, exc, exc.__traceback__) + traceback.print_exception(exc) print("\nLimit=1 Trace:") traceback.print_exception(None, exc, exc.__traceback__, limit=1) print("\nLimit=0 Trace:") From febc7a8514f9efbff8394f808483757375aca2e4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 13 Oct 2022 09:29:21 -0500 Subject: [PATCH 38/39] format_traceback: Return list, as documented, and compatible with CPython --- shared-bindings/traceback/__init__.c | 5 +++-- tests/circuitpython/traceback_test.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/shared-bindings/traceback/__init__.c b/shared-bindings/traceback/__init__.c index bc5776db2b..eeb7bc458d 100644 --- a/shared-bindings/traceback/__init__.c +++ b/shared-bindings/traceback/__init__.c @@ -110,7 +110,7 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin //| tb: Optional[TracebackType] = None, //| limit: Optional[int] = None, //| chain: Optional[bool] = True, -//| ) -> str: +//| ) -> List[str]: //| """Format a stack trace and the exception information. //| //| If the exception value is passed in ``exc``, then this exception value and its @@ -143,7 +143,8 @@ STATIC mp_obj_t traceback_format_exception(size_t n_args, const mp_obj_t *pos_ar vstr_t vstr; vstr_init_print(&vstr, 0, &print); traceback_exception_common(false, &print, n_args, pos_args, kw_args); - return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); + mp_obj_t output = mp_obj_new_str_from_vstr(&mp_type_str, &vstr); + return mp_obj_new_list(1, &output); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(traceback_format_exception_obj, 0, traceback_format_exception); diff --git a/tests/circuitpython/traceback_test.py b/tests/circuitpython/traceback_test.py index 5377f1dca4..17c54c857a 100644 --- a/tests/circuitpython/traceback_test.py +++ b/tests/circuitpython/traceback_test.py @@ -21,7 +21,7 @@ except Exception as exc: print("\nLimit=0 Trace:") traceback.print_exception(None, exc, exc.__traceback__, limit=0) print("\nLimit=-1 Trace:") - print(traceback.format_exception(None, exc, exc.__traceback__, limit=-1), end="") + print("".join(traceback.format_exception(None, exc, exc.__traceback__, limit=-1)), end="") class NonNativeException(Exception): From ead03cd96f15a6807a8e94dec59e719f5c26ad80 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 13 Oct 2022 11:47:10 -0400 Subject: [PATCH 39/39] add caveat in documentation --- shared-bindings/microcontroller/Processor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index 47c400aee3..5a4a2556e1 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -104,7 +104,11 @@ MP_PROPERTY_GETTER(mcu_processor_reset_reason_obj, //| temperature: Optional[float] //| """The on-chip temperature, in Celsius, as a float. (read-only) //| -//| Is `None` if the temperature is not available.""" +//| Is `None` if the temperature is not available. +//| +//| .. note :: On small SAMD21 builds without external flash, +//| the reported temperature has reduced accuracy and precision, to save code space. +//| """ STATIC mp_obj_t mcu_processor_get_temperature(mp_obj_t self) { float temperature = common_hal_mcu_processor_get_temperature(); return isnan(temperature) ? mp_const_none : mp_obj_new_float(temperature);