From 82a59a824c77c933a622498b9005dc50a026904e Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 27 Apr 2023 10:31:03 +1000 Subject: [PATCH 001/565] github/workflows: Fetch full history for mpremote workflow. Instead of doing the shallow checkout followed by an unshallow-with-tags, just set fetch-depth=0 to get the full history to start with. Signed-off-by: Jim Mussared --- .github/workflows/mpremote.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/mpremote.yml b/.github/workflows/mpremote.yml index 3cfb9d47d3..14aef03e07 100644 --- a/.github/workflows/mpremote.yml +++ b/.github/workflows/mpremote.yml @@ -13,11 +13,9 @@ jobs: steps: - uses: actions/checkout@v3 with: - # Version is determined from git, - # should be deep enough to get to latest tag - fetch-depth: '1000' - - run: | - git fetch --prune --unshallow --tags + # Setting this to zero means fetch all history and tags, + # which hatch-vcs can use to discover the version tag. + fetch-depth: 0 - uses: actions/setup-python@v4 - name: Install build tools run: pip install build From dc7de6ed839dfd9c0a538fd1375f2adb77a68205 Mon Sep 17 00:00:00 2001 From: Takeo Takahashi Date: Fri, 13 Jan 2023 21:28:15 +0900 Subject: [PATCH 002/565] renesas-ra: Change MICROPY_HW_BOARD_NAME definition to product name. Changes in this commit: - Change MICROPY_HW_BOARD_NAME definition to match the product name. - Rename board folder's name to match the product name style. - Change related files like Makefile, document descriptions, test cases, CI and tools. Signed-off-by: Takeo Takahashi --- docs/renesas-ra/general.rst | 2 +- docs/renesas-ra/tutorial/intro.rst | 2 +- ports/renesas-ra/Makefile | 10 +++--- ports/renesas-ra/README.md | 12 +++---- .../boards/{RA4M1_EK => EK_RA4M1}/board.json | 0 .../boards/{RA4M1_EK => EK_RA4M1}/manifest.py | 0 .../{RA4M1_EK => EK_RA4M1}/mpconfigboard.h | 2 +- .../{RA4M1_EK => EK_RA4M1}/mpconfigboard.mk | 4 +-- .../boards/{RA4M1_EK => EK_RA4M1}/pins.csv | 0 .../boards/{RA4M1_EK => EK_RA4M1}/ra4m1_ek.ld | 0 .../{RA4M1_EK => EK_RA4M1}/ra4m1_ek_conf.h | 0 .../ra_cfg/fsp_cfg/bsp/board_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h | 0 .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 0 .../ra_cfg/fsp_cfg/r_adc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_agt_cfg.h | 0 .../ra_cfg/fsp_cfg/r_dtc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_flash_lp_cfg.h | 0 .../ra_cfg/fsp_cfg/r_icu_cfg.h | 0 .../ra_cfg/fsp_cfg/r_ioport_cfg.h | 0 .../ra_cfg/fsp_cfg/r_lpm_cfg.h | 0 .../ra_cfg/fsp_cfg/r_rtc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 0 .../ra_cfg/fsp_cfg/r_spi_cfg.h | 0 .../ra_gen/RA4M1-EK.csv | 0 .../ra_gen/bsp_clock_cfg.h | 0 .../ra_gen/bsp_pin_cfg.h | 0 .../ra_gen/common_data.c | 0 .../ra_gen/common_data.h | 0 .../{RA4M1_EK => EK_RA4M1}/ra_gen/hal_data.c | 0 .../{RA4M1_EK => EK_RA4M1}/ra_gen/hal_data.h | 0 .../{RA4M1_EK => EK_RA4M1}/ra_gen/main.c | 0 .../{RA4M1_EK => EK_RA4M1}/ra_gen/pin_data.c | 0 .../ra_gen/vector_data.c | 0 .../ra_gen/vector_data.h | 0 .../{RA4M1_EK => EK_RA4M1}/src/hal_entry.c | 0 .../boards/{RA4W1_EK => EK_RA4W1}/board.json | 0 .../{RA4W1_EK => EK_RA4W1}/mpconfigboard.h | 2 +- .../{RA4W1_EK => EK_RA4W1}/mpconfigboard.mk | 2 +- .../boards/{RA4W1_EK => EK_RA4W1}/pins.csv | 0 .../boards/{RA4W1_EK => EK_RA4W1}/ra4w1_ek.ld | 0 .../{RA4W1_EK => EK_RA4W1}/ra4w1_ek_conf.h | 0 .../ra_cfg/fsp_cfg/bsp/board_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h | 0 .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 0 .../ra_cfg/fsp_cfg/r_adc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_agt_cfg.h | 0 .../ra_cfg/fsp_cfg/r_dtc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_flash_lp_cfg.h | 0 .../ra_cfg/fsp_cfg/r_icu_cfg.h | 0 .../ra_cfg/fsp_cfg/r_iic_master_cfg.h | 0 .../ra_cfg/fsp_cfg/r_ioport_cfg.h | 0 .../ra_cfg/fsp_cfg/r_lpm_cfg.h | 0 .../ra_cfg/fsp_cfg/r_rtc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 0 .../ra_cfg/fsp_cfg/r_spi_cfg.h | 0 .../ra_gen/RA4W1-EK.csv | 0 .../ra_gen/bsp_clock_cfg.h | 0 .../ra_gen/bsp_pin_cfg.h | 0 .../ra_gen/common_data.c | 0 .../ra_gen/common_data.h | 0 .../{RA4W1_EK => EK_RA4W1}/ra_gen/hal_data.c | 0 .../{RA4W1_EK => EK_RA4W1}/ra_gen/hal_data.h | 0 .../{RA4W1_EK => EK_RA4W1}/ra_gen/main.c | 0 .../{RA4W1_EK => EK_RA4W1}/ra_gen/pin_data.c | 0 .../ra_gen/vector_data.c | 0 .../ra_gen/vector_data.h | 0 .../{RA4W1_EK => EK_RA4W1}/src/hal_entry.c | 0 .../boards/{RA6M1_EK => EK_RA6M1}/board.json | 0 .../{RA6M1_EK => EK_RA6M1}/mpconfigboard.h | 2 +- .../{RA6M1_EK => EK_RA6M1}/mpconfigboard.mk | 2 +- .../boards/{RA6M1_EK => EK_RA6M1}/pins.csv | 0 .../boards/{RA6M1_EK => EK_RA6M1}/ra6m1_ek.ld | 0 .../{RA6M1_EK => EK_RA6M1}/ra6m1_ek_conf.h | 0 .../ra_cfg/fsp_cfg/bsp/board_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h | 0 .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 0 .../ra_cfg/fsp_cfg/r_adc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_agt_cfg.h | 0 .../ra_cfg/fsp_cfg/r_dtc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_flash_hp_cfg.h | 0 .../ra_cfg/fsp_cfg/r_icu_cfg.h | 0 .../ra_cfg/fsp_cfg/r_iic_master_cfg.h | 0 .../ra_cfg/fsp_cfg/r_ioport_cfg.h | 0 .../ra_cfg/fsp_cfg/r_lpm_cfg.h | 0 .../ra_cfg/fsp_cfg/r_rtc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 0 .../ra_cfg/fsp_cfg/r_spi_cfg.h | 0 .../ra_gen/RA6M1-EK.csv | 0 .../ra_gen/bsp_clock_cfg.h | 0 .../ra_gen/bsp_pin_cfg.h | 0 .../ra_gen/common_data.c | 0 .../ra_gen/common_data.h | 0 .../{RA6M1_EK => EK_RA6M1}/ra_gen/hal_data.c | 0 .../{RA6M1_EK => EK_RA6M1}/ra_gen/hal_data.h | 0 .../{RA6M1_EK => EK_RA6M1}/ra_gen/main.c | 0 .../{RA6M1_EK => EK_RA6M1}/ra_gen/pin_data.c | 0 .../ra_gen/vector_data.c | 0 .../ra_gen/vector_data.h | 0 .../{RA6M1_EK => EK_RA6M1}/src/hal_entry.c | 0 .../boards/{RA6M2_EK => EK_RA6M2}/board.json | 0 .../{RA6M2_EK => EK_RA6M2}/mpconfigboard.h | 2 +- .../{RA6M2_EK => EK_RA6M2}/mpconfigboard.mk | 2 +- .../boards/{RA6M2_EK => EK_RA6M2}/pins.csv | 0 .../boards/{RA6M2_EK => EK_RA6M2}/ra6m2_ek.ld | 0 .../{RA6M2_EK => EK_RA6M2}/ra6m2_ek_conf.h | 0 .../ra_cfg/fsp_cfg/bsp/board_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h | 0 .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 0 .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 0 .../ra_cfg/fsp_cfg/r_adc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_agt_cfg.h | 0 .../ra_cfg/fsp_cfg/r_dtc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_flash_hp_cfg.h | 0 .../ra_cfg/fsp_cfg/r_icu_cfg.h | 0 .../ra_cfg/fsp_cfg/r_iic_master_cfg.h | 0 .../ra_cfg/fsp_cfg/r_ioport_cfg.h | 0 .../ra_cfg/fsp_cfg/r_lpm_cfg.h | 0 .../ra_cfg/fsp_cfg/r_rtc_cfg.h | 0 .../ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 0 .../ra_cfg/fsp_cfg/r_spi_cfg.h | 0 .../ra_gen/RA6M2-EK.csv | 0 .../ra_gen/bsp_clock_cfg.h | 0 .../ra_gen/bsp_pin_cfg.h | 0 .../ra_gen/common_data.c | 0 .../ra_gen/common_data.h | 0 .../{RA6M2_EK => EK_RA6M2}/ra_gen/hal_data.c | 0 .../{RA6M2_EK => EK_RA6M2}/ra_gen/hal_data.h | 0 .../{RA6M2_EK => EK_RA6M2}/ra_gen/main.c | 0 .../{RA6M2_EK => EK_RA6M2}/ra_gen/pin_data.c | 0 .../ra_gen/vector_data.c | 0 .../ra_gen/vector_data.h | 0 .../{RA6M2_EK => EK_RA6M2}/src/hal_entry.c | 0 .../boards/RA4M1_CLICKER/mpconfigboard.h | 2 +- ports/renesas-ra/build_all_boards.sh | 8 ++--- tests/renesas-ra/freq.py | 34 +++++++++---------- tests/renesas-ra/i2c.py | 6 ++-- tests/renesas-ra/spi.py | 10 +++--- tests/renesas-ra/uart1.py | 10 +++--- tools/ci.sh | 5 ++- tools/metrics.py | 2 +- 148 files changed, 62 insertions(+), 59 deletions(-) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/board.json (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/manifest.py (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/mpconfigboard.h (98%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/mpconfigboard.mk (64%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/pins.csv (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra4m1_ek.ld (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra4m1_ek_conf.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/bsp/board_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/bsp/bsp_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_adc_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_agt_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_dtc_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_flash_lp_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_icu_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_ioport_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_lpm_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_rtc_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_sci_uart_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_cfg/fsp_cfg/r_spi_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/RA4M1-EK.csv (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/bsp_clock_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/bsp_pin_cfg.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/common_data.c (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/common_data.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/hal_data.c (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/hal_data.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/main.c (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/pin_data.c (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/vector_data.c (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/ra_gen/vector_data.h (100%) rename ports/renesas-ra/boards/{RA4M1_EK => EK_RA4M1}/src/hal_entry.c (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/board.json (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/mpconfigboard.h (98%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/mpconfigboard.mk (66%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/pins.csv (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra4w1_ek.ld (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra4w1_ek_conf.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/bsp/board_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/bsp/bsp_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_adc_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_agt_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_dtc_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_flash_lp_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_icu_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_iic_master_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_ioport_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_lpm_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_rtc_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_sci_uart_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_cfg/fsp_cfg/r_spi_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/RA4W1-EK.csv (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/bsp_clock_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/bsp_pin_cfg.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/common_data.c (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/common_data.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/hal_data.c (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/hal_data.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/main.c (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/pin_data.c (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/vector_data.c (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/ra_gen/vector_data.h (100%) rename ports/renesas-ra/boards/{RA4W1_EK => EK_RA4W1}/src/hal_entry.c (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/board.json (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/mpconfigboard.h (98%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/mpconfigboard.mk (66%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/pins.csv (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra6m1_ek.ld (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra6m1_ek_conf.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/bsp/board_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/bsp/bsp_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_adc_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_agt_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_dtc_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_flash_hp_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_icu_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_iic_master_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_ioport_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_lpm_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_rtc_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_sci_uart_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_cfg/fsp_cfg/r_spi_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/RA6M1-EK.csv (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/bsp_clock_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/bsp_pin_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/common_data.c (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/common_data.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/hal_data.c (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/hal_data.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/main.c (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/pin_data.c (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/vector_data.c (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/ra_gen/vector_data.h (100%) rename ports/renesas-ra/boards/{RA6M1_EK => EK_RA6M1}/src/hal_entry.c (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/board.json (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/mpconfigboard.h (98%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/mpconfigboard.mk (66%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/pins.csv (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra6m2_ek.ld (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra6m2_ek_conf.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/bsp/board_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/bsp/bsp_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_adc_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_agt_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_dtc_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_flash_hp_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_icu_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_iic_master_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_ioport_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_lpm_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_rtc_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_sci_uart_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_cfg/fsp_cfg/r_spi_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/RA6M2-EK.csv (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/bsp_clock_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/bsp_pin_cfg.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/common_data.c (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/common_data.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/hal_data.c (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/hal_data.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/main.c (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/pin_data.c (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/vector_data.c (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/ra_gen/vector_data.h (100%) rename ports/renesas-ra/boards/{RA6M2_EK => EK_RA6M2}/src/hal_entry.c (100%) diff --git a/docs/renesas-ra/general.rst b/docs/renesas-ra/general.rst index c8eea53f8b..59bc2ef206 100644 --- a/docs/renesas-ra/general.rst +++ b/docs/renesas-ra/general.rst @@ -18,7 +18,7 @@ The following boards are officially supported. * RA4M1-CLICKER -For the manual and other references for the board and RA Family MCU, please refer to the web page: `EK-RA4M1 CLICKER `_ +For the manual and other references for the board and RA Family MCU, please refer to the web page: `RA4M1 CLICKER `_ * EK-RA6M2 diff --git a/docs/renesas-ra/tutorial/intro.rst b/docs/renesas-ra/tutorial/intro.rst index 6c41f43971..6003e71575 100644 --- a/docs/renesas-ra/tutorial/intro.rst +++ b/docs/renesas-ra/tutorial/intro.rst @@ -62,6 +62,6 @@ Access the MicroPython REPL (the Python prompt) via USB serial or UART with 1152 You can see the MicroPython REPL prompt like below:: - MicroPython v1.18-293-g339aa09b8-dirty on 2022-03-26; RA6M2_EK with RA6M2 + MicroPython v1.20.0 on 2023-04-27; EK-RA6M2 with RA6M2 Type "help()" for more information. >>> diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index dc4b158483..f0b1e1ed75 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -5,7 +5,7 @@ ifdef BOARD_DIR BOARD ?= $(notdir $(BOARD_DIR:/=)) else # If not given on the command line, then default to RA6M2_EK. -BOARD ?= RA6M2_EK +BOARD ?= EK_RA6M2 BOARD_DIR ?= boards/$(BOARD) endif @@ -23,28 +23,28 @@ CMSIS_MCU_CAP = RA4M1 USE_FSP_LPM = 0 endif -ifeq ($(BOARD),RA4M1_EK) +ifeq ($(BOARD),EK_RA4M1) BOARD_LOW = ra4m1_ek CMSIS_MCU_LOW = ra4m1 CMSIS_MCU_CAP = RA4M1 USE_FSP_LPM = 0 endif -ifeq ($(BOARD),RA4W1_EK) +ifeq ($(BOARD),EK_RA4W1) BOARD_LOW = ra4w1_ek CMSIS_MCU_LOW = ra4w1 CMSIS_MCU_CAP = RA4W1 USE_FSP_LPM = 1 endif -ifeq ($(BOARD),RA6M1_EK) +ifeq ($(BOARD),EK_RA6M1) BOARD_LOW = ra6m1_ek CMSIS_MCU_LOW = ra6m1 CMSIS_MCU_CAP = RA6M1 USE_FSP_LPM = 1 endif -ifeq ($(BOARD),RA6M2_EK) +ifeq ($(BOARD),EK_RA6M2) BOARD_LOW = ra6m2_ek CMSIS_MCU_LOW = ra6m2 CMSIS_MCU_CAP = RA6M2 diff --git a/ports/renesas-ra/README.md b/ports/renesas-ra/README.md index c75a9e13d1..896d465d2d 100644 --- a/ports/renesas-ra/README.md +++ b/ports/renesas-ra/README.md @@ -48,15 +48,15 @@ First the submodules must be obtained using: * Build binary image `.hex` Then to build for a given board subdirectory name, run: - $ make BOARD=RA6M2_EK clean - $ make BOARD=RA6M2_EK + $ make BOARD=EK_RA6M2 clean + $ make BOARD=EK_RA6M2 - The default board subdirectory name is RA6M2_EK (which is for EK-RA6M2 board) + The default board subdirectory name is EK_RA6M2 (which is for EK-RA6M2 board) but any of the names of the subdirectories in the `boards/` directory can be -passed as the argument to `BOARD=`; for example `RA4M1_CLICKER`, `RA4M1_EK`, -`RA4W1_EK` and `RA6M1_EK`. +passed as the argument to `BOARD=`; for example `RA4M1_CLICKER`, `EK_RA4M1`, +`EK_RA4W1` and `EK_RA6M1`. The above command should produce binary images `firmware.hex` in the -build-RA6M2_EK/` subdirectory (or the equivalent directory for the board specified). +build-EK_RA6M2/` subdirectory (or the equivalent directory for the board specified). ## Supported/Unsupprted funtions Please refer to the `renesas-ra` quick reference. diff --git a/ports/renesas-ra/boards/RA4M1_EK/board.json b/ports/renesas-ra/boards/EK_RA4M1/board.json similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/board.json rename to ports/renesas-ra/boards/EK_RA4M1/board.json diff --git a/ports/renesas-ra/boards/RA4M1_EK/manifest.py b/ports/renesas-ra/boards/EK_RA4M1/manifest.py similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/manifest.py rename to ports/renesas-ra/boards/EK_RA4M1/manifest.py diff --git a/ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h similarity index 98% rename from ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.h rename to ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h index 2874142890..cd699e51bd 100644 --- a/ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h @@ -1,5 +1,5 @@ // MCU config -#define MICROPY_HW_BOARD_NAME "RA4M1_EK" +#define MICROPY_HW_BOARD_NAME "EK-RA4M1" #define MICROPY_HW_MCU_NAME "RA4M1" #define MICROPY_HW_MCU_SYSCLK 48000000 #define MICROPY_HW_MCU_PCLK 48000000 diff --git a/ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.mk b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.mk similarity index 64% rename from ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.mk rename to ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.mk index 1213fa3229..abc111d16e 100644 --- a/ports/renesas-ra/boards/RA4M1_EK/mpconfigboard.mk +++ b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.mk @@ -1,9 +1,9 @@ CMSIS_MCU = RA4M1 MCU_SERIES = m4 -LD_FILES = boards/RA4M1_EK/ra4m1_ek.ld +LD_FILES = boards/EK_RA4M1/ra4m1_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 # Don't include default frozen modules because MCU is tight on flash space -FROZEN_MANIFEST ?= boards/RA4M1_EK/manifest.py +FROZEN_MANIFEST ?= boards/EK_RA4M1/manifest.py diff --git a/ports/renesas-ra/boards/RA4M1_EK/pins.csv b/ports/renesas-ra/boards/EK_RA4M1/pins.csv similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/pins.csv rename to ports/renesas-ra/boards/EK_RA4M1/pins.csv diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra4m1_ek.ld b/ports/renesas-ra/boards/EK_RA4M1/ra4m1_ek.ld similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra4m1_ek.ld rename to ports/renesas-ra/boards/EK_RA4M1/ra4m1_ek.ld diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra4m1_ek_conf.h b/ports/renesas-ra/boards/EK_RA4M1/ra4m1_ek_conf.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra4m1_ek_conf.h rename to ports/renesas-ra/boards/EK_RA4M1/ra4m1_ek_conf.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/board_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/board_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/board_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/board_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/bsp_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_adc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_adc_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_adc_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_agt_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_agt_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_agt_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_dtc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_dtc_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_dtc_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_flash_lp_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_flash_lp_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_icu_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_icu_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_icu_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_ioport_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_ioport_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_ioport_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_lpm_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_lpm_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_lpm_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_rtc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_rtc_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_rtc_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_sci_uart_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_spi_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_cfg/fsp_cfg/r_spi_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_spi_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/RA4M1-EK.csv b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/RA4M1-EK.csv similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/RA4M1-EK.csv rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/RA4M1-EK.csv diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/bsp_clock_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/bsp_clock_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/bsp_clock_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/bsp_pin_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/bsp_pin_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/bsp_pin_cfg.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/bsp_pin_cfg.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/common_data.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.c similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/common_data.c rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.c diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/common_data.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/common_data.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/hal_data.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.c similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/hal_data.c rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.c diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/hal_data.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/main.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/main.c similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/main.c rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/main.c diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/pin_data.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/pin_data.c similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/pin_data.c rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/pin_data.c diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/vector_data.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.c similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/vector_data.c rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.c diff --git a/ports/renesas-ra/boards/RA4M1_EK/ra_gen/vector_data.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.h similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/ra_gen/vector_data.h rename to ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.h diff --git a/ports/renesas-ra/boards/RA4M1_EK/src/hal_entry.c b/ports/renesas-ra/boards/EK_RA4M1/src/hal_entry.c similarity index 100% rename from ports/renesas-ra/boards/RA4M1_EK/src/hal_entry.c rename to ports/renesas-ra/boards/EK_RA4M1/src/hal_entry.c diff --git a/ports/renesas-ra/boards/RA4W1_EK/board.json b/ports/renesas-ra/boards/EK_RA4W1/board.json similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/board.json rename to ports/renesas-ra/boards/EK_RA4W1/board.json diff --git a/ports/renesas-ra/boards/RA4W1_EK/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.h similarity index 98% rename from ports/renesas-ra/boards/RA4W1_EK/mpconfigboard.h rename to ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.h index 0bf907a48c..5fd2d1c6a3 100644 --- a/ports/renesas-ra/boards/RA4W1_EK/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.h @@ -1,5 +1,5 @@ // MCU config -#define MICROPY_HW_BOARD_NAME "RA4W1_EK" +#define MICROPY_HW_BOARD_NAME "EK-RA4W1" #define MICROPY_HW_MCU_NAME "RA4W1" #define MICROPY_HW_MCU_SYSCLK 48000000 #define MICROPY_HW_MCU_PCLK 48000000 diff --git a/ports/renesas-ra/boards/RA4W1_EK/mpconfigboard.mk b/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.mk similarity index 66% rename from ports/renesas-ra/boards/RA4W1_EK/mpconfigboard.mk rename to ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.mk index a22e577fcb..c4f95f79f4 100644 --- a/ports/renesas-ra/boards/RA4W1_EK/mpconfigboard.mk +++ b/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.mk @@ -1,6 +1,6 @@ CMSIS_MCU = RA4W1 MCU_SERIES = m4 -LD_FILES = boards/RA4W1_EK/ra4w1_ek.ld +LD_FILES = boards/EK_RA4W1/ra4w1_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 diff --git a/ports/renesas-ra/boards/RA4W1_EK/pins.csv b/ports/renesas-ra/boards/EK_RA4W1/pins.csv similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/pins.csv rename to ports/renesas-ra/boards/EK_RA4W1/pins.csv diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra4w1_ek.ld b/ports/renesas-ra/boards/EK_RA4W1/ra4w1_ek.ld similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra4w1_ek.ld rename to ports/renesas-ra/boards/EK_RA4W1/ra4w1_ek.ld diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra4w1_ek_conf.h b/ports/renesas-ra/boards/EK_RA4W1/ra4w1_ek_conf.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra4w1_ek_conf.h rename to ports/renesas-ra/boards/EK_RA4W1/ra4w1_ek_conf.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/board_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/board_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/board_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/board_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/bsp_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_adc_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_agt_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_dtc_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_flash_lp_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_flash_lp_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_icu_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_iic_master_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_ioport_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_lpm_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_rtc_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_sci_uart_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_cfg/fsp_cfg/r_spi_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/RA4W1-EK.csv b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/RA4W1-EK.csv similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/RA4W1-EK.csv rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/RA4W1-EK.csv diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/bsp_clock_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/bsp_clock_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/bsp_clock_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/bsp_pin_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/bsp_pin_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/bsp_pin_cfg.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/bsp_pin_cfg.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/common_data.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.c similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/common_data.c rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.c diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/common_data.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/common_data.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/hal_data.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.c similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/hal_data.c rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.c diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/hal_data.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/main.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/main.c similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/main.c rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/main.c diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/pin_data.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/pin_data.c similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/pin_data.c rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/pin_data.c diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/vector_data.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.c similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/vector_data.c rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.c diff --git a/ports/renesas-ra/boards/RA4W1_EK/ra_gen/vector_data.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.h similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/ra_gen/vector_data.h rename to ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.h diff --git a/ports/renesas-ra/boards/RA4W1_EK/src/hal_entry.c b/ports/renesas-ra/boards/EK_RA4W1/src/hal_entry.c similarity index 100% rename from ports/renesas-ra/boards/RA4W1_EK/src/hal_entry.c rename to ports/renesas-ra/boards/EK_RA4W1/src/hal_entry.c diff --git a/ports/renesas-ra/boards/RA6M1_EK/board.json b/ports/renesas-ra/boards/EK_RA6M1/board.json similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/board.json rename to ports/renesas-ra/boards/EK_RA6M1/board.json diff --git a/ports/renesas-ra/boards/RA6M1_EK/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.h similarity index 98% rename from ports/renesas-ra/boards/RA6M1_EK/mpconfigboard.h rename to ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.h index 59db4bc218..b6f76a062e 100644 --- a/ports/renesas-ra/boards/RA6M1_EK/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.h @@ -1,5 +1,5 @@ // MCU config -#define MICROPY_HW_BOARD_NAME "RA6M1_EK" +#define MICROPY_HW_BOARD_NAME "EK-RA6M1" #define MICROPY_HW_MCU_NAME "RA6M1" #define MICROPY_HW_MCU_SYSCLK 120000000 #define MICROPY_HW_MCU_PCLK 60000000 diff --git a/ports/renesas-ra/boards/RA6M1_EK/mpconfigboard.mk b/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.mk similarity index 66% rename from ports/renesas-ra/boards/RA6M1_EK/mpconfigboard.mk rename to ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.mk index 06f5f97bda..3f916eb8e3 100644 --- a/ports/renesas-ra/boards/RA6M1_EK/mpconfigboard.mk +++ b/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.mk @@ -1,6 +1,6 @@ CMSIS_MCU = RA6M1 MCU_SERIES = m4 -LD_FILES = boards/RA6M1_EK/ra6m1_ek.ld +LD_FILES = boards/EK_RA6M1/ra6m1_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 diff --git a/ports/renesas-ra/boards/RA6M1_EK/pins.csv b/ports/renesas-ra/boards/EK_RA6M1/pins.csv similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/pins.csv rename to ports/renesas-ra/boards/EK_RA6M1/pins.csv diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra6m1_ek.ld b/ports/renesas-ra/boards/EK_RA6M1/ra6m1_ek.ld similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra6m1_ek.ld rename to ports/renesas-ra/boards/EK_RA6M1/ra6m1_ek.ld diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra6m1_ek_conf.h b/ports/renesas-ra/boards/EK_RA6M1/ra6m1_ek_conf.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra6m1_ek_conf.h rename to ports/renesas-ra/boards/EK_RA6M1/ra6m1_ek_conf.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/board_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/board_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/board_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/board_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/bsp_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_adc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_adc_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_adc_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_agt_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_agt_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_agt_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_dtc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_dtc_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_dtc_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_flash_hp_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_flash_hp_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_flash_hp_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_flash_hp_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_icu_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_icu_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_icu_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_iic_master_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_iic_master_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_iic_master_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_ioport_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_ioport_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_ioport_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_lpm_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_lpm_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_lpm_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_rtc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_rtc_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_rtc_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_sci_uart_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_spi_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_cfg/fsp_cfg/r_spi_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_spi_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/RA6M1-EK.csv b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/RA6M1-EK.csv similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/RA6M1-EK.csv rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/RA6M1-EK.csv diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/bsp_clock_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/bsp_clock_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/bsp_clock_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/bsp_pin_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/bsp_pin_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/bsp_pin_cfg.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/bsp_pin_cfg.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/common_data.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.c similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/common_data.c rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.c diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/common_data.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/common_data.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/hal_data.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.c similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/hal_data.c rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.c diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/hal_data.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/main.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/main.c similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/main.c rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/main.c diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/pin_data.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/pin_data.c similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/pin_data.c rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/pin_data.c diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/vector_data.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.c similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/vector_data.c rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.c diff --git a/ports/renesas-ra/boards/RA6M1_EK/ra_gen/vector_data.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.h similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/ra_gen/vector_data.h rename to ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.h diff --git a/ports/renesas-ra/boards/RA6M1_EK/src/hal_entry.c b/ports/renesas-ra/boards/EK_RA6M1/src/hal_entry.c similarity index 100% rename from ports/renesas-ra/boards/RA6M1_EK/src/hal_entry.c rename to ports/renesas-ra/boards/EK_RA6M1/src/hal_entry.c diff --git a/ports/renesas-ra/boards/RA6M2_EK/board.json b/ports/renesas-ra/boards/EK_RA6M2/board.json similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/board.json rename to ports/renesas-ra/boards/EK_RA6M2/board.json diff --git a/ports/renesas-ra/boards/RA6M2_EK/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.h similarity index 98% rename from ports/renesas-ra/boards/RA6M2_EK/mpconfigboard.h rename to ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.h index 9988e0ed25..9e3c462eec 100644 --- a/ports/renesas-ra/boards/RA6M2_EK/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.h @@ -1,5 +1,5 @@ // MCU config -#define MICROPY_HW_BOARD_NAME "RA6M2_EK" +#define MICROPY_HW_BOARD_NAME "EK-RA6M2" #define MICROPY_HW_MCU_NAME "RA6M2" #define MICROPY_HW_MCU_SYSCLK 120000000 #define MICROPY_HW_MCU_PCLK 60000000 diff --git a/ports/renesas-ra/boards/RA6M2_EK/mpconfigboard.mk b/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.mk similarity index 66% rename from ports/renesas-ra/boards/RA6M2_EK/mpconfigboard.mk rename to ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.mk index 59d48c0e6c..a48ec6e50a 100644 --- a/ports/renesas-ra/boards/RA6M2_EK/mpconfigboard.mk +++ b/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.mk @@ -1,6 +1,6 @@ CMSIS_MCU = RA6M2 MCU_SERIES = m4 -LD_FILES = boards/RA6M2_EK/ra6m2_ek.ld +LD_FILES = boards/EK_RA6M2/ra6m2_ek.ld # MicroPython settings MICROPY_VFS_FAT = 1 diff --git a/ports/renesas-ra/boards/RA6M2_EK/pins.csv b/ports/renesas-ra/boards/EK_RA6M2/pins.csv similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/pins.csv rename to ports/renesas-ra/boards/EK_RA6M2/pins.csv diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra6m2_ek.ld b/ports/renesas-ra/boards/EK_RA6M2/ra6m2_ek.ld similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra6m2_ek.ld rename to ports/renesas-ra/boards/EK_RA6M2/ra6m2_ek.ld diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra6m2_ek_conf.h b/ports/renesas-ra/boards/EK_RA6M2/ra6m2_ek_conf.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra6m2_ek_conf.h rename to ports/renesas-ra/boards/EK_RA6M2/ra6m2_ek_conf.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/board_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/board_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/board_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/board_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/bsp_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_adc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_adc_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_adc_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_agt_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_agt_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_agt_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_dtc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_dtc_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_dtc_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_flash_hp_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_flash_hp_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_flash_hp_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_flash_hp_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_icu_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_icu_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_icu_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_iic_master_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_iic_master_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_iic_master_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_ioport_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_ioport_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_ioport_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_lpm_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_lpm_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_lpm_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_rtc_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_rtc_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_rtc_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_sci_uart_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_sci_uart_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_sci_uart_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_spi_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_cfg/fsp_cfg/r_spi_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_spi_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/RA6M2-EK.csv b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/RA6M2-EK.csv similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/RA6M2-EK.csv rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/RA6M2-EK.csv diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/bsp_clock_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/bsp_clock_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/bsp_clock_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/bsp_pin_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/bsp_pin_cfg.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/bsp_pin_cfg.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/bsp_pin_cfg.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/common_data.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.c similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/common_data.c rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.c diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/common_data.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/common_data.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/hal_data.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.c similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/hal_data.c rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.c diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/hal_data.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/main.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/main.c similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/main.c rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/main.c diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/pin_data.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/pin_data.c similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/pin_data.c rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/pin_data.c diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/vector_data.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.c similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/vector_data.c rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.c diff --git a/ports/renesas-ra/boards/RA6M2_EK/ra_gen/vector_data.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.h similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/ra_gen/vector_data.h rename to ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.h diff --git a/ports/renesas-ra/boards/RA6M2_EK/src/hal_entry.c b/ports/renesas-ra/boards/EK_RA6M2/src/hal_entry.c similarity index 100% rename from ports/renesas-ra/boards/RA6M2_EK/src/hal_entry.c rename to ports/renesas-ra/boards/EK_RA6M2/src/hal_entry.c diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.h b/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.h index f39cf8f80e..7b8ccb1445 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.h @@ -1,5 +1,5 @@ // MCU config -#define MICROPY_HW_BOARD_NAME "RA4M1_CLICKER" +#define MICROPY_HW_BOARD_NAME "RA4M1 CLICKER" #define MICROPY_HW_MCU_NAME "RA4M1" #define MICROPY_HW_MCU_SYSCLK 48000000 #define MICROPY_HW_MCU_PCLK 48000000 diff --git a/ports/renesas-ra/build_all_boards.sh b/ports/renesas-ra/build_all_boards.sh index 351047e079..0c192dba93 100644 --- a/ports/renesas-ra/build_all_boards.sh +++ b/ports/renesas-ra/build_all_boards.sh @@ -5,22 +5,22 @@ DT=`date +%Y%m%d%H%M` make DEBUG=0 BOARD=${BOARD} clean 2>&1 | tee ${BOARD}_build_${DT}.log make DEBUG=0 BOARD=${BOARD} 2>&1 | tee -a ${BOARD}_build_${DT}.log # -export BOARD="RA6M2_EK" +export BOARD="EK_RA6M2" DT=`date +%Y%m%d%H%M` make DEBUG=1 BOARD=${BOARD} clean 2>&1 | tee ${BOARD}_build_${DT}.log make DEBUG=1 BOARD=${BOARD} 2>&1 | tee -a ${BOARD}_build_${DT}.log # -export BOARD="RA4M1_EK" +export BOARD="EK_RA4M1" DT=`date +%Y%m%d%H%M` make DEBUG=0 BOARD=${BOARD} clean 2>&1 | tee ${BOARD}_build_${DT}.log make DEBUG=0 BOARD=${BOARD} 2>&1 | tee -a ${BOARD}_build_${DT}.log # -export BOARD="RA4W1_EK" +export BOARD="EK_RA4W1" DT=`date +%Y%m%d%H%M` make DEBUG=0 BOARD=${BOARD} clean 2>&1 | tee ${BOARD}_build_${DT}.log make DEBUG=0 BOARD=${BOARD} 2>&1 | tee -a ${BOARD}_build_${DT}.log # -export BOARD="RA6M1_EK" +export BOARD="EK_RA6M1" DT=`date +%Y%m%d%H%M` make DEBUG=1 BOARD=${BOARD} clean 2>&1 | tee ${BOARD}_build_${DT}.log make DEBUG=1 BOARD=${BOARD} 2>&1 | tee -a ${BOARD}_build_${DT}.log diff --git a/tests/renesas-ra/freq.py b/tests/renesas-ra/freq.py index 6fbf6ce096..6ce1871f8c 100644 --- a/tests/renesas-ra/freq.py +++ b/tests/renesas-ra/freq.py @@ -1,16 +1,16 @@ # # definitions # -MACHINE_RA4M1_CLICKER = "RA4M1_CLICKER with RA4M1" -MACHINE_RA4M1_EK = "RA4M1_EK with RA4M1" -MACHINE_RA4W1_EK = "RA4W1_EK with RA4W1" -MACHINE_RA6M1_EK = "RA6M1_EK with RA6M1" -MACHINE_RA6M2_EK = "RA6M2_EK with RA6M2" +MACHINE_RA4M1_CLICKER = "RA4M1 CLICKER with RA4M1" +MACHINE_EK_RA4M1 = "EK-RA4M1 with RA4M1" +MACHINE_EK_RA4W1 = "EK-RA4W1 with RA4W1" +MACHINE_EK_RA6M1 = "EK-RA6M1 with RA6M1" +MACHINE_EK_RA6M2 = "EK-RA6M2 with RA6M2" SYSCLK_RA4M1_CLICKER = 48000000 -SYSCLK_RA4M1_EK = 48000000 -SYSCLK_RA4W1_EK = 48000000 -SYSCLK_RA6M1_EK = 120000000 -SYSCLK_RA6M2_EK = 120000000 +SYSCLK_EK_RA4M1 = 48000000 +SYSCLK_EK_RA4W1 = 48000000 +SYSCLK_EK_RA6M1 = 120000000 +SYSCLK_EK_RA6M2 = 120000000 # # machine @@ -34,26 +34,26 @@ if m == MACHINE_RA4M1_CLICKER: print("freq: NG") -if m == MACHINE_RA4M1_EK: - if f == SYSCLK_RA4M1_EK: +if m == MACHINE_EK_RA4M1: + if f == SYSCLK_EK_RA4M1: print("freq: OK") else: print("freq: NG") -if m == MACHINE_RA4W1_EK: - if f == SYSCLK_RA4W1_EK: +if m == MACHINE_EK_RA4W1: + if f == SYSCLK_EK_RA4W1: print("freq: OK") else: print("freq: NG") -if m == MACHINE_RA6M1_EK: - if f == SYSCLK_RA6M1_EK: +if m == MACHINE_EK_RA6M1: + if f == SYSCLK_EK_RA6M1: print("freq: OK") else: print("freq: NG") -if m == MACHINE_RA6M2_EK: - if f == SYSCLK_RA6M2_EK: +if m == MACHINE_EK_RA6M2: + if f == SYSCLK_EK_RA6M2: print("freq: OK") else: print("freq: NG") diff --git a/tests/renesas-ra/i2c.py b/tests/renesas-ra/i2c.py index bb22509e45..3991f7175b 100644 --- a/tests/renesas-ra/i2c.py +++ b/tests/renesas-ra/i2c.py @@ -2,11 +2,11 @@ import os import time n = os.uname().machine -if "RA6M2_EK" in n: +if "EK-RA6M2" in n: i2c_id = 2 -elif "RA6M1_EK" in n: +elif "EK-RA6M1" in n: i2c_id = 0 -elif ("RA4M1_CLICKER" in n) or ("RA4M1_EK" in n) or ("RA4W1_EK" in n): +elif ("RA4M1 CLICKER" in n) or ("EK-RA4M1" in n) or ("EK-RA4W1" in n): print("SKIP") raise SystemExit else: diff --git a/tests/renesas-ra/spi.py b/tests/renesas-ra/spi.py index eb24f37147..52b908efbe 100644 --- a/tests/renesas-ra/spi.py +++ b/tests/renesas-ra/spi.py @@ -3,11 +3,11 @@ from machine import SPI machine = os.uname().machine if ( - "RA6M1_EK" in machine - or "RA4M1_CLICKER" in machine - or "RA4M1_EK" in machine - or "RA4W1_EK" in machine - or "RA6M1_EK" in machine + "EK-RA6M1" in machine + or "RA4M1 CLICKER" in machine + or "EK-RA4M1" in machine + or "EK-RA4W1" in machine + or "EK-RA6M1" in machine ): spis = (-1, 0) else: diff --git a/tests/renesas-ra/uart1.py b/tests/renesas-ra/uart1.py index bf7b927602..ba329fb85f 100644 --- a/tests/renesas-ra/uart1.py +++ b/tests/renesas-ra/uart1.py @@ -2,29 +2,29 @@ import os from machine import UART machine = os.uname().machine -if "RA6M2_EK" in machine: +if "EK-RA6M2" in machine: # 0, 7, 9 uart_ids = (0, 7, 9) try_id = 7 try_s = "UART(7, baudrate=115200, bits=8, parity=None, stop=1, tx=P401, rx=P402, flow=0, rxbuf=259, timeout=0, timeout_char=2)" -elif "RA4M1_CLICKER" in machine: +elif "RA4M1 CLICKER" in machine: # 0, 1 uart_ids = (0, 1) try_id = 0 try_s = "UART(0, baudrate=115200, bits=8, parity=None, stop=1, tx=P411, rx=P410, flow=0, rxbuf=259, timeout=0, timeout_char=2)" -elif "RA4M1_EK" in machine: +elif "EK-RA4M1" in machine: # 0, 1, 2, 9 # vector for 9 is not registered uart_ids = (0, 1, 2) try_id = 1 try_s = "UART(1, baudrate=115200, bits=8, parity=None, stop=1, tx=P401, rx=P402, flow=0, rxbuf=259, timeout=0, timeout_char=2)" -elif "RA4W1_EK" in machine: +elif "EK-RA4W1" in machine: # 0, 1, 4, 9 # 0 is disabled. uart_ids = (1, 4, 9) try_id = 9 try_s = "UART(9, baudrate=115200, bits=8, parity=None, stop=1, tx=P109, rx=P110, flow=0, rxbuf=259, timeout=0, timeout_char=2)" -elif "RA6M1_EK" in machine: +elif "EK-RA6M1" in machine: # 0, 1, 2, 3, 4, 8, 9 # 1/3/4/9 are disabled uart_ids = (0, 2, 8) diff --git a/tools/ci.sh b/tools/ci.sh index 9146291505..ab1585e5d9 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -272,7 +272,10 @@ function ci_renesas_ra_board_build { make ${MAKEOPTS} -C mpy-cross make ${MAKEOPTS} -C ports/renesas-ra submodules make ${MAKEOPTS} -C ports/renesas-ra BOARD=RA4M1_CLICKER - make ${MAKEOPTS} -C ports/renesas-ra BOARD=RA6M2_EK + make ${MAKEOPTS} -C ports/renesas-ra BOARD=EK_RA6M2 + make ${MAKEOPTS} -C ports/renesas-ra BOARD=EK_RA6M1 + make ${MAKEOPTS} -C ports/renesas-ra BOARD=EK_RA4M1 + make ${MAKEOPTS} -C ports/renesas-ra BOARD=EK_RA4W1 } ######################################################################################## diff --git a/tools/metrics.py b/tools/metrics.py index da4d188568..13161e9b9a 100755 --- a/tools/metrics.py +++ b/tools/metrics.py @@ -67,7 +67,7 @@ port_data = { "8": PortData("esp8266", "esp8266", "build-GENERIC/firmware.elf"), "3": PortData("esp32", "esp32", "build-GENERIC/micropython.elf"), "x": PortData("mimxrt", "mimxrt", "build-TEENSY40/firmware.elf"), - "e": PortData("renesas-ra", "renesas-ra", "build-RA6M2_EK/firmware.elf"), + "e": PortData("renesas-ra", "renesas-ra", "build-EK_RA6M2/firmware.elf"), "r": PortData("nrf", "nrf", "build-pca10040/firmware.elf"), "p": PortData("rp2", "rp2", "build-PICO/firmware.elf"), "d": PortData("samd", "samd", "build-ADAFRUIT_ITSYBITSY_M4_EXPRESS/firmware.elf"), From 26cc647fcec3bade2a470097e80b6b9c461f650b Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 11:13:31 +1100 Subject: [PATCH 003/565] extmod/utime_mphal: Provide a general mktime function. Signed-off-by: Damien George --- extmod/utime_mphal.c | 21 +++++++++++++++++++++ extmod/utime_mphal.h | 1 + 2 files changed, 22 insertions(+) diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c index 9cd5d938d0..a80c21d9d8 100644 --- a/extmod/utime_mphal.c +++ b/extmod/utime_mphal.c @@ -35,6 +35,27 @@ #include "py/smallint.h" #include "py/runtime.h" #include "extmod/utime_mphal.h" +#include "shared/timeutils/timeutils.h" + +// mktime() +// This is the inverse function of localtime. Its argument is a full 8-tuple +// which expresses a time as per localtime. It returns an integer which is +// the number of seconds since the Epoch (eg 1st Jan 1970, or 1st Jan 2000). +STATIC mp_obj_t time_mktime(mp_obj_t tuple) { + size_t len; + mp_obj_t *elem; + mp_obj_get_array(tuple, &len, &elem); + + // localtime generates a tuple of len 8. CPython uses 9, so we accept both. + if (len < 8 || len > 9) { + mp_raise_TypeError(MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9")); + } + + return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), + mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), + mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); +} +MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_mktime_obj, time_mktime); STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { #if MICROPY_PY_BUILTINS_FLOAT diff --git a/extmod/utime_mphal.h b/extmod/utime_mphal.h index 57fc348832..049e3624d1 100644 --- a/extmod/utime_mphal.h +++ b/extmod/utime_mphal.h @@ -29,6 +29,7 @@ #include "py/obj.h" +MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_mktime_obj); MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_obj); MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj); MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_us_obj); From 083dc1f08296adc8fa80cbc13a18df8cdd526824 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 11:13:43 +1100 Subject: [PATCH 004/565] ports: Use extmod version of mktime instead of port-specific one. Apart from slight differences in the error message, the functionality of all ports is unchanged. Signed-off-by: Damien George --- ports/cc3200/mods/modutime.c | 18 +----------------- ports/esp32/modutime.c | 18 +----------------- ports/esp8266/modutime.c | 22 +--------------------- ports/mimxrt/modutime.c | 22 +--------------------- ports/renesas-ra/modutime.c | 25 +------------------------ ports/rp2/modutime.c | 22 +--------------------- ports/samd/modutime.c | 19 +------------------ ports/stm32/modutime.c | 25 +------------------------ 8 files changed, 8 insertions(+), 163 deletions(-) diff --git a/ports/cc3200/mods/modutime.c b/ports/cc3200/mods/modutime.c index 237a800650..3473d5e7a5 100644 --- a/ports/cc3200/mods/modutime.c +++ b/ports/cc3200/mods/modutime.c @@ -100,22 +100,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - size_t len; - mp_obj_t *elem; - - mp_obj_get_array(tuple, &len, &elem); - - // localtime generates a tuple of len 8. CPython uses 9, so we accept both. - if (len < 8 || len > 9) { - mp_raise_TypeError(MP_ERROR_TEXT("invalid argument(s) num/type")); - } - - return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), - mp_obj_get_int(elem[3]), mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); -} -MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); - STATIC mp_obj_t time_time(void) { return mp_obj_new_int(pyb_rtc_get_seconds()); } @@ -135,7 +119,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&time_sleep_obj) }, diff --git a/ports/esp32/modutime.c b/ports/esp32/modutime.c index 631d0fe299..c3272b3d09 100644 --- a/ports/esp32/modutime.c +++ b/ports/esp32/modutime.c @@ -59,22 +59,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - size_t len; - mp_obj_t *elem; - mp_obj_get_array(tuple, &len, &elem); - - // localtime generates a tuple of len 8. CPython uses 9, so we accept both. - if (len < 8 || len > 9) { - mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9 (%d given)"), len); - } - - return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), - mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), - mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); - STATIC mp_obj_t time_time(void) { struct timeval tv; gettimeofday(&tv, NULL); @@ -87,7 +71,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, diff --git a/ports/esp8266/modutime.c b/ports/esp8266/modutime.c index 08508f8818..5b784a887d 100644 --- a/ports/esp8266/modutime.c +++ b/ports/esp8266/modutime.c @@ -77,26 +77,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -/// \function mktime() -/// This is inverse function of localtime. It's argument is a full 8-tuple -/// which expresses a time as per localtime. It returns an integer which is -/// the number of seconds since Jan 1, 2000. -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - size_t len; - mp_obj_t *elem; - mp_obj_get_array(tuple, &len, &elem); - - // localtime generates a tuple of len 8. CPython uses 9, so we accept both. - if (len < 8 || len > 9) { - mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9 (%d given)"), len); - } - - return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), - mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), - mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); -} -MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); - /// \function time() /// Returns the number of seconds, as an integer, since the Epoch. STATIC mp_obj_t time_time(void) { @@ -110,7 +90,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, diff --git a/ports/mimxrt/modutime.c b/ports/mimxrt/modutime.c index b1defff77b..93a28c84f1 100644 --- a/ports/mimxrt/modutime.c +++ b/ports/mimxrt/modutime.c @@ -70,26 +70,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -// mktime() -// This is inverse function of localtime. It's argument is a full 8-tuple -// which expresses a time as per localtime. It returns an integer which is -// the number of seconds since the Epoch. -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - size_t len; - mp_obj_t *elem; - mp_obj_get_array(tuple, &len, &elem); - - // localtime generates a tuple of len 8. CPython uses 9, so we accept both. - if (len < 8 || len > 9) { - mp_raise_TypeError(MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9")); - } - - return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), - mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), - mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); -} -MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); - // time() // Return the number of seconds since the Epoch. STATIC mp_obj_t time_time(void) { @@ -113,7 +93,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, diff --git a/ports/renesas-ra/modutime.c b/ports/renesas-ra/modutime.c index d0b670df45..ab9da1a720 100644 --- a/ports/renesas-ra/modutime.c +++ b/ports/renesas-ra/modutime.c @@ -95,29 +95,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); - -/// \function mktime() -/// This is inverse function of localtime. It's argument is a full 8-tuple -/// which expresses a time as per localtime. It returns an integer which is -/// the number of seconds since Jan 1, 2000. -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - - size_t len; - mp_obj_t *elem; - - mp_obj_get_array(tuple, &len, &elem); - - // localtime generates a tuple of len 8. CPython uses 9, so we accept both. - if (len < 8 || len > 9) { - mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9 (%d given)"), len); - } - - return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), - mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), - mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); -} -MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); - /// \function time() /// Returns the number of seconds, as an integer, since 1/1/2000. STATIC mp_obj_t time_time(void) { @@ -139,7 +116,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, diff --git a/ports/rp2/modutime.c b/ports/rp2/modutime.c index ac291c8937..a77e936fe1 100644 --- a/ports/rp2/modutime.c +++ b/ports/rp2/modutime.c @@ -69,26 +69,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -// mktime() -// This is inverse function of localtime. It's argument is a full 8-tuple -// which expresses a time as per localtime. It returns an integer which is -// the number of seconds since the Epoch. -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - size_t len; - mp_obj_t *elem; - mp_obj_get_array(tuple, &len, &elem); - - // localtime generates a tuple of len 8. CPython uses 9, so we accept both. - if (len < 8 || len > 9) { - mp_raise_TypeError(MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9")); - } - - return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), - mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), - mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); -} -MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); - // time() // Return the number of seconds since the Epoch. STATIC mp_obj_t time_time(void) { @@ -103,7 +83,7 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, diff --git a/ports/samd/modutime.c b/ports/samd/modutime.c index 6fce203154..9a3a7210ec 100644 --- a/ports/samd/modutime.c +++ b/ports/samd/modutime.c @@ -55,23 +55,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -// mktime() -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - size_t len; - mp_obj_t *elem; - mp_obj_get_array(tuple, &len, &elem); - - // localtime generates a tuple of len 8. CPython uses 9, so we accept both. - if (len < 8 || len > 9) { - mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9 (%d given)"), len); - } - - return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), - mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), - mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); - // time() STATIC mp_obj_t time_time(void) { timeutils_struct_time_t tm; @@ -86,7 +69,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, diff --git a/ports/stm32/modutime.c b/ports/stm32/modutime.c index 72a2be303a..60299582d5 100644 --- a/ports/stm32/modutime.c +++ b/ports/stm32/modutime.c @@ -92,29 +92,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); - -/// \function mktime() -/// This is inverse function of localtime. It's argument is a full 8-tuple -/// which expresses a time as per localtime. It returns an integer which is -/// the number of seconds since Jan 1, 2000. -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { - - size_t len; - mp_obj_t *elem; - - mp_obj_get_array(tuple, &len, &elem); - - // localtime generates a tuple of len 8. CPython uses 9, so we accept both. - if (len < 8 || len > 9) { - mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("mktime needs a tuple of length 8 or 9 (%d given)"), len); - } - - return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]), - mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), - mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); -} -MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); - /// \function time() /// Returns the number of seconds, as an integer, since 1/1/2000. STATIC mp_obj_t time_time(void) { @@ -136,7 +113,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, From 995555300181b3385855f5a4ffb629441553d3ea Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:16:00 +1100 Subject: [PATCH 005/565] extmod/modutime: Provide a generic time module. Based on extmod/utime_mphal.c, with: - a globals dict added - time.localtime wrapper added - time.time wrapper added - time.time_ns function added New configuration options are added for this module: - MICROPY_PY_UTIME (enabled at basic features level) - MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME - MICROPY_PY_UTIME_TIME_TIME_NS Signed-off-by: Damien George --- extmod/extmod.cmake | 2 +- extmod/extmod.mk | 2 +- extmod/{utime_mphal.c => modutime.c} | 124 +++++++++++++++++++++++---- extmod/{utime_mphal.h => modutime.h} | 6 +- ports/cc3200/mods/modutime.c | 2 +- ports/esp32/modutime.c | 2 +- ports/esp8266/modutime.c | 2 +- ports/mimxrt/modutime.c | 2 +- ports/nrf/modules/utime/modutime.c | 2 +- ports/renesas-ra/modutime.c | 2 +- ports/rp2/modutime.c | 2 +- ports/samd/modutime.c | 2 +- ports/stm32/modpyb.c | 2 +- ports/stm32/modutime.c | 2 +- ports/unix/modtime.c | 2 +- ports/webassembly/modutime.c | 2 +- ports/windows/msvc/sources.props | 2 +- ports/zephyr/modutime.c | 2 +- py/mpconfig.h | 17 +++- 19 files changed, 141 insertions(+), 38 deletions(-) rename extmod/{utime_mphal.c => modutime.c} (59%) rename extmod/{utime_mphal.h => modutime.h} (92%) diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index 0e5ed94226..7cf16fa1be 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -33,6 +33,7 @@ set(MICROPY_SOURCE_EXTMOD ${MICROPY_EXTMOD_DIR}/modusocket.c ${MICROPY_EXTMOD_DIR}/modussl_axtls.c ${MICROPY_EXTMOD_DIR}/modussl_mbedtls.c + ${MICROPY_EXTMOD_DIR}/modutime.c ${MICROPY_EXTMOD_DIR}/modutimeq.c ${MICROPY_EXTMOD_DIR}/moduwebsocket.c ${MICROPY_EXTMOD_DIR}/moduzlib.c @@ -42,7 +43,6 @@ set(MICROPY_SOURCE_EXTMOD ${MICROPY_EXTMOD_DIR}/network_ninaw10.c ${MICROPY_EXTMOD_DIR}/network_wiznet5k.c ${MICROPY_EXTMOD_DIR}/uos_dupterm.c - ${MICROPY_EXTMOD_DIR}/utime_mphal.c ${MICROPY_EXTMOD_DIR}/vfs.c ${MICROPY_EXTMOD_DIR}/vfs_blockdev.c ${MICROPY_EXTMOD_DIR}/vfs_fat.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 5aecedc228..9947077a10 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -32,6 +32,7 @@ SRC_EXTMOD_C += \ extmod/modusocket.c \ extmod/modussl_axtls.c \ extmod/modussl_mbedtls.c \ + extmod/modutime.c \ extmod/modutimeq.c \ extmod/moduwebsocket.c \ extmod/moduzlib.c \ @@ -41,7 +42,6 @@ SRC_EXTMOD_C += \ extmod/network_ninaw10.c \ extmod/network_wiznet5k.c \ extmod/uos_dupterm.c \ - extmod/utime_mphal.c \ extmod/vfs.c \ extmod/vfs_blockdev.c \ extmod/vfs_fat.c \ diff --git a/extmod/utime_mphal.c b/extmod/modutime.c similarity index 59% rename from extmod/utime_mphal.c rename to extmod/modutime.c index a80c21d9d8..d82ac6a27c 100644 --- a/extmod/utime_mphal.c +++ b/extmod/modutime.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013-2016 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * Copyright (c) 2016 Paul Sokolovsky * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,18 +25,57 @@ * THE SOFTWARE. */ -#include "py/mpconfig.h" -#if MICROPY_PY_UTIME_MP_HAL - -#include - -#include "py/obj.h" #include "py/mphal.h" -#include "py/smallint.h" #include "py/runtime.h" -#include "extmod/utime_mphal.h" +#include "py/smallint.h" +#include "extmod/modutime.h" + +#if MICROPY_PY_UTIME + +#ifdef MICROPY_PY_UTIME_INCLUDEFILE +#include MICROPY_PY_UTIME_INCLUDEFILE +#endif + +#if MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME + #include "shared/timeutils/timeutils.h" +// localtime([secs]) +// Convert a time expressed in seconds since the Epoch into an 8-tuple which +// contains: (year, month, mday, hour, minute, second, weekday, yearday) +// If secs is not provided or None, then the current time is used. +// - year is the full year, eg 2000 +// - month is 1-12 +// - mday is 1-31 +// - hour is 0-23 +// - minute is 0-59 +// - second is 0-59 +// - weekday is 0-6 for Mon-Sun +// - yearday is 1-366 +STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { + if (n_args == 0 || args[0] == mp_const_none) { + // Get current date and time. + return mp_utime_localtime_get(); + } else { + // Convert given seconds to tuple. + mp_int_t seconds = mp_obj_get_int(args[0]); + timeutils_struct_time_t tm; + timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); + mp_obj_t tuple[8] = { + tuple[0] = mp_obj_new_int(tm.tm_year), + tuple[1] = mp_obj_new_int(tm.tm_mon), + tuple[2] = mp_obj_new_int(tm.tm_mday), + tuple[3] = mp_obj_new_int(tm.tm_hour), + tuple[4] = mp_obj_new_int(tm.tm_min), + tuple[5] = mp_obj_new_int(tm.tm_sec), + tuple[6] = mp_obj_new_int(tm.tm_wday), + tuple[7] = mp_obj_new_int(tm.tm_yday), + }; + return mp_obj_new_tuple(8, tuple); + } +} +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_utime_localtime_obj, 0, 1, time_localtime); + // mktime() // This is the inverse function of localtime. Its argument is a full 8-tuple // which expresses a time as per localtime. It returns an integer which is @@ -57,12 +96,36 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_mktime_obj, time_mktime); +#endif // MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME + +#if MICROPY_PY_UTIME_TIME_TIME_NS + +// time() +// Return the number of seconds since the Epoch. +STATIC mp_obj_t time_time(void) { + return mp_utime_time_get(); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_time_obj, time_time); + +// time_ns() +// Returns the number of nanoseconds since the Epoch, as an integer. +STATIC mp_obj_t time_time_ns(void) { + return mp_obj_new_int_from_ull(mp_hal_time_ns()); +} +MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_time_ns_obj, time_time_ns); + +#endif // MICROPY_PY_UTIME_TIME_TIME_NS + STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { + #ifdef MICROPY_PY_UTIME_CUSTOM_SLEEP + mp_utime_sleep(seconds_o); + #else #if MICROPY_PY_BUILTINS_FLOAT mp_hal_delay_ms((mp_uint_t)(1000 * mp_obj_get_float(seconds_o))); #else mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o)); #endif + #endif return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep); @@ -133,10 +196,41 @@ STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj, time_ticks_add); -// Returns the number of nanoseconds since the Epoch, as an integer. -STATIC mp_obj_t time_time_ns(void) { - return mp_obj_new_int_from_ull(mp_hal_time_ns()); -} -MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_time_ns_obj, time_time_ns); +STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, -#endif // MICROPY_PY_UTIME_MP_HAL + #if MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME + { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mp_utime_localtime_obj) }, + { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mp_utime_localtime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, + #endif + + #if MICROPY_PY_UTIME_TIME_TIME_NS + { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_utime_time_obj) }, + { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, + #endif + + { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, + { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, + { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, + + { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, + + #ifdef MICROPY_PY_UTIME_EXTRA_GLOBALS + MICROPY_PY_UTIME_EXTRA_GLOBALS + #endif +}; +STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); + +const mp_obj_module_t mp_module_utime = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&mp_module_time_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); + +#endif // MICROPY_PY_UTIME diff --git a/extmod/utime_mphal.h b/extmod/modutime.h similarity index 92% rename from extmod/utime_mphal.h rename to extmod/modutime.h index 049e3624d1..2e10afb89b 100644 --- a/extmod/utime_mphal.h +++ b/extmod/modutime.h @@ -24,8 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H -#define MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H +#ifndef MICROPY_INCLUDED_EXTMOD_MODUTIME_H +#define MICROPY_INCLUDED_EXTMOD_MODUTIME_H #include "py/obj.h" @@ -40,4 +40,4 @@ MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj); MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj); MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_time_ns_obj); -#endif // MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H +#endif // MICROPY_INCLUDED_EXTMOD_MODUTIME_H diff --git a/ports/cc3200/mods/modutime.c b/ports/cc3200/mods/modutime.c index 3473d5e7a5..4d9f3a879f 100644 --- a/ports/cc3200/mods/modutime.c +++ b/ports/cc3200/mods/modutime.c @@ -34,7 +34,7 @@ #include "py/smallint.h" #include "py/mphal.h" #include "shared/timeutils/timeutils.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" diff --git a/ports/esp32/modutime.c b/ports/esp32/modutime.c index c3272b3d09..7a0b44d59c 100644 --- a/ports/esp32/modutime.c +++ b/ports/esp32/modutime.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "shared/timeutils/timeutils.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { timeutils_struct_time_t tm; diff --git a/ports/esp8266/modutime.c b/ports/esp8266/modutime.c index 5b784a887d..3220386d6a 100644 --- a/ports/esp8266/modutime.c +++ b/ports/esp8266/modutime.c @@ -35,7 +35,7 @@ #include "shared/timeutils/timeutils.h" #include "modmachine.h" #include "user_interface.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" /// \module time - time related functions /// diff --git a/ports/mimxrt/modutime.c b/ports/mimxrt/modutime.c index 93a28c84f1..8897d3878a 100644 --- a/ports/mimxrt/modutime.c +++ b/ports/mimxrt/modutime.c @@ -27,7 +27,7 @@ #include "py/runtime.h" #include "shared/timeutils/timeutils.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" #include "fsl_snvs_lp.h" // localtime([secs]) diff --git a/ports/nrf/modules/utime/modutime.c b/ports/nrf/modules/utime/modutime.c index efbae3f58a..b43f7f9181 100644 --- a/ports/nrf/modules/utime/modutime.c +++ b/ports/nrf/modules/utime/modutime.c @@ -30,7 +30,7 @@ #include "py/nlr.h" #include "py/smallint.h" #include "py/obj.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" /// \module time - time related functions /// diff --git a/ports/renesas-ra/modutime.c b/ports/renesas-ra/modutime.c index ab9da1a720..374ab12460 100644 --- a/ports/renesas-ra/modutime.c +++ b/ports/renesas-ra/modutime.c @@ -31,7 +31,7 @@ #include "py/smallint.h" #include "py/obj.h" #include "shared/timeutils/timeutils.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" #include "systick.h" #include "rtc.h" diff --git a/ports/rp2/modutime.c b/ports/rp2/modutime.c index a77e936fe1..d3e4bfe826 100644 --- a/ports/rp2/modutime.c +++ b/ports/rp2/modutime.c @@ -26,7 +26,7 @@ #include "py/runtime.h" #include "shared/timeutils/timeutils.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" #include "hardware/rtc.h" // localtime([secs]) diff --git a/ports/samd/modutime.c b/ports/samd/modutime.c index 9a3a7210ec..ee28450868 100644 --- a/ports/samd/modutime.c +++ b/ports/samd/modutime.c @@ -25,7 +25,7 @@ */ #include "py/runtime.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" #include "shared/timeutils/timeutils.h" #include "modmachine.h" diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c index 94aa6e65d1..b148898f16 100644 --- a/ports/stm32/modpyb.c +++ b/ports/stm32/modpyb.c @@ -54,7 +54,7 @@ #include "modmachine.h" #include "extmod/modnetwork.h" #include "extmod/vfs.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" #if MICROPY_PY_PYB diff --git a/ports/stm32/modutime.c b/ports/stm32/modutime.c index 60299582d5..a47f47a51f 100644 --- a/ports/stm32/modutime.c +++ b/ports/stm32/modutime.c @@ -31,7 +31,7 @@ #include "py/smallint.h" #include "py/obj.h" #include "shared/timeutils/timeutils.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" #include "systick.h" #include "portmodules.h" #include "rtc.h" diff --git a/ports/unix/modtime.c b/ports/unix/modtime.c index c9eb09c15b..83cfb26620 100644 --- a/ports/unix/modtime.c +++ b/ports/unix/modtime.c @@ -38,7 +38,7 @@ #include "py/runtime.h" #include "py/smallint.h" #include "py/mphal.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" #ifdef _WIN32 static inline int msec_sleep_tv(struct timeval *tv) { diff --git a/ports/webassembly/modutime.c b/ports/webassembly/modutime.c index 76fe8df374..9042077561 100644 --- a/ports/webassembly/modutime.c +++ b/ports/webassembly/modutime.c @@ -33,7 +33,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "shared/timeutils/timeutils.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, diff --git a/ports/windows/msvc/sources.props b/ports/windows/msvc/sources.props index b755049db0..de950c3ac9 100644 --- a/ports/windows/msvc/sources.props +++ b/ports/windows/msvc/sources.props @@ -17,9 +17,9 @@ + - diff --git a/ports/zephyr/modutime.c b/ports/zephyr/modutime.c index c1c2be1c07..fbcc9c6b09 100644 --- a/ports/zephyr/modutime.c +++ b/ports/zephyr/modutime.c @@ -33,7 +33,7 @@ #include "py/runtime.h" #include "py/smallint.h" #include "py/mphal.h" -#include "extmod/utime_mphal.h" +#include "extmod/modutime.h" STATIC mp_obj_t mod_time_time(void) { /* The absence of FP support is deliberate. The Zephyr port uses diff --git a/py/mpconfig.h b/py/mpconfig.h index 7829cc1266..89fb733e99 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1468,10 +1468,19 @@ typedef double mp_float_t; #define MICROPY_PY_USELECT_SELECT (1) #endif -// Whether to provide "utime" module functions implementation -// in terms of mp_hal_* functions. -#ifndef MICROPY_PY_UTIME_MP_HAL -#define MICROPY_PY_UTIME_MP_HAL (0) +// Whether to provide the "utime" module +#ifndef MICROPY_PY_UTIME +#define MICROPY_PY_UTIME (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_BASIC_FEATURES) +#endif + +// Whether to provide utime.gmtime/localtime/mktime functions +#ifndef MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (0) +#endif + +// Whether to provide utime.time/time_ns functions +#ifndef MICROPY_PY_UTIME_TIME_TIME_NS +#define MICROPY_PY_UTIME_TIME_TIME_NS (0) #endif // Period of values returned by utime.ticks_ms(), ticks_us(), ticks_cpu() From 8ad2da93bed964eced7d4299a2e0b13afede6f8d Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:19:16 +1100 Subject: [PATCH 006/565] cc3200/mods/modutime: Use extmod version of time module. API change: time.time_ns() is added, but it just returns 0. No API or functional change to existing time functions. Signed-off-by: Damien George --- ports/cc3200/application.mk | 1 - ports/cc3200/hal/cc3200_hal.h | 1 + ports/cc3200/mods/modutime.c | 127 +++++----------------------------- ports/cc3200/mpconfigport.h | 5 +- 4 files changed, 24 insertions(+), 110 deletions(-) diff --git a/ports/cc3200/application.mk b/ports/cc3200/application.mk index 97e113b040..78c2b8044a 100644 --- a/ports/cc3200/application.mk +++ b/ports/cc3200/application.mk @@ -81,7 +81,6 @@ APP_MODS_SRC_C = $(addprefix mods/,\ moduos.c \ modusocket.c \ modussl.c \ - modutime.c \ modwipy.c \ modwlan.c \ pybadc.c \ diff --git a/ports/cc3200/hal/cc3200_hal.h b/ports/cc3200/hal/cc3200_hal.h index 3d0d632d51..9e57d39e2e 100644 --- a/ports/cc3200/hal/cc3200_hal.h +++ b/ports/cc3200/hal/cc3200_hal.h @@ -67,3 +67,4 @@ extern void mp_hal_set_interrupt_char (int c); #define mp_hal_stdio_poll(poll_flags) (0) // not implemented #define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec)) #define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet()) +#define mp_hal_time_ns() (0) // not implemented diff --git a/ports/cc3200/mods/modutime.c b/ports/cc3200/mods/modutime.c index 4d9f3a879f..52eb1a6029 100644 --- a/ports/cc3200/mods/modutime.c +++ b/ports/cc3200/mods/modutime.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * Copyright (c) 2015 Daniel Campora * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,119 +25,30 @@ * THE SOFTWARE. */ -#include -#include - -#include "py/mpconfig.h" -#include "py/runtime.h" #include "py/obj.h" -#include "py/smallint.h" -#include "py/mphal.h" #include "shared/timeutils/timeutils.h" -#include "extmod/modutime.h" -#include "inc/hw_types.h" -#include "inc/hw_ints.h" -#include "inc/hw_memmap.h" -#include "rom_map.h" -#include "prcm.h" -#include "systick.h" #include "pybrtc.h" -#include "utils.h" -/// \module time - time related functions -/// -/// The `time` module provides functions for getting the current time and date, -/// and for sleeping. +// Return the localtime as an 8-tuple. +STATIC mp_obj_t mp_utime_localtime_get(void) { + timeutils_struct_time_t tm; -/******************************************************************************/ -// MicroPython bindings - -/// \function localtime([secs]) -/// Convert a time expressed in seconds since Jan 1, 2000 into an 8-tuple which -/// contains: (year, month, mday, hour, minute, second, weekday, yearday) -/// If secs is not provided or None, then the current time from the RTC is used. -/// year includes the century (for example 2015) -/// month is 1-12 -/// mday is 1-31 -/// hour is 0-23 -/// minute is 0-59 -/// second is 0-59 -/// weekday is 0-6 for Mon-Sun. -/// yearday is 1-366 -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { - if (n_args == 0 || args[0] == mp_const_none) { - timeutils_struct_time_t tm; - - // get the seconds from the RTC - timeutils_seconds_since_2000_to_struct_time(pyb_rtc_get_seconds(), &tm); - mp_obj_t tuple[8] = { - mp_obj_new_int(tm.tm_year), - mp_obj_new_int(tm.tm_mon), - mp_obj_new_int(tm.tm_mday), - mp_obj_new_int(tm.tm_hour), - mp_obj_new_int(tm.tm_min), - mp_obj_new_int(tm.tm_sec), - mp_obj_new_int(tm.tm_wday), - mp_obj_new_int(tm.tm_yday) - }; - return mp_obj_new_tuple(8, tuple); - } else { - mp_int_t seconds = mp_obj_get_int(args[0]); - timeutils_struct_time_t tm; - timeutils_seconds_since_2000_to_struct_time(seconds, &tm); - mp_obj_t tuple[8] = { - tuple[0] = mp_obj_new_int(tm.tm_year), - tuple[1] = mp_obj_new_int(tm.tm_mon), - tuple[2] = mp_obj_new_int(tm.tm_mday), - tuple[3] = mp_obj_new_int(tm.tm_hour), - tuple[4] = mp_obj_new_int(tm.tm_min), - tuple[5] = mp_obj_new_int(tm.tm_sec), - tuple[6] = mp_obj_new_int(tm.tm_wday), - tuple[7] = mp_obj_new_int(tm.tm_yday), - }; - return mp_obj_new_tuple(8, tuple); - } + // get the seconds from the RTC + timeutils_seconds_since_2000_to_struct_time(pyb_rtc_get_seconds(), &tm); + mp_obj_t tuple[8] = { + mp_obj_new_int(tm.tm_year), + mp_obj_new_int(tm.tm_mon), + mp_obj_new_int(tm.tm_mday), + mp_obj_new_int(tm.tm_hour), + mp_obj_new_int(tm.tm_min), + mp_obj_new_int(tm.tm_sec), + mp_obj_new_int(tm.tm_wday), + mp_obj_new_int(tm.tm_yday) + }; + return mp_obj_new_tuple(8, tuple); } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -STATIC mp_obj_t time_time(void) { +// Returns the number of seconds, as an integer, since the Epoch. +STATIC mp_obj_t mp_utime_time_get(void) { return mp_obj_new_int(pyb_rtc_get_seconds()); } -MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); - -STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { - int32_t sleep_s = mp_obj_get_int(seconds_o); - if (sleep_s > 0) { - mp_hal_delay_ms(sleep_s * 1000); - } - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep); - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&time_sleep_obj) }, - - // MicroPython additions - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t mp_module_utime = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index 93fc291c1a..cb71a28f34 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -117,7 +117,10 @@ #define MICROPY_PY_UHEAPQ (0) #define MICROPY_PY_UHASHLIB (0) #define MICROPY_PY_USELECT (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME (1) +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/cc3200/mods/modutime.c" #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) From 5be20b67df5d83d2a9b2301e71a769d3932612f8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:20:16 +1100 Subject: [PATCH 007/565] esp32/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/esp32/main/CMakeLists.txt | 1 - ports/esp32/modutime.c | 54 ++++++--------------------------- ports/esp32/mpconfigport.h | 4 ++- 3 files changed, 12 insertions(+), 47 deletions(-) diff --git a/ports/esp32/main/CMakeLists.txt b/ports/esp32/main/CMakeLists.txt index f8acfa9052..964720dd9e 100644 --- a/ports/esp32/main/CMakeLists.txt +++ b/ports/esp32/main/CMakeLists.txt @@ -56,7 +56,6 @@ set(MICROPY_SOURCE_PORT ${PROJECT_DIR}/mphalport.c ${PROJECT_DIR}/fatfs_port.c ${PROJECT_DIR}/help.c - ${PROJECT_DIR}/modutime.c ${PROJECT_DIR}/machine_bitstream.c ${PROJECT_DIR}/machine_timer.c ${PROJECT_DIR}/machine_pin.c diff --git a/ports/esp32/modutime.c b/ports/esp32/modutime.c index 7a0b44d59c..7b833a194d 100644 --- a/ports/esp32/modutime.c +++ b/ports/esp32/modutime.c @@ -5,7 +5,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Damien P. George + * Copyright (c) 2016-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,25 +26,17 @@ * THE SOFTWARE. */ -#include -#include #include -#include "py/runtime.h" +#include "py/obj.h" #include "shared/timeutils/timeutils.h" -#include "extmod/modutime.h" -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { +// Return the localtime as an 8-tuple. +STATIC mp_obj_t mp_utime_localtime_get(void) { + struct timeval tv; + gettimeofday(&tv, NULL); timeutils_struct_time_t tm; - mp_int_t seconds; - if (n_args == 0 || args[0] == mp_const_none) { - struct timeval tv; - gettimeofday(&tv, NULL); - seconds = tv.tv_sec; - } else { - seconds = mp_obj_get_int(args[0]); - } - timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); + timeutils_seconds_since_epoch_to_struct_time(tv.tv_sec, &tm); mp_obj_t tuple[8] = { tuple[0] = mp_obj_new_int(tm.tm_year), tuple[1] = mp_obj_new_int(tm.tm_mon), @@ -57,38 +49,10 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { }; return mp_obj_new_tuple(8, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -STATIC mp_obj_t time_time(void) { +// Return the number of seconds since the Epoch. +STATIC mp_obj_t mp_utime_time_get(void) { struct timeval tv; gettimeofday(&tv, NULL); return mp_obj_new_int(tv.tv_sec); } -MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, - { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t utime_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, utime_module); diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 94daa2caa1..845c7e8fd7 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -62,7 +62,9 @@ #define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (1) #define MICROPY_PY_BUILTINS_HELP_TEXT esp32_help_text #define MICROPY_PY_IO_BUFFEREDWRITER (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/esp32/modutime.c" #define MICROPY_PY_THREAD (1) #define MICROPY_PY_THREAD_GIL (1) #define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32) From 4a4046d8259c0d4088f2e5e3be4f8650fb4c09a1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:20:45 +1100 Subject: [PATCH 008/565] esp8266/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/esp8266/Makefile | 1 - ports/esp8266/boards/esp8266_common.ld | 1 - ports/esp8266/modutime.c | 73 +++----------------------- ports/esp8266/mpconfigport.h | 4 +- 4 files changed, 10 insertions(+), 69 deletions(-) diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile index fb994c752e..3aa9438f6e 100644 --- a/ports/esp8266/Makefile +++ b/ports/esp8266/Makefile @@ -106,7 +106,6 @@ SRC_C = \ machine_wdt.c \ machine_hspi.c \ modesp.c \ - modutime.c \ network_wlan.c \ ets_alt_task.c \ fatfs_port.c \ diff --git a/ports/esp8266/boards/esp8266_common.ld b/ports/esp8266/boards/esp8266_common.ld index bccfaa261f..0fbbf55217 100644 --- a/ports/esp8266/boards/esp8266_common.ld +++ b/ports/esp8266/boards/esp8266_common.ld @@ -164,7 +164,6 @@ SECTIONS *hspi.o(.literal*, .text*) *modesp.o(.literal* .text*) *moduos.o(.literal* .text*) - *modutime.o(.literal* .text*) *modlwip.o(.literal* .text*) *modsocket.o(.literal* .text*) *modonewire.o(.literal* .text*) diff --git a/ports/esp8266/modutime.c b/ports/esp8266/modutime.c index 3220386d6a..b90763371b 100644 --- a/ports/esp8266/modutime.c +++ b/ports/esp8266/modutime.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * Copyright (c) 2015 Josef Gajdusek * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,43 +25,14 @@ * THE SOFTWARE. */ -#include -#include - -#include "py/gc.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "py/smallint.h" +#include "py/obj.h" #include "shared/timeutils/timeutils.h" #include "modmachine.h" -#include "user_interface.h" -#include "extmod/modutime.h" -/// \module time - time related functions -/// -/// The `time` module provides functions for getting the current time and date, -/// and for sleeping. - -/// \function localtime([secs]) -/// Convert a time expressed in seconds since Jan 1, 2000 into an 8-tuple which -/// contains: (year, month, mday, hour, minute, second, weekday, yearday) -/// If secs is not provided or None, then the current time from the RTC is used. -/// year includes the century (for example 2014) -/// month is 1-12 -/// mday is 1-31 -/// hour is 0-23 -/// minute is 0-59 -/// second is 0-59 -/// weekday is 0-6 for Mon-Sun. -/// yearday is 1-366 -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { +// Return the localtime as an 8-tuple. +STATIC mp_obj_t mp_utime_localtime_get(void) { + mp_int_t seconds = pyb_rtc_get_us_since_epoch() / 1000 / 1000; timeutils_struct_time_t tm; - mp_int_t seconds; - if (n_args == 0 || args[0] == mp_const_none) { - seconds = pyb_rtc_get_us_since_epoch() / 1000 / 1000; - } else { - seconds = mp_obj_get_int(args[0]); - } timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); mp_obj_t tuple[8] = { tuple[0] = mp_obj_new_int(tm.tm_year), @@ -75,39 +46,9 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { }; return mp_obj_new_tuple(8, tuple); } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -/// \function time() -/// Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t time_time(void) { +// Returns the number of seconds, as an integer, since the Epoch. +STATIC mp_obj_t mp_utime_time_get(void) { // get date and time return mp_obj_new_int(pyb_rtc_get_us_since_epoch() / 1000 / 1000); } -MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t utime_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, utime_module); diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index 7576c99a87..2111d33e95 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -56,7 +56,9 @@ #define MICROPY_PY_BUILTINS_HELP_TEXT esp_help_text #define MICROPY_PY_UHASHLIB_SHA1 (MICROPY_PY_USSL && MICROPY_SSL_AXTLS) #define MICROPY_PY_URANDOM_SEED_INIT_FUNC (*WDEV_HWRNG) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/esp8266/modutime.c" #define MICROPY_PY_LWIP (1) #define MICROPY_PY_LWIP_SOCK_RAW (1) #define MICROPY_PY_MACHINE (1) From c234a269540b7c5779d4b879b9edb0fdb11202d1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:21:04 +1100 Subject: [PATCH 009/565] mimxrt/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/mimxrt/Makefile | 1 - ports/mimxrt/modutime.c | 92 ++++++++----------------------------- ports/mimxrt/mpconfigport.h | 4 +- 3 files changed, 22 insertions(+), 75 deletions(-) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index 4e4fd17528..d9ab4c859b 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -202,7 +202,6 @@ SRC_C += \ mimxrt_sdram.c \ modmachine.c \ modmimxrt.c \ - modutime.c \ mphalport.c \ mpnetworkport.c \ network_lan.c \ diff --git a/ports/mimxrt/modutime.c b/ports/mimxrt/modutime.c index 8897d3878a..5872e9d8d6 100644 --- a/ports/mimxrt/modutime.c +++ b/ports/mimxrt/modutime.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2019 Damien P. George + * Copyright (c) 2019-2023 Damien P. George * Copyright (c) 2020 Jim Mussared * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,54 +25,30 @@ * THE SOFTWARE. */ -#include "py/runtime.h" +#include "py/obj.h" #include "shared/timeutils/timeutils.h" -#include "extmod/modutime.h" #include "fsl_snvs_lp.h" -// localtime([secs]) -// Convert a time expressed in seconds since the Epoch into an 8-tuple which -// contains: (year, month, mday, hour, minute, second, weekday, yearday) -// If secs is not provided or None, then the current time from the RTC is used. -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { - if (n_args == 0 || args[0] == mp_const_none) { - // Get current date and time. - snvs_lp_srtc_datetime_t t; - SNVS_LP_SRTC_GetDatetime(SNVS, &t); - mp_obj_t tuple[8] = { - mp_obj_new_int(t.year), - mp_obj_new_int(t.month), - mp_obj_new_int(t.day), - mp_obj_new_int(t.hour), - mp_obj_new_int(t.minute), - mp_obj_new_int(t.second), - mp_obj_new_int(timeutils_calc_weekday(t.year, t.month, t.day)), - mp_obj_new_int(timeutils_year_day(t.year, t.month, t.day)), - }; - return mp_obj_new_tuple(8, tuple); - } else { - // Convert given seconds to tuple. - mp_int_t seconds = mp_obj_get_int(args[0]); - timeutils_struct_time_t tm; - timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); - mp_obj_t tuple[8] = { - tuple[0] = mp_obj_new_int(tm.tm_year), - tuple[1] = mp_obj_new_int(tm.tm_mon), - tuple[2] = mp_obj_new_int(tm.tm_mday), - tuple[3] = mp_obj_new_int(tm.tm_hour), - tuple[4] = mp_obj_new_int(tm.tm_min), - tuple[5] = mp_obj_new_int(tm.tm_sec), - tuple[6] = mp_obj_new_int(tm.tm_wday), - tuple[7] = mp_obj_new_int(tm.tm_yday), - }; - return mp_obj_new_tuple(8, tuple); - } +// Return the localtime as an 8-tuple. +STATIC mp_obj_t mp_utime_localtime_get(void) { + // Get current date and time. + snvs_lp_srtc_datetime_t t; + SNVS_LP_SRTC_GetDatetime(SNVS, &t); + mp_obj_t tuple[8] = { + mp_obj_new_int(t.year), + mp_obj_new_int(t.month), + mp_obj_new_int(t.day), + mp_obj_new_int(t.hour), + mp_obj_new_int(t.minute), + mp_obj_new_int(t.second), + mp_obj_new_int(timeutils_calc_weekday(t.year, t.month, t.day)), + mp_obj_new_int(timeutils_year_day(t.year, t.month, t.day)), + }; + return mp_obj_new_tuple(8, tuple); } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -// time() // Return the number of seconds since the Epoch. -STATIC mp_obj_t time_time(void) { +STATIC mp_obj_t mp_utime_time_get(void) { snvs_lp_srtc_datetime_t t; SNVS_LP_SRTC_GetDatetime(SNVS, &t); // EPOCH is 1970 for this port, which leads to the following trouble: @@ -86,33 +62,3 @@ STATIC mp_obj_t time_time(void) { & (t.year < 2000 ? 0xffffffff : 0xffffffffffff) ); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, - - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, - - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t mp_module_utime = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 13b456932c..b1fdf14f22 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -70,7 +70,9 @@ uint32_t trng_random_u32(void); // Extended modules #define MICROPY_EPOCH_IS_1970 (1) #define MICROPY_PY_USSL_FINALISER (MICROPY_PY_USSL) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/mimxrt/modutime.c" #define MICROPY_PY_UOS_INCLUDEFILE "ports/mimxrt/moduos.c" #define MICROPY_PY_OS_DUPTERM (3) #define MICROPY_PY_UOS_DUPTERM_NOTIFY (1) From a3c427898e5ba375b390d80d57d751c4d474dd6f Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:21:18 +1100 Subject: [PATCH 010/565] nrf/modules/utime: Use extmod version of time module. API additions; - time.sleep() is added - time.ticks_cpu() is added, but it just returns 0 No API or functional change to existing time functions. Signed-off-by: Damien George --- ports/nrf/Makefile | 1 - ports/nrf/modules/utime/modutime.c | 58 ------------------------------ ports/nrf/mpconfigport.h | 2 +- 3 files changed, 1 insertion(+), 60 deletions(-) delete mode 100644 ports/nrf/modules/utime/modutime.c diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 54b69b6370..54701adacb 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -331,7 +331,6 @@ DRIVERS_SRC_C += $(addprefix modules/,\ machine/temp.c \ uos/moduos.c \ uos/microbitfs.c \ - utime/modutime.c \ board/modboard.c \ board/led.c \ ubluepy/modubluepy.c \ diff --git a/ports/nrf/modules/utime/modutime.c b/ports/nrf/modules/utime/modutime.c deleted file mode 100644 index b43f7f9181..0000000000 --- a/ports/nrf/modules/utime/modutime.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * - * 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 -#include - -#include "py/nlr.h" -#include "py/smallint.h" -#include "py/obj.h" -#include "extmod/modutime.h" - -/// \module time - time related functions -/// -/// The `time` module provides functions for getting the current time and date, -/// and for sleeping. - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t mp_module_utime = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 8875e3faaf..a3ceb023ee 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -158,7 +158,7 @@ #define MICROPY_PY_SYS_MAXSIZE (1) #define MICROPY_PY_URANDOM (1) #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PULSE (0) #define MICROPY_PY_MACHINE_SOFTI2C (MICROPY_PY_MACHINE_I2C) From 322c53bbc983768b8ee4fa2a3d6ad7f868b543e6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:21:43 +1100 Subject: [PATCH 011/565] renesas-ra/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/renesas-ra/Makefile | 1 - ports/renesas-ra/modutime.c | 130 ++++++-------------------------- ports/renesas-ra/mpconfigport.h | 7 +- 3 files changed, 26 insertions(+), 112 deletions(-) diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index f0b1e1ed75..8dd172b50c 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -318,7 +318,6 @@ SRC_C += \ machine_pin.c \ machine_rtc.c \ modmachine.c \ - modutime.c \ extint.c \ usrsw.c \ flash.c \ diff --git a/ports/renesas-ra/modutime.c b/ports/renesas-ra/modutime.c index 374ab12460..49dcfd589d 100644 --- a/ports/renesas-ra/modutime.c +++ b/ports/renesas-ra/modutime.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,118 +24,34 @@ * THE SOFTWARE. */ -#include -#include - -#include "py/runtime.h" -#include "py/smallint.h" #include "py/obj.h" #include "shared/timeutils/timeutils.h" -#include "extmod/modutime.h" -#include "systick.h" #include "rtc.h" -#if MICROPY_PY_UTIME - -/// \module time - time related functions -/// -/// The `time` module provides functions for getting the current time and date, -/// and for sleeping. - -/// \function localtime([secs]) -/// Convert a time expressed in seconds since Jan 1, 2000 into an 8-tuple which -/// contains: (year, month, mday, hour, minute, second, weekday, yearday) -/// If secs is not provided or None, then the current time from the RTC is used. -/// year includes the century (for example 2014) -/// month is 1-12 -/// mday is 1-31 -/// hour is 0-23 -/// minute is 0-59 -/// second is 0-59 -/// weekday is 0-6 for Mon-Sun. -/// yearday is 1-366 -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { - if (n_args == 0 || args[0] == mp_const_none) { - // get current date and time - // note: need to call get time then get date to correctly access the registers - rtc_init_finalise(); - // RTC_DateTypeDef date; - // RTC_TimeTypeDef time; - // HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN); - // HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN); - ra_rtc_t time; - ra_rtc_get_time(&time); - mp_obj_t tuple[8] = { - mp_obj_new_int(time.year), - mp_obj_new_int(time.month), - mp_obj_new_int(time.date), - mp_obj_new_int(time.hour), - mp_obj_new_int(time.minute), - mp_obj_new_int(time.second), - mp_obj_new_int(time.weekday - 1), - mp_obj_new_int(timeutils_year_day(time.year, time.month, time.date)), - }; - return mp_obj_new_tuple(8, tuple); - } else { - mp_int_t seconds = mp_obj_get_int(args[0]); - timeutils_struct_time_t tm; - timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); - mp_obj_t tuple[8] = { - tuple[0] = mp_obj_new_int(tm.tm_year), - tuple[1] = mp_obj_new_int(tm.tm_mon), - tuple[2] = mp_obj_new_int(tm.tm_mday), - tuple[3] = mp_obj_new_int(tm.tm_hour), - tuple[4] = mp_obj_new_int(tm.tm_min), - tuple[5] = mp_obj_new_int(tm.tm_sec), - tuple[6] = mp_obj_new_int(tm.tm_wday), - tuple[7] = mp_obj_new_int(tm.tm_yday), - }; - return mp_obj_new_tuple(8, tuple); - } -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); - -/// \function time() -/// Returns the number of seconds, as an integer, since 1/1/2000. -STATIC mp_obj_t time_time(void) { - // get date and time - // note: need to call get time then get date to correctly access the registers +// Return the localtime as an 8-tuple. +STATIC mp_obj_t mp_utime_localtime_get(void) { + // get current date and time + rtc_init_finalise(); + ra_rtc_t time; + ra_rtc_get_time(&time); + mp_obj_t tuple[8] = { + mp_obj_new_int(time.year), + mp_obj_new_int(time.month), + mp_obj_new_int(time.date), + mp_obj_new_int(time.hour), + mp_obj_new_int(time.minute), + mp_obj_new_int(time.second), + mp_obj_new_int(time.weekday - 1), + mp_obj_new_int(timeutils_year_day(time.year, time.month, time.date)), + }; + return mp_obj_new_tuple(8, tuple); +} + +// Returns the number of seconds, as an integer, since the Epoch. +STATIC mp_obj_t mp_utime_time_get(void) { + // get date and time rtc_init_finalise(); - // RTC_DateTypeDef date; - // RTC_TimeTypeDef time; - // HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN); - // HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN); ra_rtc_t time; ra_rtc_get_time(&time); return mp_obj_new_int(timeutils_seconds_since_epoch(time.year, time.month, time.date, time.hour, time.minute, time.second)); } -MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, - { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t mp_module_utime = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); - -#endif // MICROPY_PY_UTIME diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index 6d40ac8fac..7dbe941c0e 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -99,10 +99,9 @@ #define MICROPY_PY_UOS_SYNC (1) #define MICROPY_PY_UOS_UNAME (1) #define MICROPY_PY_UOS_URANDOM (MICROPY_HW_ENABLE_RNG) -#ifndef MICROPY_PY_UTIME -#define MICROPY_PY_UTIME (1) -#endif -#define MICROPY_PY_UTIME_MP_HAL (MICROPY_PY_UTIME) +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/renesas-ra/modutime.c" #ifndef MICROPY_PY_UTIMEQ #define MICROPY_PY_UTIMEQ (1) #endif From 67e917609fe10ab84d7d7080047a975d33fbb1ff Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:21:58 +1100 Subject: [PATCH 012/565] rp2/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/rp2/CMakeLists.txt | 2 - ports/rp2/modutime.c | 92 ++++++++-------------------------------- ports/rp2/mpconfigport.h | 4 +- 3 files changed, 21 insertions(+), 77 deletions(-) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 094031c685..501957d20d 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -126,7 +126,6 @@ set(MICROPY_SOURCE_PORT main.c modmachine.c modrp2.c - modutime.c mphalport.c mpnetworkport.c mpthreadport.c @@ -157,7 +156,6 @@ set(MICROPY_SOURCE_QSTR ${PROJECT_SOURCE_DIR}/modmachine.c ${PROJECT_SOURCE_DIR}/modrp2.c ${PROJECT_SOURCE_DIR}/moduos.c - ${PROJECT_SOURCE_DIR}/modutime.c ${PROJECT_SOURCE_DIR}/rp2_flash.c ${PROJECT_SOURCE_DIR}/rp2_pio.c ${CMAKE_BINARY_DIR}/pins_${MICROPY_BOARD}.c diff --git a/ports/rp2/modutime.c b/ports/rp2/modutime.c index d3e4bfe826..9859295d1a 100644 --- a/ports/rp2/modutime.c +++ b/ports/rp2/modutime.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013-2021 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,86 +24,30 @@ * THE SOFTWARE. */ -#include "py/runtime.h" +#include "py/obj.h" #include "shared/timeutils/timeutils.h" -#include "extmod/modutime.h" #include "hardware/rtc.h" -// localtime([secs]) -// Convert a time expressed in seconds since the Epoch into an 8-tuple which -// contains: (year, month, mday, hour, minute, second, weekday, yearday) -// If secs is not provided or None, then the current time from is used. -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { - if (n_args == 0 || args[0] == mp_const_none) { - // Get current date and time. - datetime_t t; - rtc_get_datetime(&t); - mp_obj_t tuple[8] = { - mp_obj_new_int(t.year), - mp_obj_new_int(t.month), - mp_obj_new_int(t.day), - mp_obj_new_int(t.hour), - mp_obj_new_int(t.min), - mp_obj_new_int(t.sec), - mp_obj_new_int(t.dotw), - mp_obj_new_int(timeutils_year_day(t.year, t.month, t.day)), - }; - return mp_obj_new_tuple(8, tuple); - } else { - // Convert given seconds to tuple. - mp_int_t seconds = mp_obj_get_int(args[0]); - timeutils_struct_time_t tm; - timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); - mp_obj_t tuple[8] = { - tuple[0] = mp_obj_new_int(tm.tm_year), - tuple[1] = mp_obj_new_int(tm.tm_mon), - tuple[2] = mp_obj_new_int(tm.tm_mday), - tuple[3] = mp_obj_new_int(tm.tm_hour), - tuple[4] = mp_obj_new_int(tm.tm_min), - tuple[5] = mp_obj_new_int(tm.tm_sec), - tuple[6] = mp_obj_new_int(tm.tm_wday), - tuple[7] = mp_obj_new_int(tm.tm_yday), - }; - return mp_obj_new_tuple(8, tuple); - } +// Return the localtime as an 8-tuple. +STATIC mp_obj_t mp_utime_localtime_get(void) { + datetime_t t; + rtc_get_datetime(&t); + mp_obj_t tuple[8] = { + mp_obj_new_int(t.year), + mp_obj_new_int(t.month), + mp_obj_new_int(t.day), + mp_obj_new_int(t.hour), + mp_obj_new_int(t.min), + mp_obj_new_int(t.sec), + mp_obj_new_int(t.dotw), + mp_obj_new_int(timeutils_year_day(t.year, t.month, t.day)), + }; + return mp_obj_new_tuple(8, tuple); } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -// time() // Return the number of seconds since the Epoch. -STATIC mp_obj_t time_time(void) { +STATIC mp_obj_t mp_utime_time_get(void) { datetime_t t; rtc_get_datetime(&t); return mp_obj_new_int_from_ull(timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); - -STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, - - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, - - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); - -const mp_obj_module_t mp_module_utime = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_time_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index da4548a473..17586e5092 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -105,7 +105,9 @@ #define MICROPY_PY_URE_MATCH_SPAN_START_END (1) #define MICROPY_PY_UHASHLIB_SHA1 (1) #define MICROPY_PY_UCRYPTOLIB (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/rp2/modutime.c" #define MICROPY_PY_URANDOM_SEED_INIT_FUNC (rosc_random_u32()) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new From d7cb53cb606641e0172a334516a279f0615d6fae Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:22:13 +1100 Subject: [PATCH 013/565] samd/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/samd/Makefile | 1 - ports/samd/mcu/samd21/mpconfigmcu.h | 4 ++ ports/samd/modutime.c | 57 ++++++----------------------- ports/samd/mpconfigport.h | 4 +- 4 files changed, 18 insertions(+), 48 deletions(-) diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 465a70a617..290453f50b 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -103,7 +103,6 @@ SRC_C += \ machine_uart.c \ machine_wdt.c \ main.c \ - modutime.c \ modmachine.c \ modsamd.c \ mphalport.c \ diff --git a/ports/samd/mcu/samd21/mpconfigmcu.h b/ports/samd/mcu/samd21/mpconfigmcu.h index 0c5bfe5ae7..df94b9682d 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.h +++ b/ports/samd/mcu/samd21/mpconfigmcu.h @@ -14,6 +14,10 @@ #define MICROPY_PY_BUILTINS_COMPLEX (0) #endif +#ifndef MICROPY_PY_UTIME +#define MICROPY_PY_UTIME (1) +#endif + #ifndef MICROPY_PY_MATH #define MICROPY_PY_MATH (1) #endif diff --git a/ports/samd/modutime.c b/ports/samd/modutime.c index ee28450868..db90a22822 100644 --- a/ports/samd/modutime.c +++ b/ports/samd/modutime.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2019 Damien P. George + * Copyright (c) 2019-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,23 +24,16 @@ * THE SOFTWARE. */ -#include "py/runtime.h" -#include "extmod/modutime.h" +#include "py/obj.h" #include "shared/timeutils/timeutils.h" #include "modmachine.h" -// localtime([secs]) -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { +// Return the localtime as an 8-tuple. +STATIC mp_obj_t mp_utime_localtime_get(void) { timeutils_struct_time_t tm; - mp_int_t seconds; - - if (n_args == 0 || args[0] == mp_const_none) { - rtc_gettime(&tm); - } else { - seconds = mp_obj_get_int(args[0]); - timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); - } - + rtc_gettime(&tm); + tm.tm_wday = timeutils_calc_weekday(tm.tm_year, tm.tm_mon, tm.tm_mday); + tm.tm_yday = timeutils_year_day(tm.tm_year, tm.tm_mon, tm.tm_mday); mp_obj_t tuple[8] = { tuple[0] = mp_obj_new_int(tm.tm_year), tuple[1] = mp_obj_new_int(tm.tm_mon), @@ -48,44 +41,16 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { tuple[3] = mp_obj_new_int(tm.tm_hour), tuple[4] = mp_obj_new_int(tm.tm_min), tuple[5] = mp_obj_new_int(tm.tm_sec), - tuple[6] = mp_obj_new_int(timeutils_calc_weekday(tm.tm_year, tm.tm_mon, tm.tm_mday)), - tuple[7] = mp_obj_new_int(timeutils_year_day(tm.tm_year, tm.tm_mon, tm.tm_mday)), + tuple[6] = mp_obj_new_int(tm.tm_wday), + tuple[7] = mp_obj_new_int(tm.tm_yday), }; return mp_obj_new_tuple(8, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -// time() -STATIC mp_obj_t time_time(void) { +// Returns the number of seconds, as an integer, since the Epoch. +STATIC mp_obj_t mp_utime_time_get(void) { timeutils_struct_time_t tm; rtc_gettime(&tm); return mp_obj_new_int_from_uint(timeutils_mktime( tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t mp_module_utime = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 153ad75820..779bc4713e 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -78,7 +78,9 @@ #define MICROPY_PY_IO_IOBASE (1) // Extended modules -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/samd/modutime.c" #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_UOS (1) #define MICROPY_PY_UOS_INCLUDEFILE "ports/samd/moduos.c" From 996a1f911b403c690c7a7fa6d9b87062ed223390 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:22:30 +1100 Subject: [PATCH 014/565] stm32/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/stm32/Makefile | 1 - ports/stm32/modutime.c | 121 +++++++------------------------------ ports/stm32/mpconfigport.h | 7 +-- ports/stm32/portmodules.h | 1 - 4 files changed, 26 insertions(+), 104 deletions(-) diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 49b5f6f114..e51c0d2713 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -337,7 +337,6 @@ SRC_C += \ modmachine.c \ modpyb.c \ modstm.c \ - modutime.c \ network_lan.c \ extint.c \ usrsw.c \ diff --git a/ports/stm32/modutime.c b/ports/stm32/modutime.c index a47f47a51f..4eda59f81e 100644 --- a/ports/stm32/modutime.c +++ b/ports/stm32/modutime.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,77 +24,34 @@ * THE SOFTWARE. */ -#include -#include - -#include "py/runtime.h" -#include "py/smallint.h" #include "py/obj.h" #include "shared/timeutils/timeutils.h" -#include "extmod/modutime.h" -#include "systick.h" -#include "portmodules.h" #include "rtc.h" -/// \module time - time related functions -/// -/// The `time` module provides functions for getting the current time and date, -/// and for sleeping. - -/// \function localtime([secs]) -/// Convert a time expressed in seconds since Jan 1, 2000 into an 8-tuple which -/// contains: (year, month, mday, hour, minute, second, weekday, yearday) -/// If secs is not provided or None, then the current time from the RTC is used. -/// year includes the century (for example 2014) -/// month is 1-12 -/// mday is 1-31 -/// hour is 0-23 -/// minute is 0-59 -/// second is 0-59 -/// weekday is 0-6 for Mon-Sun. -/// yearday is 1-366 -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { - if (n_args == 0 || args[0] == mp_const_none) { - // get current date and time - // note: need to call get time then get date to correctly access the registers - rtc_init_finalise(); - RTC_DateTypeDef date; - RTC_TimeTypeDef time; - HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN); - HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN); - mp_obj_t tuple[8] = { - mp_obj_new_int(2000 + date.Year), - mp_obj_new_int(date.Month), - mp_obj_new_int(date.Date), - mp_obj_new_int(time.Hours), - mp_obj_new_int(time.Minutes), - mp_obj_new_int(time.Seconds), - mp_obj_new_int(date.WeekDay - 1), - mp_obj_new_int(timeutils_year_day(2000 + date.Year, date.Month, date.Date)), - }; - return mp_obj_new_tuple(8, tuple); - } else { - mp_int_t seconds = mp_obj_get_int(args[0]); - timeutils_struct_time_t tm; - timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); - mp_obj_t tuple[8] = { - tuple[0] = mp_obj_new_int(tm.tm_year), - tuple[1] = mp_obj_new_int(tm.tm_mon), - tuple[2] = mp_obj_new_int(tm.tm_mday), - tuple[3] = mp_obj_new_int(tm.tm_hour), - tuple[4] = mp_obj_new_int(tm.tm_min), - tuple[5] = mp_obj_new_int(tm.tm_sec), - tuple[6] = mp_obj_new_int(tm.tm_wday), - tuple[7] = mp_obj_new_int(tm.tm_yday), - }; - return mp_obj_new_tuple(8, tuple); - } +// Return the localtime as an 8-tuple. +STATIC mp_obj_t mp_utime_localtime_get(void) { + // get current date and time + // note: need to call get time then get date to correctly access the registers + rtc_init_finalise(); + RTC_DateTypeDef date; + RTC_TimeTypeDef time; + HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN); + HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN); + mp_obj_t tuple[8] = { + mp_obj_new_int(2000 + date.Year), + mp_obj_new_int(date.Month), + mp_obj_new_int(date.Date), + mp_obj_new_int(time.Hours), + mp_obj_new_int(time.Minutes), + mp_obj_new_int(time.Seconds), + mp_obj_new_int(date.WeekDay - 1), + mp_obj_new_int(timeutils_year_day(2000 + date.Year, date.Month, date.Date)), + }; + return mp_obj_new_tuple(8, tuple); } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -/// \function time() -/// Returns the number of seconds, as an integer, since 1/1/2000. -STATIC mp_obj_t time_time(void) { +// Returns the number of seconds, as an integer, since 1/1/2000. +STATIC mp_obj_t mp_utime_time_get(void) { // get date and time // note: need to call get time then get date to correctly access the registers rtc_init_finalise(); @@ -104,35 +61,3 @@ STATIC mp_obj_t time_time(void) { HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN); return mp_obj_new_int(timeutils_seconds_since_epoch(2000 + date.Year, date.Month, date.Date, time.Hours, time.Minutes, time.Seconds)); } -MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); - -#if MICROPY_PY_UTIME - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, - { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t mp_module_utime = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); - -#endif // MICROPY_PY_UTIME diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index e3283c8f57..fd5254082d 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -105,10 +105,9 @@ #define MICROPY_PY_UOS_UNAME (1) #define MICROPY_PY_UOS_URANDOM (MICROPY_HW_ENABLE_RNG) #define MICROPY_PY_URANDOM_SEED_INIT_FUNC (rng_get()) -#ifndef MICROPY_PY_UTIME -#define MICROPY_PY_UTIME (1) -#endif -#define MICROPY_PY_UTIME_MP_HAL (MICROPY_PY_UTIME) +#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/stm32/modutime.c" #ifndef MICROPY_PY_UTIMEQ #define MICROPY_PY_UTIMEQ (1) #endif diff --git a/ports/stm32/portmodules.h b/ports/stm32/portmodules.h index f80b4fdf82..f6edef3987 100644 --- a/ports/stm32/portmodules.h +++ b/ports/stm32/portmodules.h @@ -28,7 +28,6 @@ extern const mp_obj_module_t pyb_module; extern const mp_obj_module_t stm_module; -extern const mp_obj_module_t mp_module_utime; extern const mp_obj_module_t mp_module_usocket; // additional helper functions exported by the modules From 127fd170c860b0d04216bc14a41e3adce77c9e31 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 13:43:38 +1100 Subject: [PATCH 015/565] unix/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/unix/Makefile | 1 - ports/unix/{modtime.c => modutime.c} | 46 ++++---------------- ports/unix/variants/mpconfigvariant_common.h | 4 +- ports/windows/Makefile | 1 - ports/windows/micropython.vcxproj | 1 - ports/windows/mpconfigport.h | 4 +- 6 files changed, 14 insertions(+), 43 deletions(-) rename ports/unix/{modtime.c => modutime.c} (81%) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 403405dcc2..d2af8b0871 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -201,7 +201,6 @@ SRC_C += \ mpthreadport.c \ input.c \ modmachine.c \ - modtime.c \ moduselect.c \ alloc.c \ fatfs_port.c \ diff --git a/ports/unix/modtime.c b/ports/unix/modutime.c similarity index 81% rename from ports/unix/modtime.c rename to ports/unix/modutime.c index 83cfb26620..dade99295d 100644 --- a/ports/unix/modtime.c +++ b/ports/unix/modutime.c @@ -4,7 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2014-2017 Paul Sokolovsky - * Copyright (c) 2014-2017 Damien P. George + * Copyright (c) 2014-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,9 +25,6 @@ * THE SOFTWARE. */ -#include "py/mpconfig.h" -#if MICROPY_PY_UTIME - #include #include #include @@ -35,10 +32,8 @@ #include #include -#include "py/runtime.h" -#include "py/smallint.h" #include "py/mphal.h" -#include "extmod/modutime.h" +#include "py/runtime.h" #ifdef _WIN32 static inline int msec_sleep_tv(struct timeval *tv) { @@ -66,7 +61,7 @@ static inline int msec_sleep_tv(struct timeval *tv) { #error Unsupported clock() implementation #endif -STATIC mp_obj_t mod_time_time(void) { +STATIC mp_obj_t mp_utime_time_get(void) { #if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE struct timeval tv; gettimeofday(&tv, NULL); @@ -76,7 +71,6 @@ STATIC mp_obj_t mod_time_time(void) { return mp_obj_new_int((mp_int_t)time(NULL)); #endif } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time); // Note: this is deprecated since CPy3.3, but pystone still uses it. STATIC mp_obj_t mod_time_clock(void) { @@ -91,7 +85,7 @@ STATIC mp_obj_t mod_time_clock(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); -STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) { +STATIC mp_obj_t mp_utime_sleep(mp_obj_t arg) { #if MICROPY_PY_BUILTINS_FLOAT struct timeval tv; mp_float_t val = mp_obj_get_float(arg); @@ -130,7 +124,6 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) { #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep); STATIC mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, struct tm *(*time_func)(const time_t *timep)) { time_t t; @@ -207,31 +200,8 @@ STATIC mp_obj_t mod_time_mktime(mp_obj_t tuple) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_time_mktime_obj, mod_time_mktime); -STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - { MP_ROM_QSTR(MP_QSTR_clock), MP_ROM_PTR(&mod_time_clock_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mod_time_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mod_time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, - { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mod_time_gmtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mod_time_localtime_obj) }, +#define MICROPY_PY_UTIME_EXTRA_GLOBALS \ + { MP_ROM_QSTR(MP_QSTR_clock), MP_ROM_PTR(&mod_time_clock_obj) }, \ + { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mod_time_gmtime_obj) }, \ + { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mod_time_localtime_obj) }, \ { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mod_time_mktime_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); - -const mp_obj_module_t mp_module_time = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_time_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_time); - -#endif // MICROPY_PY_UTIME diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index 1128f21d22..072c4ca490 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -96,7 +96,9 @@ // Enable the unix-specific "time" module. #define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_CUSTOM_SLEEP (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/unix/modutime.c" // Enable the utimeq module used by the previous (v2) version of uasyncio. #define MICROPY_PY_UTIMEQ (1) diff --git a/ports/windows/Makefile b/ports/windows/Makefile index b366e03bf9..489ba15c64 100644 --- a/ports/windows/Makefile +++ b/ports/windows/Makefile @@ -57,7 +57,6 @@ SRC_C = \ ports/unix/main.c \ ports/unix/input.c \ ports/unix/modmachine.c \ - ports/unix/modtime.c \ ports/unix/gccollect.c \ windows_mphal.c \ realpath.c \ diff --git a/ports/windows/micropython.vcxproj b/ports/windows/micropython.vcxproj index 0294b9fa73..de04975cd4 100644 --- a/ports/windows/micropython.vcxproj +++ b/ports/windows/micropython.vcxproj @@ -94,7 +94,6 @@ - diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index 8967242aee..fd3a76408c 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -140,7 +140,9 @@ #define MICROPY_PY_UOS_SYSTEM (1) #define MICROPY_PY_UOS_URANDOM (1) #define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_CUSTOM_SLEEP (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/unix/modutime.c" #define MICROPY_PY_UERRNO (1) #define MICROPY_PY_UCTYPES (1) #define MICROPY_PY_UZLIB (1) From fa8a81ae23dcf0526ce284bea692c3e7a992d525 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:22:44 +1100 Subject: [PATCH 016/565] webassembly/modutime: Use extmod version of time module. No API or functional change. Signed-off-by: Damien George --- ports/webassembly/Makefile | 1 - ports/webassembly/modutime.c | 58 -------------------------------- ports/webassembly/mpconfigport.h | 1 - 3 files changed, 60 deletions(-) delete mode 100644 ports/webassembly/modutime.c diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile index db42d00966..450ef87680 100644 --- a/ports/webassembly/Makefile +++ b/ports/webassembly/Makefile @@ -28,7 +28,6 @@ SRC_SHARED = $(addprefix shared/,\ SRC_C = \ main.c \ mphalport.c \ - modutime.c \ SRC_QSTR += $(SRC_C) $(SRC_SHARED) diff --git a/ports/webassembly/modutime.c b/ports/webassembly/modutime.c deleted file mode 100644 index 9042077561..0000000000 --- a/ports/webassembly/modutime.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George and 2017, 2018 Rami Ali - * - * 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 -#include - -#include "mphalport.h" -#include "py/nlr.h" -#include "py/smallint.h" -#include "py/obj.h" -#include "py/runtime.h" -#include "shared/timeutils/timeutils.h" -#include "extmod/modutime.h" - -STATIC const mp_rom_map_elem_t time_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); - -const mp_obj_module_t mp_module_utime = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&time_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index 46335607e5..e0d1af0cce 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -53,7 +53,6 @@ #define MICROPY_VFS (1) #endif #define MICROPY_VFS_POSIX (MICROPY_VFS) -#define MICROPY_PY_UTIME_MP_HAL (1) #define MICROPY_PY_SYS_PLATFORM "webassembly" #define MICROPY_PY_SYS_STDFILES (0) From 143b863f544f53bbec46e34ad437570bdacaabc0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:22:52 +1100 Subject: [PATCH 017/565] zephyr/modutime: Use extmod version of time module. API change: time.time_ns() is added, but it just returns 0. No API or functional change to existing time functions. Signed-off-by: Damien George --- ports/zephyr/CMakeLists.txt | 1 - ports/zephyr/modutime.c | 35 ++--------------------------------- ports/zephyr/mpconfigport.h | 3 ++- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/ports/zephyr/CMakeLists.txt b/ports/zephyr/CMakeLists.txt index bd5068faf3..39942bdc84 100644 --- a/ports/zephyr/CMakeLists.txt +++ b/ports/zephyr/CMakeLists.txt @@ -44,7 +44,6 @@ set(MICROPY_SOURCE_PORT modbluetooth_zephyr.c modmachine.c modusocket.c - modutime.c modzephyr.c modzsensor.c mphalport.c diff --git a/ports/zephyr/modutime.c b/ports/zephyr/modutime.c index fbcc9c6b09..c02460ba01 100644 --- a/ports/zephyr/modutime.c +++ b/ports/zephyr/modutime.c @@ -25,45 +25,14 @@ * THE SOFTWARE. */ -#include "py/mpconfig.h" -#if MICROPY_PY_UTIME - #include -#include "py/runtime.h" -#include "py/smallint.h" -#include "py/mphal.h" -#include "extmod/modutime.h" +#include "py/obj.h" -STATIC mp_obj_t mod_time_time(void) { +STATIC mp_obj_t mp_utime_time_get(void) { /* The absence of FP support is deliberate. The Zephyr port uses * single precision floats so the fraction component will start to * lose precision on devices with a long uptime. */ return mp_obj_new_int(k_uptime_get() / 1000); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time); - -STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mod_time_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); - -const mp_obj_module_t mp_module_time = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_time_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_time); - -#endif // MICROPY_PY_UTIME diff --git a/ports/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h index 71836768a4..d3ef4375c7 100644 --- a/ports/zephyr/mpconfigport.h +++ b/ports/zephyr/mpconfigport.h @@ -87,7 +87,8 @@ #define MICROPY_PY_UHASHLIB (1) #define MICROPY_PY_UOS (1) #define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIME_MP_HAL (1) +#define MICROPY_PY_UTIME_TIME_TIME_NS (1) +#define MICROPY_PY_UTIME_INCLUDEFILE "ports/zephyr/modutime.c" #define MICROPY_PY_ZEPHYR (1) #define MICROPY_PY_ZSENSOR (1) #define MICROPY_PY_SYS_MODULES (0) From 07a719a315e8ed184513391d337f478ed05a5f82 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2023 12:56:38 +1100 Subject: [PATCH 018/565] tools/ci.sh: Build both SAMD21 and SAMD51 boards as part of samd CI. Signed-off-by: Damien George --- tools/ci.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/ci.sh b/tools/ci.sh index ab1585e5d9..d44f341cef 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -309,7 +309,8 @@ function ci_samd_setup { function ci_samd_build { make ${MAKEOPTS} -C mpy-cross make ${MAKEOPTS} -C ports/samd submodules - make ${MAKEOPTS} -C ports/samd + make ${MAKEOPTS} -C ports/samd BOARD=ADAFRUIT_ITSYBITSY_M0_EXPRESS + make ${MAKEOPTS} -C ports/samd BOARD=ADAFRUIT_ITSYBITSY_M4_EXPRESS } ######################################################################################## From d77c35f110954927ac1f91ce50ca12d81da9df1a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 8 Mar 2023 13:15:25 +1100 Subject: [PATCH 019/565] tools/ci.sh: Add functions to check code spelling using codespell. Signed-off-by: Damien George tools/ci.sh: Explicitly specify pyproject.toml. Signed-off-by: Damien George tools/ci.sh: Import tomli. Signed-off-by: Damien George --- pyproject.toml | 21 +++++++++++++++++++++ tools/ci.sh | 11 +++++++++++ 2 files changed, 32 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..3bc55993a8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[tool.codespell] +count = "" +ignore-regex = '\b[A-Z]{3}\b' +ignore-words-list = "ans,asend,deques,dout,extint,hsi,iput,numer,technic,ure" +quiet-level = 3 +skip = """ +*/build*,\ +./.git,\ +./drivers/cc3100,\ +./lib,\ +./ports/cc3200/FreeRTOS,\ +./ports/cc3200/bootmgr/sl,\ +./ports/cc3200/hal,\ +./ports/cc3200/simplelink,\ +./ports/cc3200/telnet,\ +./ports/nrf/drivers/bluetooth/s1*,\ +./ports/renesas-ra,\ +./ports/stm32/usbhost,\ +./tests,\ +ACKNOWLEDGEMENTS,\ +""" diff --git a/tools/ci.sh b/tools/ci.sh index d44f341cef..0eb94b3399 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -28,6 +28,17 @@ function ci_code_formatting_run { tools/codeformat.py -v } +######################################################################################## +# code spelling + +function ci_code_spell_setup { + pip3 install codespell tomli +} + +function ci_code_spell_run { + codespell +} + ######################################################################################## # commit formatting From e131b53fdfd062699766012165cb2859ffd596ec Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 8 Mar 2023 13:15:40 +1100 Subject: [PATCH 020/565] github/workflows: Add spell check to code formatting workflow. Signed-off-by: Damien George --- .github/workflows/code_formatting.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code_formatting.yml b/.github/workflows/code_formatting.yml index 542edd46cf..81a2715f1b 100644 --- a/.github/workflows/code_formatting.yml +++ b/.github/workflows/code_formatting.yml @@ -7,7 +7,7 @@ concurrency: cancel-in-progress: true jobs: - build: + code-formatting: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 @@ -18,3 +18,13 @@ jobs: run: source tools/ci.sh && ci_code_formatting_run - name: Check code formatting run: git diff --exit-code + + code-spelling: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - name: Install packages + run: source tools/ci.sh && ci_code_spell_setup + - name: Run spell checker + run: source tools/ci.sh && ci_code_spell_run From e160fe7bc64212a3ce56f5478f208e2b4d343a8b Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Mar 2023 09:29:18 +1100 Subject: [PATCH 021/565] tools/pyboard.py: Rename ProcessPtyToTerminal member "ser" to "serial". So that this file doesn't need to be excluded from codespell. Signed-off-by: Damien George --- tools/pyboard.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/pyboard.py b/tools/pyboard.py index c0bb778a32..10cb764b91 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -245,7 +245,7 @@ class ProcessPtyToTerminal: pty = m.group() # rtscts, dsrdtr params are to workaround pyserial bug: # http://stackoverflow.com/questions/34831131/pyserial-does-not-play-well-with-virtual-port - self.ser = serial.Serial(pty, interCharTimeout=1, rtscts=True, dsrdtr=True) + self.serial = serial.Serial(pty, interCharTimeout=1, rtscts=True, dsrdtr=True) def close(self): import signal @@ -253,13 +253,13 @@ class ProcessPtyToTerminal: os.killpg(os.getpgid(self.subp.pid), signal.SIGTERM) def read(self, size=1): - return self.ser.read(size) + return self.serial.read(size) def write(self, data): - return self.ser.write(data) + return self.serial.write(data) def inWaiting(self): - return self.ser.inWaiting() + return self.serial.inWaiting() class Pyboard: From b1229efbd1509654dec6053865ab828d769e29db Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 8 Mar 2023 14:10:02 +1100 Subject: [PATCH 022/565] all: Fix spelling mistakes based on codespell check. Signed-off-by: Damien George --- .github/ISSUE_TEMPLATE/security.md | 2 +- CODECONVENTIONS.md | 2 +- docs/develop/cmodules.rst | 2 +- docs/esp32/tutorial/intro.rst | 8 +++---- docs/esp8266/tutorial/intro.rst | 10 ++++----- docs/esp8266/tutorial/repl.rst | 2 +- docs/library/array.rst | 2 +- docs/library/bluetooth.rst | 2 +- docs/library/esp32.rst | 2 +- docs/library/machine.ADC.rst | 2 +- docs/library/machine.I2C.rst | 2 +- docs/library/machine.I2S.rst | 2 +- docs/library/machine.SPI.rst | 2 +- docs/library/machine.Timer.rst | 2 +- docs/library/os.rst | 2 +- docs/library/pyb.CAN.rst | 2 +- docs/library/pyb.I2C.rst | 2 +- docs/library/sys.rst | 2 +- docs/library/time.rst | 6 ++--- docs/library/zephyr.rst | 2 +- docs/pyboard/tutorial/usb_mouse.rst | 2 +- docs/reference/asm_thumb2_compare.rst | 4 ++-- docs/reference/constrained.rst | 4 ++-- docs/rp2/general.rst | 2 +- docs/rp2/quickref.rst | 2 +- docs/zephyr/tutorial/repl.rst | 2 +- drivers/cyw43/cywbt.c | 2 +- drivers/ninaw10/nina_wifi_drv.c | 2 +- examples/embedding/README.md | 2 +- examples/hwapi/README.md | 2 +- examples/hwapi/hwconfig_pyboard.py | 2 +- examples/natmod/features1/features1.c | 2 +- extmod/btstack/modbluetooth_btstack.c | 2 +- extmod/moduplatform.h | 2 +- extmod/modussl_axtls.c | 2 +- extmod/modussl_mbedtls.c | 4 ++-- extmod/nimble/hal/hal_uart.c | 2 +- extmod/nimble/modbluetooth_nimble.c | 8 +++---- ports/cc3200/bootmgr/main.c | 2 +- ports/cc3200/fatfs/src/drivers/sd_diskio.c | 2 +- ports/cc3200/ftp/ftp.c | 22 +++++++++---------- ports/cc3200/misc/mperror.c | 2 +- ports/cc3200/mods/modwlan.c | 4 ++-- ports/cc3200/mods/pybpin.c | 4 ++-- ports/cc3200/mods/pybrtc.c | 4 ++-- ports/cc3200/mods/pybsd.c | 2 +- ports/cc3200/mods/pybsleep.c | 4 ++-- ports/cc3200/mptask.c | 4 ++-- ports/cc3200/serverstask.c | 2 +- ports/cc3200/telnet/telnet.c | 2 +- ports/cc3200/util/cryptohash.c | 2 +- ports/esp32/machine_pwm.c | 8 +++---- ports/esp8266/esppwm.c | 2 +- ports/esp8266/hspi_register.h | 2 +- ports/esp8266/uart.c | 4 ++-- ports/mimxrt/boards/MIMXRT1176_clock_config.c | 2 +- ports/mimxrt/boards/deploy_teensy.md | 2 +- ports/mimxrt/hal/flexspi_flash_config.h | 6 ++--- ports/mimxrt/hal/fsl_flexspi_nor_boot.h | 2 +- .../phy/device/phydp83825/fsl_phydp83825.h | 2 +- .../phy/device/phydp83848/fsl_phydp83848.h | 2 +- .../phy/device/phyksz8081/fsl_phyksz8081.h | 2 +- .../phy/device/phylan8720/fsl_phylan8720.h | 2 +- .../phy/device/phyrtl8211f/fsl_phyrtl8211f.h | 2 +- ports/mimxrt/hal/phy/fsl_phy.h | 2 +- ports/mimxrt/hal/resethandler_MIMXRT10xx.S | 8 +++---- ports/mimxrt/machine_i2s.c | 2 +- ports/mimxrt/machine_pwm.c | 6 ++--- ports/mimxrt/mphalport.h | 2 +- ports/mimxrt/sdcard.c | 2 +- ports/minimal/stm32f405.ld | 2 +- ports/nrf/README.md | 8 +++---- .../arduino_nano_33_ble_sense/modules/imu.py | 2 +- ports/nrf/boards/make-pins.py | 2 +- .../boards/microbit/modules/microbitimage.c | 4 ++-- ports/nrf/drivers/bluetooth/ble_drv.c | 20 ++++++++--------- ports/nrf/drivers/ticker.c | 2 +- ports/nrf/examples/ubluepy_eddystone.py | 2 +- ports/nrf/examples/ubluepy_temp.py | 2 +- ports/nrf/modules/machine/pin.c | 2 +- ports/nrf/modules/machine/timer.c | 2 +- ports/nrf/modules/ubluepy/modubluepy.h | 2 +- .../nrf/modules/ubluepy/ubluepy_peripheral.c | 4 ++-- .../nrf/modules/ubluepy/ubluepy_scan_entry.c | 2 +- ports/nrf/modules/uos/microbitfs.c | 2 +- ports/powerpc/head.S | 2 +- ports/powerpc/powerpc.lds | 2 +- .../boards/SPARKFUN_THINGPLUS/mpconfigboard.h | 2 +- ports/rp2/boards/make-pins.py | 2 +- ports/rp2/memmap_mp.ld | 2 +- ports/rp2/mpthreadport.c | 2 +- ports/samd/machine_adc.c | 2 +- ports/samd/machine_i2c.c | 6 ++--- ports/samd/machine_uart.c | 2 +- ports/samd/mcu/samd21/clock_config.c | 10 ++++----- ports/samd/mcu/samd21/pin-af-table.csv | 2 +- ports/samd/mcu/samd51/clock_config.c | 6 ++--- ports/samd/mcu/samd51/pin-af-table.csv | 4 ++-- ports/samd/pin_af.c | 6 ++--- .../stm32/boards/ARDUINO_GIGA/mpconfigboard.h | 2 +- .../boards/ARDUINO_NICLA_VISION/board_init.c | 2 +- .../ARDUINO_NICLA_VISION/mpconfigboard.h | 2 +- .../ARDUINO_PORTENTA_H7/mpconfigboard.h | 2 +- .../boards/B_L475E_IOT01A/mpconfigboard.h | 2 +- ports/stm32/boards/LEGO_HUB_NO6/README.md | 2 +- ports/stm32/boards/LEGO_HUB_NO6/appupdate.py | 2 +- .../stm32/boards/LEGO_HUB_NO6/mpconfigboard.h | 2 +- ports/stm32/boards/LEGO_HUB_NO7/README.md | 2 +- .../stm32/boards/LEGO_HUB_NO7/mpconfigboard.h | 2 +- ports/stm32/boards/LIMIFROG/board_init.c | 4 ++-- ports/stm32/boards/common_ifs.ld | 2 +- ports/stm32/boards/make-pins.py | 2 +- ports/stm32/eth.c | 2 +- ports/stm32/machine_spi.c | 2 +- ports/stm32/machine_uart.c | 2 +- ports/stm32/mboot/README.md | 2 +- ports/stm32/mboot/fwupdate.py | 2 +- ports/stm32/mboot/main.c | 6 ++--- ports/stm32/mboot/mboot.h | 2 +- ports/stm32/mboot/mboot_pack_dfu.py | 2 +- ports/stm32/mboot/pack.h | 2 +- ports/stm32/pendsv.c | 2 +- ports/stm32/pin.c | 2 +- ports/stm32/powerctrl.c | 4 ++-- ports/stm32/pyb_can.c | 2 +- ports/stm32/pyb_i2c.c | 2 +- ports/stm32/rfcore.c | 2 +- ports/stm32/sdcard.c | 2 +- ports/stm32/sdram.c | 2 +- ports/stm32/system_stm32.c | 2 +- ports/stm32/systick.c | 2 +- ports/stm32/timer.c | 8 +++---- ports/stm32/usbd_cdc_interface.c | 4 ++-- ports/stm32/usbd_conf.c | 4 ++-- ports/stm32/usbd_desc.c | 4 ++-- .../stm32/usbdev/class/src/usbd_cdc_msc_hid.c | 2 +- ports/stm32/usbdev/class/src/usbd_msc_bot.c | 2 +- ports/stm32/usbdev/core/src/usbd_core.c | 2 +- ports/teensy/core/mk20dx128.c | 2 +- ports/teensy/core/mk20dx128.h | 2 +- ports/teensy/core/usb_desc.c | 4 ++-- ports/teensy/core/usb_desc.h | 2 +- ports/teensy/make-pins.py | 2 +- ports/teensy/modpyb.c | 4 ++-- ports/teensy/timer.c | 6 ++--- ports/unix/coverage.c | 2 +- ports/unix/main.c | 2 +- ports/unix/modtermios.c | 2 +- ports/unix/variants/mpconfigvariant_common.h | 2 +- py/asmbase.c | 2 +- py/asmthumb.c | 2 +- py/compile.c | 2 +- py/emitbc.c | 2 +- py/emitnative.c | 2 +- py/formatfloat.c | 2 +- py/gc.c | 4 ++-- py/makecompresseddata.py | 2 +- py/mkrules.mk | 4 ++-- py/modbuiltins.c | 2 +- py/objexcept.c | 2 +- py/objtype.c | 2 +- py/parse.c | 4 ++-- py/runtime.c | 2 +- py/scope.h | 2 +- py/sequence.c | 2 +- shared/netutils/dhcpserver.c | 4 ++-- shared/runtime/pyexec.c | 2 +- shared/runtime/softtimer.c | 2 +- shared/tinyusb/mp_usbd.c | 2 +- shared/upytesthelper/upytesthelper.c | 2 +- tests/basics/annotate_var.py | 2 +- tests/basics/int_big1.py | 2 +- tests/basics/struct1.py | 2 +- tests/basics/with_return.py | 4 ++-- tests/cpydiff/core_fstring_repr.py | 2 +- tests/cpydiff/core_import_path.py | 2 +- tests/cpydiff/core_import_split_ns_pkgs.py | 2 +- tests/extmod/framebuf_palette.py | 2 +- tests/extmod/uctypes_sizeof_layout.py | 2 +- tests/extmod/utimeq1.py | 2 +- tests/feature_check/README | 2 +- tests/misc/non_compliant.py | 2 +- tests/net_hosted/README | 2 +- tests/net_inet/README | 2 +- tests/thread/thread_lock1.py | 2 +- tests/wipy/uart.py | 2 +- tools/ci.sh | 2 +- tools/mpremote/mpremote/commands.py | 2 +- tools/pydfu.py | 2 +- tools/uncrustify.cfg | 14 ++++++------ tools/verifygitlog.py | 2 +- 191 files changed, 282 insertions(+), 282 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/security.md b/.github/ISSUE_TEMPLATE/security.md index 2bbfede6ce..cfe4a4befd 100644 --- a/.github/ISSUE_TEMPLATE/security.md +++ b/.github/ISSUE_TEMPLATE/security.md @@ -1,6 +1,6 @@ --- name: Security report -about: Report a security issue or vunerability in MicroPython +about: Report a security issue or vulnerability in MicroPython title: '' labels: security assignees: '' diff --git a/CODECONVENTIONS.md b/CODECONVENTIONS.md index 3b678bfeb8..6ab3324c2e 100644 --- a/CODECONVENTIONS.md +++ b/CODECONVENTIONS.md @@ -255,7 +255,7 @@ Documentation conventions ========================= MicroPython generally follows CPython in documentation process and -conventions. reStructuredText syntax is used for the documention. +conventions. reStructuredText syntax is used for the documentation. Specific conventions/suggestions: diff --git a/docs/develop/cmodules.rst b/docs/develop/cmodules.rst index 6bc2f62ab4..75dbc953c0 100644 --- a/docs/develop/cmodules.rst +++ b/docs/develop/cmodules.rst @@ -53,7 +53,7 @@ A MicroPython user C module is a directory with the following files: ``SRC_USERMOD_C`` or ``SRC_USERMOD_LIB_C`` variables. The former will be processed for ``MP_QSTR_`` and ``MP_REGISTER_MODULE`` definitions, the latter will not (e.g. helpers and library code that isn't MicroPython-specific). - These paths should include your expaned copy of ``$(USERMOD_DIR)``, e.g.:: + These paths should include your expanded copy of ``$(USERMOD_DIR)``, e.g.:: SRC_USERMOD_C += $(EXAMPLE_MOD_DIR)/modexample.c SRC_USERMOD_LIB_C += $(EXAMPLE_MOD_DIR)/utils/algorithm.c diff --git a/docs/esp32/tutorial/intro.rst b/docs/esp32/tutorial/intro.rst index 8ed42dbd3d..be09599871 100644 --- a/docs/esp32/tutorial/intro.rst +++ b/docs/esp32/tutorial/intro.rst @@ -17,7 +17,7 @@ Requirements The first thing you need is a board with an ESP32 chip. The MicroPython software supports the ESP32 chip itself and any board should work. The main characteristic of a board is how the GPIO pins are connected to the outside -world, and whether it includes a built-in USB-serial convertor to make the +world, and whether it includes a built-in USB-serial converter to make the UART available to your PC. Names of pins will be given in this tutorial using the chip names (eg GPIO2) @@ -59,7 +59,7 @@ bootloader mode, and second you need to copy across the firmware. The exact procedure for these steps is highly dependent on the particular board and you will need to refer to its documentation for details. -Fortunately, most boards have a USB connector, a USB-serial convertor, and the DTR +Fortunately, most boards have a USB connector, a USB-serial converter, and the DTR and RTS pins wired in a special way then deploying the firmware should be easy as all steps can be done automatically. Boards that have such features include the Adafruit Feather HUZZAH32, M5Stack, Wemos LOLIN32, and TinyPICO @@ -104,7 +104,7 @@ Serial prompt Once you have the firmware on the device you can access the REPL (Python prompt) over UART0 (GPIO1=TX, GPIO3=RX), which might be connected to a USB-serial -convertor, depending on your board. The baudrate is 115200. +converter, depending on your board. The baudrate is 115200. From here you can now follow the ESP8266 tutorial, because these two Espressif chips are very similar when it comes to using MicroPython on them. The ESP8266 tutorial @@ -124,7 +124,7 @@ after it, here are troubleshooting recommendations: * The flashing instructions above use flashing speed of 460800 baud, which is good compromise between speed and stability. However, depending on your - module/board, USB-UART convertor, cables, host OS, etc., the above baud + module/board, USB-UART converter, cables, host OS, etc., the above baud rate may be too high and lead to errors. Try a more common 115200 baud rate instead in such cases. diff --git a/docs/esp8266/tutorial/intro.rst b/docs/esp8266/tutorial/intro.rst index 75739bd6f9..0d4bc42e2d 100644 --- a/docs/esp8266/tutorial/intro.rst +++ b/docs/esp8266/tutorial/intro.rst @@ -18,7 +18,7 @@ The first thing you need is a board with an ESP8266 chip. The MicroPython software supports the ESP8266 chip itself and any board should work. The main characteristic of a board is how much flash it has, how the GPIO pins are connected to the outside world, and whether it includes a built-in USB-serial -convertor to make the UART available to your PC. +converter to make the UART available to your PC. The minimum requirement for flash size is 1Mbyte. There is also a special build for boards with 512KB, but it is highly limited comparing to the @@ -70,7 +70,7 @@ need to put your device in boot-loader mode, and second you need to copy across the firmware. The exact procedure for these steps is highly dependent on the particular board and you will need to refer to its documentation for details. -If you have a board that has a USB connector, a USB-serial convertor, and has +If you have a board that has a USB connector, a USB-serial converter, and has the DTR and RTS pins wired in a special way then deploying the firmware should be easy as all steps can be done automatically. Boards that have such features include the Adafruit Feather HUZZAH and NodeMCU boards. @@ -128,7 +128,7 @@ Serial prompt Once you have the firmware on the device you can access the REPL (Python prompt) over UART0 (GPIO1=TX, GPIO3=RX), which might be connected to a USB-serial -convertor, depending on your board. The baudrate is 115200. The next part of +converter, depending on your board. The baudrate is 115200. The next part of the tutorial will discuss the prompt in more detail. WiFi @@ -137,7 +137,7 @@ WiFi After a fresh install and boot the device configures itself as a WiFi access point (AP) that you can connect to. The ESSID is of the form MicroPython-xxxxxx where the x's are replaced with part of the MAC address of your device (so will -be the same everytime, and most likely different for all ESP8266 chips). The +be the same every time, and most likely different for all ESP8266 chips). The password for the WiFi is micropythoN (note the upper-case N). Its IP address will be 192.168.4.1 once you connect to its network. WiFi configuration will be discussed in more detail later in the tutorial. @@ -169,7 +169,7 @@ after it, here are troubleshooting recommendations: * The flashing instructions above use flashing speed of 460800 baud, which is good compromise between speed and stability. However, depending on your - module/board, USB-UART convertor, cables, host OS, etc., the above baud + module/board, USB-UART converter, cables, host OS, etc., the above baud rate may be too high and lead to errors. Try a more common 115200 baud rate instead in such cases. diff --git a/docs/esp8266/tutorial/repl.rst b/docs/esp8266/tutorial/repl.rst index 196541bd02..bc0142aaef 100644 --- a/docs/esp8266/tutorial/repl.rst +++ b/docs/esp8266/tutorial/repl.rst @@ -13,7 +13,7 @@ REPL over the serial port The REPL is always available on the UART0 serial peripheral, which is connected to the pins GPIO1 for TX and GPIO3 for RX. The baudrate of the REPL is 115200. -If your board has a USB-serial convertor on it then you should be able to access +If your board has a USB-serial converter on it then you should be able to access the REPL directly from your PC. Otherwise you will need to have a way of communicating with the UART. diff --git a/docs/library/array.rst b/docs/library/array.rst index f94cece2b7..f417a7046e 100644 --- a/docs/library/array.rst +++ b/docs/library/array.rst @@ -75,7 +75,7 @@ Classes Returns the string representation of the array, called as ``str(a)`` or ``repr(a)``` (where ``a`` is an ``array``). Returns the string ``"array(, [])"``, where ```` is the type code letter for the array and ```` is a comma - seperated list of the elements of the array. + separated list of the elements of the array. **Note:** ``__repr__`` cannot be called directly (``a.__repr__()`` fails) and is not present in ``__dict__``, however ``str(a)`` and ``repr(a)`` both work. diff --git a/docs/library/bluetooth.rst b/docs/library/bluetooth.rst index dd0f5ffd62..78cb4cc281 100644 --- a/docs/library/bluetooth.rst +++ b/docs/library/bluetooth.rst @@ -44,7 +44,7 @@ Configuration Get or set configuration values of the BLE interface. To get a value the parameter name should be quoted as a string, and just one parameter is - queried at a time. To set values use the keyword syntax, and one ore more + queried at a time. To set values use the keyword syntax, and one or more parameter can be set at a time. Currently supported values are: diff --git a/docs/library/esp32.rst b/docs/library/esp32.rst index f0f0c8ef1f..12d0890217 100644 --- a/docs/library/esp32.rst +++ b/docs/library/esp32.rst @@ -126,7 +126,7 @@ methods to enable over-the-air (OTA) updates. and an ``OSError(-261)`` is raised if called on firmware that doesn't have the feature enabled. It is OK to call ``mark_app_valid_cancel_rollback`` on every boot and it is not - necessary when booting firmare that was loaded using esptool. + necessary when booting firmware that was loaded using esptool. Constants ~~~~~~~~~ diff --git a/docs/library/machine.ADC.rst b/docs/library/machine.ADC.rst index eb538a4424..65225ea878 100644 --- a/docs/library/machine.ADC.rst +++ b/docs/library/machine.ADC.rst @@ -4,7 +4,7 @@ class ADC -- analog to digital conversion ========================================= -The ADC class provides an interface to analog-to-digital convertors, and +The ADC class provides an interface to analog-to-digital converters, and represents a single endpoint that can sample a continuous voltage and convert it to a discretised value. diff --git a/docs/library/machine.I2C.rst b/docs/library/machine.I2C.rst index bfc9f7ebcc..635d587344 100644 --- a/docs/library/machine.I2C.rst +++ b/docs/library/machine.I2C.rst @@ -94,7 +94,7 @@ General Methods - *freq* is the SCL clock rate In the case of hardware I2C the actual clock frequency may be lower than the - requested frequency. This is dependant on the platform hardware. The actual + requested frequency. This is dependent on the platform hardware. The actual rate may be determined by printing the I2C object. .. method:: I2C.deinit() diff --git a/docs/library/machine.I2S.rst b/docs/library/machine.I2S.rst index b602ac6504..2244ef4202 100644 --- a/docs/library/machine.I2S.rst +++ b/docs/library/machine.I2S.rst @@ -103,7 +103,7 @@ Constructor - ``ibuf`` specifies internal buffer length (bytes) For all ports, DMA runs continuously in the background and allows user applications to perform other operations while - sample data is transfered between the internal buffer and the I2S peripheral unit. + sample data is transferred between the internal buffer and the I2S peripheral unit. Increasing the size of the internal buffer has the potential to increase the time that user applications can perform non-I2S operations before underflow (e.g. ``write`` method) or overflow (e.g. ``readinto`` method). diff --git a/docs/library/machine.SPI.rst b/docs/library/machine.SPI.rst index 7b0e8cf406..7c3c4b5832 100644 --- a/docs/library/machine.SPI.rst +++ b/docs/library/machine.SPI.rst @@ -98,7 +98,7 @@ Methods specify them as a tuple of ``pins`` parameter. In the case of hardware SPI the actual clock frequency may be lower than the - requested baudrate. This is dependant on the platform hardware. The actual + requested baudrate. This is dependent on the platform hardware. The actual rate may be determined by printing the SPI object. .. method:: SPI.deinit() diff --git a/docs/library/machine.Timer.rst b/docs/library/machine.Timer.rst index 48c023a11c..44e6594080 100644 --- a/docs/library/machine.Timer.rst +++ b/docs/library/machine.Timer.rst @@ -73,7 +73,7 @@ Methods - ``callback`` - The callable to call upon expiration of the timer period. The callback must take one argument, which is passed the Timer object. The ``callback`` argument shall be specified. Otherwise an exception - will occurr upon timer expiration: + will occur upon timer expiration: ``TypeError: 'NoneType' object isn't callable`` .. method:: Timer.deinit() diff --git a/docs/library/os.rst b/docs/library/os.rst index 19652ee2bc..27a7d2d44a 100644 --- a/docs/library/os.rst +++ b/docs/library/os.rst @@ -86,7 +86,7 @@ Filesystem access .. function:: statvfs(path) - Get the status of a fileystem. + Get the status of a filesystem. Returns a tuple with the filesystem information in the following order: diff --git a/docs/library/pyb.CAN.rst b/docs/library/pyb.CAN.rst index 5ca00b65e5..57a85d54b7 100644 --- a/docs/library/pyb.CAN.rst +++ b/docs/library/pyb.CAN.rst @@ -272,7 +272,7 @@ Methods - *fdf* for CAN FD controllers, if set to True, the frame will have an FD frame format, which supports data payloads up to 64 bytes. - *brs* for CAN FD controllers, if set to True, the bitrate switching mode - is enabled, in which the data phase is transmitted at a differet bitrate. + is enabled, in which the data phase is transmitted at a different bitrate. See :meth:`CAN.init` for the data bit timing configuration parameters. If timeout is 0 the message is placed in a buffer in one of three hardware diff --git a/docs/library/pyb.I2C.rst b/docs/library/pyb.I2C.rst index 2c526854aa..71d043aa6d 100644 --- a/docs/library/pyb.I2C.rst +++ b/docs/library/pyb.I2C.rst @@ -97,7 +97,7 @@ Methods errors properly) The actual clock frequency may be lower than the requested frequency. - This is dependant on the platform hardware. The actual rate may be determined + This is dependent on the platform hardware. The actual rate may be determined by printing the I2C object. .. method:: I2C.is_ready(addr) diff --git a/docs/library/sys.rst b/docs/library/sys.rst index 3efdce964c..c8eb4b5c50 100644 --- a/docs/library/sys.rst +++ b/docs/library/sys.rst @@ -46,7 +46,7 @@ Functions .. function:: settrace(tracefunc) Enable tracing of bytecode execution. For details see the `CPython - documentaion `_. + documentation `_. This function requires a custom MicroPython build as it is typically not present in pre-built firmware (due to it affecting performance). The relevant diff --git a/docs/library/time.rst b/docs/library/time.rst index 3ab5caf248..8c1c1d4d6f 100644 --- a/docs/library/time.rst +++ b/docs/library/time.rst @@ -163,8 +163,8 @@ Functions However, values returned by `ticks_ms()`, etc. functions may wrap around, so directly using subtraction on them will produce incorrect result. That is why `ticks_diff()` is needed, it implements modular (or more specifically, ring) - arithmetics to produce correct result even for wrap-around values (as long as they not - too distant inbetween, see below). The function returns **signed** value in the range + arithmetic to produce correct result even for wrap-around values (as long as they not + too distant in between, see below). The function returns **signed** value in the range [*-TICKS_PERIOD/2* .. *TICKS_PERIOD/2-1*] (that's a typical range definition for two's-complement signed binary integers). If the result is negative, it means that *ticks1* occurred earlier in time than *ticks2*. Otherwise, it means that @@ -183,7 +183,7 @@ Functions has passed. To avoid this mistake, just look at the clock regularly. Your application should do the same. "Too long sleep" metaphor also maps directly to application behaviour: don't let your application run any single task for too long. Run tasks - in steps, and do time-keeping inbetween. + in steps, and do time-keeping in between. `ticks_diff()` is designed to accommodate various usage patterns, among them: diff --git a/docs/library/zephyr.rst b/docs/library/zephyr.rst index da3d14a093..10676d9085 100644 --- a/docs/library/zephyr.rst +++ b/docs/library/zephyr.rst @@ -32,7 +32,7 @@ Functions * *CPU utilization is only printed if runtime statistics are configured via the ``CONFIG_THREAD_RUNTIME_STATS`` kconfig* This function can only be accessed if ``CONFIG_THREAD_ANALYZER`` is configured for the port in ``zephyr/prj.conf``. - For more infomation, see documentation for Zephyr `thread analyzer + For more information, see documentation for Zephyr `thread analyzer `_. .. function:: shell_exec(cmd_in) diff --git a/docs/pyboard/tutorial/usb_mouse.rst b/docs/pyboard/tutorial/usb_mouse.rst index d05b16ed5c..31b463668f 100644 --- a/docs/pyboard/tutorial/usb_mouse.rst +++ b/docs/pyboard/tutorial/usb_mouse.rst @@ -120,7 +120,7 @@ minus sign in front of the y-coordinate in the ``hid.send()`` line above. Restoring your pyboard to normal -------------------------------- -If you leave your pyboard as-is, it'll behave as a mouse everytime you plug +If you leave your pyboard as-is, it'll behave as a mouse every time you plug it in. You probably want to change it back to normal. To do this you need to first enter safe mode (see above), and then edit the ``boot.py`` file. In the ``boot.py`` file, comment out (put a # in front of) the line with the diff --git a/docs/reference/asm_thumb2_compare.rst b/docs/reference/asm_thumb2_compare.rst index 521af69da3..5258195503 100644 --- a/docs/reference/asm_thumb2_compare.rst +++ b/docs/reference/asm_thumb2_compare.rst @@ -75,7 +75,7 @@ Execute the next instruction if is true: * ite() If then else -If is true, execute the next instruction, otherwise execute the +If is true, execute the next instruction, otherwise execute the subsequent one. Thus: :: @@ -86,5 +86,5 @@ subsequent one. Thus: mov(r0, 200) # runs if r0 != r1 # execution continues here -This may be extended to control the execution of upto four subsequent instructions: it[x[y[z]]] +This may be extended to control the execution of up to four subsequent instructions: it[x[y[z]]] where x,y,z=t/e; e.g. itt, itee, itete, ittte, itttt, iteee, etc. diff --git a/docs/reference/constrained.rst b/docs/reference/constrained.rst index 2bcf9f7fb7..59c375159b 100644 --- a/docs/reference/constrained.rst +++ b/docs/reference/constrained.rst @@ -264,7 +264,7 @@ were a string. **Runtime compiler execution** -The Python funcitons `eval` and `exec` invoke the compiler at runtime, which +The Python functions `eval` and `exec` invoke the compiler at runtime, which requires significant amounts of RAM. Note that the ``pickle`` library from `micropython-lib` employs `exec`. It may be more RAM efficient to use the `json` library for object serialisation. @@ -403,7 +403,7 @@ Control of garbage collection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A GC can be demanded at any time by issuing `gc.collect()`. It is advantageous -to do this at intervals, firstly to pre-empt fragmentation and secondly for +to do this at intervals, firstly to preempt fragmentation and secondly for performance. A GC can take several milliseconds but is quicker when there is little work to do (about 1ms on the Pyboard). An explicit call can minimise that delay while ensuring it occurs at points in the program when it is acceptable. diff --git a/docs/rp2/general.rst b/docs/rp2/general.rst index 6a8958d172..05b44f051e 100644 --- a/docs/rp2/general.rst +++ b/docs/rp2/general.rst @@ -30,7 +30,7 @@ The peripherals include: * 2 UARTs * 2 SPI controllers -* 2 I2C contollers +* 2 I2C controllers * 16 PWM channels * USB 1.1 controller * 8 PIO state machines diff --git a/docs/rp2/quickref.rst b/docs/rp2/quickref.rst index 430c130c6e..67a5cc0dfc 100644 --- a/docs/rp2/quickref.rst +++ b/docs/rp2/quickref.rst @@ -96,7 +96,7 @@ Programmable IO (PIO) --------------------- PIO is useful to build low-level IO interfaces from scratch. See the :mod:`rp2` module -for detailed explaination of the assembly instructions. +for detailed explanation of the assembly instructions. Example using PIO to blink an LED at 1Hz:: diff --git a/docs/zephyr/tutorial/repl.rst b/docs/zephyr/tutorial/repl.rst index 8cd57c9435..2c091f7ee9 100644 --- a/docs/zephyr/tutorial/repl.rst +++ b/docs/zephyr/tutorial/repl.rst @@ -10,7 +10,7 @@ REPL over the serial port The REPL is available on a UART serial peripheral specified for the board by the ``zephyr,console`` devicetree node. The baudrate of the REPL is 115200. -If your board has a USB-serial convertor on it then you should be able to access +If your board has a USB-serial converter on it then you should be able to access the REPL directly from your PC. To access the prompt over USB-serial you will need to use a terminal emulator diff --git a/drivers/cyw43/cywbt.c b/drivers/cyw43/cywbt.c index 33e749bbf9..006fd28e90 100644 --- a/drivers/cyw43/cywbt.c +++ b/drivers/cyw43/cywbt.c @@ -67,7 +67,7 @@ STATIC int cywbt_hci_cmd_raw(size_t len, uint8_t *buf) { buf[i] = uart_rx_char(&mp_bluetooth_hci_uart_obj); } - // expect a comand complete event (event 0x0e) + // expect a command complete event (event 0x0e) if (buf[0] != 0x04 || buf[1] != 0x0e) { printf("unknown response: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]); return -1; diff --git a/drivers/ninaw10/nina_wifi_drv.c b/drivers/ninaw10/nina_wifi_drv.c index 22ad0aae70..111ead003d 100644 --- a/drivers/ninaw10/nina_wifi_drv.c +++ b/drivers/ninaw10/nina_wifi_drv.c @@ -105,7 +105,7 @@ typedef enum { NINA_CMD_AP_GET_BSSID = 0x3C, NINA_CMD_AP_GET_CHANNEL = 0x3D, - // Disonnect/status commands. + // Disconnect/status commands. NINA_CMD_DISCONNECT = 0x30, NINA_CMD_CONN_STATUS = 0x20, NINA_CMD_CONN_REASON = 0x1F, diff --git a/examples/embedding/README.md b/examples/embedding/README.md index e3683acdc2..3f19aff41f 100644 --- a/examples/embedding/README.md +++ b/examples/embedding/README.md @@ -23,7 +23,7 @@ To build the example project, based on `main.c`, use: $ make -That will create an exacutable called `embed` which you can run: +That will create an executable called `embed` which you can run: $ ./embed diff --git a/examples/hwapi/README.md b/examples/hwapi/README.md index df16b4c86b..f3de752f9c 100644 --- a/examples/hwapi/README.md +++ b/examples/hwapi/README.md @@ -5,7 +5,7 @@ which would work from a board to board, from a system to another systems. This is inherently a hard problem, because hardware is different from one board type to another, and even from examplar of board to another. For example, if your app requires an external LED, one user may connect it -to one GPIO pin, while another user may find it much more convinient to +to one GPIO pin, while another user may find it much more convenient to use another pin. This of course applies to relays, buzzers, sensors, etc. With complications above in mind, it's still possible to write portable diff --git a/examples/hwapi/hwconfig_pyboard.py b/examples/hwapi/hwconfig_pyboard.py index a74a1ae151..cb77e9f2d6 100644 --- a/examples/hwapi/hwconfig_pyboard.py +++ b/examples/hwapi/hwconfig_pyboard.py @@ -1,6 +1,6 @@ from machine import Pin, Signal -# Red LED on pin LED_RED also kown as A13 +# Red LED on pin LED_RED also known as A13 LED = Signal("LED_RED", Pin.OUT) # Green LED on pin LED_GREEN also known as A14 diff --git a/examples/natmod/features1/features1.c b/examples/natmod/features1/features1.c index f865f1887c..d2494b2138 100644 --- a/examples/natmod/features1/features1.c +++ b/examples/natmod/features1/features1.c @@ -88,7 +88,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a // This must be first, it sets up the globals dict and other things MP_DYNRUNTIME_INIT_ENTRY - // Messages can be printed as usualy + // Messages can be printed as usual mp_printf(&mp_plat_print, "initialising module self=%p\n", self); // Make the functions available in the module's namespace diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c index 0e29c38efd..183c85a445 100644 --- a/extmod/btstack/modbluetooth_btstack.c +++ b/extmod/btstack/modbluetooth_btstack.c @@ -883,7 +883,7 @@ int mp_bluetooth_gatts_register_service_begin(bool append) { if (!append) { // This will reset the DB. - // Becase the DB is statically allocated, there's no problem with just re-initing it. + // Because the DB is statically allocated, there's no problem with just re-initing it. // Note this would be a memory leak if we enabled HAVE_MALLOC (there's no API to free the existing db). att_db_util_init(); diff --git a/extmod/moduplatform.h b/extmod/moduplatform.h index 42ed4de248..3597f7559f 100644 --- a/extmod/moduplatform.h +++ b/extmod/moduplatform.h @@ -29,7 +29,7 @@ #include "py/misc.h" // For MP_STRINGIFY. #include "py/mpconfig.h" -// Preprocessor directives indentifying the platform. +// Preprocessor directives identifying the platform. // The (u)platform module itself is guarded by MICROPY_PY_UPLATFORM, see the // .c file, but these are made available because they're generally usable. // TODO: Add more architectures, compilers and libraries. diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c index 2eae465048..77e942ec12 100644 --- a/extmod/modussl_axtls.c +++ b/extmod/modussl_axtls.c @@ -208,7 +208,7 @@ STATIC mp_uint_t ussl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int // default is to perform complete handshake in constructor, so // this should not happen in blocking mode. On the other hand, // in nonblocking mode EAGAIN (comparing to the alternative of - // looping) is really preferrable. + // looping) is really preferable. if (o->blocking) { continue; } else { diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index eea2d79532..74a59fdb67 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -333,7 +333,7 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc } else if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) { // If handshake is not finished, read attempt may end up in protocol // wanting to write next handshake message. The same may happen with - // renegotation. + // renegotiation. ret = MP_EWOULDBLOCK; o->poll_mask = MP_STREAM_POLL_WR; } else { @@ -361,7 +361,7 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in } else if (ret == MBEDTLS_ERR_SSL_WANT_READ) { // If handshake is not finished, write attempt may end up in protocol // wanting to read next handshake message. The same may happen with - // renegotation. + // renegotiation. ret = MP_EWOULDBLOCK; o->poll_mask = MP_STREAM_POLL_RD; } else { diff --git a/extmod/nimble/hal/hal_uart.c b/extmod/nimble/hal/hal_uart.c index 7713f75d8d..f4a9319c8b 100644 --- a/extmod/nimble/hal/hal_uart.c +++ b/extmod/nimble/hal/hal_uart.c @@ -84,7 +84,7 @@ void hal_uart_start_tx(uint32_t port) { mp_bluetooth_hci_uart_write(mp_bluetooth_hci_cmd_buf, len); if (len > 0) { - // Allow modbluetooth bindings to hook "sent packet" (e.g. to unstall l2cap channels). + // Allow modbluetooth bindings to hook "sent packet" (e.g. to un-stall l2cap channels). mp_bluetooth_nimble_sent_hci_packet(); } } diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index d9d4c13223..e23ffbf0f9 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -652,7 +652,7 @@ int mp_bluetooth_init(void) { // By default, just register the default gap/gatt service. ble_svc_gap_init(); ble_svc_gatt_init(); - // The preceeding two calls allocate service definitions on the heap, + // The preceding two calls allocate service definitions on the heap, // then we must now call gatts_start to register those services // and free the heap memory. // Otherwise it will be realloc'ed on the next stack startup. @@ -1537,7 +1537,7 @@ STATIC void destroy_l2cap_channel() { STATIC void unstall_l2cap_channel(void) { // Whenever we send an HCI packet and the sys mempool is now less than 1/4 full, - // we can unstall the L2CAP channel if it was marked as "mem_stalled" by + // we can un-stall the L2CAP channel if it was marked as "mem_stalled" by // mp_bluetooth_l2cap_send. (This happens if the pool is half-empty). mp_bluetooth_nimble_l2cap_channel_t *chan = MP_STATE_PORT(bluetooth_nimble_root_pointers)->l2cap_chan; if (!chan || !chan->mem_stalled) { @@ -1644,7 +1644,7 @@ STATIC int l2cap_channel_event(struct ble_l2cap_event *event, void *arg) { case BLE_L2CAP_EVENT_COC_TX_UNSTALLED: { DEBUG_printf("l2cap_channel_event: tx_unstalled: conn_handle=%d status=%d\n", event->tx_unstalled.conn_handle, event->tx_unstalled.status); assert(event->tx_unstalled.conn_handle == chan->chan->conn_handle); - // Don't unstall if we're still waiting for room in the sys pool. + // Don't un-stall if we're still waiting for room in the sys pool. if (!chan->mem_stalled) { ble_l2cap_get_chan_info(event->receive.chan, &info); // Map status to {0,1} (i.e. "sent everything", or "partial send"). @@ -1802,7 +1802,7 @@ int mp_bluetooth_l2cap_send(uint16_t conn_handle, uint16_t cid, const uint8_t *b err = ble_l2cap_send(chan->chan, sdu_tx); if (err == BLE_HS_ESTALLED) { // Stalled means that this one will still send but any future ones - // will fail until we receive an unstalled event. + // will fail until we receive an un-stalled event. DEBUG_printf("mp_bluetooth_l2cap_send: credit stall\n"); *stalled = true; err = 0; diff --git a/ports/cc3200/bootmgr/main.c b/ports/cc3200/bootmgr/main.c index cfb8dec21d..6feeec79a3 100644 --- a/ports/cc3200/bootmgr/main.c +++ b/ports/cc3200/bootmgr/main.c @@ -256,7 +256,7 @@ static bool wait_while_blinking (uint32_t wait_time, uint32_t period, bool force _u32 count; for (count = 0; (force_wait || MAP_GPIOPinRead(MICROPY_SAFE_BOOT_PORT, MICROPY_SAFE_BOOT_PORT_PIN)) && ((period * count) < wait_time); count++) { - // toogle the led + // toggle the led MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, ~MAP_GPIOPinRead(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN)); UtilsDelay(UTILS_DELAY_US_TO_COUNT(period * 1000)); } diff --git a/ports/cc3200/fatfs/src/drivers/sd_diskio.c b/ports/cc3200/fatfs/src/drivers/sd_diskio.c index 0a1379181b..329ae04b99 100644 --- a/ports/cc3200/fatfs/src/drivers/sd_diskio.c +++ b/ports/cc3200/fatfs/src/drivers/sd_diskio.c @@ -269,7 +269,7 @@ DSTATUS sd_disk_init (void) { // Fill in the RCA sd_disk_info.usRCA = (ulResp[0] >> 16); - // Get tha card capacity + // Get the card capacity CardCapacityGet(&sd_disk_info); } diff --git a/ports/cc3200/ftp/ftp.c b/ports/cc3200/ftp/ftp.c index d999e810d9..173bb7c2c0 100644 --- a/ports/cc3200/ftp/ftp.c +++ b/ports/cc3200/ftp/ftp.c @@ -97,7 +97,7 @@ typedef enum { typedef struct { bool uservalid : 1; bool passvalid : 1; -} ftp_loggin_t; +} ftp_login_t; typedef enum { E_FTP_NOTHING_OPEN = 0, @@ -127,8 +127,8 @@ typedef struct { uint8_t state; uint8_t substate; uint8_t txRetries; - uint8_t logginRetries; - ftp_loggin_t loggin; + uint8_t loginRetries; + ftp_login_t login; uint8_t e_open; bool closechild; bool enabled; @@ -329,10 +329,10 @@ void ftp_run (void) { if (ftp_data.c_sd < 0 && ftp_data.substate == E_FTP_STE_SUB_DISCONNECTED) { if (E_FTP_RESULT_OK == ftp_wait_for_connection(ftp_data.lc_sd, &ftp_data.c_sd)) { ftp_data.txRetries = 0; - ftp_data.logginRetries = 0; + ftp_data.loginRetries = 0; ftp_data.ctimeout = 0; - ftp_data.loggin.uservalid = false; - ftp_data.loggin.passvalid = false; + ftp_data.login.uservalid = false; + ftp_data.login.passvalid = false; strcpy (ftp_path, "/"); ftp_send_reply (220, "MicroPython FTP Server"); break; @@ -684,7 +684,7 @@ static void ftp_process_cmd (void) { if (E_FTP_RESULT_OK == (result = ftp_recv_non_blocking(ftp_data.c_sd, ftp_cmd_buffer, FTP_MAX_PARAM_SIZE + FTP_CMD_SIZE_MAX, &len))) { // bufptr is moved as commands are being popped ftp_cmd_index_t cmd = ftp_pop_command(&bufptr); - if (!ftp_data.loggin.passvalid && (cmd != E_FTP_CMD_USER && cmd != E_FTP_CMD_PASS && cmd != E_FTP_CMD_QUIT && cmd != E_FTP_CMD_FEAT)) { + if (!ftp_data.login.passvalid && (cmd != E_FTP_CMD_USER && cmd != E_FTP_CMD_PASS && cmd != E_FTP_CMD_QUIT && cmd != E_FTP_CMD_FEAT)) { ftp_send_reply(332, NULL); return; } @@ -754,16 +754,16 @@ static void ftp_process_cmd (void) { case E_FTP_CMD_USER: ftp_pop_param (&bufptr, ftp_scratch_buffer); if (!memcmp(ftp_scratch_buffer, servers_user, MAX(strlen(ftp_scratch_buffer), strlen(servers_user)))) { - ftp_data.loggin.uservalid = true && (strlen(servers_user) == strlen(ftp_scratch_buffer)); + ftp_data.login.uservalid = true && (strlen(servers_user) == strlen(ftp_scratch_buffer)); } ftp_send_reply(331, NULL); break; case E_FTP_CMD_PASS: ftp_pop_param (&bufptr, ftp_scratch_buffer); if (!memcmp(ftp_scratch_buffer, servers_pass, MAX(strlen(ftp_scratch_buffer), strlen(servers_pass))) && - ftp_data.loggin.uservalid) { - ftp_data.loggin.passvalid = true && (strlen(servers_pass) == strlen(ftp_scratch_buffer)); - if (ftp_data.loggin.passvalid) { + ftp_data.login.uservalid) { + ftp_data.login.passvalid = true && (strlen(servers_pass) == strlen(ftp_scratch_buffer)); + if (ftp_data.login.passvalid) { ftp_send_reply(230, NULL); break; } diff --git a/ports/cc3200/misc/mperror.c b/ports/cc3200/misc/mperror.c index 082d940e2f..6d6c0ff0ba 100644 --- a/ports/cc3200/misc/mperror.c +++ b/ports/cc3200/misc/mperror.c @@ -127,7 +127,7 @@ void mperror_deinit_sfe_pin (void) { void mperror_signal_error (void) { uint32_t count = 0; while ((MPERROR_TOOGLE_MS * count++) < MPERROR_SIGNAL_ERROR_MS) { - // toogle the led + // toggle the led MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, ~MAP_GPIOPinRead(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN)); UtilsDelay(UTILS_DELAY_US_TO_COUNT(MPERROR_TOOGLE_MS * 1000)); } diff --git a/ports/cc3200/mods/modwlan.c b/ports/cc3200/mods/modwlan.c index ca18b34823..bf243ce7b9 100644 --- a/ports/cc3200/mods/modwlan.c +++ b/ports/cc3200/mods/modwlan.c @@ -432,7 +432,7 @@ void wlan_sl_init (int8_t mode, const char *ssid, uint8_t ssid_len, uint8_t auth // switch to the requested mode wlan_set_mode(mode); - // stop and start again (we need to in the propper mode from now on) + // stop and start again (we need to be in the proper mode from now on) wlan_reenable(mode); // Set Tx power level for station or AP mode @@ -608,7 +608,7 @@ STATIC void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac) { // save the ssid memcpy(&wlan_obj.ssid, ssid, len); // append the last 2 bytes of the MAC address, since the use of this functionality is under our control - // we can assume that the lenght of the ssid is less than (32 - 5) + // we can assume that the length of the ssid is less than (32 - 5) if (add_mac) { snprintf((char *)&wlan_obj.ssid[len], sizeof(wlan_obj.ssid) - len, "-%02x%02x", wlan_obj.mac[4], wlan_obj.mac[5]); len += 5; diff --git a/ports/cc3200/mods/pybpin.c b/ports/cc3200/mods/pybpin.c index f04ca75654..6d10abab57 100644 --- a/ports/cc3200/mods/pybpin.c +++ b/ports/cc3200/mods/pybpin.c @@ -113,7 +113,7 @@ STATIC pybpin_wake_pin_t pybpin_wake_pin[PYBPIN_NUM_WAKE_PINS] = DEFINE PUBLIC FUNCTIONS ******************************************************************************/ void pin_init0(void) { -// this initalization also reconfigures the JTAG/SWD pins +// this initialization also reconfigures the JTAG/SWD pins #ifndef DEBUG // assign all pins to the GPIO module so that peripherals can be connected to any // pins without conflicts after a soft reset @@ -560,7 +560,7 @@ STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, size_t n_args, const mp_obj } } - // get the strenght + // get the strength uint strength = args[3].u_int; pin_validate_drive(strength); diff --git a/ports/cc3200/mods/pybrtc.c b/ports/cc3200/mods/pybrtc.c index 21e729dbf1..e79fb29d00 100644 --- a/ports/cc3200/mods/pybrtc.c +++ b/ports/cc3200/mods/pybrtc.c @@ -76,7 +76,7 @@ STATIC void rtc_msec_add(uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2); ******************************************************************************/ __attribute__ ((section (".boot"))) void pyb_rtc_pre_init(void) { - // only if comming out of a power-on reset + // only if coming out of a power-on reset if (MAP_PRCMSysResetCauseGet() == PRCM_POWER_ON) { // Mark the RTC in use first MAP_PRCMRTCInUseSet(); @@ -118,7 +118,7 @@ void pyb_rtc_repeat_alarm (pyb_rtc_obj_t *self) { pyb_rtc_get_time(&c_seconds, &c_mseconds); - // substract the time elapsed between waking up and setting up the alarm again + // subtract the time elapsed between waking up and setting up the alarm again int32_t wake_ms = ((c_seconds * 1000) + c_mseconds) - ((self->alarm_time_s * 1000) + self->alarm_time_ms); int32_t next_alarm = self->alarm_ms - wake_ms; next_alarm = next_alarm > 0 ? next_alarm : PYB_RTC_MIN_ALARM_TIME_MS; diff --git a/ports/cc3200/mods/pybsd.c b/ports/cc3200/mods/pybsd.c index 209c3b5a85..952a117c45 100644 --- a/ports/cc3200/mods/pybsd.c +++ b/ports/cc3200/mods/pybsd.c @@ -71,7 +71,7 @@ STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in); /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ -/// Initalizes the sd card hardware driver +/// Initializes the sd card hardware driver STATIC void pyb_sd_hw_init (pybsd_obj_t *self) { if (self->pin_clk) { // Configure the clock pin as output only diff --git a/ports/cc3200/mods/pybsleep.c b/ports/cc3200/mods/pybsleep.c index ffb281e6b1..ea2642c260 100644 --- a/ports/cc3200/mods/pybsleep.c +++ b/ports/cc3200/mods/pybsleep.c @@ -160,13 +160,13 @@ void pyb_sleep_init0 (void) { // register and enable the PRCM interrupt osi_InterruptRegister(INT_PRCM, (P_OSI_INTR_ENTRY)PRCMInterruptHandler, INT_PRIORITY_LVL_1); - // disable all LPDS and hibernate wake up sources (WLAN is disabed/enabled before entering LDPS mode) + // disable all LPDS and hibernate wake up sources (WLAN is disabled/enabled before entering LDPS mode) MAP_PRCMLPDSWakeupSourceDisable(PRCM_LPDS_GPIO); MAP_PRCMLPDSWakeupSourceDisable(PRCM_LPDS_TIMER); MAP_PRCMHibernateWakeupSourceDisable(PRCM_HIB_SLOW_CLK_CTR | PRCM_HIB_GPIO2 | PRCM_HIB_GPIO4 | PRCM_HIB_GPIO13 | PRCM_HIB_GPIO17 | PRCM_HIB_GPIO11 | PRCM_HIB_GPIO24 | PRCM_HIB_GPIO26); - // check the reset casue (if it's soft reset, leave it as it is) + // check the reset cause (if it's soft reset, leave it as it is) if (pybsleep_reset_cause != PYB_SLP_SOFT_RESET) { switch (MAP_PRCMSysResetCauseGet()) { case PRCM_POWER_ON: diff --git a/ports/cc3200/mptask.c b/ports/cc3200/mptask.c index 81f00e5384..a9dbf3c4c3 100644 --- a/ports/cc3200/mptask.c +++ b/ports/cc3200/mptask.c @@ -158,7 +158,7 @@ soft_reset: // to enable simplelink and leave it as is wlan_first_start(); } else { - // only if not comming out of hibernate or a soft reset + // only if not coming out of hibernate or a soft reset mptask_enter_ap_mode(); } @@ -315,7 +315,7 @@ STATIC void mptask_init_sflash_filesystem(void) { // create empty main.py mptask_create_main_py(); } else if (res == FR_OK) { - // mount sucessful + // mount successful if (FR_OK != f_stat(&vfs_fat->fatfs, "/main.py", &fno)) { // create empty main.py mptask_create_main_py(); diff --git a/ports/cc3200/serverstask.c b/ports/cc3200/serverstask.c index 03eed8eeb0..4d852447f4 100644 --- a/ports/cc3200/serverstask.c +++ b/ports/cc3200/serverstask.c @@ -111,7 +111,7 @@ void TASK_Servers(void *pvParameters) { ftp_reset(); } // and we should also close all user sockets. We do it here - // for convinience and to save on code size. + // for convenience and to save on code size. modusocket_close_all_user_sockets(); } diff --git a/ports/cc3200/telnet/telnet.c b/ports/cc3200/telnet/telnet.c index c4daac3426..df1fd1c22d 100644 --- a/ports/cc3200/telnet/telnet.c +++ b/ports/cc3200/telnet/telnet.c @@ -407,7 +407,7 @@ static void telnet_process (void) { _i16 rxLen; _i16 maxLen = (telnet_data.rxWindex >= telnet_data.rxRindex) ? (TELNET_RX_BUFFER_SIZE - telnet_data.rxWindex) : ((telnet_data.rxRindex - telnet_data.rxWindex) - 1); - // to avoid an overrrun + // to avoid an overrun maxLen = (telnet_data.rxRindex == 0) ? (maxLen - 1) : maxLen; if (maxLen > 0) { diff --git a/ports/cc3200/util/cryptohash.c b/ports/cc3200/util/cryptohash.c index 909dadc8cf..ebf12e6e36 100644 --- a/ports/cc3200/util/cryptohash.c +++ b/ports/cc3200/util/cryptohash.c @@ -59,7 +59,7 @@ void CRYPTOHASH_SHAMD5Start (uint32_t algo, uint32_t blocklen) { HWREG(SHAMD5_BASE + SHAMD5_O_MODE) |= SHAMD5_MODE_CLOSE_HASH; } - // set the lenght + // set the length HWREG(SHAMD5_BASE + SHAMD5_O_LENGTH) = blocklen; } diff --git a/ports/esp32/machine_pwm.c b/ports/esp32/machine_pwm.c index 79e11d0278..445ac80fb2 100644 --- a/ports/esp32/machine_pwm.c +++ b/ports/esp32/machine_pwm.c @@ -350,7 +350,7 @@ STATIC void set_duty_u16(machine_pwm_obj_t *self, int duty) { /* // Bug: Sometimes duty is not set right now. // Not a bug. It's a feature. The duty is applied at the beginning of the next signal period. - // Bug: It has been experimentally established that the duty is setted during 2 signal periods, but 1 period is expected. + // Bug: It has been experimentally established that the duty is set during 2 signal periods, but 1 period is expected. // See https://github.com/espressif/esp-idf/issues/7288 if (duty != get_duty_u16(self)) { PWM_DBG("set_duty_u16(%u), get_duty_u16():%u, channel_duty:%d, duty_resolution:%d, freq_hz:%d", duty, get_duty_u16(self), channel_duty, timer.duty_resolution, timer.freq_hz); @@ -510,7 +510,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, } } if ((freq <= 0) || (freq > 40000000)) { - mp_raise_ValueError(MP_ERROR_TEXT("freqency must be from 1Hz to 40MHz")); + mp_raise_ValueError(MP_ERROR_TEXT("frequency must be from 1Hz to 40MHz")); } int timer_idx; @@ -607,7 +607,7 @@ STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { self->duty_x = 0; } -// Set's and get's methods of PWM class +// Set and get methods of PWM class STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { pwm_is_active(self); @@ -617,7 +617,7 @@ STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { pwm_is_active(self); if ((freq <= 0) || (freq > 40000000)) { - mp_raise_ValueError(MP_ERROR_TEXT("freqency must be from 1Hz to 40MHz")); + mp_raise_ValueError(MP_ERROR_TEXT("frequency must be from 1Hz to 40MHz")); } if (freq == timers[TIMER_IDX(self->mode, self->timer)].freq_hz) { return; diff --git a/ports/esp8266/esppwm.c b/ports/esp8266/esppwm.c index 3b705fb94e..d7ac44a178 100644 --- a/ports/esp8266/esppwm.c +++ b/ports/esp8266/esppwm.c @@ -165,7 +165,7 @@ pwm_start(void) { } } PWM_DBG("2channel:%d,single[0]:%d,[1]:%d,[2]:%d,[3]:%d\n", *local_channel, local_single[0].h_time, local_single[1].h_time, local_single[2].h_time, local_single[3].h_time); - // step 4: cacl delt time + // step 4: calc delta time for (i = *local_channel - 1; i > 0; i--) { local_single[i].h_time -= local_single[i - 1].h_time; } diff --git a/ports/esp8266/hspi_register.h b/ports/esp8266/hspi_register.h index 50ef2fdca3..0d0cf2f747 100644 --- a/ports/esp8266/hspi_register.h +++ b/ports/esp8266/hspi_register.h @@ -79,7 +79,7 @@ #define SPI_MOSI_DELAY_NUM 0x00000007 #define SPI_MOSI_DELAY_NUM_S 23 #define SPI_MOSI_DELAY_MODE 0x00000003 //mode 0 : posedge; data set at positive edge of clk - //mode 1 : negedge + 1 cycle delay, only if freq<10MHz ; data set at negitive edge of clk + //mode 1 : negedge + 1 cycle delay, only if freq<10MHz ; data set at negative edge of clk //mode 2 : Do not use this mode. #define SPI_MOSI_DELAY_MODE_S 21 #define SPI_MISO_DELAY_NUM 0x00000007 diff --git a/ports/esp8266/uart.c b/ports/esp8266/uart.c index 117cd1bf6c..f761ecfd70 100644 --- a/ports/esp8266/uart.c +++ b/ports/esp8266/uart.c @@ -3,7 +3,7 @@ * * FileName: uart.c * - * Description: Two UART mode configration and interrupt handler. + * Description: Two UART mode configuration and interrupt handler. * Check your hardware connection while use this mode. * * Modification history: @@ -164,7 +164,7 @@ uart_os_config(int uart) { *******************************************************************************/ static void uart0_rx_intr_handler(void *para) { - /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents + /* uart0 and uart1 intr combine together, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents * uart1 and uart0 respectively */ diff --git a/ports/mimxrt/boards/MIMXRT1176_clock_config.c b/ports/mimxrt/boards/MIMXRT1176_clock_config.c index 4e01448ba3..ae02e30fa8 100644 --- a/ports/mimxrt/boards/MIMXRT1176_clock_config.c +++ b/ports/mimxrt/boards/MIMXRT1176_clock_config.c @@ -172,7 +172,7 @@ void BOARD_BootClockRUN(void) { (ANADIG_OSC->OSC_24M_CTRL & ANADIG_OSC_OSC_24M_CTRL_OSC_24M_STABLE_MASK)) { } - /* Swicth both core, M7 Systick and Bus_Lpsr to OscRC48MDiv2 first */ + /* Switch both core, M7 Systick and Bus_Lpsr to OscRC48MDiv2 first */ rootCfg.mux = kCLOCK_M7_ClockRoot_MuxOscRc48MDiv2; rootCfg.div = 1; #if __CORTEX_M == 7 diff --git a/ports/mimxrt/boards/deploy_teensy.md b/ports/mimxrt/boards/deploy_teensy.md index 28da092493..8f533a91fd 100644 --- a/ports/mimxrt/boards/deploy_teensy.md +++ b/ports/mimxrt/boards/deploy_teensy.md @@ -11,7 +11,7 @@ or for Teensy 4.1: teensy_loader_cli --mcu=imxrt1062 -v -w TEENSY41-.hex ``` -Instead of imxrt1062 with the --mcu option, you can as well use the board specic names +Instead of imxrt1062 with the --mcu option, you can as well use the board specific names TEENSY40, TEENSY41 or TEENSY_MICROMOD. When loading the firmware the PJRC boot loader will erase the board file system. diff --git a/ports/mimxrt/hal/flexspi_flash_config.h b/ports/mimxrt/hal/flexspi_flash_config.h index 80526880be..7eaf3192b5 100644 --- a/ports/mimxrt/hal/flexspi_flash_config.h +++ b/ports/mimxrt/hal/flexspi_flash_config.h @@ -123,7 +123,7 @@ enum kFlexSpiDeviceType_SerialNAND = 2, // !< Flash devices are Serial NAND kFlexSpiDeviceType_SerialRAM = 3, // !< Flash devices are Serial RAM/HyperFLASH kFlexSpiDeviceType_MCP_NOR_NAND = 0x12, // !< Flash device is MCP device, A1 is Serial NOR, A2 is Serial NAND - kFlexSpiDeviceType_MCP_NOR_RAM = 0x13, // !< Flash deivce is MCP device, A1 is Serial NOR, A2 is Serial RAMs + kFlexSpiDeviceType_MCP_NOR_RAM = 0x13, // !< Flash device is MCP device, A1 is Serial NOR, A2 is Serial RAMs }; // !@brief Flash Pad Definitions @@ -184,7 +184,7 @@ typedef struct _FlexSPIConfig // ! details uint8_t deviceType; // !< [0x044-0x044] Device Type: See Flash Type Definition for more details uint8_t sflashPadType; // !< [0x045-0x045] Serial Flash Pad Type: 1 - Single, 2 - Dual, 4 - Quad, 8 - Octal - uint8_t serialClkFreq; // !< [0x046-0x046] Serial Flash Frequencey, device specific definitions, See System Boot + uint8_t serialClkFreq; // !< [0x046-0x046] Serial Flash Frequency, device specific definitions, See System Boot // ! Chapter for more details uint8_t lutCustomSeqEnable; // !< [0x047-0x047] LUT customization Enable, it is required if the program/erase cannot // ! be done using 1 LUT sequence, currently, only applicable to HyperFLASH @@ -245,7 +245,7 @@ typedef struct _flexspi_nor_config uint8_t serialNorType; // !< Serial NOR Flash type: 0/1/2/3 uint8_t needExitNoCmdMode; // !< Need to exit NoCmd mode before other IP command uint8_t halfClkForNonReadCmd; // !< Half the Serial Clock for non-read command: true/false - uint8_t needRestoreNoCmdMode; // !< Need to Restore NoCmd mode after IP commmand execution + uint8_t needRestoreNoCmdMode; // !< Need to Restore NoCmd mode after IP command execution uint32_t blockSize; // !< Block size uint32_t reserve2[11]; // !< Reserved for future use } flexspi_nor_config_t; diff --git a/ports/mimxrt/hal/fsl_flexspi_nor_boot.h b/ports/mimxrt/hal/fsl_flexspi_nor_boot.h index fbb8a574f3..58443119d4 100644 --- a/ports/mimxrt/hal/fsl_flexspi_nor_boot.h +++ b/ports/mimxrt/hal/fsl_flexspi_nor_boot.h @@ -97,7 +97,7 @@ typedef struct _boot_data_ { uint32_t start; /* boot start location */ uint32_t size; /* size */ uint32_t plugin; /* plugin flag - 1 if downloaded application is plugin */ - uint32_t placeholder; /* placehoder to make even 0x10 size */ + uint32_t placeholder; /* placeholder to make even 0x10 size */ }BOOT_DATA_T; #if defined(BOARD_FLASH_SIZE) diff --git a/ports/mimxrt/hal/phy/device/phydp83825/fsl_phydp83825.h b/ports/mimxrt/hal/phy/device/phydp83825/fsl_phydp83825.h index 9d6b4fdf78..7d51953f5b 100644 --- a/ports/mimxrt/hal/phy/device/phydp83825/fsl_phydp83825.h +++ b/ports/mimxrt/hal/phy/device/phydp83825/fsl_phydp83825.h @@ -117,7 +117,7 @@ status_t PHY_DP83825_GetLinkStatus(phy_handle_t *handle, bool *status); * @brief Gets the PHY link speed and duplex. * * @brief This function gets the speed and duplex mode of PHY. User can give one of speed - * and duplex address paramter and set the other as NULL if only wants to get one of them. + * and duplex address parameter and set the other as NULL if only wants to get one of them. * * @param handle PHY device handle. * @param speed The address of PHY link speed. diff --git a/ports/mimxrt/hal/phy/device/phydp83848/fsl_phydp83848.h b/ports/mimxrt/hal/phy/device/phydp83848/fsl_phydp83848.h index 7ccc260f7b..6680247e43 100644 --- a/ports/mimxrt/hal/phy/device/phydp83848/fsl_phydp83848.h +++ b/ports/mimxrt/hal/phy/device/phydp83848/fsl_phydp83848.h @@ -117,7 +117,7 @@ status_t PHY_DP83848_GetLinkStatus(phy_handle_t *handle, bool *status); * @brief Gets the PHY link speed and duplex. * * @brief This function gets the speed and duplex mode of PHY. User can give one of speed - * and duplex address paramter and set the other as NULL if only wants to get one of them. + * and duplex address parameter and set the other as NULL if only wants to get one of them. * * @param handle PHY device handle. * @param speed The address of PHY link speed. diff --git a/ports/mimxrt/hal/phy/device/phyksz8081/fsl_phyksz8081.h b/ports/mimxrt/hal/phy/device/phyksz8081/fsl_phyksz8081.h index 5b93c5698a..49e930df66 100644 --- a/ports/mimxrt/hal/phy/device/phyksz8081/fsl_phyksz8081.h +++ b/ports/mimxrt/hal/phy/device/phyksz8081/fsl_phyksz8081.h @@ -117,7 +117,7 @@ status_t PHY_KSZ8081_GetLinkStatus(phy_handle_t *handle, bool *status); * @brief Gets the PHY link speed and duplex. * * @brief This function gets the speed and duplex mode of PHY. User can give one of speed - * and duplex address paramter and set the other as NULL if only wants to get one of them. + * and duplex address parameter and set the other as NULL if only wants to get one of them. * * @param handle PHY device handle. * @param speed The address of PHY link speed. diff --git a/ports/mimxrt/hal/phy/device/phylan8720/fsl_phylan8720.h b/ports/mimxrt/hal/phy/device/phylan8720/fsl_phylan8720.h index 2e8b4e3631..dcd5ebbe79 100644 --- a/ports/mimxrt/hal/phy/device/phylan8720/fsl_phylan8720.h +++ b/ports/mimxrt/hal/phy/device/phylan8720/fsl_phylan8720.h @@ -117,7 +117,7 @@ status_t PHY_LAN8720_GetLinkStatus(phy_handle_t *handle, bool *status); * @brief Gets the PHY link speed and duplex. * * @brief This function gets the speed and duplex mode of PHY. User can give one of speed - * and duplex address paramter and set the other as NULL if only wants to get one of them. + * and duplex address parameter and set the other as NULL if only wants to get one of them. * * @param handle PHY device handle. * @param speed The address of PHY link speed. diff --git a/ports/mimxrt/hal/phy/device/phyrtl8211f/fsl_phyrtl8211f.h b/ports/mimxrt/hal/phy/device/phyrtl8211f/fsl_phyrtl8211f.h index 225c249a6e..0598b25112 100644 --- a/ports/mimxrt/hal/phy/device/phyrtl8211f/fsl_phyrtl8211f.h +++ b/ports/mimxrt/hal/phy/device/phyrtl8211f/fsl_phyrtl8211f.h @@ -117,7 +117,7 @@ status_t PHY_RTL8211F_GetLinkStatus(phy_handle_t *handle, bool *status); * @brief Gets the PHY link speed and duplex. * * @brief This function gets the speed and duplex mode of PHY. User can give one of speed - * and duplex address paramter and set the other as NULL if only wants to get one of them. + * and duplex address parameter and set the other as NULL if only wants to get one of them. * * @param handle PHY device handle. * @param speed The address of PHY link speed. diff --git a/ports/mimxrt/hal/phy/fsl_phy.h b/ports/mimxrt/hal/phy/fsl_phy.h index 6a022d4eae..53edd9d0b6 100644 --- a/ports/mimxrt/hal/phy/fsl_phy.h +++ b/ports/mimxrt/hal/phy/fsl_phy.h @@ -207,7 +207,7 @@ static inline status_t PHY_GetLinkStatus(phy_handle_t *handle, bool *status) { * @brief Gets the PHY link speed and duplex. * * @brief This function gets the speed and duplex mode of PHY. User can give one of speed - * and duplex address paramter and set the other as NULL if only wants to get one of them. + * and duplex address parameter and set the other as NULL if only wants to get one of them. * * @param handle PHY device handle. * @param speed The address of PHY link speed. diff --git a/ports/mimxrt/hal/resethandler_MIMXRT10xx.S b/ports/mimxrt/hal/resethandler_MIMXRT10xx.S index efca1a7ec6..fe933c6d60 100644 --- a/ports/mimxrt/hal/resethandler_MIMXRT10xx.S +++ b/ports/mimxrt/hal/resethandler_MIMXRT10xx.S @@ -60,7 +60,7 @@ Reset_Handler: * linker script. * __etext: End of code section, i.e., begin of data sections to copy from. * __data_start__/__data_end__: RAM address range that data should be - * __noncachedata_start__/__noncachedata_end__ : none cachable region + * __noncachedata_start__/__noncachedata_end__ : non-cacheable region * __ram_function_start__/__ram_function_end__ : ramfunction region * copied to. Both must be aligned to 4 bytes boundary. */ @@ -80,7 +80,7 @@ Reset_Handler: str r0, [r2, r3] bgt .LC0 .LC1: -#else /* code size implemenation */ +#else /* code size implementation */ .LC0: cmp r2, r3 ittt lt @@ -103,7 +103,7 @@ Reset_Handler: str r0, [r2, r3] bgt .LC_ramfunc_copy_start .LC_ramfunc_copy_end: -#else /* code size implemenation */ +#else /* code size implementation */ .LC_ramfunc_copy_start: cmp r2, r3 ittt lt @@ -127,7 +127,7 @@ Reset_Handler: str r0, [r2, r3] bgt .LC2 .LC3: -#else /* code size implemenation */ +#else /* code size implementation */ .LC2: cmp r2, r3 ittt lt diff --git a/ports/mimxrt/machine_i2s.c b/ports/mimxrt/machine_i2s.c index 32daad0853..aa8eabeb0b 100644 --- a/ports/mimxrt/machine_i2s.c +++ b/ports/mimxrt/machine_i2s.c @@ -826,7 +826,7 @@ STATIC bool i2s_init(machine_i2s_obj_t *self) { memset(self->edmaTcd, 0, sizeof(edma_tcd_t)); - // continuous DMA operation is acheived using the scatter/gather feature, with one TCD linked back to itself + // continuous DMA operation is achieved using the scatter/gather feature, with one TCD linked back to itself EDMA_TcdSetTransferConfig(self->edmaTcd, &transferConfig, self->edmaTcd); EDMA_TcdEnableInterrupts(self->edmaTcd, kEDMA_MajorInterruptEnable | kEDMA_HalfInterruptEnable); EDMA_InstallTCD(DMA0, self->dma_channel, self->edmaTcd); diff --git a/ports/mimxrt/machine_pwm.c b/ports/mimxrt/machine_pwm.c index 661ec16658..c1d6bdf7a6 100644 --- a/ports/mimxrt/machine_pwm.c +++ b/ports/mimxrt/machine_pwm.c @@ -137,7 +137,7 @@ STATIC uint8_t channel_decode(char channel) { } } -// decode the AF objects module and Port numer. Returns NULL if it is not a FLEXPWM object +// decode the AF objects module and Port number. Returns NULL if it is not a FLEXPWM object STATIC const machine_pin_af_obj_t *af_name_decode_flexpwm(const machine_pin_af_obj_t *af_obj, uint8_t *module, uint8_t *submodule, uint8_t *channel) { const char *str; @@ -171,7 +171,7 @@ STATIC uint8_t qtmr_decode(char channel) { } } -// decode the AF objects module and Port numer. Returns NULL if it is not a QTMR object +// decode the AF objects module and Port number. Returns NULL if it is not a QTMR object STATIC const machine_pin_af_obj_t *af_name_decode_qtmr(const machine_pin_af_obj_t *af_obj, uint8_t *module, uint8_t *channel) { const char *str; size_t len; @@ -558,7 +558,7 @@ void machine_pwm_deinit_all(void) { for (int i = 1; i < ARRAY_SIZE(pwm_bases); i++) { PWM_StopTimer(pwm_bases[i], 0x0f); // Stop all submodules - pwm_bases[i]->OUTEN = 0; // Disable ouput on all submodules, all channels + pwm_bases[i]->OUTEN = 0; // Disable output on all submodules, all channels } #ifdef FSL_FEATURE_SOC_TMR_COUNT diff --git a/ports/mimxrt/mphalport.h b/ports/mimxrt/mphalport.h index 5136a36b38..ba7e1cfa94 100644 --- a/ports/mimxrt/mphalport.h +++ b/ports/mimxrt/mphalport.h @@ -40,7 +40,7 @@ #define MP_HAL_PIN_FMT "%q" extern ringbuf_t stdin_ringbuf; -// Define an alias fo systick_ms, because the shared softtimer.c uses +// Define an alias for systick_ms, because the shared softtimer.c uses // the symbol uwTick for the systick ms counter. #define uwTick systick_ms diff --git a/ports/mimxrt/sdcard.c b/ports/mimxrt/sdcard.c index 1d54859901..76d303aad0 100644 --- a/ports/mimxrt/sdcard.c +++ b/ports/mimxrt/sdcard.c @@ -223,7 +223,7 @@ void sdcard_card_removed_callback(USDHC_Type *base, void *userData); void sdcard_transfer_complete_callback(USDHC_Type *base, usdhc_handle_t *handle, status_t status, void *userData); void sdcard_dummy_callback(USDHC_Type *base, void *userData); -// SD Card commmands +// SD Card commands static bool sdcard_cmd_go_idle_state(mimxrt_sdcard_obj_t *card); static bool sdcard_cmd_oper_cond(mimxrt_sdcard_obj_t *card); static bool sdcard_cmd_app_cmd(mimxrt_sdcard_obj_t *card); diff --git a/ports/minimal/stm32f405.ld b/ports/minimal/stm32f405.ld index a202294a54..6a275440cf 100644 --- a/ports/minimal/stm32f405.ld +++ b/ports/minimal/stm32f405.ld @@ -28,7 +28,7 @@ SECTIONS . = ALIGN(4); _etext = .; /* define a global symbol at end of code */ - _sidata = _etext; /* This is used by the startup in order to initialize the .data secion */ + _sidata = _etext; /* This is used by the startup in order to initialize the .data section */ } >FLASH /* This is the initialized data section diff --git a/ports/nrf/README.md b/ports/nrf/README.md index a833f0f17c..fde04e61f1 100644 --- a/ports/nrf/README.md +++ b/ports/nrf/README.md @@ -98,7 +98,7 @@ Note: further tuning of features to include in bluetooth or even setting up the ## Compile with freeze manifest -Freeze manifests can be used by definining `FROZEN_MANIFEST` pointing to a +Freeze manifests can be used by defining `FROZEN_MANIFEST` pointing to a `manifest.py`. This can either be done by a `make` invocation or by defining it in the specific target board's `mpconfigboard.mk`. @@ -132,8 +132,8 @@ For example: ## Set file system size The size of the file system on the internal flash is configured by the linker -script parameter `_fs_size`. This can either be overriden by the linker script -or dynamically through the makefile. By seting a value to the `FS_SIZE`. +script parameter `_fs_size`. This can either be overridden by the linker script +or dynamically through the makefile. By setting a value to the `FS_SIZE`. The number will be passed directly to the linker scripts in order to calculate the start and end of the file system. Note that the parameter value must be in linker script syntax as it is passed directly. @@ -215,7 +215,7 @@ Install the necessary Python packages that will be used for flashing using the b The `intelhex` provides the `hexmerge.py` utility which is used by the Makefile to trim of the MBR in case SoftDevice flashing is requested. -`nrfutil` as flashing backend also requires a serial port paramter to be defined +`nrfutil` as flashing backend also requires a serial port parameter to be defined in addition to the `deploy` target of make. For example: make BOARD=nrf52840-mdk-usb-dongle NRFUTIL_PORT=/dev/ttyACM0 deploy diff --git a/ports/nrf/boards/arduino_nano_33_ble_sense/modules/imu.py b/ports/nrf/boards/arduino_nano_33_ble_sense/modules/imu.py index 50a36a1976..821795e17c 100644 --- a/ports/nrf/boards/arduino_nano_33_ble_sense/modules/imu.py +++ b/ports/nrf/boards/arduino_nano_33_ble_sense/modules/imu.py @@ -23,7 +23,7 @@ import time class IMU: def __init__(self, bus): - """Initalizes Gyro, Accelerometer and Magnetometer using default values.""" + """Initializes Gyro, Accelerometer and Magnetometer using default values.""" if 0x68 in bus.scan(): from bmm150 import BMM150 from bmi270 import BMI270 diff --git a/ports/nrf/boards/make-pins.py b/ports/nrf/boards/make-pins.py index 347ed15b21..720df6e49e 100644 --- a/ports/nrf/boards/make-pins.py +++ b/ports/nrf/boards/make-pins.py @@ -13,7 +13,7 @@ SUPPORTED_FN = {"UART": ["RX", "TX", "CTS", "RTS"]} def parse_pin(name_str): """Parses a string and returns a pin-num.""" if len(name_str) < 1: - raise ValueError("Expecting pin name to be at least 4 charcters.") + raise ValueError("Expecting pin name to be at least 4 characters.") if name_str[0] != "P": raise ValueError("Expecting pin name to start with P") pin_str = name_str[1:].split("/")[0] diff --git a/ports/nrf/boards/microbit/modules/microbitimage.c b/ports/nrf/boards/microbit/modules/microbitimage.c index fc6b18870b..08ef4babcf 100644 --- a/ports/nrf/boards/microbit/modules/microbitimage.c +++ b/ports/nrf/boards/microbit/modules/microbitimage.c @@ -219,7 +219,7 @@ STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t const char *str = mp_obj_str_get_data(args[0], &len); // make image from string if (len == 1) { - /* For a single charater, return the font glyph */ + /* For a single character, return the font glyph */ return microbit_image_for_char(str[0]); } else { /* Otherwise parse the image description string */ @@ -305,7 +305,7 @@ STATIC void image_blit(microbit_image_obj_t *src, greyscale_t *dest, mp_int_t x, greyscaleSetPixelValue(dest, i+xdest-x, j+ydest-y, val); } } - // Adjust intersection rectange to dest + // Adjust intersection rectangle to dest intersect_x0 += xdest-x; intersect_y0 += ydest-y; intersect_x1 += xdest-x; diff --git a/ports/nrf/drivers/bluetooth/ble_drv.c b/ports/nrf/drivers/bluetooth/ble_drv.c index 173d3eda01..078c7d995b 100644 --- a/ports/nrf/drivers/bluetooth/ble_drv.c +++ b/ports/nrf/drivers/bluetooth/ble_drv.c @@ -480,7 +480,7 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) { // do encoding into the adv buffer if (sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]) != 0) { - mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID into advertisment packet")); + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID into advertisement packet")); } BLE_DRIVER_LOG("encoded uuid for service %u: ", 0); @@ -528,7 +528,7 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) { // do encoding into the adv buffer if (sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]) != 0) { - mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID into advertisment packet")); + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID into advertisement packet")); } BLE_DRIVER_LOG("encoded uuid for service %u: ", 0); @@ -552,7 +552,7 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) { if ((p_adv_params->data_len > 0) && (p_adv_params->p_data != NULL)) { if (p_adv_params->data_len + byte_pos > BLE_GAP_ADV_MAX_SIZE) { - mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't fit data into advertisment packet")); + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't fit data into advertisement packet")); } memcpy(adv_data, p_adv_params->p_data, p_adv_params->data_len); @@ -590,12 +590,12 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) { #if (BLUETOOTH_SD == 110) m_adv_params.fp = BLE_GAP_ADV_FP_ANY; - m_adv_params.timeout = 0; // infinite advertisment + m_adv_params.timeout = 0; // infinite advertisement #else m_adv_params.properties.anonymous = 0; m_adv_params.properties.include_tx_power = 0; m_adv_params.filter_policy = 0; - m_adv_params.max_adv_evts = 0; // infinite advertisment + m_adv_params.max_adv_evts = 0; // infinite advertisement m_adv_params.primary_phy = BLE_GAP_PHY_AUTO; m_adv_params.secondary_phy = BLE_GAP_PHY_AUTO; m_adv_params.scan_req_notification = 0; // Do not raise scan request notifications when scanned. @@ -606,12 +606,12 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) { #if (BLUETOOTH_SD == 110) if ((err_code = sd_ble_gap_adv_data_set(adv_data, byte_pos, NULL, 0)) != 0) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("Can not apply advertisment data. status: 0x" HEX2_FMT), (uint16_t)err_code); + MP_ERROR_TEXT("Can not apply advertisement data. status: 0x" HEX2_FMT), (uint16_t)err_code); } #else if ((err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params)) != 0) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("Can not apply advertisment data. status: 0x" HEX2_FMT), (uint16_t)err_code); + MP_ERROR_TEXT("Can not apply advertisement data. status: 0x" HEX2_FMT), (uint16_t)err_code); } #endif BLE_DRIVER_LOG("Set Adv data size: " UINT_FMT "\n", byte_pos); @@ -626,7 +626,7 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) { #endif if (err_code != 0) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("Can not start advertisment. status: 0x" HEX2_FMT), (uint16_t)err_code); + MP_ERROR_TEXT("Can not start advertisement. status: 0x" HEX2_FMT), (uint16_t)err_code); } m_adv_in_progress = true; @@ -641,12 +641,12 @@ void ble_drv_advertise_stop(void) { #if (BLUETOOTH_SD == 110) if ((err_code = sd_ble_gap_adv_stop()) != 0) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("Can not stop advertisment. status: 0x" HEX2_FMT), (uint16_t)err_code); + MP_ERROR_TEXT("Can not stop advertisement. status: 0x" HEX2_FMT), (uint16_t)err_code); } #else if ((err_code = sd_ble_gap_adv_stop(m_adv_handle)) != 0) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("Can not stop advertisment. status: 0x" HEX2_FMT), (uint16_t)err_code); + MP_ERROR_TEXT("Can not stop advertisement. status: 0x" HEX2_FMT), (uint16_t)err_code); } #endif } diff --git a/ports/nrf/drivers/ticker.c b/ports/nrf/drivers/ticker.c index 46cc783c48..c2fa31e7c2 100644 --- a/ports/nrf/drivers/ticker.c +++ b/ports/nrf/drivers/ticker.c @@ -137,7 +137,7 @@ int set_ticker_callback(uint32_t index, ticker_callback_ptr func, int32_t initia ticker->INTENCLR = masks[index]; ticker->TASKS_CAPTURE[index] = 1; uint32_t t = FastTicker->CC[index]; - // Need to make sure that set tick is aligned to lastest tick + // Need to make sure that set tick is aligned to latest tick // Use CC[3] as a reference, as that is always up-to-date. int32_t cc3 = FastTicker->CC[3]; int32_t delta = t+initial_delay_us-cc3; diff --git a/ports/nrf/examples/ubluepy_eddystone.py b/ports/nrf/examples/ubluepy_eddystone.py index 1ebb2364d5..96818d01c2 100644 --- a/ports/nrf/examples/ubluepy_eddystone.py +++ b/ports/nrf/examples/ubluepy_eddystone.py @@ -53,7 +53,7 @@ def generate_eddystone_adv_packet(url): constants.ad_types.AD_TYPE_SERVICE_DATA, service_data ) - # generate advertisment packet + # generate advertisement packet packet = bytearray([]) packet.extend(packet_flags) packet.extend(packet_uuid16) diff --git a/ports/nrf/examples/ubluepy_temp.py b/ports/nrf/examples/ubluepy_temp.py index f841849dee..79c32a9da3 100644 --- a/ports/nrf/examples/ubluepy_temp.py +++ b/ports/nrf/examples/ubluepy_temp.py @@ -42,7 +42,7 @@ def event_handler(id, handle, data): rtc.stop() # indicate 'disconnected' LED(1).off() - # restart advertisment + # restart advertisement periph.advertise(device_name="micr_temp", services=[serv_env_sense]) elif id == constants.EVT_GATTS_WRITE: diff --git a/ports/nrf/modules/machine/pin.c b/ports/nrf/modules/machine/pin.c index db5cc9cbb1..974074fc91 100644 --- a/ports/nrf/modules/machine/pin.c +++ b/ports/nrf/modules/machine/pin.c @@ -618,7 +618,7 @@ MP_DEFINE_CONST_OBJ_TYPE( /// x3 = machine.Pin.board.X3 /// x3_af = x3.af_list() /// -/// x3_af will now contain an array of PinAF objects which are availble on +/// x3_af will now contain an array of PinAF objects which are available on /// pin X3. /// /// For the pyboard, x3_af would contain: diff --git a/ports/nrf/modules/machine/timer.c b/ports/nrf/modules/machine/timer.c index f6a0e54463..fbef0b0ef6 100644 --- a/ports/nrf/modules/machine/timer.c +++ b/ports/nrf/modules/machine/timer.c @@ -135,7 +135,7 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, } // Timer peripheral usage: - // Every timer instance has a numer of capture/compare (CC) registers. + // Every timer instance has a number of capture/compare (CC) registers. // These can store either the value to compare against (to trigger an // interrupt or a shortcut) or store a value returned from a // capture/compare event. diff --git a/ports/nrf/modules/ubluepy/modubluepy.h b/ports/nrf/modules/ubluepy/modubluepy.h index fbd07b8b9b..8f580acd0d 100644 --- a/ports/nrf/modules/ubluepy/modubluepy.h +++ b/ports/nrf/modules/ubluepy/modubluepy.h @@ -29,7 +29,7 @@ /* Examples: -Advertisment: +Advertisement: from ubluepy import Peripheral p = Peripheral() diff --git a/ports/nrf/modules/ubluepy/ubluepy_peripheral.c b/ports/nrf/modules/ubluepy/ubluepy_peripheral.c index d2a9e0011d..7de9aa26bb 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_peripheral.c +++ b/ports/nrf/modules/ubluepy/ubluepy_peripheral.c @@ -165,7 +165,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_conn_handler_obj, periph #if MICROPY_PY_UBLUEPY_PERIPHERAL /// \method advertise(device_name, [service=[service1, service2, ...]], [data=bytearray], [connectable=True]) -/// Start advertising. Connectable advertisment type by default. +/// Start advertising. Connectable advertisement type by default. /// STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { @@ -234,7 +234,7 @@ STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args, STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_advertise_obj, 0, peripheral_advertise); /// \method advertise_stop() -/// Stop advertisment if any onging advertisment. +/// Stop advertisement if any onging advertisement. /// STATIC mp_obj_t peripheral_advertise_stop(mp_obj_t self_in) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c b/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c index 2dd4f57860..626578360a 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c +++ b/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c @@ -71,7 +71,7 @@ STATIC mp_obj_t scan_entry_get_rssi(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_rssi_obj, scan_entry_get_rssi); /// \method getScanData() -/// Return list of the scan data tupples (ad_type, description, value) +/// Return list of the scan data tuples (ad_type, description, value) /// STATIC mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) { ubluepy_scan_entry_obj_t * self = MP_OBJ_TO_PTR(self_in); diff --git a/ports/nrf/modules/uos/microbitfs.c b/ports/nrf/modules/uos/microbitfs.c index fb88d47cc9..f4c2d20a09 100644 --- a/ports/nrf/modules/uos/microbitfs.c +++ b/ports/nrf/modules/uos/microbitfs.c @@ -127,7 +127,7 @@ extern const mp_obj_type_t uos_mbfs_textio_type; // Page indexes count down from the end of ROM. STATIC uint8_t first_page_index; STATIC uint8_t last_page_index; -// The number of useable chunks in the file system. +// The number of usable chunks in the file system. STATIC uint8_t chunks_in_file_system; // Index of chunk to start searches. This is randomised to even out wear. STATIC uint8_t start_index; diff --git a/ports/powerpc/head.S b/ports/powerpc/head.S index 09aa62e59c..f221114c7f 100644 --- a/ports/powerpc/head.S +++ b/ports/powerpc/head.S @@ -58,7 +58,7 @@ _start: b boot_entry -/* QEMU comes in at 0x10. Put a value in argc/r3 to distingush from +/* QEMU comes in at 0x10. Put a value in argc/r3 to distinguish from * microwatt. */ . = 0x10 FIXUP_ENDIAN diff --git a/ports/powerpc/powerpc.lds b/ports/powerpc/powerpc.lds index 93bd8a605c..545fa33011 100644 --- a/ports/powerpc/powerpc.lds +++ b/ports/powerpc/powerpc.lds @@ -6,7 +6,7 @@ SECTIONS KEEP(*(.head)) } - /* Put this at 0x1700 which is right after our execption + /* Put this at 0x1700 which is right after our exception * vectors in head.S. */ . = 0x1700; diff --git a/ports/rp2/boards/SPARKFUN_THINGPLUS/mpconfigboard.h b/ports/rp2/boards/SPARKFUN_THINGPLUS/mpconfigboard.h index c2ca90b968..7b5ced5de0 100644 --- a/ports/rp2/boards/SPARKFUN_THINGPLUS/mpconfigboard.h +++ b/ports/rp2/boards/SPARKFUN_THINGPLUS/mpconfigboard.h @@ -14,7 +14,7 @@ #define MICROPY_HW_SPI1_MOSI (15) #define MICROPY_HW_SPI1_MISO (12) -// Battery fuel guage MAX17048 on I2C1 +// Battery fuel gauge MAX17048 on I2C1 // BATT_ALERT GPIO24 // NeoPixel data GPIO8, power not toggleable diff --git a/ports/rp2/boards/make-pins.py b/ports/rp2/boards/make-pins.py index 55e7ebe01f..da575cf821 100755 --- a/ports/rp2/boards/make-pins.py +++ b/ports/rp2/boards/make-pins.py @@ -24,7 +24,7 @@ SUPPORTED_FN = { def parse_pin(name_str): """Parses a string and returns a pin number.""" if len(name_str) < 2: - raise ValueError("Expecting pin name to be at least 2 charcters.") + raise ValueError("Expecting pin name to be at least 2 characters.") if not name_str.startswith("GPIO") and not name_str.startswith("EXT_GPIO"): raise ValueError("Expecting pin name to start with EXT_/GPIO") return int(re.findall(r"\d+$", name_str)[0]) diff --git a/ports/rp2/memmap_mp.ld b/ports/rp2/memmap_mp.ld index 9db74ce9c9..0ed9509b82 100644 --- a/ports/rp2/memmap_mp.ld +++ b/ports/rp2/memmap_mp.ld @@ -68,7 +68,7 @@ SECTIONS /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from * FLASH ... we will include any thing excluded here in .data below by default */ *(.init) - /* Change for MicroPython... excluse gc.c, parse.c, vm.c from flash */ + /* Change for MicroPython... exclude gc.c, parse.c, vm.c from flash */ *(EXCLUDE_FILE(*libgcc.a: *libc.a: *lib_a-mem*.o *libm.a: *gc.c.obj *vm.c.obj *parse.c.obj) .text*) *(.fini) /* Pull all c'tors into .text */ diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c index 252f7b01fa..33dc698305 100644 --- a/ports/rp2/mpthreadport.c +++ b/ports/rp2/mpthreadport.c @@ -36,7 +36,7 @@ extern uint8_t __StackTop, __StackBottom; void *core_state[2]; -// This will be non-NULL while Python code is execting. +// This will be non-NULL while Python code is executing. STATIC void *(*core1_entry)(void *) = NULL; STATIC void *core1_arg = NULL; diff --git a/ports/samd/machine_adc.c b/ports/samd/machine_adc.c index d407882529..8f47fc6d15 100644 --- a/ports/samd/machine_adc.c +++ b/ports/samd/machine_adc.c @@ -113,7 +113,7 @@ STATIC mp_obj_t adc_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - // Unpack and check, whther the pin has ADC capability + // Unpack and check, whether the pin has ADC capability int id = mp_hal_get_pin_obj(args[ARG_id].u_obj); adc_config_t adc_config = get_adc_config(id, busy_flags); diff --git a/ports/samd/machine_i2c.c b/ports/samd/machine_i2c.c index 76d24674f0..330fa433d9 100644 --- a/ports/samd/machine_i2c.c +++ b/ports/samd/machine_i2c.c @@ -98,7 +98,7 @@ void common_i2c_irq_handler(int i2c_id) { i2c->I2CM.INTFLAG.reg |= SERCOM_I2CM_INTFLAG_SB; } } else if (IRQ_DATA_SENT) { - if (NACK_RECVD) { // e.g. NACK after adress for both read and write. + if (NACK_RECVD) { // e.g. NACK after address for both read and write. self->state = state_nack; // force stop of transmission i2c->I2CM.INTFLAG.reg |= SERCOM_I2CM_INTFLAG_MB; } else if (self->len > 0) { // data to be sent @@ -200,7 +200,7 @@ mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n #elif defined(MCU_SAMD51) NVIC_EnableIRQ(SERCOM0_0_IRQn + 4 * self->id); // MB interrupt NVIC_EnableIRQ(SERCOM0_0_IRQn + 4 * self->id + 1); // SB interrupt - NVIC_EnableIRQ(SERCOM0_0_IRQn + 4 * self->id + 3); // ERRROR interrupt + NVIC_EnableIRQ(SERCOM0_0_IRQn + 4 * self->id + 3); // ERROR interrupt #endif // Now enable I2C. @@ -230,7 +230,7 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si i2c->I2CM.INTENSET.reg = SERCOM_I2CM_INTENSET_MB | SERCOM_I2CM_INTENSET_SB | SERCOM_I2CM_INTENSET_ERROR; self->state = state_busy; - // Send the adress, which kicks off the transfer + // Send the address, which kicks off the transfer i2c->I2CM.ADDR.bit.ADDR = (addr << 1) | READ_MODE; // Transfer the data diff --git a/ports/samd/machine_uart.c b/ports/samd/machine_uart.c index 7917529fb9..ec1b42de9e 100644 --- a/ports/samd/machine_uart.c +++ b/ports/samd/machine_uart.c @@ -507,7 +507,7 @@ STATIC mp_uint_t machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint } } else if (request == MP_STREAM_FLUSH) { // The timeout is defined by the buffer size and the baudrate. - // Take the worst case assumtions at 13 bit symbol size times 2. + // Take the worst case assumptions at 13 bit symbol size times 2. uint64_t timeout = mp_hal_ticks_ms_64() + (3 #if MICROPY_HW_UART_TXBUF + self->write_buffer.size diff --git a/ports/samd/mcu/samd21/clock_config.c b/ports/samd/mcu/samd21/clock_config.c index d3c8c71995..4c05dd7cc7 100644 --- a/ports/samd/mcu/samd21/clock_config.c +++ b/ports/samd/mcu/samd21/clock_config.c @@ -125,14 +125,14 @@ void check_usb_recovery_mode(void) { // Purpose of the #defines for the clock configuration. // -// Both CPU and periperal devices are clocked by the DFLL48M clock. +// Both CPU and peripheral devices are clocked by the DFLL48M clock. // DFLL48M is either free running, or controlled by the 32kHz crystal, or // Synchronized with the USB clock. // // #define MICROPY_HW_XOSC32K (0 | 1) // // If MICROPY_HW_XOSC32K = 1, the 32kHz crystal is used as input for GCLK 1, which -// serves as refernce clock source for the DFLL48M oscillator, +// serves as reference clock source for the DFLL48M oscillator, // The crystal is used, unless MICROPY_HW_MCU_OSC32KULP is set. // In that case GCLK1 (and the CPU clock) is driven by the 32K Low power oscillator. // The reason for offering this option is a design flaw of the Adafruit @@ -147,11 +147,11 @@ void check_usb_recovery_mode(void) { // not exactly 48Mhz and has a substantional temperature drift. // // If MICROPY_HW_DFLL_USB_SYNC = 1, the DFLL48 is synchronized with the 1 kHz USB sync -// signal. If after boot there is no USB sync withing 500ms, the configuratuion falls +// signal. If after boot there is no USB sync within 500ms, the configuration falls // back to a free running 48Mhz oscillator. // // In all modes, the 48MHz signal has a substantial jitter, largest when -// MICROPY_HW_DFLL_USB_SYNC is active. That is caused by the repective +// MICROPY_HW_DFLL_USB_SYNC is active. That is caused by the respective // reference frequencies of 32kHz or 1 kHz being low. That affects most // PWM. Std Dev at 1kHz 0.156Hz (w. Crystal) up to 0.4 Hz (with USB sync). // @@ -171,7 +171,7 @@ void init_clocks(uint32_t cpu_freq) { // GCLK5: 48MHz, source: DFLL48M, usage: USB // GCLK8: 1kHz, source: XOSC32K or OSCULP32K, usage: WDT and RTC // DFLL48M: Reference sources: - // - in closed loop mode: eiter XOSC32K or OSCULP32K or USB clock + // - in closed loop mode: either XOSC32K or OSCULP32K or USB clock // from GCLK4. // - in open loop mode: None // FDPLL96M: Reference source GCLK1 diff --git a/ports/samd/mcu/samd21/pin-af-table.csv b/ports/samd/mcu/samd21/pin-af-table.csv index 6445d148b8..b74db0c8ef 100644 --- a/ports/samd/mcu/samd21/pin-af-table.csv +++ b/ports/samd/mcu/samd21/pin-af-table.csv @@ -2,7 +2,7 @@ # for some of the peripheral devices with many possible assignments. # The pin_cap_table is a subset from table 7-1 of the data sheet. # It contain the information about pin mux set and pad -# The eic and adc columns contain the decimal numer for the respecitive +# The eic and adc columns contain the decimal number for the respecitive # quantity, the columns for sercom, tc and tcc have in each cell # the device number in the upper nibble, and the pad number in the lower # nibble. If a signal is not available, the cell in the csv table is left empty. diff --git a/ports/samd/mcu/samd51/clock_config.c b/ports/samd/mcu/samd51/clock_config.c index 5cf543252e..50912b77ed 100644 --- a/ports/samd/mcu/samd51/clock_config.c +++ b/ports/samd/mcu/samd51/clock_config.c @@ -172,11 +172,11 @@ void check_usb_recovery_mode(void) { // not exactly 48Mhz and has a substantional temperature drift. // // If MICROPY_HW_DFLL_USB_SYNC = 1, the DFLL48 is synchronized with the 1 kHz USB sync -// signal. If after boot there is no USB sync withing 500ms, the configuratuion falls +// signal. If after boot there is no USB sync within 500ms, the configuration falls // back to a free running 48Mhz oscillator. // // In all modes, the 48MHz signal has a substantial jitter, largest when -// MICROPY_HW_DFLL_USB_SYNC is active. That is caused by the repective +// MICROPY_HW_DFLL_USB_SYNC is active. That is caused by the respective // reference frequencies of 32kHz or 1 kHz being low. That affects most // PWM. Std Dev at 1kHz 0.156Hz (w. Crystal) up to 0.4 Hz (with USB sync). // @@ -195,7 +195,7 @@ void init_clocks(uint32_t cpu_freq) { // GCLK4: 32kHz, source: XOSC32K, if crystal present, usage: DFLL48M reference // GCLK5: 48MHz, source: DFLL48M, usage: USB // DFLL48M: Reference sources: - // - in closed loop mode: eiter XOSC32K or OSCULP32K or USB clock + // - in closed loop mode: either XOSC32K or OSCULP32K or USB clock // - in open loop mode: None // DPLL0: 48 - 200 MHz diff --git a/ports/samd/mcu/samd51/pin-af-table.csv b/ports/samd/mcu/samd51/pin-af-table.csv index 70a009ba52..249ce6865c 100644 --- a/ports/samd/mcu/samd51/pin-af-table.csv +++ b/ports/samd/mcu/samd51/pin-af-table.csv @@ -1,9 +1,9 @@ # The pin_cap_table is a subset from table 6-1 of the data sheet. # It contain the information about pin mux set and pad # for some of the peripheral devices with many possible assignments. -# The colums represent the peripheral class, as defined in pin_cap_t. The +# The columns represent the peripheral class, as defined in pin_cap_t. The # column number is equivalent to the mux class. -# The eic and adc columns contain the decimal numer for the respecitive +# The eic and adc columns contain the decimal number for the respecitive # quantity, the columns for sercom, tc and tcc have in each cell # the device number in the first, and the pad number in the second # digit. If a signal is not available, the cell in the csv table is left empty. diff --git a/ports/samd/pin_af.c b/ports/samd/pin_af.c index d92a62b700..2664fd4109 100644 --- a/ports/samd/pin_af.c +++ b/ports/samd/pin_af.c @@ -121,7 +121,7 @@ const char *pin_name(int id) { return "-"; } -// Test, wether the given pin is defined and has signals for sercom. +// Test, whether the given pin is defined and has signals for sercom. // If that applies return the alt_fct and pad_nr. // If not, an error will be raised. @@ -136,7 +136,7 @@ sercom_pad_config_t get_sercom_config(int pin_id, uint8_t sercom_nr) { } } -// Test, wether the given pin is defined as ADC. +// Test, whether the given pin is defined as ADC. // If that applies return the adc instance and channel. // If not, an error will be raised. @@ -158,7 +158,7 @@ adc_config_t get_adc_config(int pin_id, int32_t flag) { } } -// Test, wether the given pin is defined and has signals for pwm. +// Test, whether the given pin is defined and has signals for pwm. // If that applies return the alt_fct, tcc number and channel number. // If not, an error will be raised. // The function either supplies a channel from a wanted device, or diff --git a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h index cc38b0a7ca..dee0106b96 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h @@ -163,7 +163,7 @@ extern struct _spi_bdev_t spi_bdev; #define MICROPY_HW_UART7_RTS (pyb_pin_BT_RTS) #define MICROPY_HW_UART7_CTS (pyb_pin_BT_CTS) -// I2C busses +// I2C buses #define MICROPY_HW_I2C1_SCL (pyb_pin_I2C1_SCL) #define MICROPY_HW_I2C1_SDA (pyb_pin_I2C1_SDA) diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/board_init.c b/ports/stm32/boards/ARDUINO_NICLA_VISION/board_init.c index 5ca495a606..ed8c609275 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/board_init.c +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/board_init.c @@ -212,7 +212,7 @@ void NICLAV_board_low_power(int mode) { // Disable all power rails, except core voltage. NICLAV_board_pmic_enable(false); - // Reset all busses, peripherals, GPIO clocks etc.. + // Reset all buses, peripherals, GPIO clocks etc.. RCC->AHB1RSTR = 0x0A00C023U; RCC->AHB2RSTR = 0x00000271U; RCC->AHB3RSTR = 0x00015031U; diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h index c47024b97d..e96d5b6a64 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h @@ -156,7 +156,7 @@ extern struct _spi_bdev_t spi_bdev; #define MICROPY_HW_LPUART1_TX (pin_A9) #define MICROPY_HW_LPUART1_RX (pin_A10) -// I2C busses +// I2C buses #define MICROPY_HW_I2C1_SCL (pin_B8) #define MICROPY_HW_I2C1_SDA (pin_B9) diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h index 674154b316..529f4d6f2a 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h @@ -161,7 +161,7 @@ extern struct _spi_bdev_t spi_bdev; #define MICROPY_HW_UART7_RTS (pyb_pin_BT_RTS) #define MICROPY_HW_UART7_CTS (pyb_pin_BT_CTS) -// I2C busses +// I2C buses #define MICROPY_HW_I2C1_SCL (pin_B6) #define MICROPY_HW_I2C1_SDA (pin_B7) diff --git a/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.h b/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.h index b017edab99..69bedd2de7 100644 --- a/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.h +++ b/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.h @@ -20,7 +20,7 @@ // USART1 config connected to ST-Link #define MICROPY_HW_UART1_TX (pin_B6) #define MICROPY_HW_UART1_RX (pin_B7) -// USART2 config connected to PMOD: Flow control is defined and therfore used +// USART2 config connected to PMOD: Flow control is defined and therefore used #define MICROPY_HW_UART2_CTS (pin_D3) #define MICROPY_HW_UART2_RTS (pin_D4) #define MICROPY_HW_UART2_TX (pin_D5) diff --git a/ports/stm32/boards/LEGO_HUB_NO6/README.md b/ports/stm32/boards/LEGO_HUB_NO6/README.md index cc67b6a4bb..a80059d19a 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/README.md +++ b/ports/stm32/boards/LEGO_HUB_NO6/README.md @@ -24,7 +24,7 @@ The built-in bootloader has some drawbacks: it cannot be entered programmaticall and it does not keep the Hub powered up when running from battery (which requires keeping BAT_PWR_EN high). As such, this board is configured to work with mboot as a secondary bootloader: mboot is placed at 0x08008000 and the main application -firmware at 0x08010000. When mboot is installed it can be entered programatically +firmware at 0x08010000. When mboot is installed it can be entered programmatically via machine.bootloader(), or by holding down the left arrow button when powering on the Hub and waiting until the display says "B" before releasing the button. diff --git a/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py b/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py index 57b24d3f2e..02398e8124 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py +++ b/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py @@ -1,4 +1,4 @@ -# Application firmware update funcion for LEGO_HUB_NO6. +# Application firmware update function for LEGO_HUB_NO6. # MIT license; Copyright (c) 2022 Damien P. George from micropython import const diff --git a/ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.h b/ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.h index 7f0b1fbe45..ffc53fa6fc 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.h +++ b/ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.h @@ -101,7 +101,7 @@ spi_bdev_ioctl(&spi_bdev, (op), (arg)) \ ) -// Configuration for stardard block protocol (block size FLASH_BLOCK_SIZE). +// Configuration for standard block protocol (block size FLASH_BLOCK_SIZE). #define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) \ spi_bdev_readblocks(&spi_bdev, (dest), MICROPY_HW_SPIFLASH_BLOCKMAP(bl), (n)) #define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) \ diff --git a/ports/stm32/boards/LEGO_HUB_NO7/README.md b/ports/stm32/boards/LEGO_HUB_NO7/README.md index 8159cf3f47..0cae109284 100644 --- a/ports/stm32/boards/LEGO_HUB_NO7/README.md +++ b/ports/stm32/boards/LEGO_HUB_NO7/README.md @@ -23,7 +23,7 @@ The built-in bootloader has some drawbacks: it cannot be entered programmaticall and it does not keep the Hub powered up when running from battery (which requires keeping BAT_PWR_EN high). As such, this board is configured to work with mboot as a secondary bootloader: mboot is placed at 0x08008000 and the main application -firmware at 0x08010000. When mboot is installed it can be entered programatically +firmware at 0x08010000. When mboot is installed it can be entered programmatically via machine.bootloader(). Backing up original Hub firmware diff --git a/ports/stm32/boards/LEGO_HUB_NO7/mpconfigboard.h b/ports/stm32/boards/LEGO_HUB_NO7/mpconfigboard.h index 50fb6c0607..3615225e51 100644 --- a/ports/stm32/boards/LEGO_HUB_NO7/mpconfigboard.h +++ b/ports/stm32/boards/LEGO_HUB_NO7/mpconfigboard.h @@ -82,7 +82,7 @@ spi_bdev_ioctl(&spi_bdev, (op), (arg)) \ ) -// Configuration for stardard block protocol (block size FLASH_BLOCK_SIZE). +// Configuration for standard block protocol (block size FLASH_BLOCK_SIZE). #define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) \ spi_bdev_readblocks(&spi_bdev, (dest), MICROPY_HW_SPIFLASH_BLOCKMAP(bl), (n)) #define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) \ diff --git a/ports/stm32/boards/LIMIFROG/board_init.c b/ports/stm32/boards/LIMIFROG/board_init.c index 1b4d9494fb..de9d65295a 100644 --- a/ports/stm32/boards/LIMIFROG/board_init.c +++ b/ports/stm32/boards/LIMIFROG/board_init.c @@ -59,7 +59,7 @@ static inline int IS_GPIO_RESET(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) { - The STM32 embeds in ROM a bootloader that allows to obtain code and boot from a number of different interfaces, - including USB in a mode called "DFU" (Device Frimware Update) + including USB in a mode called "DFU" (Device Firmware Update) [see AN3606 from ST for full details] This bootloader code is executed instead of the regular application code when pin BOOT0 is pulled-up (which on @@ -79,7 +79,7 @@ static inline int IS_GPIO_RESET(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) { other applicative code, of whether USB bootload is required (as flagged by a GPIO pulled low at reset, in the same way as BOOT0). The hadware reset pin of BLE is asserted (so that now it won't - generate any acitivity on UART3), and if USB bootload is required : + generate any activity on UART3), and if USB bootload is required : bootload ROM is remapped at address 0x0, stack pointer is updated and the code is branched to the start of the bootloader. - This code is run prior to any applicative configuration of clocks, diff --git a/ports/stm32/boards/common_ifs.ld b/ports/stm32/boards/common_ifs.ld index 1876e41561..33fa948bb7 100644 --- a/ports/stm32/boards/common_ifs.ld +++ b/ports/stm32/boards/common_ifs.ld @@ -24,7 +24,7 @@ SECTIONS . = ALIGN(4); KEEP(*(.isr_vector)) /* Startup code */ - /* This first flash block is 16K annd the isr vectors only take up + /* This first flash block is 16K and the isr vectors only take up about 400 bytes. So we pull in a couple of object files to pad it out. */ diff --git a/ports/stm32/boards/make-pins.py b/ports/stm32/boards/make-pins.py index 002a6f75f2..a3e6ee0669 100755 --- a/ports/stm32/boards/make-pins.py +++ b/ports/stm32/boards/make-pins.py @@ -80,7 +80,7 @@ CONDITIONAL_VAR = { def parse_port_pin(name_str): """Parses a string and returns a (port-num, pin-num) tuple.""" if len(name_str) < 3: - raise ValueError("Expecting pin name to be at least 3 charcters.") + raise ValueError("Expecting pin name to be at least 3 characters.") if name_str[0] != "P": raise ValueError("Expecting pin name to start with P") if name_str[1] < "A" or name_str[1] > "K": diff --git a/ports/stm32/eth.c b/ports/stm32/eth.c index 1207a728c3..0feacdae2d 100644 --- a/ports/stm32/eth.c +++ b/ports/stm32/eth.c @@ -307,7 +307,7 @@ STATIC int eth_mac_init(eth_t *self) { #endif #if defined(STM32H7) - // don't skip 32bit words since our desriptors are continuous in memory + // don't skip 32bit words since our descriptors are continuous in memory ETH->DMACCR &= ~(ETH_DMACCR_DSL_Msk); #endif diff --git a/ports/stm32/machine_spi.c b/ports/stm32/machine_spi.c index ddbd42bf29..c6d6015731 100644 --- a/ports/stm32/machine_spi.c +++ b/ports/stm32/machine_spi.c @@ -85,7 +85,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz init->CRCCalculation = SPI_CRCCALCULATION_DISABLE; init->CRCPolynomial = 0; - // set configurable paramaters + // set configurable parameters spi_set_params(self->spi, 0xffffffff, args[ARG_baudrate].u_int, args[ARG_polarity].u_int, args[ARG_phase].u_int, args[ARG_bits].u_int, args[ARG_firstbit].u_int); diff --git a/ports/stm32/machine_uart.c b/ports/stm32/machine_uart.c index bb35bac5cc..20def373fb 100644 --- a/ports/stm32/machine_uart.c +++ b/ports/stm32/machine_uart.c @@ -644,7 +644,7 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t a ret |= MP_STREAM_POLL_WR; } } else if (request == MP_STREAM_FLUSH) { - // Since uart.write() waits up to the last byte, uart.flush() always succeds. + // Since uart.write() waits up to the last byte, uart.flush() always succeeds. ret = 0; } else { *errcode = MP_EINVAL; diff --git a/ports/stm32/mboot/README.md b/ports/stm32/mboot/README.md index 936b587608..73e32fcedc 100644 --- a/ports/stm32/mboot/README.md +++ b/ports/stm32/mboot/README.md @@ -225,7 +225,7 @@ In detail for PYBv1.0 (for PYBv1.1 use PYBV11 instead of PYBV10): $ make BOARD=PYBV10 USE_MBOOT=1 clean all deploy - MicroPython will now be on the device and should boot straightaway. + MicroPython will now be on the device and should boot straight away. On PYBv1.x without mboot the flash layout is as follows: diff --git a/ports/stm32/mboot/fwupdate.py b/ports/stm32/mboot/fwupdate.py index ba36b7965b..4bf07f5a33 100644 --- a/ports/stm32/mboot/fwupdate.py +++ b/ports/stm32/mboot/fwupdate.py @@ -252,7 +252,7 @@ def update_app_elements( _ELEM_TYPE_FSLOAD, struct.pack("bmRequest == 0x21) { // host-to-device request if (req->wLength == 0) { - // no data, process command straightaway + // no data, process command straight away dfu_handle_rx(self->bRequest, self->wValue, 0, NULL); } else { // have data, prepare to receive it @@ -1538,7 +1538,7 @@ void PendSV_Handler(void) { void SysTick_Handler(void) { systick_ms += 1; - // Read the systick control regster. This has the side effect of clearing + // Read the systick control register. This has the side effect of clearing // the COUNTFLAG bit, which makes the logic in mp_hal_ticks_us // work properly. SysTick->CTRL; diff --git a/ports/stm32/mboot/mboot.h b/ports/stm32/mboot/mboot.h index 2fce9a230d..2c48133327 100644 --- a/ports/stm32/mboot/mboot.h +++ b/ports/stm32/mboot/mboot.h @@ -82,7 +82,7 @@ #define MBOOT_ADDRESS_SPACE_64BIT (0) #endif -// These values are used in initial_r0 to enter mboot programatically. +// These values are used in initial_r0 to enter mboot programmatically. #define MBOOT_INITIAL_R0_KEY (0x70ad0000) #define MBOOT_INITIAL_R0_KEY_FSLOAD (MBOOT_INITIAL_R0_KEY | 0x80) diff --git a/ports/stm32/mboot/mboot_pack_dfu.py b/ports/stm32/mboot/mboot_pack_dfu.py index 683cdd0a71..0b2919a0c2 100644 --- a/ports/stm32/mboot/mboot_pack_dfu.py +++ b/ports/stm32/mboot/mboot_pack_dfu.py @@ -43,7 +43,7 @@ except ImportError: ) -# Currenty supported version of a packed DFU file. +# Currently supported version of a packed DFU file. MBOOT_PACK_HEADER_VERSION = 1 # Must match MBOOT_PACK_HYDRO_CONTEXT in mboot/pack.h diff --git a/ports/stm32/mboot/pack.h b/ports/stm32/mboot/pack.h index 3578d9d127..91f4896ccd 100644 --- a/ports/stm32/mboot/pack.h +++ b/ports/stm32/mboot/pack.h @@ -53,7 +53,7 @@ enum mboot_pack_chunk_format { MBOOT_PACK_CHUNK_FW_GZIP = 3, }; -// Each DFU chunk transfered has this header to validate it. +// Each DFU chunk transferred has this header to validate it. typedef struct _mboot_pack_chunk_buf_t { struct { diff --git a/ports/stm32/pendsv.c b/ports/stm32/pendsv.c index d4c4496f1b..9c908addb5 100644 --- a/ports/stm32/pendsv.c +++ b/ports/stm32/pendsv.c @@ -164,7 +164,7 @@ __attribute__((naked)) void PendSV_Handler(void) { "bl pyb_thread_next\n" // get next thread to execute "mov lr, r4\n" // restore lr "mov sp, r0\n" // switch stacks - "msr primask, r5\n" // reenable interrupts + "msr primask, r5\n" // re-enable interrupts "vpop {s16-s31}\n" "pop {r4-r11, lr}\n" "bx lr\n" // return from interrupt; will return to new thread diff --git a/ports/stm32/pin.c b/ports/stm32/pin.c index 8503f3dbe0..f2db0e20e8 100644 --- a/ports/stm32/pin.c +++ b/ports/stm32/pin.c @@ -613,7 +613,7 @@ MP_DEFINE_CONST_OBJ_TYPE( /// x3 = pyb.Pin.board.X3 /// x3_af = x3.af_list() /// -/// x3_af will now contain an array of PinAF objects which are availble on +/// x3_af will now contain an array of PinAF objects which are available on /// pin X3. /// /// For the pyboard, x3_af would contain: diff --git a/ports/stm32/powerctrl.c b/ports/stm32/powerctrl.c index 0ab80b487a..d5fa9095d8 100644 --- a/ports/stm32/powerctrl.c +++ b/ports/stm32/powerctrl.c @@ -382,7 +382,7 @@ STATIC uint32_t calc_apb2_div(uint32_t wanted_div) { #if defined(STM32F4) || defined(STM32F7) || defined(STM32G0) || defined(STM32G4) || defined(STM32H7) int powerctrl_set_sysclk(uint32_t sysclk, uint32_t ahb, uint32_t apb1, uint32_t apb2) { - // Return straightaway if the clocks are already at the desired frequency + // Return straight away if the clocks are already at the desired frequency if (sysclk == HAL_RCC_GetSysClockFreq() && ahb == HAL_RCC_GetHCLKFreq() && apb1 == HAL_RCC_GetPCLK1Freq() @@ -659,7 +659,7 @@ int powerctrl_set_sysclk(uint32_t sysclk, uint32_t ahb, uint32_t apb1, uint32_t powerctrl_config_systick(); } - // Return straightaway if the clocks are already at the desired frequency. + // Return straight away if the clocks are already at the desired frequency. if (ahb == HAL_RCC_GetHCLKFreq() && apb1 == HAL_RCC_GetPCLK1Freq() && apb2 == HAL_RCC_GetPCLK2Freq()) { diff --git a/ports/stm32/pyb_can.c b/ports/stm32/pyb_can.c index 69e807c79d..3c61405e7c 100644 --- a/ports/stm32/pyb_can.c +++ b/ports/stm32/pyb_can.c @@ -917,7 +917,7 @@ STATIC mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_ma goto error; } } else { - if (filter.FilterNumber > 13) { // CAN3 is independant and has its own 14 filters. + if (filter.FilterNumber > 13) { // CAN3 is independent and has its own 14 filters. goto error; } } diff --git a/ports/stm32/pyb_i2c.c b/ports/stm32/pyb_i2c.c index 6bf04aa1b1..915eabe0b2 100644 --- a/ports/stm32/pyb_i2c.c +++ b/ports/stm32/pyb_i2c.c @@ -67,7 +67,7 @@ /// /// You can specify a timeout (in ms): /// -/// i2c.send(b'123', timeout=2000) # timout after 2 seconds +/// i2c.send(b'123', timeout=2000) # timeout after 2 seconds /// /// A controller must specify the recipient's address: /// diff --git a/ports/stm32/rfcore.c b/ports/stm32/rfcore.c index 2a75f7c74a..2e660d6d9e 100644 --- a/ports/stm32/rfcore.c +++ b/ports/stm32/rfcore.c @@ -451,7 +451,7 @@ STATIC size_t tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse LL_C1_IPCC_ClearFlag_CHx(IPCC, ch); if (ch == IPCC_CH_BLE) { - // Renable IRQs for BLE now that we've cleared the flag. + // Re-enable IRQs for BLE now that we've cleared the flag. LL_C1_IPCC_EnableReceiveChannel(IPCC, IPCC_CH_BLE); } } diff --git a/ports/stm32/sdcard.c b/ports/stm32/sdcard.c index 964ed49a67..d09ee21d09 100644 --- a/ports/stm32/sdcard.c +++ b/ports/stm32/sdcard.c @@ -86,7 +86,7 @@ #endif // The F7 & L4 series calls the peripheral SDMMC rather than SDIO, so provide some -// #defines for backwards compatability. +// #defines for backwards compatibility. #define SDIO_CLOCK_EDGE_RISING SDMMC_CLOCK_EDGE_RISING #define SDIO_CLOCK_EDGE_FALLING SDMMC_CLOCK_EDGE_FALLING diff --git a/ports/stm32/sdram.c b/ports/stm32/sdram.c index fb0e5a8688..b0a3ef2157 100644 --- a/ports/stm32/sdram.c +++ b/ports/stm32/sdram.c @@ -346,7 +346,7 @@ bool __attribute__((optimize("Os"))) sdram_test(bool exhaustive) { } } - // Check for aliasing (overlaping addresses) + // Check for aliasing (overlapping addresses) mem_base[0] = antipattern; __DSB(); for (uint32_t i = 1; i < MICROPY_HW_SDRAM_SIZE; i <<= 1) { diff --git a/ports/stm32/system_stm32.c b/ports/stm32/system_stm32.c index 08f071cd27..de1897b4a6 100644 --- a/ports/stm32/system_stm32.c +++ b/ports/stm32/system_stm32.c @@ -190,7 +190,7 @@ MP_WEAK void SystemClock_Config(void) { #endif #if defined(STM32H7) - // Wait untill the voltage levels are valid. + // Wait until the voltage levels are valid. while (!__HAL_PWR_GET_FLAG(PWR_FLAG_ACTVOSRDY)) { } diff --git a/ports/stm32/systick.c b/ports/stm32/systick.c index 76944d312a..0fd7d3b8fb 100644 --- a/ports/stm32/systick.c +++ b/ports/stm32/systick.c @@ -43,7 +43,7 @@ void SysTick_Handler(void) { uint32_t uw_tick = uwTick + 1; uwTick = uw_tick; - // Read the systick control regster. This has the side effect of clearing + // Read the systick control register. This has the side effect of clearing // the COUNTFLAG bit, which makes the logic in mp_hal_ticks_us // work properly. SysTick->CTRL; diff --git a/ports/stm32/timer.c b/ports/stm32/timer.c index 8816c218f5..6c110f87ea 100644 --- a/ports/stm32/timer.c +++ b/ports/stm32/timer.c @@ -436,7 +436,7 @@ STATIC mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) { // Computes the 8-bit value for the DTG field in the BDTR register. // // 1 tick = 1 count of the timer's clock (source_freq) divided by div. -// 0-128 ticks in inrements of 1 +// 0-128 ticks in increments of 1 // 128-256 ticks in increments of 2 // 256-512 ticks in increments of 8 // 512-1008 ticks in increments of 16 @@ -554,7 +554,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// /// Keyword arguments: /// -/// - `freq` - specifies the periodic frequency of the timer. You migh also +/// - `freq` - specifies the periodic frequency of the timer. You might also /// view this as the frequency with which the timer goes through /// one complete cycle. /// @@ -1009,7 +1009,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); /// If only a channel number is passed, then a previously initialized channel /// object is returned (or `None` if there is no previous channel). /// -/// Othwerwise, a TimerChannel object is initialized and returned. +/// Otherwise, a TimerChannel object is initialized and returned. /// /// Each channel can be configured to perform pwm, output compare, or /// input capture. All channels share the same underlying timer, which means @@ -1051,7 +1051,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); /// /// - `polarity` can be one of: /// - `Timer.HIGH` - output is active high -/// - `Timer.LOW` - output is acive low +/// - `Timer.LOW` - output is active low /// /// Optional keyword arguments for Timer.IC modes: /// diff --git a/ports/stm32/usbd_cdc_interface.c b/ports/stm32/usbd_cdc_interface.c index 5432370a74..399411d8ab 100644 --- a/ports/stm32/usbd_cdc_interface.c +++ b/ports/stm32/usbd_cdc_interface.c @@ -357,7 +357,7 @@ int usbd_cdc_tx_flow(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len) { } } -// timout in milliseconds. +// timeout in milliseconds. // Returns number of bytes written to the device. int usbd_cdc_tx(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len, uint32_t timeout) { for (uint32_t i = 0; i < len; i++) { @@ -430,7 +430,7 @@ int usbd_cdc_rx_num(usbd_cdc_itf_t *cdc) { return rx_waiting; } -// timout in milliseconds. +// timeout in milliseconds. // Returns number of bytes read from the device. int usbd_cdc_rx(usbd_cdc_itf_t *cdc, uint8_t *buf, uint32_t len, uint32_t timeout) { // loop to read bytes diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c index 3891d09ce1..a643c1eb6f 100644 --- a/ports/stm32/usbd_conf.c +++ b/ports/stm32/usbd_conf.c @@ -687,10 +687,10 @@ USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, } /** - * @brief Returns the last transfered packet size. + * @brief Returns the last transferred packet size. * @param pdev: Device handle * @param ep_addr: Endpoint Number - * @retval Recived Data Size + * @retval Received Data Size */ uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { return HAL_PCD_EP_GetRxCount(pdev->pData, ep_addr); diff --git a/ports/stm32/usbd_desc.c b/ports/stm32/usbd_desc.c index 3f6b74b800..db94fd2be8 100644 --- a/ports/stm32/usbd_desc.c +++ b/ports/stm32/usbd_desc.c @@ -8,7 +8,7 @@ * @author MCD Application Team * @version V1.0.1 * @date 26-February-2014 - * @brief This file provides the USBD descriptors and string formating method. + * @brief This file provides the USBD descriptors and string formatting method. ****************************************************************************** * @attention * @@ -129,7 +129,7 @@ STATIC uint8_t *USBD_StrDescriptor(USBD_HandleTypeDef *pdev, uint8_t idx, uint16 // the 96-bit unique ID, so for consistency we go with this algorithm. // You can see the serial number if you use: lsusb -v // - // See: https://my.st.com/52d187b7 for the algorithim used. + // See: https://my.st.com/52d187b7 for the algorithm used. uint8_t *id = (uint8_t *)MP_HAL_UNIQUE_ID_ADDRESS; snprintf(str_buf, sizeof(str_buf), diff --git a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c index c32c20ab58..65d2fd70e5 100644 --- a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c +++ b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c @@ -204,7 +204,7 @@ static const uint8_t cdc_class_desc_data[CDC_CLASS_DESC_SIZE] = { 0x08, // bLength: 8 bytes USB_DESC_TYPE_ASSOCIATION, // bDescriptorType: IAD 0x00, // bFirstInterface: first interface for this association -- to be filled in - 0x02, // bInterfaceCount: nummber of interfaces for this association + 0x02, // bInterfaceCount: number of interfaces for this association 0x02, // bFunctionClass: Communication Interface Class 0x02, // bFunctionSubClass: Abstract Control Model 0x01, // bFunctionProtocol: Common AT commands diff --git a/ports/stm32/usbdev/class/src/usbd_msc_bot.c b/ports/stm32/usbdev/class/src/usbd_msc_bot.c index 44a74a6602..5bda0f8653 100644 --- a/ports/stm32/usbdev/class/src/usbd_msc_bot.c +++ b/ports/stm32/usbdev/class/src/usbd_msc_bot.c @@ -193,7 +193,7 @@ void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev, } /** * @brief MSC_BOT_DataOut -* Proccess MSC OUT data +* Process MSC OUT data * @param pdev: device instance * @param epnum: endpoint index * @retval None diff --git a/ports/stm32/usbdev/core/src/usbd_core.c b/ports/stm32/usbdev/core/src/usbd_core.c index 4c69a77eb6..13a8faed31 100644 --- a/ports/stm32/usbdev/core/src/usbd_core.c +++ b/ports/stm32/usbdev/core/src/usbd_core.c @@ -88,7 +88,7 @@ #if 0 /** * @brief USBD_Init -* Initailizes the device stack and load the class driver +* Initializes the device stack and load the class driver * @param pdev: device instance * @param core_address: USB OTG core ID * @param pdesc: Descriptor structure address diff --git a/ports/teensy/core/mk20dx128.c b/ports/teensy/core/mk20dx128.c index 0f5f1e19e2..f79bf436f4 100644 --- a/ports/teensy/core/mk20dx128.c +++ b/ports/teensy/core/mk20dx128.c @@ -561,7 +561,7 @@ void ResetHandler(void) _init_Teensyduino_internal_(); if (RTC_SR & RTC_SR_TIF) { - // TODO: this should probably set the time more agressively, if + // TODO: this should probably set the time more aggressively, if // we could reliably detect the first reboot after programming. rtc_set(TIME_T); } diff --git a/ports/teensy/core/mk20dx128.h b/ports/teensy/core/mk20dx128.h index ab13760508..c6eda2837f 100644 --- a/ports/teensy/core/mk20dx128.h +++ b/ports/teensy/core/mk20dx128.h @@ -1018,7 +1018,7 @@ extern "C" { #define MCG_C6_VDIV0(n) (uint8_t)((n) & 0x1F) // VCO 0 Divider #define MCG_C6_CME0 (uint8_t)0x20 // Clock Monitor Enable #define MCG_C6_PLLS (uint8_t)0x40 // PLL Select, Controls whether the PLL or FLL output is selected as the MCG source when CLKS[1:0]=00. -#define MCG_C6_LOLIE0 (uint8_t)0x80 // Loss of Lock Interrrupt Enable +#define MCG_C6_LOLIE0 (uint8_t)0x80 // Loss of Lock Interrupt Enable #define MCG_S *(volatile uint8_t *)0x40064006 // MCG Status Register #define MCG_S_IRCST (uint8_t)0x01 // Internal Reference Clock Status #define MCG_S_OSCINIT0 (uint8_t)0x02 // OSC Initialization, resets to 0, is set to 1 after the initialization cycles of the crystal oscillator diff --git a/ports/teensy/core/usb_desc.c b/ports/teensy/core/usb_desc.c index 828a61967f..cc1103b9f0 100644 --- a/ports/teensy/core/usb_desc.c +++ b/ports/teensy/core/usb_desc.c @@ -799,9 +799,9 @@ const usb_descriptor_list_t usb_descriptor_list[] = { #if 0 // 0x00 = not used -// 0x19 = Recieve only +// 0x19 = Receive only // 0x15 = Transmit only -// 0x1D = Transmit & Recieve +// 0x1D = Transmit & Receive // const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] = { diff --git a/ports/teensy/core/usb_desc.h b/ports/teensy/core/usb_desc.h index a951e03f61..49ecf86aeb 100644 --- a/ports/teensy/core/usb_desc.h +++ b/ports/teensy/core/usb_desc.h @@ -69,7 +69,7 @@ automatically adapt to the changes you specify. If you need to create a new type of interface, you'll need to write the code which sends and receives packets, and presents an API to the user. -Finally, edit usb_inst.cpp, which creats instances of the C++ +Finally, edit usb_inst.cpp, which creates instances of the C++ objects for each combination. Some operating systems, especially Windows, may cache USB device diff --git a/ports/teensy/make-pins.py b/ports/teensy/make-pins.py index 4e46a8c244..844e2d8bc3 100755 --- a/ports/teensy/make-pins.py +++ b/ports/teensy/make-pins.py @@ -18,7 +18,7 @@ SUPPORTED_FN = { def parse_port_pin(name_str): """Parses a string and returns a (port-num, pin-num) tuple.""" if len(name_str) < 4: - raise ValueError("Expecting pin name to be at least 4 charcters.") + raise ValueError("Expecting pin name to be at least 4 characters.") if name_str[0:2] != "PT": raise ValueError("Expecting pin name to start with PT") if name_str[2] not in ("A", "B", "C", "D", "E", "Z"): diff --git a/ports/teensy/modpyb.c b/ports/teensy/modpyb.c index b48fecc18f..5dae8f73e5 100644 --- a/ports/teensy/modpyb.c +++ b/ports/teensy/modpyb.c @@ -165,7 +165,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis); /// Returns the number of milliseconds which have elapsed since `start`. /// /// This function takes care of counter wrap, and always returns a positive -/// number. This means it can be used to measure periods upto about 12.4 days. +/// number. This means it can be used to measure periods up to about 12.4 days. /// /// Example: /// start = pyb.millis() @@ -196,7 +196,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_micros_obj, pyb_micros); /// Returns the number of microseconds which have elapsed since `start`. /// /// This function takes care of counter wrap, and always returns a positive -/// number. This means it can be used to measure periods upto about 17.8 minutes. +/// number. This means it can be used to measure periods up to about 17.8 minutes. /// /// Example: /// start = pyb.micros() diff --git a/ports/teensy/timer.c b/ports/teensy/timer.c index 8c7609e447..56d25e3312 100644 --- a/ports/teensy/timer.c +++ b/ports/teensy/timer.c @@ -209,7 +209,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// /// Keyword arguments: /// -/// - `freq` - specifies the periodic frequency of the timer. You migh also +/// - `freq` - specifies the periodic frequency of the timer. You might also /// view this as the frequency with which the timer goes through /// one complete cycle. /// @@ -388,7 +388,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); /// If only a channel number is passed, then a previously initialized channel /// object is returned (or `None` if there is no previous channel). /// -/// Othwerwise, a TimerChannel object is initialized and returned. +/// Otherwise, a TimerChannel object is initialized and returned. /// /// Each channel can be configured to perform pwm, output compare, or /// input capture. All channels share the same underlying timer, which means @@ -425,7 +425,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); /// /// - `polarity` can be one of: /// - `Timer.HIGH` - output is active high -/// - `Timer.LOW` - output is acive low +/// - `Timer.LOW` - output is active low /// /// Optional keyword arguments for Timer.IC modes: /// diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index f545674cee..f059c21be4 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -539,7 +539,7 @@ STATIC mp_obj_t extra_coverage(void) { { mp_printf(&mp_plat_print, "# VM\n"); - // call mp_execute_bytecode with invalide bytecode (should raise NotImplementedError) + // call mp_execute_bytecode with invalid bytecode (should raise NotImplementedError) mp_module_context_t context; mp_obj_fun_bc_t fun_bc; fun_bc.context = &context; diff --git a/ports/unix/main.c b/ports/unix/main.c index d6ae1e611b..95ed216e4b 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -414,7 +414,7 @@ STATIC void pre_process_options(int argc, char **argv) { #if MICROPY_PY_THREAD mp_thread_is_realtime_enabled = true; #endif - // main thread was already intialized before the option + // main thread was already initialized before the option // was parsed, so we have to enable realtime here. mp_thread_set_realtime(); #endif diff --git a/ports/unix/modtermios.c b/ports/unix/modtermios.c index 687bf1abf1..4f9751e274 100644 --- a/ports/unix/modtermios.c +++ b/ports/unix/modtermios.c @@ -75,7 +75,7 @@ STATIC mp_obj_t mod_termios_tcsetattr(mp_obj_t fd_in, mp_obj_t when_in, mp_obj_t // We don't export TCSANOW and friends to save on code space. Then // common lazy sense says that passing 0 should be godo enough, and // it is e.g. for glibc. But for other libc's it's not, so set just - // treat 0 as defauling to TCSANOW. + // treat 0 as defaulting to TCSANOW. when = TCSANOW; } diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index 072c4ca490..e4e0c0c5d3 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -41,7 +41,7 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #endif -// Enable arbritrary precision long-int by default. +// Enable arbitrary precision long-int by default. #ifndef MICROPY_LONGINT_IMPL #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #endif diff --git a/py/asmbase.c b/py/asmbase.c index da4273506a..cf64e3f3d0 100644 --- a/py/asmbase.c +++ b/py/asmbase.c @@ -80,7 +80,7 @@ uint8_t *mp_asm_base_get_cur_to_write_bytes(void *as_in, size_t num_bytes_to_wri void mp_asm_base_label_assign(mp_asm_base_t *as, size_t label) { assert(label < as->max_num_labels); - // Assiging a label ends any dead-code region, and all following machine + // Assigning a label ends any dead-code region, and all following machine // code should be emitted (until another mp_asm_base_suppress_code() call). as->suppress = false; diff --git a/py/asmthumb.c b/py/asmthumb.c index 49574c43a7..395134028a 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -290,7 +290,7 @@ bool asm_thumb_b_n_label(asm_thumb_t *as, uint label) { #define OP_BCC_N(cond, byte_offset) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff)) -// all these bit arithmetics need coverage testing! +// all these bit-arithmetic operations need coverage testing! #define OP_BCC_W_HI(cond, byte_offset) (0xf000 | ((cond) << 6) | (((byte_offset) >> 10) & 0x0400) | (((byte_offset) >> 14) & 0x003f)) #define OP_BCC_W_LO(byte_offset) (0x8000 | ((byte_offset) & 0x2000) | (((byte_offset) >> 1) & 0x0fff)) diff --git a/py/compile.c b/py/compile.c index 7a1660b1b2..c953711081 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3493,7 +3493,7 @@ void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool } } - // update maximim number of labels needed + // update maximum number of labels needed if (comp->next_label > max_num_labels) { max_num_labels = comp->next_label; } diff --git a/py/emitbc.c b/py/emitbc.c index 70a4d8b12e..a07657408f 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -439,7 +439,7 @@ void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) { } void mp_emit_bc_label_assign(emit_t *emit, mp_uint_t l) { - // Assiging a label ends any dead-code region, and all following opcodes + // Assigning a label ends any dead-code region, and all following opcodes // should be emitted (until another unconditional flow control). emit->suppress = false; diff --git a/py/emitnative.c b/py/emitnative.c index 3cb003315d..c6e6150099 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -894,7 +894,7 @@ STATIC void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re } // does an efficient X=pop(); discard(); push(X) -// needs a (non-temp) register in case the poped element was stored in the stack +// needs a (non-temp) register in case the popped element was stored in the stack STATIC void emit_fold_stack_top(emit_t *emit, int reg_dest) { stack_info_t *si = &emit->stack_info[emit->stack_size - 2]; si[0] = si[1]; diff --git a/py/formatfloat.c b/py/formatfloat.c index fc1b2fe7fc..050d3a9dfb 100644 --- a/py/formatfloat.c +++ b/py/formatfloat.c @@ -39,7 +39,7 @@ Routine for converting a arbitrary floating point number into a string. - The code in this funcion was inspired from Fred Bayer's pdouble.c. + The code in this function was inspired from Fred Bayer's pdouble.c. Since pdouble.c was released as Public Domain, I'm releasing this code as public domain as well. diff --git a/py/gc.c b/py/gc.c index ad3e110407..0873a0e11e 100644 --- a/py/gc.c +++ b/py/gc.c @@ -150,10 +150,10 @@ STATIC void gc_setup_area(mp_state_mem_area_t *area, void *start, void *end) { #endif #if MICROPY_ENABLE_FINALISER - // clear ATBs and FTBs + // clear ATB's and FTB's memset(area->gc_alloc_table_start, 0, gc_finaliser_table_byte_len + area->gc_alloc_table_byte_len + ALLOC_TABLE_GAP_BYTE); #else - // clear ATBs + // clear ATB's memset(area->gc_alloc_table_start, 0, area->gc_alloc_table_byte_len + ALLOC_TABLE_GAP_BYTE); #endif diff --git a/py/makecompresseddata.py b/py/makecompresseddata.py index 9603de8713..1bce3e8e83 100644 --- a/py/makecompresseddata.py +++ b/py/makecompresseddata.py @@ -24,7 +24,7 @@ def check_non_ascii(msg): # Replace with . -# Trival scheme to demo/test. +# Trivial scheme to demo/test. def space_compression(error_strings): for line in error_strings: check_non_ascii(line) diff --git a/py/mkrules.mk b/py/mkrules.mk index a58bd2ee0e..aa7f77bd2a 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -34,7 +34,7 @@ QSTR_GEN_CXXFLAGS += $(QSTR_GEN_FLAGS) # tree. # # So for example, py/map.c would have an object file name py/map.o -# The object files will go into the build directory and mantain the same +# The object files will go into the build directory and maintain the same # directory structure as the source tree. So the final dependency will look # like this: # @@ -192,7 +192,7 @@ endif ifneq ($(PROG),) # Build a standalone executable (unix does this) -# The executable should have an .exe extension for builds targetting 'pure' +# The executable should have an .exe extension for builds targeting 'pure' # Windows, i.e. msvc or mingw builds, but not when using msys or cygwin's gcc. COMPILER_TARGET := $(shell $(CC) -dumpmachine) ifneq (,$(findstring mingw,$(COMPILER_TARGET))) diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 06e9f1acb5..da29e5b67d 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -79,7 +79,7 @@ STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args) meta_args[2] = class_locals; // dict of members mp_obj_t new_class = mp_call_function_n_kw(meta, 3, 0, meta_args); - // store into cell if neede + // store into cell if needed if (cell != mp_const_none) { mp_obj_cell_set(cell, new_class); } diff --git a/py/objexcept.c b/py/objexcept.c index 515cbe7425..cc0ddd9dc5 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -217,7 +217,7 @@ mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, siz mp_obj_tuple_t *o_tuple; if (n_args == 0) { - // No args, can use the empty tuple straightaway + // No args, can use the empty tuple straight away o_tuple = (mp_obj_tuple_t *)&mp_const_empty_tuple_obj; } else { // Try to allocate memory for the tuple containing the args diff --git a/py/objtype.c b/py/objtype.c index 909fc83393..7f71968ea0 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -619,7 +619,7 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des mp_obj_t member = dest[0]; if (member != MP_OBJ_NULL) { if (!(self->base.type->flags & MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS)) { - // Class doesn't have any special accessors to check so return straightaway + // Class doesn't have any special accessors to check so return straight away return; } diff --git a/py/parse.c b/py/parse.c index 62de3282b3..c228d3a34a 100644 --- a/py/parse.c +++ b/py/parse.c @@ -553,7 +553,7 @@ STATIC mp_parse_node_t make_node_const_object(parser_t *parser, size_t src_line, return (mp_parse_node_t)pn; } -// Create a parse node represeting a constant object, possibly optimising the case of +// Create a parse node representing a constant object, possibly optimising the case of // an integer, by putting the (small) integer value directly in the parse node itself. STATIC mp_parse_node_t make_node_const_object_optimised(parser_t *parser, size_t src_line, mp_obj_t obj) { if (mp_obj_is_small_int(obj)) { @@ -1002,7 +1002,7 @@ STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, #if MICROPY_COMP_CONST_TUPLE if (build_tuple(parser, src_line, rule_id, num_args)) { - // we built a tuple from this rule so return straightaway + // we built a tuple from this rule so return straight away return; } #endif diff --git a/py/runtime.c b/py/runtime.c index 23fae6041d..3c7c0350c1 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -450,7 +450,7 @@ mp_obj_t MICROPY_WRAP_MP_BINARY_OP(mp_binary_op)(mp_binary_op_t op, mp_obj_t lhs } else { // standard precision is enough for right-shift if (rhs_val >= (mp_int_t)(sizeof(lhs_val) * MP_BITS_PER_BYTE)) { - // Shifting to big amounts is underfined behavior + // Shifting to big amounts is undefined behavior // in C and is CPU-dependent; propagate sign bit. rhs_val = sizeof(lhs_val) * MP_BITS_PER_BYTE - 1; } diff --git a/py/scope.h b/py/scope.h index b781dde427..e7d2a304f7 100644 --- a/py/scope.h +++ b/py/scope.h @@ -50,7 +50,7 @@ typedef struct _id_info_t { uint8_t kind; uint8_t flags; // when it's an ID_INFO_KIND_LOCAL this is the unique number of the local - // whet it's an ID_INFO_KIND_CELL/FREE this is the unique number of the closed over variable + // when it's an ID_INFO_KIND_CELL/FREE this is the unique number of the closed over variable uint16_t local_num; qstr qst; } id_info_t; diff --git a/py/sequence.c b/py/sequence.c index fa660a3384..5838607431 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -156,7 +156,7 @@ bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, size_t len1, const mp continue; } - // Othewise, if they are not equal, we can have final decision based on them + // Otherwise, if they are not equal, we can have final decision based on them if (op == MP_BINARY_OP_EQUAL) { // In particular, if we are checking for equality, here're the answer return false; diff --git a/shared/netutils/dhcpserver.c b/shared/netutils/dhcpserver.c index ea5718d114..50cd69a1eb 100644 --- a/shared/netutils/dhcpserver.c +++ b/shared/netutils/dhcpserver.c @@ -277,8 +277,8 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, opt_write_n(&opt, DHCP_OPT_SERVER_ID, 4, &d->ip.addr); opt_write_n(&opt, DHCP_OPT_SUBNET_MASK, 4, &d->nm.addr); - opt_write_n(&opt, DHCP_OPT_ROUTER, 4, &d->ip.addr); // aka gateway; can have mulitple addresses - opt_write_u32(&opt, DHCP_OPT_DNS, DEFAULT_DNS); // can have mulitple addresses + opt_write_n(&opt, DHCP_OPT_ROUTER, 4, &d->ip.addr); // aka gateway; can have multiple addresses + opt_write_u32(&opt, DHCP_OPT_DNS, DEFAULT_DNS); // can have multiple addresses opt_write_u32(&opt, DHCP_OPT_IP_LEASE_TIME, DEFAULT_LEASE_TIME_S); *opt++ = DHCP_OPT_END; dhcp_socket_sendto(&d->udp, &dhcp_msg, opt - (uint8_t *)&dhcp_msg, 0xffffffff, PORT_DHCP_CLIENT); diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c index ec0ff87f1d..e32150e5e7 100644 --- a/shared/runtime/pyexec.c +++ b/shared/runtime/pyexec.c @@ -592,7 +592,7 @@ friendly_repl_reset: // If the user gets to here and interrupts are disabled then // they'll never see the prompt, traceback etc. The USB REPL needs // interrupts to be enabled or no transfers occur. So we try to - // do the user a favor and reenable interrupts. + // do the user a favor and re-enable interrupts. if (query_irq() == IRQ_STATE_DISABLED) { enable_irq(IRQ_STATE_ENABLED); mp_hal_stdout_tx_str("MPY: enabling IRQs\r\n"); diff --git a/shared/runtime/softtimer.c b/shared/runtime/softtimer.c index 68173ac337..267610b269 100644 --- a/shared/runtime/softtimer.c +++ b/shared/runtime/softtimer.c @@ -41,7 +41,7 @@ STATIC soft_timer_entry_t *soft_timer_heap; static inline int32_t ticks_diff(uint32_t t1, uint32_t t0) { // t1 is after t0 (i.e. positive result) if there exists a uint32_t X <= INT_MAX - // such that t0 + X = t1. Otherwise t1 is interepreted to be earlier than + // such that t0 + X = t1. Otherwise t1 is interpreted to be earlier than // t0 (negative result). return t1 - t0; } diff --git a/shared/tinyusb/mp_usbd.c b/shared/tinyusb/mp_usbd.c index 0edc489881..ea1de674bc 100644 --- a/shared/tinyusb/mp_usbd.c +++ b/shared/tinyusb/mp_usbd.c @@ -31,7 +31,7 @@ #if MICROPY_HW_ENABLE_USBDEV #ifndef NO_QSTR -#include "tusb.h" // TinyUSB is not avaiable when running the string preprocessor +#include "tusb.h" // TinyUSB is not available when running the string preprocessor #include "device/usbd.h" #include "device/usbd_pvt.h" #endif diff --git a/shared/upytesthelper/upytesthelper.c b/shared/upytesthelper/upytesthelper.c index ce60732424..9553ff468e 100644 --- a/shared/upytesthelper/upytesthelper.c +++ b/shared/upytesthelper/upytesthelper.c @@ -60,7 +60,7 @@ bool upytest_is_failed(void) { } // MP_PLAT_PRINT_STRN() should be redirected to this function. -// It will pass-thru any content to mp_hal_stdout_tx_strn_cooked() +// It will pass-through any content to mp_hal_stdout_tx_strn_cooked() // (the dfault value of MP_PLAT_PRINT_STRN), but will also match // it to the expected output as set by upytest_set_expected_output(). // If mismatch happens, upytest_is_failed() returns true. diff --git a/tests/basics/annotate_var.py b/tests/basics/annotate_var.py index 3f767e4a73..a359b229b1 100644 --- a/tests/basics/annotate_var.py +++ b/tests/basics/annotate_var.py @@ -1,4 +1,4 @@ -# test PEP 526, varible annotations +# test PEP 526, variable annotations x: int print("x" in globals()) diff --git a/tests/basics/int_big1.py b/tests/basics/int_big1.py index 108e3ee5c9..5b35e3db4a 100644 --- a/tests/basics/int_big1.py +++ b/tests/basics/int_big1.py @@ -1,4 +1,4 @@ -# to test arbitrariy precision integers +# to test arbitrary precision integers x = 1000000000000000000000000000000 xn = -1000000000000000000000000000000 diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index db34342a17..c4960d2f80 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -57,7 +57,7 @@ try: except: print("Unknown type") -# Initially repitition counters were supported only for strings, +# Initially repetition counters were supported only for strings, # but later were implemented for all. print(struct.unpack("<3B2h", b"foo\x12\x34\xff\xff")) print(struct.pack("<3B", 1, 2, 3)) diff --git a/tests/basics/with_return.py b/tests/basics/with_return.py index fd848f1331..f2083d2aec 100644 --- a/tests/basics/with_return.py +++ b/tests/basics/with_return.py @@ -30,7 +30,7 @@ def f(): return (i, j) print(f()) -# multiple for loops within nested withs +# multiple for loops within nested with's def f(): with CtxMgr(1): for i in [1, 2]: @@ -41,7 +41,7 @@ def f(): return (i, j, k, l) print(f()) -# multiple for loops that are optimised, and nested withs +# multiple for loops that are optimised, and nested with's def f(): with CtxMgr(1): for i in range(1, 3): diff --git a/tests/cpydiff/core_fstring_repr.py b/tests/cpydiff/core_fstring_repr.py index fcadcbf1b9..df80abf795 100644 --- a/tests/cpydiff/core_fstring_repr.py +++ b/tests/cpydiff/core_fstring_repr.py @@ -2,7 +2,7 @@ categories: Core description: f-strings don't support the !r, !s, and !a conversions cause: MicroPython is optimised for code space. -workaround: Use repr(), str(), and ascii() explictly. +workaround: Use repr(), str(), and ascii() explicitly. """ diff --git a/tests/cpydiff/core_import_path.py b/tests/cpydiff/core_import_path.py index 04fc4bd5bb..959fd571f5 100644 --- a/tests/cpydiff/core_import_path.py +++ b/tests/cpydiff/core_import_path.py @@ -1,7 +1,7 @@ """ categories: Core,import description: __path__ attribute of a package has a different type (single string instead of list of strings) in MicroPython -cause: MicroPython does't support namespace packages split across filesystem. Beyond that, MicroPython's import system is highly optimized for minimal memory usage. +cause: MicroPython doesn't support namespace packages split across filesystem. Beyond that, MicroPython's import system is highly optimized for minimal memory usage. workaround: Details of import handling is inherently implementation dependent. Don't rely on such details in portable applications. """ import modules diff --git a/tests/cpydiff/core_import_split_ns_pkgs.py b/tests/cpydiff/core_import_split_ns_pkgs.py index 62bf337a22..5c92b63124 100644 --- a/tests/cpydiff/core_import_split_ns_pkgs.py +++ b/tests/cpydiff/core_import_split_ns_pkgs.py @@ -1,6 +1,6 @@ """ categories: Core,import -description: MicroPython does't support namespace packages split across filesystem. +description: MicroPython doesn't support namespace packages split across filesystem. cause: MicroPython's import system is highly optimized for simplicity, minimal memory usage, and minimal filesystem search overhead. workaround: Don't install modules belonging to the same namespace package in different directories. For MicroPython, it's recommended to have at most 3-component module search paths: for your current application, per-user (writable), system-wide (non-writable). """ diff --git a/tests/extmod/framebuf_palette.py b/tests/extmod/framebuf_palette.py index 84db834c15..f5b15fda73 100644 --- a/tests/extmod/framebuf_palette.py +++ b/tests/extmod/framebuf_palette.py @@ -30,6 +30,6 @@ fbd.blit(fbc, 0, 0, -1, palette) print(fbd.pixel(0, 0) == fg) print(fbd.pixel(7, 7) == fg) -print(fbd.pixel(8, 8) == 0) # Ouside blit +print(fbd.pixel(8, 8) == 0) # Outside blit print(fbd.pixel(0, 1) == bg) print(fbd.pixel(1, 0) == bg) diff --git a/tests/extmod/uctypes_sizeof_layout.py b/tests/extmod/uctypes_sizeof_layout.py index 2108e81502..c710ecde95 100644 --- a/tests/extmod/uctypes_sizeof_layout.py +++ b/tests/extmod/uctypes_sizeof_layout.py @@ -13,7 +13,7 @@ desc = { # uctypes.NATIVE is default print(uctypes.sizeof(desc) == uctypes.sizeof(desc, uctypes.NATIVE)) -# Here we assume that that we run on a platform with convential ABI +# Here we assume that that we run on a platform with conventional ABI # (which rounds up structure size based on max alignment). For platforms # where that doesn't hold, this tests should be just disabled in the runner. print(uctypes.sizeof(desc, uctypes.NATIVE) > uctypes.sizeof(desc, uctypes.LITTLE_ENDIAN)) diff --git a/tests/extmod/utimeq1.py b/tests/extmod/utimeq1.py index ddbc969afb..688e5b834f 100644 --- a/tests/extmod/utimeq1.py +++ b/tests/extmod/utimeq1.py @@ -125,7 +125,7 @@ assert edge_case(MODULO_HALF - 1, -100) == diff # We expect diff to be always positive, per the definition of heappop() which should return # the smallest value. -# This is the edge case where this invariant breaks, due to assymetry of two's-complement +# This is the edge case where this invariant breaks, due to asymmetry of two's-complement # range - there's one more negative integer than positive, so heappushing values like below # will then make ticks_diff() return the minimum negative value. We could make heappop # return them in a different order, but ticks_diff() result would be the same. Conclusion: diff --git a/tests/feature_check/README b/tests/feature_check/README index 3b7b6cba41..3f4804cfc9 100644 --- a/tests/feature_check/README +++ b/tests/feature_check/README @@ -1,4 +1,4 @@ This directory doesn't contain real tests, but code snippets to detect -various interpreter features, which can't be/inconvenient to detecte by +various interpreter features, which can't be/inconvenient to detect by other means. Scripts here are executed by run-tests.py at the beginning of testsuite to decide what other test groups to run/exclude. diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py index 0839274462..cc63185b5d 100644 --- a/tests/misc/non_compliant.py +++ b/tests/misc/non_compliant.py @@ -39,7 +39,7 @@ try: except NotImplementedError: print("NotImplementedError") -# uPy raises TypeError, shold be ValueError +# uPy raises TypeError, should be ValueError try: "%c" % b"\x01\x02" except (TypeError, ValueError): diff --git a/tests/net_hosted/README b/tests/net_hosted/README index 709ed50ce3..887e430e29 100644 --- a/tests/net_hosted/README +++ b/tests/net_hosted/README @@ -6,6 +6,6 @@ Note that setup for these tests and tests themselves are WIP, and may not yet fully correspond to the functional specification above. So far, these tests are not run as part of the main testsuite and need -to be run seperately (from the main test/ directory): +to be run separately (from the main test/ directory): ./run-tests.py net_hosted/*.py diff --git a/tests/net_inet/README b/tests/net_inet/README index 1d6e15b174..e5e05845f8 100644 --- a/tests/net_inet/README +++ b/tests/net_inet/README @@ -1,5 +1,5 @@ This directory contains network tests which require Internet connection. Note that these tests are not run as part of the main testsuite and need -to be run seperately (from the main test/ directory): +to be run separately (from the main test/ directory): ./run-tests.py net_inet/*.py diff --git a/tests/thread/thread_lock1.py b/tests/thread/thread_lock1.py index 342c554f4a..1d0701da01 100644 --- a/tests/thread/thread_lock1.py +++ b/tests/thread/thread_lock1.py @@ -30,7 +30,7 @@ print(lock.locked()) with lock: print(lock.locked()) -# test that lock is unlocked if an error is rasied +# test that lock is unlocked if an error is raised try: with lock: print(lock.locked()) diff --git a/tests/wipy/uart.py b/tests/wipy/uart.py index 9498d95545..94ac9051b2 100644 --- a/tests/wipy/uart.py +++ b/tests/wipy/uart.py @@ -156,7 +156,7 @@ except Exception: for uart_id in uart_id_range: uart = UART(uart_id, 1000000) uart.deinit() - # test printing an unitialized uart + # test printing an uninitialized uart print(uart) # initialize it back and check that it works again uart.init(115200) diff --git a/tools/ci.sh b/tools/ci.sh index 0eb94b3399..e8c4021f37 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -45,7 +45,7 @@ function ci_code_spell_run { function ci_commit_formatting_run { git remote add upstream https://github.com/micropython/micropython.git git fetch --depth=100 upstream master - # For a PR, upstream/master..HEAD ends with a merge commit into master, exlude that one. + # For a PR, upstream/master..HEAD ends with a merge commit into master, exclude that one. tools/verifygitlog.py -v upstream/master..HEAD --no-merges } diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index fe0283ce6f..8bcb73b6ff 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -78,7 +78,7 @@ def do_disconnect(state, _args=None): state.pyb.exit_raw_repl() except OSError: # Ignore any OSError exceptions when shutting down, eg: - # - pyboard.filesystem_command will close the connecton if it had an error + # - pyboard.filesystem_command will close the connection if it had an error # - umounting will fail if serial port disappeared pass state.pyb.close() diff --git a/tools/pydfu.py b/tools/pydfu.py index f2d845a70b..05cdf92c99 100755 --- a/tools/pydfu.py +++ b/tools/pydfu.py @@ -484,7 +484,7 @@ def get_memory_layout(device): def list_dfu_devices(*args, **kwargs): - """Prints a lits of devices detected in DFU mode.""" + """Prints a list of devices detected in DFU mode.""" devices = get_dfu_devices(*args, **kwargs) if not devices: raise SystemExit("No DFU capable devices found") diff --git a/tools/uncrustify.cfg b/tools/uncrustify.cfg index 28eb49faf7..bf5e37bf3f 100644 --- a/tools/uncrustify.cfg +++ b/tools/uncrustify.cfg @@ -1326,7 +1326,7 @@ indent_using_block = true # true/false # 2: When the `:` is a continuation, indent it under `?` indent_ternary_operator = 0 # unsigned number -# Whether to indent the statments inside ternary operator. +# Whether to indent the statements inside ternary operator. indent_inside_ternary_operator = false # true/false # If true, the indentation of the chunks after a `return` sequence will be set at return indentation column. @@ -1782,7 +1782,7 @@ nl_func_call_args_multi_line = false # true/false # different lines. nl_func_call_end_multi_line = false # true/false -# Whether to respect nl_func_call_XXX option incase of closure args. +# Whether to respect nl_func_call_XXX option in case of closure args. nl_func_call_args_multi_line_ignore_closures = false # true/false # Whether to add a newline after '<' of a template parameter list. @@ -2573,7 +2573,7 @@ align_oc_decl_colon = false # true/false # (OC) Whether to not align parameters in an Objectve-C message call if first # colon is not on next line of the message call (the same way Xcode does -# aligment) +# alignment) align_oc_msg_colon_xcode_like = false # true/false # @@ -2919,28 +2919,28 @@ pp_define_at_level = false # true/false pp_ignore_define_body = false # true/false # Whether to indent case statements between #if, #else, and #endif. -# Only applies to the indent of the preprocesser that the case statements +# Only applies to the indent of the preprocessor that the case statements # directly inside of. # # Default: true pp_indent_case = true # true/false # Whether to indent whole function definitions between #if, #else, and #endif. -# Only applies to the indent of the preprocesser that the function definition +# Only applies to the indent of the preprocessor that the function definition # is directly inside of. # # Default: true pp_indent_func_def = true # true/false # Whether to indent extern C blocks between #if, #else, and #endif. -# Only applies to the indent of the preprocesser that the extern block is +# Only applies to the indent of the preprocessor that the extern block is # directly inside of. # # Default: true pp_indent_extern = true # true/false # Whether to indent braces directly inside #if, #else, and #endif. -# Only applies to the indent of the preprocesser that the braces are directly +# Only applies to the indent of the preprocessor that the braces are directly # inside of. # # Default: true diff --git a/tools/verifygitlog.py b/tools/verifygitlog.py index c237cb46be..ee3e119f37 100755 --- a/tools/verifygitlog.py +++ b/tools/verifygitlog.py @@ -139,7 +139,7 @@ def run(args): def show_help(): print("usage: verifygitlog.py [-v -n -h --check-file] ...") - print("-v : increase verbosity, can be speficied multiple times") + print("-v : increase verbosity, can be specified multiple times") print("-n : do not print multi-line suggestions") print("-h : print this help message and exit") print( From 7ad41bc2d80fc757cbd73295ba233db4c56b8d48 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Mar 2023 12:12:03 +1100 Subject: [PATCH 023/565] top: Update .git-blame-ignore-revs for latest spelling fix commit. Signed-off-by: Damien George --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 7b63f7549d..6f84de6f60 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,3 +1,6 @@ +# all: Fix spelling mistakes based on codespell check. +b1229efbd1509654dec6053865ab828d769e29db + # top: Update Python formatting to black "2023 stable style". 8b2748269244304854b3462cb8902952b4dcb892 From 867e4dd3dc9235974974fd5dab204371616d6f49 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Mar 2023 11:19:10 +1100 Subject: [PATCH 024/565] top: Add Black configuration section to pyproject.toml. For convenience, eg for IDEs. Signed-off-by: Damien George --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 3bc55993a8..3b2a9f3135 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ +[tool.black] +line-length = 99 + [tool.codespell] count = "" ignore-regex = '\b[A-Z]{3}\b' From c2bf91219c3168cec01caa3bea662372a6690a2e Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 30 Apr 2023 17:37:40 +1000 Subject: [PATCH 025/565] lib/mbedtls_errors: Update error list for current version of mbedtls. This should have been updated as part of commit 7d73b9ff9975261bd2ff3544b09e9ec494775435, when mbedtls was changed to the LTS branch v2.16. Signed-off-by: Damien George --- lib/mbedtls_errors/mp_mbedtls_errors.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/mbedtls_errors/mp_mbedtls_errors.c b/lib/mbedtls_errors/mp_mbedtls_errors.c index 03a91f0dc9..c56f8a19ff 100644 --- a/lib/mbedtls_errors/mp_mbedtls_errors.c +++ b/lib/mbedtls_errors/mp_mbedtls_errors.c @@ -53,6 +53,10 @@ #include "mbedtls/aria.h" #endif +#if defined(MBEDTLS_ASN1_PARSE_C) +#include "mbedtls/asn1.h" +#endif + #if defined(MBEDTLS_BASE64_C) #include "mbedtls/base64.h" #endif @@ -378,6 +382,7 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS), "SSL_ASYNC_IN_PROGRESS" }, { -(MBEDTLS_ERR_SSL_EARLY_MESSAGE), "SSL_EARLY_MESSAGE" }, { -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS), "SSL_CRYPTO_IN_PROGRESS" }, + { -(MBEDTLS_ERR_SSL_BAD_CONFIG), "SSL_BAD_CONFIG" }, #endif /* MBEDTLS_SSL_TLS_C */ #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) From 7e0a38f7f7eea2bf492fe641189c1da4bb8b30f1 Mon Sep 17 00:00:00 2001 From: Carlosgg Date: Fri, 28 Apr 2023 04:14:36 +0100 Subject: [PATCH 026/565] lib/mbedtls: Update to mbedtls v2.28.1. Signed-off-by: Carlos Gil --- extmod/extmod.cmake | 3 ++- extmod/extmod.mk | 3 ++- lib/mbedtls | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index 7cf16fa1be..675a4c6ecc 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -154,7 +154,6 @@ if(MICROPY_SSL_MBEDTLS) ${MICROPY_LIB_MBEDTLS_DIR}/library/md4.c ${MICROPY_LIB_MBEDTLS_DIR}/library/md5.c ${MICROPY_LIB_MBEDTLS_DIR}/library/md.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/md_wrap.c ${MICROPY_LIB_MBEDTLS_DIR}/library/oid.c ${MICROPY_LIB_MBEDTLS_DIR}/library/padlock.c ${MICROPY_LIB_MBEDTLS_DIR}/library/pem.c @@ -179,9 +178,11 @@ if(MICROPY_SSL_MBEDTLS) ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_cli.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_cookie.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_srv.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_msg.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_ticket.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_tls.c ${MICROPY_LIB_MBEDTLS_DIR}/library/timing.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/constant_time.c ${MICROPY_LIB_MBEDTLS_DIR}/library/x509.c ${MICROPY_LIB_MBEDTLS_DIR}/library/x509_create.c ${MICROPY_LIB_MBEDTLS_DIR}/library/x509_crl.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 9947077a10..40f4237ce4 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -172,7 +172,6 @@ SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ md4.c \ md5.c \ md.c \ - md_wrap.c \ oid.c \ padlock.c \ pem.c \ @@ -197,9 +196,11 @@ SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ ssl_cli.c \ ssl_cookie.c \ ssl_srv.c \ + ssl_msg.c \ ssl_ticket.c \ ssl_tls.c \ timing.c \ + constant_time.c \ x509.c \ x509_create.c \ x509_crl.c \ diff --git a/lib/mbedtls b/lib/mbedtls index 1bc2c9cb8b..dd79db1001 160000 --- a/lib/mbedtls +++ b/lib/mbedtls @@ -1 +1 @@ -Subproject commit 1bc2c9cb8b8fe4659bd94b8ebba5a4c02029b7fa +Subproject commit dd79db10014d85b26d11fe57218431f2e5ede6f2 From b5f4611969302aab0b75620b8ae4450c97d4f79d Mon Sep 17 00:00:00 2001 From: Carlosgg Date: Sun, 30 Apr 2023 22:24:26 +0100 Subject: [PATCH 027/565] lib/mbedtls_errors: Add esp32-specific mbedtls error file. This allows updating mp_mbedtls_errors.c for the other mbedtls based ports based on mbedTLS v2.28.1. This esp32-specific file will not be required after updating IDF support to >= v4.4.1. Signed-off-by: Carlos Gil --- lib/mbedtls_errors/esp32_mbedtls_errors.c | 710 ++++++++++++++++++++++ ports/esp32/main/CMakeLists.txt | 2 +- 2 files changed, 711 insertions(+), 1 deletion(-) create mode 100644 lib/mbedtls_errors/esp32_mbedtls_errors.c diff --git a/lib/mbedtls_errors/esp32_mbedtls_errors.c b/lib/mbedtls_errors/esp32_mbedtls_errors.c new file mode 100644 index 0000000000..c56f8a19ff --- /dev/null +++ b/lib/mbedtls_errors/esp32_mbedtls_errors.c @@ -0,0 +1,710 @@ +/* + * Error message information + * + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY) +#include "mbedtls/error.h" +#include +#endif + +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#else +#define mbedtls_snprintf snprintf +#define mbedtls_time_t time_t +#endif + +#if defined(MBEDTLS_ERROR_C) + +#include + +#if defined(MBEDTLS_AES_C) +#include "mbedtls/aes.h" +#endif + +#if defined(MBEDTLS_ARC4_C) +#include "mbedtls/arc4.h" +#endif + +#if defined(MBEDTLS_ARIA_C) +#include "mbedtls/aria.h" +#endif + +#if defined(MBEDTLS_ASN1_PARSE_C) +#include "mbedtls/asn1.h" +#endif + +#if defined(MBEDTLS_BASE64_C) +#include "mbedtls/base64.h" +#endif + +#if defined(MBEDTLS_BIGNUM_C) +#include "mbedtls/bignum.h" +#endif + +#if defined(MBEDTLS_BLOWFISH_C) +#include "mbedtls/blowfish.h" +#endif + +#if defined(MBEDTLS_CAMELLIA_C) +#include "mbedtls/camellia.h" +#endif + +#if defined(MBEDTLS_CCM_C) +#include "mbedtls/ccm.h" +#endif + +#if defined(MBEDTLS_CHACHA20_C) +#include "mbedtls/chacha20.h" +#endif + +#if defined(MBEDTLS_CHACHAPOLY_C) +#include "mbedtls/chachapoly.h" +#endif + +#if defined(MBEDTLS_CIPHER_C) +#include "mbedtls/cipher.h" +#endif + +#if defined(MBEDTLS_CMAC_C) +#include "mbedtls/cmac.h" +#endif + +#if defined(MBEDTLS_CTR_DRBG_C) +#include "mbedtls/ctr_drbg.h" +#endif + +#if defined(MBEDTLS_DES_C) +#include "mbedtls/des.h" +#endif + +#if defined(MBEDTLS_DHM_C) +#include "mbedtls/dhm.h" +#endif + +#if defined(MBEDTLS_ECP_C) +#include "mbedtls/ecp.h" +#endif + +#if defined(MBEDTLS_ENTROPY_C) +#include "mbedtls/entropy.h" +#endif + +#if defined(MBEDTLS_GCM_C) +#include "mbedtls/gcm.h" +#endif + +#if defined(MBEDTLS_HKDF_C) +#include "mbedtls/hkdf.h" +#endif + +#if defined(MBEDTLS_HMAC_DRBG_C) +#include "mbedtls/hmac_drbg.h" +#endif + +#if defined(MBEDTLS_MD_C) +#include "mbedtls/md.h" +#endif + +#if defined(MBEDTLS_MD2_C) +#include "mbedtls/md2.h" +#endif + +#if defined(MBEDTLS_MD4_C) +#include "mbedtls/md4.h" +#endif + +#if defined(MBEDTLS_MD5_C) +#include "mbedtls/md5.h" +#endif + +#if defined(MBEDTLS_NET_C) +#include "mbedtls/net_sockets.h" +#endif + +#if defined(MBEDTLS_OID_C) +#include "mbedtls/oid.h" +#endif + +#if defined(MBEDTLS_PADLOCK_C) +#include "mbedtls/padlock.h" +#endif + +#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) +#include "mbedtls/pem.h" +#endif + +#if defined(MBEDTLS_PK_C) +#include "mbedtls/pk.h" +#endif + +#if defined(MBEDTLS_PKCS12_C) +#include "mbedtls/pkcs12.h" +#endif + +#if defined(MBEDTLS_PKCS5_C) +#include "mbedtls/pkcs5.h" +#endif + +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#endif + +#if defined(MBEDTLS_POLY1305_C) +#include "mbedtls/poly1305.h" +#endif + +#if defined(MBEDTLS_RIPEMD160_C) +#include "mbedtls/ripemd160.h" +#endif + +#if defined(MBEDTLS_RSA_C) +#include "mbedtls/rsa.h" +#endif + +#if defined(MBEDTLS_SHA1_C) +#include "mbedtls/sha1.h" +#endif + +#if defined(MBEDTLS_SHA256_C) +#include "mbedtls/sha256.h" +#endif + +#if defined(MBEDTLS_SHA512_C) +#include "mbedtls/sha512.h" +#endif + +#if defined(MBEDTLS_SSL_TLS_C) +#include "mbedtls/ssl.h" +#endif + +#if defined(MBEDTLS_THREADING_C) +#include "mbedtls/threading.h" +#endif + +#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) +#include "mbedtls/x509.h" +#endif + +#if defined(MBEDTLS_XTEA_C) +#include "mbedtls/xtea.h" +#endif + + +// Error code table type +struct ssl_errs { + int16_t errnum; + const char *errstr; +}; + +// Table of high level error codes +static const struct ssl_errs mbedtls_high_level_error_tab[] = { +// BEGIN generated code +#if defined(MBEDTLS_CIPHER_C) + { -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE), "CIPHER_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA), "CIPHER_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED), "CIPHER_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_CIPHER_INVALID_PADDING), "CIPHER_INVALID_PADDING" }, + { -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED), "CIPHER_FULL_BLOCK_EXPECTED" }, + { -(MBEDTLS_ERR_CIPHER_AUTH_FAILED), "CIPHER_AUTH_FAILED" }, + { -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT), "CIPHER_INVALID_CONTEXT" }, + { -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED), "CIPHER_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_CIPHER_C */ + +#if defined(MBEDTLS_DHM_C) + { -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA), "DHM_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED), "DHM_READ_PARAMS_FAILED" }, + { -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED), "DHM_MAKE_PARAMS_FAILED" }, + { -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED), "DHM_READ_PUBLIC_FAILED" }, + { -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED), "DHM_MAKE_PUBLIC_FAILED" }, + { -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED), "DHM_CALC_SECRET_FAILED" }, + { -(MBEDTLS_ERR_DHM_INVALID_FORMAT), "DHM_INVALID_FORMAT" }, + { -(MBEDTLS_ERR_DHM_ALLOC_FAILED), "DHM_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_DHM_FILE_IO_ERROR), "DHM_FILE_IO_ERROR" }, + { -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED), "DHM_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED), "DHM_SET_GROUP_FAILED" }, +#endif /* MBEDTLS_DHM_C */ + +#if defined(MBEDTLS_ECP_C) + { -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA), "ECP_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL), "ECP_BUFFER_TOO_SMALL" }, + { -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE), "ECP_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_ECP_VERIFY_FAILED), "ECP_VERIFY_FAILED" }, + { -(MBEDTLS_ERR_ECP_ALLOC_FAILED), "ECP_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_ECP_RANDOM_FAILED), "ECP_RANDOM_FAILED" }, + { -(MBEDTLS_ERR_ECP_INVALID_KEY), "ECP_INVALID_KEY" }, + { -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH), "ECP_SIG_LEN_MISMATCH" }, + { -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED), "ECP_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_ECP_IN_PROGRESS), "ECP_IN_PROGRESS" }, +#endif /* MBEDTLS_ECP_C */ + +#if defined(MBEDTLS_MD_C) + { -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE), "MD_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_MD_BAD_INPUT_DATA), "MD_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_MD_ALLOC_FAILED), "MD_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_MD_FILE_IO_ERROR), "MD_FILE_IO_ERROR" }, + { -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED), "MD_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_MD_C */ + +#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) + { -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT), "PEM_NO_HEADER_FOOTER_PRESENT" }, + { -(MBEDTLS_ERR_PEM_INVALID_DATA), "PEM_INVALID_DATA" }, + { -(MBEDTLS_ERR_PEM_ALLOC_FAILED), "PEM_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_PEM_INVALID_ENC_IV), "PEM_INVALID_ENC_IV" }, + { -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG), "PEM_UNKNOWN_ENC_ALG" }, + { -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED), "PEM_PASSWORD_REQUIRED" }, + { -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH), "PEM_PASSWORD_MISMATCH" }, + { -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE), "PEM_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA), "PEM_BAD_INPUT_DATA" }, +#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */ + +#if defined(MBEDTLS_PK_C) + { -(MBEDTLS_ERR_PK_ALLOC_FAILED), "PK_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_PK_TYPE_MISMATCH), "PK_TYPE_MISMATCH" }, + { -(MBEDTLS_ERR_PK_BAD_INPUT_DATA), "PK_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_PK_FILE_IO_ERROR), "PK_FILE_IO_ERROR" }, + { -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION), "PK_KEY_INVALID_VERSION" }, + { -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT), "PK_KEY_INVALID_FORMAT" }, + { -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG), "PK_UNKNOWN_PK_ALG" }, + { -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED), "PK_PASSWORD_REQUIRED" }, + { -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH), "PK_PASSWORD_MISMATCH" }, + { -(MBEDTLS_ERR_PK_INVALID_PUBKEY), "PK_INVALID_PUBKEY" }, + { -(MBEDTLS_ERR_PK_INVALID_ALG), "PK_INVALID_ALG" }, + { -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE), "PK_UNKNOWN_NAMED_CURVE" }, + { -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE), "PK_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH), "PK_SIG_LEN_MISMATCH" }, + { -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED), "PK_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_PK_C */ + +#if defined(MBEDTLS_PKCS12_C) + { -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA), "PKCS12_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE), "PKCS12_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT), "PKCS12_PBE_INVALID_FORMAT" }, + { -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH), "PKCS12_PASSWORD_MISMATCH" }, +#endif /* MBEDTLS_PKCS12_C */ + +#if defined(MBEDTLS_PKCS5_C) + { -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA), "PKCS5_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT), "PKCS5_INVALID_FORMAT" }, + { -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE), "PKCS5_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH), "PKCS5_PASSWORD_MISMATCH" }, +#endif /* MBEDTLS_PKCS5_C */ + +#if defined(MBEDTLS_RSA_C) + { -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA), "RSA_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_RSA_INVALID_PADDING), "RSA_INVALID_PADDING" }, + { -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED), "RSA_KEY_GEN_FAILED" }, + { -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED), "RSA_KEY_CHECK_FAILED" }, + { -(MBEDTLS_ERR_RSA_PUBLIC_FAILED), "RSA_PUBLIC_FAILED" }, + { -(MBEDTLS_ERR_RSA_PRIVATE_FAILED), "RSA_PRIVATE_FAILED" }, + { -(MBEDTLS_ERR_RSA_VERIFY_FAILED), "RSA_VERIFY_FAILED" }, + { -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE), "RSA_OUTPUT_TOO_LARGE" }, + { -(MBEDTLS_ERR_RSA_RNG_FAILED), "RSA_RNG_FAILED" }, + { -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION), "RSA_UNSUPPORTED_OPERATION" }, + { -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED), "RSA_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_RSA_C */ + +#if defined(MBEDTLS_SSL_TLS_C) + { -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE), "SSL_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA), "SSL_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_SSL_INVALID_MAC), "SSL_INVALID_MAC" }, + { -(MBEDTLS_ERR_SSL_INVALID_RECORD), "SSL_INVALID_RECORD" }, + { -(MBEDTLS_ERR_SSL_CONN_EOF), "SSL_CONN_EOF" }, + { -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER), "SSL_UNKNOWN_CIPHER" }, + { -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN), "SSL_NO_CIPHER_CHOSEN" }, + { -(MBEDTLS_ERR_SSL_NO_RNG), "SSL_NO_RNG" }, + { -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE), "SSL_NO_CLIENT_CERTIFICATE" }, + { -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE), "SSL_CERTIFICATE_TOO_LARGE" }, + { -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED), "SSL_CERTIFICATE_REQUIRED" }, + { -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED), "SSL_PRIVATE_KEY_REQUIRED" }, + { -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED), "SSL_CA_CHAIN_REQUIRED" }, + { -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE), "SSL_UNEXPECTED_MESSAGE" }, + { -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED), "SSL_PEER_VERIFY_FAILED" }, + { -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY), "SSL_PEER_CLOSE_NOTIFY" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO), "SSL_BAD_HS_CLIENT_HELLO" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO), "SSL_BAD_HS_SERVER_HELLO" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE), "SSL_BAD_HS_CERTIFICATE" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST), "SSL_BAD_HS_CERTIFICATE_REQUEST" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE), "SSL_BAD_HS_SERVER_KEY_EXCHANGE" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE), "SSL_BAD_HS_SERVER_HELLO_DONE" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE), "SSL_BAD_HS_CLIENT_KEY_EXCHANGE" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP), "SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS), "SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY), "SSL_BAD_HS_CERTIFICATE_VERIFY" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC), "SSL_BAD_HS_CHANGE_CIPHER_SPEC" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED), "SSL_BAD_HS_FINISHED" }, + { -(MBEDTLS_ERR_SSL_ALLOC_FAILED), "SSL_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED), "SSL_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH), "SSL_HW_ACCEL_FALLTHROUGH" }, + { -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED), "SSL_COMPRESSION_FAILED" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION), "SSL_BAD_HS_PROTOCOL_VERSION" }, + { -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET), "SSL_BAD_HS_NEW_SESSION_TICKET" }, + { -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED), "SSL_SESSION_TICKET_EXPIRED" }, + { -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH), "SSL_PK_TYPE_MISMATCH" }, + { -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY), "SSL_UNKNOWN_IDENTITY" }, + { -(MBEDTLS_ERR_SSL_INTERNAL_ERROR), "SSL_INTERNAL_ERROR" }, + { -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING), "SSL_COUNTER_WRAPPING" }, + { -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO), "SSL_WAITING_SERVER_HELLO_RENEGO" }, + { -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED), "SSL_HELLO_VERIFY_REQUIRED" }, + { -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL), "SSL_BUFFER_TOO_SMALL" }, + { -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE), "SSL_NO_USABLE_CIPHERSUITE" }, + { -(MBEDTLS_ERR_SSL_WANT_READ), "SSL_WANT_READ" }, + { -(MBEDTLS_ERR_SSL_WANT_WRITE), "SSL_WANT_WRITE" }, + { -(MBEDTLS_ERR_SSL_TIMEOUT), "SSL_TIMEOUT" }, + { -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT), "SSL_CLIENT_RECONNECT" }, + { -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD), "SSL_UNEXPECTED_RECORD" }, + { -(MBEDTLS_ERR_SSL_NON_FATAL), "SSL_NON_FATAL" }, + { -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH), "SSL_INVALID_VERIFY_HASH" }, + { -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING), "SSL_CONTINUE_PROCESSING" }, + { -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS), "SSL_ASYNC_IN_PROGRESS" }, + { -(MBEDTLS_ERR_SSL_EARLY_MESSAGE), "SSL_EARLY_MESSAGE" }, + { -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS), "SSL_CRYPTO_IN_PROGRESS" }, + { -(MBEDTLS_ERR_SSL_BAD_CONFIG), "SSL_BAD_CONFIG" }, +#endif /* MBEDTLS_SSL_TLS_C */ + +#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) + { -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE), "X509_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_X509_UNKNOWN_OID), "X509_UNKNOWN_OID" }, + { -(MBEDTLS_ERR_X509_INVALID_FORMAT), "X509_INVALID_FORMAT" }, + { -(MBEDTLS_ERR_X509_INVALID_VERSION), "X509_INVALID_VERSION" }, + { -(MBEDTLS_ERR_X509_INVALID_SERIAL), "X509_INVALID_SERIAL" }, + { -(MBEDTLS_ERR_X509_INVALID_ALG), "X509_INVALID_ALG" }, + { -(MBEDTLS_ERR_X509_INVALID_NAME), "X509_INVALID_NAME" }, + { -(MBEDTLS_ERR_X509_INVALID_DATE), "X509_INVALID_DATE" }, + { -(MBEDTLS_ERR_X509_INVALID_SIGNATURE), "X509_INVALID_SIGNATURE" }, + { -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS), "X509_INVALID_EXTENSIONS" }, + { -(MBEDTLS_ERR_X509_UNKNOWN_VERSION), "X509_UNKNOWN_VERSION" }, + { -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG), "X509_UNKNOWN_SIG_ALG" }, + { -(MBEDTLS_ERR_X509_SIG_MISMATCH), "X509_SIG_MISMATCH" }, + { -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED), "X509_CERT_VERIFY_FAILED" }, + { -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT), "X509_CERT_UNKNOWN_FORMAT" }, + { -(MBEDTLS_ERR_X509_BAD_INPUT_DATA), "X509_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_X509_ALLOC_FAILED), "X509_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_X509_FILE_IO_ERROR), "X509_FILE_IO_ERROR" }, + { -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL), "X509_BUFFER_TOO_SMALL" }, + { -(MBEDTLS_ERR_X509_FATAL_ERROR), "X509_FATAL_ERROR" }, +#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */ +// END generated code +}; + +static const struct ssl_errs mbedtls_low_level_error_tab[] = { +// Low level error codes +// +// BEGIN generated code +#if defined(MBEDTLS_AES_C) + { -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH), "AES_INVALID_KEY_LENGTH" }, + { -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH), "AES_INVALID_INPUT_LENGTH" }, + { -(MBEDTLS_ERR_AES_BAD_INPUT_DATA), "AES_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE), "AES_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED), "AES_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_AES_C */ + +#if defined(MBEDTLS_ARC4_C) + { -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED), "ARC4_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_ARC4_C */ + +#if defined(MBEDTLS_ARIA_C) + { -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA), "ARIA_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH), "ARIA_INVALID_INPUT_LENGTH" }, + { -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE), "ARIA_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED), "ARIA_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_ARIA_C */ + +#if defined(MBEDTLS_ASN1_PARSE_C) + { -(MBEDTLS_ERR_ASN1_OUT_OF_DATA), "ASN1_OUT_OF_DATA" }, + { -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG), "ASN1_UNEXPECTED_TAG" }, + { -(MBEDTLS_ERR_ASN1_INVALID_LENGTH), "ASN1_INVALID_LENGTH" }, + { -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH), "ASN1_LENGTH_MISMATCH" }, + { -(MBEDTLS_ERR_ASN1_INVALID_DATA), "ASN1_INVALID_DATA" }, + { -(MBEDTLS_ERR_ASN1_ALLOC_FAILED), "ASN1_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL), "ASN1_BUF_TOO_SMALL" }, +#endif /* MBEDTLS_ASN1_PARSE_C */ + +#if defined(MBEDTLS_BASE64_C) + { -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL), "BASE64_BUFFER_TOO_SMALL" }, + { -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER), "BASE64_INVALID_CHARACTER" }, +#endif /* MBEDTLS_BASE64_C */ + +#if defined(MBEDTLS_BIGNUM_C) + { -(MBEDTLS_ERR_MPI_FILE_IO_ERROR), "MPI_FILE_IO_ERROR" }, + { -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA), "MPI_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_MPI_INVALID_CHARACTER), "MPI_INVALID_CHARACTER" }, + { -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL), "MPI_BUFFER_TOO_SMALL" }, + { -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE), "MPI_NEGATIVE_VALUE" }, + { -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO), "MPI_DIVISION_BY_ZERO" }, + { -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE), "MPI_NOT_ACCEPTABLE" }, + { -(MBEDTLS_ERR_MPI_ALLOC_FAILED), "MPI_ALLOC_FAILED" }, +#endif /* MBEDTLS_BIGNUM_C */ + +#if defined(MBEDTLS_BLOWFISH_C) + { -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA), "BLOWFISH_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH), "BLOWFISH_INVALID_INPUT_LENGTH" }, + { -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED), "BLOWFISH_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_BLOWFISH_C */ + +#if defined(MBEDTLS_CAMELLIA_C) + { -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA), "CAMELLIA_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH), "CAMELLIA_INVALID_INPUT_LENGTH" }, + { -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED), "CAMELLIA_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_CAMELLIA_C */ + +#if defined(MBEDTLS_CCM_C) + { -(MBEDTLS_ERR_CCM_BAD_INPUT), "CCM_BAD_INPUT" }, + { -(MBEDTLS_ERR_CCM_AUTH_FAILED), "CCM_AUTH_FAILED" }, + { -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED), "CCM_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_CCM_C */ + +#if defined(MBEDTLS_CHACHA20_C) + { -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA), "CHACHA20_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE), "CHACHA20_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED), "CHACHA20_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_CHACHA20_C */ + +#if defined(MBEDTLS_CHACHAPOLY_C) + { -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE), "CHACHAPOLY_BAD_STATE" }, + { -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED), "CHACHAPOLY_AUTH_FAILED" }, +#endif /* MBEDTLS_CHACHAPOLY_C */ + +#if defined(MBEDTLS_CMAC_C) + { -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED), "CMAC_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_CMAC_C */ + +#if defined(MBEDTLS_CTR_DRBG_C) + { -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED), "CTR_DRBG_ENTROPY_SOURCE_FAILED" }, + { -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG), "CTR_DRBG_REQUEST_TOO_BIG" }, + { -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG), "CTR_DRBG_INPUT_TOO_BIG" }, + { -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR), "CTR_DRBG_FILE_IO_ERROR" }, +#endif /* MBEDTLS_CTR_DRBG_C */ + +#if defined(MBEDTLS_DES_C) + { -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH), "DES_INVALID_INPUT_LENGTH" }, + { -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED), "DES_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_DES_C */ + +#if defined(MBEDTLS_ENTROPY_C) + { -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED), "ENTROPY_SOURCE_FAILED" }, + { -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES), "ENTROPY_MAX_SOURCES" }, + { -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED), "ENTROPY_NO_SOURCES_DEFINED" }, + { -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE), "ENTROPY_NO_STRONG_SOURCE" }, + { -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR), "ENTROPY_FILE_IO_ERROR" }, +#endif /* MBEDTLS_ENTROPY_C */ + +#if defined(MBEDTLS_GCM_C) + { -(MBEDTLS_ERR_GCM_AUTH_FAILED), "GCM_AUTH_FAILED" }, + { -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED), "GCM_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_GCM_BAD_INPUT), "GCM_BAD_INPUT" }, +#endif /* MBEDTLS_GCM_C */ + +#if defined(MBEDTLS_HKDF_C) + { -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA), "HKDF_BAD_INPUT_DATA" }, +#endif /* MBEDTLS_HKDF_C */ + +#if defined(MBEDTLS_HMAC_DRBG_C) + { -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG), "HMAC_DRBG_REQUEST_TOO_BIG" }, + { -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG), "HMAC_DRBG_INPUT_TOO_BIG" }, + { -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR), "HMAC_DRBG_FILE_IO_ERROR" }, + { -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED), "HMAC_DRBG_ENTROPY_SOURCE_FAILED" }, +#endif /* MBEDTLS_HMAC_DRBG_C */ + +#if defined(MBEDTLS_MD2_C) + { -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED), "MD2_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_MD2_C */ + +#if defined(MBEDTLS_MD4_C) + { -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED), "MD4_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_MD4_C */ + +#if defined(MBEDTLS_MD5_C) + { -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED), "MD5_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_MD5_C */ + +#if defined(MBEDTLS_NET_C) + { -(MBEDTLS_ERR_NET_SOCKET_FAILED), "NET_SOCKET_FAILED" }, + { -(MBEDTLS_ERR_NET_CONNECT_FAILED), "NET_CONNECT_FAILED" }, + { -(MBEDTLS_ERR_NET_BIND_FAILED), "NET_BIND_FAILED" }, + { -(MBEDTLS_ERR_NET_LISTEN_FAILED), "NET_LISTEN_FAILED" }, + { -(MBEDTLS_ERR_NET_ACCEPT_FAILED), "NET_ACCEPT_FAILED" }, + { -(MBEDTLS_ERR_NET_RECV_FAILED), "NET_RECV_FAILED" }, + { -(MBEDTLS_ERR_NET_SEND_FAILED), "NET_SEND_FAILED" }, + { -(MBEDTLS_ERR_NET_CONN_RESET), "NET_CONN_RESET" }, + { -(MBEDTLS_ERR_NET_UNKNOWN_HOST), "NET_UNKNOWN_HOST" }, + { -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL), "NET_BUFFER_TOO_SMALL" }, + { -(MBEDTLS_ERR_NET_INVALID_CONTEXT), "NET_INVALID_CONTEXT" }, + { -(MBEDTLS_ERR_NET_POLL_FAILED), "NET_POLL_FAILED" }, + { -(MBEDTLS_ERR_NET_BAD_INPUT_DATA), "NET_BAD_INPUT_DATA" }, +#endif /* MBEDTLS_NET_C */ + +#if defined(MBEDTLS_OID_C) + { -(MBEDTLS_ERR_OID_NOT_FOUND), "OID_NOT_FOUND" }, + { -(MBEDTLS_ERR_OID_BUF_TOO_SMALL), "OID_BUF_TOO_SMALL" }, +#endif /* MBEDTLS_OID_C */ + +#if defined(MBEDTLS_PADLOCK_C) + { -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED), "PADLOCK_DATA_MISALIGNED" }, +#endif /* MBEDTLS_PADLOCK_C */ + +#if defined(MBEDTLS_PLATFORM_C) + { -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED), "PLATFORM_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED), "PLATFORM_FEATURE_UNSUPPORTED" }, +#endif /* MBEDTLS_PLATFORM_C */ + +#if defined(MBEDTLS_POLY1305_C) + { -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA), "POLY1305_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE), "POLY1305_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED), "POLY1305_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_POLY1305_C */ + +#if defined(MBEDTLS_RIPEMD160_C) + { -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED), "RIPEMD160_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_RIPEMD160_C */ + +#if defined(MBEDTLS_SHA1_C) + { -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED), "SHA1_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA), "SHA1_BAD_INPUT_DATA" }, +#endif /* MBEDTLS_SHA1_C */ + +#if defined(MBEDTLS_SHA256_C) + { -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED), "SHA256_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA), "SHA256_BAD_INPUT_DATA" }, +#endif /* MBEDTLS_SHA256_C */ + +#if defined(MBEDTLS_SHA512_C) + { -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED), "SHA512_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA), "SHA512_BAD_INPUT_DATA" }, +#endif /* MBEDTLS_SHA512_C */ + +#if defined(MBEDTLS_THREADING_C) + { -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE), "THREADING_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA), "THREADING_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_THREADING_MUTEX_ERROR), "THREADING_MUTEX_ERROR" }, +#endif /* MBEDTLS_THREADING_C */ + +#if defined(MBEDTLS_XTEA_C) + { -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH), "XTEA_INVALID_INPUT_LENGTH" }, + { -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED), "XTEA_HW_ACCEL_FAILED" }, +#endif /* MBEDTLS_XTEA_C */ +// END generated code +}; + +static const char *mbedtls_err_prefix = "MBEDTLS_ERR_"; +#define MBEDTLS_ERR_PREFIX_LEN ( sizeof("MBEDTLS_ERR_")-1 ) + +// copy error text into buffer, ensure null termination, return strlen of result +static size_t mbedtls_err_to_str(int err, const struct ssl_errs tab[], int tab_len, char *buf, size_t buflen) { + if (buflen == 0) return 0; + + // prefix for all error names + strncpy(buf, mbedtls_err_prefix, buflen); + if (buflen <= MBEDTLS_ERR_PREFIX_LEN+1) { + buf[buflen-1] = 0; + return buflen-1; + } + + // append error name from table + for (int i = 0; i < tab_len; i++) { + if (tab[i].errnum == err) { + strncpy(buf+MBEDTLS_ERR_PREFIX_LEN, tab[i].errstr, buflen-MBEDTLS_ERR_PREFIX_LEN); + buf[buflen-1] = 0; + return strlen(buf); + } + } + + mbedtls_snprintf(buf+MBEDTLS_ERR_PREFIX_LEN, buflen-MBEDTLS_ERR_PREFIX_LEN, "UNKNOWN (0x%04X)", + err); + return strlen(buf); +} + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + +void mbedtls_strerror(int ret, char *buf, size_t buflen) { + int use_ret; + + if (buflen == 0) return; + + buf[buflen-1] = 0; + + if (ret < 0) ret = -ret; + + // + // High-level error codes + // + uint8_t got_hl = (ret & 0xFF80) != 0; + if (got_hl) { + use_ret = ret & 0xFF80; + + // special case +#if defined(MBEDTLS_SSL_TLS_C) + if (use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE)) { + strncpy(buf, "MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE", buflen); + buf[buflen-1] = 0; + return; + } +#endif + + size_t len = mbedtls_err_to_str(use_ret, mbedtls_high_level_error_tab, + ARRAY_SIZE(mbedtls_high_level_error_tab), buf, buflen); + + buf += len; + buflen -= len; + if (buflen == 0) return; + } + + // + // Low-level error codes + // + use_ret = ret & ~0xFF80; + + if (use_ret == 0) return; + + // If high level code is present, make a concatenation between both error strings. + if (got_hl) { + if (buflen < 2) return; + *buf++ = '+'; + buflen--; + } + + mbedtls_err_to_str(use_ret, mbedtls_low_level_error_tab, + ARRAY_SIZE(mbedtls_low_level_error_tab), buf, buflen); +} + +#else /* MBEDTLS_ERROR_C */ + +#if defined(MBEDTLS_ERROR_STRERROR_DUMMY) + +/* + * Provide an non-function in case MBEDTLS_ERROR_C is not defined + */ +void mbedtls_strerror( int ret, char *buf, size_t buflen ) +{ + ((void) ret); + + if( buflen > 0 ) + buf[0] = '\0'; +} + +#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */ + +#endif /* MBEDTLS_ERROR_C */ diff --git a/ports/esp32/main/CMakeLists.txt b/ports/esp32/main/CMakeLists.txt index 964720dd9e..9f777ab439 100644 --- a/ports/esp32/main/CMakeLists.txt +++ b/ports/esp32/main/CMakeLists.txt @@ -34,7 +34,7 @@ set(MICROPY_SOURCE_LIB ${MICROPY_DIR}/lib/littlefs/lfs1_util.c ${MICROPY_DIR}/lib/littlefs/lfs2.c ${MICROPY_DIR}/lib/littlefs/lfs2_util.c - ${MICROPY_DIR}/lib/mbedtls_errors/mp_mbedtls_errors.c + ${MICROPY_DIR}/lib/mbedtls_errors/esp32_mbedtls_errors.c ${MICROPY_DIR}/lib/oofatfs/ff.c ${MICROPY_DIR}/lib/oofatfs/ffunicode.c ) From 4ff148de4582bb6ed01cb4b5189cc8ec312e09f5 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 30 Apr 2023 18:06:19 +1000 Subject: [PATCH 028/565] lib/mbedtls_errors: Update patch and error list for new mbedtls. Running `./do-mp.sh` now generates this mp_mbedtls_errors.c with mbedTLS v2.28.1. Signed-off-by: Damien George --- lib/mbedtls_errors/error.fmt | 2 +- lib/mbedtls_errors/generate_errors.diff | 37 +++++++++++++++---------- lib/mbedtls_errors/mp_mbedtls_errors.c | 13 ++++++++- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/lib/mbedtls_errors/error.fmt b/lib/mbedtls_errors/error.fmt index 5beeb6e7c9..15889128d4 100644 --- a/lib/mbedtls_errors/error.fmt +++ b/lib/mbedtls_errors/error.fmt @@ -110,7 +110,7 @@ void mbedtls_strerror(int ret, char *buf, size_t buflen) { if (got_hl) { use_ret = ret & 0xFF80; - // special case + // special case, don't try to translate low level code #if defined(MBEDTLS_SSL_TLS_C) if (use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE)) { strncpy(buf, "MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE", buflen); diff --git a/lib/mbedtls_errors/generate_errors.diff b/lib/mbedtls_errors/generate_errors.diff index ad24c372fa..bea47cd66f 100644 --- a/lib/mbedtls_errors/generate_errors.diff +++ b/lib/mbedtls_errors/generate_errors.diff @@ -1,22 +1,29 @@ ---- generate_errors_orig.pl 2020-06-20 08:40:38.819060379 -0700 -+++ generate_errors.pl 2020-06-20 08:47:26.511163591 -0700 -@@ -162,16 +162,12 @@ - - if ($error_name eq "MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE") +--- generate_errors_orig.pl 2023-04-30 17:58:23.503070758 +1000 ++++ generate_errors.py 2023-04-30 17:58:20.826338349 +1000 +@@ -162,7 +162,7 @@ { -- ${$code_check} .= "${white_space}if( use_ret == -($error_name) )\n". -- "${white_space}\{\n". -- "${white_space} mbedtls_snprintf( buf, buflen, \"$module_name - $description\" );\n". -- "${white_space} return;\n". -- "${white_space}}\n" -+ # no-op, this case is hard-coded in error.fmt + $code_check = \$ll_code_check; + $old_define = \$ll_old_define; +- $white_space = ' '; ++ $white_space = ' '; } else { -- ${$code_check} .= "${white_space}if( use_ret == -($error_name) )\n". -- "${white_space} mbedtls_snprintf( buf, buflen, \"$module_name - $description\" );\n" -+ my $error_text = $error_name =~ s/^MBEDTLS_ERR_//r; -+ ${$code_check} .= "${white_space}{ -($error_name), \"$error_text\" },\n" +@@ -203,8 +203,15 @@ + ${$old_define} = $define_name; } + +- ${$code_check} .= "${white_space}case -($error_name):\n". +- "${white_space} return( \"$module_name - $description\" );\n" ++ if ($error_name eq "MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE") ++ { ++ # no-op, this case is hard-coded in error.fmt ++ } ++ else ++ { ++ my $error_text = $error_name =~ s/^MBEDTLS_ERR_//r; ++ ${$code_check} .= "${white_space}{ -($error_name), \"$error_text\" },\n" ++ } }; + if ($ll_old_define ne "") diff --git a/lib/mbedtls_errors/mp_mbedtls_errors.c b/lib/mbedtls_errors/mp_mbedtls_errors.c index c56f8a19ff..fabbb15e4e 100644 --- a/lib/mbedtls_errors/mp_mbedtls_errors.c +++ b/lib/mbedtls_errors/mp_mbedtls_errors.c @@ -113,6 +113,10 @@ #include "mbedtls/entropy.h" #endif +#if defined(MBEDTLS_ERROR_C) +#include "mbedtls/error.h" +#endif + #if defined(MBEDTLS_GCM_C) #include "mbedtls/gcm.h" #endif @@ -381,6 +385,8 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING), "SSL_CONTINUE_PROCESSING" }, { -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS), "SSL_ASYNC_IN_PROGRESS" }, { -(MBEDTLS_ERR_SSL_EARLY_MESSAGE), "SSL_EARLY_MESSAGE" }, + { -(MBEDTLS_ERR_SSL_UNEXPECTED_CID), "SSL_UNEXPECTED_CID" }, + { -(MBEDTLS_ERR_SSL_VERSION_MISMATCH), "SSL_VERSION_MISMATCH" }, { -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS), "SSL_CRYPTO_IN_PROGRESS" }, { -(MBEDTLS_ERR_SSL_BAD_CONFIG), "SSL_BAD_CONFIG" }, #endif /* MBEDTLS_SSL_TLS_C */ @@ -512,6 +518,11 @@ static const struct ssl_errs mbedtls_low_level_error_tab[] = { { -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR), "ENTROPY_FILE_IO_ERROR" }, #endif /* MBEDTLS_ENTROPY_C */ +#if defined(MBEDTLS_ERROR_C) + { -(MBEDTLS_ERR_ERROR_GENERIC_ERROR), "ERROR_GENERIC_ERROR" }, + { -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED), "ERROR_CORRUPTION_DETECTED" }, +#endif /* MBEDTLS_ERROR_C */ + #if defined(MBEDTLS_GCM_C) { -(MBEDTLS_ERR_GCM_AUTH_FAILED), "GCM_AUTH_FAILED" }, { -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED), "GCM_HW_ACCEL_FAILED" }, @@ -655,7 +666,7 @@ void mbedtls_strerror(int ret, char *buf, size_t buflen) { if (got_hl) { use_ret = ret & 0xFF80; - // special case + // special case, don't try to translate low level code #if defined(MBEDTLS_SSL_TLS_C) if (use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE)) { strncpy(buf, "MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE", buflen); From a39e2827b7b2c99994aaca1b7b5b13290144801d Mon Sep 17 00:00:00 2001 From: algonell Date: Sun, 30 Apr 2023 13:46:44 +0300 Subject: [PATCH 029/565] docs/reference: Remove double 'are' in glossary. --- docs/reference/glossary.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/glossary.rst b/docs/reference/glossary.rst index 74524b22fd..d039bf7132 100644 --- a/docs/reference/glossary.rst +++ b/docs/reference/glossary.rst @@ -120,7 +120,7 @@ Glossary `_ which provides implementations for many modules from CPython's standard library. - Some of the modules are are implemented in pure Python, and are able to + Some of the modules are implemented in pure Python, and are able to be used on all ports. However, the majority of these modules use :term:`FFI` to access operating system functionality, and as such can only be used on the :term:`MicroPython Unix port` (with limited support From 9d735d1be7afe6551eab1ea116f1122af880135a Mon Sep 17 00:00:00 2001 From: glenn20 Date: Fri, 28 Apr 2023 00:19:31 +1000 Subject: [PATCH 030/565] py/ringbuf: Implement put_bytes/get_bytes functions. --- py/ringbuf.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ py/ringbuf.h | 3 +++ 2 files changed, 50 insertions(+) diff --git a/py/ringbuf.c b/py/ringbuf.c index 83887b300b..10dca62081 100644 --- a/py/ringbuf.c +++ b/py/ringbuf.c @@ -23,6 +23,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include + #include "ringbuf.h" int ringbuf_get16(ringbuf_t *r) { @@ -71,3 +74,47 @@ int ringbuf_put16(ringbuf_t *r, uint16_t v) { r->iput = iput_b; return 0; } + +// Returns: +// 0: Success +// -1: Not enough data available to complete read (try again later) +// -2: Requested read is larger than buffer - will never succeed +int ringbuf_get_bytes(ringbuf_t *r, uint8_t *data, size_t data_len) { + if (ringbuf_avail(r) < data_len) { + return (r->size <= data_len) ? -2 : -1; + } + uint32_t iget = r->iget; + uint32_t iget_a = (iget + data_len) % r->size; + uint8_t *datap = data; + if (iget_a < iget) { + // Copy part of the data from the space left at the end of the buffer + memcpy(datap, r->buf + iget, r->size - iget); + datap += (r->size - iget); + iget = 0; + } + memcpy(datap, r->buf + iget, iget_a - iget); + r->iget = iget_a; + return 0; +} + +// Returns: +// 0: Success +// -1: Not enough free space available to complete write (try again later) +// -2: Requested write is larger than buffer - will never succeed +int ringbuf_put_bytes(ringbuf_t *r, const uint8_t *data, size_t data_len) { + if (ringbuf_free(r) < data_len) { + return (r->size <= data_len) ? -2 : -1; + } + uint32_t iput = r->iput; + uint32_t iput_a = (iput + data_len) % r->size; + const uint8_t *datap = data; + if (iput_a < iput) { + // Copy part of the data to the end of the buffer + memcpy(r->buf + iput, datap, r->size - iput); + datap += (r->size - iput); + iput = 0; + } + memcpy(r->buf + iput, datap, iput_a - iput); + r->iput = iput_a; + return 0; +} diff --git a/py/ringbuf.h b/py/ringbuf.h index 4685848961..c8508c07ed 100644 --- a/py/ringbuf.h +++ b/py/ringbuf.h @@ -96,4 +96,7 @@ int ringbuf_get16(ringbuf_t *r); int ringbuf_peek16(ringbuf_t *r); int ringbuf_put16(ringbuf_t *r, uint16_t v); +int ringbuf_get_bytes(ringbuf_t *r, uint8_t *data, size_t data_len); +int ringbuf_put_bytes(ringbuf_t *r, const uint8_t *data, size_t data_len); + #endif // MICROPY_INCLUDED_PY_RINGBUF_H From 7fa322afb8b3d4b124fa613d357cba5c30ac56d8 Mon Sep 17 00:00:00 2001 From: Glenn Moloney Date: Thu, 24 Sep 2020 15:37:04 +1000 Subject: [PATCH 031/565] esp32,esp8266: Add support for the Espressif ESP-NOW protocol. ESP-NOW is a proprietary wireless communication protocol which supports connectionless communication between ESP32 and ESP8266 devices, using vendor specific WiFi frames. This commit adds support for this protocol through a new `espnow` module. This commit builds on original work done by @nickzoic, @shawwwn and with contributions from @zoland. Features include: - Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring. - Core support in `_espnow` C module, extended by `espnow.py` module. - Asyncio support via `aioespnow.py` module (separate to this commit). - Docs provided at `docs/library/espnow.rst`. Methods available in espnow.ESPNow class are: - active(True/False) - config(): set rx buffer size, read timeout and tx rate - recv()/irecv()/recvinto() to read incoming messages from peers - send() to send messages to peer devices - any() to test if a message is ready to read - irq() to set callback for received messages - stats() returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts) - add_peer(mac, ...) registers a peer before sending messages - get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt) - mod_peer(mac, ...) changes peer info parameters - get_peers() returns all peer info tuples - peers_table supports RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Also included is a test suite in tests/multi_espnow. This tests basic espnow data transfer, multiple transfers, various message sizes, encrypted messages (pmk and lmk), and asyncio support. Initial work is from https://github.com/micropython/micropython/pull/4115. Initial import of code is from: https://github.com/nickzoic/micropython/tree/espnow-4115. --- docs/library/espnow.rst | 917 ++++++++++++++++++ docs/library/index.rst | 5 + ports/esp32/boards/manifest.py | 1 + ports/esp32/main.c | 9 + ports/esp32/main/CMakeLists.txt | 1 + ports/esp32/modespnow.c | 884 +++++++++++++++++ ports/esp32/modespnow.h | 30 + ports/esp32/modnetwork.h | 1 + ports/esp32/modules/espnow.py | 30 + ports/esp32/mpconfigport.h | 3 + ports/esp32/network_wlan.c | 12 +- ports/esp8266/Makefile | 10 + ports/esp8266/boards/GENERIC/mpconfigboard.mk | 1 + .../boards/GENERIC_1M/mpconfigboard.mk | 1 + ports/esp8266/boards/esp8266_common.ld | 1 + ports/esp8266/boards/manifest.py | 1 + ports/esp8266/main.c | 8 + ports/esp8266/modespnow.c | 507 ++++++++++ ports/esp8266/modespnow.h | 28 + ports/esp8266/modules/espnow.py | 37 + tests/multi_espnow/10_simple_data.py | 57 ++ tests/multi_espnow/10_simple_data.py.exp | 6 + tests/multi_espnow/20_send_echo.py | 93 ++ tests/multi_espnow/20_send_echo.py.exp | 21 + tests/multi_espnow/30_lmk_echo.py | 130 +++ tests/multi_espnow/30_lmk_echo.py.exp | 8 + tests/multi_espnow/40_recv_test.py | 113 +++ tests/multi_espnow/40_recv_test.py.exp | 14 + tests/multi_espnow/50_esp32_rssi_test.py | 114 +++ tests/multi_espnow/50_esp32_rssi_test.py.exp | 10 + tests/multi_espnow/60_irq_test.py | 117 +++ tests/multi_espnow/60_irq_test.py.exp | 8 + tests/multi_espnow/80_uasyncio_client.py | 110 +++ tests/multi_espnow/80_uasyncio_client.py.exp | 18 + tests/multi_espnow/81_uasyncio_server.py | 96 ++ tests/multi_espnow/81_uasyncio_server.py.exp | 11 + tests/multi_espnow/90_memory_test.py | 108 +++ tests/multi_espnow/90_memory_test.py.exp | 25 + 38 files changed, 3542 insertions(+), 4 deletions(-) create mode 100644 docs/library/espnow.rst create mode 100644 ports/esp32/modespnow.c create mode 100644 ports/esp32/modespnow.h create mode 100644 ports/esp32/modules/espnow.py create mode 100644 ports/esp8266/modespnow.c create mode 100644 ports/esp8266/modespnow.h create mode 100644 ports/esp8266/modules/espnow.py create mode 100644 tests/multi_espnow/10_simple_data.py create mode 100644 tests/multi_espnow/10_simple_data.py.exp create mode 100644 tests/multi_espnow/20_send_echo.py create mode 100644 tests/multi_espnow/20_send_echo.py.exp create mode 100644 tests/multi_espnow/30_lmk_echo.py create mode 100644 tests/multi_espnow/30_lmk_echo.py.exp create mode 100644 tests/multi_espnow/40_recv_test.py create mode 100644 tests/multi_espnow/40_recv_test.py.exp create mode 100644 tests/multi_espnow/50_esp32_rssi_test.py create mode 100644 tests/multi_espnow/50_esp32_rssi_test.py.exp create mode 100644 tests/multi_espnow/60_irq_test.py create mode 100644 tests/multi_espnow/60_irq_test.py.exp create mode 100644 tests/multi_espnow/80_uasyncio_client.py create mode 100644 tests/multi_espnow/80_uasyncio_client.py.exp create mode 100644 tests/multi_espnow/81_uasyncio_server.py create mode 100644 tests/multi_espnow/81_uasyncio_server.py.exp create mode 100644 tests/multi_espnow/90_memory_test.py create mode 100644 tests/multi_espnow/90_memory_test.py.exp diff --git a/docs/library/espnow.rst b/docs/library/espnow.rst new file mode 100644 index 0000000000..468eb38418 --- /dev/null +++ b/docs/library/espnow.rst @@ -0,0 +1,917 @@ +:mod:`espnow` --- support for the ESP-NOW wireless protocol +=========================================================== + +.. module:: espnow + :synopsis: ESP-NOW wireless protocol support + +This module provides an interface to the `ESP-NOW `_ protocol provided by Espressif on +ESP32 and ESP8266 devices (`API docs `_). + +Table of Contents: +------------------ + + - `Introduction`_ + - `Configuration`_ + - `Sending and Receiving Data`_ + - `Peer Management`_ + - `Callback Methods`_ + - `Exceptions`_ + - `Constants`_ + - `Wifi Signal Strength (RSSI) - (ESP32 Only)`_ + - `Supporting asyncio`_ + - `Broadcast and Multicast`_ + - `ESPNow and Wifi Operation`_ + - `ESPNow and Sleep Modes`_ + +Introduction +------------ + +ESP-NOW is a connection-less wireless communication protocol supporting: + +- Direct communication between up to 20 registered peers: + + - Without the need for a wireless access point (AP), + +- Encrypted and unencrypted communication (up to 6 encrypted peers), + +- Message sizes up to 250 bytes, + +- Can operate alongside Wifi operation (:doc:`network.WLAN`) on + ESP32 and ESP8266 devices. + +It is especially useful for small IoT networks, latency sensitive or power +sensitive applications (such as battery operated devices) and for long-range +communication between devices (hundreds of metres). + +This module also supports tracking the Wifi signal strength (RSSI) of peer +devices. + +A simple example would be: + +**Sender:** :: + + import network + import espnow + + # A WLAN interface must be active to send()/recv() + sta = network.WLAN(network.STA_IF) # Or network.AP_IF + sta.active(True) + sta.disconnect() # For ESP8266 + + e = espnow.ESPNow() + e.active(True) + peer = b'\xbb\xbb\xbb\xbb\xbb\xbb' # MAC address of peer's wifi interface + e.add_peer(peer) # Must add_peer() before send() + + e.send(peer, "Starting...") + for i in range(100): + e.send(peer, str(i)*20, True) + e.send(peer, b'end') + +**Receiver:** :: + + import network + import espnow + + # A WLAN interface must be active to send()/recv() + sta = network.WLAN(network.STA_IF) + sta.active(True) + sta.disconnect() # Because ESP8266 auto-connects to last Access Point + + e = espnow.ESPNow() + e.active(True) + + while True: + host, msg = e.recv() + if msg: # msg == None if timeout in recv() + print(host, msg) + if msg == b'end': + break + +class ESPNow +------------ + +Constructor +----------- + +.. class:: ESPNow() + + Returns the singleton ESPNow object. As this is a singleton, all calls to + `espnow.ESPNow()` return a reference to the same object. + + .. note:: + Some methods are available only on the ESP32 due to code size + restrictions on the ESP8266 and differences in the Espressif API. + +Configuration +------------- + +.. method:: ESPNow.active([flag]) + + Initialise or de-initialise the ESPNow communication protocol depending on + the value of the ``flag`` optional argument. + + .. data:: Arguments: + + - *flag*: Any python value which can be converted to a boolean type. + + - ``True``: Prepare the software and hardware for use of the ESPNow + communication protocol, including: + + - initialise the ESPNow data structures, + - allocate the recv data buffer, + - invoke esp_now_init() and + - register the send and recv callbacks. + + - ``False``: De-initialise the Espressif ESPNow software stack + (esp_now_deinit()), disable callbacks, deallocate the recv + data buffer and deregister all peers. + + If *flag* is not provided, return the current status of the ESPNow + interface. + + .. data:: Returns: + + ``True`` if interface is currently *active*, else ``False``. + +.. method:: ESPNow.config(param=value, ...) + ESPNow.config('param') (ESP32 only) + + Set or get configuration values of the ESPNow interface. To set values, use + the keyword syntax, and one or more parameters can be set at a time. To get + a value the parameter name should be quoted as a string, and just one + parameter is queried at a time. + + **Note:** *Getting* parameters is not supported on the ESP8266. + + .. data:: Options: + + *rxbuf*: (default=526) Get/set the size in bytes of the internal + buffer used to store incoming ESPNow packet data. The default size is + selected to fit two max-sized ESPNow packets (250 bytes) with associated + mac_address (6 bytes), a message byte count (1 byte) and RSSI data plus + buffer overhead. Increase this if you expect to receive a lot of large + packets or expect bursty incoming traffic. + + **Note:** The recv buffer is allocated by `ESPNow.active()`. Changing + this value will have no effect until the next call of + `ESPNow.active(True)`. + + *timeout_ms*: (default=300,000) Default timeout (in milliseconds) + for receiving ESPNOW messages. If *timeout_ms* is less than zero, then + wait forever. The timeout can also be provided as arg to + `recv()`/`irecv()`/`recvinto()`. + + *rate*: (ESP32 only, IDF>=4.3.0 only) Set the transmission speed for + espnow packets. Must be set to a number from the allowed numeric values + in `enum wifi_phy_rate_t + `_. + + .. data:: Returns: + + ``None`` or the value of the parameter being queried. + + .. data:: Raises: + + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_INIT")`` if not initialised. + - ``ValueError()`` on invalid configuration options or values. + +Sending and Receiving Data +-------------------------- + +A wifi interface (``network.STA_IF`` or ``network.AP_IF``) must be +`active()` before messages can be sent or received, +but it is not necessary to connect or configure the WLAN interface. +For example:: + + import network + + sta = network.WLAN(network.STA_IF) + sta.active(True) + sta.disconnect() # For ESP8266 + +**Note:** The ESP8266 has a *feature* that causes it to automatically reconnect +to the last wifi Access Point when set `active(True)` (even +after reboot/reset). This reduces the reliability of receiving ESP-NOW messages +(see `ESPNow and Wifi Operation`_). You can avoid this by calling +`disconnect()` after +`active(True)`. + +.. method:: ESPNow.send(mac, msg[, sync]) + ESPNow.send(msg) (ESP32 only) + + Send the data contained in ``msg`` to the peer with given network ``mac`` + address. In the second form, ``mac=None`` and ``sync=True``. The peer must + be registered with `ESPNow.add_peer()` before the + message can be sent. + + .. data:: Arguments: + + - *mac*: byte string exactly ``espnow.ADDR_LEN`` (6 bytes) long or + ``None``. If *mac* is ``None`` (ESP32 only) the message will be sent + to all registered peers, except any broadcast or multicast MAC + addresses. + + - *msg*: string or byte-string up to ``espnow.MAX_DATA_LEN`` (250) + bytes long. + + - *sync*: + + - ``True``: (default) send ``msg`` to the peer(s) and wait for a + response (or not). + + - ``False`` send ``msg`` and return immediately. Responses from the + peers will be discarded. + + .. data:: Returns: + + ``True`` if ``sync=False`` or if ``sync=True`` and *all* peers respond, + else ``False``. + + .. data:: Raises: + + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_INIT")`` if not initialised. + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_FOUND")`` if peer is not registered. + - ``OSError(num, "ESP_ERR_ESPNOW_IF")`` the wifi interface is not + `active()`. + - ``OSError(num, "ESP_ERR_ESPNOW_NO_MEM")`` internal ESP-NOW buffers are + full. + - ``ValueError()`` on invalid values for the parameters. + + **Note**: A peer will respond with success if its wifi interface is + `active()` and set to the same channel as the sender, + regardless of whether it has initialised it's ESP-Now system or is + actively listening for ESP-Now traffic (see the Espressif ESP-Now docs). + +.. method:: ESPNow.recv([timeout_ms]) + + Wait for an incoming message and return the ``mac`` address of the peer and + the message. **Note**: It is **not** necessary to register a peer (using + `add_peer()`) to receive a message from that peer. + + .. data:: Arguments: + + - *timeout_ms*: (Optional): May have the following values. + + - ``0``: No timeout. Return immediately if no data is available; + - ``> 0``: Specify a timeout value in milliseconds; + - ``< 0``: Do not timeout, ie. wait forever for new messages; or + - ``None`` (or not provided): Use the default timeout value set with + `ESPNow.config()`. + + .. data:: Returns: + + - ``(None, None)`` if timeout is reached before a message is received, or + + - ``[mac, msg]``: where: + + - ``mac`` is a bytestring containing the address of the device which + sent the message, and + - ``msg`` is a bytestring containing the message. + + .. data:: Raises: + + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_INIT")`` if not initialised. + - ``OSError(num, "ESP_ERR_ESPNOW_IF")`` if the wifi interface is not + `active()`. + - ``ValueError()`` on invalid *timeout_ms* values. + + `ESPNow.recv()` will allocate new storage for the returned list and the + ``peer`` and ``msg`` bytestrings. This can lead to memory fragmentation if + the data rate is high. See `ESPNow.irecv()` for a memory-friendly + alternative. + + +.. method:: ESPNow.irecv([timeout_ms]) + + Works like `ESPNow.recv()` but will re-use internal bytearrays to store the + return values: ``[mac, msg]``, so that no new memory is allocated on each + call. + + .. data:: Arguments: + + *timeout_ms*: (Optional) Timeout in milliseconds (see `ESPNow.recv()`). + + .. data:: Returns: + + - As for `ESPNow.recv()`, except that ``msg`` is a bytearray, instead of + a bytestring. On the ESP8266, ``mac`` will also be a bytearray. + + .. data:: Raises: + + - See `ESPNow.recv()`. + + **Note:** You may also read messages by iterating over the ESPNow object, + which will use the `irecv()` method for alloc-free reads, eg: :: + + import espnow + e = espnow.ESPNow(); e.active(True) + for mac, msg in e: + print(mac, msg) + if mac is None: # mac, msg will equal (None, None) on timeout + break + +.. method:: ESPNow.recvinto(data[, timeout_ms]) + + Wait for an incoming message and return the length of the message in bytes. + This is the low-level method used by both `recv()` and + `irecv()` to read messages. + + .. data:: Arguments: + + *data*: A list of at least two elements, ``[peer, msg]``. ``msg`` must + be a bytearray large enough to hold the message (250 bytes). On the + ESP8266, ``peer`` should be a bytearray of 6 bytes. The MAC address of + the sender and the message will be stored in these bytearrays (see Note + on ESP32 below). + + *timeout_ms*: (Optional) Timeout in milliseconds (see `ESPNow.recv()`). + + .. data:: Returns: + + - Length of message in bytes or 0 if *timeout_ms* is reached before a + message is received. + + .. data:: Raises: + + - See `ESPNow.recv()`. + + **Note:** On the ESP32: + + - It is unnecessary to provide a bytearray in the first element of the + ``data`` list because it will be replaced by a reference to a unique + ``peer`` address in the **peer device table** (see `ESPNow.peers_table`). + - If the list is at least 4 elements long, the rssi and timestamp values + will be saved as the 3rd and 4th elements. + +.. method:: ESPNow.any() + + Check if data is available to be read with `ESPNow.recv()`. + + For more sophisticated querying of available characters use `select.poll()`:: + + import select + import espnow + + e = espnow.ESPNow() + poll = select.poll() + poll.register(e, select.POLLIN) + poll.poll(timeout) + + .. data:: Returns: + + ``True`` if data is available to be read, else ``False``. + +.. method:: ESPNow.stats() (ESP32 only) + + .. data:: Returns: + + A 5-tuple containing the number of packets sent/received/lost: + + ``(tx_pkts, tx_responses, tx_failures, rx_packets, rx_dropped_packets)`` + + Incoming packets are *dropped* when the recv buffers are full. To reduce + packet loss, increase the ``rxbuf`` config parameters and ensure you are + reading messages as quickly as possible. + + **Note**: Dropped packets will still be acknowledged to the sender as + received. + +Peer Management +--------------- + +The Espressif ESP-Now software requires that other devices (peers) must be +*registered* before we can `send()` them messages. It is +**not** necessary to *register* a peer to receive a message from that peer. + +.. method:: ESPNow.set_pmk(pmk) + + Set the Primary Master Key (PMK) which is used to encrypt the Local Master + Keys (LMK) for encrypting ESPNow data traffic. If this is not set, a + default PMK is used by the underlying Espressif esp_now software stack. + + **Note:** messages will only be encrypted if *lmk* is also set in + `ESPNow.add_peer()` (see `Security + `_ in the Espressif API + docs). + + .. data:: Arguments: + + *pmk*: Must be a byte string, bytearray or string of length + `espnow.KEY_LEN` (16 bytes). + + .. data:: Returns: + + ``None`` + + .. data:: Raises: + + ``ValueError()`` on invalid *pmk* values. + +.. method:: ESPNow.add_peer(mac, [lmk], [channel], [ifidx], [encrypt]) + ESPNow.add_peer(mac, param=value, ...) (ESP32 only) + + Add/register the provided *mac* address as a peer. Additional parameters + may also be specified as positional or keyword arguments: + + .. data:: Arguments: + + - *mac*: The MAC address of the peer (as a 6-byte byte-string). + + - *lmk*: The Local Master Key (LMK) key used to encrypt data + transfers with this peer (unless the *encrypt* parameter is set to + ``False``). Must be: + + - a byte-string or bytearray or string of length ``espnow.KEY_LEN`` + (16 bytes), or + + - any non ``True`` python value (default= ``b''``), signifying an + *empty* key which will disable encryption. + + - *channel*: The wifi channel (2.4GHz) to communicate with this peer. + Must be an integer from 0 to 14. If channel is set to 0 the current + channel of the wifi device will be used. (default=0) + + - *ifidx*: (ESP32 only) Index of the wifi interface which will be + used to send data to this peer. Must be an integer set to + ``network.STA_IF`` (=0) or ``network.AP_IF`` (=1). + (default=0/``network.STA_IF``). See `ESPNow and Wifi Operation`_ + below for more information. + + - *encrypt*: (ESP32 only) If set to ``True`` data exchanged with + this peer will be encrypted with the PMK and LMK. (default = + ``False``) + + **ESP8266**: Keyword args may not be used on the ESP8266. + + **Note:** The maximum number of peers which may be registered is 20 + (`espnow.MAX_TOTAL_PEER_NUM`), with a maximum of 6 + (`espnow.MAX_ENCRYPT_PEER_NUM`) of those peers with encryption enabled + (see `ESP_NOW_MAX_ENCRYPT_PEER_NUM `_ in the Espressif API + docs). + + .. data:: Raises: + + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_INIT")`` if not initialised. + - ``OSError(num, "ESP_ERR_ESPNOW_EXIST")`` if *mac* is already + registered. + - ``OSError(num, "ESP_ERR_ESPNOW_FULL")`` if too many peers are + already registered. + - ``ValueError()`` on invalid keyword args or values. + +.. method:: ESPNow.del_peer(mac) + + Deregister the peer associated with the provided *mac* address. + + .. data:: Returns: + + ``None`` + + .. data:: Raises: + + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_INIT")`` if not initialised. + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_FOUND")`` if *mac* is not + registered. + - ``ValueError()`` on invalid *mac* values. + +.. method:: ESPNow.get_peer(mac) (ESP32 only) + + Return information on a registered peer. + + .. data:: Returns: + + ``(mac, lmk, channel, ifidx, encrypt)``: a tuple of the "peer + info" associated with the given *mac* address. + + .. data:: Raises: + + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_INIT")`` if not initialised. + - ``OSError(num, "ESP_ERR_ESPNOW_NOT_FOUND")`` if *mac* is not + registered. + - ``ValueError()`` on invalid *mac* values. + +.. method:: ESPNow.peer_count() (ESP32 only) + + Return the number of registered peers: + + - ``(peer_num, encrypt_num)``: where + + - ``peer_num`` is the number of peers which are registered, and + - ``encrypt_num`` is the number of encrypted peers. + +.. method:: ESPNow.get_peers() (ESP32 only) + + Return the "peer info" parameters for all the registered peers (as a tuple + of tuples). + +.. method:: ESPNow.mod_peer(mac, lmk, [channel], [ifidx], [encrypt]) (ESP32 only) + ESPNow.mod_peer(mac, 'param'=value, ...) (ESP32 only) + + Modify the parameters of the peer associated with the provided *mac* + address. Parameters may be provided as positional or keyword arguments + (see `ESPNow.add_peer()`). + +Callback Methods +---------------- + +.. method:: ESPNow.irq(callback) (ESP32 only) + + Set a callback function to be called *as soon as possible* after a message has + been received from another ESPNow device. The callback function will be called + with the `ESPNow` instance object as an argument, eg: :: + + def recv_cb(e): + print(e.irecv(0)) + e.irq(recv_cb) + + The `irq()` callback method is an alternative method for + processing incoming espnow messages, especially if the data rate is moderate + and the device is *not too busy* but there are some caveats: + + - The scheduler stack *can* overflow and callbacks will be missed if + packets are arriving at a sufficient rate or if other MicroPython components + (eg, bluetooth, machine.Pin.irq(), machine.timer, i2s, ...) are exercising + the scheduler stack. This method may be less reliable for dealing with + bursts of messages, or high throughput or on a device which is busy dealing + with other hardware operations. + + - For more information on *scheduled* function callbacks see: + `micropython.schedule()`. + +Constants +--------- + +.. data:: espnow.MAX_DATA_LEN(=250) + espnow.KEY_LEN(=16) + espnow.ADDR_LEN(=6) + espnow.MAX_TOTAL_PEER_NUM(=20) + espnow.MAX_ENCRYPT_PEER_NUM(=6) + +Exceptions +---------- + +If the underlying Espressif ESPNow software stack returns an error code, +the MicroPython ESPNow module will raise an ``OSError(errnum, errstring)`` +exception where ``errstring`` is set to the name of one of the error codes +identified in the +`Espressif ESP-Now docs +`_. For example:: + + try: + e.send(peer, 'Hello') + except OSError as err: + if len(err.args) < 2: + raise err + if err.args[1] == 'ESP_ERR_ESPNOW_NOT_INIT': + e.active(True) + elif err.args[1] == 'ESP_ERR_ESPNOW_NOT_FOUND': + e.add_peer(peer) + elif err.args[1] == 'ESP_ERR_ESPNOW_IF': + network.WLAN(network.STA_IF).active(True) + else: + raise err + +Wifi Signal Strength (RSSI) - (ESP32 only) +------------------------------------------ + +The ESPNow object maintains a **peer device table** which contains the signal +strength and timestamp of the last received message from all hosts. The **peer +device table** can be accessed using `ESPNow.peers_table` and can be used to +track device proximity and identify *nearest neighbours* in a network of peer +devices. This feature is **not** available on ESP8266 devices. + +.. data:: ESPNow.peers_table + + A reference to the **peer device table**: a dict of known peer devices + and rssi values:: + + {peer: [rssi, time_ms], ...} + + where: + + - ``peer`` is the peer MAC address (as `bytes`); + - ``rssi`` is the wifi signal strength in dBm (-127 to 0) of the last + message received from the peer; and + - ``time_ms`` is the time the message was received (in milliseconds since + system boot - wraps every 12 days). + + Example:: + + >>> e.peers_table + {b'\xaa\xaa\xaa\xaa\xaa\xaa': [-31, 18372], + b'\xbb\xbb\xbb\xbb\xbb\xbb': [-43, 12541]} + + **Note**: the ``mac`` addresses returned by `recv()` are references to + the ``peer`` key values in the **peer device table**. + + **Note**: RSSI and timestamp values in the device table are updated only + when the message is read by the application. + +Supporting asyncio +------------------ + +A supplementary module (`aioespnow`) is available to provide +:doc:`asyncio` support. + +**Note:** Asyncio support is available on all ESP32 targets as well as those +ESP8266 boards which include the asyncio module (ie. ESP8266 devices with at +least 2MB flash memory). + +A small async server example:: + + import network + import aioespnow + import uasyncio as asyncio + + # A WLAN interface must be active to send()/recv() + network.WLAN(network.STA_IF).active(True) + + e = aioespnow.AIOESPNow() # Returns AIOESPNow enhanced with async support + e.active(True) + peer = b'\xbb\xbb\xbb\xbb\xbb\xbb' + e.add_peer(peer) + + # Send a periodic ping to a peer + async def heartbeat(e, peer, period=30): + while True: + if not await e.asend(peer, b'ping'): + print("Heartbeat: peer not responding:", peer) + else: + print("Heartbeat: ping", peer) + await asyncio.sleep(period) + + # Echo any received messages back to the sender + async def echo_server(e): + async for mac, msg in e: + print("Echo:", msg) + try: + await e.asend(mac, msg) + except OSError as err: + if len(err.args) > 1 and err.args[1] == 'ESP_ERR_ESPNOW_NOT_FOUND': + e.add_peer(mac) + await e.asend(mac, msg) + + async def main(e, peer, timeout, period): + asyncio.create_task(heartbeat(e, peer, period)) + asyncio.create_task(echo_server(e)) + await asyncio.sleep(timeout) + + asyncio.run(main(e, peer, 120, 10)) + +.. module:: aioespnow + :synopsis: ESP-NOW :doc:`uasyncio` support + +.. class:: AIOESPNow() + + The `AIOESPNow` class inherits all the methods of `ESPNow` + and extends the interface with the following async methods. + +.. method:: async AIOESPNow.arecv() + + Asyncio support for `ESPNow.recv()`. Note that this method does not take a + timeout value as argument. + +.. method:: async AIOESPNow.airecv() + + Asyncio support for `ESPNow.irecv()`. Note that this method does not take a + timeout value as argument. + +.. method:: async AIOESPNow.asend(mac, msg, sync=True) + async AIOESPNow.asend(msg) + + Asyncio support for `ESPNow.send()`. + +.. method:: AIOESPNow._aiter__() / async AIOESPNow.__anext__() + + `AIOESPNow` also supports reading incoming messages by asynchronous + iteration using ``async for``; eg:: + + e = AIOESPNow() + e.active(True) + async def recv_till_halt(e): + async for mac, msg in e: + print(mac, msg) + if msg == b'halt': + break + asyncio.run(recv_till_halt(e)) + +Broadcast and Multicast +----------------------- + +All active ESP-Now clients will receive messages sent to their MAC address and +all devices (**except ESP8266 devices**) will also receive messages sent to the +*broadcast* MAC address (``b'\xff\xff\xff\xff\xff\xff'``) or any multicast +MAC address. + +All ESP-Now devices (including ESP8266 devices) can also send messages to the +broadcast MAC address or any multicast MAC address. + +To `send()` a broadcast message, the broadcast (or +multicast) MAC address must first be registered using +`add_peer()`. `send()` will always return +``True`` for broadcasts, regardless of whether any devices receive the +message. It is not permitted to encrypt messages sent to the broadcast +address or any multicast address. + +**Note**: `ESPNow.send(None, msg)` will send to all registered +peers *except* the broadcast address. To send a broadcast or multicast +message, you must specify the broadcast (or multicast) MAC address as the +peer. For example:: + + bcast = b'\xff' * 6 + e.add_peer(bcast) + e.send(bcast, "Hello World!") + +ESPNow and Wifi Operation +------------------------- + +ESPNow messages may be sent and received on any `active()` +`WLAN` interface (``network.STA_IF`` or ``network.AP_IF``), even +if that interface is also connected to a wifi network or configured as an access +point. When an ESP32 or ESP8266 device connects to a Wifi Access Point (see +`ESP32 Quickref <../esp32/quickref.html#networking>`__) the following things +happen which affect ESPNow communications: + +1. Wifi Power-saving Mode is automatically activated and +2. The radio on the esp device changes wifi ``channel`` to match the channel + used by the Access Point. + +**Wifi Power-saving Mode:** (see `Espressif Docs `_) The power saving mode causes the +device to turn off the radio periodically (typically for hundreds of +milliseconds), making it unreliable in receiving ESPNow messages. This can be +resolved by either of: + +1. Turning on the AP_IF interface, which will disable the power saving mode. + However, the device will then be advertising an active wifi access point. + + - You **may** also choose to send your messages via the AP_IF interface, but + this is not necessary. + - ESP8266 peers must send messages to this AP_IF interface (see below). + +2. Configuring ESPNow clients to retry sending messages. + +**Receiving messages from an ESP8266 device:** Strangely, an ESP32 device +connected to a wifi network using method 1 or 2 above, will receive ESP-Now +messages sent to the STA_IF MAC address from another ESP32 device, but will +**reject** messages from an ESP8266 device!!!. To receive messages from an +ESP8266 device, the AP_IF interface must be set to ``active(True)`` **and** +messages must be sent to the AP_IF MAC address. + +**Managing wifi channels:** Any other espnow devices wishing to communicate with +a device which is also connected to a Wifi Access Point MUST use the same +channel. A common scenario is where one espnow device is connected to a wifi +router and acts as a proxy for messages from a group of sensors connected via +espnow: + +**Proxy:** :: + + import network, time, espnow + + sta, ap = wifi_reset() # Reset wifi to AP off, STA on and disconnected + sta.connect('myssid', 'mypassword') + while not sta.isconnected(): # Wait until connected... + time.sleep(0.1) + ap.active(True) # Disable power-saving mode + + # Print the wifi channel used AFTER finished connecting to access point + print("Proxy running on channel:", sta.config("channel")) + e = espnow.ESPNow(); e.active(True) + for peer, msg in e: + # Receive espnow messages and forward them to MQTT broker over wifi + +**Sensor:** :: + + import network, espnow + + sta, ap = wifi_reset() # Reset wifi to AP off, STA on and disconnected + sta.config(channel=6) # Change to the channel used by the proxy above. + peer = b'0\xaa\xaa\xaa\xaa\xaa' # MAC address of proxy + e = espnow.ESPNow(); e.active(True); + e.add_peer(peer) + while True: + msg = read_sensor() + e.send(peer, msg) + time.sleep(1) + +Other issues to take care with when using ESPNow with wifi are: + +- **Set WIFI to known state on startup:** MicroPython does not reset the wifi + peripheral after a soft reset. This can lead to unexpected behaviour. To + guarantee the wifi is reset to a known state after a soft reset make sure you + deactivate the STA_IF and AP_IF before setting them to the desired state at + startup, eg.:: + + import network, time + + def wifi_reset(): # Reset wifi to AP_IF off, STA_IF on and disconnected + sta = network.WLAN(network.STA_IF); sta.active(False) + ap = network.WLAN(network.AP_IF); ap.active(False) + sta.active(True) + while not sta.active(): + time.sleep(0.1) + sta.disconnect() # For ESP8266 + while sta.isconnected(): + time.sleep(0.1) + return sta, ap + + sta, ap = wifi_reset() + + Remember that a soft reset occurs every time you connect to the device REPL + and when you type ``ctrl-D``. + +- **STA_IF and AP_IF always operate on the same channel:** the AP_IF will change + channel when you connect to a wifi network; regardless of the channel you set + for the AP_IF (see `Attention Note 3 + `_ + ). After all, there is really only one wifi radio on the device, which is + shared by the STA_IF and AP_IF virtual devices. + +- **Disable automatic channel assignment on your wifi router:** If the wifi + router for your wifi network is configured to automatically assign the wifi + channel, it may change the channel for the network if it detects interference + from other wifi routers. When this occurs, the ESP devices connected to the + wifi network will also change channels to match the router, but other + ESPNow-only devices will remain on the previous channel and communication will + be lost. To mitigate this, either set your wifi router to use a fixed wifi + channel or configure your devices to re-scan the wifi channels if they are + unable to find their expected peers on the current channel. + +- **MicroPython re-scans wifi channels when trying to reconnect:** If the esp + device is connected to a Wifi Access Point that goes down, MicroPython will + automatically start scanning channels in an attempt to reconnect to the + Access Point. This means espnow messages will be lost while scanning for the + AP. This can be disabled by ``sta.config(reconnects=0)``, which will also + disable the automatic reconnection after losing connection. + +- Some versions of the ESP IDF only permit sending ESPNow packets from the + STA_IF interface to peers which have been registered on the same wifi + channel as the STA_IF:: + + ESPNOW: Peer channel is not equal to the home channel, send fail! + +ESPNow and Sleep Modes +---------------------- + +The `machine.lightsleep([time_ms])` and +`machine.deepsleep([time_ms])` functions can be used to put +the ESP32 and peripherals (including the WiFi and Bluetooth radios) to sleep. +This is useful in many applications to conserve battery power. However, +applications must disable the WLAN peripheral (using +`active(False)`) before entering light or deep sleep (see +`Sleep Modes `_). +Otherwise the WiFi radio may not be initialised properly after wake from +sleep. If the ``STA_IF`` and ``AP_IF`` interfaces have both been set +`active(True)` then both interfaces should be set +`active(False)` before entering any sleep mode. + +**Example:** deep sleep:: + + import network, machine, espnow + + sta, ap = wifi_reset() # Reset wifi to AP off, STA on and disconnected + peer = b'0\xaa\xaa\xaa\xaa\xaa' # MAC address of peer + e = espnow.ESPNow() + e.active(True) + e.add_peer(peer) # Register peer on STA_IF + + print('Sending ping...') + if not e.send(peer, b'ping'): + print('Ping failed!') + e.active(False) + sta.active(False) # Disable the wifi before sleep + print('Going to sleep...') + machine.deepsleep(10000) # Sleep for 10 seconds then reboot + +**Example:** light sleep:: + + import network, machine, espnow + + sta, ap = wifi_reset() # Reset wifi to AP off, STA on and disconnected + sta.config(channel=6) + peer = b'0\xaa\xaa\xaa\xaa\xaa' # MAC address of peer + e = espnow.ESPNow() + e.active(True) + e.add_peer(peer) # Register peer on STA_IF + + while True: + print('Sending ping...') + if not e.send(peer, b'ping'): + print('Ping failed!') + sta.active(False) # Disable the wifi before sleep + print('Going to sleep...') + machine.lightsleep(10000) # Sleep for 10 seconds + sta.active(True) + sta.config(channel=6) # Wifi loses config after lightsleep() + diff --git a/docs/library/index.rst b/docs/library/index.rst index 59ed1127a7..8d7d8c563b 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -155,6 +155,11 @@ The following libraries are specific to the ESP8266 and ESP32. esp.rst esp32.rst +.. toctree:: + :maxdepth: 1 + + espnow.rst + Libraries specific to the RP2040 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/ports/esp32/boards/manifest.py b/ports/esp32/boards/manifest.py index a6df79f0a3..fa851b5eea 100644 --- a/ports/esp32/boards/manifest.py +++ b/ports/esp32/boards/manifest.py @@ -5,6 +5,7 @@ include("$(MPY_DIR)/extmod/uasyncio") require("bundle-networking") # Require some micropython-lib modules. +# require("aioespnow") require("dht") require("ds18x20") require("neopixel") diff --git a/ports/esp32/main.c b/ports/esp32/main.c index e7d7626a6e..0d876eb5f7 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -67,6 +67,10 @@ #include "extmod/modbluetooth.h" #endif +#if MICROPY_ESPNOW +#include "modespnow.h" +#endif + // MicroPython runs as a task under FreeRTOS #define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1) #define MP_TASK_STACK_SIZE (16 * 1024) @@ -190,6 +194,11 @@ soft_reset_exit: mp_bluetooth_deinit(); #endif + #if MICROPY_ESPNOW + espnow_deinit(mp_const_none); + MP_STATE_PORT(espnow_singleton) = NULL; + #endif + machine_timer_deinit_all(); #if MICROPY_PY_THREAD diff --git a/ports/esp32/main/CMakeLists.txt b/ports/esp32/main/CMakeLists.txt index 9f777ab439..51e53c202f 100644 --- a/ports/esp32/main/CMakeLists.txt +++ b/ports/esp32/main/CMakeLists.txt @@ -84,6 +84,7 @@ set(MICROPY_SOURCE_PORT ${PROJECT_DIR}/mpthreadport.c ${PROJECT_DIR}/machine_rtc.c ${PROJECT_DIR}/machine_sdcard.c + ${PROJECT_DIR}/modespnow.c ) set(MICROPY_SOURCE_QSTR diff --git a/ports/esp32/modespnow.c b/ports/esp32/modespnow.c new file mode 100644 index 0000000000..047245995d --- /dev/null +++ b/ports/esp32/modespnow.c @@ -0,0 +1,884 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017-2020 Nick Moore + * Copyright (c) 2018 shawwwn + * Copyright (c) 2020-2021 Glenn Moloney @glenn20 + * + * 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 +#include +#include + +#include "esp_log.h" +#include "esp_now.h" +#include "esp_wifi.h" +#include "esp_wifi_types.h" + +#include "py/runtime.h" +#include "py/mphal.h" +#include "py/mperrno.h" +#include "py/obj.h" +#include "py/objstr.h" +#include "py/objarray.h" +#include "py/stream.h" +#include "py/binary.h" +#include "py/ringbuf.h" + +#include "mpconfigport.h" +#include "mphalport.h" +#include "modnetwork.h" +#include "modespnow.h" + +#ifndef MICROPY_ESPNOW_RSSI +// Include code to track rssi of peers +#define MICROPY_ESPNOW_RSSI 1 +#endif +#ifndef MICROPY_ESPNOW_EXTRA_PEER_METHODS +// Include mod_peer(),get_peer(),peer_count() +#define MICROPY_ESPNOW_EXTRA_PEER_METHODS 1 +#endif + +// Relies on gcc Variadic Macros and Statement Expressions +#define NEW_TUPLE(...) \ + ({mp_obj_t _z[] = {__VA_ARGS__}; mp_obj_new_tuple(MP_ARRAY_SIZE(_z), _z); }) + +static const uint8_t ESPNOW_MAGIC = 0x99; + +// ESPNow packet format for the receive buffer. +// Use this for peeking at the header of the next packet in the buffer. +typedef struct { + uint8_t magic; // = ESPNOW_MAGIC + uint8_t msg_len; // Length of the message + #if MICROPY_ESPNOW_RSSI + uint32_t time_ms; // Timestamp (ms) when packet is received + int8_t rssi; // RSSI value (dBm) (-127 to 0) + #endif // MICROPY_ESPNOW_RSSI +} __attribute__((packed)) espnow_hdr_t; + +typedef struct { + espnow_hdr_t hdr; // The header + uint8_t peer[6]; // Peer address + uint8_t msg[0]; // Message is up to 250 bytes +} __attribute__((packed)) espnow_pkt_t; + +// The maximum length of an espnow packet (bytes) +static const size_t MAX_PACKET_LEN = ( + (sizeof(espnow_pkt_t) + ESP_NOW_MAX_DATA_LEN)); + +// Enough for 2 full-size packets: 2 * (6 + 7 + 250) = 526 bytes +// Will allocate an additional 7 bytes for buffer overhead +static const size_t DEFAULT_RECV_BUFFER_SIZE = (2 * MAX_PACKET_LEN); + +// Default timeout (millisec) to wait for incoming ESPNow messages (5 minutes). +static const size_t DEFAULT_RECV_TIMEOUT_MS = (5 * 60 * 1000); + +// Time to wait (millisec) for responses from sent packets: (2 seconds). +static const size_t DEFAULT_SEND_TIMEOUT_MS = (2 * 1000); + +// Number of milliseconds to wait for pending responses to sent packets. +// This is a fallback which should never be reached. +static const mp_uint_t PENDING_RESPONSES_TIMEOUT_MS = 100; +static const mp_uint_t PENDING_RESPONSES_BUSY_POLL_MS = 10; + +// The data structure for the espnow_singleton. +typedef struct _esp_espnow_obj_t { + mp_obj_base_t base; + + ringbuf_t *recv_buffer; // A buffer for received packets + size_t recv_buffer_size; // The size of the recv_buffer + mp_int_t recv_timeout_ms; // Timeout for recv() + volatile size_t rx_packets; // # of received packets + size_t dropped_rx_pkts; // # of dropped packets (buffer full) + size_t tx_packets; // # of sent packets + volatile size_t tx_responses; // # of sent packet responses received + volatile size_t tx_failures; // # of sent packet responses failed + size_t peer_count; // Cache the # of peers for send(sync=True) + mp_obj_t recv_cb; // Callback when a packet is received + mp_obj_t recv_cb_arg; // Argument passed to callback + #if MICROPY_ESPNOW_RSSI + mp_obj_t peers_table; // A dictionary of discovered peers + #endif // MICROPY_ESPNOW_RSSI +} esp_espnow_obj_t; + +const mp_obj_type_t esp_espnow_type; + +// ### Initialisation and Config functions +// + +// Return a pointer to the ESPNow module singleton +// If state == INITIALISED check the device has been initialised. +// Raises OSError if not initialised and state == INITIALISED. +static esp_espnow_obj_t *_get_singleton() { + return MP_STATE_PORT(espnow_singleton); +} + +static esp_espnow_obj_t *_get_singleton_initialised() { + esp_espnow_obj_t *self = _get_singleton(); + // assert(self); + if (self->recv_buffer == NULL) { + // Throw an espnow not initialised error + check_esp_err(ESP_ERR_ESPNOW_NOT_INIT); + } + return self; +} + +// Allocate and initialise the ESPNow module as a singleton. +// Returns the initialised espnow_singleton. +STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, + size_t n_kw, const mp_obj_t *all_args) { + + // The espnow_singleton must be defined in MICROPY_PORT_ROOT_POINTERS + // (see mpconfigport.h) to prevent memory allocated here from being + // garbage collected. + // NOTE: on soft reset the espnow_singleton MUST be set to NULL and the + // ESP-NOW functions de-initialised (see main.c). + esp_espnow_obj_t *self = MP_STATE_PORT(espnow_singleton); + if (self != NULL) { + return self; + } + self = m_new_obj(esp_espnow_obj_t); + self->base.type = &esp_espnow_type; + self->recv_buffer_size = DEFAULT_RECV_BUFFER_SIZE; + self->recv_timeout_ms = DEFAULT_RECV_TIMEOUT_MS; + self->recv_buffer = NULL; // Buffer is allocated in espnow_init() + self->recv_cb = mp_const_none; + #if MICROPY_ESPNOW_RSSI + self->peers_table = mp_obj_new_dict(0); + // Prevent user code modifying the dict + mp_obj_dict_get_map(self->peers_table)->is_fixed = 1; + #endif // MICROPY_ESPNOW_RSSI + + // Set the global singleton pointer for the espnow protocol. + MP_STATE_PORT(espnow_singleton) = self; + + return self; +} + +// Forward declare the send and recv ESPNow callbacks +STATIC void send_cb(const uint8_t *mac_addr, esp_now_send_status_t status); + +STATIC void recv_cb(const uint8_t *mac_addr, const uint8_t *data, int len); + +// ESPNow.init(): Initialise the data buffers and ESP-NOW functions. +// Initialise the Espressif ESPNOW software stack, register callbacks and +// allocate the recv data buffers. +// Returns None. +static mp_obj_t espnow_init(mp_obj_t _) { + esp_espnow_obj_t *self = _get_singleton(); + if (self->recv_buffer == NULL) { // Already initialised + self->recv_buffer = m_new_obj(ringbuf_t); + ringbuf_alloc(self->recv_buffer, self->recv_buffer_size); + + esp_initialise_wifi(); // Call the wifi init code in network_wlan.c + check_esp_err(esp_now_init()); + check_esp_err(esp_now_register_recv_cb(recv_cb)); + check_esp_err(esp_now_register_send_cb(send_cb)); + } + return mp_const_none; +} + +// ESPNow.deinit(): De-initialise the ESPNOW software stack, disable callbacks +// and deallocate the recv data buffers. +// Note: this function is called from main.c:mp_task() to cleanup before soft +// reset, so cannot be declared STATIC and must guard against self == NULL;. +mp_obj_t espnow_deinit(mp_obj_t _) { + esp_espnow_obj_t *self = _get_singleton(); + if (self != NULL && self->recv_buffer != NULL) { + check_esp_err(esp_now_unregister_recv_cb()); + check_esp_err(esp_now_unregister_send_cb()); + check_esp_err(esp_now_deinit()); + self->recv_buffer->buf = NULL; + self->recv_buffer = NULL; + self->peer_count = 0; // esp_now_deinit() removes all peers. + self->tx_packets = self->tx_responses; + } + return mp_const_none; +} + +STATIC mp_obj_t espnow_active(size_t n_args, const mp_obj_t *args) { + esp_espnow_obj_t *self = _get_singleton(); + if (n_args > 1) { + if (mp_obj_is_true(args[1])) { + espnow_init(self); + } else { + espnow_deinit(self); + } + } + return self->recv_buffer != NULL ? mp_const_true : mp_const_false; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_active); + +// ESPNow.config(['param'|param=value, ..]) +// Get or set configuration values. Supported config params: +// buffer: size of buffer for rx packets (default=514 bytes) +// timeout: Default read timeout (default=300,000 milliseconds) +STATIC mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + esp_espnow_obj_t *self = _get_singleton(); + enum { ARG_get, ARG_buffer, ARG_timeout_ms, ARG_rate }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_buffer, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_timeout_ms, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MIN} }, + { MP_QSTR_rate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + }; + 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); + + if (args[ARG_buffer].u_int >= 0) { + self->recv_buffer_size = args[ARG_buffer].u_int; + } + if (args[ARG_timeout_ms].u_int != INT_MIN) { + self->recv_timeout_ms = args[ARG_timeout_ms].u_int; + } + if (args[ARG_rate].u_int >= 0) { + #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0) + esp_initialise_wifi(); // Call the wifi init code in network_wlan.c + check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_STA, args[ARG_rate].u_int)); + check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_AP, args[ARG_rate].u_int)); + #else + mp_raise_ValueError(MP_ERROR_TEXT("rate option not supported")); + #endif + } + if (args[ARG_get].u_obj == MP_OBJ_NULL) { + return mp_const_none; + } +#define QS(x) (uintptr_t)MP_OBJ_NEW_QSTR(x) + // Return the value of the requested parameter + uintptr_t name = (uintptr_t)args[ARG_get].u_obj; + if (name == QS(MP_QSTR_buffer)) { + return mp_obj_new_int(self->recv_buffer_size); + } else if (name == QS(MP_QSTR_timeout_ms)) { + return mp_obj_new_int(self->recv_timeout_ms); + } else { + mp_raise_ValueError(MP_ERROR_TEXT("unknown config param")); + } +#undef QS + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_config_obj, 1, espnow_config); + +// ESPNow.irq(recv_cb) +// Set callback function to be invoked when a message is received. +STATIC mp_obj_t espnow_irq(size_t n_args, const mp_obj_t *args) { + esp_espnow_obj_t *self = _get_singleton(); + mp_obj_t recv_cb = args[1]; + if (recv_cb != mp_const_none && !mp_obj_is_callable(recv_cb)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid handler")); + } + self->recv_cb = recv_cb; + self->recv_cb_arg = (n_args > 2) ? args[2] : mp_const_none; + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_irq_obj, 2, 3, espnow_irq); + +// ESPnow.stats(): Provide some useful stats. +// Returns a tuple of: +// (tx_pkts, tx_responses, tx_failures, rx_pkts, dropped_rx_pkts) +STATIC mp_obj_t espnow_stats(mp_obj_t _) { + const esp_espnow_obj_t *self = _get_singleton(); + return NEW_TUPLE( + mp_obj_new_int(self->tx_packets), + mp_obj_new_int(self->tx_responses), + mp_obj_new_int(self->tx_failures), + mp_obj_new_int(self->rx_packets), + mp_obj_new_int(self->dropped_rx_pkts)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_stats_obj, espnow_stats); + +#if MICROPY_ESPNOW_RSSI +// ### Maintaining the peer table and reading RSSI values +// +// We maintain a peers table for several reasons, to: +// - support monitoring the RSSI values for all peers; and +// - to return unique bytestrings for each peer which supports more efficient +// application memory usage and peer handling. + +// Get the RSSI value from the wifi packet header +static inline int8_t _get_rssi_from_wifi_pkt(const uint8_t *msg) { + // Warning: Secret magic to get the rssi from the wifi packet header + // See espnow.c:espnow_recv_cb() at https://github.com/espressif/esp-now/ + // In the wifi packet the msg comes after a wifi_promiscuous_pkt_t + // and a espnow_frame_format_t. + // Backtrack to get a pointer to the wifi_promiscuous_pkt_t. + static const size_t sizeof_espnow_frame_format = 39; + wifi_promiscuous_pkt_t *wifi_pkt = + (wifi_promiscuous_pkt_t *)(msg - sizeof_espnow_frame_format - + sizeof(wifi_promiscuous_pkt_t)); + + #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0) + return wifi_pkt->rx_ctrl.rssi - 100; // Offset rssi for IDF 4.0.2 + #else + return wifi_pkt->rx_ctrl.rssi; + #endif +} + +// Lookup a peer in the peers table and return a reference to the item in the +// peers_table. Add peer to the table if it is not found (may alloc memory). +// Will not return NULL. +static mp_map_elem_t *_lookup_add_peer(esp_espnow_obj_t *self, const uint8_t *peer) { + // We do not want to allocate any new memory in the case that the peer + // already exists in the peers_table (which is almost all the time). + // So, we use a byte string on the stack and look that up in the dict. + mp_map_t *map = mp_obj_dict_get_map(self->peers_table); + mp_obj_str_t peer_obj = {{&mp_type_bytes}, 0, ESP_NOW_ETH_ALEN, peer}; + mp_map_elem_t *item = mp_map_lookup(map, &peer_obj, MP_MAP_LOOKUP); + if (item == NULL) { + // If not found, add the peer using a new bytestring + map->is_fixed = 0; // Allow to modify the dict + mp_obj_t new_peer = mp_obj_new_bytes(peer, ESP_NOW_ETH_ALEN); + item = mp_map_lookup(map, new_peer, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); + item->value = mp_obj_new_list(2, NULL); + map->is_fixed = 1; // Relock the dict + } + return item; +} + +// Update the peers table with the new rssi value from a received pkt and +// return a reference to the item in the peers_table. +static mp_map_elem_t *_update_rssi(const uint8_t *peer, int8_t rssi, uint32_t time_ms) { + esp_espnow_obj_t *self = _get_singleton_initialised(); + // Lookup the peer in the device table + mp_map_elem_t *item = _lookup_add_peer(self, peer); + mp_obj_list_t *list = MP_OBJ_TO_PTR(item->value); + list->items[0] = MP_OBJ_NEW_SMALL_INT(rssi); + list->items[1] = mp_obj_new_int(time_ms); + return item; +} +#endif // MICROPY_ESPNOW_RSSI + +// Return C pointer to byte memory string/bytes/bytearray in obj. +// Raise ValueError if the length does not match expected len. +static uint8_t *_get_bytes_len_rw(mp_obj_t obj, size_t len, mp_uint_t rw) { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(obj, &bufinfo, rw); + if (bufinfo.len != len) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid buffer length")); + } + return (uint8_t *)bufinfo.buf; +} + +static uint8_t *_get_bytes_len(mp_obj_t obj, size_t len) { + return _get_bytes_len_rw(obj, len, MP_BUFFER_READ); +} + +static uint8_t *_get_bytes_len_w(mp_obj_t obj, size_t len) { + return _get_bytes_len_rw(obj, len, MP_BUFFER_WRITE); +} + +// Return C pointer to the MAC address. +// Raise ValueError if mac_addr is wrong type or is not 6 bytes long. +static const uint8_t *_get_peer(mp_obj_t mac_addr) { + return mp_obj_is_true(mac_addr) + ? _get_bytes_len(mac_addr, ESP_NOW_ETH_ALEN) : NULL; +} + +// Copy data from the ring buffer - wait if buffer is empty up to timeout_ms +// 0: Success +// -1: Not enough data available to complete read (try again later) +// -2: Requested read is larger than buffer - will never succeed +static int ringbuf_get_bytes_wait(ringbuf_t *r, uint8_t *data, size_t len, mp_int_t timeout_ms) { + mp_uint_t start = mp_hal_ticks_ms(); + int status = 0; + while (((status = ringbuf_get_bytes(r, data, len)) == -1) + && (timeout_ms < 0 || (mp_uint_t)(mp_hal_ticks_ms() - start) < (mp_uint_t)timeout_ms)) { + MICROPY_EVENT_POLL_HOOK; + } + return status; +} + +// ESPNow.recvinto(buffers[, timeout_ms]): +// Waits for an espnow message and copies the peer_addr and message into +// the buffers list. +// Arguments: +// buffers: (Optional) list of bytearrays to store return values. +// timeout_ms: (Optional) timeout in milliseconds (or None). +// Buffers should be a list: [bytearray(6), bytearray(250)] +// If buffers is 4 elements long, the rssi and timestamp values will be +// loaded into the 3rd and 4th elements. +// Default timeout is set with ESPNow.config(timeout=milliseconds). +// Return (None, None) on timeout. +STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) { + esp_espnow_obj_t *self = _get_singleton_initialised(); + + mp_int_t timeout_ms = ((n_args > 2 && args[2] != mp_const_none) + ? mp_obj_get_int(args[2]) : self->recv_timeout_ms); + + mp_obj_list_t *list = MP_OBJ_TO_PTR(args[1]); + if (!mp_obj_is_type(list, &mp_type_list) || list->len < 2) { + mp_raise_ValueError(MP_ERROR_TEXT("ESPNow.recvinto(): Invalid argument")); + } + mp_obj_array_t *msg = MP_OBJ_TO_PTR(list->items[1]); + if (mp_obj_is_type(msg, &mp_type_bytearray)) { + msg->len += msg->free; // Make all the space in msg array available + msg->free = 0; + } + #if MICROPY_ESPNOW_RSSI + uint8_t peer_buf[ESP_NOW_ETH_ALEN]; + #else + uint8_t *peer_buf = _get_bytes_len_w(list->items[0], ESP_NOW_ETH_ALEN); + #endif // MICROPY_ESPNOW_RSSI + uint8_t *msg_buf = _get_bytes_len_w(msg, ESP_NOW_MAX_DATA_LEN); + + // Read the packet header from the incoming buffer + espnow_hdr_t hdr; + if (ringbuf_get_bytes_wait(self->recv_buffer, (uint8_t *)&hdr, sizeof(hdr), timeout_ms) < 0) { + return MP_OBJ_NEW_SMALL_INT(0); // Timeout waiting for packet + } + int msg_len = hdr.msg_len; + + // Check the message packet header format and read the message data + if (hdr.magic != ESPNOW_MAGIC + || msg_len > ESP_NOW_MAX_DATA_LEN + || ringbuf_get_bytes(self->recv_buffer, peer_buf, ESP_NOW_ETH_ALEN) < 0 + || ringbuf_get_bytes(self->recv_buffer, msg_buf, msg_len) < 0) { + mp_raise_ValueError(MP_ERROR_TEXT("ESPNow.recv(): buffer error")); + } + if (mp_obj_is_type(msg, &mp_type_bytearray)) { + // Set the length of the message bytearray. + size_t size = msg->len + msg->free; + msg->len = msg_len; + msg->free = size - msg_len; + } + + #if MICROPY_ESPNOW_RSSI + // Update rssi value in the peer device table + mp_map_elem_t *entry = _update_rssi(peer_buf, hdr.rssi, hdr.time_ms); + list->items[0] = entry->key; // Set first element of list to peer + if (list->len >= 4) { + list->items[2] = MP_OBJ_NEW_SMALL_INT(hdr.rssi); + list->items[3] = mp_obj_new_int(hdr.time_ms); + } + #endif // MICROPY_ESPNOW_RSSI + + return MP_OBJ_NEW_SMALL_INT(msg_len); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_recvinto_obj, 2, 3, espnow_recvinto); + +// Test if data is available to read from the buffers +STATIC mp_obj_t espnow_any(const mp_obj_t _) { + esp_espnow_obj_t *self = _get_singleton_initialised(); + + return ringbuf_avail(self->recv_buffer) ? mp_const_true : mp_const_false; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_any_obj, espnow_any); + +// Used by espnow_send() for sends() with sync==True. +// Wait till all pending sent packet responses have been received. +// ie. self->tx_responses == self->tx_packets. +static void _wait_for_pending_responses(esp_espnow_obj_t *self) { + mp_uint_t start = mp_hal_ticks_ms(); + mp_uint_t t; + while (self->tx_responses < self->tx_packets) { + if ((t = mp_hal_ticks_ms() - start) > PENDING_RESPONSES_TIMEOUT_MS) { + mp_raise_OSError(MP_ETIMEDOUT); + } + if (t > PENDING_RESPONSES_BUSY_POLL_MS) { + // After 10ms of busy waiting give other tasks a look in. + MICROPY_EVENT_POLL_HOOK; + } + } +} + +// ESPNow.send(peer_addr, message, [sync (=true), size]) +// ESPNow.send(message) +// Send a message to the peer's mac address. Optionally wait for a response. +// If peer_addr == None or any non-true value, send to all registered peers. +// If sync == True, wait for response after sending. +// If size is provided it should be the number of bytes in message to send(). +// Returns: +// True if sync==False and message sent successfully. +// True if sync==True and message is received successfully by all recipients +// False if sync==True and message is not received by at least one recipient +// Raises: EAGAIN if the internal espnow buffers are full. +STATIC mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) { + esp_espnow_obj_t *self = _get_singleton_initialised(); + // Check the various combinations of input arguments + const uint8_t *peer = (n_args > 2) ? _get_peer(args[1]) : NULL; + mp_obj_t msg = (n_args > 2) ? args[2] : (n_args == 2) ? args[1] : MP_OBJ_NULL; + bool sync = n_args <= 3 || args[3] == mp_const_none || mp_obj_is_true(args[3]); + + // Get a pointer to the data buffer of the message + mp_buffer_info_t message; + mp_get_buffer_raise(msg, &message, MP_BUFFER_READ); + + if (sync) { + // Flush out any pending responses. + // If the last call was sync==False there may be outstanding responses + // still to be received (possible many if we just had a burst of + // unsync send()s). We need to wait for all pending responses if this + // call has sync=True. + _wait_for_pending_responses(self); + } + int saved_failures = self->tx_failures; + // Send the packet - try, try again if internal esp-now buffers are full. + esp_err_t err; + mp_uint_t start = mp_hal_ticks_ms(); + while ((ESP_ERR_ESPNOW_NO_MEM == (err = esp_now_send(peer, message.buf, message.len))) + && (mp_uint_t)(mp_hal_ticks_ms() - start) < (mp_uint_t)DEFAULT_SEND_TIMEOUT_MS) { + MICROPY_EVENT_POLL_HOOK; + } + check_esp_err(err); // Will raise OSError if e != ESP_OK + // Increment the sent packet count. If peer_addr==NULL msg will be + // sent to all peers EXCEPT any broadcast or multicast addresses. + self->tx_packets += ((peer == NULL) ? self->peer_count : 1); + if (sync) { + // Wait for and tally all the expected responses from peers + _wait_for_pending_responses(self); + } + // Return False if sync and any peers did not respond. + return mp_obj_new_bool(!(sync && self->tx_failures != saved_failures)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 2, 4, espnow_send); + +// ### The ESP_Now send and recv callback routines +// + +// Callback triggered when a sent packet is acknowledged by the peer (or not). +// Just count the number of responses and number of failures. +// These are used in the send() logic. +STATIC void send_cb(const uint8_t *mac_addr, esp_now_send_status_t status) { + esp_espnow_obj_t *self = _get_singleton(); + self->tx_responses++; + if (status != ESP_NOW_SEND_SUCCESS) { + self->tx_failures++; + } +} + +// Callback triggered when an ESP-Now packet is received. +// Write the peer MAC address and the message into the recv_buffer as an +// ESPNow packet. +// If the buffer is full, drop the message and increment the dropped count. +// Schedules the user callback if one has been registered (ESPNow.config()). +STATIC void recv_cb(const uint8_t *mac_addr, const uint8_t *msg, int msg_len) { + esp_espnow_obj_t *self = _get_singleton(); + ringbuf_t *buf = self->recv_buffer; + // TODO: Test this works with ">". + if (sizeof(espnow_pkt_t) + msg_len >= ringbuf_free(buf)) { + self->dropped_rx_pkts++; + return; + } + espnow_hdr_t header; + header.magic = ESPNOW_MAGIC; + header.msg_len = msg_len; + #if MICROPY_ESPNOW_RSSI + header.rssi = _get_rssi_from_wifi_pkt(msg); + header.time_ms = mp_hal_ticks_ms(); + #endif // MICROPY_ESPNOW_RSSI + + ringbuf_put_bytes(buf, (uint8_t *)&header, sizeof(header)); + ringbuf_put_bytes(buf, mac_addr, ESP_NOW_ETH_ALEN); + ringbuf_put_bytes(buf, msg, msg_len); + self->rx_packets++; + if (self->recv_cb != mp_const_none) { + mp_sched_schedule(self->recv_cb, self->recv_cb_arg); + } +} + +// ### Peer Management Functions +// + +// Set the ESP-NOW Primary Master Key (pmk) (for encrypted communications). +// Raise OSError if ESP-NOW functions are not initialised. +// Raise ValueError if key is not a bytes-like object exactly 16 bytes long. +STATIC mp_obj_t espnow_set_pmk(mp_obj_t _, mp_obj_t key) { + check_esp_err(esp_now_set_pmk(_get_bytes_len(key, ESP_NOW_KEY_LEN))); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_set_pmk_obj, espnow_set_pmk); + +// Common code for add_peer() and mod_peer() to process the args and kw_args: +// Raise ValueError if the LMK is not a bytes-like object of exactly 16 bytes. +// Raise TypeError if invalid keyword args or too many positional args. +// Return true if all args parsed correctly. +STATIC bool _update_peer_info( + esp_now_peer_info_t *peer, size_t n_args, + const mp_obj_t *pos_args, mp_map_t *kw_args) { + + enum { ARG_lmk, ARG_channel, ARG_ifidx, ARG_encrypt }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_lmk, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_channel, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_ifidx, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_encrypt, 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 (args[ARG_lmk].u_obj != mp_const_none) { + mp_obj_t obj = args[ARG_lmk].u_obj; + peer->encrypt = mp_obj_is_true(obj); + if (peer->encrypt) { + // Key must be 16 bytes in length. + memcpy(peer->lmk, _get_bytes_len(obj, ESP_NOW_KEY_LEN), ESP_NOW_KEY_LEN); + } + } + if (args[ARG_channel].u_obj != mp_const_none) { + peer->channel = mp_obj_get_int(args[ARG_channel].u_obj); + } + if (args[ARG_ifidx].u_obj != mp_const_none) { + peer->ifidx = mp_obj_get_int(args[ARG_ifidx].u_obj); + } + if (args[ARG_encrypt].u_obj != mp_const_none) { + peer->encrypt = mp_obj_is_true(args[ARG_encrypt].u_obj); + } + return true; +} + +// Update the cached peer count in self->peer_count; +// The peer_count ignores broadcast and multicast addresses and is used for the +// send() logic and is updated from add_peer(), mod_peer() and del_peer(). +STATIC void _update_peer_count() { + esp_espnow_obj_t *self = _get_singleton_initialised(); + + esp_now_peer_info_t peer = {0}; + bool from_head = true; + int count = 0; + // esp_now_fetch_peer() skips over any broadcast or multicast addresses + while (esp_now_fetch_peer(from_head, &peer) == ESP_OK) { + from_head = false; + if (++count >= ESP_NOW_MAX_TOTAL_PEER_NUM) { + break; // Should not happen + } + } + self->peer_count = count; +} + +// ESPNow.add_peer(peer_mac, [lmk, [channel, [ifidx, [encrypt]]]]) or +// ESPNow.add_peer(peer_mac, [lmk=b'0123456789abcdef'|b''|None|False], +// [channel=1..11|0], [ifidx=0|1], [encrypt=True|False]) +// Positional args set to None will be left at defaults. +// Raise OSError if ESPNow.init() has not been called. +// Raise ValueError if mac or LMK are not bytes-like objects or wrong length. +// Raise TypeError if invalid keyword args or too many positional args. +// Return None. +STATIC mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { + esp_now_peer_info_t peer = {0}; + memcpy(peer.peer_addr, _get_peer(args[1]), ESP_NOW_ETH_ALEN); + _update_peer_info(&peer, n_args - 2, args + 2, kw_args); + + check_esp_err(esp_now_add_peer(&peer)); + _update_peer_count(); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_add_peer_obj, 2, espnow_add_peer); + +// ESPNow.del_peer(peer_mac): Unregister peer_mac. +// Raise OSError if ESPNow.init() has not been called. +// Raise ValueError if peer is not a bytes-like objects or wrong length. +// Return None. +STATIC mp_obj_t espnow_del_peer(mp_obj_t _, mp_obj_t peer) { + uint8_t peer_addr[ESP_NOW_ETH_ALEN]; + memcpy(peer_addr, _get_peer(peer), ESP_NOW_ETH_ALEN); + + check_esp_err(esp_now_del_peer(peer_addr)); + _update_peer_count(); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_del_peer_obj, espnow_del_peer); + +// Convert a peer_info struct to python tuple +// Used by espnow_get_peer() and espnow_get_peers() +static mp_obj_t _peer_info_to_tuple(const esp_now_peer_info_t *peer) { + return NEW_TUPLE( + mp_obj_new_bytes(peer->peer_addr, MP_ARRAY_SIZE(peer->peer_addr)), + mp_obj_new_bytes(peer->lmk, MP_ARRAY_SIZE(peer->lmk)), + mp_obj_new_int(peer->channel), + mp_obj_new_int(peer->ifidx), + (peer->encrypt) ? mp_const_true : mp_const_false); +} + +// ESPNow.get_peers(): Fetch peer_info records for all registered ESPNow peers. +// Raise OSError if ESPNow.init() has not been called. +// Return a tuple of tuples: +// ((peer_addr, lmk, channel, ifidx, encrypt), +// (peer_addr, lmk, channel, ifidx, encrypt), ...) +STATIC mp_obj_t espnow_get_peers(mp_obj_t _) { + esp_espnow_obj_t *self = _get_singleton_initialised(); + + // Build and initialise the peer info tuple. + mp_obj_tuple_t *peerinfo_tuple = mp_obj_new_tuple(self->peer_count, NULL); + esp_now_peer_info_t peer = {0}; + for (int i = 0; i < peerinfo_tuple->len; i++) { + int status = esp_now_fetch_peer((i == 0), &peer); + peerinfo_tuple->items[i] = + (status == ESP_OK ? _peer_info_to_tuple(&peer) : mp_const_none); + } + + return peerinfo_tuple; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_get_peers_obj, espnow_get_peers); + +#if MICROPY_ESPNOW_EXTRA_PEER_METHODS +// ESPNow.get_peer(peer_mac): Get the peer info for peer_mac as a tuple. +// Raise OSError if ESPNow.init() has not been called. +// Raise ValueError if mac or LMK are not bytes-like objects or wrong length. +// Return a tuple of (peer_addr, lmk, channel, ifidx, encrypt). +STATIC mp_obj_t espnow_get_peer(mp_obj_t _, mp_obj_t arg1) { + esp_now_peer_info_t peer = {0}; + memcpy(peer.peer_addr, _get_peer(arg1), ESP_NOW_ETH_ALEN); + + check_esp_err(esp_now_get_peer(peer.peer_addr, &peer)); + + return _peer_info_to_tuple(&peer); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_get_peer_obj, espnow_get_peer); + +// ESPNow.mod_peer(peer_mac, [lmk, [channel, [ifidx, [encrypt]]]]) or +// ESPNow.mod_peer(peer_mac, [lmk=b'0123456789abcdef'|b''|None|False], +// [channel=1..11|0], [ifidx=0|1], [encrypt=True|False]) +// Positional args set to None will be left at current values. +// Raise OSError if ESPNow.init() has not been called. +// Raise ValueError if mac or LMK are not bytes-like objects or wrong length. +// Raise TypeError if invalid keyword args or too many positional args. +// Return None. +STATIC mp_obj_t espnow_mod_peer(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { + esp_now_peer_info_t peer = {0}; + memcpy(peer.peer_addr, _get_peer(args[1]), ESP_NOW_ETH_ALEN); + check_esp_err(esp_now_get_peer(peer.peer_addr, &peer)); + + _update_peer_info(&peer, n_args - 2, args + 2, kw_args); + + check_esp_err(esp_now_mod_peer(&peer)); + _update_peer_count(); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_mod_peer_obj, 2, espnow_mod_peer); + +// ESPNow.espnow_peer_count(): Get the number of registered peers. +// Raise OSError if ESPNow.init() has not been called. +// Return a tuple of (num_total_peers, num_encrypted_peers). +STATIC mp_obj_t espnow_peer_count(mp_obj_t _) { + esp_now_peer_num_t peer_num = {0}; + check_esp_err(esp_now_get_peer_num(&peer_num)); + + return NEW_TUPLE( + mp_obj_new_int(peer_num.total_num), + mp_obj_new_int(peer_num.encrypt_num)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_peer_count_obj, espnow_peer_count); +#endif + +STATIC const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&espnow_active_obj) }, + { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&espnow_config_obj) }, + { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&espnow_irq_obj) }, + { MP_ROM_QSTR(MP_QSTR_stats), MP_ROM_PTR(&espnow_stats_obj) }, + + // Send and receive messages + { MP_ROM_QSTR(MP_QSTR_recvinto), MP_ROM_PTR(&espnow_recvinto_obj) }, + { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&espnow_send_obj) }, + { MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(&espnow_any_obj) }, + + // Peer management functions + { MP_ROM_QSTR(MP_QSTR_set_pmk), MP_ROM_PTR(&espnow_set_pmk_obj) }, + { MP_ROM_QSTR(MP_QSTR_add_peer), MP_ROM_PTR(&espnow_add_peer_obj) }, + { MP_ROM_QSTR(MP_QSTR_del_peer), MP_ROM_PTR(&espnow_del_peer_obj) }, + { MP_ROM_QSTR(MP_QSTR_get_peers), MP_ROM_PTR(&espnow_get_peers_obj) }, + #if MICROPY_ESPNOW_EXTRA_PEER_METHODS + { MP_ROM_QSTR(MP_QSTR_mod_peer), MP_ROM_PTR(&espnow_mod_peer_obj) }, + { MP_ROM_QSTR(MP_QSTR_get_peer), MP_ROM_PTR(&espnow_get_peer_obj) }, + { MP_ROM_QSTR(MP_QSTR_peer_count), MP_ROM_PTR(&espnow_peer_count_obj) }, + #endif // MICROPY_ESPNOW_EXTRA_PEER_METHODS +}; +STATIC MP_DEFINE_CONST_DICT(esp_espnow_locals_dict, esp_espnow_locals_dict_table); + +STATIC const mp_rom_map_elem_t espnow_globals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__espnow) }, + { MP_ROM_QSTR(MP_QSTR_ESPNowBase), MP_ROM_PTR(&esp_espnow_type) }, + { MP_ROM_QSTR(MP_QSTR_MAX_DATA_LEN), MP_ROM_INT(ESP_NOW_MAX_DATA_LEN)}, + { MP_ROM_QSTR(MP_QSTR_ADDR_LEN), MP_ROM_INT(ESP_NOW_ETH_ALEN)}, + { MP_ROM_QSTR(MP_QSTR_KEY_LEN), MP_ROM_INT(ESP_NOW_KEY_LEN)}, + { MP_ROM_QSTR(MP_QSTR_MAX_TOTAL_PEER_NUM), MP_ROM_INT(ESP_NOW_MAX_TOTAL_PEER_NUM)}, + { MP_ROM_QSTR(MP_QSTR_MAX_ENCRYPT_PEER_NUM), MP_ROM_INT(ESP_NOW_MAX_ENCRYPT_PEER_NUM)}, +}; +STATIC MP_DEFINE_CONST_DICT(espnow_globals_dict, espnow_globals_dict_table); + +// ### Dummy Buffer Protocol support +// ...so asyncio can poll.ipoll() on this device + +// Support ioctl(MP_STREAM_POLL, ) for asyncio +STATIC mp_uint_t espnow_stream_ioctl( + mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { + if (request != MP_STREAM_POLL) { + *errcode = MP_EINVAL; + return MP_STREAM_ERROR; + } + esp_espnow_obj_t *self = _get_singleton(); + return (self->recv_buffer == NULL) ? 0 : // If not initialised + arg ^ ( + // If no data in the buffer, unset the Read ready flag + ((ringbuf_avail(self->recv_buffer) == 0) ? MP_STREAM_POLL_RD : 0) | + // If still waiting for responses, unset the Write ready flag + ((self->tx_responses < self->tx_packets) ? MP_STREAM_POLL_WR : 0)); +} + +STATIC const mp_stream_p_t espnow_stream_p = { + .ioctl = espnow_stream_ioctl, +}; + +#if MICROPY_ESPNOW_RSSI +// Return reference to the dictionary of peers we have seen: +// {peer1: (rssi, time_sec), peer2: (rssi, time_msec), ...} +// where: +// peerX is a byte string containing the 6-byte mac address of the peer, +// rssi is the wifi signal strength from the last msg received +// (in dBm from -127 to 0) +// time_sec is the time in milliseconds since device last booted. +STATIC void espnow_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { + esp_espnow_obj_t *self = _get_singleton(); + if (dest[0] != MP_OBJ_NULL) { // Only allow "Load" operation + return; + } + if (attr == MP_QSTR_peers_table) { + dest[0] = self->peers_table; + return; + } + dest[1] = MP_OBJ_SENTINEL; // Attribute not found +} +#endif // MICROPY_ESPNOW_RSSI + +MP_DEFINE_CONST_OBJ_TYPE( + esp_espnow_type, + MP_QSTR_ESPNowBase, + MP_TYPE_FLAG_NONE, + make_new, espnow_make_new, + #if MICROPY_ESPNOW_RSSI + attr, espnow_attr, + #endif // MICROPY_ESPNOW_RSSI + protocol, &espnow_stream_p, + locals_dict, &esp_espnow_locals_dict + ); + +const mp_obj_module_t mp_module_espnow = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&espnow_globals_dict, +}; + +MP_REGISTER_MODULE(MP_QSTR__espnow, mp_module_espnow); +MP_REGISTER_ROOT_POINTER(struct _esp_espnow_obj_t *espnow_singleton); diff --git a/ports/esp32/modespnow.h b/ports/esp32/modespnow.h new file mode 100644 index 0000000000..3c6280b1ce --- /dev/null +++ b/ports/esp32/modespnow.h @@ -0,0 +1,30 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Glenn Moloney @glenn20 + * + * 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 "py/obj.h" + +// Called from main.c:mp_task() to reset the espnow software stack +mp_obj_t espnow_deinit(mp_obj_t _); diff --git a/ports/esp32/modnetwork.h b/ports/esp32/modnetwork.h index 5f2767ac8d..d7a99f5c94 100644 --- a/ports/esp32/modnetwork.h +++ b/ports/esp32/modnetwork.h @@ -63,5 +63,6 @@ static inline void esp_exceptions(esp_err_t e) { void usocket_events_deinit(void); void network_wlan_event_handler(system_event_t *event); +void esp_initialise_wifi(void); #endif diff --git a/ports/esp32/modules/espnow.py b/ports/esp32/modules/espnow.py new file mode 100644 index 0000000000..6956a3a935 --- /dev/null +++ b/ports/esp32/modules/espnow.py @@ -0,0 +1,30 @@ +# espnow module for MicroPython on ESP32 +# MIT license; Copyright (c) 2022 Glenn Moloney @glenn20 + +from _espnow import * + + +class ESPNow(ESPNowBase): + # Static buffers for alloc free receipt of messages with ESPNow.irecv(). + _data = [None, bytearray(MAX_DATA_LEN)] + _none_tuple = (None, None) + + def __init__(self): + super().__init__() + + def irecv(self, timeout_ms=None): + n = self.recvinto(self._data, timeout_ms) + return self._data if n else self._none_tuple + + def recv(self, timeout_ms=None): + n = self.recvinto(self._data, timeout_ms) + return [bytes(x) for x in self._data] if n else self._none_tuple + + def irq(self, callback): + super().irq(callback, self) + + def __iter__(self): + return self + + def __next__(self): + return self.irecv() # Use alloc free irecv() method diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 845c7e8fd7..807ae23b0c 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -70,6 +70,9 @@ #define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32) // extended modules +#ifndef MICROPY_ESPNOW +#define MICROPY_ESPNOW (1) +#endif #ifndef MICROPY_PY_BLUETOOTH #define MICROPY_PY_BLUETOOTH (1) #define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS (1) diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index aefc4394c2..84b92577fc 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -159,16 +159,20 @@ STATIC void require_if(mp_obj_t wlan_if, int if_no) { } } -STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) { - static int initialized = 0; - if (!initialized) { +void esp_initialise_wifi() { + static int wifi_initialized = 0; + if (!wifi_initialized) { wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_LOGD("modnetwork", "Initializing WiFi"); esp_exceptions(esp_wifi_init(&cfg)); esp_exceptions(esp_wifi_set_storage(WIFI_STORAGE_RAM)); ESP_LOGD("modnetwork", "Initialized"); - initialized = 1; + wifi_initialized = 1; } +} + +STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) { + esp_initialise_wifi(); int idx = (n_args > 0) ? mp_obj_get_int(args[0]) : WIFI_IF_STA; if (idx == WIFI_IF_STA) { diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile index 3aa9438f6e..e3727dfeda 100644 --- a/ports/esp8266/Makefile +++ b/ports/esp8266/Makefile @@ -70,6 +70,11 @@ LD_FILES ?= boards/esp8266_2m.ld LDFLAGS += -nostdlib -T $(LD_FILES) -Map=$(@:.elf=.map) --cref LIBS += -L$(ESP_SDK)/lib -lmain -ljson -llwip_open -lpp -lnet80211 -lwpa -lphy -lnet80211 +ifeq ($(MICROPY_ESPNOW),1) +CFLAGS += -DMICROPY_ESPNOW=1 +LIBS += -lespnow +endif + LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) LIBS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc @@ -113,6 +118,11 @@ SRC_C = \ hspi.c \ $(wildcard $(BOARD_DIR)/*.c) \ +ifeq ($(MICROPY_ESPNOW),1) +SRC_C += \ + modespnow.c +endif + LIB_SRC_C = $(addprefix lib/,\ libm/math.c \ libm/fmodf.c \ diff --git a/ports/esp8266/boards/GENERIC/mpconfigboard.mk b/ports/esp8266/boards/GENERIC/mpconfigboard.mk index 6861317218..8d7babdc84 100644 --- a/ports/esp8266/boards/GENERIC/mpconfigboard.mk +++ b/ports/esp8266/boards/GENERIC/mpconfigboard.mk @@ -1,5 +1,6 @@ LD_FILES = boards/esp8266_2m.ld +MICROPY_ESPNOW ?= 1 MICROPY_PY_BTREE ?= 1 MICROPY_VFS_FAT ?= 1 MICROPY_VFS_LFS2 ?= 1 diff --git a/ports/esp8266/boards/GENERIC_1M/mpconfigboard.mk b/ports/esp8266/boards/GENERIC_1M/mpconfigboard.mk index fdbb0d8245..adc31702e0 100644 --- a/ports/esp8266/boards/GENERIC_1M/mpconfigboard.mk +++ b/ports/esp8266/boards/GENERIC_1M/mpconfigboard.mk @@ -1,4 +1,5 @@ LD_FILES = boards/esp8266_1m.ld +MICROPY_ESPNOW ?= 1 MICROPY_PY_BTREE ?= 1 MICROPY_VFS_LFS2 ?= 1 diff --git a/ports/esp8266/boards/esp8266_common.ld b/ports/esp8266/boards/esp8266_common.ld index 0fbbf55217..7e230fd42a 100644 --- a/ports/esp8266/boards/esp8266_common.ld +++ b/ports/esp8266/boards/esp8266_common.ld @@ -83,6 +83,7 @@ SECTIONS *libnet80211.a:(.literal.* .text.*) *libwpa.a:(.literal.* .text.*) *libwpa2.a:(.literal.* .text.*) + *libespnow.a:(.literal.* .text.*) /* we put some specific text in this section */ diff --git a/ports/esp8266/boards/manifest.py b/ports/esp8266/boards/manifest.py index 10fa6da279..17f58feac8 100644 --- a/ports/esp8266/boards/manifest.py +++ b/ports/esp8266/boards/manifest.py @@ -1,4 +1,5 @@ freeze("$(PORT_DIR)/modules") +# require("aioespnow") require("bundle-networking") require("dht") require("ds18x20") diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c index 238490ebef..2aa81aba05 100644 --- a/ports/esp8266/main.c +++ b/ports/esp8266/main.c @@ -45,6 +45,10 @@ #include "gccollect.h" #include "user_interface.h" +#if MICROPY_ESPNOW +#include "modespnow.h" +#endif + STATIC char heap[38 * 1024]; STATIC void mp_reset(void) { @@ -73,6 +77,10 @@ STATIC void mp_reset(void) { mp_uos_dupterm_obj.fun.var(2, args); } + #if MICROPY_ESPNOW + espnow_deinit(mp_const_none); + #endif + #if MICROPY_MODULE_FROZEN pyexec_frozen_module("_boot.py", false); pyexec_file_if_exists("boot.py"); diff --git a/ports/esp8266/modespnow.c b/ports/esp8266/modespnow.c new file mode 100644 index 0000000000..1f89204676 --- /dev/null +++ b/ports/esp8266/modespnow.c @@ -0,0 +1,507 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017-2020 Nick Moore + * Copyright (c) 2018 shawwwn + * Copyright (c) 2020-2021 Glenn Moloney @glenn20 + * + * 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 +#include +#include + +#include "py/runtime.h" + +#if MICROPY_ESPNOW + +#include "c_types.h" +#include "espnow.h" + +#include "py/mphal.h" +#include "py/mperrno.h" +#include "py/qstr.h" +#include "py/objstr.h" +#include "py/objarray.h" +#include "py/stream.h" +#include "py/binary.h" +#include "py/ringbuf.h" + +#include "mpconfigport.h" + +#include "modespnow.h" + +// For the esp8266 +#define ESP_NOW_MAX_DATA_LEN (250) +#define ESP_NOW_KEY_LEN (16) +#define ESP_NOW_ETH_ALEN (6) +#define ESP_NOW_SEND_SUCCESS (0) +#define ESP_ERR_ESPNOW_NO_MEM (-77777) +#define ESP_OK (0) +#define ESP_NOW_MAX_TOTAL_PEER_NUM (20) +#define ESP_NOW_MAX_ENCRYPT_PEER_NUM (6) +#define ESP_ERR_ESPNOW_NOT_INIT (0x300 + 100 + 1) +typedef int esp_err_t; + +static const uint8_t ESPNOW_MAGIC = 0x99; + +// Use this for peeking at the header of the next packet in the buffer. +typedef struct { + uint8_t magic; // = ESPNOW_MAGIC + uint8_t msg_len; // Length of the message +} __attribute__((packed)) espnow_hdr_t; + +// ESPNow packet format for the receive buffer. +typedef struct { + espnow_hdr_t hdr; // The header + uint8_t peer[6]; // Peer address + uint8_t msg[0]; // Message is up to 250 bytes +} __attribute__((packed)) espnow_pkt_t; + +// The maximum length of an espnow packet (bytes) +static const size_t MAX_PACKET_LEN = ( + sizeof(espnow_pkt_t) + ESP_NOW_MAX_DATA_LEN); + +// Enough for 2 full-size packets: 2 * (6 + 2 + 250) = 516 bytes +// Will allocate an additional 7 bytes for buffer overhead +#define DEFAULT_RECV_BUFFER_SIZE \ + (2 * (sizeof(espnow_pkt_t) + ESP_NOW_MAX_DATA_LEN)) + +// Default timeout (millisec) to wait for incoming ESPNow messages (5 minutes). +#define DEFAULT_RECV_TIMEOUT_MS (5 * 60 * 1000) + +// Number of milliseconds to wait for pending responses to sent packets. +// This is a fallback which should never be reached. +#define PENDING_RESPONSES_TIMEOUT_MS 100 + +// The data structure for the espnow_singleton. +typedef struct _esp_espnow_obj_t { + mp_obj_base_t base; + ringbuf_t *recv_buffer; // A buffer for received packets + size_t recv_buffer_size; // Size of recv buffer + size_t recv_timeout_ms; // Timeout for irecv() + size_t tx_packets; // Count of sent packets + volatile size_t tx_responses; // # of sent packet responses received + volatile size_t tx_failures; // # of sent packet responses failed +} esp_espnow_obj_t; + +// Initialised below. +const mp_obj_type_t esp_espnow_type; + +static esp_espnow_obj_t espnow_singleton = { + .base.type = &esp_espnow_type, + .recv_buffer = NULL, + .recv_buffer_size = DEFAULT_RECV_BUFFER_SIZE, + .recv_timeout_ms = DEFAULT_RECV_TIMEOUT_MS, +}; + +// ### Initialisation and Config functions +// + +static void check_esp_err(int e) { + if (e != 0) { + mp_raise_OSError(e); + } +} + +// Return a pointer to the ESPNow module singleton +// If state == INITIALISED check the device has been initialised. +// Raises OSError if not initialised and state == INITIALISED. +static esp_espnow_obj_t *_get_singleton() { + return &espnow_singleton; +} + +static esp_espnow_obj_t *_get_singleton_initialised() { + esp_espnow_obj_t *self = _get_singleton(); + if (self->recv_buffer == NULL) { + // Throw an espnow not initialised error + check_esp_err(ESP_ERR_ESPNOW_NOT_INIT); + } + return self; +} + +// Allocate and initialise the ESPNow module as a singleton. +// Returns the initialised espnow_singleton. +STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, + size_t n_kw, const mp_obj_t *all_args) { + + return _get_singleton(); +} + +// Forward declare the send and recv ESPNow callbacks +STATIC void send_cb(uint8_t *mac_addr, uint8_t status); + +STATIC void recv_cb(uint8_t *mac_addr, uint8_t *data, uint8_t len); + +// ESPNow.deinit(): De-initialise the ESPNOW software stack, disable callbacks +// and deallocate the recv data buffers. +// Note: this function is called from main.c:mp_task() to cleanup before soft +// reset, so cannot be declared STATIC and must guard against self == NULL;. +mp_obj_t espnow_deinit(mp_obj_t _) { + esp_espnow_obj_t *self = _get_singleton(); + if (self->recv_buffer != NULL) { + // esp_now_unregister_recv_cb(); + esp_now_deinit(); + self->recv_buffer->buf = NULL; + self->recv_buffer = NULL; + self->tx_packets = self->tx_responses; + } + MP_STATE_PORT(espnow_buffer) = NULL; + return mp_const_none; +} + +// ESPNow.active(): Initialise the data buffers and ESP-NOW functions. +// Initialise the Espressif ESPNOW software stack, register callbacks and +// allocate the recv data buffers. +// Returns True if interface is active, else False. +STATIC mp_obj_t espnow_active(size_t n_args, const mp_obj_t *args) { + esp_espnow_obj_t *self = args[0]; + if (n_args > 1) { + if (mp_obj_is_true(args[1])) { + if (self->recv_buffer == NULL) { // Already initialised + self->recv_buffer = m_new_obj(ringbuf_t); + ringbuf_alloc(self->recv_buffer, self->recv_buffer_size); + MP_STATE_PORT(espnow_buffer) = self->recv_buffer; + esp_now_init(); + esp_now_set_self_role(ESP_NOW_ROLE_COMBO); + esp_now_register_recv_cb(recv_cb); + esp_now_register_send_cb(send_cb); + } + } else { + espnow_deinit(self); + } + } + return mp_obj_new_bool(self->recv_buffer != NULL); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_active); + +// ESPNow.config(): Initialise the data buffers and ESP-NOW functions. +// Initialise the Espressif ESPNOW software stack, register callbacks and +// allocate the recv data buffers. +// Returns True if interface is active, else False. +STATIC mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + esp_espnow_obj_t *self = _get_singleton(); + enum { ARG_rxbuf, ARG_timeout_ms }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_rxbuf, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_timeout_ms, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + }; + 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); + if (args[ARG_rxbuf].u_int >= 0) { + self->recv_buffer_size = args[ARG_rxbuf].u_int; + } + if (args[ARG_timeout_ms].u_int >= 0) { + self->recv_timeout_ms = args[ARG_timeout_ms].u_int; + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_config_obj, 1, espnow_config); + +// ### The ESP_Now send and recv callback routines +// + +// Callback triggered when a sent packet is acknowledged by the peer (or not). +// Just count the number of responses and number of failures. +// These are used in the send()/write() logic. +STATIC void send_cb(uint8_t *mac_addr, uint8_t status) { + esp_espnow_obj_t *self = _get_singleton(); + self->tx_responses++; + if (status != ESP_NOW_SEND_SUCCESS) { + self->tx_failures++; + } +} + +// Callback triggered when an ESP-Now packet is received. +// Write the peer MAC address and the message into the recv_buffer as an +// ESPNow packet. +// If the buffer is full, drop the message and increment the dropped count. +// Schedules the user callback if one has been registered (ESPNow.config()). +STATIC void recv_cb(uint8_t *mac_addr, uint8_t *msg, uint8_t msg_len) { + esp_espnow_obj_t *self = _get_singleton(); + ringbuf_t *buf = self->recv_buffer; + // TODO: Test this works with ">". + if (buf == NULL || sizeof(espnow_pkt_t) + msg_len >= ringbuf_free(buf)) { + return; + } + espnow_hdr_t header; + header.magic = ESPNOW_MAGIC; + header.msg_len = msg_len; + + ringbuf_put_bytes(buf, (uint8_t *)&header, sizeof(header)); + ringbuf_put_bytes(buf, mac_addr, ESP_NOW_ETH_ALEN); + ringbuf_put_bytes(buf, msg, msg_len); +} + +// Return C pointer to byte memory string/bytes/bytearray in obj. +// Raise ValueError if the length does not match expected len. +static uint8_t *_get_bytes_len_rw(mp_obj_t obj, size_t len, mp_uint_t rw) { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(obj, &bufinfo, rw); + if (bufinfo.len != len) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid buffer length")); + } + return (uint8_t *)bufinfo.buf; +} + +static uint8_t *_get_bytes_len(mp_obj_t obj, size_t len) { + return _get_bytes_len_rw(obj, len, MP_BUFFER_READ); +} + +static uint8_t *_get_bytes_len_w(mp_obj_t obj, size_t len) { + return _get_bytes_len_rw(obj, len, MP_BUFFER_WRITE); +} + +// ### Handling espnow packets in the recv buffer +// + +// Copy data from the ring buffer - wait if buffer is empty up to timeout_ms +// 0: Success +// -1: Not enough data available to complete read (try again later) +// -2: Requested read is larger than buffer - will never succeed +static int ringbuf_get_bytes_wait(ringbuf_t *r, uint8_t *data, size_t len, mp_int_t timeout_ms) { + mp_uint_t start = mp_hal_ticks_ms(); + int status = 0; + while (((status = ringbuf_get_bytes(r, data, len)) == -1) + && (timeout_ms < 0 || (mp_uint_t)(mp_hal_ticks_ms() - start) < (mp_uint_t)timeout_ms)) { + MICROPY_EVENT_POLL_HOOK; + } + return status; +} + +// ESPNow.recvinto([timeout_ms, []]): +// Returns a list of byte strings: (peer_addr, message) where peer_addr is +// the MAC address of the sending peer. +// Arguments: +// timeout_ms: timeout in milliseconds (or None). +// buffers: list of bytearrays to store values: [peer, message]. +// Default timeout is set with ESPNow.config(timeout=milliseconds). +// Return (None, None) on timeout. +STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) { + esp_espnow_obj_t *self = _get_singleton_initialised(); + + size_t timeout_ms = ((n_args > 2 && args[2] != mp_const_none) + ? mp_obj_get_int(args[2]) : self->recv_timeout_ms); + + mp_obj_list_t *list = MP_OBJ_TO_PTR(args[1]); + if (!mp_obj_is_type(list, &mp_type_list) || list->len < 2) { + mp_raise_ValueError(MP_ERROR_TEXT("ESPNow.recvinto(): Invalid argument")); + } + mp_obj_array_t *msg = MP_OBJ_TO_PTR(list->items[1]); + size_t msg_size = msg->len + msg->free; + if (mp_obj_is_type(msg, &mp_type_bytearray)) { + msg->len = msg_size; // Make all the space in msg array available + msg->free = 0; + } + uint8_t *peer_buf = _get_bytes_len_w(list->items[0], ESP_NOW_ETH_ALEN); + uint8_t *msg_buf = _get_bytes_len_w(msg, ESP_NOW_MAX_DATA_LEN); + + // Read the packet header from the incoming buffer + espnow_hdr_t hdr; + if (ringbuf_get_bytes_wait(self->recv_buffer, (uint8_t *)&hdr, sizeof(hdr), timeout_ms) < 0) { + return MP_OBJ_NEW_SMALL_INT(0); // Timeout waiting for packet + } + int msg_len = hdr.msg_len; + + // Check the message packet header format and read the message data + if (hdr.magic != ESPNOW_MAGIC + || msg_len > ESP_NOW_MAX_DATA_LEN + || ringbuf_get_bytes(self->recv_buffer, peer_buf, ESP_NOW_ETH_ALEN) < 0 + || ringbuf_get_bytes(self->recv_buffer, msg_buf, msg_len) < 0) { + mp_raise_ValueError(MP_ERROR_TEXT("ESPNow.recv(): buffer error")); + } + if (mp_obj_is_type(msg, &mp_type_bytearray)) { + // Set the length of the message bytearray. + msg->len = msg_len; + msg->free = msg_size - msg_len; + } + + return MP_OBJ_NEW_SMALL_INT(msg_len); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_recvinto_obj, 2, 3, espnow_recvinto); + +// Used by espnow_send() for sends() with sync==True. +// Wait till all pending sent packet responses have been received. +// ie. self->tx_responses == self->tx_packets. +// Return the number of responses where status != ESP_NOW_SEND_SUCCESS. +static void _wait_for_pending_responses(esp_espnow_obj_t *self) { + for (int i = 0; i < PENDING_RESPONSES_TIMEOUT_MS; i++) { + if (self->tx_responses >= self->tx_packets) { + return; + } + mp_hal_delay_ms(1); // Allow other tasks to run + } + // Note: the loop timeout is just a fallback - in normal operation + // we should never reach that timeout. +} + +// ESPNow.send(peer_addr, message, [sync (=true)]) +// ESPNow.send(message) +// Send a message to the peer's mac address. Optionally wait for a response. +// If sync == True, wait for response after sending. +// Returns: +// True if sync==False and message sent successfully. +// True if sync==True and message is received successfully by all recipients +// False if sync==True and message is not received by at least one recipient +// Raises: EAGAIN if the internal espnow buffers are full. +STATIC mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) { + esp_espnow_obj_t *self = _get_singleton_initialised(); + + bool sync = n_args <= 3 || args[3] == mp_const_none || mp_obj_is_true(args[3]); + // Get a pointer to the buffer of obj + mp_buffer_info_t message; + mp_get_buffer_raise(args[2], &message, MP_BUFFER_READ); + + // Bugfix: esp_now_send() generates a panic if message buffer points + // to an address in ROM (eg. a statically interned QSTR). + // Fix: if message is not in gc pool, copy to a temp buffer. + static char temp[ESP_NOW_MAX_DATA_LEN]; // Static to save code space + byte *p = (byte *)message.buf; + // if (p < MP_STATE_MEM(area.gc_pool_start) || MP_STATE_MEM(area.gc_pool_end) < p) { + if (MP_STATE_MEM(area.gc_pool_end) < p) { + // If buffer is not in GC pool copy from ROM to stack + memcpy(temp, message.buf, message.len); + message.buf = temp; + } + + if (sync) { + // If the last call was sync==False there may be outstanding responses. + // We need to wait for all pending responses if this call has sync=True. + _wait_for_pending_responses(self); + } + int saved_failures = self->tx_failures; + + check_esp_err( + esp_now_send(_get_bytes_len(args[1], ESP_NOW_ETH_ALEN), message.buf, message.len)); + self->tx_packets++; + if (sync) { + // Wait for message to be received by peer + _wait_for_pending_responses(self); + } + // Return False if sync and any peers did not respond. + return mp_obj_new_bool(!(sync && self->tx_failures != saved_failures)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 3, 4, espnow_send); + +// ### Peer Management Functions +// + +// Set the ESP-NOW Primary Master Key (pmk) (for encrypted communications). +// Raise OSError if not initialised. +// Raise ValueError if key is not a bytes-like object exactly 16 bytes long. +STATIC mp_obj_t espnow_set_pmk(mp_obj_t _, mp_obj_t key) { + check_esp_err(esp_now_set_kok(_get_bytes_len(key, ESP_NOW_KEY_LEN), ESP_NOW_KEY_LEN)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_set_pmk_obj, espnow_set_pmk); + +// ESPNow.add_peer(peer_mac, [lmk, [channel, [ifidx, [encrypt]]]]) +// Positional args set to None will be left at defaults. +// Raise OSError if not initialised. +// Raise ValueError if mac or LMK are not bytes-like objects or wrong length. +// Raise TypeError if invalid keyword args or too many positional args. +// Return None. +STATIC mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args) { + check_esp_err( + esp_now_add_peer( + _get_bytes_len(args[1], ESP_NOW_ETH_ALEN), + ESP_NOW_ROLE_COMBO, + (n_args > 3) ? mp_obj_get_int(args[3]) : 0, + (n_args > 2) ? _get_bytes_len(args[2], ESP_NOW_KEY_LEN) : NULL, + ESP_NOW_KEY_LEN)); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_add_peer_obj, 2, 4, espnow_add_peer); + +// ESPNow.del_peer(peer_mac): Unregister peer_mac. +// Raise OSError if not initialised. +// Raise ValueError if peer is not a bytes-like objects or wrong length. +// Return None. +STATIC mp_obj_t espnow_del_peer(mp_obj_t _, mp_obj_t peer) { + esp_now_del_peer(_get_bytes_len(peer, ESP_NOW_ETH_ALEN)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_del_peer_obj, espnow_del_peer); + +STATIC const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&espnow_active_obj) }, + { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&espnow_config_obj) }, + { MP_ROM_QSTR(MP_QSTR_recvinto), MP_ROM_PTR(&espnow_recvinto_obj) }, + { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&espnow_send_obj) }, + + // Peer management functions + { MP_ROM_QSTR(MP_QSTR_set_pmk), MP_ROM_PTR(&espnow_set_pmk_obj) }, + { MP_ROM_QSTR(MP_QSTR_add_peer), MP_ROM_PTR(&espnow_add_peer_obj) }, + { MP_ROM_QSTR(MP_QSTR_del_peer), MP_ROM_PTR(&espnow_del_peer_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(esp_espnow_locals_dict, esp_espnow_locals_dict_table); + +STATIC const mp_rom_map_elem_t espnow_globals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__espnow) }, + { MP_ROM_QSTR(MP_QSTR_ESPNowBase), MP_ROM_PTR(&esp_espnow_type) }, + { MP_ROM_QSTR(MP_QSTR_MAX_DATA_LEN), MP_ROM_INT(ESP_NOW_MAX_DATA_LEN)}, + { MP_ROM_QSTR(MP_QSTR_ADDR_LEN), MP_ROM_INT(ESP_NOW_ETH_ALEN)}, + { MP_ROM_QSTR(MP_QSTR_KEY_LEN), MP_ROM_INT(ESP_NOW_KEY_LEN)}, + { MP_ROM_QSTR(MP_QSTR_MAX_TOTAL_PEER_NUM), MP_ROM_INT(ESP_NOW_MAX_TOTAL_PEER_NUM)}, + { MP_ROM_QSTR(MP_QSTR_MAX_ENCRYPT_PEER_NUM), MP_ROM_INT(ESP_NOW_MAX_ENCRYPT_PEER_NUM)}, +}; +STATIC MP_DEFINE_CONST_DICT(espnow_globals_dict, espnow_globals_dict_table); + +// ### Dummy Buffer Protocol support +// ...so asyncio can poll.ipoll() on this device + +// Support ioctl(MP_STREAM_POLL, ) for asyncio +STATIC mp_uint_t espnow_stream_ioctl(mp_obj_t self_in, mp_uint_t request, + uintptr_t arg, int *errcode) { + if (request != MP_STREAM_POLL) { + *errcode = MP_EINVAL; + return MP_STREAM_ERROR; + } + esp_espnow_obj_t *self = _get_singleton(); + return (self->recv_buffer == NULL) ? 0 : // If not initialised + arg ^ ((ringbuf_avail(self->recv_buffer) == 0) ? MP_STREAM_POLL_RD : 0); +} + +STATIC const mp_stream_p_t espnow_stream_p = { + .ioctl = espnow_stream_ioctl, +}; + +MP_DEFINE_CONST_OBJ_TYPE( + esp_espnow_type, + MP_QSTR_ESPNowBase, + MP_TYPE_FLAG_NONE, + make_new, espnow_make_new, + protocol, &espnow_stream_p, + locals_dict, &esp_espnow_locals_dict + ); + +const mp_obj_module_t mp_module_espnow = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&espnow_globals_dict, +}; + +MP_REGISTER_MODULE(MP_QSTR__espnow, mp_module_espnow); +MP_REGISTER_ROOT_POINTER(void *espnow_buffer); +#endif diff --git a/ports/esp8266/modespnow.h b/ports/esp8266/modespnow.h new file mode 100644 index 0000000000..b42a615db8 --- /dev/null +++ b/ports/esp8266/modespnow.h @@ -0,0 +1,28 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Glenn Moloney @glenn20 + * + * 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. + */ + +// Called from main.c:mp_task() to reset the espnow software stack +mp_obj_t espnow_deinit(mp_obj_t _); diff --git a/ports/esp8266/modules/espnow.py b/ports/esp8266/modules/espnow.py new file mode 100644 index 0000000000..2f9c256c6b --- /dev/null +++ b/ports/esp8266/modules/espnow.py @@ -0,0 +1,37 @@ +# espnow module for MicroPython on ESP8266 +# MIT license; Copyright (c) 2022 Glenn Moloney @glenn20 + +from _espnow import * +from uselect import poll, POLLIN + + +class ESPNow(ESPNowBase): + # Static buffers for alloc free receipt of messages with ESPNow.irecv(). + _data = [bytearray(ADDR_LEN), bytearray(MAX_DATA_LEN)] + _none_tuple = (None, None) + + def __init__(self): + super().__init__() + self._poll = poll() # For any() method below... + self._poll.register(self, POLLIN) + + def irecv(self, timeout_ms=None): + n = self.recvinto(self._data, timeout_ms) + return self._data if n else self._none_tuple + + def recv(self, timeout_ms=None): + n = self.recvinto(self._data, timeout_ms) + return [bytes(x) for x in self._data] if n else self._none_tuple + + def __iter__(self): + return self + + def __next__(self): + return self.irecv() # Use alloc free irecv() method + + def any(self): # For the ESP8266 which does not have ESPNow.any() + try: + next(self._poll.ipoll(0)) + return True + except StopIteration: + return False diff --git a/tests/multi_espnow/10_simple_data.py b/tests/multi_espnow/10_simple_data.py new file mode 100644 index 0000000000..1d218fe981 --- /dev/null +++ b/tests/multi_espnow/10_simple_data.py @@ -0,0 +1,57 @@ +# Simple test of a ESPnow server and client transferring data. +# This test works with ESP32 or ESP8266 as server or client. + +try: + import network + import espnow +except ImportError: + print("SKIP") + raise SystemExit + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" + + +def init(sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e = espnow.ESPNow() + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + wlans[0].disconnect() # Force esp8266 STA interface to disconnect from AP + e.set_pmk(default_pmk) + return e + + +# Server +def instance0(): + e = init(True, False) + multitest.globals(PEERS=[network.WLAN(i).config("mac") for i in (0, 1)]) + multitest.next() + peer, msg1 = e.recv(timeout_ms) + if msg1 is None: + print("e.recv({timeout_ms}): Timeout waiting for message.") + e.active(False) + return + print(bytes(msg1)) + msg2 = b"server to client" + e.add_peer(peer) + e.send(peer, msg2) + print(bytes(msg2)) + e.active(False) + + +# Client +def instance1(): + e = init(True, False) + multitest.next() + peer = PEERS[0] + e.add_peer(peer) + msg1 = b"client to server" + e.send(peer, msg1) + print(bytes(msg1)) + peer2, msg2 = e.recv(timeout_ms) + print(bytes(msg2)) + e.active(False) diff --git a/tests/multi_espnow/10_simple_data.py.exp b/tests/multi_espnow/10_simple_data.py.exp new file mode 100644 index 0000000000..71a247f04f --- /dev/null +++ b/tests/multi_espnow/10_simple_data.py.exp @@ -0,0 +1,6 @@ +--- instance0 --- +b'client to server' +b'server to client' +--- instance1 --- +b'client to server' +b'server to client' diff --git a/tests/multi_espnow/20_send_echo.py b/tests/multi_espnow/20_send_echo.py new file mode 100644 index 0000000000..4a1d1624d8 --- /dev/null +++ b/tests/multi_espnow/20_send_echo.py @@ -0,0 +1,93 @@ +# Test of a ESPnow echo server and client transferring data. +# This test works with ESP32 or ESP8266 as server or client. + +try: + import network + import random + import espnow +except ImportError: + print("SKIP") + raise SystemExit + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" +sync = True + + +def echo_server(e): + peers = [] + while True: + peer, msg = e.recv(timeout_ms) + if peer is None: + return + if peer not in peers: + peers.append(peer) + e.add_peer(peer) + + # Echo the MAC and message back to the sender + if not e.send(peer, msg, sync): + print("ERROR: send() failed to", peer) + return + + if msg == b"!done": + return + + +def echo_test(e, peer, msg, sync): + print("TEST: send/recv(msglen=", len(msg), ",sync=", sync, "): ", end="", sep="") + try: + if not e.send(peer, msg, sync): + print("ERROR: Send failed.") + return + except OSError as exc: + # Don't print exc as it is differs for esp32 and esp8266 + print("ERROR: OSError:") + return + + p2, msg2 = e.recv(timeout_ms) + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + +def echo_client(e, peer, msglens): + for sync in [True, False]: + for msglen in msglens: + msg = bytearray(msglen) + if msglen > 0: + msg[0] = b"_"[0] # Random message must not start with '!' + for i in range(1, msglen): + msg[i] = random.getrandbits(8) + echo_test(e, peer, msg, sync) + + +def init(sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e = espnow.ESPNow() + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + wlans[0].disconnect() # Force esp8266 STA interface to disconnect from AP + return e + + +# Server +def instance0(): + e = init(True, False) + multitest.globals(PEERS=[network.WLAN(i).config("mac") for i in (0, 1)]) + multitest.next() + print("Server Start") + echo_server(e) + print("Server Done") + e.active(False) + + +# Client +def instance1(): + e = init(True, False) + multitest.next() + peer = PEERS[0] + e.add_peer(peer) + echo_client(e, peer, [1, 2, 8, 100, 249, 250, 251, 0]) + echo_test(e, peer, b"!done", True) + e.active(False) diff --git a/tests/multi_espnow/20_send_echo.py.exp b/tests/multi_espnow/20_send_echo.py.exp new file mode 100644 index 0000000000..e43900bcf6 --- /dev/null +++ b/tests/multi_espnow/20_send_echo.py.exp @@ -0,0 +1,21 @@ +--- instance0 --- +Server Start +Server Done +--- instance1 --- +TEST: send/recv(msglen=1,sync=True): OK +TEST: send/recv(msglen=2,sync=True): OK +TEST: send/recv(msglen=8,sync=True): OK +TEST: send/recv(msglen=100,sync=True): OK +TEST: send/recv(msglen=249,sync=True): OK +TEST: send/recv(msglen=250,sync=True): OK +TEST: send/recv(msglen=251,sync=True): ERROR: OSError: +TEST: send/recv(msglen=0,sync=True): ERROR: OSError: +TEST: send/recv(msglen=1,sync=False): OK +TEST: send/recv(msglen=2,sync=False): OK +TEST: send/recv(msglen=8,sync=False): OK +TEST: send/recv(msglen=100,sync=False): OK +TEST: send/recv(msglen=249,sync=False): OK +TEST: send/recv(msglen=250,sync=False): OK +TEST: send/recv(msglen=251,sync=False): ERROR: OSError: +TEST: send/recv(msglen=0,sync=False): ERROR: OSError: +TEST: send/recv(msglen=5,sync=True): OK diff --git a/tests/multi_espnow/30_lmk_echo.py b/tests/multi_espnow/30_lmk_echo.py new file mode 100644 index 0000000000..ac89080492 --- /dev/null +++ b/tests/multi_espnow/30_lmk_echo.py @@ -0,0 +1,130 @@ +# Test of a ESPnow echo server and client transferring encrypted data. +# This test works with ESP32 or ESP8266 as server or client. + +# First instance (echo server): +# Set the shared PMK +# Set the PEERS global to our mac addresses +# Run the echo server +# First exchange an unencrypted message from the client (so we +# can get its MAC address) and echo the message back (unenecrypted). +# Then set the peer LMK so all further communications are encrypted. + +# Second instance (echo client): +# Set the shared PMK +# Send an unencrypted message to the server and wait for echo response. +# Set the LMK for the peer communications so all further comms are encrypted. +# Send random messages and compare with response from server. + +try: + import network + import random + import time + import espnow +except ImportError: + print("SKIP") + raise SystemExit + + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" +default_lmk = b"0123456789abcdef" +sync = True + + +def echo_server(e): + peers = [] + while True: + # Wait for messages from the client + peer, msg = e.recv(timeout_ms) + if peer is None: + return + if peer not in peers: + # If this is first message, add the peer unencrypted + e.add_peer(peer) + + # Echo the message back to the sender + if not e.send(peer, msg, sync): + print("ERROR: send() failed to", peer) + return + + if peer not in peers: + # If this is first message, add the peer encrypted + peers.append(peer) + e.del_peer(peer) + e.add_peer(peer, default_lmk) + + if msg == b"!done": + return + + +# Send a message from the client and compare with response from server. +def echo_test(e, peer, msg, sync): + print("TEST: send/recv(msglen=", len(msg), ",sync=", sync, "): ", end="", sep="") + try: + if not e.send(peer, msg, sync): + print("ERROR: Send failed.") + return + except OSError as exc: + # Don't print exc as it is differs for esp32 and esp8266 + print("ERROR: OSError:") + return + + p2, msg2 = e.recv(timeout_ms) + if p2 is None: + print("ERROR: No response from server.") + raise SystemExit + + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + +# Send some random messages to server and check the responses +def echo_client(e, peer, msglens): + for sync in [True, False]: + for msglen in msglens: + msg = bytearray(msglen) + if msglen > 0: + msg[0] = b"_"[0] # Random message must not start with '!' + for i in range(1, msglen): + msg[i] = random.getrandbits(8) + echo_test(e, peer, msg, sync) + + +# Initialise the wifi and espnow hardware and software +def init(sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e = espnow.ESPNow() + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + wlans[0].disconnect() # Force esp8266 STA interface to disconnect from AP + return e + + +# Server +def instance0(): + e = init(True, False) + macs = [network.WLAN(i).config("mac") for i in (0, 1)] + print("Server Start") + multitest.globals(PEERS=macs) + multitest.next() + echo_server(e) + print("Server Done") + e.active(False) + + +# Client +def instance1(): + e = init(True, False) + multitest.next() + peer = PEERS[0] + e.add_peer(peer) + echo_test(e, peer, b"start", True) + # Wait long enough for the server to set the lmk + time.sleep(0.1) + e.del_peer(peer) + e.add_peer(peer, default_lmk) + echo_client(e, peer, [250]) + echo_test(e, peer, b"!done", True) + e.active(False) diff --git a/tests/multi_espnow/30_lmk_echo.py.exp b/tests/multi_espnow/30_lmk_echo.py.exp new file mode 100644 index 0000000000..cd05fe6c7f --- /dev/null +++ b/tests/multi_espnow/30_lmk_echo.py.exp @@ -0,0 +1,8 @@ +--- instance0 --- +Server Start +Server Done +--- instance1 --- +TEST: send/recv(msglen=5,sync=True): OK +TEST: send/recv(msglen=250,sync=True): OK +TEST: send/recv(msglen=250,sync=False): OK +TEST: send/recv(msglen=5,sync=True): OK diff --git a/tests/multi_espnow/40_recv_test.py b/tests/multi_espnow/40_recv_test.py new file mode 100644 index 0000000000..46f4f78df4 --- /dev/null +++ b/tests/multi_espnow/40_recv_test.py @@ -0,0 +1,113 @@ +# Test of a ESPnow echo server and client transferring data. +# This test works with ESP32 or ESP8266 as server or client. +# Explicitly tests the irecv(), rev() and recvinto() methods. + +try: + import network + import random + import espnow +except ImportError: + print("SKIP") + raise SystemExit + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" +sync = True + + +def echo_server(e): + peers = [] + while True: + peer, msg = e.irecv(timeout_ms) + if peer is None: + return + if peer not in peers: + peers.append(peer) + e.add_peer(peer) + + # Echo the MAC and message back to the sender + if not e.send(peer, msg, sync): + print("ERROR: send() failed to", peer) + return + + if msg == b"!done": + return + + +def client_send(e, peer, msg, sync): + print("TEST: send/recv(msglen=", len(msg), ",sync=", sync, "): ", end="", sep="") + try: + if not e.send(peer, msg, sync): + print("ERROR: Send failed.") + return + except OSError as exc: + # Don't print exc as it is differs for esp32 and esp8266 + print("ERROR: OSError:") + return + + +def init(sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e = espnow.ESPNow() + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + wlans[0].disconnect() # Force esp8266 STA interface to disconnect from AP + return e + + +# Server +def instance0(): + e = init(True, False) + multitest.globals(PEERS=[network.WLAN(i).config("mac") for i in (0, 1)]) + multitest.next() + print("Server Start") + echo_server(e) + print("Server Done") + e.active(False) + + +# Client +def instance1(): + # Instance 1 (the client) + e = init(True, False) + e.config(timeout_ms=timeout_ms) + multitest.next() + peer = PEERS[0] + e.add_peer(peer) + + print("RECVINTO() test...") + msg = bytes([random.getrandbits(8) for _ in range(12)]) + client_send(e, peer, msg, True) + data = [bytearray(espnow.ADDR_LEN), bytearray(espnow.MAX_DATA_LEN)] + n = e.recvinto(data) + print("OK" if data[1] == msg else "ERROR: Received != Sent") + + print("IRECV() test...") + msg = bytes([random.getrandbits(8) for _ in range(12)]) + client_send(e, peer, msg, True) + p2, msg2 = e.irecv() + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + print("RECV() test...") + msg = bytes([random.getrandbits(8) for _ in range(12)]) + client_send(e, peer, msg, True) + p2, msg2 = e.recv() + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + print("ITERATOR() test...") + msg = bytes([random.getrandbits(8) for _ in range(12)]) + client_send(e, peer, msg, True) + p2, msg2 = next(e) + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + # Tell the server to stop + print("DONE") + msg = b"!done" + client_send(e, peer, msg, True) + p2, msg2 = e.irecv() + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + e.active(False) diff --git a/tests/multi_espnow/40_recv_test.py.exp b/tests/multi_espnow/40_recv_test.py.exp new file mode 100644 index 0000000000..61f2206254 --- /dev/null +++ b/tests/multi_espnow/40_recv_test.py.exp @@ -0,0 +1,14 @@ +--- instance0 --- +Server Start +Server Done +--- instance1 --- +RECVINTO() test... +TEST: send/recv(msglen=12,sync=True): OK +IRECV() test... +TEST: send/recv(msglen=12,sync=True): OK +RECV() test... +TEST: send/recv(msglen=12,sync=True): OK +ITERATOR() test... +TEST: send/recv(msglen=12,sync=True): OK +DONE +TEST: send/recv(msglen=5,sync=True): OK diff --git a/tests/multi_espnow/50_esp32_rssi_test.py b/tests/multi_espnow/50_esp32_rssi_test.py new file mode 100644 index 0000000000..6a47b540d3 --- /dev/null +++ b/tests/multi_espnow/50_esp32_rssi_test.py @@ -0,0 +1,114 @@ +# Test the ESP32 RSSI extensions on instance1. +# Will SKIP test if instance1 is not an ESP32. +# Instance0 may be an ESP32 or ESP8266. + +try: + import time + import network + import random + import espnow +except ImportError: + print("SKIP") + raise SystemExit + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" +sync = True + + +def echo_server(e): + peers = [] + while True: + peer, msg = e.irecv(timeout_ms) + if peer is None: + return + if peer not in peers: + peers.append(peer) + e.add_peer(peer) + + # Echo the MAC and message back to the sender + if not e.send(peer, msg, sync): + print("ERROR: send() failed to", peer) + return + + if msg == b"!done": + return + + +def client_send(e, peer, msg, sync): + print("TEST: send/recv(msglen=", len(msg), ",sync=", sync, "): ", end="", sep="") + try: + if not e.send(peer, msg, sync): + print("ERROR: Send failed.") + return + except OSError as exc: + # Don't print exc as it is differs for esp32 and esp8266 + print("ERROR: OSError:") + return + + +def init(sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e = espnow.ESPNow() + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + return e + + +# Server +def instance0(): + e = init(True, False) + multitest.globals(PEERS=[network.WLAN(i).config("mac") for i in (0, 1)]) + multitest.next() + print("Server Start") + echo_server(e) + print("Server Done") + e.active(False) + + +# Client +def instance1(): + # Instance 1 (the client) + e = init(True, False) + if not hasattr(e, "peers_table"): + e.active(False) + print("SKIP") + raise SystemExit + + e.config(timeout_ms=timeout_ms) + multitest.next() + peer = PEERS[0] + e.add_peer(peer) + + # assert len(e.peers) == 1 + print("IRECV() test...") + msg = bytes([random.getrandbits(8) for _ in range(12)]) + client_send(e, peer, msg, True) + p2, msg2 = e.irecv() + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + print("RSSI test...") + if len(e.peers_table) != 1: + print("ERROR: len(ESPNow.peers_table()) != 1. ESPNow.peers_table()=", peers) + elif list(e.peers_table.keys())[0] != peer: + print("ERROR: ESPNow.peers_table().keys[0] != peer. ESPNow.peers_table()=", peers) + else: + rssi, time_ms = e.peers_table[peer] + if not -127 < rssi < 0: + print("ERROR: Invalid rssi value:", rssi) + elif time.ticks_diff(time.ticks_ms(), time_ms) > 5000: + print("ERROR: Unexpected time_ms value:", time_ms) + else: + print("OK") + + # Tell the server to stop + print("DONE") + msg = b"!done" + client_send(e, peer, msg, True) + p2, msg2 = e.irecv() + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + e.active(False) diff --git a/tests/multi_espnow/50_esp32_rssi_test.py.exp b/tests/multi_espnow/50_esp32_rssi_test.py.exp new file mode 100644 index 0000000000..22fc4f0285 --- /dev/null +++ b/tests/multi_espnow/50_esp32_rssi_test.py.exp @@ -0,0 +1,10 @@ +--- instance0 --- +Server Start +Server Done +--- instance1 --- +IRECV() test... +TEST: send/recv(msglen=12,sync=True): OK +RSSI test... +OK +DONE +TEST: send/recv(msglen=5,sync=True): OK diff --git a/tests/multi_espnow/60_irq_test.py b/tests/multi_espnow/60_irq_test.py new file mode 100644 index 0000000000..37fc57ce4a --- /dev/null +++ b/tests/multi_espnow/60_irq_test.py @@ -0,0 +1,117 @@ +# Test of a ESPnow echo server and client transferring data. +# Test the ESP32 extemnsions. Assumes instance1 is an ESP32. +# Instance0 may be an ESP32 or ESP8266 + +try: + import network + import random + import time + import espnow +except ImportError: + print("SKIP") + raise SystemExit + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" +sync = True + + +def echo_server(e): + peers = [] + while True: + peer, msg = e.irecv(timeout_ms) + if peer is None: + return + if peer not in peers: + peers.append(peer) + e.add_peer(peer) + + # Echo the MAC and message back to the sender + if not e.send(peer, msg, sync): + print("ERROR: send() failed to", peer) + return + + if msg == b"!done": + return + + +def client_send(e, peer, msg, sync): + print("TEST: send/recv(msglen=", len(msg), ",sync=", sync, "): ", end="", sep="") + try: + if not e.send(peer, msg, sync): + print("ERROR: Send failed.") + return + except OSError as exc: + # Don't print exc as it is differs for esp32 and esp8266 + print("ERROR: OSError:") + return + + +def init(sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e = espnow.ESPNow() + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + wlans[0].disconnect() # Force esp8266 STA interface to disconnect from AP + return e + + +# Server +def instance0(): + e = init(True, False) + multitest.globals(PEERS=[network.WLAN(i).config("mac") for i in (0, 1)]) + multitest.next() + print("Server Start") + echo_server(e) + print("Server Done") + e.active(False) + + +done = False + + +# Client +def instance1(): + # Instance 1 (the client) + e = init(True, False) + try: + e.irq(None) + except AttributeError: + print("SKIP") + raise SystemExit + + e.config(timeout_ms=timeout_ms) + multitest.next() + peer = PEERS[0] + e.add_peer(peer) + + def on_recv_cb(e): + global done + p2, msg2 = e.irecv(0) + print("OK" if msg2 == msg else "ERROR: Received != Sent") + done = True + + global done + print("IRQ() test...") + e.irq(on_recv_cb) + done = False + msg = bytes([random.getrandbits(8) for _ in range(12)]) + client_send(e, peer, msg, True) + start = time.ticks_ms() + while not done: + if time.ticks_diff(time.ticks_ms(), start) > timeout_ms: + print("Timeout waiting for response.") + raise SystemExit + e.irq(None) + + # Tell the server to stop + print("DONE") + msg = b"!done" + client_send(e, peer, msg, True) + p2, msg2 = e.irecv() + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + e.active(False) diff --git a/tests/multi_espnow/60_irq_test.py.exp b/tests/multi_espnow/60_irq_test.py.exp new file mode 100644 index 0000000000..c2be2dccfd --- /dev/null +++ b/tests/multi_espnow/60_irq_test.py.exp @@ -0,0 +1,8 @@ +--- instance0 --- +Server Start +Server Done +--- instance1 --- +IRQ() test... +TEST: send/recv(msglen=12,sync=True): OK +DONE +TEST: send/recv(msglen=5,sync=True): OK diff --git a/tests/multi_espnow/80_uasyncio_client.py b/tests/multi_espnow/80_uasyncio_client.py new file mode 100644 index 0000000000..fa2918cc03 --- /dev/null +++ b/tests/multi_espnow/80_uasyncio_client.py @@ -0,0 +1,110 @@ +# Test of a ESPnow echo server and asyncio client transferring data. +# Test will SKIP if instance1 (asyncio client) does not support asyncio. +# - eg. ESP8266 with 1MB flash. +# Instance0 is not required to support asyncio. + +try: + import network + import random + import espnow +except ImportError: + print("SKIP") + raise SystemExit + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" +sync = True + + +def echo_server(e): + peers = [] + while True: + peer, msg = e.irecv(timeout_ms) + if peer is None: + return + if peer not in peers: + peers.append(peer) + e.add_peer(peer) + + # Echo the MAC and message back to the sender + if not e.send(peer, msg, sync): + print("ERROR: send() failed to", peer) + return + + if msg == b"!done": + return + + +def client_send(e, peer, msg, sync): + print("TEST: send/recv(msglen=", len(msg), ",sync=", sync, "): ", end="", sep="") + try: + if not e.send(peer, msg, sync): + print("ERROR: Send failed.") + return + except OSError as exc: + # Don't print exc as it is differs for esp32 and esp8266 + print("ERROR: OSError:") + return + print("OK") + + +def init(e, sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + wlans[0].disconnect() # Force esp8266 STA interface to disconnect from AP + return e + + +async def client(e): + init(e, True, False) + e.config(timeout_ms=timeout_ms) + peer = PEERS[0] + e.add_peer(peer) + multitest.next() + + print("airecv() test...") + msgs = [] + for i in range(5): + # Send messages to the peer who will echo it back + msgs.append(bytes([random.getrandbits(8) for _ in range(12)])) + client_send(e, peer, msgs[i], True) + + for i in range(5): + mac, reply = await e.airecv() + print("OK" if reply == msgs[i] else "ERROR: Received != Sent") + + # Tell the server to stop + print("DONE") + msg = b"!done" + client_send(e, peer, msg, True) + mac, reply = await e.airecv() + print("OK" if reply == msg else "ERROR: Received != Sent") + + e.active(False) + + +# Server +def instance0(): + e = espnow.ESPNow() + init(e, True, False) + multitest.globals(PEERS=[network.WLAN(i).config("mac") for i in (0, 1)]) + multitest.next() + print("Server Start") + echo_server(e) + print("Server Done") + e.active(False) + + +# Client +def instance1(): + try: + import uasyncio as asyncio + from aioespnow import AIOESPNow + except ImportError: + print("SKIP") + raise SystemExit + asyncio.run(client(AIOESPNow())) diff --git a/tests/multi_espnow/80_uasyncio_client.py.exp b/tests/multi_espnow/80_uasyncio_client.py.exp new file mode 100644 index 0000000000..05fdf8acaf --- /dev/null +++ b/tests/multi_espnow/80_uasyncio_client.py.exp @@ -0,0 +1,18 @@ +--- instance0 --- +Server Start +Server Done +--- instance1 --- +airecv() test... +TEST: send/recv(msglen=12,sync=True): OK +TEST: send/recv(msglen=12,sync=True): OK +TEST: send/recv(msglen=12,sync=True): OK +TEST: send/recv(msglen=12,sync=True): OK +TEST: send/recv(msglen=12,sync=True): OK +OK +OK +OK +OK +OK +DONE +TEST: send/recv(msglen=5,sync=True): OK +OK diff --git a/tests/multi_espnow/81_uasyncio_server.py b/tests/multi_espnow/81_uasyncio_server.py new file mode 100644 index 0000000000..ee098b7f3b --- /dev/null +++ b/tests/multi_espnow/81_uasyncio_server.py @@ -0,0 +1,96 @@ +# Test of a ESPnow asyncio echo server and client transferring data. +# Test will SKIP if instance0 (asyncio echo server) does not support asyncio. +# - eg. ESP8266 with 1MB flash. +# Instance1 is not required to support asyncio. + +try: + import network + import random + import espnow +except ImportError: + print("SKIP") + raise SystemExit + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" +sync = True + + +def client_send(e, peer, msg, sync): + print("TEST: send/recv(msglen=", len(msg), ",sync=", sync, "): ", end="", sep="") + try: + if not e.send(peer, msg, sync): + print("ERROR: Send failed.") + return + except OSError as exc: + # Don't print exc as it is differs for esp32 and esp8266 + print("ERROR: OSError:") + return + + +def init(e, sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + wlans[0].disconnect() # Force esp8266 STA interface to disconnect from AP + return e + + +async def echo_server(e): + peers = [] + async for peer, msg in e: + if peer not in peers: + peers.append(peer) + e.add_peer(peer) + + # Echo the message back to the sender + if not await e.asend(peer, msg, sync): + print("ERROR: asend() failed to", peer) + return + + if msg == b"!done": + return + + +# Server +def instance0(): + try: + import uasyncio as asyncio + from aioespnow import AIOESPNow + except ImportError: + print("SKIP") + raise SystemExit + e = AIOESPNow() + init(e, True, False) + multitest.globals(PEERS=[network.WLAN(i).config("mac") for i in (0, 1)]) + multitest.next() + print("Server Start") + asyncio.run(echo_server(e)) + print("Server Done") + e.active(False) + + +def instance1(): + e = espnow.ESPNow() + init(e, True, False) + peer = PEERS[0] + e.add_peer(peer) + multitest.next() + + for i in range(5): + msg = bytes([random.getrandbits(8) for _ in range(12)]) + client_send(e, peer, msg, True) + p2, msg2 = e.irecv(timeout_ms) + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + # Tell the server to stop + print("DONE") + msg = b"!done" + client_send(e, peer, msg, True) + p2, msg2 = e.irecv(timeout_ms) + print("OK" if msg2 == msg else "ERROR: Received != Sent") + + e.active(False) diff --git a/tests/multi_espnow/81_uasyncio_server.py.exp b/tests/multi_espnow/81_uasyncio_server.py.exp new file mode 100644 index 0000000000..abe34fc421 --- /dev/null +++ b/tests/multi_espnow/81_uasyncio_server.py.exp @@ -0,0 +1,11 @@ +--- instance0 --- +Server Start +Server Done +--- instance1 --- +TEST: send/recv(msglen=12,sync=True): OK +TEST: send/recv(msglen=12,sync=True): OK +TEST: send/recv(msglen=12,sync=True): OK +TEST: send/recv(msglen=12,sync=True): OK +TEST: send/recv(msglen=12,sync=True): OK +DONE +TEST: send/recv(msglen=5,sync=True): OK diff --git a/tests/multi_espnow/90_memory_test.py b/tests/multi_espnow/90_memory_test.py new file mode 100644 index 0000000000..5e80eb0fdf --- /dev/null +++ b/tests/multi_espnow/90_memory_test.py @@ -0,0 +1,108 @@ +# Test of a ESPnow echo server and client transferring data. +# This test works with ESP32 or ESP8266 as server or client. + +try: + import network + import random + import espnow +except ImportError: + print("SKIP") + raise SystemExit + +# Set read timeout to 5 seconds +timeout_ms = 5000 +default_pmk = b"MicroPyth0nRules" +sync = True + + +def echo_server(e): + peers = [] + i = 0 + while True: + peer, msg = e.irecv(timeout_ms) + i += 1 + if i % 10 == 0: + print("OK:", i) + if peer is None: + return + if peer not in peers: + peers.append(peer) + e.add_peer(peer) + + # Echo the MAC and message back to the sender + if not e.send(peer, msg, sync): + print("ERROR: send() failed to", peer) + return + + if msg == b"!done": + return + + +def echo_test(e, peer, msg, sync): + try: + if not e.send(peer, msg, sync): + print("ERROR: Send failed.") + return + except OSError as exc: + # Don't print exc as it is differs for esp32 and esp8266 + print("ERROR: OSError:") + return + + p2, msg2 = e.irecv(timeout_ms) + if msg2 != msg: + print("ERROR: Received != Sent") + + +def echo_client(e, peer, msglens): + for sync in [True]: + for msglen in msglens: + msg = bytearray(msglen) + if msglen > 0: + msg[0] = b"_"[0] # Random message must not start with '!' + for i in range(1, msglen): + msg[i] = random.getrandbits(8) + echo_test(e, peer, msg, sync) + + +def init(sta_active=True, ap_active=False): + wlans = [network.WLAN(i) for i in [network.STA_IF, network.AP_IF]] + e = espnow.ESPNow() + e.active(True) + e.set_pmk(default_pmk) + wlans[0].active(sta_active) + wlans[1].active(ap_active) + wlans[0].disconnect() # Force esp8266 STA interface to disconnect from AP + return e + + +# Server +def instance0(): + e = init(True, False) + multitest.globals(PEERS=[network.WLAN(i).config("mac") for i in (0, 1)]) + multitest.next() + print("Server Start") + echo_server(e) + print("Server Done") + e.active(False) + + +# Client +def instance1(): + e = init(True, False) + multitest.next() + peer = PEERS[0] + e.add_peer(peer) + echo_test(e, peer, b"ping", True) + gc.collect() + mem_start = gc.mem_alloc() + for i in range(10): + echo_client(e, peer, [250] * 10) + print("OK:", (i + 1) * 10) + echo_test(e, peer, b"!done", True) + gc.collect() + mem_end = gc.mem_alloc() + if mem_end - mem_start < 1024: + print("OK: Less than 1024 bytes consumed") + else: + print("Error: Memory consumed is", mem_end - mem_start) + e.active(False) diff --git a/tests/multi_espnow/90_memory_test.py.exp b/tests/multi_espnow/90_memory_test.py.exp new file mode 100644 index 0000000000..1ea8c29599 --- /dev/null +++ b/tests/multi_espnow/90_memory_test.py.exp @@ -0,0 +1,25 @@ +--- instance0 --- +Server Start +OK: 10 +OK: 20 +OK: 30 +OK: 40 +OK: 50 +OK: 60 +OK: 70 +OK: 80 +OK: 90 +OK: 100 +Server Done +--- instance1 --- +OK: 10 +OK: 20 +OK: 30 +OK: 40 +OK: 50 +OK: 60 +OK: 70 +OK: 80 +OK: 90 +OK: 100 +OK: Less than 1024 bytes consumed From cda292935dca9df25019168d91b211ad68e2b054 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 10 Mar 2023 06:16:52 +0100 Subject: [PATCH 032/565] tools/mpremote: Remove unused import of serial. --- tools/mpremote/mpremote/pyboardextended.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mpremote/mpremote/pyboardextended.py b/tools/mpremote/mpremote/pyboardextended.py index dba8172b84..6bad94a561 100644 --- a/tools/mpremote/mpremote/pyboardextended.py +++ b/tools/mpremote/mpremote/pyboardextended.py @@ -1,4 +1,4 @@ -import io, os, re, serial, struct, time +import io, os, re, struct, time from errno import EPERM from .console import VT_ENABLED From 8f8bd981641e0988b9ed3276c8f2435645269b3f Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 10 Mar 2023 06:28:44 +0100 Subject: [PATCH 033/565] all: Fix strings with backslash by using raw string literals. --- docs/conf.py | 2 +- ports/cc3200/tools/uniflash.py | 2 +- tools/insert-usb-ids.py | 2 +- tools/uf2conv.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 933e7b34b2..a966b3a025 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -233,7 +233,7 @@ latex_elements = { # Additional stuff for the LaTeX preamble. #'preamble': '', # Include 3 levels of headers in PDF ToC -'preamble': '\setcounter{tocdepth}{2}', +'preamble': r'\setcounter{tocdepth}{2}', } # Grouping the document tree into LaTeX files. List of tuples diff --git a/ports/cc3200/tools/uniflash.py b/ports/cc3200/tools/uniflash.py index 0ce9d0703a..83445a12d3 100644 --- a/ports/cc3200/tools/uniflash.py +++ b/ports/cc3200/tools/uniflash.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -""" +r""" Flash the WiPy (format, update service pack and program). Example: diff --git a/tools/insert-usb-ids.py b/tools/insert-usb-ids.py index 9b53f3f68a..177a68c4a4 100644 --- a/tools/insert-usb-ids.py +++ b/tools/insert-usb-ids.py @@ -16,7 +16,7 @@ def parse_usb_ids(filename): rv = dict() for line in open(filename).readlines(): line = line.rstrip("\r\n") - match = re.match("^#define\s+(\w+)\s+\(0x([0-9A-Fa-f]+)\)$", line) + match = re.match(r"^#define\s+(\w+)\s+\(0x([0-9A-Fa-f]+)\)$", line) if match and match.group(1).startswith(config_prefix): key = match.group(1).replace(config_prefix, "USB_") val = match.group(2) diff --git a/tools/uf2conv.py b/tools/uf2conv.py index ef3e481449..b66e52876b 100644 --- a/tools/uf2conv.py +++ b/tools/uf2conv.py @@ -271,7 +271,7 @@ def get_drives(): ] ) for line in to_str(r).split("\n"): - words = re.split("\s+", line) + words = re.split(r"\s+", line) if len(words) >= 3 and words[1] == "2" and words[2] == "FAT": drives.append(words[0]) else: From 79e57473b20707ca948920fbce473d64dbd8ce25 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 10 Mar 2023 05:59:28 +0100 Subject: [PATCH 034/565] all: Fix various Python coding inconsistencies found by ruff. This fixes: - type-comparison (E721): do not compare types, use isinstance(). - string-dot-format-missing-arguments (F524): .format call is missing argument(s) for placeholder(s): {message}. - f-string-missing-placeholders (F541). - is-literal (F632): Use != to compare constant literals. The last one is fixed by just comparing for truthfulness of `state`. --- extmod/uasyncio/funcs.py | 2 +- ports/cc3200/boards/make-pins.py | 2 +- ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py | 2 +- shared/memzip/make-memzip.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extmod/uasyncio/funcs.py b/extmod/uasyncio/funcs.py index 23a585aa94..dc52ad3958 100644 --- a/extmod/uasyncio/funcs.py +++ b/extmod/uasyncio/funcs.py @@ -123,7 +123,7 @@ def gather(*aws, return_exceptions=False): # Either this gather was cancelled, or one of the sub-tasks raised an exception with # return_exceptions==False, so reraise the exception here. - if state is not 0: + if state: raise state # Return the list of return values of each sub-task. diff --git a/ports/cc3200/boards/make-pins.py b/ports/cc3200/boards/make-pins.py index 0cf0d56560..6608be438a 100644 --- a/ports/cc3200/boards/make-pins.py +++ b/ports/cc3200/boards/make-pins.py @@ -124,7 +124,7 @@ class Pins: continue if not row[pin_col].isdigit(): raise ValueError( - "Invalid pin number {:s} in row {:s}".format(row[pin_col]), row + "Invalid pin number {:s} in row {:s}".format(row[pin_col], row) ) # Pin numbers must start from 0 when used with the TI API pin_num = int(row[pin_col]) - 1 diff --git a/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py b/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py index 7cc81b4c68..fe34ce1228 100644 --- a/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py +++ b/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py @@ -704,7 +704,7 @@ def check_for_updates(force=False): if fus_uptodate and ws_uptodate and not force: log(f"Already up to date: fus: {current_version_fus}, ws: {current_version_ws}") else: - log(f"Starting firmware update") + log("Starting firmware update") log(f" - fus: {current_version_fus} -> {vers_fus}") log(f" - ws: {current_version_ws} -> {vers_ws}") _write_state(_STATE_WAITING_FOR_FUS) diff --git a/shared/memzip/make-memzip.py b/shared/memzip/make-memzip.py index 9730f5e008..cc0df82077 100755 --- a/shared/memzip/make-memzip.py +++ b/shared/memzip/make-memzip.py @@ -36,7 +36,7 @@ def create_c_from_file(c_filename, zip_filename): break print(' ', end='', file=c_file) for byte in buf: - if type(byte) is types.StringType: + if isinstance(byte, types.StringType): print(' 0x{:02x},'.format(ord(byte)), end='', file=c_file) else: print(' 0x{:02x},'.format(byte), end='', file=c_file) From 2a1db770ce8d024b31bd1680e501e8b2a65f6570 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 10 Mar 2023 07:33:32 +0100 Subject: [PATCH 035/565] all: Fix cases of Python variable assigned but never used. This fixes ruff rule F841. --- examples/network/http_server_simplistic.py | 1 - ports/cc3200/tools/update-wipy.py | 4 ++-- ports/mimxrt/boards/make-pins.py | 1 - ports/nrf/examples/seeed_tft.py | 2 -- ports/rp2/boards/make-pins.py | 4 ++-- ports/stm32/make-stmconst.py | 1 - ports/stm32/mboot/mboot.py | 2 +- tools/mpremote/mpremote/console.py | 2 +- tools/mpremote/mpremote/pyboardextended.py | 2 +- tools/mpy-tool.py | 7 +++---- tools/mpy_ld.py | 1 - 11 files changed, 10 insertions(+), 17 deletions(-) diff --git a/examples/network/http_server_simplistic.py b/examples/network/http_server_simplistic.py index 71949419e6..a9831127ff 100644 --- a/examples/network/http_server_simplistic.py +++ b/examples/network/http_server_simplistic.py @@ -28,7 +28,6 @@ def main(): while True: res = s.accept() client_s = res[0] - client_addr = res[1] req = client_s.recv(4096) print("Request:") print(req) diff --git a/ports/cc3200/tools/update-wipy.py b/ports/cc3200/tools/update-wipy.py index 8008b38605..7f5527a52b 100644 --- a/ports/cc3200/tools/update-wipy.py +++ b/ports/cc3200/tools/update-wipy.py @@ -109,7 +109,7 @@ def reset_board(args): finally: try: tn.close() - except Exception as e: + except Exception: pass return success @@ -167,7 +167,7 @@ def verify_update(args): finally: try: tn.close() - except Exception as e: + except Exception: pass return success diff --git a/ports/mimxrt/boards/make-pins.py b/ports/mimxrt/boards/make-pins.py index 9d11feb13a..429d648696 100644 --- a/ports/mimxrt/boards/make-pins.py +++ b/ports/mimxrt/boards/make-pins.py @@ -226,7 +226,6 @@ class Pins(object): # Extract indexes from header row pad_col = header.index("Pad") adc_col = header.index("ADC") - acmp_col = header.index("ACMP") # for idx, row in enumerate(rows): pad = row[pad_col] diff --git a/ports/nrf/examples/seeed_tft.py b/ports/nrf/examples/seeed_tft.py index bf246bed4f..fc0617f20b 100644 --- a/ports/nrf/examples/seeed_tft.py +++ b/ports/nrf/examples/seeed_tft.py @@ -216,8 +216,6 @@ class ILI9341: self.write_cmd(0x2C) - num_of_pixels = self.height * self.width - for row in range(0, self.pages): for pixel_pos in range(0, 8): for col in range(0, self.width): diff --git a/ports/rp2/boards/make-pins.py b/ports/rp2/boards/make-pins.py index da575cf821..97c0ff6384 100755 --- a/ports/rp2/boards/make-pins.py +++ b/ports/rp2/boards/make-pins.py @@ -207,7 +207,7 @@ class Pins(object): for row in rows: try: pin_num = parse_pin(row[pinname_col]) - except Exception as e: + except Exception: # import traceback; traceback.print_exc() continue pin = Pin(pin_num) @@ -228,7 +228,7 @@ class Pins(object): cpu_pin_name = row[1] try: - pin_num = parse_pin(cpu_pin_name) + parse_pin(cpu_pin_name) except: # import traceback; traceback.print_exc() continue diff --git a/ports/stm32/make-stmconst.py b/ports/stm32/make-stmconst.py index 44da3f07eb..bf0543716a 100644 --- a/ports/stm32/make-stmconst.py +++ b/ports/stm32/make-stmconst.py @@ -265,7 +265,6 @@ def main(): reg_defs["GPIO"].append(["BSRRL", 0x18, 16, "legacy register"]) reg_defs["GPIO"].append(["BSRRH", 0x1A, 16, "legacy register"]) - modules = [] needed_qstrs = set() needed_mpzs = set() diff --git a/ports/stm32/mboot/mboot.py b/ports/stm32/mboot/mboot.py index e0dab163ce..6eea460e10 100644 --- a/ports/stm32/mboot/mboot.py +++ b/ports/stm32/mboot/mboot.py @@ -38,7 +38,7 @@ class Bootloader: self.i2c.readfrom_into(self.addr, self.buf1) n = self.buf1[0] break - except OSError as er: + except OSError: time.sleep_us(500) if time.ticks_diff(time.ticks_ms(), start) > 5000: raise Exception("timeout") diff --git a/tools/mpremote/mpremote/console.py b/tools/mpremote/mpremote/console.py index a0ee55dce9..e34fd9e277 100644 --- a/tools/mpremote/mpremote/console.py +++ b/tools/mpremote/mpremote/console.py @@ -172,5 +172,5 @@ else: try: set_conout_mode(mode, mask) VT_ENABLED = True - except WindowsError as e: + except WindowsError: VT_ENABLED = False diff --git a/tools/mpremote/mpremote/pyboardextended.py b/tools/mpremote/mpremote/pyboardextended.py index 6bad94a561..b9dbd1e3b1 100644 --- a/tools/mpremote/mpremote/pyboardextended.py +++ b/tools/mpremote/mpremote/pyboardextended.py @@ -449,7 +449,7 @@ class PyboardCommand: try: stat = os.lstat(self.data_ilistdir[0] + "/" + entry) mode = stat.st_mode & 0xC000 - except OSError as er: + except OSError: mode = 0 self.wr_str(entry) self.wr_u32(mode) diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index fe83305d71..7f581d0b13 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -1120,7 +1120,6 @@ class RawCodeNative(RawCode): i_top = len(self.fun_data) i = 0 - qi = 0 while i < i_top: # copy machine code (max 16 bytes) i16 = min(i + 16, i_top) @@ -1276,7 +1275,7 @@ def read_raw_code(reader, parent_name, qstr_table, obj_table, segments): if native_scope_flags & MP_SCOPE_FLAG_VIPERRODATA: rodata_size = reader.read_uint() if native_scope_flags & MP_SCOPE_FLAG_VIPERBSS: - bss_size = reader.read_uint() + reader.read_uint() # bss_size if native_scope_flags & MP_SCOPE_FLAG_VIPERRODATA: reader.read_bytes(rodata_size) if native_scope_flags & MP_SCOPE_FLAG_VIPERRELOC: @@ -1285,10 +1284,10 @@ def read_raw_code(reader, parent_name, qstr_table, obj_table, segments): if op == 0xFF: break if op & 1: - addr = reader.read_uint() + reader.read_uint() # addr op >>= 1 if op <= 5 and op & 1: - n = reader.read_uint() + reader.read_uint() # n else: assert kind == MP_CODE_NATIVE_ASM native_n_pos_args = reader.read_uint() diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py index 05e70709ad..87e57869f6 100755 --- a/tools/mpy_ld.py +++ b/tools/mpy_ld.py @@ -471,7 +471,6 @@ def do_relocation_text(env, text_addr, r): # Extract relevant info about symbol that's being relocated s = r.sym s_bind = s.entry["st_info"]["bind"] - s_shndx = s.entry["st_shndx"] s_type = s.entry["st_info"]["type"] r_offset = r["r_offset"] + text_addr r_info_type = r["r_info_type"] From 78a1aa171121a73a4785e249a5b38f8514d4502e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 8 Mar 2023 16:09:36 +0100 Subject: [PATCH 036/565] github/workflows: Add GitHub Action to lint Python code with ruff. Signed-off-by: Damien George --- .github/workflows/ruff.yml | 10 ++++++++++ pyproject.toml | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .github/workflows/ruff.yml diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000000..b8e43dc78f --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,10 @@ +# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python +name: Python code lint with ruff +on: [push, pull_request] +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: pip install --user ruff + - run: ruff --format=github . diff --git a/pyproject.toml b/pyproject.toml index 3b2a9f3135..a52796860a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,3 +22,27 @@ skip = """ ./tests,\ ACKNOWLEDGEMENTS,\ """ + +[tool.ruff] +exclude = ["lib", "tests"] +extend-select = ["C9", "PLC"] +ignore = [ + "E401", + "E402", + "E722", + "E731", + "E741", + "F401", + "F403", + "F405", + "F821", + "PLC1901", +] +line-length = 337 +target-version = "py37" + +[tool.ruff.mccabe] +max-complexity = 40 + +[tool.ruff.per-file-ignores] +"ports/cc3200/tools/uniflash.py" = ["E711"] From 957bd5118477df89e0539bc2c5325810059b6ad0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 3 May 2023 13:12:54 +1000 Subject: [PATCH 037/565] py/parse: Fix build when COMP_CONST_FOLDING=0 and COMP_MODULE_CONST=1. Signed-off-by: Damien George --- py/parse.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/py/parse.c b/py/parse.c index c228d3a34a..86198224fd 100644 --- a/py/parse.c +++ b/py/parse.c @@ -242,6 +242,8 @@ typedef struct _parser_t { #endif } parser_t; +STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args); + STATIC const uint16_t *get_rule_arg(uint8_t r_id) { size_t off = rule_arg_offset_table[r_id]; if (r_id >= FIRST_RULE_WITH_OFFSET_ABOVE_255) { @@ -630,6 +632,8 @@ STATIC void push_result_token(parser_t *parser, uint8_t rule_id) { push_result_node(parser, pn); } +#if MICROPY_COMP_CONST_FOLDING + #if MICROPY_COMP_MODULE_CONST STATIC const mp_rom_map_elem_t mp_constants_table[] = { #if MICROPY_PY_UERRNO @@ -644,9 +648,6 @@ STATIC const mp_rom_map_elem_t mp_constants_table[] = { STATIC MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table); #endif -STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args); - -#if MICROPY_COMP_CONST_FOLDING #if MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND // Some versions of the xtensa-esp32-elf-gcc compiler generate wrong code if this // function is static, so provide a hook for them to work around this problem. @@ -889,7 +890,8 @@ STATIC bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) { return true; } -#endif + +#endif // MICROPY_COMP_CONST_FOLDING #if MICROPY_COMP_CONST_TUPLE STATIC bool build_tuple_from_stack(parser_t *parser, size_t src_line, size_t num_args) { From 1b980c9dbef33edcddd7b7cf8533fb8b0bbb1aec Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 3 May 2023 13:21:18 +1000 Subject: [PATCH 038/565] py/compile: Remove over-eager optimisation of tuples as if condition. When a tuple is the condition of an if statement, it's only possible to optimise that tuple away when it is a constant tuple (ie all its elements are constants), because if it's not constant then the elements must be evaluated in case they have side effects (even though the resulting tuple will always be "true"). The code before this change handled the empty tuple OK (because it doesn't need to be evaluated), but it discarded non-empty tuples without evaluating them, which is incorrect behaviour (as show by the updated test). This optimisation is anyway rarely applied because it's not common Python coding practice to write things like `if (): ...` and `if (1, 2): ...`, so removing this optimisation completely won't affect much code, if any. Furthermore, when MICROPY_COMP_CONST_TUPLE is enabled, constant tuples are already optimised by the parser, so expression with constant tuples like `if (): ...` and `if (1, 2): ...` will continue to be optimised properly (and so when this option is enabled the code that's deleted in this commit is actually unreachable when the if condition is a constant tuple). Signed-off-by: Damien George --- py/compile.c | 15 --------------- tests/basics/ifcond.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/py/compile.c b/py/compile.c index c953711081..bb7c1117fa 100644 --- a/py/compile.c +++ b/py/compile.c @@ -423,21 +423,6 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la } else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_not_test_2) { c_if_cond(comp, pns->nodes[0], !jump_if, label); return; - } else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_atom_paren) { - // cond is something in parenthesis - if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { - // empty tuple, acts as false for the condition - if (jump_if == false) { - EMIT_ARG(jump, label); - } - } else { - assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_testlist_comp)); - // non-empty tuple, acts as true for the condition - if (jump_if == true) { - EMIT_ARG(jump, label); - } - } - return; } } diff --git a/tests/basics/ifcond.py b/tests/basics/ifcond.py index 9264aa74dd..5eba143420 100644 --- a/tests/basics/ifcond.py +++ b/tests/basics/ifcond.py @@ -57,6 +57,20 @@ if not (1,): else: print('b') +# test evaluation of the if-condition with tuples as arguments +# non-constant tuples should be evaluated even though they will evaluate to true + +def f(x): + print("f", x) + +if (f(1),): + print(18) + +if (f(2), f(3)): + print(19) + +# test if-conditions within a function + f2 = 0 def f(t1, t2, f1): From 61b8e1b2d89175d288239376762184c78fdd5c9d Mon Sep 17 00:00:00 2001 From: Carlosgg Date: Tue, 2 May 2023 20:49:33 +0100 Subject: [PATCH 039/565] lib/mbedtls: Update to mbedtls v2.28.3. This is the latest release in the 2.28 long-time support branch. Signed-off-by: Carlos Gil --- lib/mbedtls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mbedtls b/lib/mbedtls index dd79db1001..981743de6f 160000 --- a/lib/mbedtls +++ b/lib/mbedtls @@ -1 +1 @@ -Subproject commit dd79db10014d85b26d11fe57218431f2e5ede6f2 +Subproject commit 981743de6fcdbe672e482b6fd724d31d0a0d2476 From f1c6cb7725960487195daa5c5c196fd8d3563811 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 3 May 2023 15:23:24 +1000 Subject: [PATCH 040/565] py/stackctrl: Add gcc pragmas to ignore dangling-pointer warning. This warning became apparent in gcc 13. Signed-off-by: Damien George --- py/stackctrl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/py/stackctrl.c b/py/stackctrl.c index c2f3adb5ee..c2566ebad9 100644 --- a/py/stackctrl.c +++ b/py/stackctrl.c @@ -28,8 +28,15 @@ #include "py/stackctrl.h" void mp_stack_ctrl_init(void) { + #if __GNUC__ >= 13 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdangling-pointer" + #endif volatile int stack_dummy; MP_STATE_THREAD(stack_top) = (char *)&stack_dummy; + #if __GNUC__ >= 13 + #pragma GCC diagnostic pop + #endif } void mp_stack_set_top(void *top) { From 0264465585ba10e80bb8ade5b3df2979363d53d0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 4 May 2023 12:12:29 +1000 Subject: [PATCH 041/565] tools/pyboard.py: Import serial.tools.list_ports. This import is needed by newer versions of pyserial. Signed-off-by: Damien George --- tools/pyboard.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/pyboard.py b/tools/pyboard.py index 10cb764b91..c5c12c95b7 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -277,6 +277,7 @@ class Pyboard: self.serial = TelnetToSerial(device, user, password, read_timeout=10) else: import serial + import serial.tools.list_ports # Set options, and exclusive if pyserial supports it serial_kwargs = {"baudrate": baudrate, "interCharTimeout": 1} From 9c7ad68165bcd224c94ca6d8f172362cf8000d99 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 23 Feb 2023 21:52:47 +0100 Subject: [PATCH 042/565] mimxrt/machine_pwm: Start PWM only if freq and duty are set. And also fix/improve the following: - Simplify the duty handling a little bit. - Allow duty_u16(65536), which sets the output high. - Rename machine_pwm_start() to mp_machine_pwm_start(), in preparation for a possible start/stop method pair. --- ports/mimxrt/machine_pwm.c | 94 +++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 42 deletions(-) diff --git a/ports/mimxrt/machine_pwm.c b/ports/mimxrt/machine_pwm.c index c1d6bdf7a6..b8b526ae02 100644 --- a/ports/mimxrt/machine_pwm.c +++ b/ports/mimxrt/machine_pwm.c @@ -39,6 +39,7 @@ #define PWM_CHANNEL1 (1) #define PWM_CHANNEL2 (2) +#define VALUE_NOT_SET (-1) typedef struct _machine_pwm_obj_t { mp_obj_base_t base; @@ -51,10 +52,10 @@ typedef struct _machine_pwm_obj_t { uint8_t channel2; uint8_t invert; bool sync; - uint32_t freq; + int32_t freq; int16_t prescale; - uint16_t duty_u16; - uint32_t duty_ns; + int32_t duty_u16; + int32_t duty_ns; uint16_t center; uint32_t deadtime; bool output_enable_1; @@ -68,7 +69,7 @@ static char *ERRMSG_FREQ = "PWM frequency too low"; static char *ERRMSG_INIT = "PWM set-up failed"; static char *ERRMSG_VALUE = "value larger than period"; -STATIC void machine_pwm_start(machine_pwm_obj_t *self); +STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self); STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -79,36 +80,40 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p } else { mp_printf(print, "channel=%c", channel_char[self->channel1]); } - if (self->duty_ns != 0) { - mp_printf(print, " duty_ns=%u", self->duty_ns); + if (self->duty_ns != VALUE_NOT_SET) { + mp_printf(print, " duty_ns=%d", self->duty_ns); } else { - mp_printf(print, " duty_u16=%u", self->duty_u16); + mp_printf(print, " duty_u16=%d", self->duty_u16); } - mp_printf(print, " freq=%u center=%u, deadtime=%u, sync=%u>", + mp_printf(print, " freq=%d center=%u, deadtime=%u, sync=%u>", self->freq, self->center, self->deadtime, self->sync); #ifdef FSL_FEATURE_SOC_TMR_COUNT } else { - mp_printf(print, "module, self->channel1, self->freq); - if (self->duty_ns != 0) { - mp_printf(print, "duty_ns=%u>", self->duty_ns); + if (self->duty_ns == VALUE_NOT_SET) { + mp_printf(print, "duty_ns=%d>", self->duty_ns); } else { - mp_printf(print, "duty_u16=%u>", self->duty_u16); + mp_printf(print, "duty_u16=%d>", self->duty_u16); } #endif } } -// Utility functions for decoding and convertings +// Utility functions for decoding and converting // STATIC uint32_t duty_ns_to_duty_u16(uint32_t freq, uint32_t duty_ns) { uint64_t duty = (uint64_t)duty_ns * freq * PWM_FULL_SCALE / 1000000000ULL; - if (duty >= PWM_FULL_SCALE) { + if (duty > PWM_FULL_SCALE) { mp_raise_ValueError(MP_ERROR_TEXT(ERRMSG_VALUE)); } return (uint32_t)duty; } +STATIC uint32_t duty_u16_to_duty_ns(machine_pwm_obj_t *self) { + return 1000000000ULL * (uint64_t)self->duty_u16 / self->freq / PWM_FULL_SCALE; +} + STATIC uint8_t module_decode(char channel) { switch (channel) { case '0': @@ -340,15 +345,20 @@ STATIC void configure_pwm(machine_pwm_obj_t *self) { set_frequency = false; } - if (self->duty_ns != 0) { - self->duty_u16 = duty_ns_to_duty_u16(self->freq, self->duty_ns); - } - if (self->is_flexpwm) { - configure_flexpwm(self); - #ifdef FSL_FEATURE_SOC_TMR_COUNT - } else { - configure_qtmr(self); - #endif + // Enable the PWM only if both freq and duty value are set + if (self->freq != VALUE_NOT_SET && (self->duty_u16 != VALUE_NOT_SET || self->duty_ns != VALUE_NOT_SET)) { + if (self->duty_ns != VALUE_NOT_SET) { + self->duty_u16 = duty_ns_to_duty_u16(self->freq, self->duty_ns); + } else { + self->duty_ns = duty_u16_to_duty_ns(self); + } + if (self->is_flexpwm) { + configure_flexpwm(self); + #ifdef FSL_FEATURE_SOC_TMR_COUNT + } else { + configure_qtmr(self); + #endif + } } } @@ -359,9 +369,9 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, enum { ARG_freq, ARG_duty_u16, ARG_duty_ns, ARG_center, ARG_align, ARG_invert, ARG_sync, ARG_xor, ARG_deadtime }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_freq, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_duty_u16, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_duty_ns, MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_freq, MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + { MP_QSTR_duty_u16, MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + { MP_QSTR_duty_ns, MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, { MP_QSTR_center, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_align, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1}}, { MP_QSTR_invert, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1}}, @@ -380,24 +390,24 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, } // Set duty_u16 cycle? - uint32_t duty = args[ARG_duty_u16].u_int; - if (duty != 0) { - if (duty >= PWM_FULL_SCALE) { + int32_t duty = args[ARG_duty_u16].u_int; + if (duty >= 0) { + if (duty > PWM_FULL_SCALE) { mp_raise_ValueError(MP_ERROR_TEXT(ERRMSG_VALUE)); } self->duty_u16 = duty; - self->duty_ns = 0; + self->duty_ns = VALUE_NOT_SET; } // Set duty_ns value? duty = args[ARG_duty_ns].u_int; - if (duty != 0) { + if (duty >= 0) { self->duty_ns = duty; - self->duty_u16 = duty_ns_to_duty_u16(self->freq, self->duty_ns); + self->duty_u16 = VALUE_NOT_SET; } // Set center value? int32_t center = args[ARG_center].u_int; if (center >= 0) { - if (center >= PWM_FULL_SCALE) { + if (center > PWM_FULL_SCALE) { mp_raise_ValueError(MP_ERROR_TEXT(ERRMSG_VALUE)); } self->center = center; @@ -432,7 +442,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, configure_pwm(self); self->is_init = true; } else { - machine_pwm_start(self); + mp_machine_pwm_start(self); } } @@ -512,10 +522,10 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args self->submodule = submodule1; self->channel1 = channel1; self->invert = 0; - self->freq = 1000; + self->freq = VALUE_NOT_SET; self->prescale = -1; - self->duty_u16 = 32768; - self->duty_ns = 0; + self->duty_u16 = VALUE_NOT_SET; + self->duty_ns = VALUE_NOT_SET; self->center = 32768; self->output_enable_1 = is_board_pin(pin1); self->sync = false; @@ -571,7 +581,7 @@ void machine_pwm_deinit_all(void) { #endif } -STATIC void machine_pwm_start(machine_pwm_obj_t *self) { +STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self) { if (self->is_flexpwm) { PWM_StartTimer(self->instance, 1 << self->submodule); #ifdef FSL_FEATURE_SOC_TMR_COUNT @@ -606,23 +616,23 @@ mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { if (duty >= 0) { - if (duty >= PWM_FULL_SCALE) { + if (duty > PWM_FULL_SCALE) { mp_raise_ValueError(MP_ERROR_TEXT(ERRMSG_VALUE)); } self->duty_u16 = duty; - self->duty_ns = 0; + self->duty_ns = VALUE_NOT_SET; configure_pwm(self); } } mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { - return MP_OBJ_NEW_SMALL_INT(1000000000ULL / self->freq * self->duty_u16 / PWM_FULL_SCALE); + return MP_OBJ_NEW_SMALL_INT(self->duty_ns); } void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { if (duty >= 0) { self->duty_ns = duty; - self->duty_u16 = duty_ns_to_duty_u16(self->freq, self->duty_ns); + self->duty_u16 = VALUE_NOT_SET; configure_pwm(self); } } From 250757716a91a05d28e4af8e07adda278f491199 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 24 Feb 2023 14:51:36 +0100 Subject: [PATCH 043/565] samd/machine_pwm: Add init() method to PWM and simplify the PWM code. The PWM.init() method has been added. Calling init() without arguments restarts a PWM channel stopped with deinit(). Otherwise single parameters except for "device=n" can be changed again. The device can only be specified once, either in the constructor or the first init() call. Also simplify get_pwm_config() and get_adc_config(), and shrink the PWM object. --- docs/samd/quickref.rst | 2 +- ports/samd/machine_pwm.c | 219 ++++++++++++++++++-------------------- ports/samd/mpconfigport.h | 2 +- ports/samd/pin_af.c | 31 ++---- 4 files changed, 118 insertions(+), 136 deletions(-) diff --git a/docs/samd/quickref.rst b/docs/samd/quickref.rst index cdfb0a4750..7a0786d4ca 100644 --- a/docs/samd/quickref.rst +++ b/docs/samd/quickref.rst @@ -191,7 +191,7 @@ It supports all basic methods listed for that class. :: PWM Constructor ``````````````` -.. class:: PWM(dest, freq, duty_u16, duty_ns, *, invert, device) +.. class:: PWM(dest, *, freq, duty_u16, duty_ns, invert, device) :noindex: Construct and return a new PWM object using the following parameters: diff --git a/ports/samd/machine_pwm.c b/ports/samd/machine_pwm.c index f6b417631e..d01ce2ff1a 100644 --- a/ports/samd/machine_pwm.c +++ b/ports/samd/machine_pwm.c @@ -40,15 +40,14 @@ typedef struct _machine_pwm_obj_t { mp_obj_base_t base; Tcc *instance; + bool defer_start; uint8_t pin_id; uint8_t alt_fct; - uint8_t device; + int8_t device; uint8_t channel; uint8_t output; uint16_t prescaler; - uint32_t period; // full period count ticks - uint32_t duty_ns; // just for reporting - uint16_t duty_u16; // just for reporting + int32_t freq; // for re-init. } machine_pwm_obj_t; #define PWM_NOT_INIT (0) @@ -58,6 +57,8 @@ typedef struct _machine_pwm_obj_t { #define PWM_FULL_SCALE (65536) #define PWM_UPDATE_TIMEOUT (2000) +#define VALUE_NOT_SET (-1) + static Tcc *tcc_instance[] = TCC_INSTS; #if defined(MCU_SAMD21) @@ -104,10 +105,12 @@ static uint8_t device_status[TCC_INST_NUM]; static uint8_t output_active[TCC_INST_NUM]; const uint16_t prescaler_table[] = {1, 2, 4, 8, 16, 64, 256, 1024}; -STATIC void pwm_stop_device(int device); STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); +STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self); +STATIC void mp_machine_pwm_stop(machine_pwm_obj_t *self); + STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -115,48 +118,39 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p pin_name(self->pin_id), self->device, self->channel, self->output); } -// PWM(pin) -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_pin, ARG_freq, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device }; +// called by the constructor and init() +STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, + size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_freq, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_freq, MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_duty_u16, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_duty_ns, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_invert, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_device, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_duty_u16, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + { MP_QSTR_duty_ns, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + { MP_QSTR_invert, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + { MP_QSTR_device, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, }; // Parse the arguments. mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all(n_args, pos_args, kw_args, + MP_ARRAY_SIZE(allowed_args), allowed_args, args); - // Get GPIO and optional device to connect to PWM. - uint32_t pin_id = mp_hal_get_pin_obj(args[ARG_pin].u_obj); - int32_t wanted_dev = args[ARG_device].u_int; // -1 = any - - // Get the peripheral object and populate it - - pwm_config_t config = get_pwm_config(pin_id, wanted_dev, device_status); - uint8_t device = config.device_channel >> 4; - if (device >= TCC_INST_NUM) { - mp_raise_ValueError(MP_ERROR_TEXT("wrong device")); + int8_t device = self->device; + if (device == VALUE_NOT_SET) { // Device not set, just get & set + int32_t wanted_dev = args[ARG_device].u_int; // -1 = any + pwm_config_t config = get_pwm_config(self->pin_id, wanted_dev, device_status); + device = config.device_channel >> 4; + self->instance = tcc_instance[device]; + self->device = device; + self->alt_fct = config.alt_fct; + self->channel = (config.device_channel & 0x0f) % tcc_channel_count[device]; + self->output = config.device_channel & 0x0f; + put_duty_value(device, self->channel, 0); } - machine_pwm_obj_t *self = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type); - self->instance = tcc_instance[device]; - self->device = device; - self->pin_id = pin_id; - self->alt_fct = config.alt_fct; - self->channel = (config.device_channel & 0x0f) % tcc_channel_count[device]; - self->output = config.device_channel & 0x0f; - self->prescaler = 1; - self->period = 1; // Use an invalid but safe value - self->duty_u16 = self->duty_ns = 0; - put_duty_value(self->device, self->channel, 0); - Tcc *tcc = self->instance; + // Initialize the hardware if needed if (device_status[device] == PWM_NOT_INIT) { // Enable the device clock at first use. #if defined(MCU_SAMD21) @@ -203,10 +197,11 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args device_status[device] = PWM_CLK_READY; } - if (args[ARG_invert].u_int != -1) { + self->defer_start = true; + if (args[ARG_invert].u_int != VALUE_NOT_SET) { bool invert = !!args[ARG_invert].u_int; if (device_status[device] != PWM_CLK_READY) { - pwm_stop_device(device); + mp_machine_pwm_stop(self); } uint32_t mask = 1 << (self->output + TCC_DRVCTRL_INVEN0_Pos); if (invert) { @@ -215,24 +210,47 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args tcc->DRVCTRL.reg &= ~(mask); } } - if (args[ARG_duty_u16].u_int != -1) { - mp_machine_pwm_duty_set_u16(self, args[ARG_duty_u16].u_int); - } - if (args[ARG_duty_ns].u_int != -1) { - mp_machine_pwm_duty_set_ns(self, args[ARG_duty_ns].u_int); - } - if (args[ARG_freq].u_int != -1) { + if (args[ARG_freq].u_int != VALUE_NOT_SET) { mp_machine_pwm_freq_set(self, args[ARG_freq].u_int); } + if (args[ARG_duty_u16].u_int != VALUE_NOT_SET) { + mp_machine_pwm_duty_set_u16(self, args[ARG_duty_u16].u_int); + } + if (args[ARG_duty_ns].u_int != VALUE_NOT_SET) { + mp_machine_pwm_duty_set_ns(self, args[ARG_duty_ns].u_int); + } + self->defer_start = false; + // Start the PWM if properly set. + mp_machine_pwm_start(self); +} + +// PWM(pin) +STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + + // Check number of arguments + mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); + + // Get the peripheral object and populate it + machine_pwm_obj_t *self = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type); + self->pin_id = mp_hal_get_pin_obj(args[0]); + self->device = VALUE_NOT_SET; + self->prescaler = 1; + self->freq = VALUE_NOT_SET; + + // Process the remaining parameters. + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, args + n_args); + mp_machine_pwm_init_helper(self, n_args - 1, args + 1, &kw_args); + return MP_OBJ_FROM_PTR(self); } -STATIC void pwm_stop_device(int device) { - Tcc *tcc = tcc_instance[device]; +STATIC void mp_machine_pwm_stop(machine_pwm_obj_t *self) { + Tcc *tcc = tcc_instance[self->device]; tcc->CTRLA.bit.ENABLE = 0; while (tcc->SYNCBUSY.reg & TCC_SYNCBUSY_ENABLE) { } - device_status[device] = PWM_CLK_READY; + device_status[self->device] = PWM_CLK_READY; } // Stop all TTC devices @@ -252,13 +270,13 @@ void pwm_deinit_all(void) { // Switch off an output. If all outputs of a device are off, // switch off that device. // This stops all channels, but keeps the configuration -// Calling pwm.freq(n) will start an instance again. +// Calling pwm.freq(n), pwm.duty_x() or pwm.init() will start it again. STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { mp_hal_clr_pin_mux(self->pin_id); // Switch the output off output_active[self->device] &= ~(1 << self->output); // clear output flasg // Stop the device, if no output is active. if (output_active[self->device] == 0) { - pwm_stop_device(self->device); + mp_machine_pwm_stop(self); } } @@ -275,80 +293,52 @@ STATIC void wait_for_register_update(Tcc *tcc) { tcc->INTFLAG.reg = TCC_INTFLAG_OVF; } -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { - if (self->instance->CTRLA.reg & TCC_CTRLA_ENABLE) { - return MP_OBJ_NEW_SMALL_INT(PWM_MASTER_CLK / self->prescaler / self->period); - } else { - return MP_OBJ_NEW_SMALL_INT(0); - } -} - -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { - // Set the frequency. The period counter is 24 bit or 16 bit with a pre-scaling +STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self) { + // Start the PWM. The period counter is 24 bit or 16 bit with a pre-scaling // of up to 1024, allowing a range from 24 MHz down to 1 Hz. static const uint32_t max_period[5] = {1 << 24, 1 << 24, 1 << 16, 1 << 16, 1 << 16}; - Tcc *tcc = self->instance; - if (freq < 1) { - pwm_stop_device(self->device); + if (self->freq < 1 || self->defer_start == true) { return; } - - // Get the actual settings of prescaler & period from the unit - // To be able for cope for changes. - uint32_t prev_period = tcc->PER.reg + 1; + Tcc *tcc = self->instance; // Check for the right prescaler uint8_t index; for (index = 0; index < 8; index++) { - uint32_t temp = PWM_MASTER_CLK / prescaler_table[index] / freq; + uint32_t temp = PWM_MASTER_CLK / prescaler_table[index] / self->freq; if (temp < max_period[self->device]) { break; } } self->prescaler = prescaler_table[index]; - uint32_t period = PWM_MASTER_CLK / self->prescaler / freq; + uint32_t period = PWM_MASTER_CLK / self->prescaler / self->freq; if (period < 2) { mp_raise_ValueError(MP_ERROR_TEXT("freq too large")); } // If the PWM is running, ensure that a cycle has passed since the - // previous setting before setting a new frequency/duty value + // previous setting before setting frequency and duty. if (tcc->CTRLA.reg & TCC_CTRLA_ENABLE) { wait_for_register_update(tcc); } // Check, if the prescaler has to be changed and stop the device if so. if (index != tcc->CTRLA.bit.PRESCALER) { - // stop the device - pwm_stop_device(self->device); - // update the prescaler + mp_machine_pwm_stop(self); tcc->CTRLA.bit.PRESCALER = index; } // Lock the update to get a glitch-free change of period and duty cycle tcc->CTRLBSET.reg = TCC_CTRLBSET_LUPD; tcc->PERBUF.reg = period - 1; - self->period = period; - // Check if the Duty rate has to be aligned again when freq or prescaler were changed. - // This condition is as well true on first call after instantiation. So (re-)configure - // all channels with a duty_u16 setting. - if (period != prev_period) { - for (uint16_t ch = 0; ch < tcc_channel_count[self->device]; ch++) { - if ((duty_type_flags[self->device] & (1 << ch)) != 0) { // duty_u16 type? - tcc->CCBUF[ch].reg = (uint64_t)get_duty_value(self->device, ch) * period / - PWM_FULL_SCALE; - } - } - } - // If the prescaler was changed, the device is disabled. So this condition is true - // after the instantiation and after a prescaler change. - // (re-)configure all channels with a duty_ns setting. - if (!(tcc->CTRLA.reg & TCC_CTRLA_ENABLE)) { - for (uint16_t ch = 0; ch < tcc_channel_count[self->device]; ch++) { - if ((duty_type_flags[self->device] & (1 << ch)) == 0) { // duty_ns type? - tcc->CCBUF[ch].reg = (uint64_t)get_duty_value(self->device, ch) * PWM_MASTER_CLK / - self->prescaler / 1000000000ULL; - } + // (re-) configure the duty type settings. + for (uint16_t ch = 0; ch < tcc_channel_count[self->device]; ch++) { + if ((duty_type_flags[self->device] & (1 << ch)) != 0) { // duty_u16 type? + tcc->CCBUF[ch].reg = (uint64_t)get_duty_value(self->device, ch) * period / + PWM_FULL_SCALE; + } else { // duty_ns type + tcc->CCBUF[ch].reg = (uint64_t)get_duty_value(self->device, ch) * PWM_MASTER_CLK / + self->prescaler / 1000000000ULL; } } // Remember the output as active. @@ -367,38 +357,39 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { tcc->CTRLBCLR.reg = TCC_CTRLBCLR_LUPD; } +STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { + return MP_OBJ_NEW_SMALL_INT(self->freq); +} + +STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { + self->freq = freq; + mp_machine_pwm_start(self); +} + STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { - return MP_OBJ_NEW_SMALL_INT(self->duty_u16); + if (duty_type_flags[self->device] & (1 << self->channel)) { + return MP_OBJ_NEW_SMALL_INT(get_duty_value(self->device, self->channel)); + } else { + return MP_OBJ_NEW_SMALL_INT(-1); + } } STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { - // Remember the values for update & reporting put_duty_value(self->device, self->channel, duty_u16); - self->duty_u16 = duty_u16; - self->duty_ns = 0; - // If the device is enabled, than the period is set and we get a reasonable value for - // the duty cycle, set to the CCBUF register. Otherwise, PWM does not start. - if (self->instance->CTRLA.reg & TCC_CTRLA_ENABLE) { - // Ensure that a cycle has passed updating the registers - // since the previous setting before setting a new duty value - wait_for_register_update(self->instance); - self->instance->CCBUF[self->channel].reg = (uint64_t)duty_u16 * (self->period) / PWM_FULL_SCALE; - } duty_type_flags[self->device] |= 1 << self->channel; + mp_machine_pwm_start(self); } STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { - return MP_OBJ_NEW_SMALL_INT(self->duty_ns); + if (!(duty_type_flags[self->device] & (1 << self->channel))) { + return MP_OBJ_NEW_SMALL_INT(get_duty_value(self->device, self->channel)); + } else { + return MP_OBJ_NEW_SMALL_INT(-1); + } } STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { - // Remember the values for update & reporting put_duty_value(self->device, self->channel, duty_ns); - self->duty_ns = duty_ns; - self->duty_u16 = 0; - // Ensure that a cycle has passed updating the registers - // since the previous setting before setting a new duty value - wait_for_register_update(self->instance); - self->instance->CCBUF[self->channel].reg = (uint64_t)duty_ns * PWM_MASTER_CLK / self->prescaler / 1000000000ULL; duty_type_flags[self->device] &= ~(1 << self->channel); + mp_machine_pwm_start(self); } diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 779bc4713e..6ed8186ec0 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -107,7 +107,7 @@ #define MICROPY_PY_MACHINE_BITSTREAM (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_PY_MACHINE_PWM (1) -#define MICROPY_PY_MACHINE_PWM_INIT (0) +#define MICROPY_PY_MACHINE_PWM_INIT (1) #define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/samd/machine_pwm.c" #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new diff --git a/ports/samd/pin_af.c b/ports/samd/pin_af.c index 2664fd4109..15743d1dfe 100644 --- a/ports/samd/pin_af.c +++ b/ports/samd/pin_af.c @@ -142,11 +142,6 @@ sercom_pad_config_t get_sercom_config(int pin_id, uint8_t sercom_nr) { adc_config_t get_adc_config(int pin_id, int32_t flag) { const machine_pin_obj_t *pct_ptr = get_pin_obj_ptr(pin_id); - #if defined(MCU_SAMD51) - if (pct_ptr->adc1 != 0xff && (flag & (1 << (pct_ptr->adc1 + 16))) == 0) { - return (adc_config_t) {1, pct_ptr->adc1}; - } else - #endif if (pct_ptr->adc0 != 0xff && (flag & (1 << pct_ptr->adc0)) == 0) { return (adc_config_t) {0, pct_ptr->adc0}; #if defined(MUC_SAMD51) @@ -174,26 +169,22 @@ pwm_config_t get_pwm_config(int pin_id, int wanted_dev, uint8_t device_status[]) return (pwm_config_t) {ALT_FCT_TCC1, tcc1}; } else if ((tcc2 >> 4) == wanted_dev) { return (pwm_config_t) {ALT_FCT_TCC2, tcc2}; - } else { - mp_raise_ValueError(MP_ERROR_TEXT("wrong device or channel")); } } else { - pwm_config_t ret = {}; + // Try to get a unused PWM device at the pin + if (((tcc1 >> 4) < TCC_INST_NUM) && (device_status[tcc1 >> 4] == 0)) { + return (pwm_config_t) {ALT_FCT_TCC1, tcc1}; + } + if (((tcc2 >> 4) < TCC_INST_NUM) && (device_status[tcc2 >> 4] == 0)) { + return (pwm_config_t) {ALT_FCT_TCC2, tcc2}; + } + // If all devices are used, return one from the pin if available if ((tcc1 >> 4) < TCC_INST_NUM) { - ret = (pwm_config_t) {ALT_FCT_TCC1, tcc1}; - if (tcc2 == 0xff) { - return ret; - } + return (pwm_config_t) {ALT_FCT_TCC1, tcc1}; } if ((tcc2 >> 4) < TCC_INST_NUM) { - // if a device in slot 1 is not available or already in use, use the one in slot 2 - if (tcc1 == 0xff || device_status[(ret.device_channel >> 4)] != 0) { - return (pwm_config_t) {ALT_FCT_TCC2, tcc2}; - } else { - return ret; - } - } else { - mp_raise_ValueError(MP_ERROR_TEXT("not a PWM pin")); + return (pwm_config_t) {ALT_FCT_TCC2, tcc2}; } } + mp_raise_ValueError(MP_ERROR_TEXT("not a PWM Pin")); } From 84302b2854334371217015a5924978c009a94d30 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 24 Feb 2023 17:06:34 +0100 Subject: [PATCH 044/565] rp2/machine_pwm: Enable keyword args in constructor and add init method. This adds support for freq/duty_u16/duty_ns keyword arguments in the PWM constructor, and adds the PWM.init() method. Using init() without arguments enables a previously deinit-ed PWM again. Further changes in this commit: - Do not start PWM output if only duty was set. - Stop all PWM slices on soft-reset. - Fix a bug when changing the freq on a channel pair with duty_ns set. --- ports/rp2/machine_pwm.c | 98 +++++++++++++++++++++++++++++++--------- ports/rp2/main.c | 1 + ports/rp2/modmachine.h | 1 + ports/rp2/mpconfigport.h | 1 + 4 files changed, 80 insertions(+), 21 deletions(-) diff --git a/ports/rp2/machine_pwm.c b/ports/rp2/machine_pwm.c index 0c840eca94..5a0c4751e9 100644 --- a/ports/rp2/machine_pwm.c +++ b/ports/rp2/machine_pwm.c @@ -39,34 +39,37 @@ typedef struct _machine_pwm_obj_t { uint8_t slice; uint8_t channel; uint8_t duty_type; + bool freq_set; mp_int_t duty; } machine_pwm_obj_t; enum { + VALUE_NOT_SET = -1, DUTY_NOT_SET = 0, DUTY_U16, DUTY_NS }; STATIC machine_pwm_obj_t machine_pwm_obj[] = { - {{&machine_pwm_type}, 0, PWM_CHAN_A, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 0, PWM_CHAN_B, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 1, PWM_CHAN_A, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 1, PWM_CHAN_B, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 2, PWM_CHAN_A, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 2, PWM_CHAN_B, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 3, PWM_CHAN_A, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 3, PWM_CHAN_B, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 4, PWM_CHAN_A, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 4, PWM_CHAN_B, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 5, PWM_CHAN_A, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 5, PWM_CHAN_B, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 6, PWM_CHAN_A, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 6, PWM_CHAN_B, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 7, PWM_CHAN_A, DUTY_NOT_SET, 0}, - {{&machine_pwm_type}, 7, PWM_CHAN_B, DUTY_NOT_SET, 0}, + {{&machine_pwm_type}, 0, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 0, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 1, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 1, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 2, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 2, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 3, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 3, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 4, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 4, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 5, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 5, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 6, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 6, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 7, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 7, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, }; +STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); @@ -75,10 +78,46 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p mp_printf(print, "", self->slice, self->channel); } -// PWM(pin) +void machine_pwm_start(machine_pwm_obj_t *self) { + // Start the PWM if properly set. + if (self->freq_set && self->duty_type != DUTY_NOT_SET) { + pwm_set_enabled(self->slice, true); + } +} + +STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, + size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_freq, ARG_duty_u16, ARG_duty_ns }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_freq, MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + { MP_QSTR_duty_u16, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + { MP_QSTR_duty_ns, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + }; + + // Parse the arguments. + 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 ((n_args + kw_args->used) > 0) { + if (args[ARG_freq].u_int != VALUE_NOT_SET) { + mp_machine_pwm_freq_set(self, args[ARG_freq].u_int); + } + if (args[ARG_duty_u16].u_int != VALUE_NOT_SET) { + mp_machine_pwm_duty_set_u16(self, args[ARG_duty_u16].u_int); + } + if (args[ARG_duty_ns].u_int != VALUE_NOT_SET) { + mp_machine_pwm_duty_set_ns(self, args[ARG_duty_ns].u_int); + } + } else { + machine_pwm_start(self); + } +} + +// PWM(pin [, args]) STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check number of arguments - mp_arg_check_num(n_args, n_kw, 1, 1, false); + mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Get GPIO to connect to PWM. uint32_t gpio = mp_hal_get_pin_obj(all_args[0]); @@ -87,16 +126,28 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args uint slice = pwm_gpio_to_slice_num(gpio); uint8_t channel = pwm_gpio_to_channel(gpio); machine_pwm_obj_t *self = &machine_pwm_obj[slice * 2 + channel]; + self->freq_set = false; self->duty_type = DUTY_NOT_SET; // Select PWM function for given GPIO. gpio_set_function(gpio, GPIO_FUNC_PWM); + // Process the remaining parameters. + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); + mp_machine_pwm_init_helper(self, n_args - 1, all_args + 1, &kw_args); + return MP_OBJ_FROM_PTR(self); } +// Stop all active slices. +void machine_pwm_deinit_all(void) { + for (int i = 0; i < 8; i++) { + pwm_set_enabled(machine_pwm_obj[i].slice, false); + } +} + STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { - self->duty_type = DUTY_NOT_SET; pwm_set_enabled(self->slice, false); } @@ -165,11 +216,16 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { } pwm_hw->slice[self->slice].div = div16; pwm_hw->slice[self->slice].top = top; + self->freq_set = true; if (self->duty_type == DUTY_U16) { mp_machine_pwm_duty_set_u16(self, self->duty); } else if (self->duty_type == DUTY_NS) { mp_machine_pwm_duty_set_ns(self, self->duty); } + machine_pwm_obj_t *other = self->channel == PWM_CHAN_A ? self + 1 : self - 1; + if (other->duty_type == DUTY_NS) { + mp_machine_pwm_duty_set_ns(other, other->duty); + } } STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { @@ -188,9 +244,9 @@ STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u // Use rounding here to set it as accurately as possible. uint32_t cc = (duty_u16 * (top + 1) + 65535 / 2) / 65535; pwm_set_chan_level(self->slice, self->channel, cc); - pwm_set_enabled(self->slice, true); self->duty = duty_u16; self->duty_type = DUTY_U16; + machine_pwm_start(self); } STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { @@ -207,7 +263,7 @@ STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns mp_raise_ValueError(MP_ERROR_TEXT("duty larger than period")); } pwm_set_chan_level(self->slice, self->channel, cc); - pwm_set_enabled(self->slice, true); self->duty = duty_ns; self->duty_type = DUTY_NS; + machine_pwm_start(self); } diff --git a/ports/rp2/main.c b/ports/rp2/main.c index 059449695c..0ecc09b346 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -206,6 +206,7 @@ int main(int argc, char **argv) { #if MICROPY_PY_BLUETOOTH mp_bluetooth_deinit(); #endif + machine_pwm_deinit_all(); machine_pin_deinit(); #if MICROPY_PY_THREAD mp_thread_deinit(); diff --git a/ports/rp2/modmachine.h b/ports/rp2/modmachine.h index 6ea4def91d..45ccd49e8c 100644 --- a/ports/rp2/modmachine.h +++ b/ports/rp2/modmachine.h @@ -16,6 +16,7 @@ extern const mp_obj_type_t machine_wdt_type; void machine_pin_init(void); void machine_pin_deinit(void); void machine_i2s_init0(void); +void machine_pwm_deinit_all(void); struct _machine_spi_obj_t *spi_from_mp_obj(mp_obj_t o); NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args); diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 17586e5092..653b51091a 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -114,6 +114,7 @@ #define MICROPY_PY_MACHINE_BITSTREAM (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_PY_MACHINE_PWM (1) +#define MICROPY_PY_MACHINE_PWM_INIT (1) #define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/rp2/machine_pwm.c" #define MICROPY_PY_MACHINE_I2C (1) From dc8f9d22ca2ec9328b519e79013c97bbbe18b6c6 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 25 Feb 2023 10:51:56 +0100 Subject: [PATCH 045/565] docs: Update the PWM examples based on recent API improvements. This adds the freq and duty_u16 keyword settings to the constructor, and sometimes other details in the PWM section. For mimxrt a clarification regarding the PWM invert argument was added, and for rp2 a few words were spent on PWM output pairs of a channel/slice. --- docs/esp32/quickref.rst | 4 ++-- docs/library/machine.PWM.rst | 3 ++- docs/mimxrt/quickref.rst | 16 +++++++++------- docs/rp2/quickref.rst | 27 +++++++++++++++++++-------- docs/samd/quickref.rst | 14 ++++++-------- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst index f74926c374..e19c6ecb40 100644 --- a/docs/esp32/quickref.rst +++ b/docs/esp32/quickref.rst @@ -305,8 +305,8 @@ Use the :ref:`machine.PWM ` class:: from machine import Pin, PWM - pwm0 = PWM(Pin(0)) # create PWM object from a pin - freq = pwm0.freq() # get current frequency (default 5kHz) + pwm0 = PWM(Pin(0), freq=5000, duty_u16=32768) # create PWM object from a pin + freq = pwm0.freq() # get current frequency pwm0.freq(1000) # set PWM frequency from 1Hz to 40MHz duty = pwm0.duty() # get current duty cycle, range 0-1023 (default 512, 50%) diff --git a/docs/library/machine.PWM.rst b/docs/library/machine.PWM.rst index 4b74355775..d6c5de4b24 100644 --- a/docs/library/machine.PWM.rst +++ b/docs/library/machine.PWM.rst @@ -10,7 +10,8 @@ Example usage:: from machine import PWM - pwm = PWM(pin) # create a PWM object on a pin + pwm = PWM(pin, freq=50, duty_u16=8192) # create a PWM object on a pin + # and set freq and duty pwm.duty_u16(32768) # set duty to 50% # reinitialise with a period of 200us, duty of 5us diff --git a/docs/mimxrt/quickref.rst b/docs/mimxrt/quickref.rst index 06f91f7f50..ab8bf8831b 100644 --- a/docs/mimxrt/quickref.rst +++ b/docs/mimxrt/quickref.rst @@ -145,11 +145,12 @@ handling signal groups. :: from machine import Pin, PWM - pwm2 = PWM(Pin(2)) # create PWM object from a pin - pwm2.freq() # get current frequency - pwm2.freq(1000) # set frequency - pwm2.duty_u16() # get current duty cycle, range 0-65535 - pwm2.duty_u16(200) # set duty cycle, range 0-65535 + # create PWM object from a pin and set the frequency and duty cycle + pwm2 = PWM(Pin(2), freq=2000, duty_u16=32768) + pwm2.freq() # get the current frequency + pwm2.freq(1000) # set/change the frequency + pwm2.duty_u16() # get the current duty cycle, range 0-65535 + pwm2.duty_u16(200) # set the duty cycle, range 0-65535 pwm2.deinit() # turn off PWM on the pin # create a complementary signal pair on Pin 2 and 3 pwm2 = PWM((2, 3), freq=2000, duty_ns=20000) @@ -206,8 +207,9 @@ PWM Constructor - *align*\=value. Shortcuts for the pulse center setting, causing the pulse either at the center of the frame (value=0), the leading edge at the begin (value=1) or the trailing edge at the end of a pulse period (value=2). - - *invert*\=True|False channel_mask. Setting a bit in the mask inverts the respective channel. - Bit 0 inverts the first specified channel, bit 2 the second. The default is 0. + - *invert*\=value channel_mask. Setting a bit in the mask inverts the respective channel. + Bit 0 inverts the first specified channel, bit 1 the second. The default is 0. For a + PWM object with a single channel, True and False may be used as values. - *sync*\=True|False. If a channel of a module's submodule 0 is already active, other submodules of the same module can be forced to be synchronous to submodule 0. Their pulse period start then at at same clock cycle. The default is False. diff --git a/docs/rp2/quickref.rst b/docs/rp2/quickref.rst index 67a5cc0dfc..11a808c110 100644 --- a/docs/rp2/quickref.rst +++ b/docs/rp2/quickref.rst @@ -146,19 +146,30 @@ See :ref:`machine.UART `. :: PWM (pulse width modulation) ---------------------------- -There are 8 independent channels each of which have 2 outputs making it 16 -PWM channels in total which can be clocked from 7Hz to 125Mhz. +There are 8 independent PWM generators called slices, which each have two +channels making it 16 PWM channels in total which can be clocked from +8Hz to 62.5Mhz at a machine.freq() of 125Mhz. The two channels of a +slice run at the same frequency, but can have a different duty rate. +The two channels are usually assigned to adjacent GPIO pin pairs with +even/odd numbers. So GPIO0 and GPIO1 are at slice 0, GPIO2 and GPIO3 +are at slice 1, and so on. A certain channel can be assigned to +different GPIO pins (see Pinout). For instance slice 0, channel A can be assigned +to both GPIO0 and GPIO16. Use the ``machine.PWM`` class:: from machine import Pin, PWM - pwm0 = PWM(Pin(0)) # create PWM object from a pin - pwm0.freq() # get current frequency - pwm0.freq(1000) # set frequency - pwm0.duty_u16() # get current duty cycle, range 0-65535 - pwm0.duty_u16(200) # set duty cycle, range 0-65535 - pwm0.deinit() # turn off PWM on the pin + # create PWM object from a pin and set the frequency of slice 0 + # and duty cycle for channel A + pwm0 = PWM(Pin(0), freq=2000, duty_u16=32768) + pwm0.freq() # get the current frequency of slice 0 + pwm0.freq(1000) # set/change the frequency of slice 0 + pwm0.duty_u16() # get the current duty cycle of channel A, range 0-65535 + pwm0.duty_u16(200) # set the duty cycle of channel A, range 0-65535 + pwm0.duty_u16(0) # stop the output at channel A + print(pwm0) # show the properties of the PWM object. + pwm0.deinit() # turn off PWM of slice 0, stopping channels A and B ADC (analog to digital conversion) ---------------------------------- diff --git a/docs/samd/quickref.rst b/docs/samd/quickref.rst index 7a0786d4ca..7da855cb37 100644 --- a/docs/samd/quickref.rst +++ b/docs/samd/quickref.rst @@ -178,11 +178,12 @@ It supports all basic methods listed for that class. :: from machine import Pin, PWM - pwm = PWM(Pin(7)) # create PWM object from a pin - pwm.freq() # get current frequency - pwm.freq(1000) # set frequency - pwm.duty_u16() # get current duty cycle, range 0-65535 - pwm.duty_u16(200) # set duty cycle, range 0-65535 + # create PWM object from a pin and set the frequency and duty cycle + pwm = PWM(Pin('D7'), freq=2000, duty_u16=32768) + pwm.freq() # get the current frequency + pwm.freq(1000) # set/change the frequency + pwm.duty_u16() # get the current duty cycle, range 0-65535 + pwm.duty_u16(200) # set the duty cycle, range 0-65535 pwm.deinit() # turn off PWM on the pin pwm # show the PWM objects properties @@ -213,9 +214,6 @@ PWM Constructor - *freq* should be an integer which sets the frequency in Hz for the PWM cycle. The valid frequency range is 1 Hz to 24 MHz. - *duty_u16* sets the duty cycle as a ratio ``duty_u16 / 65536``. - The duty cycle of a X channel can only be changed, if the A and B channel - of the respective submodule is not used. Otherwise the duty_16 value of the - X channel is 32768 (50%). - *duty_ns* sets the pulse width in nanoseconds. The limitation for X channels apply as well. - *invert*\=True|False. Setting a bit inverts the respective output. From 2ac643c15bec8c88ece0e944ce58f36d02dfd2dd Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 25 Feb 2023 14:19:32 +0100 Subject: [PATCH 046/565] esp8266/machine_pwm: Implement duty_u16() and duty_ns() for consistency. Also adds these keyword arguments to the constructor and init method. --- ports/esp8266/machine_pwm.c | 64 +++++++++++++++++++++++++++++++----- ports/esp8266/mpconfigport.h | 1 + 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/ports/esp8266/machine_pwm.c b/ports/esp8266/machine_pwm.c index 6b7728dead..58c8fa915f 100644 --- a/ports/esp8266/machine_pwm.c +++ b/ports/esp8266/machine_pwm.c @@ -35,8 +35,11 @@ typedef struct _machine_pwm_obj_t { pyb_pin_obj_t *pin; uint8_t active; uint8_t channel; + int32_t duty_ns; } machine_pwm_obj_t; +STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty); + STATIC bool pwm_inited = false; /******************************************************************************/ @@ -53,10 +56,12 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p } STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_freq, ARG_duty }; + enum { ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns }; static const mp_arg_t allowed_args[] = { { MP_QSTR_freq, MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_duty, MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_duty_u16, MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_duty_ns, MP_ARG_INT, {.u_int = -1} }, }; 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); @@ -74,6 +79,15 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, c if (args[ARG_duty].u_int != -1) { pwm_set_duty(args[ARG_duty].u_int, self->channel); } + if (args[ARG_duty_u16].u_int != -1) { + pwm_set_duty(args[ARG_duty_u16].u_int * 1000 / 65536, self->channel); + } + if (args[ARG_duty_ns].u_int != -1) { + uint32_t freq = pwm_get_freq(0); + if (freq > 0) { + pwm_set_duty((uint64_t)args[ARG_duty_ns].u_int * freq / 1000000, self->channel); + } + } if (pin_mode[self->pin->phys_port] == GPIO_MODE_OPEN_DRAIN) { mp_hal_pin_open_drain(self->pin->phys_port); @@ -91,6 +105,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args self->pin = pin; self->active = 0; self->channel = -1; + self->duty_ns = -1; // start the PWM subsystem if it's not already running if (!pwm_inited) { @@ -118,26 +133,57 @@ STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { pwm_set_freq(freq, 0); - pwm_start(); + if (self->duty_ns != -1) { + mp_machine_pwm_duty_set_ns(self, self->duty_ns); + } else { + pwm_start(); + } } -STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { +STATIC void set_active(machine_pwm_obj_t *self, bool set_pin) { if (!self->active) { pwm_add(self->pin->phys_port, self->pin->periph, self->pin->func); self->active = 1; - - if (pin_mode[self->pin->phys_port] == GPIO_MODE_OPEN_DRAIN) { + if (set_pin && pin_mode[self->pin->phys_port] == GPIO_MODE_OPEN_DRAIN) { mp_hal_pin_open_drain(self->pin->phys_port); } } +} + +STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { + set_active(self, true); return MP_OBJ_NEW_SMALL_INT(pwm_get_duty(self->channel)); } STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { - if (!self->active) { - pwm_add(self->pin->phys_port, self->pin->periph, self->pin->func); - self->active = 1; - } + set_active(self, false); + self->duty_ns = -1; pwm_set_duty(duty, self->channel); pwm_start(); } + +STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { + set_active(self, true); + return MP_OBJ_NEW_SMALL_INT(pwm_get_duty(self->channel) * 65536 / 1024); +} + +STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { + set_active(self, false); + self->duty_ns = -1; + pwm_set_duty(duty * 1024 / 65536, self->channel); + pwm_start(); +} + +STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { + set_active(self, true); + uint32_t freq = pwm_get_freq(0); + return MP_OBJ_NEW_SMALL_INT(pwm_get_duty(self->channel) * 976563 / freq); +} + +STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { + set_active(self, false); + self->duty_ns = duty; + uint32_t freq = pwm_get_freq(0); + pwm_set_duty(duty * freq / 976562, self->channel); // 1e9/1024 = 976562.5 + pwm_start(); +} diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index 2111d33e95..54549614e5 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -68,6 +68,7 @@ #define MICROPY_PY_MACHINE_PWM (1) #define MICROPY_PY_MACHINE_PWM_INIT (1) #define MICROPY_PY_MACHINE_PWM_DUTY (1) +#define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/esp8266/machine_pwm.c" #define MICROPY_PY_MACHINE_I2C (1) #define MICROPY_PY_MACHINE_SOFTI2C (1) From 0b3b508d1d681e705c4c228cb846d10549e644af Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 28 Feb 2023 12:43:52 +0100 Subject: [PATCH 047/565] rp2/machine_pwm: Add support for inverting a PWM channel output. Using the invert=True|False keyword option with the constructor or init(). --- docs/library/machine.PWM.rst | 4 +- ports/rp2/machine_pwm.c | 86 +++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/docs/library/machine.PWM.rst b/docs/library/machine.PWM.rst index d6c5de4b24..b9cf002403 100644 --- a/docs/library/machine.PWM.rst +++ b/docs/library/machine.PWM.rst @@ -24,7 +24,7 @@ Example usage:: Constructors ------------ -.. class:: PWM(dest, *, freq, duty_u16, duty_ns) +.. class:: PWM(dest, *, freq, duty_u16, duty_ns, invert) Construct and return a new PWM object using the following parameters: @@ -35,10 +35,12 @@ Constructors PWM cycle. - *duty_u16* sets the duty cycle as a ratio ``duty_u16 / 65535``. - *duty_ns* sets the pulse width in nanoseconds. + - *invert* inverts the respective output if the value is True Setting *freq* may affect other PWM objects if the objects share the same underlying PWM generator (this is hardware specific). Only one of *duty_u16* and *duty_ns* should be specified at a time. + *invert* is not available at all ports. Methods ------- diff --git a/ports/rp2/machine_pwm.c b/ports/rp2/machine_pwm.c index 5a0c4751e9..5ab1efe0aa 100644 --- a/ports/rp2/machine_pwm.c +++ b/ports/rp2/machine_pwm.c @@ -38,8 +38,8 @@ typedef struct _machine_pwm_obj_t { mp_obj_base_t base; uint8_t slice; uint8_t channel; + uint8_t invert; uint8_t duty_type; - bool freq_set; mp_int_t duty; } machine_pwm_obj_t; @@ -51,47 +51,57 @@ enum { }; STATIC machine_pwm_obj_t machine_pwm_obj[] = { - {{&machine_pwm_type}, 0, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 0, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 1, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 1, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 2, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 2, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 3, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 3, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 4, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 4, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 5, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 5, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 6, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 6, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 7, PWM_CHAN_A, DUTY_NOT_SET, 0, 0 }, - {{&machine_pwm_type}, 7, PWM_CHAN_B, DUTY_NOT_SET, 0, 0 }, + {{&machine_pwm_type}, 0, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 0, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 1, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 1, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 2, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 2, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 3, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 3, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 4, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 4, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 5, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 5, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 6, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 6, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 7, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, + {{&machine_pwm_type}, 7, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, }; +STATIC bool defer_start; +STATIC bool slice_freq_set[8]; + STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "", self->slice, self->channel); + mp_printf(print, "", + self->slice, self->channel, self->invert); } void machine_pwm_start(machine_pwm_obj_t *self) { // Start the PWM if properly set. - if (self->freq_set && self->duty_type != DUTY_NOT_SET) { + if (defer_start == false && slice_freq_set[self->slice] == true && self->duty_type != DUTY_NOT_SET) { + if (self->channel == PWM_CHAN_A) { + pwm_set_output_polarity(self->slice, self->invert, (self + 1)->invert); + } else { + pwm_set_output_polarity(self->slice, (self - 1)->invert, self->invert); + } pwm_set_enabled(self->slice, true); } } STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_freq, ARG_duty_u16, ARG_duty_ns }; + enum { ARG_freq, ARG_duty_u16, ARG_duty_ns, ARG_invert }; static const mp_arg_t allowed_args[] = { { MP_QSTR_freq, MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, { MP_QSTR_duty_u16, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, { MP_QSTR_duty_ns, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, + { MP_QSTR_invert, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = VALUE_NOT_SET} }, }; // Parse the arguments. @@ -99,19 +109,22 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if ((n_args + kw_args->used) > 0) { - if (args[ARG_freq].u_int != VALUE_NOT_SET) { - mp_machine_pwm_freq_set(self, args[ARG_freq].u_int); - } - if (args[ARG_duty_u16].u_int != VALUE_NOT_SET) { - mp_machine_pwm_duty_set_u16(self, args[ARG_duty_u16].u_int); - } - if (args[ARG_duty_ns].u_int != VALUE_NOT_SET) { - mp_machine_pwm_duty_set_ns(self, args[ARG_duty_ns].u_int); - } - } else { - machine_pwm_start(self); + // defer starting PWM until all provided args are checked. + defer_start = true; + if (args[ARG_freq].u_int != VALUE_NOT_SET) { + mp_machine_pwm_freq_set(self, args[ARG_freq].u_int); } + if (args[ARG_duty_u16].u_int != VALUE_NOT_SET) { + mp_machine_pwm_duty_set_u16(self, args[ARG_duty_u16].u_int); + } + if (args[ARG_duty_ns].u_int != VALUE_NOT_SET) { + mp_machine_pwm_duty_set_ns(self, args[ARG_duty_ns].u_int); + } + if (args[ARG_invert].u_int != VALUE_NOT_SET) { + self->invert = !!args[ARG_invert].u_int; + } + defer_start = false; + machine_pwm_start(self); } // PWM(pin [, args]) @@ -126,7 +139,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args uint slice = pwm_gpio_to_slice_num(gpio); uint8_t channel = pwm_gpio_to_channel(gpio); machine_pwm_obj_t *self = &machine_pwm_obj[slice * 2 + channel]; - self->freq_set = false; + self->invert = 0; self->duty_type = DUTY_NOT_SET; // Select PWM function for given GPIO. @@ -143,6 +156,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args // Stop all active slices. void machine_pwm_deinit_all(void) { for (int i = 0; i < 8; i++) { + slice_freq_set[i] = false; pwm_set_enabled(machine_pwm_obj[i].slice, false); } } @@ -216,14 +230,16 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { } pwm_hw->slice[self->slice].div = div16; pwm_hw->slice[self->slice].top = top; - self->freq_set = true; + slice_freq_set[self->slice] = true; if (self->duty_type == DUTY_U16) { mp_machine_pwm_duty_set_u16(self, self->duty); } else if (self->duty_type == DUTY_NS) { mp_machine_pwm_duty_set_ns(self, self->duty); } machine_pwm_obj_t *other = self->channel == PWM_CHAN_A ? self + 1 : self - 1; - if (other->duty_type == DUTY_NS) { + if (other->duty_type == DUTY_U16) { + mp_machine_pwm_duty_set_u16(other, other->duty); + } else if (other->duty_type == DUTY_NS) { mp_machine_pwm_duty_set_ns(other, other->duty); } } From 7952694a3cbf54ddc07268b84c45c80a8c6169e8 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 27 Apr 2023 21:21:56 +0200 Subject: [PATCH 048/565] rp2/machine_pwm: Add duty_x() checks and return 0 if PWM is not started. Changes in this commit: - Limit duty_u16() to 65535 and duty_ns() to the period duration. - Return 0 for pwm.freq() if the frequency has not been set yet. - Return 0 for pwm.duty_us16() and duty_ns() unless both frequency and duty cycle have been set. - Initialize the pin to PWM at the very end of the constructor, to avoid possible glitches on the pin when setting up the PWM. --- ports/rp2/machine_pwm.c | 55 +++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/ports/rp2/machine_pwm.c b/ports/rp2/machine_pwm.c index 5ab1efe0aa..a14ba0a43a 100644 --- a/ports/rp2/machine_pwm.c +++ b/ports/rp2/machine_pwm.c @@ -142,14 +142,14 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args self->invert = 0; self->duty_type = DUTY_NOT_SET; - // Select PWM function for given GPIO. - gpio_set_function(gpio, GPIO_FUNC_PWM); - // Process the remaining parameters. mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); mp_machine_pwm_init_helper(self, n_args - 1, all_args + 1, &kw_args); + // Select PWM function for given GPIO. + gpio_set_function(gpio, GPIO_FUNC_PWM); + return MP_OBJ_FROM_PTR(self); } @@ -189,10 +189,14 @@ uint32_t get_slice_hz_ceil(uint32_t div16) { } STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { - uint32_t div16 = pwm_hw->slice[self->slice].div; - uint32_t top = pwm_hw->slice[self->slice].top; - uint32_t pwm_freq = get_slice_hz_round(div16 * (top + 1)); - return MP_OBJ_NEW_SMALL_INT(pwm_freq); + if (slice_freq_set[self->slice] == true) { + uint32_t div16 = pwm_hw->slice[self->slice].div; + uint32_t top = pwm_hw->slice[self->slice].top; + uint32_t pwm_freq = get_slice_hz_round(div16 * (top + 1)); + return MP_OBJ_NEW_SMALL_INT(pwm_freq); + } else { + return MP_OBJ_NEW_SMALL_INT(0); + } } STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { @@ -245,19 +249,27 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { } STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { - uint32_t top = pwm_hw->slice[self->slice].top; - uint32_t cc = pwm_hw->slice[self->slice].cc; - cc = (cc >> (self->channel ? PWM_CH0_CC_B_LSB : PWM_CH0_CC_A_LSB)) & 0xffff; + if (self->duty_type != DUTY_NOT_SET && slice_freq_set[self->slice] == true) { + uint32_t top = pwm_hw->slice[self->slice].top; + uint32_t cc = pwm_hw->slice[self->slice].cc; + cc = (cc >> (self->channel ? PWM_CH0_CC_B_LSB : PWM_CH0_CC_A_LSB)) & 0xffff; - // Use rounding (instead of flooring) here to give as accurate an - // estimate as possible. - return MP_OBJ_NEW_SMALL_INT((cc * 65535 + (top + 1) / 2) / (top + 1)); + // Use rounding (instead of flooring) here to give as accurate an + // estimate as possible. + return MP_OBJ_NEW_SMALL_INT((cc * 65535 + (top + 1) / 2) / (top + 1)); + } else { + return MP_OBJ_NEW_SMALL_INT(0); + } } STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { uint32_t top = pwm_hw->slice[self->slice].top; + // Limit duty_u16 to 65535 // Use rounding here to set it as accurately as possible. + if (duty_u16 > 65535) { + duty_u16 = 65535; + } uint32_t cc = (duty_u16 * (top + 1) + 65535 / 2) / 65535; pwm_set_chan_level(self->slice, self->channel, cc); self->duty = duty_u16; @@ -266,17 +278,22 @@ STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u } STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { - uint32_t slice_hz = get_slice_hz_round(pwm_hw->slice[self->slice].div); - uint32_t cc = pwm_hw->slice[self->slice].cc; - cc = (cc >> (self->channel ? PWM_CH0_CC_B_LSB : PWM_CH0_CC_A_LSB)) & 0xffff; - return MP_OBJ_NEW_SMALL_INT(((uint64_t)cc * 1000000000ULL + slice_hz / 2) / slice_hz); + if (self->duty_type != DUTY_NOT_SET && slice_freq_set[self->slice] == true) { + uint32_t slice_hz = get_slice_hz_round(pwm_hw->slice[self->slice].div); + uint32_t cc = pwm_hw->slice[self->slice].cc; + cc = (cc >> (self->channel ? PWM_CH0_CC_B_LSB : PWM_CH0_CC_A_LSB)) & 0xffff; + return MP_OBJ_NEW_SMALL_INT(((uint64_t)cc * 1000000000ULL + slice_hz / 2) / slice_hz); + } else { + return MP_OBJ_NEW_SMALL_INT(0); + } } STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { uint32_t slice_hz = get_slice_hz_round(pwm_hw->slice[self->slice].div); uint32_t cc = ((uint64_t)duty_ns * slice_hz + 500000000ULL) / 1000000000ULL; - if (cc > 65535) { - mp_raise_ValueError(MP_ERROR_TEXT("duty larger than period")); + uint32_t top = pwm_hw->slice[self->slice].top; + if (cc > (top + 1)) { + cc = top + 1; } pwm_set_chan_level(self->slice, self->channel, cc); self->duty = duty_ns; From 38243cd8e0792fd6e597e4761f9d9949a9d41599 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 4 May 2023 12:58:04 +1000 Subject: [PATCH 049/565] extmod/machine_pwm: Remove PWM_INIT and PWM_DUTY_U16_NS config options. All ports that enable MICROPY_PY_MACHINE_PWM now enable these two sub-options, so remove these sub-options altogether to force consistency in new ports that implement machine.PWM. Signed-off-by: Damien George --- extmod/machine_pwm.c | 10 ---------- ports/esp32/mpconfigport.h | 2 -- ports/esp8266/mpconfigport.h | 2 -- ports/mimxrt/mpconfigport.h | 2 -- ports/nrf/mpconfigport.h | 2 -- ports/rp2/mpconfigport.h | 2 -- ports/samd/mpconfigport.h | 2 -- 7 files changed, 22 deletions(-) diff --git a/extmod/machine_pwm.c b/extmod/machine_pwm.c index 220d34d7da..8a633b3793 100644 --- a/extmod/machine_pwm.c +++ b/extmod/machine_pwm.c @@ -34,13 +34,11 @@ #include MICROPY_PY_MACHINE_PWM_INCLUDEFILE #endif -#if MICROPY_PY_MACHINE_PWM_INIT STATIC mp_obj_t machine_pwm_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { mp_machine_pwm_init_helper(args[0], n_args - 1, args + 1, kw_args); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pwm_init_obj, 1, machine_pwm_init); -#endif // PWM.deinit() STATIC mp_obj_t machine_pwm_deinit(mp_obj_t self_in) { @@ -82,8 +80,6 @@ STATIC mp_obj_t machine_pwm_duty(size_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_duty_obj, 1, 2, machine_pwm_duty); #endif -#if MICROPY_PY_MACHINE_PWM_DUTY_U16_NS - // PWM.duty_u16([value]) STATIC mp_obj_t machine_pwm_duty_u16(size_t n_args, const mp_obj_t *args) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(args[0]); @@ -114,21 +110,15 @@ STATIC mp_obj_t machine_pwm_duty_ns(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_duty_ns_obj, 1, 2, machine_pwm_duty_ns); -#endif - STATIC const mp_rom_map_elem_t machine_pwm_locals_dict_table[] = { - #if MICROPY_PY_MACHINE_PWM_INIT { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pwm_init_obj) }, - #endif { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_pwm_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_pwm_freq_obj) }, #if MICROPY_PY_MACHINE_PWM_DUTY { MP_ROM_QSTR(MP_QSTR_duty), MP_ROM_PTR(&machine_pwm_duty_obj) }, #endif - #if MICROPY_PY_MACHINE_PWM_DUTY_U16_NS { MP_ROM_QSTR(MP_QSTR_duty_u16), MP_ROM_PTR(&machine_pwm_duty_u16_obj) }, { MP_ROM_QSTR(MP_QSTR_duty_ns), MP_ROM_PTR(&machine_pwm_duty_ns_obj) }, - #endif }; STATIC MP_DEFINE_CONST_DICT(machine_pwm_locals_dict, machine_pwm_locals_dict_table); diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 807ae23b0c..ea3487bcd8 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -98,9 +98,7 @@ #define MICROPY_PY_MACHINE_BITSTREAM (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_PY_MACHINE_PWM (1) -#define MICROPY_PY_MACHINE_PWM_INIT (1) #define MICROPY_PY_MACHINE_PWM_DUTY (1) -#define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/esp32/machine_pwm.c" #define MICROPY_PY_MACHINE_I2C (1) #define MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 (1) diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index 54549614e5..12ea3716d4 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -66,9 +66,7 @@ #define MICROPY_PY_MACHINE_BITSTREAM (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_PY_MACHINE_PWM (1) -#define MICROPY_PY_MACHINE_PWM_INIT (1) #define MICROPY_PY_MACHINE_PWM_DUTY (1) -#define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/esp8266/machine_pwm.c" #define MICROPY_PY_MACHINE_I2C (1) #define MICROPY_PY_MACHINE_SOFTI2C (1) diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index b1fdf14f22..1dd7711efe 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -83,8 +83,6 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_MACHINE_BITSTREAM (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_PY_MACHINE_PWM (1) -#define MICROPY_PY_MACHINE_PWM_INIT (1) -#define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/mimxrt/machine_pwm.c" #define MICROPY_PY_MACHINE_I2C (1) #ifndef MICROPY_PY_MACHINE_I2S diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index a3ceb023ee..23f7e560dc 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -197,9 +197,7 @@ #define MICROPY_PY_MACHINE_SOFT_PWM (0) #endif -#define MICROPY_PY_MACHINE_PWM_INIT (1) #define MICROPY_PY_MACHINE_PWM_DUTY (1) -#define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #if MICROPY_PY_MACHINE_HW_PWM #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/nrf/modules/machine/pwm.c" diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 653b51091a..b4487a23d7 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -114,8 +114,6 @@ #define MICROPY_PY_MACHINE_BITSTREAM (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_PY_MACHINE_PWM (1) -#define MICROPY_PY_MACHINE_PWM_INIT (1) -#define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/rp2/machine_pwm.c" #define MICROPY_PY_MACHINE_I2C (1) #define MICROPY_PY_MACHINE_SOFTI2C (1) diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 6ed8186ec0..bc1ad3d988 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -107,8 +107,6 @@ #define MICROPY_PY_MACHINE_BITSTREAM (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_PY_MACHINE_PWM (1) -#define MICROPY_PY_MACHINE_PWM_INIT (1) -#define MICROPY_PY_MACHINE_PWM_DUTY_U16_NS (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/samd/machine_pwm.c" #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new From 786013d467d8beace7c7a8a2cd1122c799d05dae Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 25 Feb 2023 10:51:56 +0100 Subject: [PATCH 050/565] docs/samd: Make use of pin names more consistent in examples. This keeps up with the changed Pin naming scheme. --- docs/samd/pinout.rst | 2 +- docs/samd/quickref.rst | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/samd/pinout.rst b/docs/samd/pinout.rst index 46d9d7a29d..702da2c178 100644 --- a/docs/samd/pinout.rst +++ b/docs/samd/pinout.rst @@ -105,7 +105,7 @@ or other combinations. SAMD21 SPI assignments `````````````````````` -The I2C devices and signals must be chosen according to the following rules: +The SPI devices and signals must be chosen according to the following rules: - The following pad number pairs are suitable for MOSI/SCK: 0/1, 2/3, 3/1, and 0/3. - The MISO signal must be at a Pin with a different pad number than MOSI or SCK. diff --git a/docs/samd/quickref.rst b/docs/samd/quickref.rst index 7da855cb37..60c57b3a47 100644 --- a/docs/samd/quickref.rst +++ b/docs/samd/quickref.rst @@ -132,7 +132,7 @@ Use the :ref:`machine.Pin ` class:: print(p2.value()) # get value, 0 or 1 p4 = Pin('D4', Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor - p7 = Pin("PA07", Pin.OUT, value=1) # set pin high on creation + p7 = Pin('PA07', Pin.OUT, value=1) # set pin high on creation Pins can be denoted by a string or a number. The string is either the pin label of the respective board, like "D0" or "SDA", or in the form @@ -157,7 +157,7 @@ See :ref:`machine.UART `. :: # Use UART 3 on a ItsyBitsy M4 board from machine import UART - uart3 = UART(3, tx=Pin(1), rx=Pin(0), baudrate=115200) + uart3 = UART(3, tx=Pin('D1'), rx=Pin('D0'), baudrate=115200) uart3.write('hello') # write 5 bytes uart3.read(5) # read up to 5 bytes @@ -243,9 +243,9 @@ Use the :ref:`machine.ADC ` class:: from machine import ADC - adc0 = ADC(Pin("A0")) # create ADC object on ADC pin, average=16 + adc0 = ADC(Pin('A0')) # create ADC object on ADC pin, average=16 adc0.read_u16() # read value, 0-65536 across voltage range 0.0v - 3.3v - adc1 = ADC(Pin("A1"), average=1) # create ADC object on ADC pin, average=1 + adc1 = ADC(Pin('A1'), average=1) # create ADC object on ADC pin, average=1 The resolution of the ADC is 12 bit with 12 bit accuracy, irrespective of the value returned by read_u16(). If you need a higher resolution or better accuracy, use @@ -339,7 +339,7 @@ Software SPI (using bit-banging) works on all pins, and is accessed via the # construct a SoftSPI bus on the given pins # polarity is the idle state of SCK # phase=0 means sample on the first edge of SCK, phase=1 means the second - spi = SoftSPI(baudrate=100000, polarity=1, phase=0, sck=Pin(7), mosi=Pin(9), miso=Pin(10)) + spi = SoftSPI(baudrate=100000, polarity=1, phase=0, sck=Pin('D7'), mosi=Pin('D9'), miso=Pin('D10')) spi.init(baudrate=200000) # set the baud rate @@ -386,7 +386,7 @@ accessed via the :ref:`machine.SoftI2C ` class:: from machine import Pin, SoftI2C - i2c = SoftI2C(scl=Pin(10), sda=Pin(11), freq=100000) + i2c = SoftI2C(scl=Pin('D10'), sda=Pin('D11'), freq=100000) i2c.scan() # scan for devices @@ -422,7 +422,7 @@ The OneWire driver is implemented in software and works on all pins:: from machine import Pin import onewire - ow = onewire.OneWire(Pin(12)) # create a OneWire bus on GPIO12 + ow = onewire.OneWire(Pin('D12')) # create a OneWire bus on GPIO12 ow.scan() # return a list of devices on the bus ow.reset() # reset the bus ow.readbyte() # read a byte @@ -452,12 +452,12 @@ The DHT driver is implemented in software and works on all pins:: import dht import machine - d = dht.DHT11(machine.Pin(4)) + d = dht.DHT11(machine.Pin('D4')) d.measure() d.temperature() # eg. 23 (°C) d.humidity() # eg. 41 (% RH) - d = dht.DHT22(machine.Pin(4)) + d = dht.DHT22(machine.Pin('D4')) d.measure() d.temperature() # eg. 23.6 (°C) d.humidity() # eg. 41.3 (% RH) @@ -472,7 +472,7 @@ The APA102 on some Adafruit boards can be controlled using SoftSPI:: from machine import SoftSPI, Pin # create the SPI object. miso can be any unused pin. - spi=SoftSPI(sck=Pin(25), mosi=Pin(26), miso=Pin(14)) + spi=SoftSPI(sck=Pin('D25'), mosi=Pin('D26'), miso=Pin('D14')) # define a little function that writes the data with # preamble and postfix @@ -497,7 +497,7 @@ with the Neopixel driver from the MicroPython driver library:: import machine # 1 LED connected to Pin D8 on Adafruit Feather boards - p = machine.Pin(8, machine.Pin.OUT) + p = machine.Pin('D8', machine.Pin.OUT) n = neopixel.NeoPixel(p, 1) # set the led to red. From 1093dea70924a785543326773319dbb156e05c15 Mon Sep 17 00:00:00 2001 From: glenn20 Date: Thu, 25 Aug 2022 16:55:57 +1000 Subject: [PATCH 051/565] esp32,esp8266: Add support to set/get power saving mode of WLAN. For esp32 and esp8266 this commit adds: - a 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_PERFORMANCE and PM_POWERSAVE constants to the WLAN class. This API should be general enough to use with all WLAN drivers. Documentation is also added. --- docs/library/network.WLAN.rst | 16 ++++++++++++++++ ports/esp32/network_wlan.c | 15 +++++++++++++++ ports/esp8266/network_wlan.c | 13 +++++++++++++ 3 files changed, 44 insertions(+) diff --git a/docs/library/network.WLAN.rst b/docs/library/network.WLAN.rst index d1e620ef09..68cd49769a 100644 --- a/docs/library/network.WLAN.rst +++ b/docs/library/network.WLAN.rst @@ -133,4 +133,20 @@ Methods hostname The hostname that will be sent to DHCP (STA interfaces) and mDNS (if supported, both STA and AP). (Deprecated, use :func:`network.hostname` instead) reconnects Number of reconnect attempts to make (integer, 0=none, -1=unlimited) txpower Maximum transmit power in dBm (integer or float) + pm WiFi Power Management setting (see below for allowed values) ============= =========== + +Constants +--------- + +.. data:: WLAN.PM_PERFORMANCE + WLAN.PM_POWERSAVE + WLAN.PM_NONE + + Allowed values for the ``WLAN.config(pm=...)`` network interface parameter: + + * ``PM_PERFORMANCE``: enable WiFi power management to balance power + savings and WiFi performance + * ``PM_POWERSAVE``: enable WiFi power management with additional power + savings and reduced WiFi performance + * ``PM_NONE``: disable wifi power management diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index 84b92577fc..81410f209b 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -508,6 +508,10 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_ esp_exceptions(esp_wifi_set_protocol(self->if_id, mp_obj_get_int(kwargs->table[i].value))); break; } + case MP_QSTR_pm: { + esp_exceptions(esp_wifi_set_ps(mp_obj_get_int(kwargs->table[i].value))); + break; + } default: goto unknown; } @@ -602,6 +606,12 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_ val = MP_OBJ_NEW_SMALL_INT(protocol_bitmap); break; } + case MP_QSTR_pm: { + wifi_ps_type_t ps_type; + esp_exceptions(esp_wifi_get_ps(&ps_type)); + val = MP_OBJ_NEW_SMALL_INT(ps_type); + break; + } default: goto unknown; } @@ -627,6 +637,11 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_wlan_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_wlan_config_obj) }, { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_network_ifconfig_obj) }, + + // Constants + { MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(WIFI_PS_NONE) }, + { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(WIFI_PS_MIN_MODEM) }, + { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(WIFI_PS_MAX_MODEM) }, }; STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); diff --git a/ports/esp8266/network_wlan.c b/ports/esp8266/network_wlan.c index 9f89b126f6..4ab4a9a002 100644 --- a/ports/esp8266/network_wlan.c +++ b/ports/esp8266/network_wlan.c @@ -419,6 +419,10 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs system_phy_set_max_tpw(power); break; } + case MP_QSTR_pm: { + wifi_set_sleep_type(mp_obj_get_int(kwargs->table[i].value)); + break; + } default: goto unknown; } @@ -486,6 +490,10 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs val = mp_obj_new_int(wifi_get_phy_mode()); break; } + case MP_QSTR_pm: { + val = MP_OBJ_NEW_SMALL_INT(wifi_get_sleep_type()); + break; + } default: goto unknown; } @@ -511,6 +519,11 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&esp_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) }, { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) }, + + // Constants + { MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(NONE_SLEEP_T) }, + { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(MODEM_SLEEP_T) }, + { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(LIGHT_SLEEP_T) }, }; STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); From a31e3de400c5b35f954222fa924d361d5c93ff95 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 6 May 2023 15:26:53 +1000 Subject: [PATCH 052/565] extmod/network_cyw43: Add power management constants. And allow querying the current power management mode. Signed-off-by: Damien George --- extmod/network_cyw43.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index dc685031dc..168bd3d52b 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -39,6 +39,18 @@ #include "lib/cyw43-driver/src/cyw43.h" #include "lib/cyw43-driver/src/cyw43_country.h" +// This is the same as cyw43_pm_value but as a macro, to make it a true constant. +#define CYW43_PM_VALUE(pm_mode, pm2_sleep_ret_ms, li_beacon_period, li_dtim_period, li_assoc) \ + ((li_assoc) << 20 \ + | (li_dtim_period) << 16 \ + | (li_beacon_period) << 12 \ + | ((pm2_sleep_ret_ms) / 10) << 4 \ + | (pm_mode)) + +#define PM_NONE (CYW43_PM_VALUE(CYW43_NO_POWERSAVE_MODE, 10, 0, 0, 0)) +#define PM_PERFORMANCE (CYW43_PM_VALUE(CYW43_PM2_POWERSAVE_MODE, 200, 1, 1, 10)) +#define PM_POWERSAVE (CYW43_PM_VALUE(CYW43_PM1_POWERSAVE_MODE, 10, 0, 0, 0)) + typedef struct _network_cyw43_obj_t { mp_obj_base_t base; cyw43_t *cyw; @@ -397,6 +409,11 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map cyw43_wifi_get_mac(self->cyw, self->itf, buf); return mp_obj_new_bytes(buf, 6); } + case MP_QSTR_pm: { + uint32_t pm; + cyw43_wifi_get_pm(self->cyw, &pm); + return MP_OBJ_NEW_SMALL_INT(pm); + } case MP_QSTR_txpower: { uint8_t buf[13]; memcpy(buf, "qtxpower\x00\x00\x00\x00\x00", 13); @@ -516,6 +533,11 @@ STATIC const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_cyw43_ifconfig_obj) }, { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_cyw43_status_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_cyw43_config_obj) }, + + // Class constants. + { MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(PM_NONE) }, + { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(PM_PERFORMANCE) }, + { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(PM_POWERSAVE) }, }; STATIC MP_DEFINE_CONST_DICT(network_cyw43_locals_dict, network_cyw43_locals_dict_table); From 7c645b52e315fa3d63bb95bb42ccf2a9c15fe21d Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 3 May 2023 14:42:18 +1000 Subject: [PATCH 053/565] CODECONVENTIONS: Require that commits be signed-off by the author. And use "must" instead of "should" where appropriate in related text. Signed-off-by: Damien George --- CODECONVENTIONS.md | 18 +++++++----------- tools/verifygitlog.py | 18 +++++++++--------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/CODECONVENTIONS.md b/CODECONVENTIONS.md index 6ab3324c2e..d44b382b25 100644 --- a/CODECONVENTIONS.md +++ b/CODECONVENTIONS.md @@ -11,7 +11,7 @@ It's also ok to drop file extensions. Besides prefix, first line of a commit message should describe a change clearly and to the point, and be a grammatical sentence with -final full stop. First line should fit within 72 characters. Examples +final full stop. First line must fit within 72 characters. Examples of good first line of commit messages: py/objstr: Add splitlines() method. @@ -27,12 +27,9 @@ change beyond 5 lines would likely require such detailed description. To get good practical examples of good commits and their messages, browse the `git log` of the project. -When committing you are encouraged to sign-off your commit by adding -"Signed-off-by" lines and similar, eg using "git commit -s". If you don't -explicitly sign-off in this way then the commit message, which includes your -name and email address in the "Author" line, implies your sign-off. In either -case, of explicit or implicit sign-off, you are certifying and signing off -against the following: +When committing you must sign-off your commit by adding "Signed-off-by:" +line(s) at the end of the commit message, e.g. using `git commit -s`. You +are then certifying and signing off against the following: * That you wrote the change yourself, or took it from a project with a compatible license (in the latter case the commit message, and possibly @@ -49,10 +46,9 @@ against the following: * Your contribution including commit message will be publicly and indefinitely available for anyone to access, including redistribution under the terms of the project's license. -* Your signature for all of the above, which is the "Signed-off-by" line - or the "Author" line in the commit message, includes your full real name and - a valid and active email address by which you can be contacted in the - foreseeable future. +* Your signature for all of the above, which is the "Signed-off-by" line, + includes your full real name and a valid and active email address by + which you can be contacted in the foreseeable future. Code auto-formatting ==================== diff --git a/tools/verifygitlog.py b/tools/verifygitlog.py index ee3e119f37..ad9385e7ac 100755 --- a/tools/verifygitlog.py +++ b/tools/verifygitlog.py @@ -49,17 +49,17 @@ def git_log(pretty_format, *args): def diagnose_subject_line(subject_line, subject_line_format, err): err.error("Subject line: " + subject_line) if not subject_line.endswith("."): - err.error('* should end with "."') + err.error('* must end with "."') if not re.match(r"^[^!]+: ", subject_line): - err.error('* should start with "path: "') + err.error('* must start with "path: "') if re.match(r"^[^!]+: *$", subject_line): - err.error("* should contain a subject after the path.") + err.error("* must contain a subject after the path.") m = re.match(r"^[^!]+: ([a-z][^ ]*)", subject_line) if m: - err.error('* first word of subject ("{}") should be capitalised.'.format(m.group(1))) + err.error('* first word of subject ("{}") must be capitalised.'.format(m.group(1))) if re.match(r"^[^!]+: [^ ]+$", subject_line): - err.error("* subject should contain more than one word.") - err.error("* should match: " + repr(subject_line_format)) + err.error("* subject must contain more than one word.") + err.error("* must match: " + repr(subject_line_format)) err.error('* Example: "py/runtime: Add support for foo to bar."') @@ -94,11 +94,11 @@ def verify_message_body(raw_body, err): if not re.match(subject_line_format, subject_line): diagnose_subject_line(subject_line, subject_line_format, err) if len(subject_line) >= 73: - err.error("Subject line should be 72 or fewer characters: " + subject_line) + err.error("Subject line must be 72 or fewer characters: " + subject_line) # Second one divides subject and body. if len(raw_body) > 1 and raw_body[1]: - err.error("Second message line should be empty: " + raw_body[1]) + err.error("Second message line must be empty: " + raw_body[1]) # Message body lines. for line in raw_body[2:]: @@ -107,7 +107,7 @@ def verify_message_body(raw_body, err): err.error("Message lines should be 75 or less characters: " + line) if not raw_body[-1].startswith("Signed-off-by: ") or "@" not in raw_body[-1]: - err.warning('Message should be signed-off. Use "git commit -s".') + err.error('Message must be signed-off. Use "git commit -s".') def run(args): From 468ed218c954d34c1cc6affeeff4153b3f16b6b5 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 15 Mar 2023 16:48:16 -0500 Subject: [PATCH 054/565] py/gc: Make improvements to MICROPY_GC_HOOK_LOOP. Changes in this commit: - Add MICROPY_GC_HOOK_LOOP to gc_info() and gc_alloc(). Both of these can be long running (many milliseconds) which is too long to be blocking in some applications. - Pass loop variable to MICROPY_GC_HOOK_LOOP(i) macro so that implementers can use it, e.g. to improve performance by only calling a function every X number of iterations. - Drop outer call to MICROPY_GC_HOOK_LOOP in gc_mark_subtree(). --- py/gc.c | 14 +++++++------- py/mpconfig.h | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/py/gc.c b/py/gc.c index 0873a0e11e..9fefd3638b 100644 --- a/py/gc.c +++ b/py/gc.c @@ -285,10 +285,8 @@ STATIC void gc_mark_subtree(size_t block) // Start with the block passed in the argument. size_t sp = 0; for (;;) { - MICROPY_GC_HOOK_LOOP - #if !MICROPY_GC_SPLIT_HEAP - mp_state_mem_area_t * area = &MP_STATE_MEM(area); + mp_state_mem_area_t *area = &MP_STATE_MEM(area); #endif // work out number of consecutive blocks in the chain starting with this one @@ -303,7 +301,7 @@ STATIC void gc_mark_subtree(size_t block) // check this block's children void **ptrs = (void **)PTR_FROM_BLOCK(area, block); for (size_t i = n_blocks * BYTES_PER_BLOCK / sizeof(void *); i > 0; i--, ptrs++) { - MICROPY_GC_HOOK_LOOP + MICROPY_GC_HOOK_LOOP(i); void *ptr = *ptrs; // If this is a heap pointer that hasn't been marked, mark it and push // it's children to the stack. @@ -359,7 +357,7 @@ STATIC void gc_deal_with_stack_overflow(void) { // scan entire memory looking for blocks which have been marked but not their children for (mp_state_mem_area_t *area = &MP_STATE_MEM(area); area != NULL; area = NEXT_AREA(area)) { for (size_t block = 0; block < area->gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) { - MICROPY_GC_HOOK_LOOP + MICROPY_GC_HOOK_LOOP(block); // trace (again) if mark bit set if (ATB_GET_KIND(area, block) == AT_MARK) { #if MICROPY_GC_SPLIT_HEAP @@ -381,7 +379,7 @@ STATIC void gc_sweep(void) { int free_tail = 0; for (mp_state_mem_area_t *area = &MP_STATE_MEM(area); area != NULL; area = NEXT_AREA(area)) { for (size_t block = 0; block < area->gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) { - MICROPY_GC_HOOK_LOOP + MICROPY_GC_HOOK_LOOP(block); switch (ATB_GET_KIND(area, block)) { case AT_HEAD: #if MICROPY_ENABLE_FINALISER @@ -475,7 +473,7 @@ void gc_collect_root(void **ptrs, size_t len) { mp_state_mem_area_t *area = &MP_STATE_MEM(area); #endif for (size_t i = 0; i < len; i++) { - MICROPY_GC_HOOK_LOOP + MICROPY_GC_HOOK_LOOP(i); void *ptr = gc_get_ptr(ptrs, i); #if MICROPY_GC_SPLIT_HEAP mp_state_mem_area_t *area = gc_get_ptr_area(ptr); @@ -533,6 +531,7 @@ void gc_info(gc_info_t *info) { bool finish = false; info->total += area->gc_pool_end - area->gc_pool_start; for (size_t block = 0, len = 0, len_free = 0; !finish;) { + MICROPY_GC_HOOK_LOOP(block); size_t kind = ATB_GET_KIND(area, block); switch (kind) { case AT_FREE: @@ -632,6 +631,7 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) { for (; area != NULL; area = NEXT_AREA(area), i = 0) { n_free = 0; for (i = area->gc_last_free_atb_index; i < area->gc_alloc_table_byte_len; i++) { + MICROPY_GC_HOOK_LOOP(i); byte a = area->gc_alloc_table_start[i]; // *FORMAT-OFF* if (ATB_0_IS_FREE(a)) { if (++n_free >= n_blocks) { i = i * BLOCKS_PER_ATB + 0; goto found; } } else { n_free = 0; } diff --git a/py/mpconfig.h b/py/mpconfig.h index 89fb733e99..f3d5ce557a 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -617,8 +617,9 @@ #endif // Hook to run code during time consuming garbage collector operations +// *i* is the loop index variable (e.g. can be used to run every x loops) #ifndef MICROPY_GC_HOOK_LOOP -#define MICROPY_GC_HOOK_LOOP +#define MICROPY_GC_HOOK_LOOP(i) #endif // Whether to provide m_tracked_calloc, m_tracked_free functions From 7333c06d05ed42083cd4222933c077561bd57e86 Mon Sep 17 00:00:00 2001 From: Jim Lipsey Date: Thu, 27 Apr 2023 17:07:16 -0500 Subject: [PATCH 055/565] stm32/boards/ARDUINO_PORTENTA_H7: Enable FDCAN. Add pin definitions to enable FDCAN support using the pyb.CAN() class. --- ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h index 529f4d6f2a..a2efd94de4 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h @@ -206,6 +206,11 @@ extern struct _spi_bdev_t spi_bdev; #define MICROPY_HW_SDCARD_D3 (pin_B4) #define MICROPY_HW_SDCARD_MOUNT_AT_BOOT (0) +// FDCAN bus +#define MICROPY_HW_CAN1_NAME "FDCAN1" +#define MICROPY_HW_CAN1_TX (pin_H13) +#define MICROPY_HW_CAN1_RX (pin_B8) + // USB config #define MICROPY_HW_USB_HS (1) #define MICROPY_HW_USB_HS_ULPI_NXT (pin_H4) From a3f3b9045cd515022b13a96baf371d40e0f9faad Mon Sep 17 00:00:00 2001 From: Philipp Ebensberger Date: Mon, 18 Jul 2022 20:51:43 +0200 Subject: [PATCH 056/565] mimxrt/flash: Separate low level driver code from flash object. Separate low level flash access from mimxrt flash driver object. Allows better abstraction from hardware for testing and reuse in other areas (e.g. bootloader). Signed-off-by: Philipp Ebensberger --- ports/mimxrt/Makefile | 1 + ports/mimxrt/flash.c | 123 +++++++++++++++++++++++ ports/mimxrt/flash.h | 58 +++++++++++ ports/mimxrt/hal/flexspi_flash_config.h | 1 + ports/mimxrt/hal/flexspi_hyper_flash.c | 5 + ports/mimxrt/hal/flexspi_hyper_flash.h | 1 + ports/mimxrt/hal/flexspi_nor_flash.c | 31 ++++++ ports/mimxrt/hal/flexspi_nor_flash.h | 1 + ports/mimxrt/hal/qspi_nor_flash_config.c | 8 +- ports/mimxrt/mimxrt_flash.c | 83 ++------------- 10 files changed, 235 insertions(+), 77 deletions(-) create mode 100644 ports/mimxrt/flash.c create mode 100644 ports/mimxrt/flash.h diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index d9ab4c859b..dd053b3dc1 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -183,6 +183,7 @@ SRC_C += \ drivers/dht/dht.c \ eth.c \ fatfs_port.c \ + flash.c \ hal/pwm_backport.c \ led.c \ machine_adc.c \ diff --git a/ports/mimxrt/flash.c b/ports/mimxrt/flash.c new file mode 100644 index 0000000000..3a18f8f51b --- /dev/null +++ b/ports/mimxrt/flash.c @@ -0,0 +1,123 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Philipp Ebensberger + * + * 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 "flash.h" + +void flash_init(void) { + // Upload the custom flash configuration + // This should be performed by the boot ROM but for some reason it is not. + FLEXSPI_UpdateLUT(BOARD_FLEX_SPI, 0, + qspiflash_config.memConfig.lookupTable, + ARRAY_SIZE(qspiflash_config.memConfig.lookupTable)); + + // Configure FLEXSPI IP FIFO access. + BOARD_FLEX_SPI->MCR0 &= ~(FLEXSPI_MCR0_ARDFEN_MASK); + BOARD_FLEX_SPI->MCR0 &= ~(FLEXSPI_MCR0_ATDFEN_MASK); + BOARD_FLEX_SPI->MCR0 |= FLEXSPI_MCR0_ARDFEN(0); + BOARD_FLEX_SPI->MCR0 |= FLEXSPI_MCR0_ATDFEN(0); +} + +// flash_erase_block(erase_addr) +// erases the block starting at addr. Block size according to the flash properties. +__attribute__((section(".ram_functions"))) status_t flash_erase_block(uint32_t erase_addr) { + status_t status = kStatus_Fail; + + SCB_CleanInvalidateDCache(); + SCB_DisableDCache(); + __disable_irq(); + + status = flexspi_nor_flash_erase_block(BOARD_FLEX_SPI, erase_addr); + + __enable_irq(); + SCB_EnableDCache(); + + return status; +} + +// flash_erase_sector(erase_addr_bytes) +// erases the sector starting at addr. Sector size according to the flash properties. +__attribute__((section(".ram_functions"))) status_t flash_erase_sector(uint32_t erase_addr) { + status_t status = kStatus_Fail; + + SCB_CleanInvalidateDCache(); + SCB_DisableDCache(); + __disable_irq(); + + status = flexspi_nor_flash_erase_sector(BOARD_FLEX_SPI, erase_addr); + + __enable_irq(); + SCB_EnableDCache(); + + return status; +} + +// flash_write_block(flash_dest_addr_bytes, data_source, length_bytes) +// writes length_byte data to the destination address +// the vfs driver takes care for erasing the sector if required +__attribute__((section(".ram_functions"))) status_t flash_write_block(uint32_t dest_addr, const uint8_t *src, uint32_t length) { + status_t status = kStatus_Fail; + uint32_t write_length; + uint32_t next_addr; + + if (length == 0) { + status = kStatus_Success; // Nothing to do + } else { + + SCB_CleanInvalidateDCache(); + SCB_DisableDCache(); + + // write data in chunks not crossing a page boundary + do { + next_addr = dest_addr - (dest_addr % PAGE_SIZE_BYTES) + PAGE_SIZE_BYTES; // next page boundary + write_length = next_addr - dest_addr; // calculate write length based on destination address and subsequent page boundary. + if (write_length > length) { // compare possible write_length against remaining data length + write_length = length; + } + + __disable_irq(); + status = flexspi_nor_flash_page_program(BOARD_FLEX_SPI, dest_addr, (uint32_t *)src, write_length); + __enable_irq(); + + // Update remaining data length + length -= write_length; + + // Move source and destination pointer + src += write_length; + dest_addr += write_length; + } while ((length > 0) && (status == kStatus_Success)); + + SCB_EnableDCache(); + + } + return status; +} + +// flash_read_block(flash_src_addr_bytes, data_dest, length_bytes) +// read length_byte data to the source address +// It is just a shim to provide the same structure for read_block and write_block. +__attribute__((section(".ram_functions"))) void flash_read_block(uint32_t src_addr, uint8_t *dest, uint32_t length) { + memcpy(dest, (const uint8_t *)(BOARD_FLEX_SPI_ADDR_BASE + src_addr), length); +} diff --git a/ports/mimxrt/flash.h b/ports/mimxrt/flash.h new file mode 100644 index 0000000000..ad010767c8 --- /dev/null +++ b/ports/mimxrt/flash.h @@ -0,0 +1,58 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Philipp Ebensberger + * + * 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. + */ + +#ifndef MICROPY_INCLUDED_MIMXRT_FLASH_H +#define MICROPY_INCLUDED_MIMXRT_FLASH_H + +#include BOARD_FLASH_OPS_HEADER_H + +#define SECTOR_SIZE_BYTES (qspiflash_config.sectorSize) +#define PAGE_SIZE_BYTES (qspiflash_config.pageSize) +#define BLOCK_SIZE_BYTES (qspiflash_config.blockSize) + +#define SECTOR_SIZE_BYTES (qspiflash_config.sectorSize) +#define PAGE_SIZE_BYTES (qspiflash_config.pageSize) + +#ifndef MICROPY_HW_FLASH_STORAGE_BYTES +#define MICROPY_HW_FLASH_STORAGE_BYTES (((uint32_t)&__vfs_end) - ((uint32_t)&__vfs_start)) +#endif + +#ifndef MICROPY_HW_FLASH_STORAGE_BASE +#define MICROPY_HW_FLASH_STORAGE_BASE (((uint32_t)&__vfs_start) - ((uint32_t)&__flash_start)) +#endif + +// Linker symbols +extern uint8_t __vfs_start; +extern uint8_t __vfs_end; +extern uint8_t __flash_start; + +void flash_init(void); +status_t flash_erase_sector(uint32_t erase_addr); +status_t flash_erase_block(uint32_t erase_addr); +void flash_read_block(uint32_t src_addr, uint8_t *dest, uint32_t length); +status_t flash_write_block(uint32_t dest_addr, const uint8_t *src, uint32_t length); + +#endif // MICROPY_INCLUDED_MIMXRT_FLASH_H diff --git a/ports/mimxrt/hal/flexspi_flash_config.h b/ports/mimxrt/hal/flexspi_flash_config.h index 7eaf3192b5..5320231a14 100644 --- a/ports/mimxrt/hal/flexspi_flash_config.h +++ b/ports/mimxrt/hal/flexspi_flash_config.h @@ -222,6 +222,7 @@ typedef struct _FlexSPIConfig #define NOR_CMD_LUT_SEQ_IDX_ENTERQPI 10 #define NOR_CMD_LUT_SEQ_IDX_CHIPERASE 11 #define NOR_CMD_LUT_SEQ_IDX_EXITQPI 12 +#define NOR_CMD_LUT_SEQ_IDX_ERASEBLOCK 13 #define HYPERFLASH_CMD_LUT_SEQ_IDX_READDATA 0 #define HYPERFLASH_CMD_LUT_SEQ_IDX_WRITEDATA 1 diff --git a/ports/mimxrt/hal/flexspi_hyper_flash.c b/ports/mimxrt/hal/flexspi_hyper_flash.c index a9f17f2d1c..5e5d87166d 100644 --- a/ports/mimxrt/hal/flexspi_hyper_flash.c +++ b/ports/mimxrt/hal/flexspi_hyper_flash.c @@ -175,6 +175,11 @@ status_t flexspi_nor_flash_erase_sector(FLEXSPI_Type *base, uint32_t address) { return status; } +status_t flexspi_nor_flash_erase_block(FLEXSPI_Type *base, uint32_t address) __attribute__((section(".ram_functions"))); +status_t flexspi_nor_flash_erase_block(FLEXSPI_Type *base, uint32_t address) { + return flexspi_nor_flash_erase_sector(base, address); // HyperFlash does not support block erase! +} + status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t address, const uint32_t *src, uint32_t size) __attribute__((section(".ram_functions"))); status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t address, const uint32_t *src, uint32_t size) { status_t status; diff --git a/ports/mimxrt/hal/flexspi_hyper_flash.h b/ports/mimxrt/hal/flexspi_hyper_flash.h index 3c016bc78e..a6454a1c9a 100644 --- a/ports/mimxrt/hal/flexspi_hyper_flash.h +++ b/ports/mimxrt/hal/flexspi_hyper_flash.h @@ -49,6 +49,7 @@ status_t flexspi_nor_hyperflash_cfi(FLEXSPI_Type *base); void flexspi_hyper_flash_init(void); void flexspi_nor_update_lut(void); status_t flexspi_nor_flash_erase_sector(FLEXSPI_Type *base, uint32_t address); +status_t flexspi_nor_flash_erase_block(FLEXSPI_Type *base, uint32_t address); status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t address, const uint32_t *src, uint32_t size); static inline uint32_t flexspi_get_frequency(void) { diff --git a/ports/mimxrt/hal/flexspi_nor_flash.c b/ports/mimxrt/hal/flexspi_nor_flash.c index 48792ec487..956fb657db 100644 --- a/ports/mimxrt/hal/flexspi_nor_flash.c +++ b/ports/mimxrt/hal/flexspi_nor_flash.c @@ -165,6 +165,37 @@ status_t flexspi_nor_flash_erase_sector(FLEXSPI_Type *base, uint32_t address) { return status; } +status_t flexspi_nor_flash_erase_block(FLEXSPI_Type *base, uint32_t address) __attribute__((section(".ram_functions"))); +status_t flexspi_nor_flash_erase_block(FLEXSPI_Type *base, uint32_t address) { + status_t status; + flexspi_transfer_t flashXfer; + + /* Write enable */ + status = flexspi_nor_write_enable(base, address); + + if (status != kStatus_Success) { + return status; + } + + /* Erase sector */ + flashXfer.deviceAddress = address; + flashXfer.port = kFLEXSPI_PortA1; + flashXfer.cmdType = kFLEXSPI_Command; + flashXfer.SeqNumber = 1; + flashXfer.seqIndex = NOR_CMD_LUT_SEQ_IDX_ERASEBLOCK; + status = FLEXSPI_TransferBlocking(base, &flashXfer); + + if (status != kStatus_Success) { + return status; + } + + status = flexspi_nor_wait_bus_busy(base); + + flexspi_nor_reset(base); + + return status; +} + status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t dstAddr, const uint32_t *src, uint32_t size) __attribute__((section(".ram_functions"))); status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t dstAddr, const uint32_t *src, uint32_t size) { status_t status; diff --git a/ports/mimxrt/hal/flexspi_nor_flash.h b/ports/mimxrt/hal/flexspi_nor_flash.h index edc81e37f1..6526142af2 100644 --- a/ports/mimxrt/hal/flexspi_nor_flash.h +++ b/ports/mimxrt/hal/flexspi_nor_flash.h @@ -48,6 +48,7 @@ status_t flexspi_nor_get_vendor_id(FLEXSPI_Type *base, uint8_t *vendorId); status_t flexspi_nor_init(void); void flexspi_nor_update_lut(void); status_t flexspi_nor_flash_erase_sector(FLEXSPI_Type *base, uint32_t address); +status_t flexspi_nor_flash_erase_block(FLEXSPI_Type *base, uint32_t address); status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t address, const uint32_t *src, uint32_t size); #endif // MICROPY_INCLUDED_MIMXRT_HAL_FLEXSPI_NOR_FLASH_H diff --git a/ports/mimxrt/hal/qspi_nor_flash_config.c b/ports/mimxrt/hal/qspi_nor_flash_config.c index 469a584b87..a6bbd624ed 100644 --- a/ports/mimxrt/hal/qspi_nor_flash_config.c +++ b/ports/mimxrt/hal/qspi_nor_flash_config.c @@ -129,11 +129,17 @@ const flexspi_nor_config_t qspiflash_config = { FLEXSPI_LUT_SEQ(0, 0, 0, 0, 0, 0), // Filler FLEXSPI_LUT_SEQ(0, 0, 0, 0, 0, 0), // Filler FLEXSPI_LUT_SEQ(0, 0, 0, 0, 0, 0), // Filler + + // 13 Erase Block (32k) -> 13 + FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x52, RADDR_SDR, FLEXSPI_1PAD, 24), + FLEXSPI_LUT_SEQ(0, 0, 0, 0, 0, 0), // Filler + FLEXSPI_LUT_SEQ(0, 0, 0, 0, 0, 0), // Filler + FLEXSPI_LUT_SEQ(0, 0, 0, 0, 0, 0), // Filler }, }, .pageSize = 256u, .sectorSize = 4u * 1024u, - .blockSize = 64u * 1024u, + .blockSize = 32u * 1024u, .isUniformBlockSize = false, // .ipcmdSerialClkFreq = kFlexSpiSerialClk_30MHz, }; diff --git a/ports/mimxrt/mimxrt_flash.c b/ports/mimxrt/mimxrt_flash.c index 536fb60981..d229367e81 100644 --- a/ports/mimxrt/mimxrt_flash.c +++ b/ports/mimxrt/mimxrt_flash.c @@ -4,7 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2020-2021 Damien P. George - * Copyright (c) 2021 Philipp Ebensberger + * Copyright (c) 2021-2023 Philipp Ebensberger * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,23 +30,9 @@ #include "py/runtime.h" #include "extmod/vfs.h" #include "modmimxrt.h" +#include "flash.h" #include BOARD_FLASH_OPS_HEADER_H -#define SECTOR_SIZE_BYTES (qspiflash_config.sectorSize) -#define PAGE_SIZE_BYTES (qspiflash_config.pageSize) - -#ifndef MICROPY_HW_FLASH_STORAGE_BYTES -#define MICROPY_HW_FLASH_STORAGE_BYTES (((uint32_t)&__vfs_end) - ((uint32_t)&__vfs_start)) -#endif - -#ifndef MICROPY_HW_FLASH_STORAGE_BASE -#define MICROPY_HW_FLASH_STORAGE_BASE (((uint32_t)&__vfs_start) - ((uint32_t)&__flash_start)) -#endif - -// Linker symbols -extern uint8_t __vfs_start; -extern uint8_t __vfs_end; -extern uint8_t __flash_start; extern flexspi_nor_config_t qspiflash_config; @@ -60,67 +46,11 @@ STATIC mimxrt_flash_obj_t mimxrt_flash_obj = { .base = { &mimxrt_flash_type } }; -// flash_erase_block(erase_addr_bytes) -// erases the sector starting at addr. Sector size according to the flash properties. -status_t flash_erase_block(uint32_t erase_addr) __attribute__((section(".ram_functions"))); -status_t flash_erase_block(uint32_t erase_addr) { - status_t status; - SCB_CleanInvalidateDCache(); - SCB_DisableDCache(); - __disable_irq(); - status = flexspi_nor_flash_erase_sector(BOARD_FLEX_SPI, erase_addr); - __enable_irq(); - SCB_EnableDCache(); - return status; -} - -// flash_write_block(flash_dest_addr_bytes, data_source, length_bytes) -// writes length_byte data to the destination address -// the vfs driver takes care for erasing the sector if required -status_t flash_write_block(uint32_t dest_addr, const uint8_t *src, uint32_t length) __attribute__((section(".ram_functions"))); -status_t flash_write_block(uint32_t dest_addr, const uint8_t *src, uint32_t length) { - status_t status = 0; - uint32_t size; - uint32_t next_addr; - - SCB_CleanInvalidateDCache(); - SCB_DisableDCache(); - // write data in chunks not crossing a page boundary - while (length > 0) { - next_addr = dest_addr - (dest_addr % PAGE_SIZE_BYTES) + PAGE_SIZE_BYTES; // next page boundary - size = next_addr - dest_addr; // maximal chunk length - if (size > length) { // compare against remaining data size - size = length; - } - __disable_irq(); - status = flexspi_nor_flash_page_program(BOARD_FLEX_SPI, dest_addr, (uint32_t *)src, size); - __enable_irq(); - if (status != kStatus_Success) { - break; - } - length -= size; - src += size; - dest_addr += size; - } - SCB_EnableDCache(); - return status; -} - STATIC mp_obj_t mimxrt_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check args. mp_arg_check_num(n_args, n_kw, 0, 0, false); - // Upload the custom flash configuration - // This should be performed by the boot ROM but for some reason it is not. - FLEXSPI_UpdateLUT(BOARD_FLEX_SPI, 0, - qspiflash_config.memConfig.lookupTable, - ARRAY_SIZE(qspiflash_config.memConfig.lookupTable)); - - // Configure BOARD_FLEX_SPI IP FIFO access. - BOARD_FLEX_SPI->MCR0 &= ~(FLEXSPI_MCR0_ARDFEN_MASK); - BOARD_FLEX_SPI->MCR0 &= ~(FLEXSPI_MCR0_ATDFEN_MASK); - BOARD_FLEX_SPI->MCR0 |= FLEXSPI_MCR0_ARDFEN(0); - BOARD_FLEX_SPI->MCR0 |= FLEXSPI_MCR0_ATDFEN(0); + flash_init(); // Update information based on linker symbols. mimxrt_flash_obj.flash_base = MICROPY_HW_FLASH_STORAGE_BASE; @@ -142,7 +72,8 @@ STATIC mp_obj_t mimxrt_flash_readblocks(size_t n_args, const mp_obj_t *args) { if (n_args == 4) { offset += mp_obj_get_int(args[3]); } - memcpy(bufinfo.buf, (uint8_t *)(BOARD_FLEX_SPI_ADDR_BASE + self->flash_base + offset), bufinfo.len); + + flash_read_block((self->flash_base + offset), (uint8_t *)bufinfo.buf, (uint32_t)bufinfo.len); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mimxrt_flash_readblocks_obj, 3, 4, mimxrt_flash_readblocks); @@ -161,7 +92,7 @@ STATIC mp_obj_t mimxrt_flash_writeblocks(size_t n_args, const mp_obj_t *args) { uint32_t offset = mp_obj_get_int(args[1]) * SECTOR_SIZE_BYTES; if (n_args == 3) { - status = flash_erase_block(self->flash_base + offset); + status = flash_erase_sector(self->flash_base + offset); if (status != kStatus_Success) { mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("flash erase command failed with %d"), status); @@ -199,7 +130,7 @@ STATIC mp_obj_t mimxrt_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t a return MP_OBJ_NEW_SMALL_INT(SECTOR_SIZE_BYTES); case MP_BLOCKDEV_IOCTL_BLOCK_ERASE: { uint32_t offset = mp_obj_get_int(arg_in) * SECTOR_SIZE_BYTES; - status = flash_erase_block(self->flash_base + offset); + status = flash_erase_sector(self->flash_base + offset); return MP_OBJ_NEW_SMALL_INT(status != kStatus_Success); } default: From facc51f3ea6acc83fcc54effe5d4826ef07f4e4f Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 21 Apr 2023 14:51:21 +0200 Subject: [PATCH 057/565] mimxrt/mpconfigport: Add back lost uos.urandom(). It got lost in a clean-up session recently. --- ports/mimxrt/mpconfigport.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 1dd7711efe..f4732da397 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -77,6 +77,7 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_OS_DUPTERM (3) #define MICROPY_PY_UOS_DUPTERM_NOTIFY (1) #define MICROPY_PY_UOS_UNAME (1) +#define MICROPY_PY_UOS_URANDOM (1) #define MICROPY_PY_URANDOM_SEED_INIT_FUNC (trng_random_u32()) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new From d2a02dcee3ae4d3bc4d29629264cbee9501d1c05 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 30 Apr 2023 15:44:04 +0200 Subject: [PATCH 058/565] mimxrt: Add missing UART defintion and remove obsolete config. Changes in this commit: - Add a missing UART defintion for MIMXRT1010_EVK. - Remove an obsolete line from mpconfigport.h. --- ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h | 2 +- ports/mimxrt/mpconfigport.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h index 73055526a0..eff9e9c2cd 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h @@ -20,7 +20,7 @@ #define IOMUX_TABLE_UART \ { IOMUXC_GPIO_10_LPUART1_TXD }, { IOMUXC_GPIO_09_LPUART1_RXD }, \ { 0 }, { 0 }, \ - { 0 }, { 0 }, \ + { IOMUXC_GPIO_08_LPUART3_TXD }, { IOMUXC_GPIO_AD_07_LPUART3_RXD }, \ { IOMUXC_GPIO_AD_02_LPUART4_TXD }, { IOMUXC_GPIO_AD_01_LPUART4_RXD }, #define MICROPY_HW_SPI_INDEX { 1 } diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index f4732da397..4482e54960 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -182,8 +182,6 @@ extern const struct _mp_obj_type_t network_lan_type; MICROPY_HW_NIC_ETH \ MICROPY_BOARD_NETWORK_INTERFACES \ -#define MICROPY_HW_PIT_NUM_CHANNELS 3 - #ifndef MICROPY_BOARD_ROOT_POINTERS #define MICROPY_BOARD_ROOT_POINTERS #endif From 14b862f70fdf61cf4040d99439f59f0d0aa925b0 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 30 Apr 2023 13:29:56 +0200 Subject: [PATCH 059/565] mimxrt/machine_spi: Ignore transfers with len=0. It was treated as an error before. The error surfaced when using the NINAW10 drivers for WiFi support. Even if this is a bad behavior of the NINA driver, machine_spi can be forgiving in that situation. --- ports/mimxrt/machine_spi.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ports/mimxrt/machine_spi.c b/ports/mimxrt/machine_spi.c index d6aff2a329..bafe94b970 100644 --- a/ports/mimxrt/machine_spi.c +++ b/ports/mimxrt/machine_spi.c @@ -240,17 +240,19 @@ STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { machine_spi_obj_t *self = (machine_spi_obj_t *)self_in; - // Wait a short while for the previous transfer to finish, but not forever - for (volatile int j = 0; (j < 5000) && ((self->spi_inst->SR & kLPSPI_ModuleBusyFlag) != 0); j++) {} + if (len > 0) { + // Wait a short while for the previous transfer to finish, but not forever + for (volatile int j = 0; (j < 5000) && ((self->spi_inst->SR & kLPSPI_ModuleBusyFlag) != 0); j++) {} - lpspi_transfer_t masterXfer; - masterXfer.txData = (uint8_t *)src; - masterXfer.rxData = (uint8_t *)dest; - masterXfer.dataSize = len; - masterXfer.configFlags = (self->master_config->whichPcs << LPSPI_MASTER_PCS_SHIFT) | kLPSPI_MasterPcsContinuous | kLPSPI_MasterByteSwap; + lpspi_transfer_t masterXfer; + masterXfer.txData = (uint8_t *)src; + masterXfer.rxData = (uint8_t *)dest; + masterXfer.dataSize = len; + masterXfer.configFlags = (self->master_config->whichPcs << LPSPI_MASTER_PCS_SHIFT) | kLPSPI_MasterPcsContinuous | kLPSPI_MasterByteSwap; - if (LPSPI_MasterTransferBlocking(self->spi_inst, &masterXfer) != kStatus_Success) { - mp_raise_OSError(EIO); + if (LPSPI_MasterTransferBlocking(self->spi_inst, &masterXfer) != kStatus_Success) { + mp_raise_OSError(EIO); + } } } From 65d376b11d8087ba07df503669cc5292d4f1d0e2 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 6 May 2023 15:31:43 +0200 Subject: [PATCH 060/565] mimxrt/machine_pin: Perform full configuration in machine_pin_set_mode. machine_pin_set_mode() is used by the internal mp_hal_pin_xxx() set of functions to configure pins. --- ports/mimxrt/machine_pin.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ports/mimxrt/machine_pin.c b/ports/mimxrt/machine_pin.c index d44e649964..f005e38d69 100644 --- a/ports/mimxrt/machine_pin.c +++ b/ports/mimxrt/machine_pin.c @@ -174,15 +174,17 @@ void machine_pin_irq_deinit(void) { // Simplified mode setting used by the extmod modules void machine_pin_set_mode(const machine_pin_obj_t *self, uint8_t mode) { gpio_pin_config_t pin_config = {kGPIO_DigitalInput, 1, kGPIO_NoIntmode}; + uint32_t pad_config; pin_config.direction = (mode == PIN_MODE_IN ? kGPIO_DigitalInput : kGPIO_DigitalOutput); - GPIO_PinInit(self->gpio, self->pin, &pin_config); if (mode == PIN_MODE_OPEN_DRAIN) { - uint32_t pad_config = *(uint32_t *)self->configRegister; - pad_config |= IOMUXC_SW_PAD_CTL_PAD_ODE(0b1) | IOMUXC_SW_PAD_CTL_PAD_DSE(0b110); - IOMUXC_SetPinMux(self->muxRegister, PIN_AF_MODE_ALT5, 0, 0, self->configRegister, 1U); // Software Input On Field: Input Path is determined by functionality - IOMUXC_SetPinConfig(self->muxRegister, PIN_AF_MODE_ALT5, 0, 0, self->configRegister, pad_config); + pad_config = pin_generate_config(PIN_PULL_UP_22K, mode, PIN_DRIVE_3, self->configRegister); + } else { + pad_config = pin_generate_config(PIN_PULL_DISABLED, mode, PIN_DRIVE_3, self->configRegister); } + IOMUXC_SetPinConfig(self->muxRegister, PIN_AF_MODE_ALT5, 0, 0, self->configRegister, pad_config); + IOMUXC_SetPinMux(self->muxRegister, PIN_AF_MODE_ALT5, 0, 0, self->configRegister, 1U); + GPIO_PinInit(self->gpio, self->pin, &pin_config); } STATIC mp_obj_t machine_pin_obj_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { From a000c61d5d6933b9750413de434ac664254eca2b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 2 May 2023 16:12:36 +0200 Subject: [PATCH 061/565] tools/pyboard.py: Import errno to fix undefined name in PyboardError. This will keep line 96 from raising a NameError. Signed-off-by: Christian Clauss --- tools/pyboard.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/pyboard.py b/tools/pyboard.py index c5c12c95b7..7b546b99d1 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -68,6 +68,7 @@ Or: """ import ast +import errno import os import struct import sys From 4e4bdbd191eb00ef42d9bd6fe9a8303a16f6878d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 2 May 2023 10:39:44 +0200 Subject: [PATCH 062/565] top: Add ruff to pre-commit. This does not align with the other pre-commit jobs with are local custom code but it should run accurately and quickly. Signed-off-by: Christian Clauss --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 12f3d79c93..e9815a4b2e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,7 @@ repos: language: python verbose: true stages: [commit-msg] + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.265 + hooks: + - id: ruff From 3e64d76122b8adf33d59b0d9858beb38f8e7d87c Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 1 May 2023 11:07:47 -0500 Subject: [PATCH 063/565] docs/reference/mpyfiles: Add release info on v6.1. This documents when MPY v6.1 was released. Also add some clarification on how the version is encoded in the header. Signed-off-by: David Lechner --- docs/reference/mpyfiles.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/reference/mpyfiles.rst b/docs/reference/mpyfiles.rst index d93a86383e..1588eda570 100644 --- a/docs/reference/mpyfiles.rst +++ b/docs/reference/mpyfiles.rst @@ -86,7 +86,8 @@ and .mpy version. =================== ============ MicroPython release .mpy version =================== ============ -v1.19 and up 6 +v1.20 and up 6.1 +v1.19.x 6 v1.12 - v1.18 5 v1.11 4 v1.9.3 - v1.10 3 @@ -100,6 +101,7 @@ MicroPython repository at which the .mpy version was changed. =================== ======================================== .mpy version change Git commit =================== ======================================== +6 to 6.1 d94141e1473aebae0d3c63aeaa8397651ad6fa01 5 to 6 f2040bfc7ee033e48acef9f289790f3b4e6b74e5 4 to 5 5716c5cf65e9b2cb46c2906f40302401bdd27517 3 to 4 9a5f92ea72754c01cc03e5efcdfe94021120531e @@ -146,8 +148,8 @@ The .mpy header is: size field ====== ================================ byte value 0x4d (ASCII 'M') -byte .mpy version number -byte feature flags +byte .mpy major version number +byte native arch and minor version number (was feature flags in older versions) byte number of bits in a small int ====== ================================ From 6836acf3dc6b9301693b1cf8875240aee04360ff Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 9 May 2023 09:32:14 -0500 Subject: [PATCH 064/565] unix/Makefile: Allow variants to add QSTR_DEFS. This modifies the unix port Makefile to use += for QSTR_DEFS and QSTR_GLOBAL_DEPENDENCIES so that variants can add additional files if needed (similar to stm32 port). Signed-off-by: David Lechner --- ports/unix/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index d2af8b0871..0ff2e4b6e8 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -27,8 +27,8 @@ FROZEN_MANIFEST ?= variants/manifest.py PROG ?= micropython # qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h -QSTR_GLOBAL_DEPENDENCIES = $(VARIANT_DIR)/mpconfigvariant.h +QSTR_DEFS += qstrdefsport.h +QSTR_GLOBAL_DEPENDENCIES += $(VARIANT_DIR)/mpconfigvariant.h # OS name, for simple autoconfig UNAME_S := $(shell uname -s) From 6a4a9bc147f3a9dfeb8d603a6c137b63c1bf2cf0 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 9 May 2023 09:34:20 -0500 Subject: [PATCH 065/565] windows/Makefile: Allow variants to add QSTR_DEFS. This modifies the windows port Makefile to use += for QSTR_DEFS and QSTR_GLOBAL_DEPENDENCIES so that variants can add additional files if needed (similar to stm32 port). Signed-off-by: David Lechner --- ports/windows/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/windows/Makefile b/ports/windows/Makefile index 489ba15c64..7753fa25d4 100644 --- a/ports/windows/Makefile +++ b/ports/windows/Makefile @@ -26,8 +26,8 @@ FROZEN_MANIFEST ?= variants/manifest.py PROG ?= micropython # qstr definitions (must come before including py.mk) -QSTR_DEFS = ../unix/qstrdefsport.h -QSTR_GLOBAL_DEPENDENCIES = $(VARIANT_DIR)/mpconfigvariant.h +QSTR_DEFS += ../unix/qstrdefsport.h +QSTR_GLOBAL_DEPENDENCIES += $(VARIANT_DIR)/mpconfigvariant.h # include py core make definitions include $(TOP)/py/py.mk From 0c58e290743f41f49793201713d41ab7dd36bb63 Mon Sep 17 00:00:00 2001 From: Takeo Takahashi Date: Mon, 1 May 2023 20:16:02 +0900 Subject: [PATCH 066/565] lib/fsp: Update FSP for renesas-ra to the latest version v4.4.0. Signed-off-by: Takeo Takahashi --- lib/fsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fsp b/lib/fsp index 55bffd3a71..e78939d32d 160000 --- a/lib/fsp +++ b/lib/fsp @@ -1 +1 @@ -Subproject commit 55bffd3a71cbeed2104cf30e7a39b641d8c1ff48 +Subproject commit e78939d32d1ccea9f0ba8bb42c51aceffd386b9b From b4834e5cba70a620265b81e74521665d863cf597 Mon Sep 17 00:00:00 2001 From: Takeo Takahashi Date: Mon, 1 May 2023 22:48:52 +0900 Subject: [PATCH 067/565] renesas-ra: Update boards and ra directory files to support FSP v4.4.0. * Update boards and ra files * Remove unreferenced files, board_init.c and board_leds.c, from Makefile * Remove unreferenced FSP instances from ra_gen/*.[ch] * Remove unreferenced FSP config files ra_cfg/*.h * e2 studio generates FSP instances but renesas-ra uses only followings: lpm, flash, ioport Signed-off-by: Takeo Takahashi --- ports/renesas-ra/Makefile | 5 - .../EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 21 +- .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 1 + .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 13 +- .../EK_RA4M1/ra_cfg/fsp_cfg/r_adc_cfg.h | 8 + .../EK_RA4M1/ra_cfg/fsp_cfg/r_agt_cfg.h | 7 - .../EK_RA4M1/ra_cfg/fsp_cfg/r_dtc_cfg.h | 6 - .../EK_RA4M1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h | 8 + .../EK_RA4M1/ra_cfg/fsp_cfg/r_icu_cfg.h | 5 - .../EK_RA4M1/ra_cfg/fsp_cfg/r_ioport_cfg.h | 8 + .../EK_RA4M1/ra_cfg/fsp_cfg/r_lpm_cfg.h | 9 + .../EK_RA4M1/ra_cfg/fsp_cfg/r_rtc_cfg.h | 5 - .../EK_RA4M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 8 - .../EK_RA4M1/ra_cfg/fsp_cfg/r_spi_cfg.h | 7 - .../boards/EK_RA4M1/ra_gen/bsp_clock_cfg.h | 2 +- .../boards/EK_RA4M1/ra_gen/common_data.c | 2 - .../boards/EK_RA4M1/ra_gen/common_data.h | 4 +- .../boards/EK_RA4M1/ra_gen/hal_data.c | 453 +-------- .../boards/EK_RA4M1/ra_gen/hal_data.h | 123 +-- .../boards/EK_RA4M1/ra_gen/pin_data.c | 188 ++-- .../boards/EK_RA4M1/ra_gen/vector_data.c | 46 +- .../boards/EK_RA4M1/ra_gen/vector_data.h | 62 +- .../EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 21 +- .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 1 + .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 13 +- .../EK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h | 8 + .../EK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h | 7 - .../EK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h | 6 - .../EK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h | 8 + .../EK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h | 5 - .../ra_cfg/fsp_cfg/r_iic_master_cfg.h | 7 - .../EK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h | 8 + .../EK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h | 9 + .../EK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h | 5 - .../EK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 8 - .../EK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h | 7 - .../boards/EK_RA4W1/ra_gen/bsp_clock_cfg.h | 4 +- .../boards/EK_RA4W1/ra_gen/common_data.c | 2 - .../boards/EK_RA4W1/ra_gen/common_data.h | 5 +- .../boards/EK_RA4W1/ra_gen/hal_data.c | 605 +---------- .../boards/EK_RA4W1/ra_gen/hal_data.h | 185 +--- .../boards/EK_RA4W1/ra_gen/pin_data.c | 135 +-- .../boards/EK_RA4W1/ra_gen/vector_data.c | 80 +- .../boards/EK_RA4W1/ra_gen/vector_data.h | 80 +- .../EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 21 +- .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 1 + .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 13 +- .../EK_RA6M1/ra_cfg/fsp_cfg/r_adc_cfg.h | 8 + .../EK_RA6M1/ra_cfg/fsp_cfg/r_agt_cfg.h | 7 - .../EK_RA6M1/ra_cfg/fsp_cfg/r_dtc_cfg.h | 6 - .../EK_RA6M1/ra_cfg/fsp_cfg/r_flash_hp_cfg.h | 8 + .../EK_RA6M1/ra_cfg/fsp_cfg/r_icu_cfg.h | 5 - .../ra_cfg/fsp_cfg/r_iic_master_cfg.h | 7 - .../EK_RA6M1/ra_cfg/fsp_cfg/r_ioport_cfg.h | 8 + .../EK_RA6M1/ra_cfg/fsp_cfg/r_lpm_cfg.h | 9 + .../EK_RA6M1/ra_cfg/fsp_cfg/r_rtc_cfg.h | 5 - .../EK_RA6M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 8 - .../EK_RA6M1/ra_cfg/fsp_cfg/r_spi_cfg.h | 7 - .../boards/EK_RA6M1/ra_gen/bsp_clock_cfg.h | 4 +- .../boards/EK_RA6M1/ra_gen/common_data.c | 3 - .../boards/EK_RA6M1/ra_gen/common_data.h | 4 +- .../boards/EK_RA6M1/ra_gen/hal_data.c | 810 +-------------- .../boards/EK_RA6M1/ra_gen/hal_data.h | 286 +----- .../boards/EK_RA6M1/ra_gen/pin_data.c | 193 ++-- .../boards/EK_RA6M1/ra_gen/vector_data.c | 118 +-- .../boards/EK_RA6M1/ra_gen/vector_data.h | 98 +- .../EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 21 +- .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 1 + .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 13 +- .../EK_RA6M2/ra_cfg/fsp_cfg/r_adc_cfg.h | 8 + .../EK_RA6M2/ra_cfg/fsp_cfg/r_agt_cfg.h | 7 - .../EK_RA6M2/ra_cfg/fsp_cfg/r_dtc_cfg.h | 6 - .../EK_RA6M2/ra_cfg/fsp_cfg/r_flash_hp_cfg.h | 8 + .../EK_RA6M2/ra_cfg/fsp_cfg/r_icu_cfg.h | 5 - .../ra_cfg/fsp_cfg/r_iic_master_cfg.h | 7 - .../EK_RA6M2/ra_cfg/fsp_cfg/r_ioport_cfg.h | 8 + .../EK_RA6M2/ra_cfg/fsp_cfg/r_lpm_cfg.h | 9 + .../EK_RA6M2/ra_cfg/fsp_cfg/r_rtc_cfg.h | 5 - .../EK_RA6M2/ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 8 - .../EK_RA6M2/ra_cfg/fsp_cfg/r_spi_cfg.h | 7 - .../boards/EK_RA6M2/ra_gen/bsp_clock_cfg.h | 6 +- .../boards/EK_RA6M2/ra_gen/common_data.c | 4 +- .../boards/EK_RA6M2/ra_gen/common_data.h | 5 +- .../boards/EK_RA6M2/ra_gen/hal_data.c | 959 +----------------- .../boards/EK_RA6M2/ra_gen/hal_data.h | 345 ------- .../boards/EK_RA6M2/ra_gen/pin_data.c | 206 ++-- .../boards/EK_RA6M2/ra_gen/vector_data.c | 136 +-- .../boards/EK_RA6M2/ra_gen/vector_data.h | 108 +- .../ra_cfg/fsp_cfg/bsp/board_cfg.h | 8 + .../ra_cfg/fsp_cfg/bsp/bsp_cfg.h | 21 +- .../fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h | 1 + .../ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h | 13 +- .../RA4M1_CLICKER/ra_cfg/fsp_cfg/r_adc_cfg.h | 8 + .../RA4M1_CLICKER/ra_cfg/fsp_cfg/r_agt_cfg.h | 7 - .../RA4M1_CLICKER/ra_cfg/fsp_cfg/r_dtc_cfg.h | 6 - .../ra_cfg/fsp_cfg/r_flash_lp_cfg.h | 8 + .../RA4M1_CLICKER/ra_cfg/fsp_cfg/r_icu_cfg.h | 5 - .../ra_cfg/fsp_cfg/r_iic_master_cfg.h | 7 - .../ra_cfg/fsp_cfg/r_ioport_cfg.h | 8 + .../RA4M1_CLICKER/ra_cfg/fsp_cfg/r_lpm_cfg.h | 9 + .../RA4M1_CLICKER/ra_cfg/fsp_cfg/r_rtc_cfg.h | 5 - .../ra_cfg/fsp_cfg/r_sci_uart_cfg.h | 8 - .../RA4M1_CLICKER/ra_cfg/fsp_cfg/r_spi_cfg.h | 7 - .../RA4M1_CLICKER/ra_gen/bsp_clock_cfg.h | 2 +- .../boards/RA4M1_CLICKER/ra_gen/common_data.c | 1 - .../boards/RA4M1_CLICKER/ra_gen/common_data.h | 3 +- .../boards/RA4M1_CLICKER/ra_gen/hal_data.c | 468 +-------- .../boards/RA4M1_CLICKER/ra_gen/hal_data.h | 146 --- .../boards/RA4M1_CLICKER/ra_gen/pin_data.c | 141 +-- .../boards/RA4M1_CLICKER/ra_gen/vector_data.c | 60 +- .../boards/RA4M1_CLICKER/ra_gen/vector_data.h | 66 +- ports/renesas-ra/ra/ra_timer.c | 24 +- ports/renesas-ra/ra/ra_utils.c | 2 +- ports/renesas-ra/ra/ra_utils.h | 75 +- 114 files changed, 1331 insertions(+), 5489 deletions(-) delete mode 100644 ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_agt_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_dtc_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_icu_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_rtc_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_spi_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_agt_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_dtc_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_icu_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_iic_master_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_rtc_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_spi_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_agt_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_dtc_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_icu_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_iic_master_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_rtc_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_sci_uart_cfg.h delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_spi_cfg.h delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_agt_cfg.h delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_dtc_cfg.h delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_icu_cfg.h delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_iic_master_cfg.h delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_rtc_cfg.h delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_sci_uart_cfg.h delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_spi_cfg.h diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index 8dd172b50c..bcfae8555e 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -342,11 +342,6 @@ SRC_O += \ SRC_O += \ shared/runtime/gchelper_thumb2.o -HAL_SRC_C += $(addprefix $(HAL_DIR)/ra/board/$(BOARD_LOW)/,\ - board_init.c \ - board_leds.c \ - ) - HAL_SRC_C += $(addprefix $(HAL_DIR)/ra/fsp/src/bsp/mcu/all/,\ bsp_clocks.c \ bsp_common.c \ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h index 9940d7ed3b..e341e99942 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_CFG_H_ #define BSP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_clock_cfg.h" #include "bsp_mcu_family_cfg.h" #include "board_cfg.h" @@ -14,7 +18,13 @@ #define BSP_CFG_RTOS (0) #endif #endif +#ifndef BSP_CFG_RTC_USED +#define BSP_CFG_RTC_USED (1) +#endif #undef RA_NOT_DEFINED +#if defined(_RA_BOOT_IMAGE) +#define BSP_CFG_BOOT_IMAGE (1) +#endif #define BSP_CFG_MCU_VCC_MV (3300) #define BSP_CFG_STACK_MAIN_BYTES (0x1000) #define BSP_CFG_HEAP_BYTES (0x4980) @@ -25,15 +35,14 @@ #define BSP_CFG_PFS_PROTECT ((1)) #define BSP_CFG_C_RUNTIME_INIT ((1)) +#define BSP_CFG_EARLY_INIT ((0)) -#define BSP_CFG_SOFT_RESET_SUPPORTED ((0)) +#define BSP_CFG_STARTUP_CLOCK_REG_NOT_RESET ((0)) #ifndef BSP_CLOCK_CFG_MAIN_OSC_POPULATED #define BSP_CLOCK_CFG_MAIN_OSC_POPULATED (1) #endif -#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT -#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) -#endif + #ifndef BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE #define BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE (0) #endif @@ -46,4 +55,8 @@ #ifndef BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS #define BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS 1000 #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h index f52adbafae..d810dabb2f 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h @@ -2,6 +2,7 @@ #ifndef BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_R7FA4M1AB3CFP +#define BSP_MCU_FEATURE_SET ('A') #define BSP_ROM_SIZE_BYTES (262144) #define BSP_RAM_SIZE_BYTES (32768) #define BSP_DATA_FLASH_SIZE_BYTES (8192) diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h index 4766823b35..a9b4de20c0 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_MCU_FAMILY_CFG_H_ #define BSP_MCU_FAMILY_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_mcu_device_pn_cfg.h" #include "bsp_mcu_device_cfg.h" #include "../../../ra/fsp/src/bsp/mcu/ra4m1/bsp_mcu_info.h" @@ -22,7 +26,6 @@ #endif #define BSP_CORTEX_VECTOR_TABLE_ENTRIES (16U) #define BSP_VECTOR_TABLE_MAX_ENTRIES (48U) -#define BSP_MCU_VBATT_SUPPORT (1) #define OFS_SEQ1 0xA001A001 | (1 << 1) | (3 << 2) #define OFS_SEQ2 (15 << 4) | (3 << 8) | (3 << 10) @@ -50,7 +53,9 @@ #define BSP_CFG_ROM_REG_MPU_REGION3_ENABLE (1) #define BSP_CFG_ROM_REG_MPU_REGION3_START (0x400DFFFC) #define BSP_CFG_ROM_REG_MPU_REGION3_END (0x400DFFFF) - +#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT +#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) +#endif /* Used to create IELS values for the interrupt initialization table g_interrupt_event_link_select. */ #define BSP_PRV_IELS_ENUM(vector) (ELC_##vector) @@ -71,4 +76,8 @@ #define BSP_CFG_ID_CODE_LONG_3 (0xFFFFFFFF) #define BSP_CFG_ID_CODE_LONG_4 (0xffFFFFFF) #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_MCU_FAMILY_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_adc_cfg.h index 9c59889ca8..be8a427206 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_adc_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_adc_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_ADC_CFG_H_ #define R_ADC_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define ADC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_ADC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_agt_cfg.h deleted file mode 100644 index d3ab559238..0000000000 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_agt_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_AGT_CFG_H_ -#define R_AGT_CFG_H_ -#define AGT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define AGT_CFG_OUTPUT_SUPPORT_ENABLE (0) -#define AGT_CFG_INPUT_SUPPORT_ENABLE (0) -#endif /* R_AGT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_dtc_cfg.h deleted file mode 100644 index 21405f9674..0000000000 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_dtc_cfg.h +++ /dev/null @@ -1,6 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_DTC_CFG_H_ -#define R_DTC_CFG_H_ -#define DTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define DTC_CFG_VECTOR_TABLE_SECTION_NAME ".fsp_dtc_vector_table" -#endif /* R_DTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h index 26879f9f4e..7f285caced 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h @@ -1,7 +1,15 @@ /* generated configuration header file - do not edit */ #ifndef R_FLASH_LP_CFG_H_ #define R_FLASH_LP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define FLASH_LP_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) #define FLASH_LP_CFG_CODE_FLASH_PROGRAMMING_ENABLE (1) #define FLASH_LP_CFG_DATA_FLASH_PROGRAMMING_ENABLE (0) + +#ifdef __cplusplus +} +#endif #endif /* R_FLASH_LP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_icu_cfg.h deleted file mode 100644 index 5e77b6980f..0000000000 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_icu_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_ICU_CFG_H_ -#define R_ICU_CFG_H_ -#define ICU_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_ICU_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_ioport_cfg.h index 6b4353d238..d2688bf5ba 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_ioport_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_ioport_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_IOPORT_CFG_H_ #define R_IOPORT_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define IOPORT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_IOPORT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_lpm_cfg.h index 5f4d5c4a73..6712eee6a1 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_lpm_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_lpm_cfg.h @@ -1,5 +1,14 @@ /* generated configuration header file - do not edit */ #ifndef R_LPM_CFG_H_ #define R_LPM_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define LPM_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define LPM_CFG_STANDBY_LIMIT (0) + +#ifdef __cplusplus +} +#endif #endif /* R_LPM_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_rtc_cfg.h deleted file mode 100644 index 484b7ed044..0000000000 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_rtc_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_RTC_CFG_H_ -#define R_RTC_CFG_H_ -#define RTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_RTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h deleted file mode 100644 index c70c0be344..0000000000 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h +++ /dev/null @@ -1,8 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SCI_UART_CFG_H_ -#define R_SCI_UART_CFG_H_ -#define SCI_UART_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SCI_UART_CFG_FIFO_SUPPORT (0) -#define SCI_UART_CFG_DTC_SUPPORTED (0) -#define SCI_UART_CFG_FLOW_CONTROL_SUPPORT (0) -#endif /* R_SCI_UART_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_spi_cfg.h deleted file mode 100644 index 861fe12194..0000000000 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_cfg/fsp_cfg/r_spi_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SPI_CFG_H_ -#define R_SPI_CFG_H_ -#define SPI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SPI_DTC_SUPPORT_ENABLE (1) -#define SPI_TRANSMIT_FROM_RXI_ISR (0) -#endif /* R_SPI_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/bsp_clock_cfg.h index cf28c33d7a..5f407b90f4 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/bsp_clock_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/bsp_clock_cfg.h @@ -7,7 +7,7 @@ #define BSP_CFG_PLL_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_MAIN_OSC) /* PLL Src: XTAL */ #define BSP_CFG_HOCO_FREQUENCY (0) /* HOCO 24MHz */ #define BSP_CFG_PLL_DIV (BSP_CLOCKS_PLL_DIV_2) /* PLL Div /2 */ -#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL_8_0 /* PLL Mul x8 */ +#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL(8U, 0U) /* PLL Mul x8 */ #define BSP_CFG_CLOCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_PLL) /* Clock Src: PLL */ #define BSP_CFG_ICLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* ICLK Div /1 */ #define BSP_CFG_PCLKA_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* PCLKA Div /1 */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.c index 34aad762ff..fb539ac4ac 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.c +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.c @@ -3,5 +3,3 @@ ioport_instance_ctrl_t g_ioport_ctrl; const ioport_instance_t g_ioport = { .p_api = &g_ioport_on_ioport, .p_ctrl = &g_ioport_ctrl, .p_cfg = &g_bsp_pin_cfg, }; -void g_common_init(void) { -} diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.h index e2eb70836b..3a764eda7b 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/common_data.h @@ -3,14 +3,16 @@ #define COMMON_DATA_H_ #include #include "bsp_api.h" +#include "r_icu.h" +#include "r_external_irq_api.h" #include "r_ioport.h" #include "bsp_pin_cfg.h" FSP_HEADER + /* IOPORT Instance */ extern const ioport_instance_t g_ioport; /* IOPORT control structure. */ extern ioport_instance_ctrl_t g_ioport_ctrl; -void g_common_init(void); FSP_FOOTER #endif /* COMMON_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.c index cfaa1abd0e..19c94dde25 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.c +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.c @@ -1,52 +1,15 @@ -/* generated HAL source file - do not edit */ #include "hal_data.h" -/* Macros to tie dynamic ELC links to ADC_TRIGGER_SYNC_ELC option in adc_trigger_t. */ -#define ADC_TRIGGER_ADC0 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC0_B ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1_B ADC_TRIGGER_SYNC_ELC -adc_instance_ctrl_t g_adc0_ctrl; -const adc_extended_cfg_t g_adc0_cfg_extend = -{ .add_average_count = ADC_ADD_OFF, - .clearing = ADC_CLEAR_AFTER_READ_ON, - .trigger_group_b = ADC_TRIGGER_SYNC_ELC, - .double_trigger_mode = ADC_DOUBLE_TRIGGER_DISABLED, - .adc_vref_control = ADC_VREF_CONTROL_VREFH, }; -const adc_cfg_t g_adc0_cfg = -{ .unit = 0, .mode = ADC_MODE_SINGLE_SCAN, .resolution = ADC_RESOLUTION_14_BIT, .alignment = - (adc_alignment_t)ADC_ALIGNMENT_RIGHT, - .trigger = ADC_TRIGGER_SOFTWARE, .p_callback = NULL, .p_context = NULL, .p_extend = &g_adc0_cfg_extend, - #if defined(VECTOR_NUMBER_ADC0_SCAN_END) - .scan_end_irq = VECTOR_NUMBER_ADC0_SCAN_END, - #else - .scan_end_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_ipl = (BSP_IRQ_DISABLED), - #if defined(VECTOR_NUMBER_ADC0_SCAN_END_B) - .scan_end_b_irq = VECTOR_NUMBER_ADC0_SCAN_END_B, - #else - .scan_end_b_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; -const adc_channel_cfg_t g_adc0_channel_cfg = -{ .scan_mask = 0, - .scan_mask_group_b = 0, - .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, - .add_mask = 0, - .sample_hold_mask = 0, - .sample_hold_states = 24, }; -/* Instance structure to use this module. */ -const adc_instance_t g_adc0 = -{ .p_ctrl = &g_adc0_ctrl, .p_cfg = &g_adc0_cfg, .p_channel_cfg = &g_adc0_channel_cfg, .p_api = &g_adc_on_adc }; lpm_instance_ctrl_t g_lpm0_ctrl; const lpm_cfg_t g_lpm0_cfg = -{ .low_power_mode = LPM_MODE_SLEEP, +{ .low_power_mode = LPM_MODE_SLEEP, .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM + | (lpm_standby_wake_source_t)0, + #if BSP_FEATURE_LPM_HAS_SNOOZE .snooze_cancel_sources = LPM_SNOOZE_CANCEL_SOURCE_NONE, - .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM | (lpm_standby_wake_source_t)0, .snooze_request_source = LPM_SNOOZE_REQUEST_RXD0_FALLING, .snooze_end_sources = (lpm_snooze_end_t)0, .dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE, + #endif #if BSP_FEATURE_LPM_HAS_SBYCR_OPE .output_port_enable = 0, #endif @@ -56,171 +19,23 @@ const lpm_cfg_t g_lpm0_cfg = .deep_standby_cancel_source = (lpm_deep_standby_cancel_source_t)0, .deep_standby_cancel_edge = (lpm_deep_standby_cancel_edge_t)0, #endif + #if BSP_FEATURE_LPM_HAS_PDRAMSCR + .ram_retention_cfg.ram_retention = (uint8_t)(0), + .ram_retention_cfg.tcm_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_DPSBYCR_SRKEEP + .ram_retention_cfg.standby_ram_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_LDO_CONTROL + .ldo_standby_cfg.pll1_ldo = false, + .ldo_standby_cfg.pll2_ldo = false, + .ldo_standby_cfg.hoco_ldo = false, + #endif .p_extend = NULL, }; const lpm_instance_t g_lpm0 = { .p_api = &g_lpm_on_lpm, .p_ctrl = &g_lpm0_ctrl, .p_cfg = &g_lpm0_cfg }; -dtc_instance_ctrl_t g_transfer1_ctrl; -transfer_info_t g_transfer1_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .repeat_area = TRANSFER_REPEAT_AREA_DESTINATION, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer1_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_RXI, }; -const transfer_cfg_t g_transfer1_cfg = -{ .p_info = &g_transfer1_info, .p_extend = &g_transfer1_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer1 = -{ .p_ctrl = &g_transfer1_ctrl, .p_cfg = &g_transfer1_cfg, .p_api = &g_transfer_on_dtc }; -dtc_instance_ctrl_t g_transfer0_ctrl; - -transfer_info_t g_transfer0_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .repeat_area = TRANSFER_REPEAT_AREA_SOURCE, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer0_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_TXI, }; -const transfer_cfg_t g_transfer0_cfg = -{ .p_info = &g_transfer0_info, .p_extend = &g_transfer0_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer0 = -{ .p_ctrl = &g_transfer0_ctrl, .p_cfg = &g_transfer0_cfg, .p_api = &g_transfer_on_dtc }; -spi_instance_ctrl_t g_spi0_ctrl; - -/** SPI extended configuration for SPI HAL driver */ -const spi_extended_cfg_t g_spi0_ext_cfg = -{ .spi_clksyn = SPI_SSL_MODE_CLK_SYN, - .spi_comm = SPI_COMMUNICATION_FULL_DUPLEX, - .ssl_polarity = SPI_SSLP_LOW, - .ssl_select = SPI_SSL_SELECT_SSL0, - .mosi_idle = SPI_MOSI_IDLE_VALUE_FIXING_DISABLE, - .parity = SPI_PARITY_MODE_DISABLE, - .byte_swap = SPI_BYTE_SWAP_DISABLE, - .spck_div = - { - /* Actual calculated bitrate: 12000000. */ .spbr = 1, - .brdv = 0 - }, - .spck_delay = SPI_DELAY_COUNT_1, - .ssl_negation_delay = SPI_DELAY_COUNT_1, - .next_access_delay = SPI_DELAY_COUNT_1 }; - -/** SPI configuration for SPI HAL driver */ -const spi_cfg_t g_spi0_cfg = -{ .channel = 0, - - #if defined(VECTOR_NUMBER_SPI0_RXI) - .rxi_irq = VECTOR_NUMBER_SPI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TXI) - .txi_irq = VECTOR_NUMBER_SPI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TEI) - .tei_irq = VECTOR_NUMBER_SPI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_ERI) - .eri_irq = VECTOR_NUMBER_SPI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - - .rxi_ipl = (12), - .txi_ipl = (12), - .tei_ipl = (12), - .eri_ipl = (12), - - .operating_mode = SPI_MODE_MASTER, - - .clk_phase = SPI_CLK_PHASE_EDGE_ODD, - .clk_polarity = SPI_CLK_POLARITY_LOW, - - .mode_fault = SPI_MODE_FAULT_ERROR_DISABLE, - .bit_order = SPI_BIT_ORDER_MSB_FIRST, - .p_transfer_tx = g_spi0_P_TRANSFER_TX, - .p_transfer_rx = g_spi0_P_TRANSFER_RX, - .p_callback = spi_callback, - - .p_context = NULL, - .p_extend = (void *)&g_spi0_ext_cfg, }; - -/* Instance structure to use this module. */ -const spi_instance_t g_spi0 = -{ .p_ctrl = &g_spi0_ctrl, .p_cfg = &g_spi0_cfg, .p_api = &g_spi_on_spi }; -icu_instance_ctrl_t g_external_irq0_ctrl; -const external_irq_cfg_t g_external_irq0_cfg = -{ .channel = 0, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ0) - .irq = VECTOR_NUMBER_ICU_IRQ0, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq0 = -{ .p_ctrl = &g_external_irq0_ctrl, .p_cfg = &g_external_irq0_cfg, .p_api = &g_external_irq_on_icu }; -agt_instance_ctrl_t g_timer0_ctrl; -const agt_extended_cfg_t g_timer0_extend = -{ .count_source = AGT_CLOCK_PCLKB, - .agto = AGT_PIN_CFG_DISABLED, - .agtoa = AGT_PIN_CFG_DISABLED, - .agtob = AGT_PIN_CFG_DISABLED, - .measurement_mode = AGT_MEASURE_DISABLED, - .agtio_filter = AGT_AGTIO_FILTER_NONE, - .enable_pin = AGT_ENABLE_PIN_NOT_USED, - .trigger_edge = AGT_TRIGGER_EDGE_RISING, }; -const timer_cfg_t g_timer0_cfg = -{ .mode = TIMER_MODE_PERIODIC, -/* Actual period: 0.002730666666666667 seconds. Actual duty: 50%. */ .period_counts = 0x10000, - .duty_cycle_counts = 0x8000, .source_div = (timer_source_div_t)0, .channel = 0, .p_callback = callback_agt, - /** If NULL then do not add & */ - #if defined(NULL) - .p_context = NULL, - #else - .p_context = &NULL, - #endif - .p_extend = &g_timer0_extend, - .cycle_end_ipl = (5), - #if defined(VECTOR_NUMBER_AGT0_INT) - .cycle_end_irq = VECTOR_NUMBER_AGT0_INT, - #else - .cycle_end_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const timer_instance_t g_timer0 = -{ .p_ctrl = &g_timer0_ctrl, .p_cfg = &g_timer0_cfg, .p_api = &g_timer_on_agt }; flash_lp_instance_ctrl_t g_flash0_ctrl; const flash_cfg_t g_flash0_cfg = { .data_flash_bgo = false, .p_callback = NULL, .p_context = NULL, .ipl = (BSP_IRQ_DISABLED), @@ -233,239 +48,3 @@ const flash_cfg_t g_flash0_cfg = /* Instance structure to use this module. */ const flash_instance_t g_flash0 = { .p_ctrl = &g_flash0_ctrl, .p_cfg = &g_flash0_cfg, .p_api = &g_flash_on_flash_lp }; -rtc_instance_ctrl_t g_rtc0_ctrl; -const rtc_error_adjustment_cfg_t g_rtc0_err_cfg = -{ .adjustment_mode = RTC_ERROR_ADJUSTMENT_MODE_AUTOMATIC, - .adjustment_period = RTC_ERROR_ADJUSTMENT_PERIOD_10_SECOND, - .adjustment_type = RTC_ERROR_ADJUSTMENT_NONE, - .adjustment_value = 0, }; -const rtc_cfg_t g_rtc0_cfg = -{ .clock_source = RTC_CLOCK_SOURCE_LOCO, .freq_compare_value_loco = 255, .p_err_cfg = &g_rtc0_err_cfg, .p_callback = - NULL, - .p_context = NULL, .alarm_ipl = (14), .periodic_ipl = (14), .carry_ipl = (14), - #if defined(VECTOR_NUMBER_RTC_ALARM) - .alarm_irq = VECTOR_NUMBER_RTC_ALARM, - #else - .alarm_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_PERIOD) - .periodic_irq = VECTOR_NUMBER_RTC_PERIOD, - #else - .periodic_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_CARRY) - .carry_irq = VECTOR_NUMBER_RTC_CARRY, - #else - .carry_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const rtc_instance_t g_rtc0 = -{ .p_ctrl = &g_rtc0_ctrl, .p_cfg = &g_rtc0_cfg, .p_api = &g_rtc_on_rtc }; -sci_uart_instance_ctrl_t g_uart2_ctrl; - -baud_setting_t g_uart2_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart2_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart2_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart2_cfg = -{ .channel = 2, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart2_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI2_RXI) - .rxi_irq = VECTOR_NUMBER_SCI2_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI2_TXI) - .txi_irq = VECTOR_NUMBER_SCI2_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI2_TEI) - .tei_irq = VECTOR_NUMBER_SCI2_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI2_ERI) - .eri_irq = VECTOR_NUMBER_SCI2_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart2 = -{ .p_ctrl = &g_uart2_ctrl, .p_cfg = &g_uart2_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart1_ctrl; - -baud_setting_t g_uart1_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart1_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart1_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart1_cfg = -{ .channel = 1, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart1_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI1_RXI) - .rxi_irq = VECTOR_NUMBER_SCI1_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_TXI) - .txi_irq = VECTOR_NUMBER_SCI1_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_TEI) - .tei_irq = VECTOR_NUMBER_SCI1_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_ERI) - .eri_irq = VECTOR_NUMBER_SCI1_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart1 = -{ .p_ctrl = &g_uart1_ctrl, .p_cfg = &g_uart1_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart0_ctrl; - -baud_setting_t g_uart0_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart0_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart0_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart0_cfg = -{ .channel = 0, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart0_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI0_RXI) - .rxi_irq = VECTOR_NUMBER_SCI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_TXI) - .txi_irq = VECTOR_NUMBER_SCI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_TEI) - .tei_irq = VECTOR_NUMBER_SCI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_ERI) - .eri_irq = VECTOR_NUMBER_SCI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart0 = -{ .p_ctrl = &g_uart0_ctrl, .p_cfg = &g_uart0_cfg, .p_api = &g_uart_on_sci }; -void g_hal_init(void) { - g_common_init(); -} diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h index 4120a48030..7b1e505f68 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h @@ -2,99 +2,20 @@ #ifndef HAL_DATA_H_ #define HAL_DATA_H_ #include -#include "bsp_api.h" #include "common_data.h" -#include "r_adc.h" -#include "r_adc_api.h" #include "r_lpm.h" #include "r_lpm_api.h" -#include "r_dtc.h" -#include "r_transfer_api.h" -#include "r_spi.h" -#include "r_icu.h" -#include "r_external_irq_api.h" -#include "r_agt.h" -#include "r_timer_api.h" #include "r_flash_lp.h" #include "r_flash_api.h" -#include "r_rtc.h" -#include "r_rtc_api.h" -#include "r_sci_uart.h" -#include "r_uart_api.h" FSP_HEADER -/** ADC on ADC Instance. */ -extern const adc_instance_t g_adc0; -/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ -extern adc_instance_ctrl_t g_adc0_ctrl; -extern const adc_cfg_t g_adc0_cfg; -extern const adc_channel_cfg_t g_adc0_channel_cfg; - -#ifndef NULL -void NULL(adc_callback_args_t *p_args); -#endif /** lpm Instance */ extern const lpm_instance_t g_lpm0; /** Access the LPM instance using these structures when calling API functions directly (::p_api is not used). */ extern lpm_instance_ctrl_t g_lpm0_ctrl; extern const lpm_cfg_t g_lpm0_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer1; -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer1_ctrl; -extern const transfer_cfg_t g_transfer1_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer0; - -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer0_ctrl; -extern const transfer_cfg_t g_transfer0_cfg; -/** SPI on SPI Instance. */ -extern const spi_instance_t g_spi0; - -/** Access the SPI instance using these structures when calling API functions directly (::p_api is not used). */ -extern spi_instance_ctrl_t g_spi0_ctrl; -extern const spi_cfg_t g_spi0_cfg; - -/** Callback used by SPI Instance. */ -#ifndef spi_callback -void spi_callback(spi_callback_args_t *p_args); -#endif - -#define RA_NOT_DEFINED (1) -#if (RA_NOT_DEFINED == g_transfer0) - #define g_spi0_P_TRANSFER_TX (NULL) -#else -#define g_spi0_P_TRANSFER_TX (&g_transfer0) -#endif -#if (RA_NOT_DEFINED == g_transfer1) - #define g_spi0_P_TRANSFER_RX (NULL) -#else -#define g_spi0_P_TRANSFER_RX (&g_transfer1) -#endif -#undef RA_NOT_DEFINED -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq0; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq0_ctrl; -extern const external_irq_cfg_t g_external_irq0_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** AGT Timer Instance */ -extern const timer_instance_t g_timer0; - -/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ -extern agt_instance_ctrl_t g_timer0_ctrl; -extern const timer_cfg_t g_timer0_cfg; - -#ifndef callback_agt -void callback_agt(timer_callback_args_t *p_args); -#endif /* Flash on Flash LP Instance. */ extern const flash_instance_t g_flash0; @@ -105,50 +26,8 @@ extern const flash_cfg_t g_flash0_cfg; #ifndef NULL void NULL(flash_callback_args_t *p_args); #endif -/* RTC Instance. */ -extern const rtc_instance_t g_rtc0; -/** Access the RTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern rtc_instance_ctrl_t g_rtc0_ctrl; -extern const rtc_cfg_t g_rtc0_cfg; - -#ifndef NULL -void NULL(rtc_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart2; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart2_ctrl; -extern const uart_cfg_t g_uart2_cfg; -extern const sci_uart_extended_cfg_t g_uart2_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart1; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart1_ctrl; -extern const uart_cfg_t g_uart1_cfg; -extern const sci_uart_extended_cfg_t g_uart1_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart0; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart0_ctrl; -extern const uart_cfg_t g_uart0_cfg; -extern const sci_uart_extended_cfg_t g_uart0_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif void hal_entry(void); -void g_hal_init(void); + FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/pin_data.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/pin_data.c index bc928d63f5..93eb2ae0d7 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/pin_data.c +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/pin_data.c @@ -1,105 +1,91 @@ /* generated pin source file - do not edit */ #include "bsp_api.h" #include "r_ioport_api.h" -const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = { - { - .pin = BSP_IO_PORT_00_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE), - }, - { - .pin = BSP_IO_PORT_01_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_03, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_05, - .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), - }, - { - .pin = BSP_IO_PORT_01_PIN_06, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_01_PIN_08, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_09, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_15, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_CTSU), - }, - { - .pin = BSP_IO_PORT_02_PIN_05, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_CTSU), - }, - { - .pin = BSP_IO_PORT_03_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_03_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_03_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_04_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_04_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_04_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_04_PIN_03, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_04_PIN_07, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_USB_FS), - }, - { - .pin = BSP_IO_PORT_04_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_04_PIN_11, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_09_PIN_14, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_USB_FS), - }, - { - .pin = BSP_IO_PORT_09_PIN_15, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_USB_FS), - }, -}; -const ioport_cfg_t g_bsp_pin_cfg = { - .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), - .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], + +const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = +{ + { .pin = BSP_IO_PORT_00_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, + { .pin = BSP_IO_PORT_01_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_03, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_05, .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, + { .pin = BSP_IO_PORT_01_PIN_06, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_01_PIN_08, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_09, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_15, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_CTSU) }, + { .pin = BSP_IO_PORT_02_PIN_05, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_CTSU) }, + { .pin = BSP_IO_PORT_03_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_03_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_03_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_04_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_04_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_04_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_04_PIN_03, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_04_PIN_07, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_USB_FS) }, + { .pin = BSP_IO_PORT_04_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_04_PIN_11, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_09_PIN_14, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_USB_FS) }, + { .pin = BSP_IO_PORT_09_PIN_15, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_USB_FS) }, }; + +const ioport_cfg_t g_bsp_pin_cfg = +{ .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], }; + +#if BSP_TZ_SECURE_BUILD + +void R_BSP_PinCfgSecurityInit(void); + +/* Initialize SAR registers for secure pins. */ +void R_BSP_PinCfgSecurityInit(void) { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + uint32_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #else + uint16_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #endif + memset(pmsar, 0xFF, BSP_FEATURE_BSP_NUM_PMSAR * sizeof(R_PMISC->PMSAR[0])); + + + for (uint32_t i = 0; i < g_bsp_pin_cfg.number_of_pins; i++) + { + uint32_t port_pin = g_bsp_pin_cfg.p_pin_cfg_data[i].pin; + uint32_t port = port_pin >> 8U; + uint32_t pin = port_pin & 0xFFU; + pmsar[port] &= (uint16_t) ~(1U << pin); + } + + for (uint32_t i = 0; i < BSP_FEATURE_BSP_NUM_PMSAR; i++) + { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + R_PMISC->PMSAR[i].PMSAR = (uint16_t)pmsar[i]; + #else + R_PMISC->PMSAR[i].PMSAR = pmsar[i]; + #endif + } + +} +#endif diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.c index a5f0092a56..d2aafa6e70 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.c +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.c @@ -4,7 +4,7 @@ #if VECTOR_DATA_IRQ_COUNT > 0 BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BSP_PLACE_IN_SECTION(BSP_SECTION_APPLICATION_VECTORS) = { - [0] = sci_uart_rxi_isr, /* SCI0 RXI (Receive data full) */ + [0] = sci_uart_rxi_isr, /* SCI0 RXI (Receive data full) */ [1] = sci_uart_txi_isr, /* SCI0 TXI (Transmit data empty) */ [2] = sci_uart_tei_isr, /* SCI0 TEI (Transmit end) */ [3] = sci_uart_eri_isr, /* SCI0 ERI (Receive error) */ @@ -14,17 +14,17 @@ BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BS [7] = sci_uart_eri_isr, /* SCI1 ERI (Receive error) */ [8] = sci_uart_rxi_isr, /* SCI2 RXI (Received data full) */ [9] = sci_uart_txi_isr, /* SCI2 TXI (Transmit data empty) */ - [10] = sci_uart_tei_isr, /* SCI2 TEI (Transmit end) */ - [11] = sci_uart_eri_isr, /* SCI2 ERI (Receive error) */ - [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ - [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ - [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ - [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ - [16] = r_icu_isr, /* ICU IRQ0 (External pin interrupt 0) */ - [17] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ - [18] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ - [19] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ - [20] = spi_eri_isr, /* SPI0 ERI (Error) */ + [10] = sci_uart_tei_isr, /* SCI2 TEI (Transmit end) */ + [11] = sci_uart_eri_isr, /* SCI2 ERI (Receive error) */ + [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ + [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ + [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ + [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ + [16] = r_icu_isr, /* ICU IRQ0 (External pin interrupt 0) */ + [17] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ + [18] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ + [19] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ + [20] = spi_eri_isr, /* SPI0 ERI (Error) */ }; const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = { @@ -38,16 +38,16 @@ const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENT [7] = BSP_PRV_IELS_ENUM(EVENT_SCI1_ERI), /* SCI1 ERI (Receive error) */ [8] = BSP_PRV_IELS_ENUM(EVENT_SCI2_RXI), /* SCI2 RXI (Received data full) */ [9] = BSP_PRV_IELS_ENUM(EVENT_SCI2_TXI), /* SCI2 TXI (Transmit data empty) */ - [10] = BSP_PRV_IELS_ENUM(EVENT_SCI2_TEI), /* SCI2 TEI (Transmit end) */ - [11] = BSP_PRV_IELS_ENUM(EVENT_SCI2_ERI), /* SCI2 ERI (Receive error) */ - [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ - [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ - [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ - [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ - [16] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ0), /* ICU IRQ0 (External pin interrupt 0) */ - [17] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ - [18] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ - [19] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ - [20] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ + [10] = BSP_PRV_IELS_ENUM(EVENT_SCI2_TEI), /* SCI2 TEI (Transmit end) */ + [11] = BSP_PRV_IELS_ENUM(EVENT_SCI2_ERI), /* SCI2 ERI (Receive error) */ + [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ + [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ + [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ + [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ + [16] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ0), /* ICU IRQ0 (External pin interrupt 0) */ + [17] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ + [18] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ + [19] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ + [20] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ }; #endif diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.h index 1e23b674ca..068f001b85 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/vector_data.h @@ -1,6 +1,9 @@ /* generated vector header file - do not edit */ #ifndef VECTOR_DATA_H #define VECTOR_DATA_H +#ifdef __cplusplus +extern "C" { +#endif /* Number of interrupts allocated */ #ifndef VECTOR_DATA_IRQ_COUNT #define VECTOR_DATA_IRQ_COUNT (21) @@ -21,59 +24,48 @@ void spi_eri_isr(void); /* Vector table allocations */ #define VECTOR_NUMBER_SCI0_RXI ((IRQn_Type)0) /* SCI0 RXI (Receive data full) */ +#define SCI0_RXI_IRQn ((IRQn_Type)0) /* SCI0 RXI (Receive data full) */ #define VECTOR_NUMBER_SCI0_TXI ((IRQn_Type)1) /* SCI0 TXI (Transmit data empty) */ +#define SCI0_TXI_IRQn ((IRQn_Type)1) /* SCI0 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI0_TEI ((IRQn_Type)2) /* SCI0 TEI (Transmit end) */ +#define SCI0_TEI_IRQn ((IRQn_Type)2) /* SCI0 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI0_ERI ((IRQn_Type)3) /* SCI0 ERI (Receive error) */ +#define SCI0_ERI_IRQn ((IRQn_Type)3) /* SCI0 ERI (Receive error) */ #define VECTOR_NUMBER_SCI1_RXI ((IRQn_Type)4) /* SCI1 RXI (Received data full) */ +#define SCI1_RXI_IRQn ((IRQn_Type)4) /* SCI1 RXI (Received data full) */ #define VECTOR_NUMBER_SCI1_TXI ((IRQn_Type)5) /* SCI1 TXI (Transmit data empty) */ +#define SCI1_TXI_IRQn ((IRQn_Type)5) /* SCI1 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI1_TEI ((IRQn_Type)6) /* SCI1 TEI (Transmit end) */ +#define SCI1_TEI_IRQn ((IRQn_Type)6) /* SCI1 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI1_ERI ((IRQn_Type)7) /* SCI1 ERI (Receive error) */ +#define SCI1_ERI_IRQn ((IRQn_Type)7) /* SCI1 ERI (Receive error) */ #define VECTOR_NUMBER_SCI2_RXI ((IRQn_Type)8) /* SCI2 RXI (Received data full) */ +#define SCI2_RXI_IRQn ((IRQn_Type)8) /* SCI2 RXI (Received data full) */ #define VECTOR_NUMBER_SCI2_TXI ((IRQn_Type)9) /* SCI2 TXI (Transmit data empty) */ +#define SCI2_TXI_IRQn ((IRQn_Type)9) /* SCI2 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI2_TEI ((IRQn_Type)10) /* SCI2 TEI (Transmit end) */ +#define SCI2_TEI_IRQn ((IRQn_Type)10) /* SCI2 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI2_ERI ((IRQn_Type)11) /* SCI2 ERI (Receive error) */ +#define SCI2_ERI_IRQn ((IRQn_Type)11) /* SCI2 ERI (Receive error) */ #define VECTOR_NUMBER_RTC_ALARM ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ +#define RTC_ALARM_IRQn ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ #define VECTOR_NUMBER_RTC_PERIOD ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ +#define RTC_PERIOD_IRQn ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ #define VECTOR_NUMBER_RTC_CARRY ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ +#define RTC_CARRY_IRQn ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ #define VECTOR_NUMBER_AGT0_INT ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ +#define AGT0_INT_IRQn ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ #define VECTOR_NUMBER_ICU_IRQ0 ((IRQn_Type)16) /* ICU IRQ0 (External pin interrupt 0) */ +#define ICU_IRQ0_IRQn ((IRQn_Type)16) /* ICU IRQ0 (External pin interrupt 0) */ #define VECTOR_NUMBER_SPI0_RXI ((IRQn_Type)17) /* SPI0 RXI (Receive buffer full) */ +#define SPI0_RXI_IRQn ((IRQn_Type)17) /* SPI0 RXI (Receive buffer full) */ #define VECTOR_NUMBER_SPI0_TXI ((IRQn_Type)18) /* SPI0 TXI (Transmit buffer empty) */ +#define SPI0_TXI_IRQn ((IRQn_Type)18) /* SPI0 TXI (Transmit buffer empty) */ #define VECTOR_NUMBER_SPI0_TEI ((IRQn_Type)19) /* SPI0 TEI (Transmission complete event) */ +#define SPI0_TEI_IRQn ((IRQn_Type)19) /* SPI0 TEI (Transmission complete event) */ #define VECTOR_NUMBER_SPI0_ERI ((IRQn_Type)20) /* SPI0 ERI (Error) */ -typedef enum IRQn -{ - Reset_IRQn = -15, - NonMaskableInt_IRQn = -14, - HardFault_IRQn = -13, - MemoryManagement_IRQn = -12, - BusFault_IRQn = -11, - UsageFault_IRQn = -10, - SecureFault_IRQn = -9, - SVCall_IRQn = -5, - DebugMonitor_IRQn = -4, - PendSV_IRQn = -2, - SysTick_IRQn = -1, - SCI0_RXI_IRQn = 0, /* SCI0 RXI (Receive data full) */ - SCI0_TXI_IRQn = 1, /* SCI0 TXI (Transmit data empty) */ - SCI0_TEI_IRQn = 2, /* SCI0 TEI (Transmit end) */ - SCI0_ERI_IRQn = 3, /* SCI0 ERI (Receive error) */ - SCI1_RXI_IRQn = 4, /* SCI1 RXI (Received data full) */ - SCI1_TXI_IRQn = 5, /* SCI1 TXI (Transmit data empty) */ - SCI1_TEI_IRQn = 6, /* SCI1 TEI (Transmit end) */ - SCI1_ERI_IRQn = 7, /* SCI1 ERI (Receive error) */ - SCI2_RXI_IRQn = 8, /* SCI2 RXI (Received data full) */ - SCI2_TXI_IRQn = 9, /* SCI2 TXI (Transmit data empty) */ - SCI2_TEI_IRQn = 10, /* SCI2 TEI (Transmit end) */ - SCI2_ERI_IRQn = 11, /* SCI2 ERI (Receive error) */ - RTC_ALARM_IRQn = 12, /* RTC ALARM (Alarm interrupt) */ - RTC_PERIOD_IRQn = 13, /* RTC PERIOD (Periodic interrupt) */ - RTC_CARRY_IRQn = 14, /* RTC CARRY (Carry interrupt) */ - AGT0_INT_IRQn = 15, /* AGT0 INT (AGT interrupt) */ - ICU_IRQ0_IRQn = 16, /* ICU IRQ0 (External pin interrupt 0) */ - SPI0_RXI_IRQn = 17, /* SPI0 RXI (Receive buffer full) */ - SPI0_TXI_IRQn = 18, /* SPI0 TXI (Transmit buffer empty) */ - SPI0_TEI_IRQn = 19, /* SPI0 TEI (Transmission complete event) */ - SPI0_ERI_IRQn = 20, /* SPI0 ERI (Error) */ -} IRQn_Type; +#define SPI0_ERI_IRQn ((IRQn_Type)20) /* SPI0 ERI (Error) */ +#ifdef __cplusplus +} +#endif #endif /* VECTOR_DATA_H */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h index 9ebcbf9777..d6d8e7df3c 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_CFG_H_ #define BSP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_clock_cfg.h" #include "bsp_mcu_family_cfg.h" #include "board_cfg.h" @@ -14,7 +18,13 @@ #define BSP_CFG_RTOS (0) #endif #endif +#ifndef BSP_CFG_RTC_USED +#define BSP_CFG_RTC_USED (1) +#endif #undef RA_NOT_DEFINED +#if defined(_RA_BOOT_IMAGE) +#define BSP_CFG_BOOT_IMAGE (1) +#endif #define BSP_CFG_MCU_VCC_MV (3300) #define BSP_CFG_STACK_MAIN_BYTES (0x4000) #define BSP_CFG_HEAP_BYTES (0xf000) @@ -25,15 +35,14 @@ #define BSP_CFG_PFS_PROTECT ((1)) #define BSP_CFG_C_RUNTIME_INIT ((1)) +#define BSP_CFG_EARLY_INIT ((0)) -#define BSP_CFG_SOFT_RESET_SUPPORTED ((0)) +#define BSP_CFG_STARTUP_CLOCK_REG_NOT_RESET ((0)) #ifndef BSP_CLOCK_CFG_MAIN_OSC_POPULATED #define BSP_CLOCK_CFG_MAIN_OSC_POPULATED (0) #endif -#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT -#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) -#endif + #ifndef BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE #define BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE (0) #endif @@ -46,4 +55,8 @@ #ifndef BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS #define BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS 1000 #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h index 70984c8ef6..3795df6502 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h @@ -2,6 +2,7 @@ #ifndef BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_R7FA4W1AD2CNG +#define BSP_MCU_FEATURE_SET ('A') #define BSP_ROM_SIZE_BYTES (524288) #define BSP_RAM_SIZE_BYTES (98304) #define BSP_DATA_FLASH_SIZE_BYTES (8192) diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h index fd26bb64e0..7ea92f74b0 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_MCU_FAMILY_CFG_H_ #define BSP_MCU_FAMILY_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_mcu_device_pn_cfg.h" #include "bsp_mcu_device_cfg.h" #include "../../../ra/fsp/src/bsp/mcu/ra4w1/bsp_mcu_info.h" @@ -22,7 +26,6 @@ #endif #define BSP_CORTEX_VECTOR_TABLE_ENTRIES (16U) #define BSP_VECTOR_TABLE_MAX_ENTRIES (48U) -#define BSP_MCU_VBATT_SUPPORT (1) #define OFS_SEQ1 0xA001A001 | (1 << 1) | (3 << 2) #define OFS_SEQ2 (15 << 4) | (3 << 8) | (3 << 10) @@ -50,7 +53,9 @@ #define BSP_CFG_ROM_REG_MPU_REGION3_ENABLE (1) #define BSP_CFG_ROM_REG_MPU_REGION3_START (0x400DFFFC) #define BSP_CFG_ROM_REG_MPU_REGION3_END (0x400DFFFF) - +#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT +#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) +#endif /* Used to create IELS values for the interrupt initialization table g_interrupt_event_link_select. */ #define BSP_PRV_IELS_ENUM(vector) (ELC_##vector) @@ -71,4 +76,8 @@ #define BSP_CFG_ID_CODE_LONG_3 (0xFFFFFFFF) #define BSP_CFG_ID_CODE_LONG_4 (0xffFFFFFF) #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_MCU_FAMILY_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h index 9c59889ca8..be8a427206 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_adc_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_ADC_CFG_H_ #define R_ADC_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define ADC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_ADC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h deleted file mode 100644 index d3ab559238..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_agt_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_AGT_CFG_H_ -#define R_AGT_CFG_H_ -#define AGT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define AGT_CFG_OUTPUT_SUPPORT_ENABLE (0) -#define AGT_CFG_INPUT_SUPPORT_ENABLE (0) -#endif /* R_AGT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h deleted file mode 100644 index 21405f9674..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_dtc_cfg.h +++ /dev/null @@ -1,6 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_DTC_CFG_H_ -#define R_DTC_CFG_H_ -#define DTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define DTC_CFG_VECTOR_TABLE_SECTION_NAME ".fsp_dtc_vector_table" -#endif /* R_DTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h index 26879f9f4e..7f285caced 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_flash_lp_cfg.h @@ -1,7 +1,15 @@ /* generated configuration header file - do not edit */ #ifndef R_FLASH_LP_CFG_H_ #define R_FLASH_LP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define FLASH_LP_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) #define FLASH_LP_CFG_CODE_FLASH_PROGRAMMING_ENABLE (1) #define FLASH_LP_CFG_DATA_FLASH_PROGRAMMING_ENABLE (0) + +#ifdef __cplusplus +} +#endif #endif /* R_FLASH_LP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h deleted file mode 100644 index 5e77b6980f..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_icu_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_ICU_CFG_H_ -#define R_ICU_CFG_H_ -#define ICU_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_ICU_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h deleted file mode 100644 index 595ea938d1..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_iic_master_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_IIC_MASTER_CFG_H_ -#define R_IIC_MASTER_CFG_H_ -#define IIC_MASTER_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define IIC_MASTER_CFG_DTC_ENABLE (0) -#define IIC_MASTER_CFG_ADDR_MODE_10_BIT_ENABLE (0) -#endif /* R_IIC_MASTER_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h index 6b4353d238..d2688bf5ba 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_ioport_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_IOPORT_CFG_H_ #define R_IOPORT_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define IOPORT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_IOPORT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h index 5f4d5c4a73..6712eee6a1 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_lpm_cfg.h @@ -1,5 +1,14 @@ /* generated configuration header file - do not edit */ #ifndef R_LPM_CFG_H_ #define R_LPM_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define LPM_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define LPM_CFG_STANDBY_LIMIT (0) + +#ifdef __cplusplus +} +#endif #endif /* R_LPM_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h deleted file mode 100644 index 484b7ed044..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_rtc_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_RTC_CFG_H_ -#define R_RTC_CFG_H_ -#define RTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_RTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h deleted file mode 100644 index c70c0be344..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h +++ /dev/null @@ -1,8 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SCI_UART_CFG_H_ -#define R_SCI_UART_CFG_H_ -#define SCI_UART_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SCI_UART_CFG_FIFO_SUPPORT (0) -#define SCI_UART_CFG_DTC_SUPPORTED (0) -#define SCI_UART_CFG_FLOW_CONTROL_SUPPORT (0) -#endif /* R_SCI_UART_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h deleted file mode 100644 index 861fe12194..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_cfg/fsp_cfg/r_spi_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SPI_CFG_H_ -#define R_SPI_CFG_H_ -#define SPI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SPI_DTC_SUPPORT_ENABLE (1) -#define SPI_TRANSMIT_FROM_RXI_ISR (0) -#endif /* R_SPI_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/bsp_clock_cfg.h index 9432ad009c..4669c98c40 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/bsp_clock_cfg.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/bsp_clock_cfg.h @@ -7,15 +7,13 @@ #define BSP_CFG_PLL_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_MAIN_OSC) /* PLL Src: XTAL */ #define BSP_CFG_HOCO_FREQUENCY (4) /* HOCO 48MHz */ #define BSP_CFG_PLL_DIV (BSP_CLOCKS_PLL_DIV_2) /* PLL Div /2 */ -#define BSP_CFG_PLL_MUL (BSP_CLOCKS_PLL_MUL_12_0) /* PLL Mul x12 */ +#define BSP_CFG_PLL_MUL (BSP_CLOCKS_PLL_MUL(12U, 0U)) /* PLL Mul x12 */ #define BSP_CFG_CLOCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_HOCO) /* Clock Src: HOCO */ #define BSP_CFG_ICLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* ICLK Div /1 */ #define BSP_CFG_PCLKA_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* PCLKA Div /1 */ #define BSP_CFG_PCLKB_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* PCLKB Div /2 */ #define BSP_CFG_PCLKC_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* PCLKC Div /1 */ #define BSP_CFG_PCLKD_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* PCLKD Div /1 */ -#define BSP_CFG_BCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* BCLK Div /2 */ -#define BSP_CFG_BCLK_OUTPUT (2) /* BCK/2 */ #define BSP_CFG_FCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* FCLK Div /2 */ #define BSP_CFG_CLKOUT_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* CLKOUT Disabled */ #define BSP_CFG_CLKOUT_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* CLKOUT Div /1 */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.c index 34aad762ff..fb539ac4ac 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.c +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.c @@ -3,5 +3,3 @@ ioport_instance_ctrl_t g_ioport_ctrl; const ioport_instance_t g_ioport = { .p_api = &g_ioport_on_ioport, .p_ctrl = &g_ioport_ctrl, .p_cfg = &g_bsp_pin_cfg, }; -void g_common_init(void) { -} diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.h index e2eb70836b..5c61c76363 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/common_data.h @@ -5,12 +5,15 @@ #include "bsp_api.h" #include "r_ioport.h" #include "bsp_pin_cfg.h" +#include "r_icu.h" +#include "r_external_irq_api.h" FSP_HEADER + /* IOPORT Instance */ extern const ioport_instance_t g_ioport; /* IOPORT control structure. */ extern ioport_instance_ctrl_t g_ioport_ctrl; -void g_common_init(void); + FSP_FOOTER #endif /* COMMON_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.c index 8e7ee1bd4a..af7f3ebd45 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.c +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.c @@ -1,98 +1,15 @@ -/* generated HAL source file - do not edit */ #include "hal_data.h" -/* Macros to tie dynamic ELC links to ADC_TRIGGER_SYNC_ELC option in adc_trigger_t. */ -#define ADC_TRIGGER_ADC0 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC0_B ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1_B ADC_TRIGGER_SYNC_ELC -adc_instance_ctrl_t g_adc0_ctrl; -const adc_extended_cfg_t g_adc0_cfg_extend = -{ .add_average_count = ADC_ADD_OFF, - .clearing = ADC_CLEAR_AFTER_READ_ON, - .trigger_group_b = ADC_TRIGGER_SYNC_ELC, - .double_trigger_mode = ADC_DOUBLE_TRIGGER_DISABLED, - .adc_vref_control = ADC_VREF_CONTROL_VREFH, }; -const adc_cfg_t g_adc0_cfg = -{ .unit = 0, .mode = ADC_MODE_SINGLE_SCAN, .resolution = ADC_RESOLUTION_14_BIT, .alignment = - (adc_alignment_t)ADC_ALIGNMENT_RIGHT, - .trigger = ADC_TRIGGER_SOFTWARE, .p_callback = NULL, .p_context = NULL, .p_extend = &g_adc0_cfg_extend, - #if defined(VECTOR_NUMBER_ADC0_SCAN_END) - .scan_end_irq = VECTOR_NUMBER_ADC0_SCAN_END, - #else - .scan_end_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_ipl = (BSP_IRQ_DISABLED), - #if defined(VECTOR_NUMBER_ADC0_SCAN_END_B) - .scan_end_b_irq = VECTOR_NUMBER_ADC0_SCAN_END_B, - #else - .scan_end_b_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; -const adc_channel_cfg_t g_adc0_channel_cfg = -{ .scan_mask = 0, - .scan_mask_group_b = 0, - .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, - .add_mask = 0, - .sample_hold_mask = 0, - .sample_hold_states = 24, }; -/* Instance structure to use this module. */ -const adc_instance_t g_adc0 = -{ .p_ctrl = &g_adc0_ctrl, .p_cfg = &g_adc0_cfg, .p_channel_cfg = &g_adc0_channel_cfg, .p_api = &g_adc_on_adc }; -iic_master_instance_ctrl_t g_i2c_master0_ctrl; -const iic_master_extended_cfg_t g_i2c_master0_extend = -{ .timeout_mode = IIC_MASTER_TIMEOUT_MODE_SHORT, -/* Actual calculated bitrate: 99272. Actual calculated duty cycle: 49%. */ .clock_settings.brl_value = 27, - .clock_settings.brh_value = 26, .clock_settings.cks_value = 2, }; -const i2c_master_cfg_t g_i2c_master0_cfg = -{ .channel = 0, .rate = I2C_MASTER_RATE_STANDARD, .slave = 0x00, .addr_mode = I2C_MASTER_ADDR_MODE_7BIT, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .p_callback = callback_iic, - .p_context = NULL, - #if defined(VECTOR_NUMBER_IIC0_RXI) - .rxi_irq = VECTOR_NUMBER_IIC0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC0_TXI) - .txi_irq = VECTOR_NUMBER_IIC0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC0_TEI) - .tei_irq = VECTOR_NUMBER_IIC0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC0_ERI) - .eri_irq = VECTOR_NUMBER_IIC0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - .ipl = (12), - .p_extend = &g_i2c_master0_extend, }; -/* Instance structure to use this module. */ -const i2c_master_instance_t g_i2c_master0 = -{ .p_ctrl = &g_i2c_master0_ctrl, .p_cfg = &g_i2c_master0_cfg, .p_api = &g_i2c_master_on_iic }; lpm_instance_ctrl_t g_lpm0_ctrl; const lpm_cfg_t g_lpm0_cfg = -{ .low_power_mode = LPM_MODE_SLEEP, +{ .low_power_mode = LPM_MODE_SLEEP, .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM + | (lpm_standby_wake_source_t)0, + #if BSP_FEATURE_LPM_HAS_SNOOZE .snooze_cancel_sources = LPM_SNOOZE_CANCEL_SOURCE_NONE, - .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM | (lpm_standby_wake_source_t)0, .snooze_request_source = LPM_SNOOZE_REQUEST_RXD0_FALLING, .snooze_end_sources = (lpm_snooze_end_t)0, .dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE, + #endif #if BSP_FEATURE_LPM_HAS_SBYCR_OPE .output_port_enable = LPM_OUTPUT_PORT_ENABLE_RETAIN, #endif @@ -102,278 +19,24 @@ const lpm_cfg_t g_lpm0_cfg = .deep_standby_cancel_source = (lpm_deep_standby_cancel_source_t)0, .deep_standby_cancel_edge = (lpm_deep_standby_cancel_edge_t)0, #endif + #if BSP_FEATURE_LPM_HAS_PDRAMSCR + .ram_retention_cfg.ram_retention = (uint8_t)(0), + .ram_retention_cfg.tcm_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_DPSBYCR_SRKEEP + .ram_retention_cfg.standby_ram_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_LDO_CONTROL + .ldo_standby_cfg.pll1_ldo = false, + .ldo_standby_cfg.pll2_ldo = false, + .ldo_standby_cfg.hoco_ldo = false, + #endif .p_extend = NULL, }; const lpm_instance_t g_lpm0 = { .p_api = &g_lpm_on_lpm, .p_ctrl = &g_lpm0_ctrl, .p_cfg = &g_lpm0_cfg }; -dtc_instance_ctrl_t g_transfer1_ctrl; -transfer_info_t g_transfer1_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .repeat_area = TRANSFER_REPEAT_AREA_DESTINATION, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer1_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_RXI, }; -const transfer_cfg_t g_transfer1_cfg = -{ .p_info = &g_transfer1_info, .p_extend = &g_transfer1_cfg_extend, }; -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer1 = -{ .p_ctrl = &g_transfer1_ctrl, .p_cfg = &g_transfer1_cfg, .p_api = &g_transfer_on_dtc }; -dtc_instance_ctrl_t g_transfer0_ctrl; - -transfer_info_t g_transfer0_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .repeat_area = TRANSFER_REPEAT_AREA_SOURCE, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer0_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_TXI, }; -const transfer_cfg_t g_transfer0_cfg = -{ .p_info = &g_transfer0_info, .p_extend = &g_transfer0_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer0 = -{ .p_ctrl = &g_transfer0_ctrl, .p_cfg = &g_transfer0_cfg, .p_api = &g_transfer_on_dtc }; -spi_instance_ctrl_t g_spi0_ctrl; - -/** SPI extended configuration for SPI HAL driver */ -const spi_extended_cfg_t g_spi0_ext_cfg = -{ .spi_clksyn = SPI_SSL_MODE_CLK_SYN, - .spi_comm = SPI_COMMUNICATION_FULL_DUPLEX, - .ssl_polarity = SPI_SSLP_LOW, - .ssl_select = SPI_SSL_SELECT_SSL0, - .mosi_idle = SPI_MOSI_IDLE_VALUE_FIXING_DISABLE, - .parity = SPI_PARITY_MODE_DISABLE, - .byte_swap = SPI_BYTE_SWAP_DISABLE, - .spck_div = - { - /* Actual calculated bitrate: 12000000. */ .spbr = 1, - .brdv = 0 - }, - .spck_delay = SPI_DELAY_COUNT_1, - .ssl_negation_delay = SPI_DELAY_COUNT_1, - .next_access_delay = SPI_DELAY_COUNT_1 }; - -/** SPI configuration for SPI HAL driver */ -const spi_cfg_t g_spi0_cfg = -{ .channel = 0, - - #if defined(VECTOR_NUMBER_SPI0_RXI) - .rxi_irq = VECTOR_NUMBER_SPI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TXI) - .txi_irq = VECTOR_NUMBER_SPI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TEI) - .tei_irq = VECTOR_NUMBER_SPI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_ERI) - .eri_irq = VECTOR_NUMBER_SPI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - - .rxi_ipl = (12), - .txi_ipl = (12), - .tei_ipl = (12), - .eri_ipl = (12), - - .operating_mode = SPI_MODE_MASTER, - - .clk_phase = SPI_CLK_PHASE_EDGE_ODD, - .clk_polarity = SPI_CLK_POLARITY_LOW, - - .mode_fault = SPI_MODE_FAULT_ERROR_DISABLE, - .bit_order = SPI_BIT_ORDER_MSB_FIRST, - .p_transfer_tx = g_spi0_P_TRANSFER_TX, - .p_transfer_rx = g_spi0_P_TRANSFER_RX, - .p_callback = spi_callback, - - .p_context = NULL, - .p_extend = (void *)&g_spi0_ext_cfg, }; - -/* Instance structure to use this module. */ -const spi_instance_t g_spi0 = -{ .p_ctrl = &g_spi0_ctrl, .p_cfg = &g_spi0_cfg, .p_api = &g_spi_on_spi }; -icu_instance_ctrl_t g_external_irq4_ctrl; -const external_irq_cfg_t g_external_irq4_cfg = -{ .channel = 4, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ4) - .irq = VECTOR_NUMBER_ICU_IRQ4, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq4 = -{ .p_ctrl = &g_external_irq4_ctrl, .p_cfg = &g_external_irq4_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq3_ctrl; -const external_irq_cfg_t g_external_irq3_cfg = -{ .channel = 3, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ3) - .irq = VECTOR_NUMBER_ICU_IRQ3, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq3 = -{ .p_ctrl = &g_external_irq3_ctrl, .p_cfg = &g_external_irq3_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq2_ctrl; -const external_irq_cfg_t g_external_irq2_cfg = -{ .channel = 2, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ2) - .irq = VECTOR_NUMBER_ICU_IRQ2, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq2 = -{ .p_ctrl = &g_external_irq2_ctrl, .p_cfg = &g_external_irq2_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq1_ctrl; -const external_irq_cfg_t g_external_irq1_cfg = -{ .channel = 1, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ1) - .irq = VECTOR_NUMBER_ICU_IRQ1, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq1 = -{ .p_ctrl = &g_external_irq1_ctrl, .p_cfg = &g_external_irq1_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq0_ctrl; -const external_irq_cfg_t g_external_irq0_cfg = -{ .channel = 0, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ0) - .irq = VECTOR_NUMBER_ICU_IRQ0, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq0 = -{ .p_ctrl = &g_external_irq0_ctrl, .p_cfg = &g_external_irq0_cfg, .p_api = &g_external_irq_on_icu }; -agt_instance_ctrl_t g_timer1_ctrl; -const agt_extended_cfg_t g_timer1_extend = -{ .count_source = AGT_CLOCK_PCLKB, - .agto = AGT_PIN_CFG_DISABLED, - .agtoa = AGT_PIN_CFG_DISABLED, - .agtob = AGT_PIN_CFG_DISABLED, - .measurement_mode = AGT_MEASURE_DISABLED, - .agtio_filter = AGT_AGTIO_FILTER_NONE, - .enable_pin = AGT_ENABLE_PIN_NOT_USED, - .trigger_edge = AGT_TRIGGER_EDGE_RISING, }; -const timer_cfg_t g_timer1_cfg = -{ .mode = TIMER_MODE_PERIODIC, -/* Actual period: 0.002730666666666667 seconds. Actual duty: 50%. */ .period_counts = 0x10000, - .duty_cycle_counts = 0x8000, .source_div = (timer_source_div_t)0, .channel = 1, .p_callback = callback_agt, - /** If NULL then do not add & */ - #if defined(NULL) - .p_context = NULL, - #else - .p_context = &NULL, - #endif - .p_extend = &g_timer1_extend, - .cycle_end_ipl = (5), - #if defined(VECTOR_NUMBER_AGT1_INT) - .cycle_end_irq = VECTOR_NUMBER_AGT1_INT, - #else - .cycle_end_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const timer_instance_t g_timer1 = -{ .p_ctrl = &g_timer1_ctrl, .p_cfg = &g_timer1_cfg, .p_api = &g_timer_on_agt }; -agt_instance_ctrl_t g_timer0_ctrl; -const agt_extended_cfg_t g_timer0_extend = -{ .count_source = AGT_CLOCK_PCLKB, - .agto = AGT_PIN_CFG_DISABLED, - .agtoa = AGT_PIN_CFG_DISABLED, - .agtob = AGT_PIN_CFG_DISABLED, - .measurement_mode = AGT_MEASURE_DISABLED, - .agtio_filter = AGT_AGTIO_FILTER_NONE, - .enable_pin = AGT_ENABLE_PIN_NOT_USED, - .trigger_edge = AGT_TRIGGER_EDGE_RISING, }; -const timer_cfg_t g_timer0_cfg = -{ .mode = TIMER_MODE_PERIODIC, -/* Actual period: 0.002730666666666667 seconds. Actual duty: 50%. */ .period_counts = 0x10000, - .duty_cycle_counts = 0x8000, .source_div = (timer_source_div_t)0, .channel = 0, .p_callback = callback_agt, - /** If NULL then do not add & */ - #if defined(NULL) - .p_context = NULL, - #else - .p_context = &NULL, - #endif - .p_extend = &g_timer0_extend, - .cycle_end_ipl = (5), - #if defined(VECTOR_NUMBER_AGT0_INT) - .cycle_end_irq = VECTOR_NUMBER_AGT0_INT, - #else - .cycle_end_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const timer_instance_t g_timer0 = -{ .p_ctrl = &g_timer0_ctrl, .p_cfg = &g_timer0_cfg, .p_api = &g_timer_on_agt }; flash_lp_instance_ctrl_t g_flash0_ctrl; const flash_cfg_t g_flash0_cfg = { .data_flash_bgo = false, .p_callback = NULL, .p_context = NULL, .ipl = (BSP_IRQ_DISABLED), @@ -386,239 +49,3 @@ const flash_cfg_t g_flash0_cfg = /* Instance structure to use this module. */ const flash_instance_t g_flash0 = { .p_ctrl = &g_flash0_ctrl, .p_cfg = &g_flash0_cfg, .p_api = &g_flash_on_flash_lp }; -rtc_instance_ctrl_t g_rtc0_ctrl; -const rtc_error_adjustment_cfg_t g_rtc0_err_cfg = -{ .adjustment_mode = RTC_ERROR_ADJUSTMENT_MODE_AUTOMATIC, - .adjustment_period = RTC_ERROR_ADJUSTMENT_PERIOD_10_SECOND, - .adjustment_type = RTC_ERROR_ADJUSTMENT_NONE, - .adjustment_value = 0, }; -const rtc_cfg_t g_rtc0_cfg = -{ .clock_source = RTC_CLOCK_SOURCE_LOCO, .freq_compare_value_loco = 255, .p_err_cfg = &g_rtc0_err_cfg, .p_callback = - NULL, - .p_context = NULL, .alarm_ipl = (14), .periodic_ipl = (14), .carry_ipl = (14), - #if defined(VECTOR_NUMBER_RTC_ALARM) - .alarm_irq = VECTOR_NUMBER_RTC_ALARM, - #else - .alarm_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_PERIOD) - .periodic_irq = VECTOR_NUMBER_RTC_PERIOD, - #else - .periodic_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_CARRY) - .carry_irq = VECTOR_NUMBER_RTC_CARRY, - #else - .carry_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const rtc_instance_t g_rtc0 = -{ .p_ctrl = &g_rtc0_ctrl, .p_cfg = &g_rtc0_cfg, .p_api = &g_rtc_on_rtc }; -sci_uart_instance_ctrl_t g_uart9_ctrl; - -baud_setting_t g_uart9_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart9_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart9_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart9_cfg = -{ .channel = 9, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart9_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI9_RXI) - .rxi_irq = VECTOR_NUMBER_SCI9_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI9_TXI) - .txi_irq = VECTOR_NUMBER_SCI9_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI9_TEI) - .tei_irq = VECTOR_NUMBER_SCI9_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI9_ERI) - .eri_irq = VECTOR_NUMBER_SCI9_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart9 = -{ .p_ctrl = &g_uart9_ctrl, .p_cfg = &g_uart9_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart4_ctrl; - -baud_setting_t g_uart4_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart4_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart4_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart4_cfg = -{ .channel = 4, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart4_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI4_RXI) - .rxi_irq = VECTOR_NUMBER_SCI4_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI4_TXI) - .txi_irq = VECTOR_NUMBER_SCI4_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI4_TEI) - .tei_irq = VECTOR_NUMBER_SCI4_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI4_ERI) - .eri_irq = VECTOR_NUMBER_SCI4_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart4 = -{ .p_ctrl = &g_uart4_ctrl, .p_cfg = &g_uart4_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart1_ctrl; - -baud_setting_t g_uart1_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart1_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart1_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart1_cfg = -{ .channel = 1, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart1_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI1_RXI) - .rxi_irq = VECTOR_NUMBER_SCI1_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_TXI) - .txi_irq = VECTOR_NUMBER_SCI1_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_TEI) - .tei_irq = VECTOR_NUMBER_SCI1_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_ERI) - .eri_irq = VECTOR_NUMBER_SCI1_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart1 = -{ .p_ctrl = &g_uart1_ctrl, .p_cfg = &g_uart1_cfg, .p_api = &g_uart_on_sci }; -void g_hal_init(void) { - g_common_init(); -} diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h index cf3f00771b..7b1e505f68 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h @@ -2,161 +2,20 @@ #ifndef HAL_DATA_H_ #define HAL_DATA_H_ #include -#include "bsp_api.h" #include "common_data.h" -#include "r_adc.h" -#include "r_adc_api.h" -#include "r_iic_master.h" -#include "r_i2c_master_api.h" #include "r_lpm.h" #include "r_lpm_api.h" -#include "r_dtc.h" -#include "r_transfer_api.h" -#include "r_spi.h" -#include "r_icu.h" -#include "r_external_irq_api.h" -#include "r_agt.h" -#include "r_timer_api.h" #include "r_flash_lp.h" #include "r_flash_api.h" -#include "r_rtc.h" -#include "r_rtc_api.h" -#include "r_sci_uart.h" -#include "r_uart_api.h" FSP_HEADER -/** ADC on ADC Instance. */ -extern const adc_instance_t g_adc0; -/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ -extern adc_instance_ctrl_t g_adc0_ctrl; -extern const adc_cfg_t g_adc0_cfg; -extern const adc_channel_cfg_t g_adc0_channel_cfg; - -#ifndef NULL -void NULL(adc_callback_args_t *p_args); -#endif -/* I2C Master on IIC Instance. */ -extern const i2c_master_instance_t g_i2c_master0; - -/** Access the I2C Master instance using these structures when calling API functions directly (::p_api is not used). */ -extern iic_master_instance_ctrl_t g_i2c_master0_ctrl; -extern const i2c_master_cfg_t g_i2c_master0_cfg; - -#ifndef callback_iic -void callback_iic(i2c_master_callback_args_t *p_args); -#endif /** lpm Instance */ extern const lpm_instance_t g_lpm0; /** Access the LPM instance using these structures when calling API functions directly (::p_api is not used). */ extern lpm_instance_ctrl_t g_lpm0_ctrl; extern const lpm_cfg_t g_lpm0_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer1; -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer1_ctrl; -extern const transfer_cfg_t g_transfer1_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer0; - -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer0_ctrl; -extern const transfer_cfg_t g_transfer0_cfg; -/** SPI on SPI Instance. */ -extern const spi_instance_t g_spi0; - -/** Access the SPI instance using these structures when calling API functions directly (::p_api is not used). */ -extern spi_instance_ctrl_t g_spi0_ctrl; -extern const spi_cfg_t g_spi0_cfg; - -/** Callback used by SPI Instance. */ -#ifndef spi_callback -void spi_callback(spi_callback_args_t *p_args); -#endif - -#define RA_NOT_DEFINED (1) -#if (RA_NOT_DEFINED == g_transfer0) - #define g_spi0_P_TRANSFER_TX (NULL) -#else -#define g_spi0_P_TRANSFER_TX (&g_transfer0) -#endif -#if (RA_NOT_DEFINED == g_transfer1) - #define g_spi0_P_TRANSFER_RX (NULL) -#else -#define g_spi0_P_TRANSFER_RX (&g_transfer1) -#endif -#undef RA_NOT_DEFINED -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq4; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq4_ctrl; -extern const external_irq_cfg_t g_external_irq4_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq3; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq3_ctrl; -extern const external_irq_cfg_t g_external_irq3_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq2; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq2_ctrl; -extern const external_irq_cfg_t g_external_irq2_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq1; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq1_ctrl; -extern const external_irq_cfg_t g_external_irq1_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq0; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq0_ctrl; -extern const external_irq_cfg_t g_external_irq0_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** AGT Timer Instance */ -extern const timer_instance_t g_timer1; - -/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ -extern agt_instance_ctrl_t g_timer1_ctrl; -extern const timer_cfg_t g_timer1_cfg; - -#ifndef callback_agt -void callback_agt(timer_callback_args_t *p_args); -#endif -/** AGT Timer Instance */ -extern const timer_instance_t g_timer0; - -/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ -extern agt_instance_ctrl_t g_timer0_ctrl; -extern const timer_cfg_t g_timer0_cfg; - -#ifndef callback_agt -void callback_agt(timer_callback_args_t *p_args); -#endif /* Flash on Flash LP Instance. */ extern const flash_instance_t g_flash0; @@ -167,50 +26,8 @@ extern const flash_cfg_t g_flash0_cfg; #ifndef NULL void NULL(flash_callback_args_t *p_args); #endif -/* RTC Instance. */ -extern const rtc_instance_t g_rtc0; -/** Access the RTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern rtc_instance_ctrl_t g_rtc0_ctrl; -extern const rtc_cfg_t g_rtc0_cfg; - -#ifndef NULL -void NULL(rtc_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart9; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart9_ctrl; -extern const uart_cfg_t g_uart9_cfg; -extern const sci_uart_extended_cfg_t g_uart9_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart4; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart4_ctrl; -extern const uart_cfg_t g_uart4_cfg; -extern const sci_uart_extended_cfg_t g_uart4_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart1; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart1_ctrl; -extern const uart_cfg_t g_uart1_cfg; -extern const sci_uart_extended_cfg_t g_uart1_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif void hal_entry(void); -void g_hal_init(void); + FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/pin_data.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/pin_data.c index 2a5a8764c5..7e318319e5 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/pin_data.c +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/pin_data.c @@ -1,69 +1,74 @@ /* generated pin source file - do not edit */ #include "bsp_api.h" #include "r_ioport_api.h" -const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = { - { - .pin = BSP_IO_PORT_01_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_03, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH), - }, - { - .pin = BSP_IO_PORT_01_PIN_06, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH), - }, - { - .pin = BSP_IO_PORT_01_PIN_09, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_01_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_01_PIN_11, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH), - }, - { - .pin = BSP_IO_PORT_02_PIN_04, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH), - }, - { - .pin = BSP_IO_PORT_02_PIN_05, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_02_PIN_06, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_02_PIN_12, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_02_PIN_13, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_04_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), - }, - { - .pin = BSP_IO_PORT_04_PIN_04, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH), - }, -}; -const ioport_cfg_t g_bsp_pin_cfg = { - .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), - .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], + +const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = +{ + { .pin = BSP_IO_PORT_01_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_03, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH) }, + { .pin = BSP_IO_PORT_01_PIN_06, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH) }, + { .pin = BSP_IO_PORT_01_PIN_09, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_01_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_01_PIN_11, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH) }, + { .pin = BSP_IO_PORT_02_PIN_04, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH) }, + { .pin = BSP_IO_PORT_02_PIN_05, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_02_PIN_06, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_02_PIN_12, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_02_PIN_13, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_04_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, + { .pin = BSP_IO_PORT_04_PIN_04, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_HIGH) }, }; + +const ioport_cfg_t g_bsp_pin_cfg = +{ .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], }; + +#if BSP_TZ_SECURE_BUILD + +void R_BSP_PinCfgSecurityInit(void); + +/* Initialize SAR registers for secure pins. */ +void R_BSP_PinCfgSecurityInit(void) { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + uint32_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #else + uint16_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #endif + memset(pmsar, 0xFF, BSP_FEATURE_BSP_NUM_PMSAR * sizeof(R_PMISC->PMSAR[0])); + + + for (uint32_t i = 0; i < g_bsp_pin_cfg.number_of_pins; i++) + { + uint32_t port_pin = g_bsp_pin_cfg.p_pin_cfg_data[i].pin; + uint32_t port = port_pin >> 8U; + uint32_t pin = port_pin & 0xFFU; + pmsar[port] &= (uint16_t) ~(1U << pin); + } + + for (uint32_t i = 0; i < BSP_FEATURE_BSP_NUM_PMSAR; i++) + { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + R_PMISC->PMSAR[i].PMSAR = (uint16_t)pmsar[i]; + #else + R_PMISC->PMSAR[i].PMSAR = pmsar[i]; + #endif + } + +} +#endif diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.c index 1867e73836..18986d0ae7 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.c +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.c @@ -14,26 +14,26 @@ BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BS [7] = sci_uart_eri_isr, /* SCI4 ERI (Receive error) */ [8] = sci_uart_rxi_isr, /* SCI9 RXI (Received data full) */ [9] = sci_uart_txi_isr, /* SCI9 TXI (Transmit data empty) */ - [10] = sci_uart_tei_isr, /* SCI9 TEI (Transmit end) */ - [11] = sci_uart_eri_isr, /* SCI9 ERI (Receive error) */ - [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ - [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ - [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ - [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ - [16] = agt_int_isr, /* AGT1 INT (AGT interrupt) */ - [17] = r_icu_isr, /* ICU IRQ0 (External pin interrupt 0) */ - [18] = r_icu_isr, /* ICU IRQ1 (External pin interrupt 1) */ - [19] = r_icu_isr, /* ICU IRQ2 (External pin interrupt 2) */ - [20] = r_icu_isr, /* ICU IRQ3 (External pin interrupt 3) */ - [21] = r_icu_isr, /* ICU IRQ4 (External pin interrupt 4) */ - [22] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ - [23] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ - [24] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ - [25] = spi_eri_isr, /* SPI0 ERI (Error) */ - [26] = iic_master_rxi_isr, /* IIC0 RXI (Receive data full) */ - [27] = iic_master_txi_isr, /* IIC0 TXI (Transmit data empty) */ - [28] = iic_master_tei_isr, /* IIC0 TEI (Transmit end) */ - [29] = iic_master_eri_isr, /* IIC0 ERI (Transfer error) */ + [10] = sci_uart_tei_isr, /* SCI9 TEI (Transmit end) */ + [11] = sci_uart_eri_isr, /* SCI9 ERI (Receive error) */ + [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ + [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ + [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ + [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ + [16] = agt_int_isr, /* AGT1 INT (AGT interrupt) */ + [17] = r_icu_isr, /* ICU IRQ0 (External pin interrupt 0) */ + [18] = r_icu_isr, /* ICU IRQ1 (External pin interrupt 1) */ + [19] = r_icu_isr, /* ICU IRQ2 (External pin interrupt 2) */ + [20] = r_icu_isr, /* ICU IRQ3 (External pin interrupt 3) */ + [21] = r_icu_isr, /* ICU IRQ4 (External pin interrupt 4) */ + [22] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ + [23] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ + [24] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ + [25] = spi_eri_isr, /* SPI0 ERI (Error) */ + [26] = iic_master_rxi_isr, /* IIC0 RXI (Receive data full) */ + [27] = iic_master_txi_isr, /* IIC0 TXI (Transmit data empty) */ + [28] = iic_master_tei_isr, /* IIC0 TEI (Transmit end) */ + [29] = iic_master_eri_isr, /* IIC0 ERI (Transfer error) */ }; const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = { @@ -47,25 +47,25 @@ const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENT [7] = BSP_PRV_IELS_ENUM(EVENT_SCI4_ERI), /* SCI4 ERI (Receive error) */ [8] = BSP_PRV_IELS_ENUM(EVENT_SCI9_RXI), /* SCI9 RXI (Received data full) */ [9] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TXI), /* SCI9 TXI (Transmit data empty) */ - [10] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TEI), /* SCI9 TEI (Transmit end) */ - [11] = BSP_PRV_IELS_ENUM(EVENT_SCI9_ERI), /* SCI9 ERI (Receive error) */ - [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ - [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ - [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ - [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ - [16] = BSP_PRV_IELS_ENUM(EVENT_AGT1_INT), /* AGT1 INT (AGT interrupt) */ - [17] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ0), /* ICU IRQ0 (External pin interrupt 0) */ - [18] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ1), /* ICU IRQ1 (External pin interrupt 1) */ - [19] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ2), /* ICU IRQ2 (External pin interrupt 2) */ - [20] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ3), /* ICU IRQ3 (External pin interrupt 3) */ - [21] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ4), /* ICU IRQ4 (External pin interrupt 4) */ - [22] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ - [23] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ - [24] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ - [25] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ - [26] = BSP_PRV_IELS_ENUM(EVENT_IIC0_RXI), /* IIC0 RXI (Receive data full) */ - [27] = BSP_PRV_IELS_ENUM(EVENT_IIC0_TXI), /* IIC0 TXI (Transmit data empty) */ - [28] = BSP_PRV_IELS_ENUM(EVENT_IIC0_TEI), /* IIC0 TEI (Transmit end) */ - [29] = BSP_PRV_IELS_ENUM(EVENT_IIC0_ERI), /* IIC0 ERI (Transfer error) */ + [10] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TEI), /* SCI9 TEI (Transmit end) */ + [11] = BSP_PRV_IELS_ENUM(EVENT_SCI9_ERI), /* SCI9 ERI (Receive error) */ + [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ + [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ + [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ + [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ + [16] = BSP_PRV_IELS_ENUM(EVENT_AGT1_INT), /* AGT1 INT (AGT interrupt) */ + [17] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ0), /* ICU IRQ0 (External pin interrupt 0) */ + [18] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ1), /* ICU IRQ1 (External pin interrupt 1) */ + [19] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ2), /* ICU IRQ2 (External pin interrupt 2) */ + [20] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ3), /* ICU IRQ3 (External pin interrupt 3) */ + [21] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ4), /* ICU IRQ4 (External pin interrupt 4) */ + [22] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ + [23] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ + [24] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ + [25] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ + [26] = BSP_PRV_IELS_ENUM(EVENT_IIC0_RXI), /* IIC0 RXI (Receive data full) */ + [27] = BSP_PRV_IELS_ENUM(EVENT_IIC0_TXI), /* IIC0 TXI (Transmit data empty) */ + [28] = BSP_PRV_IELS_ENUM(EVENT_IIC0_TEI), /* IIC0 TEI (Transmit end) */ + [29] = BSP_PRV_IELS_ENUM(EVENT_IIC0_ERI), /* IIC0 ERI (Transfer error) */ }; #endif diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.h index c45ef8d959..a4adf6ab0e 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/vector_data.h @@ -1,6 +1,9 @@ /* generated vector header file - do not edit */ #ifndef VECTOR_DATA_H #define VECTOR_DATA_H +#ifdef __cplusplus +extern "C" { +#endif /* Number of interrupts allocated */ #ifndef VECTOR_DATA_IRQ_COUNT #define VECTOR_DATA_IRQ_COUNT (30) @@ -25,77 +28,66 @@ void iic_master_eri_isr(void); /* Vector table allocations */ #define VECTOR_NUMBER_SCI1_RXI ((IRQn_Type)0) /* SCI1 RXI (Received data full) */ +#define SCI1_RXI_IRQn ((IRQn_Type)0) /* SCI1 RXI (Received data full) */ #define VECTOR_NUMBER_SCI1_TXI ((IRQn_Type)1) /* SCI1 TXI (Transmit data empty) */ +#define SCI1_TXI_IRQn ((IRQn_Type)1) /* SCI1 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI1_TEI ((IRQn_Type)2) /* SCI1 TEI (Transmit end) */ +#define SCI1_TEI_IRQn ((IRQn_Type)2) /* SCI1 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI1_ERI ((IRQn_Type)3) /* SCI1 ERI (Receive error) */ +#define SCI1_ERI_IRQn ((IRQn_Type)3) /* SCI1 ERI (Receive error) */ #define VECTOR_NUMBER_SCI4_RXI ((IRQn_Type)4) /* SCI4 RXI (Received data full) */ +#define SCI4_RXI_IRQn ((IRQn_Type)4) /* SCI4 RXI (Received data full) */ #define VECTOR_NUMBER_SCI4_TXI ((IRQn_Type)5) /* SCI4 TXI (Transmit data empty) */ +#define SCI4_TXI_IRQn ((IRQn_Type)5) /* SCI4 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI4_TEI ((IRQn_Type)6) /* SCI4 TEI (Transmit end) */ +#define SCI4_TEI_IRQn ((IRQn_Type)6) /* SCI4 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI4_ERI ((IRQn_Type)7) /* SCI4 ERI (Receive error) */ +#define SCI4_ERI_IRQn ((IRQn_Type)7) /* SCI4 ERI (Receive error) */ #define VECTOR_NUMBER_SCI9_RXI ((IRQn_Type)8) /* SCI9 RXI (Received data full) */ +#define SCI9_RXI_IRQn ((IRQn_Type)8) /* SCI9 RXI (Received data full) */ #define VECTOR_NUMBER_SCI9_TXI ((IRQn_Type)9) /* SCI9 TXI (Transmit data empty) */ +#define SCI9_TXI_IRQn ((IRQn_Type)9) /* SCI9 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI9_TEI ((IRQn_Type)10) /* SCI9 TEI (Transmit end) */ +#define SCI9_TEI_IRQn ((IRQn_Type)10) /* SCI9 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI9_ERI ((IRQn_Type)11) /* SCI9 ERI (Receive error) */ +#define SCI9_ERI_IRQn ((IRQn_Type)11) /* SCI9 ERI (Receive error) */ #define VECTOR_NUMBER_RTC_ALARM ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ +#define RTC_ALARM_IRQn ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ #define VECTOR_NUMBER_RTC_PERIOD ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ +#define RTC_PERIOD_IRQn ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ #define VECTOR_NUMBER_RTC_CARRY ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ +#define RTC_CARRY_IRQn ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ #define VECTOR_NUMBER_AGT0_INT ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ +#define AGT0_INT_IRQn ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ #define VECTOR_NUMBER_AGT1_INT ((IRQn_Type)16) /* AGT1 INT (AGT interrupt) */ +#define AGT1_INT_IRQn ((IRQn_Type)16) /* AGT1 INT (AGT interrupt) */ #define VECTOR_NUMBER_ICU_IRQ0 ((IRQn_Type)17) /* ICU IRQ0 (External pin interrupt 0) */ +#define ICU_IRQ0_IRQn ((IRQn_Type)17) /* ICU IRQ0 (External pin interrupt 0) */ #define VECTOR_NUMBER_ICU_IRQ1 ((IRQn_Type)18) /* ICU IRQ1 (External pin interrupt 1) */ +#define ICU_IRQ1_IRQn ((IRQn_Type)18) /* ICU IRQ1 (External pin interrupt 1) */ #define VECTOR_NUMBER_ICU_IRQ2 ((IRQn_Type)19) /* ICU IRQ2 (External pin interrupt 2) */ +#define ICU_IRQ2_IRQn ((IRQn_Type)19) /* ICU IRQ2 (External pin interrupt 2) */ #define VECTOR_NUMBER_ICU_IRQ3 ((IRQn_Type)20) /* ICU IRQ3 (External pin interrupt 3) */ +#define ICU_IRQ3_IRQn ((IRQn_Type)20) /* ICU IRQ3 (External pin interrupt 3) */ #define VECTOR_NUMBER_ICU_IRQ4 ((IRQn_Type)21) /* ICU IRQ4 (External pin interrupt 4) */ +#define ICU_IRQ4_IRQn ((IRQn_Type)21) /* ICU IRQ4 (External pin interrupt 4) */ #define VECTOR_NUMBER_SPI0_RXI ((IRQn_Type)22) /* SPI0 RXI (Receive buffer full) */ +#define SPI0_RXI_IRQn ((IRQn_Type)22) /* SPI0 RXI (Receive buffer full) */ #define VECTOR_NUMBER_SPI0_TXI ((IRQn_Type)23) /* SPI0 TXI (Transmit buffer empty) */ +#define SPI0_TXI_IRQn ((IRQn_Type)23) /* SPI0 TXI (Transmit buffer empty) */ #define VECTOR_NUMBER_SPI0_TEI ((IRQn_Type)24) /* SPI0 TEI (Transmission complete event) */ +#define SPI0_TEI_IRQn ((IRQn_Type)24) /* SPI0 TEI (Transmission complete event) */ #define VECTOR_NUMBER_SPI0_ERI ((IRQn_Type)25) /* SPI0 ERI (Error) */ +#define SPI0_ERI_IRQn ((IRQn_Type)25) /* SPI0 ERI (Error) */ #define VECTOR_NUMBER_IIC0_RXI ((IRQn_Type)26) /* IIC0 RXI (Receive data full) */ +#define IIC0_RXI_IRQn ((IRQn_Type)26) /* IIC0 RXI (Receive data full) */ #define VECTOR_NUMBER_IIC0_TXI ((IRQn_Type)27) /* IIC0 TXI (Transmit data empty) */ +#define IIC0_TXI_IRQn ((IRQn_Type)27) /* IIC0 TXI (Transmit data empty) */ #define VECTOR_NUMBER_IIC0_TEI ((IRQn_Type)28) /* IIC0 TEI (Transmit end) */ +#define IIC0_TEI_IRQn ((IRQn_Type)28) /* IIC0 TEI (Transmit end) */ #define VECTOR_NUMBER_IIC0_ERI ((IRQn_Type)29) /* IIC0 ERI (Transfer error) */ -typedef enum IRQn -{ - Reset_IRQn = -15, - NonMaskableInt_IRQn = -14, - HardFault_IRQn = -13, - MemoryManagement_IRQn = -12, - BusFault_IRQn = -11, - UsageFault_IRQn = -10, - SecureFault_IRQn = -9, - SVCall_IRQn = -5, - DebugMonitor_IRQn = -4, - PendSV_IRQn = -2, - SysTick_IRQn = -1, - SCI1_RXI_IRQn = 0, /* SCI1 RXI (Received data full) */ - SCI1_TXI_IRQn = 1, /* SCI1 TXI (Transmit data empty) */ - SCI1_TEI_IRQn = 2, /* SCI1 TEI (Transmit end) */ - SCI1_ERI_IRQn = 3, /* SCI1 ERI (Receive error) */ - SCI4_RXI_IRQn = 4, /* SCI4 RXI (Received data full) */ - SCI4_TXI_IRQn = 5, /* SCI4 TXI (Transmit data empty) */ - SCI4_TEI_IRQn = 6, /* SCI4 TEI (Transmit end) */ - SCI4_ERI_IRQn = 7, /* SCI4 ERI (Receive error) */ - SCI9_RXI_IRQn = 8, /* SCI9 RXI (Received data full) */ - SCI9_TXI_IRQn = 9, /* SCI9 TXI (Transmit data empty) */ - SCI9_TEI_IRQn = 10, /* SCI9 TEI (Transmit end) */ - SCI9_ERI_IRQn = 11, /* SCI9 ERI (Receive error) */ - RTC_ALARM_IRQn = 12, /* RTC ALARM (Alarm interrupt) */ - RTC_PERIOD_IRQn = 13, /* RTC PERIOD (Periodic interrupt) */ - RTC_CARRY_IRQn = 14, /* RTC CARRY (Carry interrupt) */ - AGT0_INT_IRQn = 15, /* AGT0 INT (AGT interrupt) */ - AGT1_INT_IRQn = 16, /* AGT1 INT (AGT interrupt) */ - ICU_IRQ0_IRQn = 17, /* ICU IRQ0 (External pin interrupt 0) */ - ICU_IRQ1_IRQn = 18, /* ICU IRQ1 (External pin interrupt 1) */ - ICU_IRQ2_IRQn = 19, /* ICU IRQ2 (External pin interrupt 2) */ - ICU_IRQ3_IRQn = 20, /* ICU IRQ3 (External pin interrupt 3) */ - ICU_IRQ4_IRQn = 21, /* ICU IRQ4 (External pin interrupt 4) */ - SPI0_RXI_IRQn = 22, /* SPI0 RXI (Receive buffer full) */ - SPI0_TXI_IRQn = 23, /* SPI0 TXI (Transmit buffer empty) */ - SPI0_TEI_IRQn = 24, /* SPI0 TEI (Transmission complete event) */ - SPI0_ERI_IRQn = 25, /* SPI0 ERI (Error) */ - IIC0_RXI_IRQn = 26, /* IIC0 RXI (Receive data full) */ - IIC0_TXI_IRQn = 27, /* IIC0 TXI (Transmit data empty) */ - IIC0_TEI_IRQn = 28, /* IIC0 TEI (Transmit end) */ - IIC0_ERI_IRQn = 29, /* IIC0 ERI (Transfer error) */ -} IRQn_Type; +#define IIC0_ERI_IRQn ((IRQn_Type)29) /* IIC0 ERI (Transfer error) */ +#ifdef __cplusplus +} +#endif #endif /* VECTOR_DATA_H */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h index 54b41a45d4..0dcada794a 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_CFG_H_ #define BSP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_clock_cfg.h" #include "bsp_mcu_family_cfg.h" #include "board_cfg.h" @@ -14,7 +18,13 @@ #define BSP_CFG_RTOS (0) #endif #endif +#ifndef BSP_CFG_RTC_USED +#define BSP_CFG_RTC_USED (1) +#endif #undef RA_NOT_DEFINED +#if defined(_RA_BOOT_IMAGE) +#define BSP_CFG_BOOT_IMAGE (1) +#endif #define BSP_CFG_MCU_VCC_MV (3300) #define BSP_CFG_STACK_MAIN_BYTES (0x4000) #define BSP_CFG_HEAP_BYTES (0x2d000) @@ -25,15 +35,14 @@ #define BSP_CFG_PFS_PROTECT ((1)) #define BSP_CFG_C_RUNTIME_INIT ((1)) +#define BSP_CFG_EARLY_INIT ((0)) -#define BSP_CFG_SOFT_RESET_SUPPORTED ((0)) +#define BSP_CFG_STARTUP_CLOCK_REG_NOT_RESET ((0)) #ifndef BSP_CLOCK_CFG_MAIN_OSC_POPULATED #define BSP_CLOCK_CFG_MAIN_OSC_POPULATED (1) #endif -#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT -#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) -#endif + #ifndef BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE #define BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE (0) #endif @@ -46,4 +55,8 @@ #ifndef BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS #define BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS 1000 #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h index 5fc7730d2d..40bb3a3bfc 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h @@ -2,6 +2,7 @@ #ifndef BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_R7FA6M1AD3CFP +#define BSP_MCU_FEATURE_SET ('A') #define BSP_ROM_SIZE_BYTES (524288) #define BSP_RAM_SIZE_BYTES (262144) #define BSP_DATA_FLASH_SIZE_BYTES (8192) diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h index 720eee2d7f..c299ef1704 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_MCU_FAMILY_CFG_H_ #define BSP_MCU_FAMILY_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_mcu_device_pn_cfg.h" #include "bsp_mcu_device_cfg.h" #include "../../../ra/fsp/src/bsp/mcu/ra6m1/bsp_mcu_info.h" @@ -23,7 +27,6 @@ #define BSP_CORTEX_VECTOR_TABLE_ENTRIES (16U) #define BSP_VECTOR_TABLE_MAX_ENTRIES (112U) -#define BSP_MCU_VBATT_SUPPORT (1) #define OFS_SEQ1 0xA001A001 | (1 << 1) | (3 << 2) #define OFS_SEQ2 (15 << 4) | (3 << 8) | (3 << 10) @@ -50,7 +53,9 @@ #define BSP_CFG_ROM_REG_MPU_REGION3_ENABLE (1) #define BSP_CFG_ROM_REG_MPU_REGION3_START (0x400DFFFC) #define BSP_CFG_ROM_REG_MPU_REGION3_END (0x400DFFFF) - +#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT +#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) +#endif /* Used to create IELS values for the interrupt initialization table g_interrupt_event_link_select. */ #define BSP_PRV_IELS_ENUM(vector) (ELC_##vector) @@ -71,4 +76,8 @@ #define BSP_CFG_ID_CODE_LONG_3 (0xFFFFFFFF) #define BSP_CFG_ID_CODE_LONG_4 (0xffFFFFFF) #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_MCU_FAMILY_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_adc_cfg.h index 9c59889ca8..be8a427206 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_adc_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_adc_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_ADC_CFG_H_ #define R_ADC_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define ADC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_ADC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_agt_cfg.h deleted file mode 100644 index d3ab559238..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_agt_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_AGT_CFG_H_ -#define R_AGT_CFG_H_ -#define AGT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define AGT_CFG_OUTPUT_SUPPORT_ENABLE (0) -#define AGT_CFG_INPUT_SUPPORT_ENABLE (0) -#endif /* R_AGT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_dtc_cfg.h deleted file mode 100644 index 21405f9674..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_dtc_cfg.h +++ /dev/null @@ -1,6 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_DTC_CFG_H_ -#define R_DTC_CFG_H_ -#define DTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define DTC_CFG_VECTOR_TABLE_SECTION_NAME ".fsp_dtc_vector_table" -#endif /* R_DTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_flash_hp_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_flash_hp_cfg.h index 48c9dec4e0..9f7819b71a 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_flash_hp_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_flash_hp_cfg.h @@ -1,7 +1,15 @@ /* generated configuration header file - do not edit */ #ifndef R_FLASH_HP_CFG_H_ #define R_FLASH_HP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define FLASH_HP_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) #define FLASH_HP_CFG_CODE_FLASH_PROGRAMMING_ENABLE (1) #define FLASH_HP_CFG_DATA_FLASH_PROGRAMMING_ENABLE (0) + +#ifdef __cplusplus +} +#endif #endif /* R_FLASH_HP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_icu_cfg.h deleted file mode 100644 index 5e77b6980f..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_icu_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_ICU_CFG_H_ -#define R_ICU_CFG_H_ -#define ICU_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_ICU_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_iic_master_cfg.h deleted file mode 100644 index 595ea938d1..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_iic_master_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_IIC_MASTER_CFG_H_ -#define R_IIC_MASTER_CFG_H_ -#define IIC_MASTER_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define IIC_MASTER_CFG_DTC_ENABLE (0) -#define IIC_MASTER_CFG_ADDR_MODE_10_BIT_ENABLE (0) -#endif /* R_IIC_MASTER_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_ioport_cfg.h index 6b4353d238..d2688bf5ba 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_ioport_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_ioport_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_IOPORT_CFG_H_ #define R_IOPORT_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define IOPORT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_IOPORT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_lpm_cfg.h index 5f4d5c4a73..6712eee6a1 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_lpm_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_lpm_cfg.h @@ -1,5 +1,14 @@ /* generated configuration header file - do not edit */ #ifndef R_LPM_CFG_H_ #define R_LPM_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define LPM_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define LPM_CFG_STANDBY_LIMIT (0) + +#ifdef __cplusplus +} +#endif #endif /* R_LPM_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_rtc_cfg.h deleted file mode 100644 index 484b7ed044..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_rtc_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_RTC_CFG_H_ -#define R_RTC_CFG_H_ -#define RTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_RTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h deleted file mode 100644 index c70c0be344..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_sci_uart_cfg.h +++ /dev/null @@ -1,8 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SCI_UART_CFG_H_ -#define R_SCI_UART_CFG_H_ -#define SCI_UART_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SCI_UART_CFG_FIFO_SUPPORT (0) -#define SCI_UART_CFG_DTC_SUPPORTED (0) -#define SCI_UART_CFG_FLOW_CONTROL_SUPPORT (0) -#endif /* R_SCI_UART_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_spi_cfg.h deleted file mode 100644 index 861fe12194..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_cfg/fsp_cfg/r_spi_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SPI_CFG_H_ -#define R_SPI_CFG_H_ -#define SPI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SPI_DTC_SUPPORT_ENABLE (1) -#define SPI_TRANSMIT_FROM_RXI_ISR (0) -#endif /* R_SPI_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/bsp_clock_cfg.h index 013621000b..c9775187a0 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/bsp_clock_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/bsp_clock_cfg.h @@ -7,7 +7,7 @@ #define BSP_CFG_PLL_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_MAIN_OSC) /* PLL Src: XTAL */ #define BSP_CFG_HOCO_FREQUENCY (2) /* HOCO 20MHz */ #define BSP_CFG_PLL_DIV (BSP_CLOCKS_PLL_DIV_1) /* PLL Div /1 */ -#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL_20_0 /* PLL Mul x20.0 */ +#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL(20U, 0U) /* PLL Mul x20.0 */ #define BSP_CFG_CLOCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_PLL) /* Clock Src: PLL */ #define BSP_CFG_ICLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* ICLK Div /2 */ #define BSP_CFG_PCLKA_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* PCLKA Div /2 */ @@ -15,7 +15,7 @@ #define BSP_CFG_PCLKC_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_4) /* PCLKC Div /4 */ #define BSP_CFG_PCLKD_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* PCLKD Div /2 */ #define BSP_CFG_BCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* BCLK Div /2 */ -#define BSP_CFG_BCLK_OUTPUT (2) /* BCK/2 */ +#define BSP_CFG_BCLK_OUTPUT (2) /* EBCLK Div /2 */ #define BSP_CFG_UCK_DIV (BSP_CLOCKS_USB_CLOCK_DIV_5) /* UCLK Div /5 */ #define BSP_CFG_FCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_4) /* FCLK Div /4 */ #define BSP_CFG_CLKOUT_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* CLKOUT Disabled */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.c index 34aad762ff..ceee4985ec 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.c +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.c @@ -1,7 +1,4 @@ -/* generated common source file - do not edit */ #include "common_data.h" ioport_instance_ctrl_t g_ioport_ctrl; const ioport_instance_t g_ioport = { .p_api = &g_ioport_on_ioport, .p_ctrl = &g_ioport_ctrl, .p_cfg = &g_bsp_pin_cfg, }; -void g_common_init(void) { -} diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.h index e2eb70836b..3a764eda7b 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/common_data.h @@ -3,14 +3,16 @@ #define COMMON_DATA_H_ #include #include "bsp_api.h" +#include "r_icu.h" +#include "r_external_irq_api.h" #include "r_ioport.h" #include "bsp_pin_cfg.h" FSP_HEADER + /* IOPORT Instance */ extern const ioport_instance_t g_ioport; /* IOPORT control structure. */ extern ioport_instance_ctrl_t g_ioport_ctrl; -void g_common_init(void); FSP_FOOTER #endif /* COMMON_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.c index 56f1735118..bfc382ec14 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.c +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.c @@ -1,131 +1,15 @@ -/* generated HAL source file - do not edit */ #include "hal_data.h" -/* Macros to tie dynamic ELC links to ADC_TRIGGER_SYNC_ELC option in adc_trigger_t. */ -#define ADC_TRIGGER_ADC0 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC0_B ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1_B ADC_TRIGGER_SYNC_ELC -adc_instance_ctrl_t g_adc1_ctrl; -const adc_extended_cfg_t g_adc1_cfg_extend = -{ .add_average_count = ADC_ADD_OFF, - .clearing = ADC_CLEAR_AFTER_READ_ON, - .trigger_group_b = ADC_TRIGGER_SYNC_ELC, - .double_trigger_mode = ADC_DOUBLE_TRIGGER_DISABLED, - .adc_vref_control = ADC_VREF_CONTROL_VREFH, }; -const adc_cfg_t g_adc1_cfg = -{ .unit = 1, .mode = ADC_MODE_SINGLE_SCAN, .resolution = ADC_RESOLUTION_12_BIT, .alignment = - (adc_alignment_t)ADC_ALIGNMENT_RIGHT, - .trigger = ADC_TRIGGER_SOFTWARE, .p_callback = NULL, .p_context = NULL, .p_extend = &g_adc1_cfg_extend, - #if defined(VECTOR_NUMBER_ADC1_SCAN_END) - .scan_end_irq = VECTOR_NUMBER_ADC1_SCAN_END, - #else - .scan_end_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_ipl = (BSP_IRQ_DISABLED), - #if defined(VECTOR_NUMBER_ADC1_SCAN_END_B) - .scan_end_b_irq = VECTOR_NUMBER_ADC1_SCAN_END_B, - #else - .scan_end_b_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; -const adc_channel_cfg_t g_adc1_channel_cfg = -{ .scan_mask = 0, - .scan_mask_group_b = 0, - .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, - .add_mask = 0, - .sample_hold_mask = 0, - .sample_hold_states = 24, }; -/* Instance structure to use this module. */ -const adc_instance_t g_adc1 = -{ .p_ctrl = &g_adc1_ctrl, .p_cfg = &g_adc1_cfg, .p_channel_cfg = &g_adc1_channel_cfg, .p_api = &g_adc_on_adc }; -iic_master_instance_ctrl_t g_i2c_master0_ctrl; -const iic_master_extended_cfg_t g_i2c_master0_extend = -{ .timeout_mode = IIC_MASTER_TIMEOUT_MODE_SHORT, -/* Actual calculated bitrate: 98945. Actual calculated duty cycle: 51%. */ .clock_settings.brl_value = 15, - .clock_settings.brh_value = 16, .clock_settings.cks_value = 4, }; -const i2c_master_cfg_t g_i2c_master0_cfg = -{ .channel = 0, .rate = I2C_MASTER_RATE_STANDARD, .slave = 0x00, .addr_mode = I2C_MASTER_ADDR_MODE_7BIT, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .p_callback = callback_iic, - .p_context = NULL, - #if defined(VECTOR_NUMBER_IIC0_RXI) - .rxi_irq = VECTOR_NUMBER_IIC0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC0_TXI) - .txi_irq = VECTOR_NUMBER_IIC0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC0_TEI) - .tei_irq = VECTOR_NUMBER_IIC0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC0_ERI) - .eri_irq = VECTOR_NUMBER_IIC0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - .ipl = (12), - .p_extend = &g_i2c_master0_extend, }; -/* Instance structure to use this module. */ -const i2c_master_instance_t g_i2c_master0 = -{ .p_ctrl = &g_i2c_master0_ctrl, .p_cfg = &g_i2c_master0_cfg, .p_api = &g_i2c_master_on_iic }; -adc_instance_ctrl_t g_adc0_ctrl; -const adc_extended_cfg_t g_adc0_cfg_extend = -{ .add_average_count = ADC_ADD_OFF, - .clearing = ADC_CLEAR_AFTER_READ_ON, - .trigger_group_b = ADC_TRIGGER_SYNC_ELC, - .double_trigger_mode = ADC_DOUBLE_TRIGGER_DISABLED, - .adc_vref_control = ADC_VREF_CONTROL_VREFH, }; -const adc_cfg_t g_adc0_cfg = -{ .unit = 0, .mode = ADC_MODE_SINGLE_SCAN, .resolution = ADC_RESOLUTION_12_BIT, .alignment = - (adc_alignment_t)ADC_ALIGNMENT_RIGHT, - .trigger = ADC_TRIGGER_SOFTWARE, .p_callback = NULL, .p_context = NULL, .p_extend = &g_adc0_cfg_extend, - #if defined(VECTOR_NUMBER_ADC0_SCAN_END) - .scan_end_irq = VECTOR_NUMBER_ADC0_SCAN_END, - #else - .scan_end_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_ipl = (BSP_IRQ_DISABLED), - #if defined(VECTOR_NUMBER_ADC0_SCAN_END_B) - .scan_end_b_irq = VECTOR_NUMBER_ADC0_SCAN_END_B, - #else - .scan_end_b_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; -const adc_channel_cfg_t g_adc0_channel_cfg = -{ .scan_mask = 0, - .scan_mask_group_b = 0, - .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, - .add_mask = 0, - .sample_hold_mask = 0, - .sample_hold_states = 24, }; -/* Instance structure to use this module. */ -const adc_instance_t g_adc0 = -{ .p_ctrl = &g_adc0_ctrl, .p_cfg = &g_adc0_cfg, .p_channel_cfg = &g_adc0_channel_cfg, .p_api = &g_adc_on_adc }; lpm_instance_ctrl_t g_lpm0_ctrl; const lpm_cfg_t g_lpm0_cfg = -{ .low_power_mode = LPM_MODE_SLEEP, +{ .low_power_mode = LPM_MODE_SLEEP, .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM + | (lpm_standby_wake_source_t)0, + #if BSP_FEATURE_LPM_HAS_SNOOZE .snooze_cancel_sources = LPM_SNOOZE_CANCEL_SOURCE_NONE, - .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM | (lpm_standby_wake_source_t)0, .snooze_request_source = LPM_SNOOZE_REQUEST_RXD0_FALLING, .snooze_end_sources = (lpm_snooze_end_t)0, .dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE, + #endif #if BSP_FEATURE_LPM_HAS_SBYCR_OPE .output_port_enable = LPM_OUTPUT_PORT_ENABLE_RETAIN, #endif @@ -135,449 +19,23 @@ const lpm_cfg_t g_lpm0_cfg = .deep_standby_cancel_source = (lpm_deep_standby_cancel_source_t)0, .deep_standby_cancel_edge = (lpm_deep_standby_cancel_edge_t)0, #endif + #if BSP_FEATURE_LPM_HAS_PDRAMSCR + .ram_retention_cfg.ram_retention = (uint8_t)(0), + .ram_retention_cfg.tcm_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_DPSBYCR_SRKEEP + .ram_retention_cfg.standby_ram_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_LDO_CONTROL + .ldo_standby_cfg.pll1_ldo = false, + .ldo_standby_cfg.pll2_ldo = false, + .ldo_standby_cfg.hoco_ldo = false, + #endif .p_extend = NULL, }; const lpm_instance_t g_lpm0 = { .p_api = &g_lpm_on_lpm, .p_ctrl = &g_lpm0_ctrl, .p_cfg = &g_lpm0_cfg }; -dtc_instance_ctrl_t g_transfer1_ctrl; -transfer_info_t g_transfer1_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .repeat_area = TRANSFER_REPEAT_AREA_DESTINATION, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer1_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_RXI, }; -const transfer_cfg_t g_transfer1_cfg = -{ .p_info = &g_transfer1_info, .p_extend = &g_transfer1_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer1 = -{ .p_ctrl = &g_transfer1_ctrl, .p_cfg = &g_transfer1_cfg, .p_api = &g_transfer_on_dtc }; -dtc_instance_ctrl_t g_transfer0_ctrl; - -transfer_info_t g_transfer0_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .repeat_area = TRANSFER_REPEAT_AREA_SOURCE, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer0_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_TXI, }; -const transfer_cfg_t g_transfer0_cfg = -{ .p_info = &g_transfer0_info, .p_extend = &g_transfer0_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer0 = -{ .p_ctrl = &g_transfer0_ctrl, .p_cfg = &g_transfer0_cfg, .p_api = &g_transfer_on_dtc }; -spi_instance_ctrl_t g_spi0_ctrl; - -/** SPI extended configuration for SPI HAL driver */ -const spi_extended_cfg_t g_spi0_ext_cfg = -{ .spi_clksyn = SPI_SSL_MODE_CLK_SYN, - .spi_comm = SPI_COMMUNICATION_FULL_DUPLEX, - .ssl_polarity = SPI_SSLP_LOW, - .ssl_select = SPI_SSL_SELECT_SSL0, - .mosi_idle = SPI_MOSI_IDLE_VALUE_FIXING_DISABLE, - .parity = SPI_PARITY_MODE_DISABLE, - .byte_swap = SPI_BYTE_SWAP_DISABLE, - .spck_div = - { - /* Actual calculated bitrate: 15000000. */ .spbr = 3, - .brdv = 0 - }, - .spck_delay = SPI_DELAY_COUNT_1, - .ssl_negation_delay = SPI_DELAY_COUNT_1, - .next_access_delay = SPI_DELAY_COUNT_1 }; - -/** SPI configuration for SPI HAL driver */ -const spi_cfg_t g_spi0_cfg = -{ .channel = 0, - - #if defined(VECTOR_NUMBER_SPI0_RXI) - .rxi_irq = VECTOR_NUMBER_SPI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TXI) - .txi_irq = VECTOR_NUMBER_SPI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TEI) - .tei_irq = VECTOR_NUMBER_SPI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_ERI) - .eri_irq = VECTOR_NUMBER_SPI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - - .rxi_ipl = (12), - .txi_ipl = (12), - .tei_ipl = (12), - .eri_ipl = (12), - - .operating_mode = SPI_MODE_MASTER, - - .clk_phase = SPI_CLK_PHASE_EDGE_ODD, - .clk_polarity = SPI_CLK_POLARITY_LOW, - - .mode_fault = SPI_MODE_FAULT_ERROR_DISABLE, - .bit_order = SPI_BIT_ORDER_MSB_FIRST, - .p_transfer_tx = g_spi0_P_TRANSFER_TX, - .p_transfer_rx = g_spi0_P_TRANSFER_RX, - .p_callback = spi_callback, - - .p_context = NULL, - .p_extend = (void *)&g_spi0_ext_cfg, }; - -/* Instance structure to use this module. */ -const spi_instance_t g_spi0 = -{ .p_ctrl = &g_spi0_ctrl, .p_cfg = &g_spi0_cfg, .p_api = &g_spi_on_spi }; -icu_instance_ctrl_t g_external_irq13_ctrl; -const external_irq_cfg_t g_external_irq13_cfg = -{ .channel = 13, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ13) - .irq = VECTOR_NUMBER_ICU_IRQ13, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq13 = -{ .p_ctrl = &g_external_irq13_ctrl, .p_cfg = &g_external_irq13_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq12_ctrl; -const external_irq_cfg_t g_external_irq12_cfg = -{ .channel = 12, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ12) - .irq = VECTOR_NUMBER_ICU_IRQ12, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq12 = -{ .p_ctrl = &g_external_irq12_ctrl, .p_cfg = &g_external_irq12_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq11_ctrl; -const external_irq_cfg_t g_external_irq11_cfg = -{ .channel = 11, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ11) - .irq = VECTOR_NUMBER_ICU_IRQ11, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq11 = -{ .p_ctrl = &g_external_irq11_ctrl, .p_cfg = &g_external_irq11_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq10_ctrl; -const external_irq_cfg_t g_external_irq10_cfg = -{ .channel = 10, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ10) - .irq = VECTOR_NUMBER_ICU_IRQ10, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq10 = -{ .p_ctrl = &g_external_irq10_ctrl, .p_cfg = &g_external_irq10_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq9_ctrl; -const external_irq_cfg_t g_external_irq9_cfg = -{ .channel = 9, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ9) - .irq = VECTOR_NUMBER_ICU_IRQ9, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq9 = -{ .p_ctrl = &g_external_irq9_ctrl, .p_cfg = &g_external_irq9_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq8_ctrl; -const external_irq_cfg_t g_external_irq8_cfg = -{ .channel = 8, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ8) - .irq = VECTOR_NUMBER_ICU_IRQ8, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq8 = -{ .p_ctrl = &g_external_irq8_ctrl, .p_cfg = &g_external_irq8_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq7_ctrl; -const external_irq_cfg_t g_external_irq7_cfg = -{ .channel = 7, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ7) - .irq = VECTOR_NUMBER_ICU_IRQ7, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq7 = -{ .p_ctrl = &g_external_irq7_ctrl, .p_cfg = &g_external_irq7_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq6_ctrl; -const external_irq_cfg_t g_external_irq6_cfg = -{ .channel = 6, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ6) - .irq = VECTOR_NUMBER_ICU_IRQ6, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq6 = -{ .p_ctrl = &g_external_irq6_ctrl, .p_cfg = &g_external_irq6_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq5_ctrl; -const external_irq_cfg_t g_external_irq5_cfg = -{ .channel = 5, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ5) - .irq = VECTOR_NUMBER_ICU_IRQ5, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq5 = -{ .p_ctrl = &g_external_irq5_ctrl, .p_cfg = &g_external_irq5_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq4_ctrl; -const external_irq_cfg_t g_external_irq4_cfg = -{ .channel = 4, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ4) - .irq = VECTOR_NUMBER_ICU_IRQ4, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq4 = -{ .p_ctrl = &g_external_irq4_ctrl, .p_cfg = &g_external_irq4_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq3_ctrl; -const external_irq_cfg_t g_external_irq3_cfg = -{ .channel = 3, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ3) - .irq = VECTOR_NUMBER_ICU_IRQ3, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq3 = -{ .p_ctrl = &g_external_irq3_ctrl, .p_cfg = &g_external_irq3_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq2_ctrl; -const external_irq_cfg_t g_external_irq2_cfg = -{ .channel = 2, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ2) - .irq = VECTOR_NUMBER_ICU_IRQ2, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq2 = -{ .p_ctrl = &g_external_irq2_ctrl, .p_cfg = &g_external_irq2_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq1_ctrl; -const external_irq_cfg_t g_external_irq1_cfg = -{ .channel = 1, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ1) - .irq = VECTOR_NUMBER_ICU_IRQ1, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq1 = -{ .p_ctrl = &g_external_irq1_ctrl, .p_cfg = &g_external_irq1_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq0_ctrl; -const external_irq_cfg_t g_external_irq0_cfg = -{ .channel = 0, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ0) - .irq = VECTOR_NUMBER_ICU_IRQ0, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq0 = -{ .p_ctrl = &g_external_irq0_ctrl, .p_cfg = &g_external_irq0_cfg, .p_api = &g_external_irq_on_icu }; -agt_instance_ctrl_t g_timer1_ctrl; -const agt_extended_cfg_t g_timer1_extend = -{ .count_source = AGT_CLOCK_PCLKB, - .agto = AGT_PIN_CFG_DISABLED, - .agtoa = AGT_PIN_CFG_DISABLED, - .agtob = AGT_PIN_CFG_DISABLED, - .measurement_mode = AGT_MEASURE_DISABLED, - .agtio_filter = AGT_AGTIO_FILTER_NONE, - .enable_pin = AGT_ENABLE_PIN_NOT_USED, - .trigger_edge = AGT_TRIGGER_EDGE_RISING, }; -const timer_cfg_t g_timer1_cfg = -{ .mode = TIMER_MODE_PERIODIC, -/* Actual period: 0.0010922666666666667 seconds. Actual duty: 50%. */ .period_counts = 0x10000, - .duty_cycle_counts = 0x8000, .source_div = (timer_source_div_t)0, .channel = 1, .p_callback = callback_agt, - /** If NULL then do not add & */ - #if defined(NULL) - .p_context = NULL, - #else - .p_context = &NULL, - #endif - .p_extend = &g_timer1_extend, - .cycle_end_ipl = (5), - #if defined(VECTOR_NUMBER_AGT1_INT) - .cycle_end_irq = VECTOR_NUMBER_AGT1_INT, - #else - .cycle_end_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const timer_instance_t g_timer1 = -{ .p_ctrl = &g_timer1_ctrl, .p_cfg = &g_timer1_cfg, .p_api = &g_timer_on_agt }; -agt_instance_ctrl_t g_timer0_ctrl; -const agt_extended_cfg_t g_timer0_extend = -{ .count_source = AGT_CLOCK_PCLKB, - .agto = AGT_PIN_CFG_DISABLED, - .agtoa = AGT_PIN_CFG_DISABLED, - .agtob = AGT_PIN_CFG_DISABLED, - .measurement_mode = AGT_MEASURE_DISABLED, - .agtio_filter = AGT_AGTIO_FILTER_NONE, - .enable_pin = AGT_ENABLE_PIN_NOT_USED, - .trigger_edge = AGT_TRIGGER_EDGE_RISING, }; -const timer_cfg_t g_timer0_cfg = -{ .mode = TIMER_MODE_PERIODIC, -/* Actual period: 0.0010922666666666667 seconds. Actual duty: 50%. */ .period_counts = 0x10000, - .duty_cycle_counts = 0x8000, .source_div = (timer_source_div_t)0, .channel = 0, .p_callback = callback_agt, - /** If NULL then do not add & */ - #if defined(NULL) - .p_context = NULL, - #else - .p_context = &NULL, - #endif - .p_extend = &g_timer0_extend, - .cycle_end_ipl = (5), - #if defined(VECTOR_NUMBER_AGT0_INT) - .cycle_end_irq = VECTOR_NUMBER_AGT0_INT, - #else - .cycle_end_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const timer_instance_t g_timer0 = -{ .p_ctrl = &g_timer0_ctrl, .p_cfg = &g_timer0_cfg, .p_api = &g_timer_on_agt }; flash_hp_instance_ctrl_t g_flash0_ctrl; const flash_cfg_t g_flash0_cfg = { .data_flash_bgo = false, .p_callback = NULL, .p_context = NULL, @@ -596,239 +54,3 @@ const flash_cfg_t g_flash0_cfg = /* Instance structure to use this module. */ const flash_instance_t g_flash0 = { .p_ctrl = &g_flash0_ctrl, .p_cfg = &g_flash0_cfg, .p_api = &g_flash_on_flash_hp }; -rtc_instance_ctrl_t g_rtc0_ctrl; -const rtc_error_adjustment_cfg_t g_rtc0_err_cfg = -{ .adjustment_mode = RTC_ERROR_ADJUSTMENT_MODE_AUTOMATIC, - .adjustment_period = RTC_ERROR_ADJUSTMENT_PERIOD_10_SECOND, - .adjustment_type = RTC_ERROR_ADJUSTMENT_NONE, - .adjustment_value = 0, }; -const rtc_cfg_t g_rtc0_cfg = -{ .clock_source = RTC_CLOCK_SOURCE_LOCO, .freq_compare_value_loco = 255, .p_err_cfg = &g_rtc0_err_cfg, .p_callback = - NULL, - .p_context = NULL, .alarm_ipl = (14), .periodic_ipl = (14), .carry_ipl = (14), - #if defined(VECTOR_NUMBER_RTC_ALARM) - .alarm_irq = VECTOR_NUMBER_RTC_ALARM, - #else - .alarm_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_PERIOD) - .periodic_irq = VECTOR_NUMBER_RTC_PERIOD, - #else - .periodic_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_CARRY) - .carry_irq = VECTOR_NUMBER_RTC_CARRY, - #else - .carry_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const rtc_instance_t g_rtc0 = -{ .p_ctrl = &g_rtc0_ctrl, .p_cfg = &g_rtc0_cfg, .p_api = &g_rtc_on_rtc }; -sci_uart_instance_ctrl_t g_uart8_ctrl; - -baud_setting_t g_uart8_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 64, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart8_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart8_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart8_cfg = -{ .channel = 8, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart8_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI8_RXI) - .rxi_irq = VECTOR_NUMBER_SCI8_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI8_TXI) - .txi_irq = VECTOR_NUMBER_SCI8_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI8_TEI) - .tei_irq = VECTOR_NUMBER_SCI8_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI8_ERI) - .eri_irq = VECTOR_NUMBER_SCI8_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart8 = -{ .p_ctrl = &g_uart8_ctrl, .p_cfg = &g_uart8_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart2_ctrl; - -baud_setting_t g_uart2_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 64, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart2_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart2_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart2_cfg = -{ .channel = 2, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart2_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI2_RXI) - .rxi_irq = VECTOR_NUMBER_SCI2_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI2_TXI) - .txi_irq = VECTOR_NUMBER_SCI2_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI2_TEI) - .tei_irq = VECTOR_NUMBER_SCI2_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI2_ERI) - .eri_irq = VECTOR_NUMBER_SCI2_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart2 = -{ .p_ctrl = &g_uart2_ctrl, .p_cfg = &g_uart2_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart0_ctrl; - -baud_setting_t g_uart0_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 64, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart0_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart0_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart0_cfg = -{ .channel = 0, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart0_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI0_RXI) - .rxi_irq = VECTOR_NUMBER_SCI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_TXI) - .txi_irq = VECTOR_NUMBER_SCI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_TEI) - .tei_irq = VECTOR_NUMBER_SCI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_ERI) - .eri_irq = VECTOR_NUMBER_SCI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart0 = -{ .p_ctrl = &g_uart0_ctrl, .p_cfg = &g_uart0_cfg, .p_api = &g_uart_on_sci }; -void g_hal_init(void) { - g_common_init(); -} diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h index d8773ab5ed..c661dfb183 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h @@ -2,262 +2,20 @@ #ifndef HAL_DATA_H_ #define HAL_DATA_H_ #include -#include "bsp_api.h" #include "common_data.h" -#include "r_adc.h" -#include "r_adc_api.h" -#include "r_iic_master.h" -#include "r_i2c_master_api.h" #include "r_lpm.h" #include "r_lpm_api.h" -#include "r_dtc.h" -#include "r_transfer_api.h" -#include "r_spi.h" -#include "r_icu.h" -#include "r_external_irq_api.h" -#include "r_agt.h" -#include "r_timer_api.h" #include "r_flash_hp.h" #include "r_flash_api.h" -#include "r_rtc.h" -#include "r_rtc_api.h" -#include "r_sci_uart.h" -#include "r_uart_api.h" FSP_HEADER -/** ADC on ADC Instance. */ -extern const adc_instance_t g_adc1; -/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ -extern adc_instance_ctrl_t g_adc1_ctrl; -extern const adc_cfg_t g_adc1_cfg; -extern const adc_channel_cfg_t g_adc1_channel_cfg; - -#ifndef NULL -void NULL(adc_callback_args_t *p_args); -#endif -/* I2C Master on IIC Instance. */ -extern const i2c_master_instance_t g_i2c_master0; - -/** Access the I2C Master instance using these structures when calling API functions directly (::p_api is not used). */ -extern iic_master_instance_ctrl_t g_i2c_master0_ctrl; -extern const i2c_master_cfg_t g_i2c_master0_cfg; - -#ifndef callback_iic -void callback_iic(i2c_master_callback_args_t *p_args); -#endif -/** ADC on ADC Instance. */ -extern const adc_instance_t g_adc0; - -/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ -extern adc_instance_ctrl_t g_adc0_ctrl; -extern const adc_cfg_t g_adc0_cfg; -extern const adc_channel_cfg_t g_adc0_channel_cfg; - -#ifndef NULL -void NULL(adc_callback_args_t *p_args); -#endif /** lpm Instance */ extern const lpm_instance_t g_lpm0; /** Access the LPM instance using these structures when calling API functions directly (::p_api is not used). */ extern lpm_instance_ctrl_t g_lpm0_ctrl; extern const lpm_cfg_t g_lpm0_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer1; -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer1_ctrl; -extern const transfer_cfg_t g_transfer1_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer0; - -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer0_ctrl; -extern const transfer_cfg_t g_transfer0_cfg; -/** SPI on SPI Instance. */ -extern const spi_instance_t g_spi0; - -/** Access the SPI instance using these structures when calling API functions directly (::p_api is not used). */ -extern spi_instance_ctrl_t g_spi0_ctrl; -extern const spi_cfg_t g_spi0_cfg; - -/** Callback used by SPI Instance. */ -#ifndef spi_callback -void spi_callback(spi_callback_args_t *p_args); -#endif - -#define RA_NOT_DEFINED (1) -#if (RA_NOT_DEFINED == g_transfer0) - #define g_spi0_P_TRANSFER_TX (NULL) -#else -#define g_spi0_P_TRANSFER_TX (&g_transfer0) -#endif -#if (RA_NOT_DEFINED == g_transfer1) - #define g_spi0_P_TRANSFER_RX (NULL) -#else -#define g_spi0_P_TRANSFER_RX (&g_transfer1) -#endif -#undef RA_NOT_DEFINED -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq13; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq13_ctrl; -extern const external_irq_cfg_t g_external_irq13_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq12; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq12_ctrl; -extern const external_irq_cfg_t g_external_irq12_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq11; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq11_ctrl; -extern const external_irq_cfg_t g_external_irq11_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq10; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq10_ctrl; -extern const external_irq_cfg_t g_external_irq10_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq9; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq9_ctrl; -extern const external_irq_cfg_t g_external_irq9_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq8; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq8_ctrl; -extern const external_irq_cfg_t g_external_irq8_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq7; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq7_ctrl; -extern const external_irq_cfg_t g_external_irq7_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq6; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq6_ctrl; -extern const external_irq_cfg_t g_external_irq6_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq5; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq5_ctrl; -extern const external_irq_cfg_t g_external_irq5_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq4; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq4_ctrl; -extern const external_irq_cfg_t g_external_irq4_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq3; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq3_ctrl; -extern const external_irq_cfg_t g_external_irq3_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq2; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq2_ctrl; -extern const external_irq_cfg_t g_external_irq2_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq1; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq1_ctrl; -extern const external_irq_cfg_t g_external_irq1_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq0; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq0_ctrl; -extern const external_irq_cfg_t g_external_irq0_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** AGT Timer Instance */ -extern const timer_instance_t g_timer1; - -/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ -extern agt_instance_ctrl_t g_timer1_ctrl; -extern const timer_cfg_t g_timer1_cfg; - -#ifndef callback_agt -void callback_agt(timer_callback_args_t *p_args); -#endif -/** AGT Timer Instance */ -extern const timer_instance_t g_timer0; - -/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ -extern agt_instance_ctrl_t g_timer0_ctrl; -extern const timer_cfg_t g_timer0_cfg; - -#ifndef callback_agt -void callback_agt(timer_callback_args_t *p_args); -#endif /* Flash on Flash HP Instance */ extern const flash_instance_t g_flash0; @@ -268,50 +26,8 @@ extern const flash_cfg_t g_flash0_cfg; #ifndef NULL void NULL(flash_callback_args_t *p_args); #endif -/* RTC Instance. */ -extern const rtc_instance_t g_rtc0; -/** Access the RTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern rtc_instance_ctrl_t g_rtc0_ctrl; -extern const rtc_cfg_t g_rtc0_cfg; - -#ifndef NULL -void NULL(rtc_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart8; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart8_ctrl; -extern const uart_cfg_t g_uart8_cfg; -extern const sci_uart_extended_cfg_t g_uart8_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart2; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart2_ctrl; -extern const uart_cfg_t g_uart2_cfg; -extern const sci_uart_extended_cfg_t g_uart2_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart0; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart0_ctrl; -extern const uart_cfg_t g_uart0_cfg; -extern const sci_uart_extended_cfg_t g_uart0_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif void hal_entry(void); -void g_hal_init(void); + FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/pin_data.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/pin_data.c index a2ddad010f..164aeaa589 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/pin_data.c +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/pin_data.c @@ -1,109 +1,92 @@ /* generated pin source file - do not edit */ #include "bsp_api.h" #include "r_ioport_api.h" -const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = { - { - .pin = BSP_IO_PORT_00_PIN_04, - .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE), - }, - { - .pin = BSP_IO_PORT_01_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_03, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_04, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_01_PIN_05, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_01_PIN_06, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_01_PIN_07, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_01_PIN_08, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_09, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_12, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_02_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), - }, - { - .pin = BSP_IO_PORT_02_PIN_05, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_CTSU), - }, - { - .pin = BSP_IO_PORT_02_PIN_07, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_CTSU), - }, - { - .pin = BSP_IO_PORT_03_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_03_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_03_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_04_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC), - }, - { - .pin = BSP_IO_PORT_04_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC), - }, - { - .pin = BSP_IO_PORT_04_PIN_07, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_USB_FS), - }, - { - .pin = BSP_IO_PORT_04_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_04_PIN_11, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_04_PIN_15, - .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), - }, -}; -const ioport_cfg_t g_bsp_pin_cfg = { - .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), - .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], + +const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = +{ + { .pin = BSP_IO_PORT_00_PIN_04, .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, + { .pin = BSP_IO_PORT_01_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_03, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_04, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_01_PIN_05, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_01_PIN_06, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_01_PIN_07, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_01_PIN_08, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_09, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_12, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_02_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, + { .pin = BSP_IO_PORT_02_PIN_05, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_CTSU) }, + { .pin = BSP_IO_PORT_02_PIN_07, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_CTSU) }, + { .pin = BSP_IO_PORT_03_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_03_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_03_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_04_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID + | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC) }, + { .pin = BSP_IO_PORT_04_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID + | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC) }, + { .pin = BSP_IO_PORT_04_PIN_07, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_USB_FS) }, + { .pin = BSP_IO_PORT_04_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_04_PIN_11, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_04_PIN_15, .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, }; + +const ioport_cfg_t g_bsp_pin_cfg = +{ .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], }; + +#if BSP_TZ_SECURE_BUILD + +void R_BSP_PinCfgSecurityInit(void); + +/* Initialize SAR registers for secure pins. */ +void R_BSP_PinCfgSecurityInit(void) { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + uint32_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #else + uint16_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #endif + memset(pmsar, 0xFF, BSP_FEATURE_BSP_NUM_PMSAR * sizeof(R_PMISC->PMSAR[0])); + + + for (uint32_t i = 0; i < g_bsp_pin_cfg.number_of_pins; i++) + { + uint32_t port_pin = g_bsp_pin_cfg.p_pin_cfg_data[i].pin; + uint32_t port = port_pin >> 8U; + uint32_t pin = port_pin & 0xFFU; + pmsar[port] &= (uint16_t) ~(1U << pin); + } + + for (uint32_t i = 0; i < BSP_FEATURE_BSP_NUM_PMSAR; i++) + { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + R_PMISC->PMSAR[i].PMSAR = (uint16_t)pmsar[i]; + #else + R_PMISC->PMSAR[i].PMSAR = pmsar[i]; + #endif + } + +} +#endif diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.c index cf17573a03..2004d5589e 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.c +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.c @@ -4,7 +4,7 @@ #if VECTOR_DATA_IRQ_COUNT > 0 BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BSP_PLACE_IN_SECTION(BSP_SECTION_APPLICATION_VECTORS) = { - [0] = sci_uart_rxi_isr, /* SCI0 RXI (Receive data full) */ + [0] = sci_uart_rxi_isr, /* SCI0 RXI (Receive data full) */ [1] = sci_uart_txi_isr, /* SCI0 TXI (Transmit data empty) */ [2] = sci_uart_tei_isr, /* SCI0 TEI (Transmit end) */ [3] = sci_uart_eri_isr, /* SCI0 ERI (Receive error) */ @@ -14,35 +14,35 @@ BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BS [7] = sci_uart_eri_isr, /* SCI2 ERI (Receive error) */ [8] = sci_uart_rxi_isr, /* SCI8 RXI (Received data full) */ [9] = sci_uart_txi_isr, /* SCI8 TXI (Transmit data empty) */ - [10] = sci_uart_tei_isr, /* SCI8 TEI (Transmit end) */ - [11] = sci_uart_eri_isr, /* SCI8 ERI (Receive error) */ - [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ - [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ - [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ - [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ - [16] = agt_int_isr, /* AGT1 INT (AGT interrupt) */ - [17] = r_icu_isr, /* ICU IRQ0 (External pin interrupt 0) */ - [18] = r_icu_isr, /* ICU IRQ1 (External pin interrupt 1) */ - [19] = r_icu_isr, /* ICU IRQ2 (External pin interrupt 2) */ - [20] = r_icu_isr, /* ICU IRQ3 (External pin interrupt 3) */ - [21] = r_icu_isr, /* ICU IRQ4 (External pin interrupt 4) */ - [22] = r_icu_isr, /* ICU IRQ5 (External pin interrupt 5) */ - [23] = r_icu_isr, /* ICU IRQ6 (External pin interrupt 6) */ - [24] = r_icu_isr, /* ICU IRQ7 (External pin interrupt 7) */ - [25] = r_icu_isr, /* ICU IRQ8 (External pin interrupt 8) */ - [26] = r_icu_isr, /* ICU IRQ9 (External pin interrupt 9) */ - [27] = r_icu_isr, /* ICU IRQ10 (External pin interrupt 10) */ - [28] = r_icu_isr, /* ICU IRQ11 (External pin interrupt 11) */ - [29] = r_icu_isr, /* ICU IRQ12 (External pin interrupt 12) */ - [30] = r_icu_isr, /* ICU IRQ13 (External pin interrupt 13) */ - [31] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ - [32] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ - [33] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ - [34] = spi_eri_isr, /* SPI0 ERI (Error) */ - [35] = iic_master_rxi_isr, /* IIC0 RXI (Receive data full) */ - [36] = iic_master_txi_isr, /* IIC0 TXI (Transmit data empty) */ - [37] = iic_master_tei_isr, /* IIC0 TEI (Transmit end) */ - [38] = iic_master_eri_isr, /* IIC0 ERI (Transfer error) */ + [10] = sci_uart_tei_isr, /* SCI8 TEI (Transmit end) */ + [11] = sci_uart_eri_isr, /* SCI8 ERI (Receive error) */ + [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ + [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ + [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ + [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ + [16] = agt_int_isr, /* AGT1 INT (AGT interrupt) */ + [17] = r_icu_isr, /* ICU IRQ0 (External pin interrupt 0) */ + [18] = r_icu_isr, /* ICU IRQ1 (External pin interrupt 1) */ + [19] = r_icu_isr, /* ICU IRQ2 (External pin interrupt 2) */ + [20] = r_icu_isr, /* ICU IRQ3 (External pin interrupt 3) */ + [21] = r_icu_isr, /* ICU IRQ4 (External pin interrupt 4) */ + [22] = r_icu_isr, /* ICU IRQ5 (External pin interrupt 5) */ + [23] = r_icu_isr, /* ICU IRQ6 (External pin interrupt 6) */ + [24] = r_icu_isr, /* ICU IRQ7 (External pin interrupt 7) */ + [25] = r_icu_isr, /* ICU IRQ8 (External pin interrupt 8) */ + [26] = r_icu_isr, /* ICU IRQ9 (External pin interrupt 9) */ + [27] = r_icu_isr, /* ICU IRQ10 (External pin interrupt 10) */ + [28] = r_icu_isr, /* ICU IRQ11 (External pin interrupt 11) */ + [29] = r_icu_isr, /* ICU IRQ12 (External pin interrupt 12) */ + [30] = r_icu_isr, /* ICU IRQ13 (External pin interrupt 13) */ + [31] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ + [32] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ + [33] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ + [34] = spi_eri_isr, /* SPI0 ERI (Error) */ + [35] = iic_master_rxi_isr, /* IIC0 RXI (Receive data full) */ + [36] = iic_master_txi_isr, /* IIC0 TXI (Transmit data empty) */ + [37] = iic_master_tei_isr, /* IIC0 TEI (Transmit end) */ + [38] = iic_master_eri_isr, /* IIC0 ERI (Transfer error) */ }; const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = { @@ -56,34 +56,34 @@ const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENT [7] = BSP_PRV_IELS_ENUM(EVENT_SCI2_ERI), /* SCI2 ERI (Receive error) */ [8] = BSP_PRV_IELS_ENUM(EVENT_SCI8_RXI), /* SCI8 RXI (Received data full) */ [9] = BSP_PRV_IELS_ENUM(EVENT_SCI8_TXI), /* SCI8 TXI (Transmit data empty) */ - [10] = BSP_PRV_IELS_ENUM(EVENT_SCI8_TEI), /* SCI8 TEI (Transmit end) */ - [11] = BSP_PRV_IELS_ENUM(EVENT_SCI8_ERI), /* SCI8 ERI (Receive error) */ - [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ - [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ - [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ - [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ - [16] = BSP_PRV_IELS_ENUM(EVENT_AGT1_INT), /* AGT1 INT (AGT interrupt) */ - [17] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ0), /* ICU IRQ0 (External pin interrupt 0) */ - [18] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ1), /* ICU IRQ1 (External pin interrupt 1) */ - [19] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ2), /* ICU IRQ2 (External pin interrupt 2) */ - [20] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ3), /* ICU IRQ3 (External pin interrupt 3) */ - [21] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ4), /* ICU IRQ4 (External pin interrupt 4) */ - [22] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ5), /* ICU IRQ5 (External pin interrupt 5) */ - [23] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ6), /* ICU IRQ6 (External pin interrupt 6) */ - [24] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ7), /* ICU IRQ7 (External pin interrupt 7) */ - [25] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ8), /* ICU IRQ8 (External pin interrupt 8) */ - [26] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ9), /* ICU IRQ9 (External pin interrupt 9) */ - [27] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ10), /* ICU IRQ10 (External pin interrupt 10) */ - [28] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ11), /* ICU IRQ11 (External pin interrupt 11) */ - [29] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ12), /* ICU IRQ12 (External pin interrupt 12) */ - [30] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ13), /* ICU IRQ13 (External pin interrupt 13) */ - [31] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ - [32] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ - [33] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ - [34] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ - [35] = BSP_PRV_IELS_ENUM(EVENT_IIC0_RXI), /* IIC0 RXI (Receive data full) */ - [36] = BSP_PRV_IELS_ENUM(EVENT_IIC0_TXI), /* IIC0 TXI (Transmit data empty) */ - [37] = BSP_PRV_IELS_ENUM(EVENT_IIC0_TEI), /* IIC0 TEI (Transmit end) */ - [38] = BSP_PRV_IELS_ENUM(EVENT_IIC0_ERI), /* IIC0 ERI (Transfer error) */ + [10] = BSP_PRV_IELS_ENUM(EVENT_SCI8_TEI), /* SCI8 TEI (Transmit end) */ + [11] = BSP_PRV_IELS_ENUM(EVENT_SCI8_ERI), /* SCI8 ERI (Receive error) */ + [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ + [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ + [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ + [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ + [16] = BSP_PRV_IELS_ENUM(EVENT_AGT1_INT), /* AGT1 INT (AGT interrupt) */ + [17] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ0), /* ICU IRQ0 (External pin interrupt 0) */ + [18] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ1), /* ICU IRQ1 (External pin interrupt 1) */ + [19] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ2), /* ICU IRQ2 (External pin interrupt 2) */ + [20] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ3), /* ICU IRQ3 (External pin interrupt 3) */ + [21] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ4), /* ICU IRQ4 (External pin interrupt 4) */ + [22] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ5), /* ICU IRQ5 (External pin interrupt 5) */ + [23] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ6), /* ICU IRQ6 (External pin interrupt 6) */ + [24] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ7), /* ICU IRQ7 (External pin interrupt 7) */ + [25] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ8), /* ICU IRQ8 (External pin interrupt 8) */ + [26] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ9), /* ICU IRQ9 (External pin interrupt 9) */ + [27] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ10), /* ICU IRQ10 (External pin interrupt 10) */ + [28] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ11), /* ICU IRQ11 (External pin interrupt 11) */ + [29] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ12), /* ICU IRQ12 (External pin interrupt 12) */ + [30] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ13), /* ICU IRQ13 (External pin interrupt 13) */ + [31] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ + [32] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ + [33] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ + [34] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ + [35] = BSP_PRV_IELS_ENUM(EVENT_IIC0_RXI), /* IIC0 RXI (Receive data full) */ + [36] = BSP_PRV_IELS_ENUM(EVENT_IIC0_TXI), /* IIC0 TXI (Transmit data empty) */ + [37] = BSP_PRV_IELS_ENUM(EVENT_IIC0_TEI), /* IIC0 TEI (Transmit end) */ + [38] = BSP_PRV_IELS_ENUM(EVENT_IIC0_ERI), /* IIC0 ERI (Transfer error) */ }; #endif diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.h index b812cff2e1..688c2c39fe 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/vector_data.h @@ -1,6 +1,9 @@ /* generated vector header file - do not edit */ #ifndef VECTOR_DATA_H #define VECTOR_DATA_H +#ifdef __cplusplus +extern "C" { +#endif /* Number of interrupts allocated */ #ifndef VECTOR_DATA_IRQ_COUNT #define VECTOR_DATA_IRQ_COUNT (39) @@ -25,95 +28,84 @@ void iic_master_eri_isr(void); /* Vector table allocations */ #define VECTOR_NUMBER_SCI0_RXI ((IRQn_Type)0) /* SCI0 RXI (Receive data full) */ +#define SCI0_RXI_IRQn ((IRQn_Type)0) /* SCI0 RXI (Receive data full) */ #define VECTOR_NUMBER_SCI0_TXI ((IRQn_Type)1) /* SCI0 TXI (Transmit data empty) */ +#define SCI0_TXI_IRQn ((IRQn_Type)1) /* SCI0 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI0_TEI ((IRQn_Type)2) /* SCI0 TEI (Transmit end) */ +#define SCI0_TEI_IRQn ((IRQn_Type)2) /* SCI0 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI0_ERI ((IRQn_Type)3) /* SCI0 ERI (Receive error) */ +#define SCI0_ERI_IRQn ((IRQn_Type)3) /* SCI0 ERI (Receive error) */ #define VECTOR_NUMBER_SCI2_RXI ((IRQn_Type)4) /* SCI2 RXI (Received data full) */ +#define SCI2_RXI_IRQn ((IRQn_Type)4) /* SCI2 RXI (Received data full) */ #define VECTOR_NUMBER_SCI2_TXI ((IRQn_Type)5) /* SCI2 TXI (Transmit data empty) */ +#define SCI2_TXI_IRQn ((IRQn_Type)5) /* SCI2 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI2_TEI ((IRQn_Type)6) /* SCI2 TEI (Transmit end) */ +#define SCI2_TEI_IRQn ((IRQn_Type)6) /* SCI2 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI2_ERI ((IRQn_Type)7) /* SCI2 ERI (Receive error) */ +#define SCI2_ERI_IRQn ((IRQn_Type)7) /* SCI2 ERI (Receive error) */ #define VECTOR_NUMBER_SCI8_RXI ((IRQn_Type)8) /* SCI8 RXI (Received data full) */ +#define SCI8_RXI_IRQn ((IRQn_Type)8) /* SCI8 RXI (Received data full) */ #define VECTOR_NUMBER_SCI8_TXI ((IRQn_Type)9) /* SCI8 TXI (Transmit data empty) */ +#define SCI8_TXI_IRQn ((IRQn_Type)9) /* SCI8 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI8_TEI ((IRQn_Type)10) /* SCI8 TEI (Transmit end) */ +#define SCI8_TEI_IRQn ((IRQn_Type)10) /* SCI8 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI8_ERI ((IRQn_Type)11) /* SCI8 ERI (Receive error) */ +#define SCI8_ERI_IRQn ((IRQn_Type)11) /* SCI8 ERI (Receive error) */ #define VECTOR_NUMBER_RTC_ALARM ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ +#define RTC_ALARM_IRQn ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ #define VECTOR_NUMBER_RTC_PERIOD ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ +#define RTC_PERIOD_IRQn ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ #define VECTOR_NUMBER_RTC_CARRY ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ +#define RTC_CARRY_IRQn ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ #define VECTOR_NUMBER_AGT0_INT ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ +#define AGT0_INT_IRQn ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ #define VECTOR_NUMBER_AGT1_INT ((IRQn_Type)16) /* AGT1 INT (AGT interrupt) */ +#define AGT1_INT_IRQn ((IRQn_Type)16) /* AGT1 INT (AGT interrupt) */ #define VECTOR_NUMBER_ICU_IRQ0 ((IRQn_Type)17) /* ICU IRQ0 (External pin interrupt 0) */ +#define ICU_IRQ0_IRQn ((IRQn_Type)17) /* ICU IRQ0 (External pin interrupt 0) */ #define VECTOR_NUMBER_ICU_IRQ1 ((IRQn_Type)18) /* ICU IRQ1 (External pin interrupt 1) */ +#define ICU_IRQ1_IRQn ((IRQn_Type)18) /* ICU IRQ1 (External pin interrupt 1) */ #define VECTOR_NUMBER_ICU_IRQ2 ((IRQn_Type)19) /* ICU IRQ2 (External pin interrupt 2) */ +#define ICU_IRQ2_IRQn ((IRQn_Type)19) /* ICU IRQ2 (External pin interrupt 2) */ #define VECTOR_NUMBER_ICU_IRQ3 ((IRQn_Type)20) /* ICU IRQ3 (External pin interrupt 3) */ +#define ICU_IRQ3_IRQn ((IRQn_Type)20) /* ICU IRQ3 (External pin interrupt 3) */ #define VECTOR_NUMBER_ICU_IRQ4 ((IRQn_Type)21) /* ICU IRQ4 (External pin interrupt 4) */ +#define ICU_IRQ4_IRQn ((IRQn_Type)21) /* ICU IRQ4 (External pin interrupt 4) */ #define VECTOR_NUMBER_ICU_IRQ5 ((IRQn_Type)22) /* ICU IRQ5 (External pin interrupt 5) */ +#define ICU_IRQ5_IRQn ((IRQn_Type)22) /* ICU IRQ5 (External pin interrupt 5) */ #define VECTOR_NUMBER_ICU_IRQ6 ((IRQn_Type)23) /* ICU IRQ6 (External pin interrupt 6) */ +#define ICU_IRQ6_IRQn ((IRQn_Type)23) /* ICU IRQ6 (External pin interrupt 6) */ #define VECTOR_NUMBER_ICU_IRQ7 ((IRQn_Type)24) /* ICU IRQ7 (External pin interrupt 7) */ +#define ICU_IRQ7_IRQn ((IRQn_Type)24) /* ICU IRQ7 (External pin interrupt 7) */ #define VECTOR_NUMBER_ICU_IRQ8 ((IRQn_Type)25) /* ICU IRQ8 (External pin interrupt 8) */ +#define ICU_IRQ8_IRQn ((IRQn_Type)25) /* ICU IRQ8 (External pin interrupt 8) */ #define VECTOR_NUMBER_ICU_IRQ9 ((IRQn_Type)26) /* ICU IRQ9 (External pin interrupt 9) */ +#define ICU_IRQ9_IRQn ((IRQn_Type)26) /* ICU IRQ9 (External pin interrupt 9) */ #define VECTOR_NUMBER_ICU_IRQ10 ((IRQn_Type)27) /* ICU IRQ10 (External pin interrupt 10) */ +#define ICU_IRQ10_IRQn ((IRQn_Type)27) /* ICU IRQ10 (External pin interrupt 10) */ #define VECTOR_NUMBER_ICU_IRQ11 ((IRQn_Type)28) /* ICU IRQ11 (External pin interrupt 11) */ +#define ICU_IRQ11_IRQn ((IRQn_Type)28) /* ICU IRQ11 (External pin interrupt 11) */ #define VECTOR_NUMBER_ICU_IRQ12 ((IRQn_Type)29) /* ICU IRQ12 (External pin interrupt 12) */ +#define ICU_IRQ12_IRQn ((IRQn_Type)29) /* ICU IRQ12 (External pin interrupt 12) */ #define VECTOR_NUMBER_ICU_IRQ13 ((IRQn_Type)30) /* ICU IRQ13 (External pin interrupt 13) */ +#define ICU_IRQ13_IRQn ((IRQn_Type)30) /* ICU IRQ13 (External pin interrupt 13) */ #define VECTOR_NUMBER_SPI0_RXI ((IRQn_Type)31) /* SPI0 RXI (Receive buffer full) */ +#define SPI0_RXI_IRQn ((IRQn_Type)31) /* SPI0 RXI (Receive buffer full) */ #define VECTOR_NUMBER_SPI0_TXI ((IRQn_Type)32) /* SPI0 TXI (Transmit buffer empty) */ +#define SPI0_TXI_IRQn ((IRQn_Type)32) /* SPI0 TXI (Transmit buffer empty) */ #define VECTOR_NUMBER_SPI0_TEI ((IRQn_Type)33) /* SPI0 TEI (Transmission complete event) */ +#define SPI0_TEI_IRQn ((IRQn_Type)33) /* SPI0 TEI (Transmission complete event) */ #define VECTOR_NUMBER_SPI0_ERI ((IRQn_Type)34) /* SPI0 ERI (Error) */ +#define SPI0_ERI_IRQn ((IRQn_Type)34) /* SPI0 ERI (Error) */ #define VECTOR_NUMBER_IIC0_RXI ((IRQn_Type)35) /* IIC0 RXI (Receive data full) */ +#define IIC0_RXI_IRQn ((IRQn_Type)35) /* IIC0 RXI (Receive data full) */ #define VECTOR_NUMBER_IIC0_TXI ((IRQn_Type)36) /* IIC0 TXI (Transmit data empty) */ +#define IIC0_TXI_IRQn ((IRQn_Type)36) /* IIC0 TXI (Transmit data empty) */ #define VECTOR_NUMBER_IIC0_TEI ((IRQn_Type)37) /* IIC0 TEI (Transmit end) */ +#define IIC0_TEI_IRQn ((IRQn_Type)37) /* IIC0 TEI (Transmit end) */ #define VECTOR_NUMBER_IIC0_ERI ((IRQn_Type)38) /* IIC0 ERI (Transfer error) */ -typedef enum IRQn -{ - Reset_IRQn = -15, - NonMaskableInt_IRQn = -14, - HardFault_IRQn = -13, - MemoryManagement_IRQn = -12, - BusFault_IRQn = -11, - UsageFault_IRQn = -10, - SecureFault_IRQn = -9, - SVCall_IRQn = -5, - DebugMonitor_IRQn = -4, - PendSV_IRQn = -2, - SysTick_IRQn = -1, - SCI0_RXI_IRQn = 0, /* SCI0 RXI (Receive data full) */ - SCI0_TXI_IRQn = 1, /* SCI0 TXI (Transmit data empty) */ - SCI0_TEI_IRQn = 2, /* SCI0 TEI (Transmit end) */ - SCI0_ERI_IRQn = 3, /* SCI0 ERI (Receive error) */ - SCI2_RXI_IRQn = 4, /* SCI2 RXI (Received data full) */ - SCI2_TXI_IRQn = 5, /* SCI2 TXI (Transmit data empty) */ - SCI2_TEI_IRQn = 6, /* SCI2 TEI (Transmit end) */ - SCI2_ERI_IRQn = 7, /* SCI2 ERI (Receive error) */ - SCI8_RXI_IRQn = 8, /* SCI8 RXI (Received data full) */ - SCI8_TXI_IRQn = 9, /* SCI8 TXI (Transmit data empty) */ - SCI8_TEI_IRQn = 10, /* SCI8 TEI (Transmit end) */ - SCI8_ERI_IRQn = 11, /* SCI8 ERI (Receive error) */ - RTC_ALARM_IRQn = 12, /* RTC ALARM (Alarm interrupt) */ - RTC_PERIOD_IRQn = 13, /* RTC PERIOD (Periodic interrupt) */ - RTC_CARRY_IRQn = 14, /* RTC CARRY (Carry interrupt) */ - AGT0_INT_IRQn = 15, /* AGT0 INT (AGT interrupt) */ - AGT1_INT_IRQn = 16, /* AGT1 INT (AGT interrupt) */ - ICU_IRQ0_IRQn = 17, /* ICU IRQ0 (External pin interrupt 0) */ - ICU_IRQ1_IRQn = 18, /* ICU IRQ1 (External pin interrupt 1) */ - ICU_IRQ2_IRQn = 19, /* ICU IRQ2 (External pin interrupt 2) */ - ICU_IRQ3_IRQn = 20, /* ICU IRQ3 (External pin interrupt 3) */ - ICU_IRQ4_IRQn = 21, /* ICU IRQ4 (External pin interrupt 4) */ - ICU_IRQ5_IRQn = 22, /* ICU IRQ5 (External pin interrupt 5) */ - ICU_IRQ6_IRQn = 23, /* ICU IRQ6 (External pin interrupt 6) */ - ICU_IRQ7_IRQn = 24, /* ICU IRQ7 (External pin interrupt 7) */ - ICU_IRQ8_IRQn = 25, /* ICU IRQ8 (External pin interrupt 8) */ - ICU_IRQ9_IRQn = 26, /* ICU IRQ9 (External pin interrupt 9) */ - ICU_IRQ10_IRQn = 27, /* ICU IRQ10 (External pin interrupt 10) */ - ICU_IRQ11_IRQn = 28, /* ICU IRQ11 (External pin interrupt 11) */ - ICU_IRQ12_IRQn = 29, /* ICU IRQ12 (External pin interrupt 12) */ - ICU_IRQ13_IRQn = 30, /* ICU IRQ13 (External pin interrupt 13) */ - SPI0_RXI_IRQn = 31, /* SPI0 RXI (Receive buffer full) */ - SPI0_TXI_IRQn = 32, /* SPI0 TXI (Transmit buffer empty) */ - SPI0_TEI_IRQn = 33, /* SPI0 TEI (Transmission complete event) */ - SPI0_ERI_IRQn = 34, /* SPI0 ERI (Error) */ - IIC0_RXI_IRQn = 35, /* IIC0 RXI (Receive data full) */ - IIC0_TXI_IRQn = 36, /* IIC0 TXI (Transmit data empty) */ - IIC0_TEI_IRQn = 37, /* IIC0 TEI (Transmit end) */ - IIC0_ERI_IRQn = 38, /* IIC0 ERI (Transfer error) */ -} IRQn_Type; +#define IIC0_ERI_IRQn ((IRQn_Type)38) /* IIC0 ERI (Transfer error) */ +#ifdef __cplusplus +} +#endif #endif /* VECTOR_DATA_H */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_cfg.h index 7255cdd17c..9952bf9b15 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_CFG_H_ #define BSP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_clock_cfg.h" #include "bsp_mcu_family_cfg.h" #include "board_cfg.h" @@ -14,7 +18,13 @@ #define BSP_CFG_RTOS (0) #endif #endif +#ifndef BSP_CFG_RTC_USED +#define BSP_CFG_RTC_USED (1) +#endif #undef RA_NOT_DEFINED +#if defined(_RA_BOOT_IMAGE) +#define BSP_CFG_BOOT_IMAGE (1) +#endif #define BSP_CFG_MCU_VCC_MV (3300) #define BSP_CFG_STACK_MAIN_BYTES (0x4000) #define BSP_CFG_HEAP_BYTES (0x4d000) @@ -25,15 +35,14 @@ #define BSP_CFG_PFS_PROTECT ((1)) #define BSP_CFG_C_RUNTIME_INIT ((1)) +#define BSP_CFG_EARLY_INIT ((0)) -#define BSP_CFG_SOFT_RESET_SUPPORTED ((0)) +#define BSP_CFG_STARTUP_CLOCK_REG_NOT_RESET ((0)) #ifndef BSP_CLOCK_CFG_MAIN_OSC_POPULATED #define BSP_CLOCK_CFG_MAIN_OSC_POPULATED (1) #endif -#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT -#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) -#endif + #ifndef BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE #define BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE (0) #endif @@ -46,4 +55,8 @@ #ifndef BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS #define BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS 1000 #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h index 6097e9d7d3..39e9384f7c 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h @@ -2,6 +2,7 @@ #ifndef BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_R7FA6M2AF3CFB +#define BSP_MCU_FEATURE_SET ('A') #define BSP_ROM_SIZE_BYTES (1048576) #define BSP_RAM_SIZE_BYTES (393216) #define BSP_DATA_FLASH_SIZE_BYTES (32768) diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h index 51f399e3c9..f3b369cbc4 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_MCU_FAMILY_CFG_H_ #define BSP_MCU_FAMILY_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_mcu_device_pn_cfg.h" #include "bsp_mcu_device_cfg.h" #include "../../../ra/fsp/src/bsp/mcu/ra6m2/bsp_mcu_info.h" @@ -23,7 +27,6 @@ #define BSP_CORTEX_VECTOR_TABLE_ENTRIES (16U) #define BSP_VECTOR_TABLE_MAX_ENTRIES (112U) -#define BSP_MCU_VBATT_SUPPORT (1) #define OFS_SEQ1 0xA001A001 | (1 << 1) | (3 << 2) #define OFS_SEQ2 (15 << 4) | (3 << 8) | (3 << 10) @@ -50,7 +53,9 @@ #define BSP_CFG_ROM_REG_MPU_REGION3_ENABLE (1) #define BSP_CFG_ROM_REG_MPU_REGION3_START (0x400DFFFC) #define BSP_CFG_ROM_REG_MPU_REGION3_END (0x400DFFFF) - +#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT +#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) +#endif /* Used to create IELS values for the interrupt initialization table g_interrupt_event_link_select. */ #define BSP_PRV_IELS_ENUM(vector) (ELC_##vector) @@ -71,4 +76,8 @@ #define BSP_CFG_ID_CODE_LONG_3 (0xFFFFFFFF) #define BSP_CFG_ID_CODE_LONG_4 (0xffFFFFFF) #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_MCU_FAMILY_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_adc_cfg.h index 9c59889ca8..be8a427206 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_adc_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_adc_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_ADC_CFG_H_ #define R_ADC_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define ADC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_ADC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_agt_cfg.h deleted file mode 100644 index d3ab559238..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_agt_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_AGT_CFG_H_ -#define R_AGT_CFG_H_ -#define AGT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define AGT_CFG_OUTPUT_SUPPORT_ENABLE (0) -#define AGT_CFG_INPUT_SUPPORT_ENABLE (0) -#endif /* R_AGT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_dtc_cfg.h deleted file mode 100644 index 21405f9674..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_dtc_cfg.h +++ /dev/null @@ -1,6 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_DTC_CFG_H_ -#define R_DTC_CFG_H_ -#define DTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define DTC_CFG_VECTOR_TABLE_SECTION_NAME ".fsp_dtc_vector_table" -#endif /* R_DTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_flash_hp_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_flash_hp_cfg.h index 48c9dec4e0..9f7819b71a 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_flash_hp_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_flash_hp_cfg.h @@ -1,7 +1,15 @@ /* generated configuration header file - do not edit */ #ifndef R_FLASH_HP_CFG_H_ #define R_FLASH_HP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define FLASH_HP_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) #define FLASH_HP_CFG_CODE_FLASH_PROGRAMMING_ENABLE (1) #define FLASH_HP_CFG_DATA_FLASH_PROGRAMMING_ENABLE (0) + +#ifdef __cplusplus +} +#endif #endif /* R_FLASH_HP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_icu_cfg.h deleted file mode 100644 index 5e77b6980f..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_icu_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_ICU_CFG_H_ -#define R_ICU_CFG_H_ -#define ICU_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_ICU_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_iic_master_cfg.h deleted file mode 100644 index 595ea938d1..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_iic_master_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_IIC_MASTER_CFG_H_ -#define R_IIC_MASTER_CFG_H_ -#define IIC_MASTER_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define IIC_MASTER_CFG_DTC_ENABLE (0) -#define IIC_MASTER_CFG_ADDR_MODE_10_BIT_ENABLE (0) -#endif /* R_IIC_MASTER_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_ioport_cfg.h index 6b4353d238..d2688bf5ba 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_ioport_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_ioport_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_IOPORT_CFG_H_ #define R_IOPORT_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define IOPORT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_IOPORT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_lpm_cfg.h index 5f4d5c4a73..6712eee6a1 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_lpm_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_lpm_cfg.h @@ -1,5 +1,14 @@ /* generated configuration header file - do not edit */ #ifndef R_LPM_CFG_H_ #define R_LPM_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define LPM_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define LPM_CFG_STANDBY_LIMIT (0) + +#ifdef __cplusplus +} +#endif #endif /* R_LPM_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_rtc_cfg.h deleted file mode 100644 index 484b7ed044..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_rtc_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_RTC_CFG_H_ -#define R_RTC_CFG_H_ -#define RTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_RTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_sci_uart_cfg.h deleted file mode 100644 index c70c0be344..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_sci_uart_cfg.h +++ /dev/null @@ -1,8 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SCI_UART_CFG_H_ -#define R_SCI_UART_CFG_H_ -#define SCI_UART_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SCI_UART_CFG_FIFO_SUPPORT (0) -#define SCI_UART_CFG_DTC_SUPPORTED (0) -#define SCI_UART_CFG_FLOW_CONTROL_SUPPORT (0) -#endif /* R_SCI_UART_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_spi_cfg.h deleted file mode 100644 index 861fe12194..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_cfg/fsp_cfg/r_spi_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SPI_CFG_H_ -#define R_SPI_CFG_H_ -#define SPI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SPI_DTC_SUPPORT_ENABLE (1) -#define SPI_TRANSMIT_FROM_RXI_ISR (0) -#endif /* R_SPI_CFG_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/bsp_clock_cfg.h index 2c93a573b4..85616224ef 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/bsp_clock_cfg.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/bsp_clock_cfg.h @@ -7,16 +7,16 @@ #define BSP_CFG_PLL_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_MAIN_OSC) /* PLL Src: XTAL */ #define BSP_CFG_HOCO_FREQUENCY (2) /* HOCO 20MHz */ #define BSP_CFG_PLL_DIV (BSP_CLOCKS_PLL_DIV_1) /* PLL Div /1 */ -#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL_20_0 /* PLL Mul x20.0 */ +#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL(20U, 0U) /* PLL Mul x20.0 */ #define BSP_CFG_CLOCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_PLL) /* Clock Src: PLL */ #define BSP_CFG_ICLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* ICLK Div /2 */ #define BSP_CFG_PCLKA_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* PCLKA Div /2 */ #define BSP_CFG_PCLKB_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_4) /* PCLKB Div /4 */ #define BSP_CFG_PCLKC_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_4) /* PCLKC Div /4 */ #define BSP_CFG_PCLKD_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* PCLKD Div /2 */ -#define BSP_CFG_SDCLK_OUTPUT (1) /* SDCLKout On */ +#define BSP_CFG_SDCLK_OUTPUT (1) /* SDCLK Enabled */ #define BSP_CFG_BCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_2) /* BCLK Div /2 */ -#define BSP_CFG_BCLK_OUTPUT (2) /* BCK/2 */ +#define BSP_CFG_BCLK_OUTPUT (2) /* EBCLK Div /2 */ #define BSP_CFG_UCK_DIV (BSP_CLOCKS_USB_CLOCK_DIV_5) /* UCLK Div /5 */ #define BSP_CFG_FCLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_4) /* FCLK Div /4 */ #define BSP_CFG_CLKOUT_SOURCE (BSP_CLOCKS_CLOCK_DISABLED) /* CLKOUT Disabled */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.c index 34aad762ff..c52056c5ce 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.c +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.c @@ -1,7 +1,5 @@ -/* generated common source file - do not edit */ #include "common_data.h" + ioport_instance_ctrl_t g_ioport_ctrl; const ioport_instance_t g_ioport = { .p_api = &g_ioport_on_ioport, .p_ctrl = &g_ioport_ctrl, .p_cfg = &g_bsp_pin_cfg, }; -void g_common_init(void) { -} diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.h index e2eb70836b..3cabbef1b3 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/common_data.h @@ -1,16 +1,17 @@ -/* generated common header file - do not edit */ #ifndef COMMON_DATA_H_ #define COMMON_DATA_H_ #include #include "bsp_api.h" +#include "r_icu.h" +#include "r_external_irq_api.h" #include "r_ioport.h" #include "bsp_pin_cfg.h" FSP_HEADER + /* IOPORT Instance */ extern const ioport_instance_t g_ioport; /* IOPORT control structure. */ extern ioport_instance_ctrl_t g_ioport_ctrl; -void g_common_init(void); FSP_FOOTER #endif /* COMMON_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.c index b0d38881e0..0138e5b11f 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.c +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.c @@ -1,131 +1,16 @@ -/* generated HAL source file - do not edit */ #include "hal_data.h" -/* Macros to tie dynamic ELC links to ADC_TRIGGER_SYNC_ELC option in adc_trigger_t. */ -#define ADC_TRIGGER_ADC0 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC0_B ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1_B ADC_TRIGGER_SYNC_ELC -iic_master_instance_ctrl_t g_i2c_master2_ctrl; -const iic_master_extended_cfg_t g_i2c_master2_extend = -{ .timeout_mode = IIC_MASTER_TIMEOUT_MODE_SHORT, -/* Actual calculated bitrate: 98945. Actual calculated duty cycle: 51%. */ .clock_settings.brl_value = 15, - .clock_settings.brh_value = 16, .clock_settings.cks_value = 4, }; -const i2c_master_cfg_t g_i2c_master2_cfg = -{ .channel = 2, .rate = I2C_MASTER_RATE_STANDARD, .slave = 0x00, .addr_mode = I2C_MASTER_ADDR_MODE_7BIT, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .p_callback = callback_iic, - .p_context = NULL, - #if defined(VECTOR_NUMBER_IIC2_RXI) - .rxi_irq = VECTOR_NUMBER_IIC2_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC2_TXI) - .txi_irq = VECTOR_NUMBER_IIC2_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC2_TEI) - .tei_irq = VECTOR_NUMBER_IIC2_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC2_ERI) - .eri_irq = VECTOR_NUMBER_IIC2_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - .ipl = (12), - .p_extend = &g_i2c_master2_extend, }; -/* Instance structure to use this module. */ -const i2c_master_instance_t g_i2c_master2 = -{ .p_ctrl = &g_i2c_master2_ctrl, .p_cfg = &g_i2c_master2_cfg, .p_api = &g_i2c_master_on_iic }; -adc_instance_ctrl_t g_adc1_ctrl; -const adc_extended_cfg_t g_adc1_cfg_extend = -{ .add_average_count = ADC_ADD_OFF, - .clearing = ADC_CLEAR_AFTER_READ_ON, - .trigger_group_b = ADC_TRIGGER_SYNC_ELC, - .double_trigger_mode = ADC_DOUBLE_TRIGGER_DISABLED, - .adc_vref_control = ADC_VREF_CONTROL_VREFH, }; -const adc_cfg_t g_adc1_cfg = -{ .unit = 1, .mode = ADC_MODE_SINGLE_SCAN, .resolution = ADC_RESOLUTION_12_BIT, .alignment = - (adc_alignment_t)ADC_ALIGNMENT_RIGHT, - .trigger = ADC_TRIGGER_SOFTWARE, .p_callback = NULL, .p_context = NULL, .p_extend = &g_adc1_cfg_extend, - #if defined(VECTOR_NUMBER_ADC1_SCAN_END) - .scan_end_irq = VECTOR_NUMBER_ADC1_SCAN_END, - #else - .scan_end_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_ipl = (BSP_IRQ_DISABLED), - #if defined(VECTOR_NUMBER_ADC1_SCAN_END_B) - .scan_end_b_irq = VECTOR_NUMBER_ADC1_SCAN_END_B, - #else - .scan_end_b_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; -const adc_channel_cfg_t g_adc1_channel_cfg = -{ .scan_mask = 0, - .scan_mask_group_b = 0, - .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, - .add_mask = 0, - .sample_hold_mask = 0, - .sample_hold_states = 24, }; -/* Instance structure to use this module. */ -const adc_instance_t g_adc1 = -{ .p_ctrl = &g_adc1_ctrl, .p_cfg = &g_adc1_cfg, .p_channel_cfg = &g_adc1_channel_cfg, .p_api = &g_adc_on_adc }; -adc_instance_ctrl_t g_adc0_ctrl; -const adc_extended_cfg_t g_adc0_cfg_extend = -{ .add_average_count = ADC_ADD_OFF, - .clearing = ADC_CLEAR_AFTER_READ_ON, - .trigger_group_b = ADC_TRIGGER_SYNC_ELC, - .double_trigger_mode = ADC_DOUBLE_TRIGGER_DISABLED, - .adc_vref_control = ADC_VREF_CONTROL_VREFH, }; -const adc_cfg_t g_adc0_cfg = -{ .unit = 0, .mode = ADC_MODE_SINGLE_SCAN, .resolution = ADC_RESOLUTION_12_BIT, .alignment = - (adc_alignment_t)ADC_ALIGNMENT_RIGHT, - .trigger = ADC_TRIGGER_SOFTWARE, .p_callback = NULL, .p_context = NULL, .p_extend = &g_adc0_cfg_extend, - #if defined(VECTOR_NUMBER_ADC0_SCAN_END) - .scan_end_irq = VECTOR_NUMBER_ADC0_SCAN_END, - #else - .scan_end_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_ipl = (BSP_IRQ_DISABLED), - #if defined(VECTOR_NUMBER_ADC0_SCAN_END_B) - .scan_end_b_irq = VECTOR_NUMBER_ADC0_SCAN_END_B, - #else - .scan_end_b_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; -const adc_channel_cfg_t g_adc0_channel_cfg = -{ .scan_mask = 0, - .scan_mask_group_b = 0, - .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, - .add_mask = 0, - .sample_hold_mask = 0, - .sample_hold_states = 24, }; -/* Instance structure to use this module. */ -const adc_instance_t g_adc0 = -{ .p_ctrl = &g_adc0_ctrl, .p_cfg = &g_adc0_cfg, .p_channel_cfg = &g_adc0_channel_cfg, .p_api = &g_adc_on_adc }; + lpm_instance_ctrl_t g_lpm0_ctrl; const lpm_cfg_t g_lpm0_cfg = -{ .low_power_mode = LPM_MODE_SLEEP, +{ .low_power_mode = LPM_MODE_SLEEP, .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM + | (lpm_standby_wake_source_t)0, + #if BSP_FEATURE_LPM_HAS_SNOOZE .snooze_cancel_sources = LPM_SNOOZE_CANCEL_SOURCE_NONE, - .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM | (lpm_standby_wake_source_t)0, .snooze_request_source = LPM_SNOOZE_REQUEST_RXD0_FALLING, .snooze_end_sources = (lpm_snooze_end_t)0, .dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE, + #endif #if BSP_FEATURE_LPM_HAS_SBYCR_OPE .output_port_enable = LPM_OUTPUT_PORT_ENABLE_RETAIN, #endif @@ -135,598 +20,24 @@ const lpm_cfg_t g_lpm0_cfg = .deep_standby_cancel_source = (lpm_deep_standby_cancel_source_t)0, .deep_standby_cancel_edge = (lpm_deep_standby_cancel_edge_t)0, #endif + #if BSP_FEATURE_LPM_HAS_PDRAMSCR + .ram_retention_cfg.ram_retention = (uint8_t)(0), + .ram_retention_cfg.tcm_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_DPSBYCR_SRKEEP + .ram_retention_cfg.standby_ram_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_LDO_CONTROL + .ldo_standby_cfg.pll1_ldo = false, + .ldo_standby_cfg.pll2_ldo = false, + .ldo_standby_cfg.hoco_ldo = false, + #endif .p_extend = NULL, }; const lpm_instance_t g_lpm0 = { .p_api = &g_lpm_on_lpm, .p_ctrl = &g_lpm0_ctrl, .p_cfg = &g_lpm0_cfg }; -dtc_instance_ctrl_t g_transfer3_ctrl; -transfer_info_t g_transfer3_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .repeat_area = TRANSFER_REPEAT_AREA_DESTINATION, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer3_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI1_RXI, }; -const transfer_cfg_t g_transfer3_cfg = -{ .p_info = &g_transfer3_info, .p_extend = &g_transfer3_cfg_extend, }; -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer3 = -{ .p_ctrl = &g_transfer3_ctrl, .p_cfg = &g_transfer3_cfg, .p_api = &g_transfer_on_dtc }; -dtc_instance_ctrl_t g_transfer2_ctrl; - -transfer_info_t g_transfer2_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .repeat_area = TRANSFER_REPEAT_AREA_SOURCE, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer2_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI1_TXI, }; -const transfer_cfg_t g_transfer2_cfg = -{ .p_info = &g_transfer2_info, .p_extend = &g_transfer2_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer2 = -{ .p_ctrl = &g_transfer2_ctrl, .p_cfg = &g_transfer2_cfg, .p_api = &g_transfer_on_dtc }; -spi_instance_ctrl_t g_spi1_ctrl; - -/** SPI extended configuration for SPI HAL driver */ -const spi_extended_cfg_t g_spi1_ext_cfg = -{ .spi_clksyn = SPI_SSL_MODE_CLK_SYN, - .spi_comm = SPI_COMMUNICATION_FULL_DUPLEX, - .ssl_polarity = SPI_SSLP_LOW, - .ssl_select = SPI_SSL_SELECT_SSL0, - .mosi_idle = SPI_MOSI_IDLE_VALUE_FIXING_DISABLE, - .parity = SPI_PARITY_MODE_DISABLE, - .byte_swap = SPI_BYTE_SWAP_DISABLE, - .spck_div = - { - /* Actual calculated bitrate: 15000000. */ .spbr = 3, - .brdv = 0 - }, - .spck_delay = SPI_DELAY_COUNT_1, - .ssl_negation_delay = SPI_DELAY_COUNT_1, - .next_access_delay = SPI_DELAY_COUNT_1 }; - -/** SPI configuration for SPI HAL driver */ -const spi_cfg_t g_spi1_cfg = -{ .channel = 1, - - #if defined(VECTOR_NUMBER_SPI1_RXI) - .rxi_irq = VECTOR_NUMBER_SPI1_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI1_TXI) - .txi_irq = VECTOR_NUMBER_SPI1_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI1_TEI) - .tei_irq = VECTOR_NUMBER_SPI1_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI1_ERI) - .eri_irq = VECTOR_NUMBER_SPI1_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - - .rxi_ipl = (12), - .txi_ipl = (12), - .tei_ipl = (12), - .eri_ipl = (12), - - .operating_mode = SPI_MODE_MASTER, - - .clk_phase = SPI_CLK_PHASE_EDGE_ODD, - .clk_polarity = SPI_CLK_POLARITY_LOW, - - .mode_fault = SPI_MODE_FAULT_ERROR_DISABLE, - .bit_order = SPI_BIT_ORDER_MSB_FIRST, - .p_transfer_tx = g_spi1_P_TRANSFER_TX, - .p_transfer_rx = g_spi1_P_TRANSFER_RX, - .p_callback = spi_callback, - - .p_context = NULL, - .p_extend = (void *)&g_spi1_ext_cfg, }; - -/* Instance structure to use this module. */ -const spi_instance_t g_spi1 = -{ .p_ctrl = &g_spi1_ctrl, .p_cfg = &g_spi1_cfg, .p_api = &g_spi_on_spi }; -dtc_instance_ctrl_t g_transfer1_ctrl; - -transfer_info_t g_transfer1_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .repeat_area = TRANSFER_REPEAT_AREA_DESTINATION, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer1_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_RXI, }; -const transfer_cfg_t g_transfer1_cfg = -{ .p_info = &g_transfer1_info, .p_extend = &g_transfer1_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer1 = -{ .p_ctrl = &g_transfer1_ctrl, .p_cfg = &g_transfer1_cfg, .p_api = &g_transfer_on_dtc }; -dtc_instance_ctrl_t g_transfer0_ctrl; - -transfer_info_t g_transfer0_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .repeat_area = TRANSFER_REPEAT_AREA_SOURCE, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer0_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_TXI, }; -const transfer_cfg_t g_transfer0_cfg = -{ .p_info = &g_transfer0_info, .p_extend = &g_transfer0_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer0 = -{ .p_ctrl = &g_transfer0_ctrl, .p_cfg = &g_transfer0_cfg, .p_api = &g_transfer_on_dtc }; -spi_instance_ctrl_t g_spi0_ctrl; - -/** SPI extended configuration for SPI HAL driver */ -const spi_extended_cfg_t g_spi0_ext_cfg = -{ .spi_clksyn = SPI_SSL_MODE_CLK_SYN, - .spi_comm = SPI_COMMUNICATION_FULL_DUPLEX, - .ssl_polarity = SPI_SSLP_LOW, - .ssl_select = SPI_SSL_SELECT_SSL0, - .mosi_idle = SPI_MOSI_IDLE_VALUE_FIXING_DISABLE, - .parity = SPI_PARITY_MODE_DISABLE, - .byte_swap = SPI_BYTE_SWAP_DISABLE, - .spck_div = - { - /* Actual calculated bitrate: 15000000. */ .spbr = 3, - .brdv = 0 - }, - .spck_delay = SPI_DELAY_COUNT_1, - .ssl_negation_delay = SPI_DELAY_COUNT_1, - .next_access_delay = SPI_DELAY_COUNT_1 }; - -/** SPI configuration for SPI HAL driver */ -const spi_cfg_t g_spi0_cfg = -{ .channel = 0, - - #if defined(VECTOR_NUMBER_SPI0_RXI) - .rxi_irq = VECTOR_NUMBER_SPI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TXI) - .txi_irq = VECTOR_NUMBER_SPI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TEI) - .tei_irq = VECTOR_NUMBER_SPI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_ERI) - .eri_irq = VECTOR_NUMBER_SPI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - - .rxi_ipl = (12), - .txi_ipl = (12), - .tei_ipl = (12), - .eri_ipl = (12), - - .operating_mode = SPI_MODE_MASTER, - - .clk_phase = SPI_CLK_PHASE_EDGE_ODD, - .clk_polarity = SPI_CLK_POLARITY_LOW, - - .mode_fault = SPI_MODE_FAULT_ERROR_DISABLE, - .bit_order = SPI_BIT_ORDER_MSB_FIRST, - .p_transfer_tx = g_spi0_P_TRANSFER_TX, - .p_transfer_rx = g_spi0_P_TRANSFER_RX, - .p_callback = spi_callback, - - .p_context = NULL, - .p_extend = (void *)&g_spi0_ext_cfg, }; - -/* Instance structure to use this module. */ -const spi_instance_t g_spi0 = -{ .p_ctrl = &g_spi0_ctrl, .p_cfg = &g_spi0_cfg, .p_api = &g_spi_on_spi }; -icu_instance_ctrl_t g_external_irq15_ctrl; -const external_irq_cfg_t g_external_irq15_cfg = -{ .channel = 15, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ15) - .irq = VECTOR_NUMBER_ICU_IRQ15, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq15 = -{ .p_ctrl = &g_external_irq15_ctrl, .p_cfg = &g_external_irq15_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq14_ctrl; -const external_irq_cfg_t g_external_irq14_cfg = -{ .channel = 14, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ14) - .irq = VECTOR_NUMBER_ICU_IRQ14, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq14 = -{ .p_ctrl = &g_external_irq14_ctrl, .p_cfg = &g_external_irq14_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq13_ctrl; -const external_irq_cfg_t g_external_irq13_cfg = -{ .channel = 13, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ13) - .irq = VECTOR_NUMBER_ICU_IRQ13, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq13 = -{ .p_ctrl = &g_external_irq13_ctrl, .p_cfg = &g_external_irq13_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq12_ctrl; -const external_irq_cfg_t g_external_irq12_cfg = -{ .channel = 12, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ12) - .irq = VECTOR_NUMBER_ICU_IRQ12, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq12 = -{ .p_ctrl = &g_external_irq12_ctrl, .p_cfg = &g_external_irq12_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq11_ctrl; -const external_irq_cfg_t g_external_irq11_cfg = -{ .channel = 11, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ11) - .irq = VECTOR_NUMBER_ICU_IRQ11, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq11 = -{ .p_ctrl = &g_external_irq11_ctrl, .p_cfg = &g_external_irq11_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq10_ctrl; -const external_irq_cfg_t g_external_irq10_cfg = -{ .channel = 10, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ10) - .irq = VECTOR_NUMBER_ICU_IRQ10, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq10 = -{ .p_ctrl = &g_external_irq10_ctrl, .p_cfg = &g_external_irq10_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq9_ctrl; -const external_irq_cfg_t g_external_irq9_cfg = -{ .channel = 9, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ9) - .irq = VECTOR_NUMBER_ICU_IRQ9, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq9 = -{ .p_ctrl = &g_external_irq9_ctrl, .p_cfg = &g_external_irq9_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq8_ctrl; -const external_irq_cfg_t g_external_irq8_cfg = -{ .channel = 8, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ8) - .irq = VECTOR_NUMBER_ICU_IRQ8, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq8 = -{ .p_ctrl = &g_external_irq8_ctrl, .p_cfg = &g_external_irq8_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq7_ctrl; -const external_irq_cfg_t g_external_irq7_cfg = -{ .channel = 7, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ7) - .irq = VECTOR_NUMBER_ICU_IRQ7, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq7 = -{ .p_ctrl = &g_external_irq7_ctrl, .p_cfg = &g_external_irq7_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq6_ctrl; -const external_irq_cfg_t g_external_irq6_cfg = -{ .channel = 6, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ6) - .irq = VECTOR_NUMBER_ICU_IRQ6, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq6 = -{ .p_ctrl = &g_external_irq6_ctrl, .p_cfg = &g_external_irq6_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq5_ctrl; -const external_irq_cfg_t g_external_irq5_cfg = -{ .channel = 5, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ5) - .irq = VECTOR_NUMBER_ICU_IRQ5, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq5 = -{ .p_ctrl = &g_external_irq5_ctrl, .p_cfg = &g_external_irq5_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq4_ctrl; -const external_irq_cfg_t g_external_irq4_cfg = -{ .channel = 4, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ4) - .irq = VECTOR_NUMBER_ICU_IRQ4, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq4 = -{ .p_ctrl = &g_external_irq4_ctrl, .p_cfg = &g_external_irq4_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq3_ctrl; -const external_irq_cfg_t g_external_irq3_cfg = -{ .channel = 3, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ3) - .irq = VECTOR_NUMBER_ICU_IRQ3, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq3 = -{ .p_ctrl = &g_external_irq3_ctrl, .p_cfg = &g_external_irq3_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq2_ctrl; -const external_irq_cfg_t g_external_irq2_cfg = -{ .channel = 2, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ2) - .irq = VECTOR_NUMBER_ICU_IRQ2, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq2 = -{ .p_ctrl = &g_external_irq2_ctrl, .p_cfg = &g_external_irq2_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq1_ctrl; -const external_irq_cfg_t g_external_irq1_cfg = -{ .channel = 1, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ1) - .irq = VECTOR_NUMBER_ICU_IRQ1, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq1 = -{ .p_ctrl = &g_external_irq1_ctrl, .p_cfg = &g_external_irq1_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq0_ctrl; -const external_irq_cfg_t g_external_irq0_cfg = -{ .channel = 0, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ0) - .irq = VECTOR_NUMBER_ICU_IRQ0, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq0 = -{ .p_ctrl = &g_external_irq0_ctrl, .p_cfg = &g_external_irq0_cfg, .p_api = &g_external_irq_on_icu }; -agt_instance_ctrl_t g_timer1_ctrl; -const agt_extended_cfg_t g_timer1_extend = -{ .count_source = AGT_CLOCK_PCLKB, - .agto = AGT_PIN_CFG_DISABLED, - .agtoa = AGT_PIN_CFG_DISABLED, - .agtob = AGT_PIN_CFG_DISABLED, - .measurement_mode = AGT_MEASURE_DISABLED, - .agtio_filter = AGT_AGTIO_FILTER_NONE, - .enable_pin = AGT_ENABLE_PIN_NOT_USED, - .trigger_edge = AGT_TRIGGER_EDGE_RISING, }; -const timer_cfg_t g_timer1_cfg = -{ .mode = TIMER_MODE_PERIODIC, -/* Actual period: 0.0010922666666666667 seconds. Actual duty: 50%. */ .period_counts = 0x10000, - .duty_cycle_counts = 0x8000, .source_div = (timer_source_div_t)0, .channel = 0, .p_callback = callback_agt, - /** If NULL then do not add & */ - #if defined(NULL) - .p_context = NULL, - #else - .p_context = &NULL, - #endif - .p_extend = &g_timer1_extend, - .cycle_end_ipl = (5), - #if defined(VECTOR_NUMBER_AGT0_INT) - .cycle_end_irq = VECTOR_NUMBER_AGT0_INT, - #else - .cycle_end_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const timer_instance_t g_timer1 = -{ .p_ctrl = &g_timer1_ctrl, .p_cfg = &g_timer1_cfg, .p_api = &g_timer_on_agt }; -agt_instance_ctrl_t g_timer0_ctrl; -const agt_extended_cfg_t g_timer0_extend = -{ .count_source = AGT_CLOCK_PCLKB, - .agto = AGT_PIN_CFG_DISABLED, - .agtoa = AGT_PIN_CFG_DISABLED, - .agtob = AGT_PIN_CFG_DISABLED, - .measurement_mode = AGT_MEASURE_DISABLED, - .agtio_filter = AGT_AGTIO_FILTER_NONE, - .enable_pin = AGT_ENABLE_PIN_NOT_USED, - .trigger_edge = AGT_TRIGGER_EDGE_RISING, }; -const timer_cfg_t g_timer0_cfg = -{ .mode = TIMER_MODE_PERIODIC, -/* Actual period: 0.0010922666666666667 seconds. Actual duty: 50%. */ .period_counts = 0x10000, - .duty_cycle_counts = 0x8000, .source_div = (timer_source_div_t)0, .channel = 0, .p_callback = callback_agt, - /** If NULL then do not add & */ - #if defined(NULL) - .p_context = NULL, - #else - .p_context = &NULL, - #endif - .p_extend = &g_timer0_extend, - .cycle_end_ipl = (5), - #if defined(VECTOR_NUMBER_AGT0_INT) - .cycle_end_irq = VECTOR_NUMBER_AGT0_INT, - #else - .cycle_end_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const timer_instance_t g_timer0 = -{ .p_ctrl = &g_timer0_ctrl, .p_cfg = &g_timer0_cfg, .p_api = &g_timer_on_agt }; flash_hp_instance_ctrl_t g_flash0_ctrl; const flash_cfg_t g_flash0_cfg = { .data_flash_bgo = false, .p_callback = NULL, .p_context = NULL, @@ -745,239 +56,3 @@ const flash_cfg_t g_flash0_cfg = /* Instance structure to use this module. */ const flash_instance_t g_flash0 = { .p_ctrl = &g_flash0_ctrl, .p_cfg = &g_flash0_cfg, .p_api = &g_flash_on_flash_hp }; -rtc_instance_ctrl_t g_rtc0_ctrl; -const rtc_error_adjustment_cfg_t g_rtc0_err_cfg = -{ .adjustment_mode = RTC_ERROR_ADJUSTMENT_MODE_AUTOMATIC, - .adjustment_period = RTC_ERROR_ADJUSTMENT_PERIOD_10_SECOND, - .adjustment_type = RTC_ERROR_ADJUSTMENT_NONE, - .adjustment_value = 0, }; -const rtc_cfg_t g_rtc0_cfg = -{ .clock_source = RTC_CLOCK_SOURCE_LOCO, .freq_compare_value_loco = 255, .p_err_cfg = &g_rtc0_err_cfg, .p_callback = - NULL, - .p_context = NULL, .alarm_ipl = (14), .periodic_ipl = (14), .carry_ipl = (14), - #if defined(VECTOR_NUMBER_RTC_ALARM) - .alarm_irq = VECTOR_NUMBER_RTC_ALARM, - #else - .alarm_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_PERIOD) - .periodic_irq = VECTOR_NUMBER_RTC_PERIOD, - #else - .periodic_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_CARRY) - .carry_irq = VECTOR_NUMBER_RTC_CARRY, - #else - .carry_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const rtc_instance_t g_rtc0 = -{ .p_ctrl = &g_rtc0_ctrl, .p_cfg = &g_rtc0_cfg, .p_api = &g_rtc_on_rtc }; -sci_uart_instance_ctrl_t g_uart9_ctrl; - -baud_setting_t g_uart9_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 64, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart9_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart9_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart9_cfg = -{ .channel = 9, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart9_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI9_RXI) - .rxi_irq = VECTOR_NUMBER_SCI9_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI9_TXI) - .txi_irq = VECTOR_NUMBER_SCI9_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI9_TEI) - .tei_irq = VECTOR_NUMBER_SCI9_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI9_ERI) - .eri_irq = VECTOR_NUMBER_SCI9_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart9 = -{ .p_ctrl = &g_uart9_ctrl, .p_cfg = &g_uart9_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart7_ctrl; - -baud_setting_t g_uart7_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 64, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart7_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart7_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart7_cfg = -{ .channel = 7, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart7_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI7_RXI) - .rxi_irq = VECTOR_NUMBER_SCI7_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI7_TXI) - .txi_irq = VECTOR_NUMBER_SCI7_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI7_TEI) - .tei_irq = VECTOR_NUMBER_SCI7_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI7_ERI) - .eri_irq = VECTOR_NUMBER_SCI7_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart7 = -{ .p_ctrl = &g_uart7_ctrl, .p_cfg = &g_uart7_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart0_ctrl; - -baud_setting_t g_uart0_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 64, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart0_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart0_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart0_cfg = -{ .channel = 0, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart0_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI0_RXI) - .rxi_irq = VECTOR_NUMBER_SCI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_TXI) - .txi_irq = VECTOR_NUMBER_SCI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_TEI) - .tei_irq = VECTOR_NUMBER_SCI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_ERI) - .eri_irq = VECTOR_NUMBER_SCI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart0 = -{ .p_ctrl = &g_uart0_ctrl, .p_cfg = &g_uart0_cfg, .p_api = &g_uart_on_sci }; -void g_hal_init(void) { - g_common_init(); -} diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h index 59d2a91228..51fe21a160 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h @@ -2,318 +2,20 @@ #ifndef HAL_DATA_H_ #define HAL_DATA_H_ #include -#include "bsp_api.h" #include "common_data.h" -#include "r_iic_master.h" -#include "r_i2c_master_api.h" -#include "r_adc.h" -#include "r_adc_api.h" #include "r_lpm.h" #include "r_lpm_api.h" -#include "r_dtc.h" -#include "r_transfer_api.h" -#include "r_spi.h" -#include "r_icu.h" -#include "r_external_irq_api.h" -#include "r_agt.h" -#include "r_timer_api.h" #include "r_flash_hp.h" #include "r_flash_api.h" -#include "r_rtc.h" -#include "r_rtc_api.h" -#include "r_sci_uart.h" -#include "r_uart_api.h" FSP_HEADER -/* I2C Master on IIC Instance. */ -extern const i2c_master_instance_t g_i2c_master2; -/** Access the I2C Master instance using these structures when calling API functions directly (::p_api is not used). */ -extern iic_master_instance_ctrl_t g_i2c_master2_ctrl; -extern const i2c_master_cfg_t g_i2c_master2_cfg; - -#ifndef callback_iic -void callback_iic(i2c_master_callback_args_t *p_args); -#endif -/** ADC on ADC Instance. */ -extern const adc_instance_t g_adc1; - -/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ -extern adc_instance_ctrl_t g_adc1_ctrl; -extern const adc_cfg_t g_adc1_cfg; -extern const adc_channel_cfg_t g_adc1_channel_cfg; - -#ifndef NULL -void NULL(adc_callback_args_t *p_args); -#endif -/** ADC on ADC Instance. */ -extern const adc_instance_t g_adc0; - -/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ -extern adc_instance_ctrl_t g_adc0_ctrl; -extern const adc_cfg_t g_adc0_cfg; -extern const adc_channel_cfg_t g_adc0_channel_cfg; - -#ifndef NULL -void NULL(adc_callback_args_t *p_args); -#endif /** lpm Instance */ extern const lpm_instance_t g_lpm0; /** Access the LPM instance using these structures when calling API functions directly (::p_api is not used). */ extern lpm_instance_ctrl_t g_lpm0_ctrl; extern const lpm_cfg_t g_lpm0_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer3; -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer3_ctrl; -extern const transfer_cfg_t g_transfer3_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer2; - -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer2_ctrl; -extern const transfer_cfg_t g_transfer2_cfg; -/** SPI on SPI Instance. */ -extern const spi_instance_t g_spi1; - -/** Access the SPI instance using these structures when calling API functions directly (::p_api is not used). */ -extern spi_instance_ctrl_t g_spi1_ctrl; -extern const spi_cfg_t g_spi1_cfg; - -/** Callback used by SPI Instance. */ -#ifndef spi_callback -void spi_callback(spi_callback_args_t *p_args); -#endif - -#define RA_NOT_DEFINED (1) -#if (RA_NOT_DEFINED == g_transfer2) - #define g_spi1_P_TRANSFER_TX (NULL) -#else -#define g_spi1_P_TRANSFER_TX (&g_transfer2) -#endif -#if (RA_NOT_DEFINED == g_transfer3) - #define g_spi1_P_TRANSFER_RX (NULL) -#else -#define g_spi1_P_TRANSFER_RX (&g_transfer3) -#endif -#undef RA_NOT_DEFINED -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer1; - -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer1_ctrl; -extern const transfer_cfg_t g_transfer1_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer0; - -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer0_ctrl; -extern const transfer_cfg_t g_transfer0_cfg; -/** SPI on SPI Instance. */ -extern const spi_instance_t g_spi0; - -/** Access the SPI instance using these structures when calling API functions directly (::p_api is not used). */ -extern spi_instance_ctrl_t g_spi0_ctrl; -extern const spi_cfg_t g_spi0_cfg; - -/** Callback used by SPI Instance. */ -#ifndef spi_callback -void spi_callback(spi_callback_args_t *p_args); -#endif - -#define RA_NOT_DEFINED (1) -#if (RA_NOT_DEFINED == g_transfer0) - #define g_spi0_P_TRANSFER_TX (NULL) -#else -#define g_spi0_P_TRANSFER_TX (&g_transfer0) -#endif -#if (RA_NOT_DEFINED == g_transfer1) - #define g_spi0_P_TRANSFER_RX (NULL) -#else -#define g_spi0_P_TRANSFER_RX (&g_transfer1) -#endif -#undef RA_NOT_DEFINED -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq15; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq15_ctrl; -extern const external_irq_cfg_t g_external_irq15_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq14; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq14_ctrl; -extern const external_irq_cfg_t g_external_irq14_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq13; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq13_ctrl; -extern const external_irq_cfg_t g_external_irq13_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq12; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq12_ctrl; -extern const external_irq_cfg_t g_external_irq12_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq11; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq11_ctrl; -extern const external_irq_cfg_t g_external_irq11_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq10; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq10_ctrl; -extern const external_irq_cfg_t g_external_irq10_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq9; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq9_ctrl; -extern const external_irq_cfg_t g_external_irq9_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq8; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq8_ctrl; -extern const external_irq_cfg_t g_external_irq8_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq7; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq7_ctrl; -extern const external_irq_cfg_t g_external_irq7_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq6; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq6_ctrl; -extern const external_irq_cfg_t g_external_irq6_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq5; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq5_ctrl; -extern const external_irq_cfg_t g_external_irq5_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq4; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq4_ctrl; -extern const external_irq_cfg_t g_external_irq4_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq3; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq3_ctrl; -extern const external_irq_cfg_t g_external_irq3_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq2; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq2_ctrl; -extern const external_irq_cfg_t g_external_irq2_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq1; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq1_ctrl; -extern const external_irq_cfg_t g_external_irq1_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq0; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq0_ctrl; -extern const external_irq_cfg_t g_external_irq0_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** AGT Timer Instance */ -extern const timer_instance_t g_timer1; - -/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ -extern agt_instance_ctrl_t g_timer1_ctrl; -extern const timer_cfg_t g_timer1_cfg; - -#ifndef callback_agt -void callback_agt(timer_callback_args_t *p_args); -#endif -/** AGT Timer Instance */ -extern const timer_instance_t g_timer0; - -/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ -extern agt_instance_ctrl_t g_timer0_ctrl; -extern const timer_cfg_t g_timer0_cfg; - -#ifndef callback_agt -void callback_agt(timer_callback_args_t *p_args); -#endif /* Flash on Flash HP Instance */ extern const flash_instance_t g_flash0; @@ -321,53 +23,6 @@ extern const flash_instance_t g_flash0; extern flash_hp_instance_ctrl_t g_flash0_ctrl; extern const flash_cfg_t g_flash0_cfg; -#ifndef NULL -void NULL(flash_callback_args_t *p_args); -#endif -/* RTC Instance. */ -extern const rtc_instance_t g_rtc0; - -/** Access the RTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern rtc_instance_ctrl_t g_rtc0_ctrl; -extern const rtc_cfg_t g_rtc0_cfg; - -#ifndef NULL -void NULL(rtc_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart9; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart9_ctrl; -extern const uart_cfg_t g_uart9_cfg; -extern const sci_uart_extended_cfg_t g_uart9_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart7; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart7_ctrl; -extern const uart_cfg_t g_uart7_cfg; -extern const sci_uart_extended_cfg_t g_uart7_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart0; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart0_ctrl; -extern const uart_cfg_t g_uart0_cfg; -extern const sci_uart_extended_cfg_t g_uart0_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif void hal_entry(void); -void g_hal_init(void); FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/pin_data.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/pin_data.c index 28330830c9..da649d1587 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/pin_data.c +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/pin_data.c @@ -1,117 +1,97 @@ /* generated pin source file - do not edit */ #include "bsp_api.h" #include "r_ioport_api.h" -const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = { - { - .pin = BSP_IO_PORT_00_PIN_04, - .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE), - }, - { - .pin = BSP_IO_PORT_01_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_03, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_05, - .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), - }, - { - .pin = BSP_IO_PORT_01_PIN_06, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_01_PIN_08, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_09, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_02_PIN_05, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_CTSU), - }, - { - .pin = BSP_IO_PORT_02_PIN_07, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_CTSU), - }, - { - .pin = BSP_IO_PORT_03_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_04_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_04_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_04_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_04_PIN_07, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_USB_FS), - }, - { - .pin = BSP_IO_PORT_04_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_04_PIN_11, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_05_PIN_11, - .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC), - }, - { - .pin = BSP_IO_PORT_05_PIN_12, - .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC), - }, - { - .pin = BSP_IO_PORT_06_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_06_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_07_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_07_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_07_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_07_PIN_03, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, -}; -const ioport_cfg_t g_bsp_pin_cfg = { - .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), - .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], + +const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = +{ + { .pin = BSP_IO_PORT_00_PIN_04, .pin_cfg = ((uint32_t)IOPORT_CFG_ANALOG_ENABLE) }, + { .pin = BSP_IO_PORT_01_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_03, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_05, .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, + { .pin = BSP_IO_PORT_01_PIN_06, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_01_PIN_08, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_09, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_02_PIN_05, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_CTSU) }, + { .pin = BSP_IO_PORT_02_PIN_07, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_CTSU) }, + { .pin = BSP_IO_PORT_03_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_04_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_04_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_04_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_04_PIN_07, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_USB_FS) }, + { .pin = BSP_IO_PORT_04_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_04_PIN_11, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_05_PIN_11, .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID + | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC) }, + { .pin = BSP_IO_PORT_05_PIN_12, .pin_cfg = ((uint32_t)IOPORT_CFG_DRIVE_MID + | (uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_IIC) }, + { .pin = BSP_IO_PORT_06_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_06_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_07_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_07_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_07_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_07_PIN_03, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, }; + +const ioport_cfg_t g_bsp_pin_cfg = +{ .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], }; + +#if BSP_TZ_SECURE_BUILD + +void R_BSP_PinCfgSecurityInit(void); + +/* Initialize SAR registers for secure pins. */ +void R_BSP_PinCfgSecurityInit(void) { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + uint32_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #else + uint16_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #endif + memset(pmsar, 0xFF, BSP_FEATURE_BSP_NUM_PMSAR * sizeof(R_PMISC->PMSAR[0])); + + + for (uint32_t i = 0; i < g_bsp_pin_cfg.number_of_pins; i++) + { + uint32_t port_pin = g_bsp_pin_cfg.p_pin_cfg_data[i].pin; + uint32_t port = port_pin >> 8U; + uint32_t pin = port_pin & 0xFFU; + pmsar[port] &= (uint16_t) ~(1U << pin); + } + + for (uint32_t i = 0; i < BSP_FEATURE_BSP_NUM_PMSAR; i++) + { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + R_PMISC->PMSAR[i].PMSAR = (uint16_t)pmsar[i]; + #else + R_PMISC->PMSAR[i].PMSAR = pmsar[i]; + #endif + } + +} +#endif diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.c index 35de44a48b..db8a3fd391 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.c +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.c @@ -14,40 +14,40 @@ BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BS [7] = sci_uart_eri_isr, /* SCI7 ERI (Receive error) */ [8] = sci_uart_rxi_isr, /* SCI9 RXI (Received data full) */ [9] = sci_uart_txi_isr, /* SCI9 TXI (Transmit data empty) */ - [10] = sci_uart_tei_isr, /* SCI9 TEI (Transmit end) */ - [11] = sci_uart_eri_isr, /* SCI9 ERI (Receive error) */ - [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ - [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ - [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ - [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ - [16] = r_icu_isr, /* ICU IRQ0 (External pin interrupt 0) */ - [17] = r_icu_isr, /* ICU IRQ1 (External pin interrupt 1) */ - [18] = r_icu_isr, /* ICU IRQ2 (External pin interrupt 2) */ - [19] = r_icu_isr, /* ICU IRQ3 (External pin interrupt 3) */ - [20] = r_icu_isr, /* ICU IRQ4 (External pin interrupt 4) */ - [21] = r_icu_isr, /* ICU IRQ5 (External pin interrupt 5) */ - [22] = r_icu_isr, /* ICU IRQ6 (External pin interrupt 6) */ - [23] = r_icu_isr, /* ICU IRQ7 (External pin interrupt 7) */ - [24] = r_icu_isr, /* ICU IRQ8 (External pin interrupt 8) */ - [25] = r_icu_isr, /* ICU IRQ9 (External pin interrupt 9) */ - [26] = r_icu_isr, /* ICU IRQ10 (External pin interrupt 10) */ - [27] = r_icu_isr, /* ICU IRQ11 (External pin interrupt 11) */ - [28] = r_icu_isr, /* ICU IRQ12 (External pin interrupt 12) */ - [29] = r_icu_isr, /* ICU IRQ13 (External pin interrupt 13) */ - [30] = r_icu_isr, /* ICU IRQ14 (External pin interrupt 14) */ - [31] = r_icu_isr, /* ICU IRQ15 (External pin interrupt 15) */ - [32] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ - [33] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ - [34] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ - [35] = spi_eri_isr, /* SPI0 ERI (Error) */ - [36] = spi_rxi_isr, /* SPI1 RXI (Receive buffer full) */ - [37] = spi_txi_isr, /* SPI1 TXI (Transmit buffer empty) */ - [38] = spi_tei_isr, /* SPI1 TEI (Transmission complete event) */ - [39] = spi_eri_isr, /* SPI1 ERI (Error) */ - [40] = iic_master_rxi_isr, /* IIC2 RXI (Receive data full) */ - [41] = iic_master_txi_isr, /* IIC2 TXI (Transmit data empty) */ - [42] = iic_master_tei_isr, /* IIC2 TEI (Transmit end) */ - [43] = iic_master_eri_isr, /* IIC2 ERI (Transfer error) */ + [10] = sci_uart_tei_isr, /* SCI9 TEI (Transmit end) */ + [11] = sci_uart_eri_isr, /* SCI9 ERI (Receive error) */ + [12] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ + [13] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ + [14] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ + [15] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ + [16] = r_icu_isr, /* ICU IRQ0 (External pin interrupt 0) */ + [17] = r_icu_isr, /* ICU IRQ1 (External pin interrupt 1) */ + [18] = r_icu_isr, /* ICU IRQ2 (External pin interrupt 2) */ + [19] = r_icu_isr, /* ICU IRQ3 (External pin interrupt 3) */ + [20] = r_icu_isr, /* ICU IRQ4 (External pin interrupt 4) */ + [21] = r_icu_isr, /* ICU IRQ5 (External pin interrupt 5) */ + [22] = r_icu_isr, /* ICU IRQ6 (External pin interrupt 6) */ + [23] = r_icu_isr, /* ICU IRQ7 (External pin interrupt 7) */ + [24] = r_icu_isr, /* ICU IRQ8 (External pin interrupt 8) */ + [25] = r_icu_isr, /* ICU IRQ9 (External pin interrupt 9) */ + [26] = r_icu_isr, /* ICU IRQ10 (External pin interrupt 10) */ + [27] = r_icu_isr, /* ICU IRQ11 (External pin interrupt 11) */ + [28] = r_icu_isr, /* ICU IRQ12 (External pin interrupt 12) */ + [29] = r_icu_isr, /* ICU IRQ13 (External pin interrupt 13) */ + [30] = r_icu_isr, /* ICU IRQ14 (External pin interrupt 14) */ + [31] = r_icu_isr, /* ICU IRQ15 (External pin interrupt 15) */ + [32] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ + [33] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ + [34] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ + [35] = spi_eri_isr, /* SPI0 ERI (Error) */ + [36] = spi_rxi_isr, /* SPI1 RXI (Receive buffer full) */ + [37] = spi_txi_isr, /* SPI1 TXI (Transmit buffer empty) */ + [38] = spi_tei_isr, /* SPI1 TEI (Transmission complete event) */ + [39] = spi_eri_isr, /* SPI1 ERI (Error) */ + [40] = iic_master_rxi_isr, /* IIC2 RXI (Receive data full) */ + [41] = iic_master_txi_isr, /* IIC2 TXI (Transmit data empty) */ + [42] = iic_master_tei_isr, /* IIC2 TEI (Transmit end) */ + [43] = iic_master_eri_isr, /* IIC2 ERI (Transfer error) */ }; const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = { @@ -61,39 +61,39 @@ const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENT [7] = BSP_PRV_IELS_ENUM(EVENT_SCI7_ERI), /* SCI7 ERI (Receive error) */ [8] = BSP_PRV_IELS_ENUM(EVENT_SCI9_RXI), /* SCI9 RXI (Received data full) */ [9] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TXI), /* SCI9 TXI (Transmit data empty) */ - [10] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TEI), /* SCI9 TEI (Transmit end) */ - [11] = BSP_PRV_IELS_ENUM(EVENT_SCI9_ERI), /* SCI9 ERI (Receive error) */ - [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ - [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ - [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ - [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ - [16] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ0), /* ICU IRQ0 (External pin interrupt 0) */ - [17] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ1), /* ICU IRQ1 (External pin interrupt 1) */ - [18] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ2), /* ICU IRQ2 (External pin interrupt 2) */ - [19] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ3), /* ICU IRQ3 (External pin interrupt 3) */ - [20] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ4), /* ICU IRQ4 (External pin interrupt 4) */ - [21] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ5), /* ICU IRQ5 (External pin interrupt 5) */ - [22] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ6), /* ICU IRQ6 (External pin interrupt 6) */ - [23] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ7), /* ICU IRQ7 (External pin interrupt 7) */ - [24] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ8), /* ICU IRQ8 (External pin interrupt 8) */ - [25] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ9), /* ICU IRQ9 (External pin interrupt 9) */ - [26] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ10), /* ICU IRQ10 (External pin interrupt 10) */ - [27] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ11), /* ICU IRQ11 (External pin interrupt 11) */ - [28] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ12), /* ICU IRQ12 (External pin interrupt 12) */ - [29] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ13), /* ICU IRQ13 (External pin interrupt 13) */ - [30] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ14), /* ICU IRQ14 (External pin interrupt 14) */ - [31] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ15), /* ICU IRQ15 (External pin interrupt 15) */ - [32] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ - [33] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ - [34] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ - [35] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ - [36] = BSP_PRV_IELS_ENUM(EVENT_SPI1_RXI), /* SPI1 RXI (Receive buffer full) */ - [37] = BSP_PRV_IELS_ENUM(EVENT_SPI1_TXI), /* SPI1 TXI (Transmit buffer empty) */ - [38] = BSP_PRV_IELS_ENUM(EVENT_SPI1_TEI), /* SPI1 TEI (Transmission complete event) */ - [39] = BSP_PRV_IELS_ENUM(EVENT_SPI1_ERI), /* SPI1 ERI (Error) */ - [40] = BSP_PRV_IELS_ENUM(EVENT_IIC2_RXI), /* IIC2 RXI (Receive data full) */ - [41] = BSP_PRV_IELS_ENUM(EVENT_IIC2_TXI), /* IIC2 TXI (Transmit data empty) */ - [42] = BSP_PRV_IELS_ENUM(EVENT_IIC2_TEI), /* IIC2 TEI (Transmit end) */ - [43] = BSP_PRV_IELS_ENUM(EVENT_IIC2_ERI), /* IIC2 ERI (Transfer error) */ + [10] = BSP_PRV_IELS_ENUM(EVENT_SCI9_TEI), /* SCI9 TEI (Transmit end) */ + [11] = BSP_PRV_IELS_ENUM(EVENT_SCI9_ERI), /* SCI9 ERI (Receive error) */ + [12] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ + [13] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ + [14] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ + [15] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ + [16] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ0), /* ICU IRQ0 (External pin interrupt 0) */ + [17] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ1), /* ICU IRQ1 (External pin interrupt 1) */ + [18] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ2), /* ICU IRQ2 (External pin interrupt 2) */ + [19] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ3), /* ICU IRQ3 (External pin interrupt 3) */ + [20] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ4), /* ICU IRQ4 (External pin interrupt 4) */ + [21] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ5), /* ICU IRQ5 (External pin interrupt 5) */ + [22] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ6), /* ICU IRQ6 (External pin interrupt 6) */ + [23] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ7), /* ICU IRQ7 (External pin interrupt 7) */ + [24] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ8), /* ICU IRQ8 (External pin interrupt 8) */ + [25] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ9), /* ICU IRQ9 (External pin interrupt 9) */ + [26] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ10), /* ICU IRQ10 (External pin interrupt 10) */ + [27] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ11), /* ICU IRQ11 (External pin interrupt 11) */ + [28] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ12), /* ICU IRQ12 (External pin interrupt 12) */ + [29] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ13), /* ICU IRQ13 (External pin interrupt 13) */ + [30] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ14), /* ICU IRQ14 (External pin interrupt 14) */ + [31] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ15), /* ICU IRQ15 (External pin interrupt 15) */ + [32] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ + [33] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ + [34] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ + [35] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ + [36] = BSP_PRV_IELS_ENUM(EVENT_SPI1_RXI), /* SPI1 RXI (Receive buffer full) */ + [37] = BSP_PRV_IELS_ENUM(EVENT_SPI1_TXI), /* SPI1 TXI (Transmit buffer empty) */ + [38] = BSP_PRV_IELS_ENUM(EVENT_SPI1_TEI), /* SPI1 TEI (Transmission complete event) */ + [39] = BSP_PRV_IELS_ENUM(EVENT_SPI1_ERI), /* SPI1 ERI (Error) */ + [40] = BSP_PRV_IELS_ENUM(EVENT_IIC2_RXI), /* IIC2 RXI (Receive data full) */ + [41] = BSP_PRV_IELS_ENUM(EVENT_IIC2_TXI), /* IIC2 TXI (Transmit data empty) */ + [42] = BSP_PRV_IELS_ENUM(EVENT_IIC2_TEI), /* IIC2 TEI (Transmit end) */ + [43] = BSP_PRV_IELS_ENUM(EVENT_IIC2_ERI), /* IIC2 ERI (Transfer error) */ }; #endif diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.h index 6629824be8..955834de59 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/vector_data.h @@ -1,6 +1,9 @@ /* generated vector header file - do not edit */ #ifndef VECTOR_DATA_H #define VECTOR_DATA_H +#ifdef __cplusplus +extern "C" { +#endif /* Number of interrupts allocated */ #ifndef VECTOR_DATA_IRQ_COUNT #define VECTOR_DATA_IRQ_COUNT (44) @@ -25,105 +28,94 @@ void iic_master_eri_isr(void); /* Vector table allocations */ #define VECTOR_NUMBER_SCI0_RXI ((IRQn_Type)0) /* SCI0 RXI (Receive data full) */ +#define SCI0_RXI_IRQn ((IRQn_Type)0) /* SCI0 RXI (Receive data full) */ #define VECTOR_NUMBER_SCI0_TXI ((IRQn_Type)1) /* SCI0 TXI (Transmit data empty) */ +#define SCI0_TXI_IRQn ((IRQn_Type)1) /* SCI0 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI0_TEI ((IRQn_Type)2) /* SCI0 TEI (Transmit end) */ +#define SCI0_TEI_IRQn ((IRQn_Type)2) /* SCI0 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI0_ERI ((IRQn_Type)3) /* SCI0 ERI (Receive error) */ +#define SCI0_ERI_IRQn ((IRQn_Type)3) /* SCI0 ERI (Receive error) */ #define VECTOR_NUMBER_SCI7_RXI ((IRQn_Type)4) /* SCI7 RXI (Received data full) */ +#define SCI7_RXI_IRQn ((IRQn_Type)4) /* SCI7 RXI (Received data full) */ #define VECTOR_NUMBER_SCI7_TXI ((IRQn_Type)5) /* SCI7 TXI (Transmit data empty) */ +#define SCI7_TXI_IRQn ((IRQn_Type)5) /* SCI7 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI7_TEI ((IRQn_Type)6) /* SCI7 TEI (Transmit end) */ +#define SCI7_TEI_IRQn ((IRQn_Type)6) /* SCI7 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI7_ERI ((IRQn_Type)7) /* SCI7 ERI (Receive error) */ +#define SCI7_ERI_IRQn ((IRQn_Type)7) /* SCI7 ERI (Receive error) */ #define VECTOR_NUMBER_SCI9_RXI ((IRQn_Type)8) /* SCI9 RXI (Received data full) */ +#define SCI9_RXI_IRQn ((IRQn_Type)8) /* SCI9 RXI (Received data full) */ #define VECTOR_NUMBER_SCI9_TXI ((IRQn_Type)9) /* SCI9 TXI (Transmit data empty) */ +#define SCI9_TXI_IRQn ((IRQn_Type)9) /* SCI9 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI9_TEI ((IRQn_Type)10) /* SCI9 TEI (Transmit end) */ +#define SCI9_TEI_IRQn ((IRQn_Type)10) /* SCI9 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI9_ERI ((IRQn_Type)11) /* SCI9 ERI (Receive error) */ +#define SCI9_ERI_IRQn ((IRQn_Type)11) /* SCI9 ERI (Receive error) */ #define VECTOR_NUMBER_RTC_ALARM ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ +#define RTC_ALARM_IRQn ((IRQn_Type)12) /* RTC ALARM (Alarm interrupt) */ #define VECTOR_NUMBER_RTC_PERIOD ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ +#define RTC_PERIOD_IRQn ((IRQn_Type)13) /* RTC PERIOD (Periodic interrupt) */ #define VECTOR_NUMBER_RTC_CARRY ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ +#define RTC_CARRY_IRQn ((IRQn_Type)14) /* RTC CARRY (Carry interrupt) */ #define VECTOR_NUMBER_AGT0_INT ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ +#define AGT0_INT_IRQn ((IRQn_Type)15) /* AGT0 INT (AGT interrupt) */ #define VECTOR_NUMBER_ICU_IRQ0 ((IRQn_Type)16) /* ICU IRQ0 (External pin interrupt 0) */ +#define ICU_IRQ0_IRQn ((IRQn_Type)16) /* ICU IRQ0 (External pin interrupt 0) */ #define VECTOR_NUMBER_ICU_IRQ1 ((IRQn_Type)17) /* ICU IRQ1 (External pin interrupt 1) */ +#define ICU_IRQ1_IRQn ((IRQn_Type)17) /* ICU IRQ1 (External pin interrupt 1) */ #define VECTOR_NUMBER_ICU_IRQ2 ((IRQn_Type)18) /* ICU IRQ2 (External pin interrupt 2) */ +#define ICU_IRQ2_IRQn ((IRQn_Type)18) /* ICU IRQ2 (External pin interrupt 2) */ #define VECTOR_NUMBER_ICU_IRQ3 ((IRQn_Type)19) /* ICU IRQ3 (External pin interrupt 3) */ +#define ICU_IRQ3_IRQn ((IRQn_Type)19) /* ICU IRQ3 (External pin interrupt 3) */ #define VECTOR_NUMBER_ICU_IRQ4 ((IRQn_Type)20) /* ICU IRQ4 (External pin interrupt 4) */ +#define ICU_IRQ4_IRQn ((IRQn_Type)20) /* ICU IRQ4 (External pin interrupt 4) */ #define VECTOR_NUMBER_ICU_IRQ5 ((IRQn_Type)21) /* ICU IRQ5 (External pin interrupt 5) */ +#define ICU_IRQ5_IRQn ((IRQn_Type)21) /* ICU IRQ5 (External pin interrupt 5) */ #define VECTOR_NUMBER_ICU_IRQ6 ((IRQn_Type)22) /* ICU IRQ6 (External pin interrupt 6) */ +#define ICU_IRQ6_IRQn ((IRQn_Type)22) /* ICU IRQ6 (External pin interrupt 6) */ #define VECTOR_NUMBER_ICU_IRQ7 ((IRQn_Type)23) /* ICU IRQ7 (External pin interrupt 7) */ +#define ICU_IRQ7_IRQn ((IRQn_Type)23) /* ICU IRQ7 (External pin interrupt 7) */ #define VECTOR_NUMBER_ICU_IRQ8 ((IRQn_Type)24) /* ICU IRQ8 (External pin interrupt 8) */ +#define ICU_IRQ8_IRQn ((IRQn_Type)24) /* ICU IRQ8 (External pin interrupt 8) */ #define VECTOR_NUMBER_ICU_IRQ9 ((IRQn_Type)25) /* ICU IRQ9 (External pin interrupt 9) */ +#define ICU_IRQ9_IRQn ((IRQn_Type)25) /* ICU IRQ9 (External pin interrupt 9) */ #define VECTOR_NUMBER_ICU_IRQ10 ((IRQn_Type)26) /* ICU IRQ10 (External pin interrupt 10) */ +#define ICU_IRQ10_IRQn ((IRQn_Type)26) /* ICU IRQ10 (External pin interrupt 10) */ #define VECTOR_NUMBER_ICU_IRQ11 ((IRQn_Type)27) /* ICU IRQ11 (External pin interrupt 11) */ +#define ICU_IRQ11_IRQn ((IRQn_Type)27) /* ICU IRQ11 (External pin interrupt 11) */ #define VECTOR_NUMBER_ICU_IRQ12 ((IRQn_Type)28) /* ICU IRQ12 (External pin interrupt 12) */ +#define ICU_IRQ12_IRQn ((IRQn_Type)28) /* ICU IRQ12 (External pin interrupt 12) */ #define VECTOR_NUMBER_ICU_IRQ13 ((IRQn_Type)29) /* ICU IRQ13 (External pin interrupt 13) */ +#define ICU_IRQ13_IRQn ((IRQn_Type)29) /* ICU IRQ13 (External pin interrupt 13) */ #define VECTOR_NUMBER_ICU_IRQ14 ((IRQn_Type)30) /* ICU IRQ14 (External pin interrupt 14) */ +#define ICU_IRQ14_IRQn ((IRQn_Type)30) /* ICU IRQ14 (External pin interrupt 14) */ #define VECTOR_NUMBER_ICU_IRQ15 ((IRQn_Type)31) /* ICU IRQ15 (External pin interrupt 15) */ +#define ICU_IRQ15_IRQn ((IRQn_Type)31) /* ICU IRQ15 (External pin interrupt 15) */ #define VECTOR_NUMBER_SPI0_RXI ((IRQn_Type)32) /* SPI0 RXI (Receive buffer full) */ +#define SPI0_RXI_IRQn ((IRQn_Type)32) /* SPI0 RXI (Receive buffer full) */ #define VECTOR_NUMBER_SPI0_TXI ((IRQn_Type)33) /* SPI0 TXI (Transmit buffer empty) */ +#define SPI0_TXI_IRQn ((IRQn_Type)33) /* SPI0 TXI (Transmit buffer empty) */ #define VECTOR_NUMBER_SPI0_TEI ((IRQn_Type)34) /* SPI0 TEI (Transmission complete event) */ +#define SPI0_TEI_IRQn ((IRQn_Type)34) /* SPI0 TEI (Transmission complete event) */ #define VECTOR_NUMBER_SPI0_ERI ((IRQn_Type)35) /* SPI0 ERI (Error) */ +#define SPI0_ERI_IRQn ((IRQn_Type)35) /* SPI0 ERI (Error) */ #define VECTOR_NUMBER_SPI1_RXI ((IRQn_Type)36) /* SPI1 RXI (Receive buffer full) */ +#define SPI1_RXI_IRQn ((IRQn_Type)36) /* SPI1 RXI (Receive buffer full) */ #define VECTOR_NUMBER_SPI1_TXI ((IRQn_Type)37) /* SPI1 TXI (Transmit buffer empty) */ +#define SPI1_TXI_IRQn ((IRQn_Type)37) /* SPI1 TXI (Transmit buffer empty) */ #define VECTOR_NUMBER_SPI1_TEI ((IRQn_Type)38) /* SPI1 TEI (Transmission complete event) */ +#define SPI1_TEI_IRQn ((IRQn_Type)38) /* SPI1 TEI (Transmission complete event) */ #define VECTOR_NUMBER_SPI1_ERI ((IRQn_Type)39) /* SPI1 ERI (Error) */ +#define SPI1_ERI_IRQn ((IRQn_Type)39) /* SPI1 ERI (Error) */ #define VECTOR_NUMBER_IIC2_RXI ((IRQn_Type)40) /* IIC2 RXI (Receive data full) */ +#define IIC2_RXI_IRQn ((IRQn_Type)40) /* IIC2 RXI (Receive data full) */ #define VECTOR_NUMBER_IIC2_TXI ((IRQn_Type)41) /* IIC2 TXI (Transmit data empty) */ +#define IIC2_TXI_IRQn ((IRQn_Type)41) /* IIC2 TXI (Transmit data empty) */ #define VECTOR_NUMBER_IIC2_TEI ((IRQn_Type)42) /* IIC2 TEI (Transmit end) */ +#define IIC2_TEI_IRQn ((IRQn_Type)42) /* IIC2 TEI (Transmit end) */ #define VECTOR_NUMBER_IIC2_ERI ((IRQn_Type)43) /* IIC2 ERI (Transfer error) */ -typedef enum IRQn -{ - Reset_IRQn = -15, - NonMaskableInt_IRQn = -14, - HardFault_IRQn = -13, - MemoryManagement_IRQn = -12, - BusFault_IRQn = -11, - UsageFault_IRQn = -10, - SecureFault_IRQn = -9, - SVCall_IRQn = -5, - DebugMonitor_IRQn = -4, - PendSV_IRQn = -2, - SysTick_IRQn = -1, - SCI0_RXI_IRQn = 0, /* SCI0 RXI (Receive data full) */ - SCI0_TXI_IRQn = 1, /* SCI0 TXI (Transmit data empty) */ - SCI0_TEI_IRQn = 2, /* SCI0 TEI (Transmit end) */ - SCI0_ERI_IRQn = 3, /* SCI0 ERI (Receive error) */ - SCI7_RXI_IRQn = 4, /* SCI7 RXI (Received data full) */ - SCI7_TXI_IRQn = 5, /* SCI7 TXI (Transmit data empty) */ - SCI7_TEI_IRQn = 6, /* SCI7 TEI (Transmit end) */ - SCI7_ERI_IRQn = 7, /* SCI7 ERI (Receive error) */ - SCI9_RXI_IRQn = 8, /* SCI9 RXI (Received data full) */ - SCI9_TXI_IRQn = 9, /* SCI9 TXI (Transmit data empty) */ - SCI9_TEI_IRQn = 10, /* SCI9 TEI (Transmit end) */ - SCI9_ERI_IRQn = 11, /* SCI9 ERI (Receive error) */ - RTC_ALARM_IRQn = 12, /* RTC ALARM (Alarm interrupt) */ - RTC_PERIOD_IRQn = 13, /* RTC PERIOD (Periodic interrupt) */ - RTC_CARRY_IRQn = 14, /* RTC CARRY (Carry interrupt) */ - AGT0_INT_IRQn = 15, /* AGT0 INT (AGT interrupt) */ - ICU_IRQ0_IRQn = 16, /* ICU IRQ0 (External pin interrupt 0) */ - ICU_IRQ1_IRQn = 17, /* ICU IRQ1 (External pin interrupt 1) */ - ICU_IRQ2_IRQn = 18, /* ICU IRQ2 (External pin interrupt 2) */ - ICU_IRQ3_IRQn = 19, /* ICU IRQ3 (External pin interrupt 3) */ - ICU_IRQ4_IRQn = 20, /* ICU IRQ4 (External pin interrupt 4) */ - ICU_IRQ5_IRQn = 21, /* ICU IRQ5 (External pin interrupt 5) */ - ICU_IRQ6_IRQn = 22, /* ICU IRQ6 (External pin interrupt 6) */ - ICU_IRQ7_IRQn = 23, /* ICU IRQ7 (External pin interrupt 7) */ - ICU_IRQ8_IRQn = 24, /* ICU IRQ8 (External pin interrupt 8) */ - ICU_IRQ9_IRQn = 25, /* ICU IRQ9 (External pin interrupt 9) */ - ICU_IRQ10_IRQn = 26, /* ICU IRQ10 (External pin interrupt 10) */ - ICU_IRQ11_IRQn = 27, /* ICU IRQ11 (External pin interrupt 11) */ - ICU_IRQ12_IRQn = 28, /* ICU IRQ12 (External pin interrupt 12) */ - ICU_IRQ13_IRQn = 29, /* ICU IRQ13 (External pin interrupt 13) */ - ICU_IRQ14_IRQn = 30, /* ICU IRQ14 (External pin interrupt 14) */ - ICU_IRQ15_IRQn = 31, /* ICU IRQ15 (External pin interrupt 15) */ - SPI0_RXI_IRQn = 32, /* SPI0 RXI (Receive buffer full) */ - SPI0_TXI_IRQn = 33, /* SPI0 TXI (Transmit buffer empty) */ - SPI0_TEI_IRQn = 34, /* SPI0 TEI (Transmission complete event) */ - SPI0_ERI_IRQn = 35, /* SPI0 ERI (Error) */ - SPI1_RXI_IRQn = 36, /* SPI1 RXI (Receive buffer full) */ - SPI1_TXI_IRQn = 37, /* SPI1 TXI (Transmit buffer empty) */ - SPI1_TEI_IRQn = 38, /* SPI1 TEI (Transmission complete event) */ - SPI1_ERI_IRQn = 39, /* SPI1 ERI (Error) */ - IIC2_RXI_IRQn = 40, /* IIC2 RXI (Receive data full) */ - IIC2_TXI_IRQn = 41, /* IIC2 TXI (Transmit data empty) */ - IIC2_TEI_IRQn = 42, /* IIC2 TEI (Transmit end) */ - IIC2_ERI_IRQn = 43, /* IIC2 ERI (Transfer error) */ -} IRQn_Type; +#define IIC2_ERI_IRQn ((IRQn_Type)43) /* IIC2 ERI (Transfer error) */ +#ifdef __cplusplus +} +#endif #endif /* VECTOR_DATA_H */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/board_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/board_cfg.h index 87cb51e00b..a57cf3249e 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/board_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/board_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef BOARD_CFG_H_ #define BOARD_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + void bsp_init(void *p_args); + +#ifdef __cplusplus +} +#endif #endif /* BOARD_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_cfg.h index 9940d7ed3b..e341e99942 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_CFG_H_ #define BSP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_clock_cfg.h" #include "bsp_mcu_family_cfg.h" #include "board_cfg.h" @@ -14,7 +18,13 @@ #define BSP_CFG_RTOS (0) #endif #endif +#ifndef BSP_CFG_RTC_USED +#define BSP_CFG_RTC_USED (1) +#endif #undef RA_NOT_DEFINED +#if defined(_RA_BOOT_IMAGE) +#define BSP_CFG_BOOT_IMAGE (1) +#endif #define BSP_CFG_MCU_VCC_MV (3300) #define BSP_CFG_STACK_MAIN_BYTES (0x1000) #define BSP_CFG_HEAP_BYTES (0x4980) @@ -25,15 +35,14 @@ #define BSP_CFG_PFS_PROTECT ((1)) #define BSP_CFG_C_RUNTIME_INIT ((1)) +#define BSP_CFG_EARLY_INIT ((0)) -#define BSP_CFG_SOFT_RESET_SUPPORTED ((0)) +#define BSP_CFG_STARTUP_CLOCK_REG_NOT_RESET ((0)) #ifndef BSP_CLOCK_CFG_MAIN_OSC_POPULATED #define BSP_CLOCK_CFG_MAIN_OSC_POPULATED (1) #endif -#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT -#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) -#endif + #ifndef BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE #define BSP_CLOCK_CFG_MAIN_OSC_CLOCK_SOURCE (0) #endif @@ -46,4 +55,8 @@ #ifndef BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS #define BSP_CLOCK_CFG_SUBCLOCK_STABILIZATION_MS 1000 #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h index 713af295bc..d840f24958 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_mcu_device_pn_cfg.h @@ -2,6 +2,7 @@ #ifndef BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_DEVICE_PN_CFG_H_ #define BSP_MCU_R7FA4M1AB3CFM +#define BSP_MCU_FEATURE_SET ('A') #define BSP_ROM_SIZE_BYTES (262144) #define BSP_RAM_SIZE_BYTES (32768) #define BSP_DATA_FLASH_SIZE_BYTES (8192) diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h index 4766823b35..a9b4de20c0 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h @@ -1,6 +1,10 @@ /* generated configuration header file - do not edit */ #ifndef BSP_MCU_FAMILY_CFG_H_ #define BSP_MCU_FAMILY_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "bsp_mcu_device_pn_cfg.h" #include "bsp_mcu_device_cfg.h" #include "../../../ra/fsp/src/bsp/mcu/ra4m1/bsp_mcu_info.h" @@ -22,7 +26,6 @@ #endif #define BSP_CORTEX_VECTOR_TABLE_ENTRIES (16U) #define BSP_VECTOR_TABLE_MAX_ENTRIES (48U) -#define BSP_MCU_VBATT_SUPPORT (1) #define OFS_SEQ1 0xA001A001 | (1 << 1) | (3 << 2) #define OFS_SEQ2 (15 << 4) | (3 << 8) | (3 << 10) @@ -50,7 +53,9 @@ #define BSP_CFG_ROM_REG_MPU_REGION3_ENABLE (1) #define BSP_CFG_ROM_REG_MPU_REGION3_START (0x400DFFFC) #define BSP_CFG_ROM_REG_MPU_REGION3_END (0x400DFFFF) - +#ifndef BSP_CLOCK_CFG_MAIN_OSC_WAIT +#define BSP_CLOCK_CFG_MAIN_OSC_WAIT (9) +#endif /* Used to create IELS values for the interrupt initialization table g_interrupt_event_link_select. */ #define BSP_PRV_IELS_ENUM(vector) (ELC_##vector) @@ -71,4 +76,8 @@ #define BSP_CFG_ID_CODE_LONG_3 (0xFFFFFFFF) #define BSP_CFG_ID_CODE_LONG_4 (0xffFFFFFF) #endif + +#ifdef __cplusplus +} +#endif #endif /* BSP_MCU_FAMILY_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_adc_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_adc_cfg.h index 9c59889ca8..be8a427206 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_adc_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_adc_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_ADC_CFG_H_ #define R_ADC_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define ADC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_ADC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_agt_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_agt_cfg.h deleted file mode 100644 index d3ab559238..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_agt_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_AGT_CFG_H_ -#define R_AGT_CFG_H_ -#define AGT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define AGT_CFG_OUTPUT_SUPPORT_ENABLE (0) -#define AGT_CFG_INPUT_SUPPORT_ENABLE (0) -#endif /* R_AGT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_dtc_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_dtc_cfg.h deleted file mode 100644 index 21405f9674..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_dtc_cfg.h +++ /dev/null @@ -1,6 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_DTC_CFG_H_ -#define R_DTC_CFG_H_ -#define DTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define DTC_CFG_VECTOR_TABLE_SECTION_NAME ".fsp_dtc_vector_table" -#endif /* R_DTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_flash_lp_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_flash_lp_cfg.h index 26879f9f4e..7f285caced 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_flash_lp_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_flash_lp_cfg.h @@ -1,7 +1,15 @@ /* generated configuration header file - do not edit */ #ifndef R_FLASH_LP_CFG_H_ #define R_FLASH_LP_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define FLASH_LP_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) #define FLASH_LP_CFG_CODE_FLASH_PROGRAMMING_ENABLE (1) #define FLASH_LP_CFG_DATA_FLASH_PROGRAMMING_ENABLE (0) + +#ifdef __cplusplus +} +#endif #endif /* R_FLASH_LP_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_icu_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_icu_cfg.h deleted file mode 100644 index 5e77b6980f..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_icu_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_ICU_CFG_H_ -#define R_ICU_CFG_H_ -#define ICU_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_ICU_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_iic_master_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_iic_master_cfg.h deleted file mode 100644 index 595ea938d1..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_iic_master_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_IIC_MASTER_CFG_H_ -#define R_IIC_MASTER_CFG_H_ -#define IIC_MASTER_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define IIC_MASTER_CFG_DTC_ENABLE (0) -#define IIC_MASTER_CFG_ADDR_MODE_10_BIT_ENABLE (0) -#endif /* R_IIC_MASTER_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_ioport_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_ioport_cfg.h index 6b4353d238..d2688bf5ba 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_ioport_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_ioport_cfg.h @@ -1,5 +1,13 @@ /* generated configuration header file - do not edit */ #ifndef R_IOPORT_CFG_H_ #define R_IOPORT_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define IOPORT_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) + +#ifdef __cplusplus +} +#endif #endif /* R_IOPORT_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_lpm_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_lpm_cfg.h index 5f4d5c4a73..6712eee6a1 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_lpm_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_lpm_cfg.h @@ -1,5 +1,14 @@ /* generated configuration header file - do not edit */ #ifndef R_LPM_CFG_H_ #define R_LPM_CFG_H_ +#ifdef __cplusplus +extern "C" { +#endif + #define LPM_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) +#define LPM_CFG_STANDBY_LIMIT (0) + +#ifdef __cplusplus +} +#endif #endif /* R_LPM_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_rtc_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_rtc_cfg.h deleted file mode 100644 index 484b7ed044..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_rtc_cfg.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_RTC_CFG_H_ -#define R_RTC_CFG_H_ -#define RTC_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#endif /* R_RTC_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_sci_uart_cfg.h deleted file mode 100644 index c70c0be344..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_sci_uart_cfg.h +++ /dev/null @@ -1,8 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SCI_UART_CFG_H_ -#define R_SCI_UART_CFG_H_ -#define SCI_UART_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SCI_UART_CFG_FIFO_SUPPORT (0) -#define SCI_UART_CFG_DTC_SUPPORTED (0) -#define SCI_UART_CFG_FLOW_CONTROL_SUPPORT (0) -#endif /* R_SCI_UART_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_spi_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_spi_cfg.h deleted file mode 100644 index 861fe12194..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_cfg/fsp_cfg/r_spi_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -/* generated configuration header file - do not edit */ -#ifndef R_SPI_CFG_H_ -#define R_SPI_CFG_H_ -#define SPI_CFG_PARAM_CHECKING_ENABLE (BSP_CFG_PARAM_CHECKING_ENABLE) -#define SPI_DTC_SUPPORT_ENABLE (1) -#define SPI_TRANSMIT_FROM_RXI_ISR (0) -#endif /* R_SPI_CFG_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/bsp_clock_cfg.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/bsp_clock_cfg.h index cf28c33d7a..5f407b90f4 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/bsp_clock_cfg.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/bsp_clock_cfg.h @@ -7,7 +7,7 @@ #define BSP_CFG_PLL_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_MAIN_OSC) /* PLL Src: XTAL */ #define BSP_CFG_HOCO_FREQUENCY (0) /* HOCO 24MHz */ #define BSP_CFG_PLL_DIV (BSP_CLOCKS_PLL_DIV_2) /* PLL Div /2 */ -#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL_8_0 /* PLL Mul x8 */ +#define BSP_CFG_PLL_MUL BSP_CLOCKS_PLL_MUL(8U, 0U) /* PLL Mul x8 */ #define BSP_CFG_CLOCK_SOURCE (BSP_CLOCKS_SOURCE_CLOCK_PLL) /* Clock Src: PLL */ #define BSP_CFG_ICLK_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* ICLK Div /1 */ #define BSP_CFG_PCLKA_DIV (BSP_CLOCKS_SYS_CLOCK_DIV_1) /* PCLKA Div /1 */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/common_data.c b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/common_data.c index 34aad762ff..48640e8b7a 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/common_data.c +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/common_data.c @@ -1,4 +1,3 @@ -/* generated common source file - do not edit */ #include "common_data.h" ioport_instance_ctrl_t g_ioport_ctrl; const ioport_instance_t g_ioport = diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/common_data.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/common_data.h index e2eb70836b..a81384f8f7 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/common_data.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/common_data.h @@ -3,6 +3,8 @@ #define COMMON_DATA_H_ #include #include "bsp_api.h" +#include "r_icu.h" +#include "r_external_irq_api.h" #include "r_ioport.h" #include "bsp_pin_cfg.h" FSP_HEADER @@ -11,6 +13,5 @@ extern const ioport_instance_t g_ioport; /* IOPORT control structure. */ extern ioport_instance_ctrl_t g_ioport_ctrl; -void g_common_init(void); FSP_FOOTER #endif /* COMMON_DATA_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.c b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.c index ebef37a7df..64c728b999 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.c +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.c @@ -1,136 +1,17 @@ /* generated HAL source file - do not edit */ #include "hal_data.h" -/* Macros to tie dynamic ELC links to ADC_TRIGGER_SYNC_ELC option in adc_trigger_t. */ -#define ADC_TRIGGER_ADC0 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC0_B ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1 ADC_TRIGGER_SYNC_ELC -#define ADC_TRIGGER_ADC1_B ADC_TRIGGER_SYNC_ELC -icu_instance_ctrl_t g_external_irq9_ctrl; -const external_irq_cfg_t g_external_irq9_cfg = -{ .channel = 9, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ9) - .irq = VECTOR_NUMBER_ICU_IRQ9, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq9 = -{ .p_ctrl = &g_external_irq9_ctrl, .p_cfg = &g_external_irq9_cfg, .p_api = &g_external_irq_on_icu }; -icu_instance_ctrl_t g_external_irq6_ctrl; -const external_irq_cfg_t g_external_irq6_cfg = -{ .channel = 6, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ6) - .irq = VECTOR_NUMBER_ICU_IRQ6, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq6 = -{ .p_ctrl = &g_external_irq6_ctrl, .p_cfg = &g_external_irq6_cfg, .p_api = &g_external_irq_on_icu }; -iic_master_instance_ctrl_t g_i2c_master1_ctrl; -const iic_master_extended_cfg_t g_i2c_master1_extend = -{ .timeout_mode = IIC_MASTER_TIMEOUT_MODE_SHORT, -/* Actual calculated bitrate: 99272. Actual calculated duty cycle: 49%. */ .clock_settings.brl_value = 27, - .clock_settings.brh_value = 26, .clock_settings.cks_value = 2, }; -const i2c_master_cfg_t g_i2c_master1_cfg = -{ .channel = 1, .rate = I2C_MASTER_RATE_STANDARD, .slave = 0x00, .addr_mode = I2C_MASTER_ADDR_MODE_7BIT, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .p_callback = callback_iic, - .p_context = NULL, - #if defined(VECTOR_NUMBER_IIC1_RXI) - .rxi_irq = VECTOR_NUMBER_IIC1_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC1_TXI) - .txi_irq = VECTOR_NUMBER_IIC1_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC1_TEI) - .tei_irq = VECTOR_NUMBER_IIC1_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_IIC1_ERI) - .eri_irq = VECTOR_NUMBER_IIC1_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - .ipl = (12), - .p_extend = &g_i2c_master1_extend, }; -/* Instance structure to use this module. */ -const i2c_master_instance_t g_i2c_master1 = -{ .p_ctrl = &g_i2c_master1_ctrl, .p_cfg = &g_i2c_master1_cfg, .p_api = &g_i2c_master_on_iic }; -adc_instance_ctrl_t g_adc0_ctrl; -const adc_extended_cfg_t g_adc0_cfg_extend = -{ .add_average_count = ADC_ADD_OFF, - .clearing = ADC_CLEAR_AFTER_READ_ON, - .trigger_group_b = ADC_TRIGGER_SYNC_ELC, - .double_trigger_mode = ADC_DOUBLE_TRIGGER_DISABLED, - .adc_vref_control = ADC_VREF_CONTROL_VREFH, }; -const adc_cfg_t g_adc0_cfg = -{ .unit = 0, .mode = ADC_MODE_SINGLE_SCAN, .resolution = ADC_RESOLUTION_14_BIT, .alignment = - (adc_alignment_t)ADC_ALIGNMENT_RIGHT, - .trigger = ADC_TRIGGER_SOFTWARE, .p_callback = NULL, .p_context = NULL, .p_extend = &g_adc0_cfg_extend, - #if defined(VECTOR_NUMBER_ADC0_SCAN_END) - .scan_end_irq = VECTOR_NUMBER_ADC0_SCAN_END, - #else - .scan_end_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_ipl = (BSP_IRQ_DISABLED), - #if defined(VECTOR_NUMBER_ADC0_SCAN_END_B) - .scan_end_b_irq = VECTOR_NUMBER_ADC0_SCAN_END_B, - #else - .scan_end_b_irq = FSP_INVALID_VECTOR, - #endif - .scan_end_b_ipl = (BSP_IRQ_DISABLED), }; -const adc_channel_cfg_t g_adc0_channel_cfg = -{ .scan_mask = 0, - .scan_mask_group_b = 0, - .priority_group_a = ADC_GROUP_A_PRIORITY_OFF, - .add_mask = 0, - .sample_hold_mask = 0, - .sample_hold_states = 24, }; -/* Instance structure to use this module. */ -const adc_instance_t g_adc0 = -{ .p_ctrl = &g_adc0_ctrl, .p_cfg = &g_adc0_cfg, .p_channel_cfg = &g_adc0_channel_cfg, .p_api = &g_adc_on_adc }; + lpm_instance_ctrl_t g_lpm0_ctrl; const lpm_cfg_t g_lpm0_cfg = -{ .low_power_mode = LPM_MODE_SLEEP, +{ .low_power_mode = LPM_MODE_SLEEP, .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM + | (lpm_standby_wake_source_t)0, + #if BSP_FEATURE_LPM_HAS_SNOOZE .snooze_cancel_sources = LPM_SNOOZE_CANCEL_SOURCE_NONE, - .standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM | (lpm_standby_wake_source_t)0, .snooze_request_source = LPM_SNOOZE_REQUEST_RXD0_FALLING, .snooze_end_sources = (lpm_snooze_end_t)0, .dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE, + #endif #if BSP_FEATURE_LPM_HAS_SBYCR_OPE .output_port_enable = 0, #endif @@ -140,171 +21,24 @@ const lpm_cfg_t g_lpm0_cfg = .deep_standby_cancel_source = (lpm_deep_standby_cancel_source_t)0, .deep_standby_cancel_edge = (lpm_deep_standby_cancel_edge_t)0, #endif + #if BSP_FEATURE_LPM_HAS_PDRAMSCR + .ram_retention_cfg.ram_retention = (uint8_t)(0), + .ram_retention_cfg.tcm_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_DPSBYCR_SRKEEP + .ram_retention_cfg.standby_ram_retention = false, + #endif + #if BSP_FEATURE_LPM_HAS_LDO_CONTROL + .ldo_standby_cfg.pll1_ldo = false, + .ldo_standby_cfg.pll2_ldo = false, + .ldo_standby_cfg.hoco_ldo = false, + #endif .p_extend = NULL, }; const lpm_instance_t g_lpm0 = { .p_api = &g_lpm_on_lpm, .p_ctrl = &g_lpm0_ctrl, .p_cfg = &g_lpm0_cfg }; -dtc_instance_ctrl_t g_transfer1_ctrl; -transfer_info_t g_transfer1_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .repeat_area = TRANSFER_REPEAT_AREA_DESTINATION, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer1_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_RXI, }; -const transfer_cfg_t g_transfer1_cfg = -{ .p_info = &g_transfer1_info, .p_extend = &g_transfer1_cfg_extend, }; -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer1 = -{ .p_ctrl = &g_transfer1_ctrl, .p_cfg = &g_transfer1_cfg, .p_api = &g_transfer_on_dtc }; -dtc_instance_ctrl_t g_transfer0_ctrl; - -transfer_info_t g_transfer0_info = -{ .dest_addr_mode = TRANSFER_ADDR_MODE_FIXED, - .repeat_area = TRANSFER_REPEAT_AREA_SOURCE, - .irq = TRANSFER_IRQ_END, - .chain_mode = TRANSFER_CHAIN_MODE_DISABLED, - .src_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED, - .size = TRANSFER_SIZE_2_BYTE, - .mode = TRANSFER_MODE_NORMAL, - .p_dest = (void *)NULL, - .p_src = (void const *)NULL, - .num_blocks = 0, - .length = 0, }; -const dtc_extended_cfg_t g_transfer0_cfg_extend = -{ .activation_source = VECTOR_NUMBER_SPI0_TXI, }; -const transfer_cfg_t g_transfer0_cfg = -{ .p_info = &g_transfer0_info, .p_extend = &g_transfer0_cfg_extend, }; - -/* Instance structure to use this module. */ -const transfer_instance_t g_transfer0 = -{ .p_ctrl = &g_transfer0_ctrl, .p_cfg = &g_transfer0_cfg, .p_api = &g_transfer_on_dtc }; -spi_instance_ctrl_t g_spi0_ctrl; - -/** SPI extended configuration for SPI HAL driver */ -const spi_extended_cfg_t g_spi0_ext_cfg = -{ .spi_clksyn = SPI_SSL_MODE_CLK_SYN, - .spi_comm = SPI_COMMUNICATION_FULL_DUPLEX, - .ssl_polarity = SPI_SSLP_LOW, - .ssl_select = SPI_SSL_SELECT_SSL0, - .mosi_idle = SPI_MOSI_IDLE_VALUE_FIXING_DISABLE, - .parity = SPI_PARITY_MODE_DISABLE, - .byte_swap = SPI_BYTE_SWAP_DISABLE, - .spck_div = - { - /* Actual calculated bitrate: 12000000. */ .spbr = 1, - .brdv = 0 - }, - .spck_delay = SPI_DELAY_COUNT_1, - .ssl_negation_delay = SPI_DELAY_COUNT_1, - .next_access_delay = SPI_DELAY_COUNT_1 }; - -/** SPI configuration for SPI HAL driver */ -const spi_cfg_t g_spi0_cfg = -{ .channel = 0, - - #if defined(VECTOR_NUMBER_SPI0_RXI) - .rxi_irq = VECTOR_NUMBER_SPI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TXI) - .txi_irq = VECTOR_NUMBER_SPI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_TEI) - .tei_irq = VECTOR_NUMBER_SPI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SPI0_ERI) - .eri_irq = VECTOR_NUMBER_SPI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif - - .rxi_ipl = (12), - .txi_ipl = (12), - .tei_ipl = (12), - .eri_ipl = (12), - - .operating_mode = SPI_MODE_MASTER, - - .clk_phase = SPI_CLK_PHASE_EDGE_ODD, - .clk_polarity = SPI_CLK_POLARITY_LOW, - - .mode_fault = SPI_MODE_FAULT_ERROR_DISABLE, - .bit_order = SPI_BIT_ORDER_MSB_FIRST, - .p_transfer_tx = g_spi0_P_TRANSFER_TX, - .p_transfer_rx = g_spi0_P_TRANSFER_RX, - .p_callback = spi_callback, - - .p_context = NULL, - .p_extend = (void *)&g_spi0_ext_cfg, }; - -/* Instance structure to use this module. */ -const spi_instance_t g_spi0 = -{ .p_ctrl = &g_spi0_ctrl, .p_cfg = &g_spi0_cfg, .p_api = &g_spi_on_spi }; -icu_instance_ctrl_t g_external_irq5_ctrl; -const external_irq_cfg_t g_external_irq5_cfg = -{ .channel = 5, - .trigger = EXTERNAL_IRQ_TRIG_RISING, - .filter_enable = false, - .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, - .p_callback = callback_icu, - .p_context = NULL, - .p_extend = NULL, - .ipl = (12), - #if defined(VECTOR_NUMBER_ICU_IRQ5) - .irq = VECTOR_NUMBER_ICU_IRQ5, - #else - .irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const external_irq_instance_t g_external_irq5 = -{ .p_ctrl = &g_external_irq5_ctrl, .p_cfg = &g_external_irq5_cfg, .p_api = &g_external_irq_on_icu }; -agt_instance_ctrl_t g_timer0_ctrl; -const agt_extended_cfg_t g_timer0_extend = -{ .count_source = AGT_CLOCK_PCLKB, - .agto = AGT_PIN_CFG_DISABLED, - .agtoa = AGT_PIN_CFG_DISABLED, - .agtob = AGT_PIN_CFG_DISABLED, - .measurement_mode = AGT_MEASURE_DISABLED, - .agtio_filter = AGT_AGTIO_FILTER_NONE, - .enable_pin = AGT_ENABLE_PIN_NOT_USED, - .trigger_edge = AGT_TRIGGER_EDGE_RISING, }; -const timer_cfg_t g_timer0_cfg = -{ .mode = TIMER_MODE_PERIODIC, -/* Actual period: 0.002730666666666667 seconds. Actual duty: 50%. */ .period_counts = 0x10000, - .duty_cycle_counts = 0x8000, .source_div = (timer_source_div_t)0, .channel = 0, .p_callback = callback_agt, - /** If NULL then do not add & */ - #if defined(NULL) - .p_context = NULL, - #else - .p_context = &NULL, - #endif - .p_extend = &g_timer0_extend, - .cycle_end_ipl = (5), - #if defined(VECTOR_NUMBER_AGT0_INT) - .cycle_end_irq = VECTOR_NUMBER_AGT0_INT, - #else - .cycle_end_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const timer_instance_t g_timer0 = -{ .p_ctrl = &g_timer0_ctrl, .p_cfg = &g_timer0_cfg, .p_api = &g_timer_on_agt }; flash_lp_instance_ctrl_t g_flash0_ctrl; const flash_cfg_t g_flash0_cfg = { .data_flash_bgo = false, .p_callback = NULL, .p_context = NULL, .ipl = (BSP_IRQ_DISABLED), @@ -317,171 +51,3 @@ const flash_cfg_t g_flash0_cfg = /* Instance structure to use this module. */ const flash_instance_t g_flash0 = { .p_ctrl = &g_flash0_ctrl, .p_cfg = &g_flash0_cfg, .p_api = &g_flash_on_flash_lp }; -rtc_instance_ctrl_t g_rtc0_ctrl; -const rtc_error_adjustment_cfg_t g_rtc0_err_cfg = -{ .adjustment_mode = RTC_ERROR_ADJUSTMENT_MODE_AUTOMATIC, - .adjustment_period = RTC_ERROR_ADJUSTMENT_PERIOD_10_SECOND, - .adjustment_type = RTC_ERROR_ADJUSTMENT_NONE, - .adjustment_value = 0, }; -const rtc_cfg_t g_rtc0_cfg = -{ .clock_source = RTC_CLOCK_SOURCE_SUBCLK, .freq_compare_value_loco = 255, .p_err_cfg = &g_rtc0_err_cfg, .p_callback = - NULL, - .p_context = NULL, .alarm_ipl = (14), .periodic_ipl = (14), .carry_ipl = (14), - #if defined(VECTOR_NUMBER_RTC_ALARM) - .alarm_irq = VECTOR_NUMBER_RTC_ALARM, - #else - .alarm_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_PERIOD) - .periodic_irq = VECTOR_NUMBER_RTC_PERIOD, - #else - .periodic_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_RTC_CARRY) - .carry_irq = VECTOR_NUMBER_RTC_CARRY, - #else - .carry_irq = FSP_INVALID_VECTOR, - #endif -}; -/* Instance structure to use this module. */ -const rtc_instance_t g_rtc0 = -{ .p_ctrl = &g_rtc0_ctrl, .p_cfg = &g_rtc0_cfg, .p_api = &g_rtc_on_rtc }; -sci_uart_instance_ctrl_t g_uart1_ctrl; - -baud_setting_t g_uart1_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart1_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart1_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart1_cfg = -{ .channel = 1, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart1_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI1_RXI) - .rxi_irq = VECTOR_NUMBER_SCI1_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_TXI) - .txi_irq = VECTOR_NUMBER_SCI1_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_TEI) - .tei_irq = VECTOR_NUMBER_SCI1_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI1_ERI) - .eri_irq = VECTOR_NUMBER_SCI1_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart1 = -{ .p_ctrl = &g_uart1_ctrl, .p_cfg = &g_uart1_cfg, .p_api = &g_uart_on_sci }; -sci_uart_instance_ctrl_t g_uart0_ctrl; - -baud_setting_t g_uart0_baud_setting = -{ -/* Baud rate calculated with 0.160% error. */ .abcse = 0, - .abcs = 0, .bgdm = 1, .cks = 0, .brr = 25, .mddr = (uint8_t)256, .brme = false -}; - -/** UART extended configuration for UARTonSCI HAL driver */ -const sci_uart_extended_cfg_t g_uart0_cfg_extend = -{ .clock = SCI_UART_CLOCK_INT, - .rx_edge_start = SCI_UART_START_BIT_FALLING_EDGE, - .noise_cancel = SCI_UART_NOISE_CANCELLATION_DISABLE, - .rx_fifo_trigger = SCI_UART_RX_FIFO_TRIGGER_MAX, - .p_baud_setting = &g_uart0_baud_setting, - .uart_mode = UART_MODE_RS232, - .ctsrts_en = SCI_UART_CTSRTS_RTS_OUTPUT, - #if 0 - .flow_control_pin = BSP_IO_PORT_00_PIN_00, - #else - .flow_control_pin = (bsp_io_port_pin_t)(0xFFFFU), - #endif -}; - -/** UART interface configuration */ -const uart_cfg_t g_uart0_cfg = -{ .channel = 0, .data_bits = UART_DATA_BITS_8, .parity = UART_PARITY_OFF, .stop_bits = UART_STOP_BITS_1, .p_callback = - user_uart_callback, - .p_context = NULL, .p_extend = &g_uart0_cfg_extend, -#define RA_NOT_DEFINED (1) - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_tx = NULL, - #else - .p_transfer_tx = &RA_NOT_DEFINED, - #endif - #if (RA_NOT_DEFINED == RA_NOT_DEFINED) - .p_transfer_rx = NULL, - #else - .p_transfer_rx = &RA_NOT_DEFINED, - #endif -#undef RA_NOT_DEFINED - .rxi_ipl = (12), - .txi_ipl = (12), .tei_ipl = (12), .eri_ipl = (12), - #if defined(VECTOR_NUMBER_SCI0_RXI) - .rxi_irq = VECTOR_NUMBER_SCI0_RXI, - #else - .rxi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_TXI) - .txi_irq = VECTOR_NUMBER_SCI0_TXI, - #else - .txi_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_TEI) - .tei_irq = VECTOR_NUMBER_SCI0_TEI, - #else - .tei_irq = FSP_INVALID_VECTOR, - #endif - #if defined(VECTOR_NUMBER_SCI0_ERI) - .eri_irq = VECTOR_NUMBER_SCI0_ERI, - #else - .eri_irq = FSP_INVALID_VECTOR, - #endif -}; - -/* Instance structure to use this module. */ -const uart_instance_t g_uart0 = -{ .p_ctrl = &g_uart0_ctrl, .p_cfg = &g_uart0_cfg, .p_api = &g_uart_on_sci }; -void g_hal_init(void) { - g_common_init(); -} diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.h index 2c95755ee0..41019e6dd6 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.h @@ -2,131 +2,21 @@ #ifndef HAL_DATA_H_ #define HAL_DATA_H_ #include -#include "bsp_api.h" #include "common_data.h" -#include "r_icu.h" -#include "r_external_irq_api.h" -#include "r_iic_master.h" -#include "r_i2c_master_api.h" -#include "r_adc.h" -#include "r_adc_api.h" #include "r_lpm.h" #include "r_lpm_api.h" -#include "r_dtc.h" -#include "r_transfer_api.h" -#include "r_spi.h" -#include "r_agt.h" -#include "r_timer_api.h" #include "r_flash_lp.h" #include "r_flash_api.h" -#include "r_rtc.h" -#include "r_rtc_api.h" -#include "r_sci_uart.h" -#include "r_uart_api.h" FSP_HEADER -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq9; -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq9_ctrl; -extern const external_irq_cfg_t g_external_irq9_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq6; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq6_ctrl; -extern const external_irq_cfg_t g_external_irq6_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/* I2C Master on IIC Instance. */ -extern const i2c_master_instance_t g_i2c_master1; - -/** Access the I2C Master instance using these structures when calling API functions directly (::p_api is not used). */ -extern iic_master_instance_ctrl_t g_i2c_master1_ctrl; -extern const i2c_master_cfg_t g_i2c_master1_cfg; - -#ifndef callback_iic -void callback_iic(i2c_master_callback_args_t *p_args); -#endif -/** ADC on ADC Instance. */ -extern const adc_instance_t g_adc0; - -/** Access the ADC instance using these structures when calling API functions directly (::p_api is not used). */ -extern adc_instance_ctrl_t g_adc0_ctrl; -extern const adc_cfg_t g_adc0_cfg; -extern const adc_channel_cfg_t g_adc0_channel_cfg; - -#ifndef NULL -void NULL(adc_callback_args_t *p_args); -#endif /** lpm Instance */ extern const lpm_instance_t g_lpm0; /** Access the LPM instance using these structures when calling API functions directly (::p_api is not used). */ extern lpm_instance_ctrl_t g_lpm0_ctrl; extern const lpm_cfg_t g_lpm0_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer1; -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer1_ctrl; -extern const transfer_cfg_t g_transfer1_cfg; -/* Transfer on DTC Instance. */ -extern const transfer_instance_t g_transfer0; -/** Access the DTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern dtc_instance_ctrl_t g_transfer0_ctrl; -extern const transfer_cfg_t g_transfer0_cfg; -/** SPI on SPI Instance. */ -extern const spi_instance_t g_spi0; - -/** Access the SPI instance using these structures when calling API functions directly (::p_api is not used). */ -extern spi_instance_ctrl_t g_spi0_ctrl; -extern const spi_cfg_t g_spi0_cfg; - -/** Callback used by SPI Instance. */ -#ifndef spi_callback -void spi_callback(spi_callback_args_t *p_args); -#endif - -#define RA_NOT_DEFINED (1) -#if (RA_NOT_DEFINED == g_transfer0) - #define g_spi0_P_TRANSFER_TX (NULL) -#else -#define g_spi0_P_TRANSFER_TX (&g_transfer0) -#endif -#if (RA_NOT_DEFINED == g_transfer1) - #define g_spi0_P_TRANSFER_RX (NULL) -#else -#define g_spi0_P_TRANSFER_RX (&g_transfer1) -#endif -#undef RA_NOT_DEFINED -/** External IRQ on ICU Instance. */ -extern const external_irq_instance_t g_external_irq5; - -/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ -extern icu_instance_ctrl_t g_external_irq5_ctrl; -extern const external_irq_cfg_t g_external_irq5_cfg; - -#ifndef callback_icu -void callback_icu(external_irq_callback_args_t *p_args); -#endif -/** AGT Timer Instance */ -extern const timer_instance_t g_timer0; - -/** Access the AGT instance using these structures when calling API functions directly (::p_api is not used). */ -extern agt_instance_ctrl_t g_timer0_ctrl; -extern const timer_cfg_t g_timer0_cfg; - -#ifndef callback_agt -void callback_agt(timer_callback_args_t *p_args); -#endif /* Flash on Flash LP Instance. */ extern const flash_instance_t g_flash0; @@ -134,42 +24,6 @@ extern const flash_instance_t g_flash0; extern flash_lp_instance_ctrl_t g_flash0_ctrl; extern const flash_cfg_t g_flash0_cfg; -#ifndef NULL -void NULL(flash_callback_args_t *p_args); -#endif -/* RTC Instance. */ -extern const rtc_instance_t g_rtc0; - -/** Access the RTC instance using these structures when calling API functions directly (::p_api is not used). */ -extern rtc_instance_ctrl_t g_rtc0_ctrl; -extern const rtc_cfg_t g_rtc0_cfg; - -#ifndef NULL -void NULL(rtc_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart1; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart1_ctrl; -extern const uart_cfg_t g_uart1_cfg; -extern const sci_uart_extended_cfg_t g_uart1_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif -/** UART on SCI Instance. */ -extern const uart_instance_t g_uart0; - -/** Access the UART instance using these structures when calling API functions directly (::p_api is not used). */ -extern sci_uart_instance_ctrl_t g_uart0_ctrl; -extern const uart_cfg_t g_uart0_cfg; -extern const sci_uart_extended_cfg_t g_uart0_cfg_extend; - -#ifndef user_uart_callback -void user_uart_callback(uart_callback_args_t *p_args); -#endif void hal_entry(void); -void g_hal_init(void); FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/pin_data.c b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/pin_data.c index 2479b76a0c..a260afed89 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/pin_data.c +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/pin_data.c @@ -1,73 +1,76 @@ /* generated pin source file - do not edit */ #include "bsp_api.h" #include "r_ioport_api.h" -const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = { - { - .pin = BSP_IO_PORT_01_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SPI), - }, - { - .pin = BSP_IO_PORT_01_PIN_08, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_09, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_01_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_03_PIN_00, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_DEBUG), - }, - { - .pin = BSP_IO_PORT_03_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), - }, - { - .pin = BSP_IO_PORT_03_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), - }, - { - .pin = BSP_IO_PORT_03_PIN_04, - .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT), - }, - { - .pin = BSP_IO_PORT_04_PIN_01, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_04_PIN_02, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9), - }, - { - .pin = BSP_IO_PORT_04_PIN_08, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_04_PIN_09, - .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW), - }, - { - .pin = BSP_IO_PORT_04_PIN_10, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, - { - .pin = BSP_IO_PORT_04_PIN_11, - .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8), - }, -}; -const ioport_cfg_t g_bsp_pin_cfg = { - .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), - .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], + +const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = +{ + { .pin = BSP_IO_PORT_01_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SPI) }, + { .pin = BSP_IO_PORT_01_PIN_08, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_09, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_01_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_03_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_DEBUG) }, + { .pin = BSP_IO_PORT_03_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, + { .pin = BSP_IO_PORT_03_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, + { .pin = BSP_IO_PORT_03_PIN_04, .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, + { .pin = BSP_IO_PORT_04_PIN_01, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_04_PIN_02, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, + { .pin = BSP_IO_PORT_04_PIN_08, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_04_PIN_09, .pin_cfg = ((uint32_t)IOPORT_CFG_PORT_DIRECTION_OUTPUT + | (uint32_t)IOPORT_CFG_PORT_OUTPUT_LOW) }, + { .pin = BSP_IO_PORT_04_PIN_10, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_04_PIN_11, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN + | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, }; + +const ioport_cfg_t g_bsp_pin_cfg = +{ .number_of_pins = sizeof(g_bsp_pin_cfg_data) / sizeof(ioport_pin_cfg_t), .p_pin_cfg_data = &g_bsp_pin_cfg_data[0], }; + +#if BSP_TZ_SECURE_BUILD + +void R_BSP_PinCfgSecurityInit(void); + +/* Initialize SAR registers for secure pins. */ +void R_BSP_PinCfgSecurityInit(void) { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + uint32_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #else + uint16_t pmsar[BSP_FEATURE_BSP_NUM_PMSAR]; + #endif + memset(pmsar, 0xFF, BSP_FEATURE_BSP_NUM_PMSAR * sizeof(R_PMISC->PMSAR[0])); + + + for (uint32_t i = 0; i < g_bsp_pin_cfg.number_of_pins; i++) + { + uint32_t port_pin = g_bsp_pin_cfg.p_pin_cfg_data[i].pin; + uint32_t port = port_pin >> 8U; + uint32_t pin = port_pin & 0xFFU; + pmsar[port] &= (uint16_t) ~(1U << pin); + } + + for (uint32_t i = 0; i < BSP_FEATURE_BSP_NUM_PMSAR; i++) + { + #if (2U == BSP_FEATURE_IOPORT_VERSION) + R_PMISC->PMSAR[i].PMSAR = (uint16_t)pmsar[i]; + #else + R_PMISC->PMSAR[i].PMSAR = pmsar[i]; + #endif + } + +} +#endif diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/vector_data.c b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/vector_data.c index ea2f3b066f..44ae4d2535 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/vector_data.c +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/vector_data.c @@ -12,21 +12,21 @@ BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BS [5] = sci_uart_txi_isr, /* SCI1 TXI (Transmit data empty) */ [6] = sci_uart_tei_isr, /* SCI1 TEI (Transmit end) */ [7] = sci_uart_eri_isr, /* SCI1 ERI (Receive error) */ - [8] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ - [9] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ - [10] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ - [11] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ - [12] = r_icu_isr, /* ICU IRQ5 (External pin interrupt 5) */ - [13] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ - [14] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ - [15] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ - [16] = spi_eri_isr, /* SPI0 ERI (Error) */ - [17] = iic_master_rxi_isr, /* IIC1 RXI (Receive data full) */ - [18] = iic_master_txi_isr, /* IIC1 TXI (Transmit data empty) */ - [19] = iic_master_tei_isr, /* IIC1 TEI (Transmit end) */ - [20] = iic_master_eri_isr, /* IIC1 ERI (Transfer error) */ - [21] = r_icu_isr, /* ICU IRQ6 (External pin interrupt 6) */ - [22] = r_icu_isr, /* ICU IRQ9 (External pin interrupt 9) */ + [8] = rtc_alarm_periodic_isr, /* RTC ALARM (Alarm interrupt) */ + [9] = rtc_alarm_periodic_isr, /* RTC PERIOD (Periodic interrupt) */ + [10] = rtc_carry_isr, /* RTC CARRY (Carry interrupt) */ + [11] = agt_int_isr, /* AGT0 INT (AGT interrupt) */ + [12] = r_icu_isr, /* ICU IRQ5 (External pin interrupt 5) */ + [13] = spi_rxi_isr, /* SPI0 RXI (Receive buffer full) */ + [14] = spi_txi_isr, /* SPI0 TXI (Transmit buffer empty) */ + [15] = spi_tei_isr, /* SPI0 TEI (Transmission complete event) */ + [16] = spi_eri_isr, /* SPI0 ERI (Error) */ + [17] = iic_master_rxi_isr, /* IIC1 RXI (Receive data full) */ + [18] = iic_master_txi_isr, /* IIC1 TXI (Transmit data empty) */ + [19] = iic_master_tei_isr, /* IIC1 TEI (Transmit end) */ + [20] = iic_master_eri_isr, /* IIC1 ERI (Transfer error) */ + [21] = r_icu_isr, /* ICU IRQ6 (External pin interrupt 6) */ + [22] = r_icu_isr, /* ICU IRQ9 (External pin interrupt 9) */ }; const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = { @@ -38,20 +38,20 @@ const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENT [5] = BSP_PRV_IELS_ENUM(EVENT_SCI1_TXI), /* SCI1 TXI (Transmit data empty) */ [6] = BSP_PRV_IELS_ENUM(EVENT_SCI1_TEI), /* SCI1 TEI (Transmit end) */ [7] = BSP_PRV_IELS_ENUM(EVENT_SCI1_ERI), /* SCI1 ERI (Receive error) */ - [8] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ - [9] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ - [10] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ - [11] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ - [12] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ5), /* ICU IRQ5 (External pin interrupt 5) */ - [13] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ - [14] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ - [15] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ - [16] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ - [17] = BSP_PRV_IELS_ENUM(EVENT_IIC1_RXI), /* IIC1 RXI (Receive data full) */ - [18] = BSP_PRV_IELS_ENUM(EVENT_IIC1_TXI), /* IIC1 TXI (Transmit data empty) */ - [19] = BSP_PRV_IELS_ENUM(EVENT_IIC1_TEI), /* IIC1 TEI (Transmit end) */ - [20] = BSP_PRV_IELS_ENUM(EVENT_IIC1_ERI), /* IIC1 ERI (Transfer error) */ - [21] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ6), /* ICU IRQ6 (External pin interrupt 6) */ - [22] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ9), /* ICU IRQ9 (External pin interrupt 9) */ + [8] = BSP_PRV_IELS_ENUM(EVENT_RTC_ALARM), /* RTC ALARM (Alarm interrupt) */ + [9] = BSP_PRV_IELS_ENUM(EVENT_RTC_PERIOD), /* RTC PERIOD (Periodic interrupt) */ + [10] = BSP_PRV_IELS_ENUM(EVENT_RTC_CARRY), /* RTC CARRY (Carry interrupt) */ + [11] = BSP_PRV_IELS_ENUM(EVENT_AGT0_INT), /* AGT0 INT (AGT interrupt) */ + [12] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ5), /* ICU IRQ5 (External pin interrupt 5) */ + [13] = BSP_PRV_IELS_ENUM(EVENT_SPI0_RXI), /* SPI0 RXI (Receive buffer full) */ + [14] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TXI), /* SPI0 TXI (Transmit buffer empty) */ + [15] = BSP_PRV_IELS_ENUM(EVENT_SPI0_TEI), /* SPI0 TEI (Transmission complete event) */ + [16] = BSP_PRV_IELS_ENUM(EVENT_SPI0_ERI), /* SPI0 ERI (Error) */ + [17] = BSP_PRV_IELS_ENUM(EVENT_IIC1_RXI), /* IIC1 RXI (Receive data full) */ + [18] = BSP_PRV_IELS_ENUM(EVENT_IIC1_TXI), /* IIC1 TXI (Transmit data empty) */ + [19] = BSP_PRV_IELS_ENUM(EVENT_IIC1_TEI), /* IIC1 TEI (Transmit end) */ + [20] = BSP_PRV_IELS_ENUM(EVENT_IIC1_ERI), /* IIC1 ERI (Transfer error) */ + [21] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ6), /* ICU IRQ6 (External pin interrupt 6) */ + [22] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ9), /* ICU IRQ9 (External pin interrupt 9) */ }; #endif diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/vector_data.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/vector_data.h index 5481e446c1..7ff71ed14e 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/vector_data.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/vector_data.h @@ -1,6 +1,9 @@ /* generated vector header file - do not edit */ #ifndef VECTOR_DATA_H #define VECTOR_DATA_H +#ifdef __cplusplus +extern "C" { +#endif /* Number of interrupts allocated */ #ifndef VECTOR_DATA_IRQ_COUNT #define VECTOR_DATA_IRQ_COUNT (23) @@ -25,63 +28,52 @@ void iic_master_eri_isr(void); /* Vector table allocations */ #define VECTOR_NUMBER_SCI0_RXI ((IRQn_Type)0) /* SCI0 RXI (Receive data full) */ +#define SCI0_RXI_IRQn ((IRQn_Type)0) /* SCI0 RXI (Receive data full) */ #define VECTOR_NUMBER_SCI0_TXI ((IRQn_Type)1) /* SCI0 TXI (Transmit data empty) */ +#define SCI0_TXI_IRQn ((IRQn_Type)1) /* SCI0 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI0_TEI ((IRQn_Type)2) /* SCI0 TEI (Transmit end) */ +#define SCI0_TEI_IRQn ((IRQn_Type)2) /* SCI0 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI0_ERI ((IRQn_Type)3) /* SCI0 ERI (Receive error) */ +#define SCI0_ERI_IRQn ((IRQn_Type)3) /* SCI0 ERI (Receive error) */ #define VECTOR_NUMBER_SCI1_RXI ((IRQn_Type)4) /* SCI1 RXI (Received data full) */ +#define SCI1_RXI_IRQn ((IRQn_Type)4) /* SCI1 RXI (Received data full) */ #define VECTOR_NUMBER_SCI1_TXI ((IRQn_Type)5) /* SCI1 TXI (Transmit data empty) */ +#define SCI1_TXI_IRQn ((IRQn_Type)5) /* SCI1 TXI (Transmit data empty) */ #define VECTOR_NUMBER_SCI1_TEI ((IRQn_Type)6) /* SCI1 TEI (Transmit end) */ +#define SCI1_TEI_IRQn ((IRQn_Type)6) /* SCI1 TEI (Transmit end) */ #define VECTOR_NUMBER_SCI1_ERI ((IRQn_Type)7) /* SCI1 ERI (Receive error) */ +#define SCI1_ERI_IRQn ((IRQn_Type)7) /* SCI1 ERI (Receive error) */ #define VECTOR_NUMBER_RTC_ALARM ((IRQn_Type)8) /* RTC ALARM (Alarm interrupt) */ +#define RTC_ALARM_IRQn ((IRQn_Type)8) /* RTC ALARM (Alarm interrupt) */ #define VECTOR_NUMBER_RTC_PERIOD ((IRQn_Type)9) /* RTC PERIOD (Periodic interrupt) */ +#define RTC_PERIOD_IRQn ((IRQn_Type)9) /* RTC PERIOD (Periodic interrupt) */ #define VECTOR_NUMBER_RTC_CARRY ((IRQn_Type)10) /* RTC CARRY (Carry interrupt) */ +#define RTC_CARRY_IRQn ((IRQn_Type)10) /* RTC CARRY (Carry interrupt) */ #define VECTOR_NUMBER_AGT0_INT ((IRQn_Type)11) /* AGT0 INT (AGT interrupt) */ +#define AGT0_INT_IRQn ((IRQn_Type)11) /* AGT0 INT (AGT interrupt) */ #define VECTOR_NUMBER_ICU_IRQ5 ((IRQn_Type)12) /* ICU IRQ5 (External pin interrupt 5) */ +#define ICU_IRQ5_IRQn ((IRQn_Type)12) /* ICU IRQ5 (External pin interrupt 5) */ #define VECTOR_NUMBER_SPI0_RXI ((IRQn_Type)13) /* SPI0 RXI (Receive buffer full) */ +#define SPI0_RXI_IRQn ((IRQn_Type)13) /* SPI0 RXI (Receive buffer full) */ #define VECTOR_NUMBER_SPI0_TXI ((IRQn_Type)14) /* SPI0 TXI (Transmit buffer empty) */ +#define SPI0_TXI_IRQn ((IRQn_Type)14) /* SPI0 TXI (Transmit buffer empty) */ #define VECTOR_NUMBER_SPI0_TEI ((IRQn_Type)15) /* SPI0 TEI (Transmission complete event) */ +#define SPI0_TEI_IRQn ((IRQn_Type)15) /* SPI0 TEI (Transmission complete event) */ #define VECTOR_NUMBER_SPI0_ERI ((IRQn_Type)16) /* SPI0 ERI (Error) */ +#define SPI0_ERI_IRQn ((IRQn_Type)16) /* SPI0 ERI (Error) */ #define VECTOR_NUMBER_IIC1_RXI ((IRQn_Type)17) /* IIC1 RXI (Receive data full) */ +#define IIC1_RXI_IRQn ((IRQn_Type)17) /* IIC1 RXI (Receive data full) */ #define VECTOR_NUMBER_IIC1_TXI ((IRQn_Type)18) /* IIC1 TXI (Transmit data empty) */ +#define IIC1_TXI_IRQn ((IRQn_Type)18) /* IIC1 TXI (Transmit data empty) */ #define VECTOR_NUMBER_IIC1_TEI ((IRQn_Type)19) /* IIC1 TEI (Transmit end) */ +#define IIC1_TEI_IRQn ((IRQn_Type)19) /* IIC1 TEI (Transmit end) */ #define VECTOR_NUMBER_IIC1_ERI ((IRQn_Type)20) /* IIC1 ERI (Transfer error) */ +#define IIC1_ERI_IRQn ((IRQn_Type)20) /* IIC1 ERI (Transfer error) */ #define VECTOR_NUMBER_ICU_IRQ6 ((IRQn_Type)21) /* ICU IRQ6 (External pin interrupt 6) */ +#define ICU_IRQ6_IRQn ((IRQn_Type)21) /* ICU IRQ6 (External pin interrupt 6) */ #define VECTOR_NUMBER_ICU_IRQ9 ((IRQn_Type)22) /* ICU IRQ9 (External pin interrupt 9) */ -typedef enum IRQn -{ - Reset_IRQn = -15, - NonMaskableInt_IRQn = -14, - HardFault_IRQn = -13, - MemoryManagement_IRQn = -12, - BusFault_IRQn = -11, - UsageFault_IRQn = -10, - SecureFault_IRQn = -9, - SVCall_IRQn = -5, - DebugMonitor_IRQn = -4, - PendSV_IRQn = -2, - SysTick_IRQn = -1, - SCI0_RXI_IRQn = 0, /* SCI0 RXI (Receive data full) */ - SCI0_TXI_IRQn = 1, /* SCI0 TXI (Transmit data empty) */ - SCI0_TEI_IRQn = 2, /* SCI0 TEI (Transmit end) */ - SCI0_ERI_IRQn = 3, /* SCI0 ERI (Receive error) */ - SCI1_RXI_IRQn = 4, /* SCI1 RXI (Received data full) */ - SCI1_TXI_IRQn = 5, /* SCI1 TXI (Transmit data empty) */ - SCI1_TEI_IRQn = 6, /* SCI1 TEI (Transmit end) */ - SCI1_ERI_IRQn = 7, /* SCI1 ERI (Receive error) */ - RTC_ALARM_IRQn = 8, /* RTC ALARM (Alarm interrupt) */ - RTC_PERIOD_IRQn = 9, /* RTC PERIOD (Periodic interrupt) */ - RTC_CARRY_IRQn = 10, /* RTC CARRY (Carry interrupt) */ - AGT0_INT_IRQn = 11, /* AGT0 INT (AGT interrupt) */ - ICU_IRQ5_IRQn = 12, /* ICU IRQ5 (External pin interrupt 5) */ - SPI0_RXI_IRQn = 13, /* SPI0 RXI (Receive buffer full) */ - SPI0_TXI_IRQn = 14, /* SPI0 TXI (Transmit buffer empty) */ - SPI0_TEI_IRQn = 15, /* SPI0 TEI (Transmission complete event) */ - SPI0_ERI_IRQn = 16, /* SPI0 ERI (Error) */ - IIC1_RXI_IRQn = 17, /* IIC1 RXI (Receive data full) */ - IIC1_TXI_IRQn = 18, /* IIC1 TXI (Transmit data empty) */ - IIC1_TEI_IRQn = 19, /* IIC1 TEI (Transmit end) */ - IIC1_ERI_IRQn = 20, /* IIC1 ERI (Transfer error) */ - ICU_IRQ6_IRQn = 21, /* ICU IRQ6 (External pin interrupt 6) */ - ICU_IRQ9_IRQn = 22, /* ICU IRQ9 (External pin interrupt 9) */ -} IRQn_Type; +#define ICU_IRQ9_IRQn ((IRQn_Type)22) /* ICU IRQ9 (External pin interrupt 9) */ +#ifdef __cplusplus +} +#endif #endif /* VECTOR_DATA_H */ diff --git a/ports/renesas-ra/ra/ra_timer.c b/ports/renesas-ra/ra/ra_timer.c index 5f2adcdfab..9c2a3c010e 100644 --- a/ports/renesas-ra/ra/ra_timer.c +++ b/ports/renesas-ra/ra/ra_timer.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2021 Renesas Electronics Corporation + * Copyright (c) 2021-2023 Renesas Electronics Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -42,9 +42,9 @@ enum AGT_SOURCE { AGT_AGTSCLK }; -static R_AGT0_Type *agt_regs[AGT_CH_SIZE] = { - (R_AGT0_Type *)0x40084000, - (R_AGT0_Type *)0x40084100 +static R_AGTX0_AGT16_Type *agt_regs[AGT_CH_SIZE] = { + (R_AGTX0_AGT16_Type *)0x40084000, + (R_AGTX0_AGT16_Type *)0x40084100 }; static uint8_t ch_to_irq[AGT_CH_SIZE] = { @@ -77,15 +77,15 @@ static void ra_agt_timer_chk_callback(uint32_t ch) { } void ra_agt_timer_start(uint32_t ch) { - agt_regs[ch]->AGTCR_b.TSTART = 1; /* start counter */ + agt_regs[ch]->CTRL.AGTCR_b.TSTART = 1; /* start counter */ } void ra_agt_timer_stop(uint32_t ch) { - agt_regs[ch]->AGTCR_b.TSTART = 0; /* stop counter */ + agt_regs[ch]->CTRL.AGTCR_b.TSTART = 0; /* stop counter */ } void ra_agt_timer_set_freq(uint32_t ch, float freq) { - R_AGT0_Type *agt_reg = agt_regs[ch]; + R_AGTX0_AGT16_Type *agt_reg = agt_regs[ch]; uint8_t source = 0; uint16_t period = 0; uint8_t cks = 0; @@ -107,9 +107,9 @@ void ra_agt_timer_set_freq(uint32_t ch, float freq) { return; } ra_agt_freq[ch] = freq; - agt_reg->AGTCR_b.TSTART = 0; // stop counter - agt_reg->AGTMR2 = cks; - agt_reg->AGTMR1 = (uint8_t)(source << 4); // mode is timer mode + agt_reg->CTRL.AGTCR_b.TSTART = 0; // stop counter + agt_reg->CTRL.AGTMR2 = cks; + agt_reg->CTRL.AGTMR1 = (uint8_t)(source << 4); // mode is timer mode agt_reg->AGT = (uint16_t)period; } @@ -118,14 +118,14 @@ float ra_agt_timer_get_freq(uint32_t ch) { } void ra_agt_timer_init(uint32_t ch, float freq) { - R_AGT0_Type *agt_reg = agt_regs[ch]; + R_AGTX0_AGT16_Type *agt_reg = agt_regs[ch]; if (ch == 0) { ra_mstpcrd_start(R_MSTP_MSTPCRD_MSTPD3_Msk); } else { ra_mstpcrd_start(R_MSTP_MSTPCRD_MSTPD2_Msk); } ra_agt_timer_set_freq(ch, freq); - agt_reg->AGTCR_b.TUNDF = 1; // underflow interrupt + agt_reg->CTRL.AGTCR_b.TUNDF = 1; // underflow interrupt R_BSP_IrqCfgEnable((IRQn_Type const)ch_to_irq[ch], RA_PRI_TIM5, (void *)NULL); } diff --git a/ports/renesas-ra/ra/ra_utils.c b/ports/renesas-ra/ra/ra_utils.c index 94e30ded11..ae91427eec 100644 --- a/ports/renesas-ra/ra/ra_utils.c +++ b/ports/renesas-ra/ra/ra_utils.c @@ -27,7 +27,7 @@ #include "ra_utils.h" static R_SYSTEM_Type *system_reg = (R_SYSTEM_Type *)0x4001E000; -static R_MSTP_Type *mstp_reg = (R_MSTP_Type *)0x40047000; +static R_MSTP_Type *mstp_reg = (R_MSTP_Type *)R_MSTP; void ra_mstpcra_stop(uint32_t mod_mask) { system_reg->PRCR = 0xa502; diff --git a/ports/renesas-ra/ra/ra_utils.h b/ports/renesas-ra/ra/ra_utils.h index 4da30d06cf..3ff0f3a371 100644 --- a/ports/renesas-ra/ra/ra_utils.h +++ b/ports/renesas-ra/ra/ra_utils.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2021 Renesas Electronics Corporation + * Copyright (c) 2021-2023 Renesas Electronics Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -53,4 +53,77 @@ void ra_mstpcrc_start(uint32_t mod_mask); void ra_mstpcrd_stop(uint32_t mod_mask); void ra_mstpcrd_start(uint32_t mod_mask); +/* mask bit definition for Module Stop Control Register B */ +#ifndef R_MSTP_MSTPCRB_MSTPB7_Msk +#define R_MSTP_MSTPCRB_MSTPB7_Msk (0x1UL << 7) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB8_Msk +#define R_MSTP_MSTPCRB_MSTPB8_Msk (0x1UL << 8) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB9_Msk +#define R_MSTP_MSTPCRB_MSTPB9_Msk (0x1UL << 9) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB18_Msk +#define R_MSTP_MSTPCRB_MSTPB18_Msk (0x1UL << 18) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB19_Msk +#define R_MSTP_MSTPCRB_MSTPB19_Msk (0x1UL << 19) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB22_Msk +#define R_MSTP_MSTPCRB_MSTPB22_Msk (0x1UL << 22) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB23_Msk +#define R_MSTP_MSTPCRB_MSTPB23_Msk (0x1UL << 23) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB24_Msk +#define R_MSTP_MSTPCRB_MSTPB24_Msk (0x1UL << 24) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB25_Msk +#define R_MSTP_MSTPCRB_MSTPB25_Msk (0x1UL << 25) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB26_Msk +#define R_MSTP_MSTPCRB_MSTPB26_Msk (0x1UL << 26) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB27_Msk +#define R_MSTP_MSTPCRB_MSTPB27_Msk (0x1UL << 27) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB28_Msk +#define R_MSTP_MSTPCRB_MSTPB28_Msk (0x1UL << 28) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB29_Msk +#define R_MSTP_MSTPCRB_MSTPB29_Msk (0x1UL << 29) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB30_Msk +#define R_MSTP_MSTPCRB_MSTPB30_Msk (0x1UL << 30) +#endif +#ifndef R_MSTP_MSTPCRB_MSTPB31_Msk +#define R_MSTP_MSTPCRB_MSTPB31_Msk (0x1UL << 31) +#endif + +/* mask bit definition for Module Stop Control Register D */ +#ifndef R_MSTP_MSTPCRD_MSTPD2_Msk +#define R_MSTP_MSTPCRD_MSTPD2_Msk (0x1UL << 2) +#endif +#ifndef R_MSTP_MSTPCRD_MSTPD3_Msk +#define R_MSTP_MSTPCRD_MSTPD3_Msk (0x1UL << 3) +#endif +#ifndef R_MSTP_MSTPCRD_MSTPD5_Msk +#define R_MSTP_MSTPCRD_MSTPD5_Msk (0x1UL << 5) +#endif +#ifndef R_MSTP_MSTPCRD_MSTPD6_Msk +#define R_MSTP_MSTPCRD_MSTPD6_Msk (0x1UL << 6) +#endif +#ifndef R_MSTP_MSTPCRD_MSTPD15_Msk +#define R_MSTP_MSTPCRD_MSTPD15_Msk (0x1UL << 15) +#endif +#ifndef R_MSTP_MSTPCRD_MSTPD16_Msk +#define R_MSTP_MSTPCRD_MSTPD16_Msk (0x1UL << 16) +#endif +#ifndef R_MSTP_MSTPCRD_MSTPD20_Msk +#define R_MSTP_MSTPCRD_MSTPD20_Msk (0x1UL << 20) +#endif +#ifndef R_MSTP_MSTPCRD_MSTPD22_Msk +#define R_MSTP_MSTPCRD_MSTPD22_Msk (0x1UL << 22) +#endif + #endif /* RA_RA_UTILS_H_ */ From 3229791b60185faa47d87af80b6a8ccbb34d15e5 Mon Sep 17 00:00:00 2001 From: Takeo Takahashi Date: Mon, 1 May 2023 22:54:32 +0900 Subject: [PATCH 068/565] renesas-ra: Add a macro definition to avoid compile error of FSP v4.4.0. FSP v4.4.0 refers to CMSIS V5.4.1, and __COMPILER_BARRIER() is used in bsp. On the other hand, lib/cmsis is V5.1.0 and the macro is not defined. Therefore, compile error happens. As the workaround, the macro definition is added. If lib/cmsis is updated in the future, this addition can be removed. Signed-off-by: Takeo Takahashi --- ports/renesas-ra/Makefile | 1 + ports/renesas-ra/boards/compiler_barrier.h | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 ports/renesas-ra/boards/compiler_barrier.h diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index bcfae8555e..85ffd9a1e9 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -89,6 +89,7 @@ SYSTEM_FILE ?= lib/fsp/ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/system.o # Select the cross compile prefix CROSS_COMPILE ?= arm-none-eabi- +INC += -imacros boards/compiler_barrier.h INC += -I. INC += -I$(TOP) INC += -I$(BUILD) diff --git a/ports/renesas-ra/boards/compiler_barrier.h b/ports/renesas-ra/boards/compiler_barrier.h new file mode 100644 index 0000000000..c1145b1b9d --- /dev/null +++ b/ports/renesas-ra/boards/compiler_barrier.h @@ -0,0 +1,4 @@ +// we need to provide a definition of __COMPILER_BARRIER() defined in cmsis/cmsis_gcc.h V5.4.1 for FSP v4.4.0 +#ifndef __COMPILER_BARRIER + #define __COMPILER_BARRIER() __ASM volatile ("" ::: "memory") +#endif From f9958417d8adb21147de776361a4414073cf7c77 Mon Sep 17 00:00:00 2001 From: Adam Green Date: Thu, 20 Apr 2023 22:23:46 -0700 Subject: [PATCH 069/565] rp2: Make rp2_state_machine_exec accept integers. Currently rp2.StateMachine.exec(instr_in) requires that the instr_in parameter be a string representing the PIO assembly language instruction to be encoded by rp2.asm_pio_encode(). This commit allows the parameter to also be of integral type. This is useful if the exec() method is being called often where the use of pre-encoded machine code is desireable. This commit still supports calls like: sm.exec("set(0, 1)") It also now supports calls like: # Performed once earlier, maybe in __init__() assembled_instr = rp2.asm_pio_encode("out(y, 8)", 0) # Performed multiple times later as the PIO state machine is # configured for its next run. sm.exec(assembled_instr) The existing examples/rp2/pio_exec.py and examples/rp2/pio_pwm.py that exercise the rp2.StateMachine.exec() method still work with this change. Signed-off-by: Adam Green --- docs/library/rp2.StateMachine.rst | 11 +++++++++-- ports/rp2/rp2_pio.c | 23 +++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/docs/library/rp2.StateMachine.rst b/docs/library/rp2.StateMachine.rst index d39194e6ff..ee16ce3c51 100644 --- a/docs/library/rp2.StateMachine.rst +++ b/docs/library/rp2.StateMachine.rst @@ -82,11 +82,18 @@ Methods .. method:: StateMachine.exec(instr) - Execute a single PIO instruction. Uses `asm_pio_encode` to encode the - instruction from the given string *instr*. + Execute a single PIO instruction. + + If *instr* is a string then uses `asm_pio_encode` to encode the instruction + from the given string. >>> sm.exec("set(0, 1)") + If *instr* is an integer then it is treated as an already encoded PIO + machine code instruction to be executed. + + >>> sm.exec(rp2.asm_pio_encode("out(y, 8)", 0)) + .. method:: StateMachine.get(buf=None, shift=0) Pull a word from the state machine's RX FIFO. diff --git a/ports/rp2/rp2_pio.c b/ports/rp2/rp2_pio.c index 3ece26bd41..2e30475257 100644 --- a/ports/rp2/rp2_pio.c +++ b/ports/rp2/rp2_pio.c @@ -684,16 +684,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_restart_obj, rp2_state_machin // StateMachine.exec(instr) STATIC mp_obj_t rp2_state_machine_exec(mp_obj_t self_in, mp_obj_t instr_in) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_t rp2_module = mp_import_name(MP_QSTR_rp2, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)); - mp_obj_t asm_pio_encode = mp_load_attr(rp2_module, MP_QSTR_asm_pio_encode); - uint32_t sideset_count = self->pio->sm[self->sm].pinctrl >> PIO_SM0_PINCTRL_SIDESET_COUNT_LSB; - uint8_t sideset_opt = !!(self->pio->sm[self->sm].execctrl & (1 << PIO_SM0_EXECCTRL_SIDE_EN_LSB)); - mp_obj_t args[3]; - args[0] = instr_in; - args[1] = MP_OBJ_NEW_SMALL_INT(sideset_count); - args[2] = MP_OBJ_NEW_SMALL_INT(sideset_opt); - mp_obj_t encoded_obj = mp_call_function_n_kw(asm_pio_encode, 3, 0, args); - mp_int_t encoded = mp_obj_get_int(encoded_obj); + mp_int_t encoded = 0; + if (!mp_obj_get_int_maybe(instr_in, &encoded)) { + mp_obj_t rp2_module = mp_import_name(MP_QSTR_rp2, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)); + mp_obj_t asm_pio_encode = mp_load_attr(rp2_module, MP_QSTR_asm_pio_encode); + uint32_t sideset_count = self->pio->sm[self->sm].pinctrl >> PIO_SM0_PINCTRL_SIDESET_COUNT_LSB; + uint8_t sideset_opt = !!(self->pio->sm[self->sm].execctrl & (1 << PIO_SM0_EXECCTRL_SIDE_EN_LSB)); + mp_obj_t args[3]; + args[0] = instr_in; + args[1] = MP_OBJ_NEW_SMALL_INT(sideset_count); + args[2] = MP_OBJ_NEW_SMALL_INT(sideset_opt); + mp_obj_t encoded_obj = mp_call_function_n_kw(asm_pio_encode, 3, 0, args); + encoded = mp_obj_get_int(encoded_obj); + } pio_sm_exec(self->pio, self->sm, encoded); return mp_const_none; } From 4ce360fa831a35d7bc0e194f11d74632a0fba60b Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 4 May 2023 21:25:52 +0100 Subject: [PATCH 070/565] rp2/CMakeLists: Allow relative MICROPY_BOARD_DIR when invoking cmake. Convert to an absolute path to always reliably locate manifest.py. This is already done in Makefile, but is also needed in CMakeLists.txt if cmake is invoked directly. Signed-off-by: Phil Howard --- ports/rp2/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 501957d20d..4d0de92182 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -31,6 +31,7 @@ endif() if(NOT MICROPY_BOARD_DIR) set(MICROPY_BOARD_DIR ${MICROPY_PORT_DIR}/boards/${MICROPY_BOARD}) endif() +get_filename_component(MICROPY_BOARD_DIR ${MICROPY_BOARD_DIR} ABSOLUTE) if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake) message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}") endif() From 29401a719fa944ae639734c69e95795023704adb Mon Sep 17 00:00:00 2001 From: Ondrej Wisniewski Date: Fri, 5 May 2023 13:08:55 +0200 Subject: [PATCH 071/565] rp2/mphalport: Only use CYW43 MAC for WLAN0 interface. Building the Pico-W needs the MICROPY_PY_NETWORK_CYW43 flag to be set in order to include building the CYW43 Wifi driver. But then mp_hal_get_mac() handles the MAC assignment for all nics the "CYW43 way", copying the real MAC provided by the WiFi hardware. This will fail for all other NIC types, resulting in an invalid MAC address. The solution in this commit is to add a check for the NIC type parameter idx and handle the MAC address respectively. --- ports/rp2/mphalport.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index f56c2bda13..84a34b2a40 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -204,10 +204,12 @@ MP_WEAK void mp_hal_get_mac(int idx, uint8_t buf[6]) { // The mac should come from cyw43 otp when CYW43_USE_OTP_MAC is defined // This is loaded into the state after the driver is initialised // cyw43_hal_generate_laa_mac is only called by the driver to generate a mac if otp is not set - memcpy(buf, cyw43_state.mac, 6); - #else - mp_hal_generate_laa_mac(idx, buf); + if (idx == MP_HAL_MAC_WLAN0) { + memcpy(buf, cyw43_state.mac, 6); + return; + } #endif + mp_hal_generate_laa_mac(idx, buf); } void mp_hal_get_mac_ascii(int idx, size_t chr_off, size_t chr_len, char *dest) { From ab3f9ecb595bf114c744e253cdbd6d1e42951d2f Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 18 May 2023 13:00:36 +1000 Subject: [PATCH 072/565] github/workflows: Force use of Ubuntu-20.04 for unix 32-bit builds. To be able to install libffi-dev:i386. Signed-off-by: Damien George --- .github/workflows/ports_unix.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ports_unix.yml b/.github/workflows/ports_unix.yml index fe25deb4ad..87c58055b9 100644 --- a/.github/workflows/ports_unix.yml +++ b/.github/workflows/ports_unix.yml @@ -85,7 +85,7 @@ jobs: run: tests/run-tests.py --print-failures coverage_32bit: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 # use 20.04 to get libffi-dev:i386 steps: - uses: actions/checkout@v3 - name: Install packages @@ -103,7 +103,7 @@ jobs: run: tests/run-tests.py --print-failures nanbox: - runs-on: ubuntu-20.04 # use 20.04 to get python2 + runs-on: ubuntu-20.04 # use 20.04 to get python2, and libffi-dev:i386 steps: - uses: actions/checkout@v3 - name: Install packages From 17127bbee52f2c674c5c79b675fabacea7bc2751 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 11 May 2023 14:28:35 +1000 Subject: [PATCH 073/565] tests/run-tests.py: Ensure correct cwd for mpy tests. Previously when using --via-mpy, the file was compiled to tests/.mpy and then run using `micropython -m ` in the current cwd (usually tests/). This meant that an import in the test would be resolved relative to tests/. This is different to regular (non-via-mpy) tests, where we run (for example) `micropython basics/test.py` which means that an import would be resolved relative to basics/. Now --via-mpy matches the .py behavior. This is important because: a) It makes it so import tests do the right thing. b) There are directory names in tests/ that match built-in module names. Furthermore, it always ensures the cwd (for both micropython and cpython) is the test directory (e.g. basics/) rather than being left unset. This also makes it clearer inside the test that e.g. file access is relative to the Python file. Updated tests with file paths to match. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/io/file1.py | 20 ++++++++++---------- tests/io/file_iter.py | 2 +- tests/io/file_long_read.py | 2 +- tests/io/file_long_read2.py | 2 +- tests/io/file_long_read3.py | 2 +- tests/io/file_readinto.py | 6 +++--- tests/io/file_readinto_len.py | 4 ++-- tests/io/file_readline.py | 4 ++-- tests/io/file_seek.py | 6 +++--- tests/io/file_with.py | 2 +- tests/run-tests.py | 16 ++++++++++------ tests/unicode/file1.py | 2 +- tests/unicode/file2.py | 2 +- tests/unicode/file_invalid.py | 2 +- 14 files changed, 38 insertions(+), 34 deletions(-) diff --git a/tests/io/file1.py b/tests/io/file1.py index de30045d31..1274a653d1 100644 --- a/tests/io/file1.py +++ b/tests/io/file1.py @@ -1,20 +1,20 @@ -f = open("io/data/file1") +f = open("data/file1") print(f.read(5)) print(f.readline()) print(f.read()) -f = open("io/data/file1") +f = open("data/file1") print(f.readlines()) -f = open("io/data/file1", "r") +f = open("data/file1", "r") print(f.readlines()) -f = open("io/data/file1", "rb") +f = open("data/file1", "rb") print(f.readlines()) -f = open("io/data/file1", mode="r") +f = open("data/file1", mode="r") print(f.readlines()) -f = open("io/data/file1", mode="rb") +f = open("data/file1", mode="rb") print(f.readlines()) # write() error -f = open("io/data/file1", "r") +f = open("data/file1", "r") try: f.write("x") except OSError: @@ -22,7 +22,7 @@ except OSError: f.close() # read(n) error on binary file -f = open("io/data/file1", "ab") +f = open("data/file1", "ab") try: f.read(1) except OSError: @@ -30,7 +30,7 @@ except OSError: f.close() # read(n) error on text file -f = open("io/data/file1", "at") +f = open("data/file1", "at") try: f.read(1) except OSError: @@ -38,7 +38,7 @@ except OSError: f.close() # read() w/o args error -f = open("io/data/file1", "ab") +f = open("data/file1", "ab") try: f.read() except OSError: diff --git a/tests/io/file_iter.py b/tests/io/file_iter.py index 48e8739966..26e82b9b1a 100644 --- a/tests/io/file_iter.py +++ b/tests/io/file_iter.py @@ -1,3 +1,3 @@ -f = open("io/data/file1") +f = open("data/file1") for l in f: print(l) diff --git a/tests/io/file_long_read.py b/tests/io/file_long_read.py index 8bdd484504..3f57d5594d 100644 --- a/tests/io/file_long_read.py +++ b/tests/io/file_long_read.py @@ -1,3 +1,3 @@ -f = open("io/data/file1") +f = open("data/file1") b = f.read(100) print(len(b)) diff --git a/tests/io/file_long_read2.py b/tests/io/file_long_read2.py index 337a5fba96..ea87f91f10 100644 --- a/tests/io/file_long_read2.py +++ b/tests/io/file_long_read2.py @@ -1,4 +1,4 @@ -f = open("io/data/bigfile1") +f = open("data/bigfile1") b = f.read() print(len(b)) print(b) diff --git a/tests/io/file_long_read3.py b/tests/io/file_long_read3.py index d8b0cce550..1ea47e1853 100644 --- a/tests/io/file_long_read3.py +++ b/tests/io/file_long_read3.py @@ -1,4 +1,4 @@ -f = open("io/data/bigfile1", "rb") +f = open("data/bigfile1", "rb") b = f.read(512) print(len(b)) print(b) diff --git a/tests/io/file_readinto.py b/tests/io/file_readinto.py index 1f3702a217..f9004013d9 100644 --- a/tests/io/file_readinto.py +++ b/tests/io/file_readinto.py @@ -1,13 +1,13 @@ b = bytearray(30) -f = open("io/data/file1", "rb") +f = open("data/file1", "rb") print(f.readinto(b)) print(b) -f = open("io/data/file2", "rb") +f = open("data/file2", "rb") print(f.readinto(b)) print(b) # readinto() on writable file -f = open("io/data/file1", "ab") +f = open("data/file1", "ab") try: f.readinto(bytearray(4)) except OSError: diff --git a/tests/io/file_readinto_len.py b/tests/io/file_readinto_len.py index 84cc8cf5e1..d6eb1dfc41 100644 --- a/tests/io/file_readinto_len.py +++ b/tests/io/file_readinto_len.py @@ -1,10 +1,10 @@ b = bytearray(30) -f = open("io/data/file1", "rb") +f = open("data/file1", "rb") # 2nd arg (length to read) is extension to CPython print(f.readinto(b, 8)) print(b) b = bytearray(4) -f = open("io/data/file1", "rb") +f = open("data/file1", "rb") print(f.readinto(b, 8)) print(b) diff --git a/tests/io/file_readline.py b/tests/io/file_readline.py index 86d010eaf6..3d270db514 100644 --- a/tests/io/file_readline.py +++ b/tests/io/file_readline.py @@ -1,4 +1,4 @@ -f = open("io/data/file1") +f = open("data/file1") print(f.readline()) print(f.readline(3)) print(f.readline(4)) @@ -6,7 +6,7 @@ print(f.readline(5)) print(f.readline()) # readline() on writable file -f = open("io/data/file1", "ab") +f = open("data/file1", "ab") try: f.readline() except OSError: diff --git a/tests/io/file_seek.py b/tests/io/file_seek.py index 2fe57692c6..3990df8409 100644 --- a/tests/io/file_seek.py +++ b/tests/io/file_seek.py @@ -1,4 +1,4 @@ -f = open("io/data/file1", "rb") +f = open("data/file1", "rb") print(f.seek(6)) print(f.read(5)) print(f.tell()) @@ -18,14 +18,14 @@ print(f.tell()) f.close() # test text mode -f = open("io/data/file1", "rt") +f = open("data/file1", "rt") print(f.seek(6)) print(f.read(5)) print(f.tell()) f.close() # seek closed file -f = open("io/data/file1", "r") +f = open("data/file1", "r") f.close() try: f.seek(1) diff --git a/tests/io/file_with.py b/tests/io/file_with.py index 899c0f9287..d5217dfe96 100644 --- a/tests/io/file_with.py +++ b/tests/io/file_with.py @@ -1,4 +1,4 @@ -f = open("io/data/file1") +f = open("data/file1") with f as f2: print(f2.read()) diff --git a/tests/run-tests.py b/tests/run-tests.py index 03269a9f1c..498db8b404 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -261,29 +261,31 @@ def run_micropython(pyb, args, test_file, is_special=False): # a standard test run on PC # create system command - cmdlist = [MICROPYTHON, "-X", "emit=" + args.emit] + cmdlist = [os.path.abspath(MICROPYTHON), "-X", "emit=" + args.emit] if args.heapsize is not None: cmdlist.extend(["-X", "heapsize=" + args.heapsize]) if sys.platform == "darwin": cmdlist.extend(["-X", "realtime"]) + cwd = os.path.dirname(test_file) + # if running via .mpy, first compile the .py file if args.via_mpy: - mpy_modname = tempfile.mktemp(dir="") - mpy_filename = mpy_modname + ".mpy" + mpy_filename = tempfile.mktemp(dir=cwd, suffix=".mpy") subprocess.check_output( [MPYCROSS] + args.mpy_cross_flags.split() + ["-o", mpy_filename, "-X", "emit=" + args.emit, test_file] ) + mpy_modname = os.path.splitext(os.path.basename(mpy_filename))[0] cmdlist.extend(["-m", mpy_modname]) else: - cmdlist.append(test_file) + cmdlist.append(os.path.abspath(test_file)) # run the actual test try: output_mupy = subprocess.check_output( - cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT + cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT, cwd=cwd ) except subprocess.CalledProcessError as er: had_crash = True @@ -707,7 +709,9 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): else: # run CPython to work out expected output try: - output_expected = subprocess.check_output(CPYTHON3_CMD + [test_file]) + output_expected = subprocess.check_output( + CPYTHON3_CMD + [os.path.abspath(test_file)], cwd=os.path.dirname(test_file) + ) if args.write_exp: with open(test_file_expected, "wb") as f: f.write(output_expected) diff --git a/tests/unicode/file1.py b/tests/unicode/file1.py index 08b7d25041..6508b5f716 100644 --- a/tests/unicode/file1.py +++ b/tests/unicode/file1.py @@ -1,4 +1,4 @@ -f = open("unicode/data/utf-8_1.txt", encoding="utf-8") +f = open("data/utf-8_1.txt", encoding="utf-8") l = f.readline() print(l) print(len(l)) diff --git a/tests/unicode/file2.py b/tests/unicode/file2.py index 1a5b933c89..c35c18789c 100644 --- a/tests/unicode/file2.py +++ b/tests/unicode/file2.py @@ -6,7 +6,7 @@ def do(mode): enc = None else: enc = "utf-8" - f = open("unicode/data/utf-8_2.txt", mode=mode, encoding=enc) + f = open("data/utf-8_2.txt", mode=mode, encoding=enc) print(f.read(1)) print(f.read(1)) print(f.read(2)) diff --git a/tests/unicode/file_invalid.py b/tests/unicode/file_invalid.py index 3f7f184062..5c42302519 100644 --- a/tests/unicode/file_invalid.py +++ b/tests/unicode/file_invalid.py @@ -1,5 +1,5 @@ try: - f = open("unicode/data/utf-8_invalid.txt", encoding="utf-8") + f = open("data/utf-8_invalid.txt", encoding="utf-8") f.read() except UnicodeError: print("UnicodeError") From 53cb073571196d2ba7174706d5d784e42e5430cf Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 11 May 2023 11:51:02 +1000 Subject: [PATCH 074/565] esp32,esp8266: Change network.WLAN from a function to a type. When the network module was first introduced in the esp8266 port in ee3fec3167db6e28869d37fb60058c884fb36264 there was only one interface (STA) and, to save flash, the WLAN object was aliased to the network module, which had just static methods for WLAN operations. This was subsequently changed in 9e8396accbcb695e2fe9def666bfb31b26efde06 when the AP interface was introduced, and the WLAN object became a true class. But, network.WLAN remained a function that returned either the STA or AP object and was never upgraded to the type itself. This scheme was then copied over to the esp32 port when it was first introduced. This commit changes network.WLAN from a function to a reference to the WLAN type. This makes it consistent with other ports and network objects, and allows accessing constants of network.WLAN without creating an instance. Signed-off-by: Damien George --- ports/esp32/modnetwork.h | 2 ++ ports/esp32/modnetwork_globals.h | 2 +- ports/esp32/network_wlan.c | 12 +++++++----- ports/esp8266/modnetwork.h | 3 ++- ports/esp8266/modnetwork_globals.h | 2 +- ports/esp8266/network_wlan.c | 13 +++++++------ 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ports/esp32/modnetwork.h b/ports/esp32/modnetwork.h index d7a99f5c94..80537ea473 100644 --- a/ports/esp32/modnetwork.h +++ b/ports/esp32/modnetwork.h @@ -45,6 +45,8 @@ typedef struct _wlan_if_obj_t { int if_id; } wlan_if_obj_t; +extern const mp_obj_type_t esp_network_wlan_type; + MP_DECLARE_CONST_FUN_OBJ_0(esp_network_initialize_obj); MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_get_wlan_obj); MP_DECLARE_CONST_FUN_OBJ_KW(esp_network_get_lan_obj); diff --git a/ports/esp32/modnetwork_globals.h b/ports/esp32/modnetwork_globals.h index 72d1ff3afb..1f657fb5c8 100644 --- a/ports/esp32/modnetwork_globals.h +++ b/ports/esp32/modnetwork_globals.h @@ -1,7 +1,7 @@ { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&esp_network_initialize_obj) }, #if MICROPY_PY_NETWORK_WLAN -{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&esp_network_get_wlan_obj) }, +{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&esp_network_wlan_type) }, #endif #if MICROPY_PY_NETWORK_LAN diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index 81410f209b..e56d73b237 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -171,7 +171,9 @@ void esp_initialise_wifi() { } } -STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t network_wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 1, false); + esp_initialise_wifi(); int idx = (n_args > 0) ? mp_obj_get_int(args[0]) : WIFI_IF_STA; @@ -183,7 +185,6 @@ STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("invalid WLAN interface identifier")); } } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_get_wlan_obj, 0, 1, get_wlan); STATIC mp_obj_t network_wlan_active(size_t n_args, const mp_obj_t *args) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); @@ -646,13 +647,14 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( - wlan_if_type, + esp_network_wlan_type, MP_QSTR_WLAN, MP_TYPE_FLAG_NONE, + make_new, network_wlan_make_new, locals_dict, &wlan_if_locals_dict ); -STATIC const wlan_if_obj_t wlan_sta_obj = {{&wlan_if_type}, WIFI_IF_STA}; -STATIC const wlan_if_obj_t wlan_ap_obj = {{&wlan_if_type}, WIFI_IF_AP}; +STATIC const wlan_if_obj_t wlan_sta_obj = {{&esp_network_wlan_type}, WIFI_IF_STA}; +STATIC const wlan_if_obj_t wlan_ap_obj = {{&esp_network_wlan_type}, WIFI_IF_AP}; #endif // MICROPY_PY_NETWORK_WLAN diff --git a/ports/esp8266/modnetwork.h b/ports/esp8266/modnetwork.h index dc9203b0fb..5fd142e71e 100644 --- a/ports/esp8266/modnetwork.h +++ b/ports/esp8266/modnetwork.h @@ -1,2 +1,3 @@ -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_get_wlan_obj); +extern const mp_obj_type_t esp_network_wlan_type; + MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj); diff --git a/ports/esp8266/modnetwork_globals.h b/ports/esp8266/modnetwork_globals.h index f977cd14e4..1a04568024 100644 --- a/ports/esp8266/modnetwork_globals.h +++ b/ports/esp8266/modnetwork_globals.h @@ -1,4 +1,4 @@ -{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&esp_network_get_wlan_obj) }, +{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&esp_network_wlan_type) }, { MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_network_phy_mode_obj) }, { MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(STATION_IF)}, diff --git a/ports/esp8266/network_wlan.c b/ports/esp8266/network_wlan.c index 4ab4a9a002..348d7f6355 100644 --- a/ports/esp8266/network_wlan.c +++ b/ports/esp8266/network_wlan.c @@ -39,6 +39,7 @@ #include "spi_flash.h" #include "ets_alt_task.h" #include "lwip/dns.h" +#include "modnetwork.h" typedef struct _wlan_if_obj_t { mp_obj_base_t base; @@ -46,11 +47,10 @@ typedef struct _wlan_if_obj_t { } wlan_if_obj_t; void error_check(bool status, const char *msg); -const mp_obj_type_t wlan_if_type; STATIC const wlan_if_obj_t wlan_objs[] = { - {{&wlan_if_type}, STATION_IF}, - {{&wlan_if_type}, SOFTAP_IF}, + {{&esp_network_wlan_type}, STATION_IF}, + {{&esp_network_wlan_type}, SOFTAP_IF}, }; STATIC void require_if(mp_obj_t wlan_if, int if_no) { @@ -60,7 +60,8 @@ STATIC void require_if(mp_obj_t wlan_if, int if_no) { } } -STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t esp_wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 1, false); int idx = 0; if (n_args > 0) { idx = mp_obj_get_int(args[0]); @@ -70,7 +71,6 @@ STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) { } return MP_OBJ_FROM_PTR(&wlan_objs[idx]); } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_get_wlan_obj, 0, 1, get_wlan); STATIC mp_obj_t esp_active(size_t n_args, const mp_obj_t *args) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); @@ -529,9 +529,10 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( - wlan_if_type, + esp_network_wlan_type, MP_QSTR_WLAN, MP_TYPE_FLAG_NONE, + make_new, esp_wlan_make_new, locals_dict, &wlan_if_locals_dict ); From eaccaa36771f784dfb458b8ba3591f11513824e6 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 27 Dec 2022 16:30:05 -0600 Subject: [PATCH 075/565] py/obj: Remove mp_generic_unary_op(). Since converting to variable sized slots in mp_obj_type_t, we can now reduce the code size a bit by removing mp_generic_unary_op() and the corresponding slots where it is used. Instead we just implement the generic `__hash__` operation in the runtime. Signed-off-by: David Lechner --- py/obj.c | 9 --------- py/obj.h | 1 - py/objfun.c | 24 ++++++++---------------- py/objgenerator.c | 9 +++------ py/objnone.c | 3 +-- py/objsingleton.c | 3 +-- py/objtype.c | 1 - py/profile.c | 2 -- py/runtime.c | 3 +++ 9 files changed, 16 insertions(+), 39 deletions(-) diff --git a/py/obj.c b/py/obj.c index 3b0fd171cc..7e26d4c7fd 100644 --- a/py/obj.c +++ b/py/obj.c @@ -594,12 +594,3 @@ void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flag mp_raise_TypeError(MP_ERROR_TEXT("object with buffer protocol required")); } } - -mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in) { - switch (op) { - case MP_UNARY_OP_HASH: - return MP_OBJ_NEW_SMALL_INT((mp_uint_t)o_in); - default: - return MP_OBJ_NULL; // op not supported - } -} diff --git a/py/obj.h b/py/obj.h index d41511b0e9..04c153f501 100644 --- a/py/obj.h +++ b/py/obj.h @@ -1016,7 +1016,6 @@ mp_obj_t mp_obj_id(mp_obj_t o_in); mp_obj_t mp_obj_len(mp_obj_t o_in); mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val); -mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in); // cell diff --git a/py/objfun.c b/py/objfun.c index 390ddaa2d2..94b33cd5bd 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -58,8 +58,7 @@ STATIC mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw, MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_builtin_0, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - call, fun_builtin_0_call, - unary_op, mp_generic_unary_op + call, fun_builtin_0_call ); STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -71,8 +70,7 @@ STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_builtin_1, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - call, fun_builtin_1_call, - unary_op, mp_generic_unary_op + call, fun_builtin_1_call ); STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -84,8 +82,7 @@ STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_builtin_2, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - call, fun_builtin_2_call, - unary_op, mp_generic_unary_op + call, fun_builtin_2_call ); STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -97,8 +94,7 @@ STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_builtin_3, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - call, fun_builtin_3_call, - unary_op, mp_generic_unary_op + call, fun_builtin_3_call ); STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -126,8 +122,7 @@ STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_k MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_builtin_var, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - call, fun_builtin_var_call, - unary_op, mp_generic_unary_op + call, fun_builtin_var_call ); /******************************************************************************/ @@ -370,8 +365,7 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_TYPE_FLAG_BINDS_SELF, FUN_BC_TYPE_PRINT FUN_BC_TYPE_ATTR - call, fun_bc_call, - unary_op, mp_generic_unary_op + call, fun_bc_call ); mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_module_context_t *context, struct _mp_raw_code_t *const *child_table) { @@ -432,8 +426,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( MP_TYPE_FLAG_BINDS_SELF, FUN_BC_TYPE_PRINT FUN_BC_TYPE_ATTR - call, fun_native_call, - unary_op, mp_generic_unary_op + call, fun_native_call ); mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { @@ -540,8 +533,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_asm, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, - call, fun_asm_call, - unary_op, mp_generic_unary_op + call, fun_asm_call ); mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) { diff --git a/py/objgenerator.c b/py/objgenerator.c index 8175dbd683..ecd1f583ea 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -81,8 +81,7 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_QSTR_generator, MP_TYPE_FLAG_BINDS_SELF, GEN_WRAP_TYPE_ATTR - call, gen_wrap_call, - unary_op, mp_generic_unary_op + call, gen_wrap_call ); /******************************************************************************/ @@ -136,7 +135,7 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k } #if MICROPY_PY_FUNCTION_ATTRS -#define NATIVE_GEN_WRAP_TYPE_ATTR attr, mp_obj_fun_bc_attr, +#define NATIVE_GEN_WRAP_TYPE_ATTR , attr, mp_obj_fun_bc_attr #else #define NATIVE_GEN_WRAP_TYPE_ATTR #endif @@ -145,9 +144,8 @@ MP_DEFINE_CONST_OBJ_TYPE( mp_type_native_gen_wrap, MP_QSTR_generator, MP_TYPE_FLAG_BINDS_SELF, - call, native_gen_wrap_call, + call, native_gen_wrap_call NATIVE_GEN_WRAP_TYPE_ATTR - unary_op, mp_generic_unary_op ); #endif // MICROPY_EMIT_NATIVE @@ -370,7 +368,6 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_QSTR_generator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, print, gen_instance_print, - unary_op, mp_generic_unary_op, iter, gen_instance_iternext, locals_dict, &gen_instance_locals_dict ); diff --git a/py/objnone.c b/py/objnone.c index 4f8996e897..4b0696d3a1 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -47,8 +47,7 @@ MP_DEFINE_CONST_OBJ_TYPE( mp_type_NoneType, MP_QSTR_NoneType, MP_TYPE_FLAG_NONE, - print, none_print, - unary_op, mp_generic_unary_op + print, none_print ); #if !MICROPY_OBJ_IMMEDIATE_OBJS diff --git a/py/objsingleton.c b/py/objsingleton.c index dc73d28c27..6537676c52 100644 --- a/py/objsingleton.c +++ b/py/objsingleton.c @@ -45,8 +45,7 @@ STATIC void singleton_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ MP_DEFINE_CONST_OBJ_TYPE( mp_type_singleton, MP_QSTR_, MP_TYPE_FLAG_NONE, - print, singleton_print, - unary_op, mp_generic_unary_op + print, singleton_print ); const mp_obj_singleton_t mp_const_ellipsis_obj = {{&mp_type_singleton}, MP_QSTR_Ellipsis}; diff --git a/py/objtype.c b/py/objtype.c index 7f71968ea0..88d1c8ebe0 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -1112,7 +1112,6 @@ MP_DEFINE_CONST_OBJ_TYPE( make_new, type_make_new, print, type_print, call, type_call, - unary_op, mp_generic_unary_op, attr, type_attr ); diff --git a/py/profile.c b/py/profile.c index fd2d61caa9..89af8640a0 100644 --- a/py/profile.c +++ b/py/profile.c @@ -177,7 +177,6 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_QSTR_code, MP_TYPE_FLAG_NONE, print, code_print, - unary_op, mp_generic_unary_op, attr, code_attr ); @@ -247,7 +246,6 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_QSTR_frame, MP_TYPE_FLAG_NONE, print, frame_print, - unary_op, mp_generic_unary_op, attr, frame_attr ); diff --git a/py/runtime.c b/py/runtime.c index 3c7c0350c1..47e094763c 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -314,6 +314,9 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) { if (result != MP_OBJ_NULL) { return result; } + } else if (op == MP_UNARY_OP_HASH) { + // Type doesn't have unary_op so use hash of object instance. + return MP_OBJ_NEW_SMALL_INT((mp_uint_t)arg); } if (op == MP_UNARY_OP_BOOL) { // Type doesn't have unary_op (or didn't handle MP_UNARY_OP_BOOL), From 8491eb190f2ea27f113c0cc7c0e619807a84f7ed Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 12 Jan 2023 19:51:45 -0600 Subject: [PATCH 076/565] py/objslice: Ensure slice is not hashable. As per https://bugs.python.org/issue408326, the slice object should not be hashable. Since MicroPython has an implicit fallback when the unary_op slot is empty, we need to fill this slot. Signed-off-by: David Lechner --- py/objslice.c | 7 +++++++ tests/basics/slice_op.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/basics/slice_op.py diff --git a/py/objslice.c b/py/objslice.c index 01d4da0dbd..75fa3bc3f5 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -46,6 +46,12 @@ STATIC void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t mp_print_str(print, ")"); } +STATIC mp_obj_t slice_unary_op(mp_unary_op_t op, mp_obj_t o_in) { + // Needed to explicitly opt out of default __hash__. + // REVISIT: CPython implements comparison operators for slice. + return MP_OBJ_NULL; +} + #if MICROPY_PY_BUILTINS_SLICE_INDICES STATIC mp_obj_t slice_indices(mp_obj_t self_in, mp_obj_t length_obj) { mp_int_t length = mp_obj_int_get_checked(length_obj); @@ -104,6 +110,7 @@ MP_DEFINE_CONST_OBJ_TYPE( mp_type_slice, MP_QSTR_slice, MP_TYPE_FLAG_NONE, + unary_op, slice_unary_op, SLICE_TYPE_ATTR_OR_LOCALS_DICT print, slice_print ); diff --git a/tests/basics/slice_op.py b/tests/basics/slice_op.py new file mode 100644 index 0000000000..f1e83c5e27 --- /dev/null +++ b/tests/basics/slice_op.py @@ -0,0 +1,15 @@ + +try: + t = [][:] +except: + print("SKIP") + raise SystemExit + + +# REVISIT: slice comparison operators are not implemented in MicroPython + +# test that slice is not hashable, i.e. it can't be used to copy a dict +try: + {}[:] = {} +except TypeError: + print('TypeError') From 2fe6d4eb86a8496620a5db0958972ad5573932fb Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 18 Jan 2023 13:59:54 -0600 Subject: [PATCH 077/565] py/objdict: Fix __hash__ for dict_view types. This adds a unary_op implementation for the dict_view type that makes the implementation of `hash()` for these types compatible with CPython. Signed-off-by: David Lechner --- py/objdict.c | 10 ++++++++++ tests/basics/dict_views.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/py/objdict.c b/py/objdict.c index baad8a1b9e..a621c4feaf 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -515,6 +515,15 @@ STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ mp_print_str(print, "])"); } +STATIC mp_obj_t dict_view_unary_op(mp_unary_op_t op, mp_obj_t o_in) { + mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(o_in); + // only dict.values() supports __hash__. + if (op == MP_UNARY_OP_HASH && o->kind == MP_DICT_VIEW_VALUES) { + return MP_OBJ_NEW_SMALL_INT((mp_uint_t)o_in); + } + return MP_OBJ_NULL; +} + STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // only supported for the 'keys' kind until sets and dicts are refactored mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(lhs_in); @@ -532,6 +541,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( MP_QSTR_dict_view, MP_TYPE_FLAG_ITER_IS_GETITER, print, dict_view_print, + unary_op, dict_view_unary_op, binary_op, dict_view_binary_op, iter, dict_view_getiter ); diff --git a/tests/basics/dict_views.py b/tests/basics/dict_views.py index 7ebcc1f56d..a82f47b6be 100644 --- a/tests/basics/dict_views.py +++ b/tests/basics/dict_views.py @@ -18,4 +18,22 @@ try: except TypeError: print('TypeError') +# keys dict_view is not hashable + +try: + hash({}.keys()) +except TypeError: + print('TypeError') + +# values dict_view is hashable + +print(type(hash({}.values()))) + +# items dict_view is not hashable + +try: + hash({}.items()) +except TypeError: + print('TypeError') + # set operations still to come From 9accb7dd446f7f17720f574d0449c294c4df1685 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 19 May 2023 12:15:55 +1000 Subject: [PATCH 078/565] tests/basics: Add more tests for hashing of various types. Signed-off-by: Damien George --- tests/basics/builtin_compile.py | 3 +++ tests/basics/builtin_hash.py | 18 ++++++++++++++++++ tests/basics/io_buffered_writer.py | 3 +++ tests/basics/io_buffered_writer.py.exp | 1 + 4 files changed, 25 insertions(+) diff --git a/tests/basics/builtin_compile.py b/tests/basics/builtin_compile.py index a2f2cbe550..41dc746ad1 100644 --- a/tests/basics/builtin_compile.py +++ b/tests/basics/builtin_compile.py @@ -42,4 +42,7 @@ def test(): print("NameError") print(x) # check 'x' still exists as a global + # hashing a compiled function object + print(type(hash(compile("", "", "exec")))) + test() diff --git a/tests/basics/builtin_hash.py b/tests/basics/builtin_hash.py index 704895fbb6..89e1cfb47a 100644 --- a/tests/basics/builtin_hash.py +++ b/tests/basics/builtin_hash.py @@ -5,6 +5,24 @@ print(hash(True)) print({():1}) # hash tuple print({(1,):1}) # hash non-empty tuple print(hash in {hash:1}) # hash function +print(type(hash(list.pop))) # hash checked function (mp_type_checked_fun) +print(type(hash([].pop))) # hash bound method +print(type(hash(object()))) # hash object instance +print(type(hash(super(object, object)))) # hash super +print(type(hash(classmethod(hash)))) # hash classmethod +print(type(hash(staticmethod(hash)))) # hash staticmethod +print(type(hash(iter("")))) # hash string iterator +print(type(hash(iter(b"")))) # hash bytes iterator +print(type(hash(iter(range(0))))) # hash range iterator +print(type(hash(map(None, [])))) # hash map object +print(type(hash(zip([])))) # hash zip object + +def f(x): + def g(): + return x + return g + +print(type(hash(f(1)))) # hash closure try: hash([]) diff --git a/tests/basics/io_buffered_writer.py b/tests/basics/io_buffered_writer.py index c2cedb9912..0e943cb0a9 100644 --- a/tests/basics/io_buffered_writer.py +++ b/tests/basics/io_buffered_writer.py @@ -25,3 +25,6 @@ bts = io.BytesIO() buf = io.BufferedWriter(bts, 1) buf.write(b"foo") print(bts.getvalue()) + +# hashing a BufferedWriter +print(type(hash(buf))) diff --git a/tests/basics/io_buffered_writer.py.exp b/tests/basics/io_buffered_writer.py.exp index d086935a92..2209348f5a 100644 --- a/tests/basics/io_buffered_writer.py.exp +++ b/tests/basics/io_buffered_writer.py.exp @@ -3,3 +3,4 @@ b'foobarfo' b'foobarfoobar' b'foobarfoobar' b'foo' + From ca9068e0efc5e53ff7042ef68ad4a4ec9ff91915 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 12 May 2023 23:14:44 +1000 Subject: [PATCH 079/565] py/objarray: Disallow memoryview addition. Following CPython. This is important for subsequent commits to work correctly. Signed-off-by: Damien George --- py/objarray.c | 6 ++++++ tests/basics/op_error_memoryview.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/py/objarray.c b/py/objarray.c index 0d9411d7c4..a3adb255e8 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -292,6 +292,12 @@ STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs mp_obj_array_t *lhs = MP_OBJ_TO_PTR(lhs_in); switch (op) { case MP_BINARY_OP_ADD: { + #if MICROPY_PY_BUILTINS_MEMORYVIEW + if (lhs->base.type == &mp_type_memoryview) { + return MP_OBJ_NULL; // op not supported + } + #endif + // allow to add anything that has the buffer protocol (extension to CPython) mp_buffer_info_t lhs_bufinfo; mp_buffer_info_t rhs_bufinfo; diff --git a/tests/basics/op_error_memoryview.py b/tests/basics/op_error_memoryview.py index 233f7f9ab7..4853704289 100644 --- a/tests/basics/op_error_memoryview.py +++ b/tests/basics/op_error_memoryview.py @@ -6,8 +6,18 @@ except: raise SystemExit # unsupported binary operators +try: + memoryview(b"") + b"" +except TypeError: + print("TypeError") + +try: + memoryview(b"") + memoryview(b"") +except TypeError: + print("TypeError") + try: m = memoryview(bytearray()) m += bytearray() except TypeError: - print('TypeError') + print("TypeError") From 4b57330465b98df30ef8a10e19a0e197b5797550 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 12 May 2023 23:17:20 +1000 Subject: [PATCH 080/565] py/objstr: Return unsupported binop instead of raising TypeError. So that user types can implement reverse operators and have them work with str on the left-hand-side, eg `"a" + UserType()`. Signed-off-by: Damien George --- py/objstr.c | 11 ++++++++++- tests/basics/class_reverse_op.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/py/objstr.c b/py/objstr.c index 4d9dca04af..e6c5ee71cf 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -403,7 +403,16 @@ mp_obj_t mp_obj_str_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i } else { // LHS is str and RHS has an incompatible type // (except if operation is EQUAL, but that's handled by mp_obj_equal) - bad_implicit_conversion(rhs_in); + + // CONTAINS must fail with a bad-implicit-conversion exception, because + // otherwise mp_binary_op() will fallback to `list(lhs).__contains__(rhs)`. + if (op == MP_BINARY_OP_CONTAINS) { + bad_implicit_conversion(rhs_in); + } + + // All other operations are not supported, and may be handled by another + // type, eg for reverse operations. + return MP_OBJ_NULL; } switch (op) { diff --git a/tests/basics/class_reverse_op.py b/tests/basics/class_reverse_op.py index b0dae5f8a3..11aba6aada 100644 --- a/tests/basics/class_reverse_op.py +++ b/tests/basics/class_reverse_op.py @@ -1,5 +1,7 @@ -class A: +# Test reverse operators. +# Test user type with integers. +class A: def __init__(self, v): self.v = v @@ -14,5 +16,33 @@ class A: def __repr__(self): return "A({})".format(self.v) + print(A(3) + 1) print(2 + A(5)) + + +# Test user type with strings. +class B: + def __init__(self, v): + self.v = v + + def __repr__(self): + return "B({})".format(self.v) + + def __ror__(self, o): + return B(o + "|" + self.v) + + def __radd__(self, o): + return B(o + "+" + self.v) + + def __rmul__(self, o): + return B(o + "*" + self.v) + + def __rtruediv__(self, o): + return B(o + "/" + self.v) + + +print("a" | B("b")) +print("a" + B("b")) +print("a" * B("b")) +print("a" / B("b")) From ea7031faff9efe6803d8a8f67ad2e3b4a6d390e3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 12 May 2023 23:16:37 +1000 Subject: [PATCH 081/565] py/runtime: If inplace binop fails then try corresponding normal binop. The code that handles inplace-operator to normal-binary-operator fallback is moved in this commit from py/objtype.c to py/runtime.c, making it apply to all types, not just user classes. Signed-off-by: Damien George --- py/objtype.c | 13 +------------ py/runtime.c | 9 +++++++++ tests/basics/class_reverse_op.py | 5 +++++ tests/basics/list_mult.py | 10 ++++++++++ tests/basics/string_mult.py | 10 ++++++++++ 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/py/objtype.c b/py/objtype.c index 88d1c8ebe0..04bdf5acd7 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -534,7 +534,6 @@ STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t // Note: For ducktyping, CPython does not look in the instance members or use // __getattr__ or __getattribute__. It only looks in the class dictionary. mp_obj_instance_t *lhs = MP_OBJ_TO_PTR(lhs_in); -retry:; qstr op_name = mp_binary_op_method_name[op]; /* Still try to lookup native slot if (op_name == 0) { @@ -559,22 +558,12 @@ retry:; res = mp_call_method_n_kw(1, 0, dest); res = op == MP_BINARY_OP_CONTAINS ? mp_obj_new_bool(mp_obj_is_true(res)) : res; } else { - // If this was an inplace method, fallback to normal method - // https://docs.python.org/3/reference/datamodel.html#object.__iadd__ : - // "If a specific method is not defined, the augmented assignment - // falls back to the normal methods." - if (op >= MP_BINARY_OP_INPLACE_OR && op <= MP_BINARY_OP_INPLACE_POWER) { - op -= MP_BINARY_OP_INPLACE_OR - MP_BINARY_OP_OR; - goto retry; - } return MP_OBJ_NULL; // op not supported } #if MICROPY_PY_BUILTINS_NOTIMPLEMENTED // NotImplemented means "try other fallbacks (like calling __rop__ - // instead of __op__) and if nothing works, raise TypeError". As - // MicroPython doesn't implement any fallbacks, signal to raise - // TypeError right away. + // instead of __op__) and if nothing works, raise TypeError". if (res == mp_const_notimplemented) { return MP_OBJ_NULL; // op not supported } diff --git a/py/runtime.c b/py/runtime.c index 47e094763c..3434d9cc48 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -625,6 +625,15 @@ generic_binary_op: } } + // If this was an inplace method, fallback to the corresponding normal method. + // https://docs.python.org/3/reference/datamodel.html#object.__iadd__ : + // "If a specific method is not defined, the augmented assignment falls back + // to the normal methods." + if (op >= MP_BINARY_OP_INPLACE_OR && op <= MP_BINARY_OP_INPLACE_POWER) { + op += MP_BINARY_OP_OR - MP_BINARY_OP_INPLACE_OR; + goto generic_binary_op; + } + #if MICROPY_PY_REVERSE_SPECIAL_METHODS if (op >= MP_BINARY_OP_OR && op <= MP_BINARY_OP_POWER) { mp_obj_t t = rhs; diff --git a/tests/basics/class_reverse_op.py b/tests/basics/class_reverse_op.py index 11aba6aada..915b3a9ef3 100644 --- a/tests/basics/class_reverse_op.py +++ b/tests/basics/class_reverse_op.py @@ -46,3 +46,8 @@ print("a" | B("b")) print("a" + B("b")) print("a" * B("b")) print("a" / B("b")) + +x = "a"; x |= B("b"); print(x) +x = "a"; x += B("b"); print(x) +x = "a"; x *= B("b"); print(x) +x = "a"; x /= B("b"); print(x) diff --git a/tests/basics/list_mult.py b/tests/basics/list_mult.py index 548f88534e..125c548eec 100644 --- a/tests/basics/list_mult.py +++ b/tests/basics/list_mult.py @@ -11,6 +11,16 @@ a = [1, 2, 3] c = a * 3 print(a, c) +# check inplace multiplication +a = [4, 5, 6] +a *= 3 +print(a) + +# check reverse inplace multiplication +a = 3 +a *= [7, 8, 9] +print(a) + # unsupported type on RHS try: [] * None diff --git a/tests/basics/string_mult.py b/tests/basics/string_mult.py index c0713c1d3a..5a7d822947 100644 --- a/tests/basics/string_mult.py +++ b/tests/basics/string_mult.py @@ -10,3 +10,13 @@ for i in (-4, -2, 0, 2, 4): a = '123' c = a * 3 print(a, c) + +# check inplace multiplication +a = '456' +a *= 3 +print(a) + +# check reverse inplace multiplication +a = 3 +a *= '789' +print(a) From 12dbbc8065e1073ffa1bb038f0cdc24101f69bc4 Mon Sep 17 00:00:00 2001 From: glenn20 Date: Wed, 10 May 2023 13:06:52 +1000 Subject: [PATCH 082/565] docs/library/espnow: Update espnow docs for WLAN.config(pm=x) options. Update docs/library/espnow.rst to add: - guidance on using WLAN.config(pm=WLAN.PM_NONE) for reliable espnow performance while also connected to a wifi access point; - guidance on receiving encrypted messages; - correction for default value of "encrypt" parameter (add_peer()); - guidance on use of ESPNow.irq(): recommand users readout all messages in the buffer each time the callback is called. Signed-off-by: Glenn Moloney --- docs/library/espnow.rst | 89 +++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/docs/library/espnow.rst b/docs/library/espnow.rst index 468eb38418..f821de59aa 100644 --- a/docs/library/espnow.rst +++ b/docs/library/espnow.rst @@ -110,14 +110,14 @@ Configuration .. method:: ESPNow.active([flag]) - Initialise or de-initialise the ESPNow communication protocol depending on + Initialise or de-initialise the ESP-NOW communication protocol depending on the value of the ``flag`` optional argument. .. data:: Arguments: - *flag*: Any python value which can be converted to a boolean type. - - ``True``: Prepare the software and hardware for use of the ESPNow + - ``True``: Prepare the software and hardware for use of the ESP-NOW communication protocol, including: - initialise the ESPNow data structures, @@ -125,7 +125,7 @@ Configuration - invoke esp_now_init() and - register the send and recv callbacks. - - ``False``: De-initialise the Espressif ESPNow software stack + - ``False``: De-initialise the Espressif ESP-NOW software stack (esp_now_deinit()), disable callbacks, deallocate the recv data buffer and deregister all peers. @@ -160,12 +160,12 @@ Configuration `ESPNow.active(True)`. *timeout_ms*: (default=300,000) Default timeout (in milliseconds) - for receiving ESPNOW messages. If *timeout_ms* is less than zero, then + for receiving ESPNow messages. If *timeout_ms* is less than zero, then wait forever. The timeout can also be provided as arg to `recv()`/`irecv()`/`recvinto()`. *rate*: (ESP32 only, IDF>=4.3.0 only) Set the transmission speed for - espnow packets. Must be set to a number from the allowed numeric values + ESPNow packets. Must be set to a number from the allowed numeric values in `enum wifi_phy_rate_t `_. @@ -243,8 +243,8 @@ after reboot/reset). This reduces the reliability of receiving ESP-NOW messages **Note**: A peer will respond with success if its wifi interface is `active()` and set to the same channel as the sender, - regardless of whether it has initialised it's ESP-Now system or is - actively listening for ESP-Now traffic (see the Espressif ESP-Now docs). + regardless of whether it has initialised it's ESP-NOW system or is + actively listening for ESP-NOW traffic (see the Espressif ESP-NOW docs). .. method:: ESPNow.recv([timeout_ms]) @@ -383,15 +383,21 @@ after reboot/reset). This reduces the reliability of receiving ESP-NOW messages Peer Management --------------- -The Espressif ESP-Now software requires that other devices (peers) must be -*registered* before we can `send()` them messages. It is -**not** necessary to *register* a peer to receive a message from that peer. +On ESP32 devices, the Espressif ESP-NOW software requires that other devices +(peers) must be *registered* using `add_peer()` before we can +`send()` them messages (this is *not* enforced on ESP8266 +devices). It is **not** necessary to register a peer to receive an +un-encrypted message from that peer. + +**Encrypted messages**: To receive an *encrypted* message, the receiving device +must first register the sender and use the same encryption keys as the sender +(PMK and LMK) (see `set_pmk()` and `add_peer()`. .. method:: ESPNow.set_pmk(pmk) Set the Primary Master Key (PMK) which is used to encrypt the Local Master - Keys (LMK) for encrypting ESPNow data traffic. If this is not set, a - default PMK is used by the underlying Espressif esp_now software stack. + Keys (LMK) for encrypting messages. If this is not set, a default PMK is + used by the underlying Espressif ESP-NOW software stack. **Note:** messages will only be encrypted if *lmk* is also set in `ESPNow.add_peer()` (see `Security @@ -415,8 +421,9 @@ The Espressif ESP-Now software requires that other devices (peers) must be .. method:: ESPNow.add_peer(mac, [lmk], [channel], [ifidx], [encrypt]) ESPNow.add_peer(mac, param=value, ...) (ESP32 only) - Add/register the provided *mac* address as a peer. Additional parameters - may also be specified as positional or keyword arguments: + Add/register the provided *mac* address as a peer. Additional parameters may + also be specified as positional or keyword arguments (any parameter set to + ``None`` will be set to it's default value): .. data:: Arguments: @@ -444,7 +451,7 @@ The Espressif ESP-Now software requires that other devices (peers) must be - *encrypt*: (ESP32 only) If set to ``True`` data exchanged with this peer will be encrypted with the PMK and LMK. (default = - ``False``) + ``True`` if *lmk* is set to a valid key, else ``False``) **ESP8266**: Keyword args may not be used on the ESP8266. @@ -515,7 +522,8 @@ The Espressif ESP-Now software requires that other devices (peers) must be Modify the parameters of the peer associated with the provided *mac* address. Parameters may be provided as positional or keyword arguments - (see `ESPNow.add_peer()`). + (see `ESPNow.add_peer()`). Any parameter that is not set (or set to + ``None``) will retain the existing value for that parameter. Callback Methods ---------------- @@ -524,14 +532,20 @@ Callback Methods Set a callback function to be called *as soon as possible* after a message has been received from another ESPNow device. The callback function will be called - with the `ESPNow` instance object as an argument, eg: :: + with the `ESPNow` instance object as an argument. For more reliable operation, + it is recommended to read out as many messages as are available when the + callback is invoked and to set the read timeout to zero, eg: :: - def recv_cb(e): - print(e.irecv(0)) - e.irq(recv_cb) + def recv_cb(e): + while True: # Read out all messages waiting in the buffer + mac, msg = e.irecv(0) # Don't wait if no messages left + if mac is None: + return + print(mac, msg) + e.irq(recv_cb) The `irq()` callback method is an alternative method for - processing incoming espnow messages, especially if the data rate is moderate + processing incoming messages, especially if the data rate is moderate and the device is *not too busy* but there are some caveats: - The scheduler stack *can* overflow and callbacks will be missed if @@ -556,11 +570,11 @@ Constants Exceptions ---------- -If the underlying Espressif ESPNow software stack returns an error code, -the MicroPython ESPNow module will raise an ``OSError(errnum, errstring)`` +If the underlying Espressif ESP-NOW software stack returns an error code, +the MicroPython espnow module will raise an ``OSError(errnum, errstring)`` exception where ``errstring`` is set to the name of one of the error codes identified in the -`Espressif ESP-Now docs +`Espressif ESP-NOW docs `_. For example:: @@ -705,12 +719,12 @@ A small async server example:: Broadcast and Multicast ----------------------- -All active ESP-Now clients will receive messages sent to their MAC address and +All active ESPNow clients will receive messages sent to their MAC address and all devices (**except ESP8266 devices**) will also receive messages sent to the *broadcast* MAC address (``b'\xff\xff\xff\xff\xff\xff'``) or any multicast MAC address. -All ESP-Now devices (including ESP8266 devices) can also send messages to the +All ESPNow devices (including ESP8266 devices) can also send messages to the broadcast MAC address or any multicast MAC address. To `send()` a broadcast message, the broadcast (or @@ -739,7 +753,8 @@ point. When an ESP32 or ESP8266 device connects to a Wifi Access Point (see `ESP32 Quickref <../esp32/quickref.html#networking>`__) the following things happen which affect ESPNow communications: -1. Wifi Power-saving Mode is automatically activated and +1. Wifi Power-saving Mode (`network.WLAN.PM_PERFORMANCE`) + is automatically activated and 2. The radio on the esp device changes wifi ``channel`` to match the channel used by the Access Point. @@ -750,27 +765,31 @@ device to turn off the radio periodically (typically for hundreds of milliseconds), making it unreliable in receiving ESPNow messages. This can be resolved by either of: -1. Turning on the AP_IF interface, which will disable the power saving mode. +1. Disabling the power-saving mode on the STA_IF interface; + + - Use ``sta.config(pm=sta.PM_NONE)`` + +2. Turning on the AP_IF interface, which will disable the power saving mode. However, the device will then be advertising an active wifi access point. - You **may** also choose to send your messages via the AP_IF interface, but this is not necessary. - ESP8266 peers must send messages to this AP_IF interface (see below). -2. Configuring ESPNow clients to retry sending messages. +3. Configuring ESPNow clients to retry sending messages. **Receiving messages from an ESP8266 device:** Strangely, an ESP32 device -connected to a wifi network using method 1 or 2 above, will receive ESP-Now +connected to a wifi network using method 1 or 2 above, will receive ESPNow messages sent to the STA_IF MAC address from another ESP32 device, but will **reject** messages from an ESP8266 device!!!. To receive messages from an ESP8266 device, the AP_IF interface must be set to ``active(True)`` **and** messages must be sent to the AP_IF MAC address. -**Managing wifi channels:** Any other espnow devices wishing to communicate with +**Managing wifi channels:** Any other ESPNow devices wishing to communicate with a device which is also connected to a Wifi Access Point MUST use the same -channel. A common scenario is where one espnow device is connected to a wifi +channel. A common scenario is where one ESPNow device is connected to a wifi router and acts as a proxy for messages from a group of sensors connected via -espnow: +ESPNow: **Proxy:** :: @@ -780,7 +799,7 @@ espnow: sta.connect('myssid', 'mypassword') while not sta.isconnected(): # Wait until connected... time.sleep(0.1) - ap.active(True) # Disable power-saving mode + sta.config(pm=sta.PM_NONE) # ..then disable power saving # Print the wifi channel used AFTER finished connecting to access point print("Proxy running on channel:", sta.config("channel")) @@ -850,7 +869,7 @@ Other issues to take care with when using ESPNow with wifi are: - **MicroPython re-scans wifi channels when trying to reconnect:** If the esp device is connected to a Wifi Access Point that goes down, MicroPython will automatically start scanning channels in an attempt to reconnect to the - Access Point. This means espnow messages will be lost while scanning for the + Access Point. This means ESPNow messages will be lost while scanning for the AP. This can be disabled by ``sta.config(reconnects=0)``, which will also disable the automatic reconnection after losing connection. From b5c81f6bfbd77ab5b0c3590d6ea7a6a3bb1e12f2 Mon Sep 17 00:00:00 2001 From: marble Date: Fri, 14 Apr 2023 18:31:22 +0200 Subject: [PATCH 083/565] docs/develop/porting: Add missing code to example main.c and Makefile. These two missing lines caused the build process to fail when implementing the tutorial example port. Signed-off-by: marble --- docs/develop/porting.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/develop/porting.rst b/docs/develop/porting.rst index 74974a39e1..fab8a751b8 100644 --- a/docs/develop/porting.rst +++ b/docs/develop/porting.rst @@ -38,6 +38,7 @@ The basic MicroPython firmware is implemented in the main port file, e.g ``main. .. code-block:: c + #include "py/builtin.h" #include "py/compile.h" #include "py/gc.h" #include "py/mperrno.h" @@ -110,6 +111,9 @@ We also need a Makefile at this point for the port: shared/runtime/pyexec.c \ shared/runtime/stdout_helpers.c \ + # Define source files containung qstrs. + SRC_QSTR += shared/readline/readline.c shared/runtime/pyexec.c + # Define the required object files. OBJ = $(PY_CORE_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) From 46d070bfeeda5926e222a49be02196cf7e8f69a8 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 16 May 2023 17:24:26 +1000 Subject: [PATCH 084/565] tools/manifestfile.py: Fix license capturing. The license field was incorrectly being set to the version. Signed-off-by: Jim Mussared --- tools/manifestfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/manifestfile.py b/tools/manifestfile.py index f9b8a70357..3b613d9e1d 100644 --- a/tools/manifestfile.py +++ b/tools/manifestfile.py @@ -143,7 +143,7 @@ class ManifestPackageMetadata: self.description = description self.version = version - self.license = version + self.license = license self.author = author self.pypi = pypi self.pypi_publish = pypi_publish From 978829fcd6a6cae2a004fc1425f968c3b6a093c7 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Fri, 12 May 2023 16:26:48 -0500 Subject: [PATCH 085/565] shared/upytesthelper: Fix spelling of "default". Signed-off-by: David Lechner --- shared/upytesthelper/upytesthelper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/upytesthelper/upytesthelper.c b/shared/upytesthelper/upytesthelper.c index 9553ff468e..12fa8276b0 100644 --- a/shared/upytesthelper/upytesthelper.c +++ b/shared/upytesthelper/upytesthelper.c @@ -61,7 +61,7 @@ bool upytest_is_failed(void) { // MP_PLAT_PRINT_STRN() should be redirected to this function. // It will pass-through any content to mp_hal_stdout_tx_strn_cooked() -// (the dfault value of MP_PLAT_PRINT_STRN), but will also match +// (the default value of MP_PLAT_PRINT_STRN), but will also match // it to the expected output as set by upytest_set_expected_output(). // If mismatch happens, upytest_is_failed() returns true. void upytest_output(const char *str, mp_uint_t len) { From a9fc0343f08287ba3cb51c231507583770ae5dfe Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Thu, 20 Apr 2023 18:20:37 -0400 Subject: [PATCH 086/565] extmod/vfs_lfsx: Fix offset used before range check. Use of offset 'from' should follow the range check. Signed-off-by: Mingjie Shen --- extmod/vfs_lfsx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c index de1f421977..fe0731eced 100644 --- a/extmod/vfs_lfsx.c +++ b/extmod/vfs_lfsx.c @@ -323,7 +323,7 @@ STATIC mp_obj_t MP_VFS_LFSx(chdir)(mp_obj_t self_in, mp_obj_t path_in) { size_t from = 1; char *cwd = vstr_str(&self->cur_dir); while (from < CWD_LEN) { - for (; cwd[from] == '/' && from < CWD_LEN; ++from) { + for (; from < CWD_LEN && cwd[from] == '/'; ++from) { // Scan for the start } if (from > to) { @@ -331,7 +331,7 @@ STATIC mp_obj_t MP_VFS_LFSx(chdir)(mp_obj_t self_in, mp_obj_t path_in) { vstr_cut_out_bytes(&self->cur_dir, to, from - to); from = to; } - for (; cwd[from] != '/' && from < CWD_LEN; ++from) { + for (; from < CWD_LEN && cwd[from] != '/'; ++from) { // Scan for the next / } if ((from - to) == 1 && cwd[to] == '.') { From 1ecc54888fde25f63cb26740a000bbadf0d4b199 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 15 May 2023 23:08:41 -0700 Subject: [PATCH 087/565] extmod/extmod.mk: Suppress deprecated-non-prototype warning. Signed-off-by: Chris Wilson --- extmod/extmod.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 40f4237ce4..ee9372e18d 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -294,7 +294,7 @@ SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\ CFLAGS_EXTMOD += -DMICROPY_PY_BTREE=1 # we need to suppress certain warnings to get berkeley-db to compile cleanly # and we have separate BTREE_DEFS so the definitions don't interfere with other source code -$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS) +$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-unknown-warning-option $(BTREE_DEFS) $(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS) endif From ad216be5f13ac86e67cafa6257aea5d6e7f82cda Mon Sep 17 00:00:00 2001 From: brave ulysses Date: Sat, 29 Apr 2023 08:08:43 -0500 Subject: [PATCH 088/565] stm32/boards/stm32h723_af.csv: Fix ADC AF definitions. These were incorrectly added in d995c010428420c7690d5cd59b9580c3f4f9649a. The fix here includes the full differential ADC definitions. Signed-off-by: brave ulysses --- ports/stm32/boards/stm32h723_af.csv | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/ports/stm32/boards/stm32h723_af.csv b/ports/stm32/boards/stm32h723_af.csv index fe16b378df..701e9381b2 100644 --- a/ports/stm32/boards/stm32h723_af.csv +++ b/ports/stm32/boards/stm32h723_af.csv @@ -1,13 +1,13 @@ Port,,AF0,AF1,AF2,AF3,AF4,AF5,AF6,AF7,AF8,AF9,AF10,AF11,AF12,AF13,AF14,AF15, ,,SYS,FMC/LPTIM1/SAI4/TIM16/17/TIM1x/TIM2x,FDCAN3/PDM_SAI1/TIM3/4/5/12/15,DFSDM1/LCD/LPTIM2/3/4/5/LPUART1/OCTOSPIM_P1/2/TIM8,CEC/DCMI/PSSI/DFSDM1/I2C1/2/3/4/5/LPTIM2/OCTOSPIM_P1/TIM15/USART1/10,CEC/FDCAN3/SPI1/I2S1/SPI2/I2S2/SPI3/I2S3/SPI4/5/6,DFSDM1/I2C4/5/OCTOSPIM_P1/SAI1/SPI3/I2S3/UART4,SDMMC1/SPI2/I2S2/SPI3/I2S3/SPI6/UART7/USART1/2/3/6,LPUART1/SAI4/SDMMC1/SPDIFRX1/SPI6/UART4/5/8,FDCAN1/2/FMC/LCD/OCTOSPIM_P1/2/SAI4/SDMMC2/SPDIFRX1/TIM13/14,CRS/FMC/LCD/OCTOSPIM_P1/OTG1_FS/OTG1_HS/SAI4/SDMMC2/TIM8,DFSDM1/ETH/I2C4/LCD/MDIOS/OCTOSPIM_P1/SDMMC2/SWPMI1/TIM1x/TIM8/UART7/9/USART10,FMC/LCD/MDIOS/OCTOSPIM_P1/SDMMC1/TIM1x/TIM8,COMP/DCMI/PSSI/LCD/TIM1x/TIM23,LCD/TIM24/UART5,SYS,ADC -PortA,PA0,,TIM2_CH1/TIM2_ETR,TIM5_CH1,TIM8_ETR,TIM15_BKIN,SPI6_NSS/I2S6_WS,,USART2_CTS/USART2_NSS,UART4_TX,SDMMC2_CMD,SAI4_SD_B,ETH_MII_CRS,FMC_A19,,,EVENTOUT,ADC123_IN0 -PortA,PA1,,TIM2_CH2,TIM5_CH2,LPTIM3_OUT,TIM15_CH1N,,,USART2_RTS/USART2_DE,UART4_RX,OCTOSPIM_P1_IO3,SAI4_MCLK_B,ETH_MII_RX_CLK/ETH_RMII_REF_CLK,OCTOSPIM_P1_DQS,,LCD_R2,EVENTOUT,ADC123_IN1 -PortA,PA2,,TIM2_CH3,TIM5_CH3,LPTIM4_OUT,TIM15_CH1,,OCTOSPIM_P1_IO0,USART2_TX,SAI4_SCK_B,,,ETH_MDIO,MDIOS_MDIO,,LCD_R1,EVENTOUT,ADC123_IN2 -PortA,PA3,,TIM2_CH4,TIM5_CH4,LPTIM5_OUT,TIM15_CH2,I2S6_MCK,OCTOSPIM_P1_IO2,USART2_RX,,LCD_B2,OTG_HS_ULPI_D0,ETH_MII_COL,OCTOSPIM_P1_CLK,,LCD_B5,EVENTOUT,ADC123_IN3 -PortA,PA4,D1PWREN,,TIM5_ETR,,,SPI1_NSS/I2S1_WS,SPI3_NSS/I2S3_WS,USART2_CK,SPI6_NSS/I2S6_WS,,,,FMC_D8/FMC_AD8,DCMI_HSYNC/PSSI_DE,LCD_VSYNC,EVENTOUT,ADC12_IN4 -PortA,PA5,D2PWREN,TIM2_CH1/TIM2_ETR,,TIM8_CH1N,,SPI1_SCK/I2S1_CK,,,SPI6_SCK/I2S6_CK,,OTG_HS_ULPI_CK,,FMC_D9/FMC_AD9,PSSI_D14,LCD_R4,EVENTOUT,ADC12_IN5 -PortA,PA6,,TIM1_BKIN,TIM3_CH1,TIM8_BKIN,,SPI1_MISO/I2S1_SDI,OCTOSPIM_P1_IO3,,SPI6_MISO/I2S6_SDI,TIM13_CH1,TIM8_BKIN_COMP12,MDIOS_MDC,TIM1_BKIN_COMP12,DCMI_PIXCLK/PSSI_PDCK,LCD_G2,EVENTOUT,ADC12_IN6 -PortA,PA7,,TIM1_CH1N,TIM3_CH2,TIM8_CH1N,,SPI1_MOSI/I2S1_SDO,,,SPI6_MOSI/I2S6_SDO,TIM14_CH1,OCTOSPIM_P1_IO2,ETH_MII_RX_DV/ETH_RMII_CRS_DV,FMC_SDNWE,,LCD_VSYNC,EVENTOUT,ADC12_IN7 +PortA,PA0,,TIM2_CH1/TIM2_ETR,TIM5_CH1,TIM8_ETR,TIM15_BKIN,SPI6_NSS/I2S6_WS,,USART2_CTS/USART2_NSS,UART4_TX,SDMMC2_CMD,SAI4_SD_B,ETH_MII_CRS,FMC_A19,,,EVENTOUT,ADC1_INP16 +PortA,PA1,,TIM2_CH2,TIM5_CH2,LPTIM3_OUT,TIM15_CH1N,,,USART2_RTS/USART2_DE,UART4_RX,OCTOSPIM_P1_IO3,SAI4_MCLK_B,ETH_MII_RX_CLK/ETH_RMII_REF_CLK,OCTOSPIM_P1_DQS,,LCD_R2,EVENTOUT,ADC1_INP17/ADC1_INN16 +PortA,PA2,,TIM2_CH3,TIM5_CH3,LPTIM4_OUT,TIM15_CH1,,OCTOSPIM_P1_IO0,USART2_TX,SAI4_SCK_B,,,ETH_MDIO,MDIOS_MDIO,,LCD_R1,EVENTOUT,ADC12_INP14 +PortA,PA3,,TIM2_CH4,TIM5_CH4,LPTIM5_OUT,TIM15_CH2,I2S6_MCK,OCTOSPIM_P1_IO2,USART2_RX,,LCD_B2,OTG_HS_ULPI_D0,ETH_MII_COL,OCTOSPIM_P1_CLK,,LCD_B5,EVENTOUT,ADC12_INP15 +PortA,PA4,D1PWREN,,TIM5_ETR,,,SPI1_NSS/I2S1_WS,SPI3_NSS/I2S3_WS,USART2_CK,SPI6_NSS/I2S6_WS,,,,FMC_D8/FMC_AD8,DCMI_HSYNC/PSSI_DE,LCD_VSYNC,EVENTOUT,ADC12_INP18 +PortA,PA5,D2PWREN,TIM2_CH1/TIM2_ETR,,TIM8_CH1N,,SPI1_SCK/I2S1_CK,,,SPI6_SCK/I2S6_CK,,OTG_HS_ULPI_CK,,FMC_D9/FMC_AD9,PSSI_D14,LCD_R4,EVENTOUT,ADC12_INP19/ADC12_INN18 +PortA,PA6,,TIM1_BKIN,TIM3_CH1,TIM8_BKIN,,SPI1_MISO/I2S1_SDI,OCTOSPIM_P1_IO3,,SPI6_MISO/I2S6_SDI,TIM13_CH1,TIM8_BKIN_COMP12,MDIOS_MDC,TIM1_BKIN_COMP12,DCMI_PIXCLK/PSSI_PDCK,LCD_G2,EVENTOUT,ADC12_INP3 +PortA,PA7,,TIM1_CH1N,TIM3_CH2,TIM8_CH1N,,SPI1_MOSI/I2S1_SDO,,,SPI6_MOSI/I2S6_SDO,TIM14_CH1,OCTOSPIM_P1_IO2,ETH_MII_RX_DV/ETH_RMII_CRS_DV,FMC_SDNWE,,LCD_VSYNC,EVENTOUT,ADC12_INP7/ADC12_INN3 PortA,PA8,MCO1,TIM1_CH1,,TIM8_BKIN2,I2C3_SCL,,I2C5_SCL,USART1_CK,,,OTG_HS_SOF,UART7_RX,TIM8_BKIN2_COMP12,LCD_B3,LCD_R6,EVENTOUT, PortA,PA9,,TIM1_CH2,,LPUART1_TX,I2C3_SMBA,SPI2_SCK/I2S2_CK,I2C5_SMBA,USART1_TX,,,,ETH_TX_ER,,DCMI_D0/PSSI_D0,LCD_R5,EVENTOUT, PortA,PA10,,TIM1_CH3,,LPUART1_RX,,,,USART1_RX,,,OTG_HS_ID,MDIOS_MDIO,LCD_B4,DCMI_D1/PSSI_D1,LCD_B1,EVENTOUT, @@ -16,8 +16,8 @@ PortA,PA12,,TIM1_ETR,,LPUART1_RTS/LPUART1_DE,,SPI2_SCK/I2S2_CK,UART4_TX,USART1_R PortA,PA13,JTMS/SWDIO,,,,,,,,,,,,,,,EVENTOUT, PortA,PA14,JTCK/SWCLK,,,,,,,,,,,,,,,EVENTOUT, PortA,PA15,JTDI,TIM2_CH1/TIM2_ETR,,,CEC,SPI1_NSS/I2S1_WS,SPI3_NSS/I2S3_WS,SPI6_NSS/I2S6_WS,UART4_RTS/UART4_DE,LCD_R3,,UART7_TX,,,LCD_B6,EVENTOUT, -PortB,PB0,,TIM1_CH2N,TIM3_CH3,TIM8_CH2N,OCTOSPIM_P1_IO1,,DFSDM1_CKOUT,,UART4_CTS,LCD_R3,OTG_HS_ULPI_D1,ETH_MII_RXD2,,,LCD_G1,EVENTOUT,ADC12_IN8 -PortB,PB1,,TIM1_CH3N,TIM3_CH4,TIM8_CH3N,OCTOSPIM_P1_IO0,,DFSDM1_DATIN1,,,LCD_R6,OTG_HS_ULPI_D2,ETH_MII_RXD3,,,LCD_G0,EVENTOUT,ADC12_IN9 +PortB,PB0,,TIM1_CH2N,TIM3_CH3,TIM8_CH2N,OCTOSPIM_P1_IO1,,DFSDM1_CKOUT,,UART4_CTS,LCD_R3,OTG_HS_ULPI_D1,ETH_MII_RXD2,,,LCD_G1,EVENTOUT,ADC12_INP9/ADC12_INN5 +PortB,PB1,,TIM1_CH3N,TIM3_CH4,TIM8_CH3N,OCTOSPIM_P1_IO0,,DFSDM1_DATIN1,,,LCD_R6,OTG_HS_ULPI_D2,ETH_MII_RXD3,,,LCD_G0,EVENTOUT,ADC12_INP5 PortB,PB2,RTC_OUT,SAI4_D1,SAI1_D1,,DFSDM1_CKIN1,,SAI1_SD_A,SPI3_MOSI/I2S3_SDO,SAI4_SD_A,OCTOSPIM_P1_CLK,OCTOSPIM_P1_DQS,ETH_TX_ER,,TIM23_ETR,,EVENTOUT, PortB,PB3,JTDO/TRACESWO,TIM2_CH2,,,,SPI1_SCK/I2S1_CK,SPI3_SCK/I2S3_CK,,SPI6_SCK/I2S6_CK,SDMMC2_D2,CRS_SYNC,UART7_RX,,,TIM24_ETR,EVENTOUT, PortB,PB4,NJTRST,TIM16_BKIN,TIM3_CH1,,,SPI1_MISO/I2S1_SDI,SPI3_MISO/I2S3_SDI,SPI2_NSS/I2S2_WS,SPI6_MISO/I2S6_SDI,SDMMC2_D3,,UART7_TX,,,,EVENTOUT, @@ -32,12 +32,12 @@ PortB,PB12,,TIM1_BKIN,,OCTOSPIM_P1_NCLK,I2C2_SMBA,SPI2_NSS/I2S2_WS,DFSDM1_DATIN1 PortB,PB13,,TIM1_CH1N,,LPTIM2_OUT,OCTOSPIM_P1_IO2,SPI2_SCK/I2S2_CK,DFSDM1_CKIN1,USART3_CTS/USART3_NSS,,FDCAN2_TX,OTG_HS_ULPI_D6,ETH_MII_TXD1/ETH_RMII_TXD1,SDMMC1_D0,DCMI_D2/PSSI_D2,UART5_TX,EVENTOUT, PortB,PB14,,TIM1_CH2N,TIM12_CH1,TIM8_CH2N,USART1_TX,SPI2_MISO/I2S2_SDI,DFSDM1_DATIN2,USART3_RTS/USART3_DE,UART4_RTS/UART4_DE,SDMMC2_D0,,,FMC_D10/FMC_AD10,,LCD_CLK,EVENTOUT, PortB,PB15,RTC_REFIN,TIM1_CH3N,TIM12_CH2,TIM8_CH3N,USART1_RX,SPI2_MOSI/I2S2_SDO,DFSDM1_CKIN2,,UART4_CTS,SDMMC2_D1,,,FMC_D11/FMC_AD11,,LCD_G7,EVENTOUT, -PortC,PC0,,FMC_D12/FMC_AD12,,DFSDM1_CKIN0,,,DFSDM1_DATIN4,,SAI4_FS_B,FMC_A25,OTG_HS_ULPI_STP,LCD_G2,FMC_SDNWE,,LCD_R5,EVENTOUT,ADC123_IN10 -PortC,PC1,TRACED0,SAI4_D1,SAI1_D1,DFSDM1_DATIN0,DFSDM1_CKIN4,SPI2_MOSI/I2S2_SDO,SAI1_SD_A,,SAI4_SD_A,SDMMC2_CK,OCTOSPIM_P1_IO4,ETH_MDC,MDIOS_MDC,,LCD_G5,EVENTOUT,ADC123_IN11 -PortC,PC2,PWR_DEEPSLEEP,,,DFSDM1_CKIN1,OCTOSPIM_P1_IO5,SPI2_MISO/I2S2_SDI,DFSDM1_CKOUT,,,OCTOSPIM_P1_IO2,OTG_HS_ULPI_DIR,ETH_MII_TXD2,FMC_SDNE0,,,EVENTOUT,ADC123_IN12 -PortC,PC3,PWR_SLEEP,,,DFSDM1_DATIN1,OCTOSPIM_P1_IO6,SPI2_MOSI/I2S2_SDO,,,,OCTOSPIM_P1_IO0,OTG_HS_ULPI_NXT,ETH_MII_TX_CLK,FMC_SDCKE0,,,EVENTOUT,ADC123_IN13 -PortC,PC4,PWR_DEEPSLEEP,FMC_A22,,DFSDM1_CKIN2,,I2S1_MCK,,,,SPDIFRX1_IN3,SDMMC2_CKIN,ETH_MII_RXD0/ETH_RMII_RXD0,FMC_SDNE0,,LCD_R7,EVENTOUT,ADC12_IN14 -PortC,PC5,PWR_SLEEP,SAI4_D3,SAI1_D3,DFSDM1_DATIN2,PSSI_D15,,,,,SPDIFRX1_IN4,OCTOSPIM_P1_DQS,ETH_MII_RXD1/ETH_RMII_RXD1,FMC_SDCKE0,COMP1_OUT,LCD_DE,EVENTOUT,ADC12_IN15 +PortC,PC0,,FMC_D12/FMC_AD12,,DFSDM1_CKIN0,,,DFSDM1_DATIN4,,SAI4_FS_B,FMC_A25,OTG_HS_ULPI_STP,LCD_G2,FMC_SDNWE,,LCD_R5,EVENTOUT,ADC123_INP10 +PortC,PC1,TRACED0,SAI4_D1,SAI1_D1,DFSDM1_DATIN0,DFSDM1_CKIN4,SPI2_MOSI/I2S2_SDO,SAI1_SD_A,,SAI4_SD_A,SDMMC2_CK,OCTOSPIM_P1_IO4,ETH_MDC,MDIOS_MDC,,LCD_G5,EVENTOUT,ADC123_INP11/ADC123_INN10 +PortC,PC2,PWR_DEEPSLEEP,,,DFSDM1_CKIN1,OCTOSPIM_P1_IO5,SPI2_MISO/I2S2_SDI,DFSDM1_CKOUT,,,OCTOSPIM_P1_IO2,OTG_HS_ULPI_DIR,ETH_MII_TXD2,FMC_SDNE0,,,EVENTOUT,ADC123_INP12/ADC123_INN11 +PortC,PC3,PWR_SLEEP,,,DFSDM1_DATIN1,OCTOSPIM_P1_IO6,SPI2_MOSI/I2S2_SDO,,,,OCTOSPIM_P1_IO0,OTG_HS_ULPI_NXT,ETH_MII_TX_CLK,FMC_SDCKE0,,,EVENTOUT,ADC123_INP13/ADC123_INN12 +PortC,PC4,PWR_DEEPSLEEP,FMC_A22,,DFSDM1_CKIN2,,I2S1_MCK,,,,SPDIFRX1_IN3,SDMMC2_CKIN,ETH_MII_RXD0/ETH_RMII_RXD0,FMC_SDNE0,,LCD_R7,EVENTOUT,ADC12_INP4 +PortC,PC5,PWR_SLEEP,SAI4_D3,SAI1_D3,DFSDM1_DATIN2,PSSI_D15,,,,,SPDIFRX1_IN4,OCTOSPIM_P1_DQS,ETH_MII_RXD1/ETH_RMII_RXD1,FMC_SDCKE0,COMP1_OUT,LCD_DE,EVENTOUT,ADC12_INP8/ADC12_INN4 PortC,PC6,,,TIM3_CH1,TIM8_CH1,DFSDM1_CKIN3,I2S2_MCK,,USART6_TX,SDMMC1_D0DIR,FMC_NWAIT,SDMMC2_D6,,SDMMC1_D6,DCMI_D0/PSSI_D0,LCD_HSYNC,EVENTOUT, PortC,PC7,DBTRGIO,,TIM3_CH2,TIM8_CH2,DFSDM1_DATIN3,,I2S3_MCK,USART6_RX,SDMMC1_D123DIR,FMC_NE1,SDMMC2_D7,SWPMI_TX,SDMMC1_D7,DCMI_D1/PSSI_D1,LCD_G6,EVENTOUT, PortC,PC8,TRACED1,,TIM3_CH3,TIM8_CH3,,,,USART6_CK,UART5_RTS/UART5_DE,FMC_NE2/FMC_NCE,FMC_INT,SWPMI_RX,SDMMC1_D0,DCMI_D2/PSSI_D2,,EVENTOUT, @@ -83,18 +83,18 @@ PortE,PE15,,TIM1_BKIN,,,,,,,,,,USART10_CK,FMC_D12/FMC_AD12,TIM1_BKIN_COMP12,LCD_ PortF,PF0,,,,,I2C2_SDA,,I2C5_SDA,,,OCTOSPIM_P2_IO0,,,FMC_A0,TIM23_CH1,,EVENTOUT, PortF,PF1,,,,,I2C2_SCL,,I2C5_SCL,,,OCTOSPIM_P2_IO1,,,FMC_A1,TIM23_CH2,,EVENTOUT, PortF,PF2,,,,,I2C2_SMBA,,I2C5_SMBA,,,OCTOSPIM_P2_IO2,,,FMC_A2,TIM23_CH3,,EVENTOUT, -PortF,PF3,,,,,,,,,,OCTOSPIM_P2_IO3,,,FMC_A3,TIM23_CH4,,EVENTOUT,ADC3_IN9 -PortF,PF4,,,,,,,,,,OCTOSPIM_P2_CLK,,,FMC_A4,,,EVENTOUT,ADC3_IN14 -PortF,PF5,,,,,,,,,,OCTOSPIM_P2_NCLK,,,FMC_A5,,,EVENTOUT,ADC3_IN15 -PortF,PF6,,TIM16_CH1,FDCAN3_RX,,,SPI5_NSS,SAI1_SD_B,UART7_RX,SAI4_SD_B,,OCTOSPIM_P1_IO3,,,TIM23_CH1,,EVENTOUT,ADC3_IN4 -PortF,PF7,,TIM17_CH1,FDCAN3_TX,,,SPI5_SCK,SAI1_MCLK_B,UART7_TX,SAI4_MCLK_B,,OCTOSPIM_P1_IO2,,,TIM23_CH2,,EVENTOUT,ADC3_IN5 -PortF,PF8,,TIM16_CH1N,,,,SPI5_MISO,SAI1_SCK_B,UART7_RTS/UART7_DE,SAI4_SCK_B,TIM13_CH1,OCTOSPIM_P1_IO0,,,TIM23_CH3,,EVENTOUT,ADC3_IN6 -PortF,PF9,,TIM17_CH1N,,,,SPI5_MOSI,SAI1_FS_B,UART7_CTS,SAI4_FS_B,TIM14_CH1,OCTOSPIM_P1_IO1,,,TIM23_CH4,,EVENTOUT,ADC3_IN7 -PortF,PF10,,TIM16_BKIN,SAI1_D3,,PSSI_D15,,,,,OCTOSPIM_P1_CLK,SAI4_D3,,,DCMI_D11/PSSI_D11,LCD_DE,EVENTOUT,ADC3_IN8 -PortF,PF11,,,,,,SPI5_MOSI,,,,OCTOSPIM_P1_NCLK,SAI4_SD_B,,FMC_NRAS,DCMI_D12/PSSI_D12,TIM24_CH1,EVENTOUT, -PortF,PF12,,,,,,,,,,OCTOSPIM_P2_DQS,,,FMC_A6,,TIM24_CH2,EVENTOUT, -PortF,PF13,,,,DFSDM1_DATIN6,I2C4_SMBA,,,,,,,,FMC_A7,,TIM24_CH3,EVENTOUT, -PortF,PF14,,,,DFSDM1_CKIN6,I2C4_SCL,,,,,,,,FMC_A8,,TIM24_CH4,EVENTOUT, +PortF,PF3,,,,,,,,,,OCTOSPIM_P2_IO3,,,FMC_A3,TIM23_CH4,,EVENTOUT,ADC3_INP5 +PortF,PF4,,,,,,,,,,OCTOSPIM_P2_CLK,,,FMC_A4,,,EVENTOUT,ADC3_INP9/ADC3_INN5 +PortF,PF5,,,,,,,,,,OCTOSPIM_P2_NCLK,,,FMC_A5,,,EVENTOUT,ADC3_INP4 +PortF,PF6,,TIM16_CH1,FDCAN3_RX,,,SPI5_NSS,SAI1_SD_B,UART7_RX,SAI4_SD_B,,OCTOSPIM_P1_IO3,,,TIM23_CH1,,EVENTOUT,ADC3_INP8/ADC3_INN4 +PortF,PF7,,TIM17_CH1,FDCAN3_TX,,,SPI5_SCK,SAI1_MCLK_B,UART7_TX,SAI4_MCLK_B,,OCTOSPIM_P1_IO2,,,TIM23_CH2,,EVENTOUT,ADC3_INP3 +PortF,PF8,,TIM16_CH1N,,,,SPI5_MISO,SAI1_SCK_B,UART7_RTS/UART7_DE,SAI4_SCK_B,TIM13_CH1,OCTOSPIM_P1_IO0,,,TIM23_CH3,,EVENTOUT,ADC3_INP7/ADC3_INN3 +PortF,PF9,,TIM17_CH1N,,,,SPI5_MOSI,SAI1_FS_B,UART7_CTS,SAI4_FS_B,TIM14_CH1,OCTOSPIM_P1_IO1,,,TIM23_CH4,,EVENTOUT,ADC3_INP2 +PortF,PF10,,TIM16_BKIN,SAI1_D3,,PSSI_D15,,,,,OCTOSPIM_P1_CLK,SAI4_D3,,,DCMI_D11/PSSI_D11,LCD_DE,EVENTOUT,ADC3_INP6/ADC3_INN2 +PortF,PF11,,,,,,SPI5_MOSI,,,,OCTOSPIM_P1_NCLK,SAI4_SD_B,,FMC_NRAS,DCMI_D12/PSSI_D12,TIM24_CH1,EVENTOUT,ADC1_INP2 +PortF,PF12,,,,,,,,,,OCTOSPIM_P2_DQS,,,FMC_A6,,TIM24_CH2,EVENTOUT,ADC1_INP5/ADC1_INN2 +PortF,PF13,,,,DFSDM1_DATIN6,I2C4_SMBA,,,,,,,,FMC_A7,,TIM24_CH3,EVENTOUT,ADC2_INP2 +PortF,PF14,,,,DFSDM1_CKIN6,I2C4_SCL,,,,,,,,FMC_A8,,TIM24_CH4,EVENTOUT,ADC2_INP6/ADC2_INN2 PortF,PF15,,,,,I2C4_SDA,,,,,,,,FMC_A9,,,EVENTOUT, PortG,PG0,,,,,,,,,,OCTOSPIM_P2_IO4,,UART9_RX,FMC_A10,,,EVENTOUT, PortG,PG1,,,,,,,,,,OCTOSPIM_P2_IO5,,UART9_TX,FMC_A11,,,EVENTOUT, From f03ac04321cbba4bd65b1790eddd4d121f649ce0 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Thu, 11 May 2023 15:45:53 +1000 Subject: [PATCH 089/565] stm32/mboot: Fix alignment of packed final buffer. Once all the firmware has been flashed and the final signatures checked, mboot writes the "all good" byte into the header of the application. This step uses the buffer firmware_head which, if unaligned in the build, fails when cast to a uint64_t* in flash.c. Signed-off-by: Andrew Leech --- ports/stm32/mboot/pack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm32/mboot/pack.c b/ports/stm32/mboot/pack.c index 6a2b7d4780..7d4adf4780 100644 --- a/ports/stm32/mboot/pack.c +++ b/ports/stm32/mboot/pack.c @@ -59,7 +59,7 @@ static uint8_t uncompressed_buf[MBOOT_PACK_GZIP_BUFFER_SIZE] __attribute__((alig // Buffer to hold the start of the firmware, which is only written once the // entire firmware is validated. This is 8 bytes due to STM32WB MCUs requiring // that a double-word write to flash can only be done once (due to ECC). -static uint8_t firmware_head[8]; +static uint8_t firmware_head[8] __attribute__((aligned(8))); // Flag to indicate that firmware_head contains valid data. static bool firmware_head_valid; From 70b60fe24edce3ea4ef57ebd294ca4323c10c041 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 11 May 2023 19:11:03 +0200 Subject: [PATCH 090/565] renesas-ra/irq: Fix typo in comment about IRQ priorities. Signed-off-by: iabdalkader --- ports/renesas-ra/irq.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/renesas-ra/irq.h b/ports/renesas-ra/irq.h index f2d0478224..076247953e 100644 --- a/ports/renesas-ra/irq.h +++ b/ports/renesas-ra/irq.h @@ -100,8 +100,8 @@ static inline void restore_irq_pri(uint32_t state) { // // The default priority grouping is set to NVIC_PRIORITYGROUP_4 in the // HAL_Init function. This corresponds to 4 bits for the priority field -// and 0 bits for the sub-priority field (which means that for all intensive -// purposes that the sub-priorities below are ignored). +// and 0 bits for the sub-priority field (which means that for all intents +// and purposes, the sub-priorities below are ignored). // // While a given interrupt is being processed, only higher priority (lower number) // interrupts will preempt a given interrupt. If sub-priorities are active From bfcaf391977cc65c47a026b4ab890590a696e15e Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 11 May 2023 19:11:34 +0200 Subject: [PATCH 091/565] stm32/irq: Fix typo in comment about priorities. Signed-off-by: iabdalkader --- ports/stm32/irq.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/stm32/irq.h b/ports/stm32/irq.h index 6c10f5e1b0..8e98b4cc5e 100644 --- a/ports/stm32/irq.h +++ b/ports/stm32/irq.h @@ -98,8 +98,8 @@ static inline void restore_irq_pri(uint32_t state) { // // The default priority grouping is set to NVIC_PRIORITYGROUP_4 in the // HAL_Init function. This corresponds to 4 bits for the priority field -// and 0 bits for the sub-priority field (which means that for all intensive -// purposes that the sub-priorities below are ignored). +// and 0 bits for the sub-priority field (which means that for all intents +// and purposes, the sub-priorities below are ignored). // // While a given interrupt is being processed, only higher priority (lower number) // interrupts will preempt a given interrupt. If sub-priorities are active From 3a7ad642672a61d3adb1510bf26913376ff837c8 Mon Sep 17 00:00:00 2001 From: UnexpectedMaker Date: Thu, 30 Mar 2023 13:27:17 +1100 Subject: [PATCH 092/565] esp32/boards: Add some missing board configs for two UM boards. --- ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake | 3 ++- ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board | 2 ++ ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake | 3 +++ ports/esp32/boards/UM_TINYS2/sdkconfig.board | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake index b0b3e3aa99..c98ef69176 100644 --- a/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake @@ -3,6 +3,7 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.spiram_sx boards/sdkconfig.usb + boards/UM_FEATHERS2NEO/sdkconfig.board ) -set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) \ No newline at end of file +set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board b/ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board index 87a92892d0..556de1f8b4 100644 --- a/ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board +++ b/ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board @@ -3,6 +3,8 @@ CONFIG_ESPTOOLPY_FLASHFREQ_80M=y CONFIG_USB_AND_UART=y CONFIG_ESPTOOLPY_AFTER_NORESET=y +CONFIG_SPIRAM_MEMTEST= + # LWIP CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS2Neo" # end of LWIP diff --git a/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake b/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake index e4b7b4a915..70cb4a814f 100644 --- a/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake @@ -3,4 +3,7 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.spiram_sx boards/sdkconfig.usb + boards/UM_TINYS2/sdkconfig.board ) + +set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) diff --git a/ports/esp32/boards/UM_TINYS2/sdkconfig.board b/ports/esp32/boards/UM_TINYS2/sdkconfig.board index 48b6749c72..39a2a293ac 100644 --- a/ports/esp32/boards/UM_TINYS2/sdkconfig.board +++ b/ports/esp32/boards/UM_TINYS2/sdkconfig.board @@ -1,6 +1,10 @@ CONFIG_FLASHMODE_QIO=y CONFIG_ESPTOOLPY_FLASHFREQ_80M=y CONFIG_USB_AND_UART=y +CONFIG_ESPTOOLPY_AFTER_NORESET=y + +CONFIG_SPIRAM_MEMTEST= + # LWIP CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS2" # end of LWIP From 05e143dbddbde07e4f31a0376b8869bcf9fb1939 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 17 May 2023 01:06:04 +1000 Subject: [PATCH 093/565] esp32/esp32_ulp: Enable FSM ULP for S2 and S3 chips. This commit enables the ULP for the S2 and S3 chips. Note this is the FSM (Finite State Machine) ULP. Signed-off-by: Patrick Joy --- docs/library/esp32.rst | 8 ++++++++ ports/esp32/esp32_ulp.c | 9 ++++++++- ports/esp32/modesp32.c | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/library/esp32.rst b/docs/library/esp32.rst index 12d0890217..d9241d545c 100644 --- a/docs/library/esp32.rst +++ b/docs/library/esp32.rst @@ -279,6 +279,14 @@ For more details see Espressif's `ESP-IDF RMT documentation. Ultra-Low-Power co-processor ---------------------------- +This class gives access to the Ultra Low Power (ULP) co-processor on the ESP32, +ESP32-S2 and ESP32-S3 chips. + +.. warning:: + + This class does not provide access to the RISCV ULP co-processor available + on the ESP32-S2 and ESP32-S3 chips. + .. class:: ULP() This class provides access to the Ultra-Low-Power co-processor. diff --git a/ports/esp32/esp32_ulp.c b/ports/esp32/esp32_ulp.c index 843bdb2366..e7962ce1ac 100644 --- a/ports/esp32/esp32_ulp.c +++ b/ports/esp32/esp32_ulp.c @@ -26,7 +26,8 @@ #include "py/runtime.h" -#if CONFIG_IDF_TARGET_ESP32 + +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #include "esp32/ulp.h" #include "esp_err.h" @@ -87,7 +88,13 @@ STATIC const mp_rom_map_elem_t esp32_ulp_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_set_wakeup_period), MP_ROM_PTR(&esp32_ulp_set_wakeup_period_obj) }, { MP_ROM_QSTR(MP_QSTR_load_binary), MP_ROM_PTR(&esp32_ulp_load_binary_obj) }, { MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&esp32_ulp_run_obj) }, + #if CONFIG_IDF_TARGET_ESP32 { MP_ROM_QSTR(MP_QSTR_RESERVE_MEM), MP_ROM_INT(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM) }, + #elif CONFIG_IDF_TARGET_ESP32S2 + { MP_ROM_QSTR(MP_QSTR_RESERVE_MEM), MP_ROM_INT(CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM) }, + #elif CONFIG_IDF_TARGET_ESP32S3 + { MP_ROM_QSTR(MP_QSTR_RESERVE_MEM), MP_ROM_INT(CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM) }, + #endif }; STATIC MP_DEFINE_CONST_DICT(esp32_ulp_locals_dict, esp32_ulp_locals_dict_table); diff --git a/ports/esp32/modesp32.c b/ports/esp32/modesp32.c index 017db36e22..7a436bf77c 100644 --- a/ports/esp32/modesp32.c +++ b/ports/esp32/modesp32.c @@ -217,7 +217,7 @@ STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_NVS), MP_ROM_PTR(&esp32_nvs_type) }, { MP_ROM_QSTR(MP_QSTR_Partition), MP_ROM_PTR(&esp32_partition_type) }, { MP_ROM_QSTR(MP_QSTR_RMT), MP_ROM_PTR(&esp32_rmt_type) }, - #if CONFIG_IDF_TARGET_ESP32 + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 { MP_ROM_QSTR(MP_QSTR_ULP), MP_ROM_PTR(&esp32_ulp_type) }, #endif From a802f719085d52f61bd08908de298f92d226be0b Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 14 May 2023 17:36:56 +1000 Subject: [PATCH 094/565] esp32/uart: Use xtal as UART clock source on S3 and C3. Change UART clock source on S3/C3 so the UART can operate when CPU frequency is below 80MHz. This allows the UART to remain operational when using Dynamic Frequency Scaling (DFS). Signed-off-by: Patrick Joy --- ports/esp32/machine_uart.c | 4 ++++ ports/esp32/uart.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c index 4cfa31b71d..8e6e5788d0 100644 --- a/ports/esp32/machine_uart.c +++ b/ports/esp32/machine_uart.c @@ -319,6 +319,10 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 0 }; + #if SOC_UART_SUPPORT_XTAL_CLK + // works independently of APB frequency + uartcfg.source_clk = UART_SCLK_XTAL; // ESP32C3, ESP32S3 + #endif // create instance machine_uart_obj_t *self = mp_obj_malloc(machine_uart_obj_t, &machine_uart_type); diff --git a/ports/esp32/uart.c b/ports/esp32/uart.c index f6493dc796..e871ca1d7a 100644 --- a/ports/esp32/uart.c +++ b/ports/esp32/uart.c @@ -46,6 +46,10 @@ void uart_stdout_init(void) { .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 0 }; + #if SOC_UART_SUPPORT_XTAL_CLK + // works independently of APB frequency + uartcfg.source_clk = UART_SCLK_XTAL; // ESP32C3, ESP32S3 + #endif uart_param_config(MICROPY_HW_UART_REPL, &uartcfg); const uint32_t rxbuf = 129; // IDF requires > 128 min From 2771b20d29569bf51ea841a804a66048efde1593 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 11 May 2023 13:24:14 +1000 Subject: [PATCH 095/565] tools/mpremote: Add repl option to escape non-printable characters. This commit adds the "--escape-non-printable" option to the repl command. When specified the REPL console will escape non-printable characters, printing them as their hex value in square brackets. This escaping behaviour was previously the default and only behaviour, but it is now opt-in. As part of this change, the speed of echoing device data to the console is improved by by reading and writing in chunks. Signed-off-by: Damien George --- docs/reference/mpremote.rst | 1 + tools/mpremote/mpremote/main.py | 1 + tools/mpremote/mpremote/repl.py | 27 +++++++++++++++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/reference/mpremote.rst b/docs/reference/mpremote.rst index 3225fc5f24..e96b32cbbe 100644 --- a/docs/reference/mpremote.rst +++ b/docs/reference/mpremote.rst @@ -92,6 +92,7 @@ The full list of supported commands are: Options are: + - ``--escape-non-printable``, to print non-printable bytes/characters as their hex code - ``--capture ``, to capture output of the REPL session to the given file - ``--inject-code ``, to specify characters to inject at the REPL when diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index 988ffe8f60..eafa5b97e3 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -119,6 +119,7 @@ def argparse_mount(): def argparse_repl(): cmd_parser = argparse.ArgumentParser(description="connect to given device") + _bool_flag(cmd_parser, "escape-non-printable", "e", False, "escape non-printable characters") cmd_parser.add_argument( "--capture", type=str, diff --git a/tools/mpremote/mpremote/repl.py b/tools/mpremote/mpremote/repl.py index d5eb2b8712..239e267d75 100644 --- a/tools/mpremote/mpremote/repl.py +++ b/tools/mpremote/mpremote/repl.py @@ -3,7 +3,9 @@ from .console import Console, ConsolePosix from . import pyboardextended as pyboard -def do_repl_main_loop(state, console_in, console_out_write, *, code_to_inject, file_to_inject): +def do_repl_main_loop( + state, console_in, console_out_write, *, escape_non_printable, code_to_inject, file_to_inject +): while True: console_in.waitchar(state.pyb.serial) c = console_in.readchar() @@ -37,26 +39,34 @@ def do_repl_main_loop(state, console_in, console_out_write, *, code_to_inject, f break if n > 0: - c = state.pyb.serial.read(1) - if c is not None: - # pass character through to the console - oc = ord(c) - if oc in (8, 9, 10, 13, 27) or 32 <= oc <= 126: - console_out_write(c) + dev_data_in = state.pyb.serial.read(n) + if dev_data_in is not None: + if escape_non_printable: + # Pass data through to the console, with escaping of non-printables. + console_data_out = bytearray() + for c in dev_data_in: + if c in (8, 9, 10, 13, 27) or 32 <= c <= 126: + console_data_out.append(c) + else: + console_data_out.extend(b"[%02x]" % c) else: - console_out_write(b"[%02x]" % ord(c)) + console_data_out = dev_data_in + console_out_write(console_data_out) def do_repl(state, args): state.ensure_friendly_repl() state.did_action() + escape_non_printable = args.escape_non_printable capture_file = args.capture code_to_inject = args.inject_code file_to_inject = args.inject_file print("Connected to MicroPython at %s" % state.pyb.device_name) print("Use Ctrl-] or Ctrl-x to exit this shell") + if escape_non_printable: + print("Escaping non-printable bytes/characters by printing their hex code") if capture_file is not None: print('Capturing session to file "%s"' % capture_file) capture_file = open(capture_file, "wb") @@ -80,6 +90,7 @@ def do_repl(state, args): state, console, console_out_write, + escape_non_printable=escape_non_printable, code_to_inject=code_to_inject, file_to_inject=file_to_inject, ) From 267d1ab2ba5adfeeb18820c4fd839037a13441dd Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 14 Mar 2023 12:41:42 +0100 Subject: [PATCH 096/565] samd/mpconfigport: Drop support for SoftSPI max speed. Saves ~140 bytes and is not really needed, since for higher baud rates hard SPI is available. Signed-off-by: robert-hh --- ports/samd/mpconfigport.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index bc1ad3d988..3b89ee082b 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -99,8 +99,6 @@ #define MICROPY_PY_MACHINE_SOFTI2C (1) #define MICROPY_PY_MACHINE_SPI (1) #define MICROPY_PY_MACHINE_SOFTSPI (1) -#define MICROPY_HW_SOFTSPI_MIN_DELAY (1) -#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (1000000) #define MICROPY_PY_MACHINE_TIMER (1) #define MICROPY_SOFT_TIMER_TICKS_MS systick_ms #define MICROPY_PY_OS_DUPTERM (3) From 457d9ee68a1e603648eb195c50175c7862be7a7e Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 18 Mar 2023 22:12:51 +0100 Subject: [PATCH 097/565] samd/boards/MINISAM_M4: Update pins.csv for the Mini SAM M4 board. Signed-off-by: robert-hh --- ports/samd/boards/MINISAM_M4/pins.csv | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ports/samd/boards/MINISAM_M4/pins.csv b/ports/samd/boards/MINISAM_M4/pins.csv index f676c290a0..793e523fcd 100644 --- a/ports/samd/boards/MINISAM_M4/pins.csv +++ b/ports/samd/boards/MINISAM_M4/pins.csv @@ -3,18 +3,19 @@ # If the pin name is omitted, the pin number is added as name. # Empty lines and lines not starting with PIN_ are ignored -PIN_PA02,A0_D9 -PIN_PB08,A1_D10 -PIN_PB09,A2_D11 -PIN_PA04,A3_D12 -PIN_PA05,A4_D13 +PIN_PA02,A0 +PIN_PB08,A1 +PIN_PB09,A2 +PIN_PA04,A3 +PIN_PA05,A4 PIN_PA06,A5 -PIN_PA16,D0 -PIN_PA17,D1 -PIN_PA07,A6_D2 +PIN_PA07,A6 +PIN_PA16,RX +PIN_PA17,TX PIN_PA19,D3 PIN_PA20,D4 PIN_PA21,D5 +PIN_PA15,LED PIN_PA00,BUTTON PIN_PA03,AREF PIN_PA12,SDA @@ -25,8 +26,6 @@ PIN_PA01,SCK PIN_PB03,DOTSTAR_DATA PIN_PB02,DOTSTAR_CLK -PIN_PA15,LED - PIN_PA24,USB_DM PIN_PA25,USB_DP PIN_PA26,USB_SOF From 315eb949da3bb3fe476050e164f03b613ca64afa Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 27 Jan 2023 16:02:05 +0100 Subject: [PATCH 098/565] samd: Rearrange the MCU-specific loader files. Such that they are easier to adapt. The maximum code size is set by: MICROPY_HW_CODESIZE=xxxK in mpconfigmcu.mk for the MCU family as default or in mpconfigboard.mk for a specific board. Setting the maximum code size allows the loader to error out if the code gets larger than the space dedicated for it. Signed-off-by: robert-hh --- ports/samd/Makefile | 3 +++ ports/samd/boards/samd21x18a.ld | 14 +++++++++++--- ports/samd/boards/samd51x19a.ld | 14 +++++++++++--- ports/samd/boards/samd51x20a.ld | 14 +++++++++++--- ports/samd/mcu/samd21/mpconfigmcu.mk | 2 ++ ports/samd/mcu/samd51/mpconfigmcu.mk | 2 ++ 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 290453f50b..6f7c8fbd85 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -65,7 +65,10 @@ CFLAGS += $(INC) -Wall -Werror -std=c99 -nostdlib -mthumb $(CFLAGS_MCU) -fsingle CFLAGS += -DMCU_$(MCU_SERIES) -D__$(CMSIS_MCU)__ CFLAGS += $(CFLAGS_EXTRA) +CFLAGS += -DMICROPY_HW_CODESIZE=$(MICROPY_HW_CODESIZE) + LDFLAGS += -nostdlib $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref +LDFLAGS += --defsym=_codesize=$(MICROPY_HW_CODESIZE) LIBS += $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) diff --git a/ports/samd/boards/samd21x18a.ld b/ports/samd/boards/samd21x18a.ld index 81a84a15d7..3ab051569f 100644 --- a/ports/samd/boards/samd21x18a.ld +++ b/ports/samd/boards/samd21x18a.ld @@ -2,10 +2,18 @@ GNU linker script for SAMD21 */ +/* +_codesize is defined in mpconfigmcu.mk or mpconfigboard.mk as +MICROPY_HW_CODESIZE and is set in Makefile +*/ + +_flashsize = 256K; /* The physical flash size */ +_bootloader = 8K; /* Must match the ORIGIN value of FLASH */ + /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00002000, LENGTH = 256K - 8K + FLASH (rx) : ORIGIN = 0x00002000, LENGTH = _codesize RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K } @@ -13,8 +21,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 8K; -_oflash_fs = ORIGIN(FLASH) + 192K - 8K; -_sflash_fs = LENGTH(FLASH) - 192K + 8K - 1; +_oflash_fs = ORIGIN(FLASH) + _codesize; +_sflash_fs = _flashsize - _codesize - _bootloader; _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/boards/samd51x19a.ld b/ports/samd/boards/samd51x19a.ld index cd03320ba4..30bc8e3328 100644 --- a/ports/samd/boards/samd51x19a.ld +++ b/ports/samd/boards/samd51x19a.ld @@ -2,10 +2,18 @@ GNU linker script for SAMD51 */ +/* +_codesize is defined in mpconfigmcu.mk or mpconfigboard.mk as +MICROPY_HW_CODESIZE and is set in Makefile +*/ + +_flashsize = 512K; /* The physical flash size */ +_bootloader = 16K; /* Must match the ORIGIN value of FLASH */ + /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00004000, LENGTH = 512K - 16K + FLASH (rx) : ORIGIN = 0x00004000, LENGTH = _codesize RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K } @@ -13,8 +21,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 16K; -_oflash_fs = ORIGIN(FLASH) + 384K - 16K; -_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1; +_oflash_fs = ORIGIN(FLASH) + _codesize; +_sflash_fs = _flashsize - _codesize - _bootloader; _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/boards/samd51x20a.ld b/ports/samd/boards/samd51x20a.ld index f0d5e5c6ae..472ab316c6 100644 --- a/ports/samd/boards/samd51x20a.ld +++ b/ports/samd/boards/samd51x20a.ld @@ -2,10 +2,18 @@ GNU linker script for SAMD51x20 */ +/* +_codesize is defined in mpconfigmcu.mk or mpconfigboard.mk as +MICROPY_HW_CODESIZE and is set in Makefile +*/ + +_flashsize = 1024K; /* The physical flash size */ +_bootloader = 16K; /* Must match the ORIGIN value of FLASH */ + /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00004000, LENGTH = 1024K - 16K + FLASH (rx) : ORIGIN = 0x00004000, LENGTH = _codesize RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K } @@ -13,8 +21,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 16K; -_oflash_fs = ORIGIN(FLASH) + 384K - 16K; -_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1; +_oflash_fs = ORIGIN(FLASH) + _codesize; +_sflash_fs = _flashsize - _codesize - _bootloader; _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/mcu/samd21/mpconfigmcu.mk b/ports/samd/mcu/samd21/mpconfigmcu.mk index ddd3e8b410..2e16d12a2d 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.mk +++ b/ports/samd/mcu/samd21/mpconfigmcu.mk @@ -2,6 +2,8 @@ CFLAGS_MCU += -mtune=cortex-m0plus -mcpu=cortex-m0plus -msoft-float MPY_CROSS_MCU_ARCH = armv6m +MICROPY_HW_CODESIZE ?= 184K + SRC_S += shared/runtime/gchelper_thumb1.s LIBM_SRC_C += $(addprefix lib/libm/,\ diff --git a/ports/samd/mcu/samd51/mpconfigmcu.mk b/ports/samd/mcu/samd51/mpconfigmcu.mk index 8596f59821..433404fd11 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.mk +++ b/ports/samd/mcu/samd51/mpconfigmcu.mk @@ -2,6 +2,8 @@ CFLAGS_MCU += -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=har MPY_CROSS_MCU_ARCH = armv7m +MICROPY_HW_CODESIZE ?= 368K + MICROPY_VFS_LFS2 ?= 1 MICROPY_VFS_FAT ?= 1 FROZEN_MANIFEST ?= mcu/$(MCU_SERIES_LOWER)/manifest.py From 05e684dc0717b27ba52eeac7c480ebb6aa032fac Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 30 Mar 2023 16:07:35 +0200 Subject: [PATCH 099/565] samd/mcu/samd51: Enable MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF. Signed-off-by: robert-hh --- ports/samd/mcu/samd51/mpconfigmcu.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index 5ac431b297..0598c353d6 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -7,6 +7,9 @@ #define MICROPY_EMIT_THUMB (1) #define MICROPY_EMIT_INLINE_THUMB (1) +// Python internal features +#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) + #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #ifndef MICROPY_PY_BUILTINS_COMPLEX From b7180d53f091c645a39377ddc17ee9d0bae2767f Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 6 Apr 2023 16:21:58 +0200 Subject: [PATCH 100/565] samd/boards: Add default deploy instructions. Signed-off-by: robert-hh --- ports/samd/boards/deploy.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ports/samd/boards/deploy.md b/ports/samd/boards/deploy.md index e69de29bb2..fac5c994ab 100644 --- a/ports/samd/boards/deploy.md +++ b/ports/samd/boards/deploy.md @@ -0,0 +1,10 @@ +For deploying the MicroPython firmware to the SAMD module, follow +the procedure: + +- Push the reset button twice or call machine.bootloader(). A drive + icon should appear representing a virtual drive. + +- Copy the .uf2 file with the required firmware to that drive. + +As soon as the drive disappears, the firmware is loaded and started. + From 7a847bab1e448c428ecd5d1ad1b7c66b70009587 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 7 Apr 2023 17:34:15 +0200 Subject: [PATCH 101/565] samd/main: Fix sercom deinit ordering in soft-reset. If sockets were open when calling soft reset, gc_sweep_all() would try to close them. In case of e.g. the NINA WiFi handler, connected through SPI, spi_transfer() would be called for command exchange with the NINA module. But at that time SerCom was already disabled. Moving sercom_deinit_all() behind gc_sweep_all() solves this issue. Signed-off-by: robert-hh --- ports/samd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/samd/main.c b/ports/samd/main.c index bc0e45ee64..1e30df13d4 100644 --- a/ports/samd/main.c +++ b/ports/samd/main.c @@ -84,9 +84,9 @@ void samd_main(void) { adc_deinit_all(); pin_irq_deinit_all(); pwm_deinit_all(); - sercom_deinit_all(); soft_timer_deinit(); gc_sweep_all(); + sercom_deinit_all(); mp_deinit(); } } From b2df094bf8051758b10f2f0222e09e79ed97427e Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 9 Apr 2023 14:14:16 +0200 Subject: [PATCH 102/565] samd/modmachine: Add machine.deepsleep as alias of machine.lightsleep. Just for coverage. Signed-off-by: robert-hh --- ports/samd/modmachine.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index ec3e99f163..a2ef34b99d 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -256,6 +256,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, { MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) }, { MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, + { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, { MP_ROM_QSTR(MP_QSTR_bitstream), MP_ROM_PTR(&machine_bitstream_obj) }, #if MICROPY_PY_MACHINE_DHT_READINTO From 47fa723586dc4ae81df02f5a0a10b2b018045ab0 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 11 Mar 2023 08:03:18 +0100 Subject: [PATCH 103/565] samd/modmachine: Make some machine classes configurable by #defines. These include ADC, DAC, I2C, SoftI2C, SPI, SoftI2C, PWM, UART, pulse. This is useful for devices like the Adafruit Trinket series which have almost no accessible GPIO pins. Signed-off-by: robert-hh --- ports/samd/machine_adc.c | 16 +++++++--------- ports/samd/machine_dac.c | 7 ++++++- ports/samd/machine_i2c.c | 5 +++++ ports/samd/machine_pwm.c | 7 ++++++- ports/samd/machine_spi.c | 17 ++++++----------- ports/samd/machine_uart.c | 33 ++++++++++++++++++++++++++------- ports/samd/machine_wdt.c | 9 ++++++++- ports/samd/main.c | 6 ++++++ ports/samd/modmachine.c | 18 ++++++++++++++++++ ports/samd/modmachine.h | 12 ++++++++++++ ports/samd/mpconfigport.h | 25 +++++++++++++++++++++++-- ports/samd/pin_af.c | 8 ++++++++ 12 files changed, 131 insertions(+), 32 deletions(-) diff --git a/ports/samd/machine_adc.c b/ports/samd/machine_adc.c index 8f47fc6d15..1d848e32bc 100644 --- a/ports/samd/machine_adc.c +++ b/ports/samd/machine_adc.c @@ -25,9 +25,12 @@ * THE SOFTWARE. */ +#include "py/runtime.h" + +#if MICROPY_PY_MACHINE_ADC + #include #include "py/obj.h" -#include "py/runtime.h" #include "py/mphal.h" #include "sam.h" @@ -82,14 +85,7 @@ static uint8_t resolution[] = { ADC_CTRLB_RESSEL_8BIT_Val, ADC_CTRLB_RESSEL_10BIT_Val, ADC_CTRLB_RESSEL_12BIT_Val }; -// Calculate the floor value of log2(n) -mp_int_t log2i(mp_int_t num) { - mp_int_t res = 0; - for (; num > 1; num >>= 1) { - res += 1; - } - return res; -} +extern mp_int_t log2i(mp_int_t num); STATIC void adc_obj_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { (void)kind; @@ -274,3 +270,5 @@ static void adc_init(machine_adc_obj_t *self) { // Set the port as given in self->id as ADC mp_hal_set_pin_mux(self->id, ALT_FCT_ADC); } + +#endif diff --git a/ports/samd/machine_dac.c b/ports/samd/machine_dac.c index a1da9285e5..195c06e4f4 100644 --- a/ports/samd/machine_dac.c +++ b/ports/samd/machine_dac.c @@ -25,9 +25,12 @@ * THE SOFTWARE. */ +#include "py/runtime.h" + +#if MICROPY_PY_MACHINE_DAC + #include #include "py/obj.h" -#include "py/runtime.h" #include "py/mphal.h" #include "sam.h" @@ -183,3 +186,5 @@ MP_DEFINE_CONST_OBJ_TYPE( print, dac_print, locals_dict, &dac_locals_dict ); + +#endif diff --git a/ports/samd/machine_i2c.c b/ports/samd/machine_i2c.c index 330fa433d9..f3364950bd 100644 --- a/ports/samd/machine_i2c.c +++ b/ports/samd/machine_i2c.c @@ -26,6 +26,9 @@ */ #include "py/runtime.h" + +#if MICROPY_PY_MACHINE_I2C + #include "py/mphal.h" #include "py/mperrno.h" #include "extmod/machine_i2c.h" @@ -274,3 +277,5 @@ MP_DEFINE_CONST_OBJ_TYPE( protocol, &machine_i2c_p, locals_dict, &mp_machine_i2c_locals_dict ); + +#endif diff --git a/ports/samd/machine_pwm.c b/ports/samd/machine_pwm.c index d01ce2ff1a..1b5f6c3ed8 100644 --- a/ports/samd/machine_pwm.c +++ b/ports/samd/machine_pwm.c @@ -25,8 +25,11 @@ * THE SOFTWARE. */ -#include #include "py/runtime.h" + +#if MICROPY_PY_MACHINE_PWM + +#include #include "py/mphal.h" #include "modmachine.h" #include "clock_config.h" @@ -393,3 +396,5 @@ STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns duty_type_flags[self->device] &= ~(1 << self->channel); mp_machine_pwm_start(self); } + +#endif diff --git a/ports/samd/machine_spi.c b/ports/samd/machine_spi.c index bbd7031e94..99eb4e17f6 100644 --- a/ports/samd/machine_spi.c +++ b/ports/samd/machine_spi.c @@ -24,7 +24,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + #include "py/runtime.h" + +#if MICROPY_PY_MACHINE_SPI + #include "py/mphal.h" #include "extmod/machine_spi.h" #include "modmachine.h" @@ -57,7 +61,6 @@ typedef struct _machine_spi_obj_t { } machine_spi_obj_t; extern Sercom *sercom_instance[]; -MP_REGISTER_ROOT_POINTER(void *sercom_table[SERCOM_INST_NUM]); void common_spi_irq_handler(int spi_id) { // handle Sercom IRQ RXC @@ -270,16 +273,6 @@ STATIC void machine_sercom_deinit(mp_obj_base_t *self_in) { MP_STATE_PORT(sercom_table[self->id]) = NULL; } -void sercom_deinit_all(void) { - for (int i = 0; i < SERCOM_INST_NUM; i++) { - Sercom *spi = sercom_instance[i]; - spi->SPI.INTENCLR.reg = 0xff; - sercom_register_irq(i, NULL); - sercom_enable(spi, 0); - MP_STATE_PORT(sercom_table[i]) = NULL; - } -} - STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { machine_spi_obj_t *self = (machine_spi_obj_t *)self_in; @@ -341,3 +334,5 @@ MP_DEFINE_CONST_OBJ_TYPE( protocol, &machine_spi_p, locals_dict, &mp_machine_spi_locals_dict ); + +#endif diff --git a/ports/samd/machine_uart.c b/ports/samd/machine_uart.c index ec1b42de9e..8028d8872d 100644 --- a/ports/samd/machine_uart.c +++ b/ports/samd/machine_uart.c @@ -25,6 +25,9 @@ * THE SOFTWARE. */ #include "py/runtime.h" + +#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART + #include "py/mphal.h" #include "py/stream.h" #include "py/ringbuf.h" @@ -59,6 +62,28 @@ typedef struct _machine_uart_obj_t { } machine_uart_obj_t; Sercom *sercom_instance[] = SERCOM_INSTS; +MP_REGISTER_ROOT_POINTER(void *sercom_table[SERCOM_INST_NUM]); + +// Common Sercom functions used by all Serial devices +void sercom_enable(Sercom *uart, int state) { + uart->USART.CTRLA.bit.ENABLE = state; // Set the state on/off + // Wait for the Registers to update. + while (uart->USART.SYNCBUSY.bit.ENABLE) { + } +} + +void sercom_deinit_all(void) { + for (int i = 0; i < SERCOM_INST_NUM; i++) { + Sercom *uart = sercom_instance[i]; + uart->USART.INTENCLR.reg = 0xff; + sercom_register_irq(i, NULL); + sercom_enable(uart, 0); + MP_STATE_PORT(sercom_table[i]) = NULL; + } +} +#endif + +#if MICROPY_PY_MACHINE_UART STATIC const char *_parity_name[] = {"None", "", "0", "1"}; // Is defined as 0, 2, 3 @@ -105,13 +130,6 @@ void common_uart_irq_handler(int uart_id) { } } -void sercom_enable(Sercom *uart, int state) { - uart->USART.CTRLA.bit.ENABLE = state; // Set the state on/off - // Wait for the Registers to update. - while (uart->USART.SYNCBUSY.bit.ENABLE) { - } -} - STATIC void machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, " @@ -544,3 +562,4 @@ MP_DEFINE_CONST_OBJ_TYPE( protocol, &uart_stream_p, locals_dict, &machine_uart_locals_dict ); +#endif diff --git a/ports/samd/machine_wdt.c b/ports/samd/machine_wdt.c index c0fbfdbfbc..d7dcfcf54e 100644 --- a/ports/samd/machine_wdt.c +++ b/ports/samd/machine_wdt.c @@ -36,7 +36,14 @@ typedef struct _machine_wdt_obj_t { mp_obj_base_t base; } machine_wdt_obj_t; -extern mp_int_t log2i(mp_int_t num); +// Calculate the floor value of log2(n) +mp_int_t log2i(mp_int_t num) { + mp_int_t res = 0; + for (; num > 1; num >>= 1) { + res += 1; + } + return res; +} STATIC const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; diff --git a/ports/samd/main.c b/ports/samd/main.c index 1e30df13d4..74eb5e3285 100644 --- a/ports/samd/main.c +++ b/ports/samd/main.c @@ -81,12 +81,18 @@ void samd_main(void) { soft_reset_exit: mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n"); + #if MICROPY_PY_MACHINE_ADC adc_deinit_all(); + #endif pin_irq_deinit_all(); + #if MICROPY_PY_MACHINE_PWM pwm_deinit_all(); + #endif soft_timer_deinit(); gc_sweep_all(); + #if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART sercom_deinit_all(); + #endif mp_deinit(); } } diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index a2ef34b99d..58ca895b45 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -234,17 +234,33 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) }, { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, + #if MICROPY_PY_MACHINE_ADC { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&machine_adc_type) }, + #endif + #if MICROPY_PY_MACHINE_DAC { MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&machine_dac_type) }, + #endif { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, { MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) }, + #if MICROPY_PY_MACHINE_PWM { MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_PTR(&machine_pwm_type) }, + #endif + #if MICROPY_PY_MACHINE_SOFTI2C { MP_ROM_QSTR(MP_QSTR_SoftI2C), MP_ROM_PTR(&mp_machine_soft_i2c_type) }, + #endif + #if MICROPY_PY_MACHINE_I2C { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) }, + #endif + #if MICROPY_PY_MACHINE_SOFTSPI { MP_ROM_QSTR(MP_QSTR_SoftSPI), MP_ROM_PTR(&mp_machine_soft_spi_type) }, + #endif + #if MICROPY_PY_MACHINE_SPI { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_spi_type) }, + #endif { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, + #if MICROPY_PY_MACHINE_UART { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) }, + #endif { MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) }, #if MICROPY_PY_MACHINE_RTC { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, @@ -254,7 +270,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, + #if MICROPY_PY_MACHINE_PULSE { MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) }, + #endif { MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, diff --git a/ports/samd/modmachine.h b/ports/samd/modmachine.h index 8b3059d9fc..b3ba44039a 100644 --- a/ports/samd/modmachine.h +++ b/ports/samd/modmachine.h @@ -29,14 +29,26 @@ #include "py/obj.h" #include "shared/timeutils/timeutils.h" +#if MICROPY_PY_MACHINE_ADC extern const mp_obj_type_t machine_adc_type; +#endif +#if MICROPY_PY_MACHINE_DAC extern const mp_obj_type_t machine_dac_type; +#endif +#if MICROPY_PY_MACHINE_I2C extern const mp_obj_type_t machine_i2c_type; +#endif extern const mp_obj_type_t machine_pin_type; +#if MICROPY_PY_MACHINE_PWM extern const mp_obj_type_t machine_pwm_type; +#endif +#if MICROPY_PY_MACHINE_SPI extern const mp_obj_type_t machine_spi_type; +#endif extern const mp_obj_type_t machine_timer_type; +#if MICROPY_PY_MACHINE_UART extern const mp_obj_type_t machine_uart_type; +#endif extern const mp_obj_type_t machine_wdt_type; #if MICROPY_PY_MACHINE_RTC extern const mp_obj_type_t machine_rtc_type; diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 3b89ee082b..bf03b5f7bd 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -94,18 +94,39 @@ #define MICROPY_PY_URANDOM (1) #define MICROPY_PY_UZLIB (1) #define MICROPY_PY_UASYNCIO (1) -#define MICROPY_PY_MACHINE_I2C (1) #define MICROPY_PY_MACHINE_RTC (1) -#define MICROPY_PY_MACHINE_SOFTI2C (1) +#ifndef MICROPY_PY_MACHINE_ADC +#define MICROPY_PY_MACHINE_ADC (1) +#endif +#ifndef MICROPY_PY_MACHINE_DAC +#define MICROPY_PY_MACHINE_DAC (1) +#endif +#ifndef MICROPY_PY_MACHINE_I2C +#define MICROPY_PY_MACHINE_I2C (1) +#endif +#ifndef MICROPY_PY_MACHINE_SPI #define MICROPY_PY_MACHINE_SPI (1) +#endif +#ifndef MICROPY_PY_MACHINE_SOFTI2C +#define MICROPY_PY_MACHINE_SOFTI2C (1) +#endif +#ifndef MICROPY_PY_MACHINE_SOFTSPI #define MICROPY_PY_MACHINE_SOFTSPI (1) +#endif +#ifndef MICROPY_PY_MACHINE_UART +#define MICROPY_PY_MACHINE_UART (1) +#endif #define MICROPY_PY_MACHINE_TIMER (1) #define MICROPY_SOFT_TIMER_TICKS_MS systick_ms #define MICROPY_PY_OS_DUPTERM (3) #define MICROPY_PY_MACHINE_BITSTREAM (1) +#ifndef MICROPY_PY_MACHINE_PULSE #define MICROPY_PY_MACHINE_PULSE (1) +#endif +#ifndef MICROPY_PY_MACHINE_PWM #define MICROPY_PY_MACHINE_PWM (1) #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/samd/machine_pwm.c" +#endif #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new #define MP_STATE_PORT MP_STATE_VM diff --git a/ports/samd/pin_af.c b/ports/samd/pin_af.c index 15743d1dfe..419b814776 100644 --- a/ports/samd/pin_af.c +++ b/ports/samd/pin_af.c @@ -121,6 +121,7 @@ const char *pin_name(int id) { return "-"; } +#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART // Test, whether the given pin is defined and has signals for sercom. // If that applies return the alt_fct and pad_nr. // If not, an error will be raised. @@ -135,7 +136,9 @@ sercom_pad_config_t get_sercom_config(int pin_id, uint8_t sercom_nr) { mp_raise_ValueError(MP_ERROR_TEXT("wrong serial device")); } } +#endif +#if MICROPY_PY_MACHINE_ADC // Test, whether the given pin is defined as ADC. // If that applies return the adc instance and channel. // If not, an error will be raised. @@ -152,6 +155,9 @@ adc_config_t get_adc_config(int pin_id, int32_t flag) { mp_raise_ValueError(MP_ERROR_TEXT("ADC pin used")); } } +#endif + +#if MICROPY_PY_MACHINE_PWM // Test, whether the given pin is defined and has signals for pwm. // If that applies return the alt_fct, tcc number and channel number. @@ -188,3 +194,5 @@ pwm_config_t get_pwm_config(int pin_id, int wanted_dev, uint8_t device_status[]) } mp_raise_ValueError(MP_ERROR_TEXT("not a PWM Pin")); } + +#endif From 984456731b01a3ee0eb84db790f1b0dbbd2cd98e Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 5 May 2023 20:46:32 +0200 Subject: [PATCH 104/565] samd/boards/SEEED_WIO_TERMINAL: Rename two pins starting with a digit. So the names don't start with a digit, which isn't allowed in Python. Signed-off-by: robert-hh --- ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv b/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv index 622de4c6c5..55cbb5bf04 100644 --- a/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv +++ b/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv @@ -20,8 +20,8 @@ PIN_PD20,SWITCH_U PIN_PC26,BUTTON_1 PIN_PC27,BUTTON_2 PIN_PC28,BUTTON_3 -PIN_PC14,5V_ENABLE -PIN_PC15,3V3_ENABLE +PIN_PC14,ENABLE_5V +PIN_PC15,ENABLE_3V3 PIN_PB26,TX PIN_PB27,RX PIN_PA13,SDA0 From 2a38531d73a9795c479635162c0609f6328e088c Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 12 May 2023 11:04:04 +0200 Subject: [PATCH 105/565] samd/mcu: Reduce the startup time after hard reset. With Crystal: set the crystal startup wait time to 1 second. It was 2 seconds before, and that seeemed too long. With USB-Sync: scan for up to 1 second for the USB to be registered and carry on with boot as soon as it it. Before, the code just waited for 500ms. Side change: improve related comments. Signed-off-by: robert-hh --- ports/samd/mcu/samd21/clock_config.c | 41 +++++++++++++-------- ports/samd/mcu/samd51/clock_config.c | 55 +++++++++++++++------------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/ports/samd/mcu/samd21/clock_config.c b/ports/samd/mcu/samd21/clock_config.c index 4c05dd7cc7..d84ee52676 100644 --- a/ports/samd/mcu/samd21/clock_config.c +++ b/ports/samd/mcu/samd21/clock_config.c @@ -52,7 +52,7 @@ uint32_t get_peripheral_freq(void) { void set_cpu_freq(uint32_t cpu_freq_arg) { - // Set 1 waitstate to be safe + // Set 1 wait state to be safe NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_MANW | NVMCTRL_CTRLB_RWS(1); int div = MAX(DFLL48M_FREQ / cpu_freq_arg, 1); @@ -75,7 +75,7 @@ void set_cpu_freq(uint32_t cpu_freq_arg) { while (GCLK->STATUS.bit.SYNCBUSY) { } // configure the FDPLL96 - // CtrlB: Set the ref ource to GCLK, set the Wakup-Fast Flag. + // CtrlB: Set the ref source to GCLK, set the Wakeup-Fast Flag. SYSCTRL->DPLLCTRLB.reg = SYSCTRL_DPLLCTRLB_REFCLK_GCLK | SYSCTRL_DPLLCTRLB_WUF; // Set the FDPLL ratio and enable the DPLL. int ldr = cpu_freq / FDPLL_REF_FREQ; @@ -106,25 +106,36 @@ void set_cpu_freq(uint32_t cpu_freq_arg) { while (GCLK->STATUS.bit.SYNCBUSY) { } } - // Set 0 waitstates for slower CPU clock + // Set 0 wait states for slower CPU clock NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_MANW | NVMCTRL_CTRLB_RWS(cpu_freq > 24000000 ? 1 : 0); SysTick_Config(cpu_freq / 1000); } void check_usb_recovery_mode(void) { #if !MICROPY_HW_XOSC32K - mp_hal_delay_ms(500); - // Check USB status. If not connected, switch DFLL48M back to open loop - if (USB->DEVICE.DeviceEndpoint[0].EPCFG.reg == 0) { - // Set/keep the open loop mode of the device. - SYSCTRL->DFLLVAL.reg = dfll48m_calibration; - SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_CCDIS | SYSCTRL_DFLLCTRL_ENABLE; + // Check USB status for up to 1 second. If not connected, + // switch DFLL48M back to open loop + for (int i = 0; i < 100; i++) { + if (USB->DEVICE.DeviceEndpoint[0].EPCFG.reg != 0) { + return; + } + mp_hal_delay_ms(10); } + // Set/keep the open loop mode of the device. + SYSCTRL->DFLLVAL.reg = dfll48m_calibration; + SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_CCDIS | SYSCTRL_DFLLCTRL_ENABLE; #endif // MICROPY_HW_XOSC32K } // Purpose of the #defines for the clock configuration. // +// The CPU is either driven by the FDPLL96 oscillator for f >= 48MHz, +// or by the DFLL48M for lower frequencies. The FDPLL96 takes 32768 Hz +// as reference frequency, supplied through GCLK1. +// +// DFLL48M is used for the peripheral clock, e.g. for PWM, UART, SPI, I2C. +// DFLL48M is either free running, or controlled by the 32kHz crystal, or +// Synchronized with the USB clock. // Both CPU and peripheral devices are clocked by the DFLL48M clock. // DFLL48M is either free running, or controlled by the 32kHz crystal, or // Synchronized with the USB clock. @@ -136,7 +147,7 @@ void check_usb_recovery_mode(void) { // The crystal is used, unless MICROPY_HW_MCU_OSC32KULP is set. // In that case GCLK1 (and the CPU clock) is driven by the 32K Low power oscillator. // The reason for offering this option is a design flaw of the Adafruit -// Feather boards, where the RGB Led and Debug signals interfere with the +// Feather boards, where the RGB LED and Debug signals interfere with the // crystal, causing the CPU to fail if it is driven by the crystal. // // If MICROPY_HW_XOSC32K = 0, the 32kHz signal for GCLK1 (and the CPU) is @@ -144,10 +155,10 @@ void check_usb_recovery_mode(void) { // // If MICROPY_HW_DFLL_USB_SYNC = 0, the DFLL48M oscillator is free running using // the pre-configured trim values. In that mode, the peripheral clock is -// not exactly 48Mhz and has a substantional temperature drift. +// not exactly 48Mhz and has a substitutional temperature drift. // // If MICROPY_HW_DFLL_USB_SYNC = 1, the DFLL48 is synchronized with the 1 kHz USB sync -// signal. If after boot there is no USB sync within 500ms, the configuration falls +// signal. If after boot there is no USB sync within 1000 ms, the configuration falls // back to a free running 48Mhz oscillator. // // In all modes, the 48MHz signal has a substantial jitter, largest when @@ -181,7 +192,7 @@ void init_clocks(uint32_t cpu_freq) { NVMCTRL->CTRLB.bit.RWS = 1; // 1 read wait state for 48MHz #if MICROPY_HW_XOSC32K - // Set up OSC32K according datasheet 17.6.3 + // Set up OSC32K according data sheet 17.6.3 SYSCTRL->XOSC32K.reg = SYSCTRL_XOSC32K_STARTUP(0x3) | SYSCTRL_XOSC32K_EN32K | SYSCTRL_XOSC32K_XTALEN; SYSCTRL->XOSC32K.bit.ENABLE = 1; @@ -211,12 +222,12 @@ void init_clocks(uint32_t cpu_freq) { while (GCLK->STATUS.bit.SYNCBUSY) { } - // Enable access to the DFLLCTRL reg acc. to Errata 1.2.1 + // Enable access to the DFLLCTRL register according to Errata 1.2.1 SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_ENABLE; while (SYSCTRL->PCLKSR.bit.DFLLRDY == 0) { } // Step 2: Set the coarse and fine values. - // Get the coarse value from the calib data. In case it is not set, + // Get the coarse value from the calibration data. In case it is not set, // set a midrange value. uint32_t coarse = (*((uint32_t *)FUSES_DFLL48M_COARSE_CAL_ADDR) & FUSES_DFLL48M_COARSE_CAL_Msk) >> FUSES_DFLL48M_COARSE_CAL_Pos; diff --git a/ports/samd/mcu/samd51/clock_config.c b/ports/samd/mcu/samd51/clock_config.c index 50912b77ed..b30cc46f24 100644 --- a/ports/samd/mcu/samd51/clock_config.c +++ b/ports/samd/mcu/samd51/clock_config.c @@ -117,27 +117,32 @@ void set_cpu_freq(uint32_t cpu_freq_arg) { void check_usb_recovery_mode(void) { #if !MICROPY_HW_XOSC32K - mp_hal_delay_ms(500); - // Check USB status. If not connected, switch DFLL48M back to open loop - if (USB->DEVICE.DeviceEndpoint[0].EPCFG.reg == 0) { - // as per Errata 2.8.3 - OSCCTRL->DFLLMUL.reg = 0; - while (OSCCTRL->DFLLSYNC.bit.DFLLMUL == 1) { - } - // Set the mode to open loop mode - OSCCTRL->DFLLCTRLB.reg = 0; - while (OSCCTRL->DFLLSYNC.bit.DFLLCTRLB == 1) { - } - OSCCTRL->DFLLCTRLA.reg = OSCCTRL_DFLLCTRLA_RUNSTDBY | OSCCTRL_DFLLCTRLA_ENABLE; - while (OSCCTRL->DFLLSYNC.bit.ENABLE == 1) { - } - OSCCTRL->DFLLVAL.reg = dfll48m_calibration; // Reload DFLLVAL register - while (OSCCTRL->DFLLSYNC.bit.DFLLVAL == 1) { - } - // Set the mode to open loop mode - OSCCTRL->DFLLCTRLB.reg = 0; - while (OSCCTRL->DFLLSYNC.bit.DFLLCTRLB == 1) { + // Check USB status for up to 1 second. If not connected, + // switch DFLL48M back to open loop + for (int i = 0; i < 100; i++) { + if (USB->DEVICE.DeviceEndpoint[0].EPCFG.reg != 0) { + return; } + mp_hal_delay_ms(10); + } + // No connection. Switch back to open loop mode. + // as per Errata 2.8.3 + OSCCTRL->DFLLMUL.reg = 0; + while (OSCCTRL->DFLLSYNC.bit.DFLLMUL == 1) { + } + // Set the mode to open loop mode + OSCCTRL->DFLLCTRLB.reg = 0; + while (OSCCTRL->DFLLSYNC.bit.DFLLCTRLB == 1) { + } + OSCCTRL->DFLLCTRLA.reg = OSCCTRL_DFLLCTRLA_RUNSTDBY | OSCCTRL_DFLLCTRLA_ENABLE; + while (OSCCTRL->DFLLSYNC.bit.ENABLE == 1) { + } + OSCCTRL->DFLLVAL.reg = dfll48m_calibration; // Reload DFLLVAL register + while (OSCCTRL->DFLLSYNC.bit.DFLLVAL == 1) { + } + // Set the mode to open loop mode + OSCCTRL->DFLLCTRLB.reg = 0; + while (OSCCTRL->DFLLSYNC.bit.DFLLCTRLB == 1) { } #endif // MICROPY_HW_XOSC32K } @@ -169,10 +174,10 @@ void check_usb_recovery_mode(void) { // // If MICROPY_HW_DFLL_USB_SYNC = 0, the DFLL48M oscillator is free running using // the pre-configured trim values. In that mode, the peripheral clock is -// not exactly 48Mhz and has a substantional temperature drift. +// not exactly 48Mhz and has a substitutional temperature drift. // // If MICROPY_HW_DFLL_USB_SYNC = 1, the DFLL48 is synchronized with the 1 kHz USB sync -// signal. If after boot there is no USB sync within 500ms, the configuration falls +// signal. If after boot there is no USB sync within 1000 ms, the configuration falls // back to a free running 48Mhz oscillator. // // In all modes, the 48MHz signal has a substantial jitter, largest when @@ -223,16 +228,16 @@ void init_clocks(uint32_t cpu_freq) { OSC32KCTRL->RTCCTRL.reg = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC1K; // Setup XOSC32K OSC32KCTRL->INTFLAG.reg = OSC32KCTRL_INTFLAG_XOSC32KRDY | OSC32KCTRL_INTFLAG_XOSC32KFAIL; - OSC32KCTRL->CFDCTRL.bit.CFDEN = 1; // Fall back to internal Osc on crystal fail + OSC32KCTRL->CFDCTRL.bit.CFDEN = 1; // Fall back to internal oscillator on crystal fail OSC32KCTRL->XOSC32K.reg = OSC32KCTRL_XOSC32K_CGM_HS | OSC32KCTRL_XOSC32K_XTALEN | OSC32KCTRL_XOSC32K_EN32K | OSC32KCTRL_XOSC32K_EN1K | OSC32KCTRL_XOSC32K_RUNSTDBY | - OSC32KCTRL_XOSC32K_STARTUP(4) | + OSC32KCTRL_XOSC32K_STARTUP(3) | OSC32KCTRL_XOSC32K_ENABLE; - // make sure osc32kcrtl is ready + // Wait until the oscillator is running and stable while (OSC32KCTRL->STATUS.bit.XOSC32KRDY == 0) { } From 20fd22edad051384b9cd929d925a91d607fbed8d Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 4 Apr 2023 16:12:45 +0200 Subject: [PATCH 106/565] samd/machine_uart: Add support for UART hardware flow control. By specifying rts=pin(x) and/or cts=Pin(x) in the constructor. The pad numbers for the UART pins are fix in this case: TX must be at pad 0, RX at pad 1, RTS at pad 2 and CTS at pad 3. repr(uart) shows the pin names for rts and cts, if set. In case of a RX overflow, the rx interrupt will be disabled instead of just discarding the data. That allows RTS to act. If RTS is inactive, still 2 bytes can be buffered in the FIFO. Signed-off-by: robert-hh --- docs/samd/pinout.rst | 8 +++- ports/samd/machine_uart.c | 72 +++++++++++++++++++++++++---- ports/samd/mcu/samd51/mpconfigmcu.h | 3 ++ 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/docs/samd/pinout.rst b/docs/samd/pinout.rst index 702da2c178..64db455eac 100644 --- a/docs/samd/pinout.rst +++ b/docs/samd/pinout.rst @@ -83,7 +83,9 @@ Examples for Adafruit ItsyBitsy M0 Express: - uart 4 at pins D2/D5 - uart 5 at pins SCL/SDA -or other combinations. +or other combinations. For hardware flow control, tx must be at pad 0, rx at pad 1, +rts at pad 2 and cts at pad 3. This applies for instance to +UART 3 or UART 1 at the pins D13/D11/D10/D12 for rx/tx/rts/cts. SAMD21 I2C assignments `````````````````````` @@ -214,7 +216,9 @@ Examples for Adafruit ItsyBitsy 4 Express: - uart 4 at pins SDA/SCL - uart 5 at pins D12/D13 -or other combinations. +or other combinations. For hardware flow control, tx must be at pad 0, rx at pad 1, +rts at pad 2 and cts at pad 3. This applies for instance to +UART 5 at the pins D12/D13/D10/D11 for rx/tx/rts/cts. SAMD51 I2C assignments `````````````````````` diff --git a/ports/samd/machine_uart.c b/ports/samd/machine_uart.c index 8028d8872d..b95e158b3c 100644 --- a/ports/samd/machine_uart.c +++ b/ports/samd/machine_uart.c @@ -40,6 +40,8 @@ #define DEFAULT_BUFFER_SIZE (256) #define MIN_BUFFER_SIZE (32) #define MAX_BUFFER_SIZE (32766) +#define FLOW_CONTROL_RTS (1) +#define FLOW_CONTROL_CTS (2) typedef struct _machine_uart_obj_t { mp_obj_base_t base; @@ -49,9 +51,15 @@ typedef struct _machine_uart_obj_t { uint8_t parity; uint8_t stop; uint8_t tx; - sercom_pad_config_t tx_pad_config; uint8_t rx; + sercom_pad_config_t tx_pad_config; sercom_pad_config_t rx_pad_config; + #if MICROPY_HW_UART_RTSCTS + uint8_t rts; + uint8_t cts; + sercom_pad_config_t rts_pad_config; + sercom_pad_config_t cts_pad_config; + #endif uint16_t timeout; // timeout waiting for first char (in ms) uint16_t timeout_char; // timeout waiting between chars (in ms) bool new; @@ -96,11 +104,10 @@ STATIC void uart_drain_rx_fifo(machine_uart_obj_t *self, Sercom *uart) { // get a byte from uart and put into the buffer ringbuf_put(&(self->read_buffer), uart->USART.DATA.bit.DATA); } else { - // if the buffer is full, discard the data for now - // t.b.d.: flow control - uint32_t temp; - (void)temp; - temp = uart->USART.DATA.bit.DATA; + // if the buffer is full, disable the RX interrupt + // allowing RTS to come up. It will be re-enabled by the next read + uart->USART.INTENCLR.reg = SERCOM_USART_INTENSET_RXC; + break; } } } @@ -137,18 +144,25 @@ STATIC void machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_pri #if MICROPY_HW_UART_TXBUF ", txbuf=%d" #endif + #if MICROPY_HW_UART_RTSCTS + ", rts=%s, cts=%s" + #endif ")", self->id, self->baudrate, self->bits, _parity_name[self->parity], self->stop + 1, self->timeout, self->timeout_char, self->read_buffer.size - 1 #if MICROPY_HW_UART_TXBUF , self->write_buffer.size - 1 #endif + #if MICROPY_HW_UART_RTSCTS + , self->rts != 0xff ? pin_name(self->rts) : "None" + , self->cts != 0xff ? pin_name(self->cts) : "None" + #endif ); } STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_tx, ARG_rx, - ARG_timeout, ARG_timeout_char, ARG_rxbuf, ARG_txbuf}; + ARG_timeout, ARG_timeout_char, ARG_rxbuf, ARG_txbuf, ARG_rts, ARG_cts }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_bits, MP_ARG_INT, {.u_int = -1} }, @@ -162,6 +176,10 @@ STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args #if MICROPY_HW_UART_TXBUF { MP_QSTR_txbuf, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, #endif + #if MICROPY_HW_UART_RTSCTS + { MP_QSTR_rts, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, + { MP_QSTR_cts, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, + #endif }; // Parse args @@ -201,6 +219,25 @@ STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args if (args[ARG_rx].u_obj != mp_const_none) { self->rx = mp_hal_get_pin_obj(args[ARG_rx].u_obj); } + #if MICROPY_HW_UART_RTSCTS + uint8_t flow_control = 0; + // Set RTS/CTS pins if configured. + if (args[ARG_rts].u_obj != mp_const_none) { + self->rts = mp_hal_get_pin_obj(args[ARG_rts].u_obj); + self->rts_pad_config = get_sercom_config(self->rts, self->id); + flow_control = FLOW_CONTROL_RTS; + } + if (args[ARG_cts].u_obj != mp_const_none) { + self->cts = mp_hal_get_pin_obj(args[ARG_cts].u_obj); + self->cts_pad_config = get_sercom_config(self->cts, self->id); + flow_control |= FLOW_CONTROL_CTS; + } + // rts only flow control is not allowed. Otherwise the state of the + // cts pin is undefined. + if (flow_control == FLOW_CONTROL_RTS) { + mp_raise_ValueError(MP_ERROR_TEXT("cts missing for flow control")); + } + #endif // Set timeout if configured. if (args[ARG_timeout].u_int >= 0) { @@ -282,8 +319,18 @@ STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args } else #endif if (self->tx_pad_config.pad_nr != 0) { - mp_raise_ValueError(MP_ERROR_TEXT("invalid tx pin")); + mp_raise_ValueError(MP_ERROR_TEXT("invalid UART pin")); } + #if MICROPY_HW_UART_RTSCTS + if ((flow_control & FLOW_CONTROL_RTS) && self->rts_pad_config.pad_nr == 2) { + txpo = 2; + mp_hal_set_pin_mux(self->rts, self->rts_pad_config.alt_fct); + } + if ((flow_control & FLOW_CONTROL_CTS) && self->cts_pad_config.pad_nr == 3) { + txpo = 2; + mp_hal_set_pin_mux(self->cts, self->cts_pad_config.alt_fct); + } + #endif uart->USART.CTRLA.reg = SERCOM_USART_CTRLA_DORD // Data order @@ -349,6 +396,10 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, self->timeout_char = 1; self->tx = 0xff; self->rx = 0xff; + #if MICROPY_HW_UART_RTSCTS + self->rts = 0xff; + self->cts = 0xff; + #endif self->new = true; MP_STATE_PORT(sercom_table[uart_id]) = self; @@ -444,6 +495,7 @@ STATIC MP_DEFINE_CONST_DICT(machine_uart_locals_dict, machine_uart_locals_dict_t STATIC mp_uint_t machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); + Sercom *uart = sercom_instance[self->id]; uint64_t t = mp_hal_ticks_ms_64() + self->timeout; uint64_t timeout_char = self->timeout_char; uint8_t *dest = buf_in; @@ -463,6 +515,10 @@ STATIC mp_uint_t machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t siz } *dest++ = ringbuf_get(&(self->read_buffer)); t = mp_hal_ticks_ms_64() + timeout_char; + // (Re-)Enable RXC interrupt + if ((uart->USART.INTENSET.reg & SERCOM_USART_INTENSET_RXC) == 0) { + uart->USART.INTENSET.reg = SERCOM_USART_INTENSET_RXC; + } } return size; } diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index 0598c353d6..07d4696901 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -46,6 +46,9 @@ unsigned long trng_random_u32(void); #ifndef MICROPY_HW_UART_TXBUF #define MICROPY_HW_UART_TXBUF (1) #endif +#ifndef MICROPY_HW_UART_RTSCTS +#define MICROPY_HW_UART_RTSCTS (1) +#endif #define CPU_FREQ (120000000) #define DFLL48M_FREQ (48000000) From c3f031afaca1c1063ed499e3c0f40a136d6ffec2 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 11 Apr 2023 08:40:02 +0200 Subject: [PATCH 107/565] samd/boards/ADAFRUIT_METRO_M4_EXPRESS: Add Metro M4 Express Airlift. The board files can be used for both Adafruit Metro M4 variants. The Wifi support is in progress. --- .../ADAFRUIT_METRO_M4_EXPRESS/board.json | 27 ++++++++ .../ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.h | 30 +++++++++ .../mpconfigboard.mk | 12 ++++ .../boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv | 66 +++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/board.json create mode 100644 ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.h create mode 100644 ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk create mode 100644 ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv diff --git a/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/board.json b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/board.json new file mode 100644 index 0000000000..e0a256cf88 --- /dev/null +++ b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/board.json @@ -0,0 +1,27 @@ +{ + "deploy": [ + "../deploy.md" + ], + "docs": "", + "features": [ + "Micro USB", + "ADC", + "DAC", + "RGB LED", + "QSPI Flash", + "WiFi", + "BLE", + "JLink" + ], + "images": [ + "metro_m4_express_airlift.jpg" + ], + "mcu": "samd51", + "variants": { + "wlan": "WLAN without SSL support" + }, + "product": "Metro M4 Express Airlift", + "thumbnail": "", + "url": "https://www.adafruit.com/product/4000", + "vendor": "Adafruit" +} diff --git a/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.h new file mode 100644 index 0000000000..7893cd706a --- /dev/null +++ b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.h @@ -0,0 +1,30 @@ +#define MICROPY_HW_BOARD_NAME "Metro M4 Express Airlift" +#define MICROPY_HW_MCU_NAME "SAMD51J19A" + +#define MICROPY_HW_XOSC32K (1) +#define MICROPY_HW_QSPIFLASH GD25Q16C + +// defines for WLAN +#define MICROPY_HW_WIFI_SPI_ID (2) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) + +#define MICROPY_HW_WIFI_SPI_SCK (13) +#define MICROPY_HW_WIFI_SPI_MOSI (12) +#define MICROPY_HW_WIFI_SPI_MISO (14) + +#define MICROPY_HW_NINA_ACK (36) +#define MICROPY_HW_NINA_GPIO1 (15) +#define MICROPY_HW_NINA_RESET (37) +// #define MICROPY_HW_NINA_GPIO0 (33) + +// defines for BLE +#define MICROPY_PY_BLUETOOTH_NINAW10 (1) + +#define MICROPY_HW_BLE_UART_ID (0) +#define MICROPY_HW_BLE_UART_BAUDRATE (115200) + +#define MICROPY_HW_BLE_UART_TX (4) +#define MICROPY_HW_BLE_UART_RX (7) + +#define MICROPY_HW_NINA_RTS (12) +#define MICROPY_HW_NINA_CTS (36) diff --git a/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk new file mode 100644 index 0000000000..238ca0055d --- /dev/null +++ b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk @@ -0,0 +1,12 @@ +MCU_SERIES = SAMD51 +CMSIS_MCU = SAMD51J19A +LD_FILES = boards/samd51x19a.ld sections.ld +TEXT0 = 0x4000 + +# MicroPython settings +MICROPY_VFS_LFS1 ?= 1 + +MICROPY_PY_NETWORK ?= 1 +MICROPY_PY_NETWORK_NINAW10 ?= 1 + +BOARD_VARIANTS += "wlan" diff --git a/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv new file mode 100644 index 0000000000..0bda767600 --- /dev/null +++ b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/pins.csv @@ -0,0 +1,66 @@ +# Pin rows contain Pin number and pin name. +# Pin rows start with PIN_ +# If the pin name is omitted, the pin number is added as name. +# Empty lines and lines not starting with PIN_ are ignored + +PIN_PA02,A0 +PIN_PA05,A1 +PIN_PA06,A2 +PIN_PB00,A3 +PIN_PB08,A4 +PIN_PB09,A5 +PIN_PA03,AREF + +PIN_PA23,D0 +PIN_PA22,D1 +PIN_PB17,D2 +PIN_PB16,D3 +PIN_PB13,D4 +PIN_PB14,D5 +PIN_PB15,D6 +PIN_PB12,D7 +PIN_PA21,D8 +PIN_PA20,D9 +PIN_PA18,D10 +PIN_PA19,D11 +PIN_PA17,D12 +PIN_PA16,D13 + +PIN_PB02,SDA +PIN_PB03,SCL + +PIN_PA13,SCK +PIN_PA12,MOSI +PIN_PA14,MISO + +PIN_PB22,NEOPIXEL +PIN_PB06,RXLED +PIN_PB07,TXLED + +# Airlift +PIN_PB05,ESP_RESET +PIN_PB04,ESP_BUSY +PIN_PA15,ESP_CS +PIN_PB01,ESP_GPIO0 +PIN_PA07,ESP_RX +PIN_PA04,ESP_TX +PIN_PB23,ESP_RTS + +# QSPI flash +PIN_PA08,FLASH_MOSI +PIN_PA09,FLASH_MISO +PIN_PA10,FLASH_WP +PIN_PA11,FLASH_HOLD +PIN_PB10,FLASH_SCK +PIN_PB11,FLASH_CS + +# USB +PIN_PA24,USB_DM +PIN_PA25,USB_DP +PIN_PA26,USB_SOF +PIN_PA17,USB_HOSTEN + +# JLink +PIN_PA30,SWCLK +PIN_PA31,SWDIO +PIN_PB30,SWO From 0f0dcec9847d8687f9f9b9ccc5d68a8d0d1ee44d Mon Sep 17 00:00:00 2001 From: Yilin Sun Date: Tue, 16 May 2023 14:34:59 +0800 Subject: [PATCH 108/565] mimxrt/sdcard: Fix GCC 13 build error with sdcard_cmd_set_bus_width. This updates the declaration of 'sdcard_cmd_set_bus_width()' to the same as its definition. Signed-off-by: Yilin Sun --- ports/mimxrt/sdcard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/mimxrt/sdcard.c b/ports/mimxrt/sdcard.c index 76d303aad0..6dbd45303b 100644 --- a/ports/mimxrt/sdcard.c +++ b/ports/mimxrt/sdcard.c @@ -234,7 +234,7 @@ static bool sdcard_cmd_set_rel_add(mimxrt_sdcard_obj_t *card); static bool sdcard_cmd_send_csd(mimxrt_sdcard_obj_t *card, csd_t *csd); static bool sdcard_cmd_select_card(mimxrt_sdcard_obj_t *sdcard); static bool sdcard_cmd_set_blocklen(mimxrt_sdcard_obj_t *sdcard); -static bool sdcard_cmd_set_bus_width(mimxrt_sdcard_obj_t *sdcard, uint8_t bus_width); +static bool sdcard_cmd_set_bus_width(mimxrt_sdcard_obj_t *sdcard, usdhc_data_bus_width_t bus_width); void sdcard_card_inserted_callback(USDHC_Type *base, void *userData) { #if defined MICROPY_USDHC1 && USDHC1_AVAIL From 8d446b2ad51a6c5a89498f27862a8b37111577b2 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 19 May 2023 20:42:07 +0200 Subject: [PATCH 109/565] mimxrt/led: Add support for up to four LEDs. Signed-off-by: iabdalkader --- ports/mimxrt/led.c | 26 ++++++++++++++------------ ports/mimxrt/led.h | 22 ++++++++++++++-------- ports/mimxrt/machine_led.c | 4 ++-- ports/mimxrt/main.c | 5 ++++- ports/mimxrt/modmachine.c | 2 +- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/ports/mimxrt/led.c b/ports/mimxrt/led.c index cb9f985464..216affa227 100644 --- a/ports/mimxrt/led.c +++ b/ports/mimxrt/led.c @@ -31,16 +31,23 @@ #include "py/mphal.h" #include "led.h" -#if NUM_LEDS +#if defined(MICROPY_HW_LED1_PIN) -const machine_led_obj_t machine_led_obj[NUM_LEDS] = { - { - .base = {&machine_led_type}, - .led_id = 1U, - .led_pin = &MICROPY_HW_LED1_PIN, - } +const machine_led_obj_t machine_led_obj[] = { + { .base = {&machine_led_type}, .led_id = 1U, .led_pin = &MICROPY_HW_LED1_PIN, }, + #if defined(MICROPY_HW_LED2_PIN) + { .base = {&machine_led_type}, .led_id = 2U, .led_pin = &MICROPY_HW_LED2_PIN, }, + #if defined(MICROPY_HW_LED3_PIN) + { .base = {&machine_led_type}, .led_id = 3U, .led_pin = &MICROPY_HW_LED3_PIN, }, + #if defined(MICROPY_HW_LED4_PIN) + { .base = {&machine_led_type}, .led_id = 4U, .led_pin = &MICROPY_HW_LED4_PIN, }, + #endif + #endif + #endif }; +#define NUM_LEDS MP_ARRAY_SIZE(machine_led_obj) + void led_init(void) { // Turn off LEDs and initialize for (mp_int_t led = 0; led < NUM_LEDS; led++) { @@ -94,9 +101,4 @@ void led_debug(int value, int delay) { mp_hal_delay_ms(delay); } -#else - -void led_init(void) { -} - #endif diff --git a/ports/mimxrt/led.h b/ports/mimxrt/led.h index a0628e90ed..7807c4a903 100644 --- a/ports/mimxrt/led.h +++ b/ports/mimxrt/led.h @@ -29,14 +29,20 @@ #include "pin.h" -#if defined(MICROPY_HW_LED1_PIN) -#define NUM_LEDS (1) -#else -#define NUM_LEDS (0) -#endif - typedef enum { - MACHINE_BOARD_LED = 1, + #if defined(MICROPY_HW_LED1_PIN) + MACHINE_BOARD_LED1 = 1, + #if defined(MICROPY_HW_LED2_PIN) + MACHINE_BOARD_LED2 = 2, + #if defined(MICROPY_HW_LED3_PIN) + MACHINE_BOARD_LED3 = 3, + #if defined(MICROPY_HW_LED4_PIN) + MACHINE_BOARD_LED4 = 4, + #endif + #endif + #endif + #endif + MICROPY_HW_LED_MAX } machine_led_t; typedef struct _machine_led_obj_t { @@ -51,6 +57,6 @@ void led_toggle(machine_led_t led); void led_debug(int value, int delay); extern const mp_obj_type_t machine_led_type; -extern const machine_led_obj_t machine_led_obj[NUM_LEDS]; +extern const machine_led_obj_t machine_led_obj[]; #endif // MICROPY_INCLUDED_MIMXRT_LED_H diff --git a/ports/mimxrt/machine_led.c b/ports/mimxrt/machine_led.c index 35743697f2..a927c570a2 100644 --- a/ports/mimxrt/machine_led.c +++ b/ports/mimxrt/machine_led.c @@ -28,7 +28,7 @@ #include "py/mphal.h" #include "led.h" -#if NUM_LEDS +#if defined(MICROPY_HW_LED1_PIN) STATIC void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; @@ -43,7 +43,7 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_ mp_int_t led_id = mp_obj_get_int(args[0]); // Check led id is in range - if (!(1 <= led_id && led_id <= NUM_LEDS)) { + if (!(1 <= led_id && led_id < MICROPY_HW_LED_MAX)) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("LED(%d) doesn't exist"), led_id); } diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index 1a85f21c6d..8f8ecd91d4 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -55,7 +55,6 @@ int main(void) { board_init(); ticks_init(); tusb_init(); - led_init(); pendsv_init(); #if MICROPY_PY_LWIP @@ -71,6 +70,10 @@ int main(void) { #endif for (;;) { + #if defined(MICROPY_HW_LED1) + led_init(); + #endif + mp_stack_set_top(&_estack); mp_stack_set_limit(&_estack - &_sstack - 1024); diff --git a/ports/mimxrt/modmachine.c b/ports/mimxrt/modmachine.c index 049499cb2e..7b00470cca 100644 --- a/ports/mimxrt/modmachine.c +++ b/ports/mimxrt/modmachine.c @@ -139,7 +139,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, { MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) }, - #if NUM_LEDS + #if defined(MICROPY_HW_LED1_PIN) { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&machine_led_type) }, #endif { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, From 5707fd74e570968fa97b8f243e31497e8f35ce42 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Mon, 8 May 2023 12:45:04 +0200 Subject: [PATCH 110/565] mimxrt/boards/ADAFRUIT_METRO_M7: Add Adafruit Metro M7 board definition. Support for WiFi and BLE is in progress. Signed-off-by: robert-hh --- .../boards/ADAFRUIT_METRO_M7/board.json | 26 ++++ .../ADAFRUIT_METRO_M7/deploy_metro_m7.md | 141 ++++++++++++++++++ .../boards/ADAFRUIT_METRO_M7/mpconfigboard.h | 65 ++++++++ .../boards/ADAFRUIT_METRO_M7/mpconfigboard.mk | 11 ++ .../mimxrt/boards/ADAFRUIT_METRO_M7/pins.csv | 31 ++++ 5 files changed, 274 insertions(+) create mode 100644 ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json create mode 100644 ports/mimxrt/boards/ADAFRUIT_METRO_M7/deploy_metro_m7.md create mode 100644 ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h create mode 100644 ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk create mode 100644 ports/mimxrt/boards/ADAFRUIT_METRO_M7/pins.csv diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json new file mode 100644 index 0000000000..c96e9b08fe --- /dev/null +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/board.json @@ -0,0 +1,26 @@ +{ + "deploy": [ + "deploy_metro_m7.md" + ], + "docs": "", + "features": [ + "USB-C", + "SPI", + "I2C", + "UART", + "RGB LED", + "QSPI Flash", + "QWIIC", + "JLink", + "WiFi", + "BLE" + ], + "images": [ + "Metro_M7.jpg" + ], + "mcu": "mimxrt", + "product": "Adafruit Metro M7", + "thumbnail": "", + "url": "https://www.adafruit.com/product/4950", + "vendor": "Adafruit" +} diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/deploy_metro_m7.md b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/deploy_metro_m7.md new file mode 100644 index 0000000000..bc92016b71 --- /dev/null +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/deploy_metro_m7.md @@ -0,0 +1,141 @@ +## 1. Deploy the MicroPython firmware to the Metro M7 board. + +### 1.1 Deploy the firmware using the serial bootloader. + +For initial deployment of the firmware a few preparation steps are required, which +have to be done once. + +1. Get the files ufconv.py and uf2families.json from the micropython/tools directory, +e.g. at https://github.com/micropython/micropython/tree/master/tools. + +2. Get the NXP program sdphost for your operating system, e.g. from +https://github.com/adafruit/tinyuf2/tree/master/ports/mimxrt10xx/sdphost. +You can also get them from the NXP web sites. + +3. Get the UF2 boot-loader package https://github.com/adafruit/tinyuf2/releases/download/0.9.0/tinyuf2-imxrt1010_evk-0.9.0.zip +and extract the file tinyuf2-imxrt1010_evk-0.9.0.bin. + +Now you have all files at hand that you will need for updating. + +1. Get the firmware you want to upload from the MicroPython download page. + +2. Set the two BOOTSEL DIP switches to the 1/0 position, which is the opposite position of the normal use mode. + +3. Push the reset button. + +4. Run the commands: + +``` +sudo ./sdphost -u 0x1fc9,0x0145 -- write-file 0x20206400 tinyuf2-imxrt1010_evk-0.9.0.bin +sudo ./sdphost -u 0x1fc9,0x0145 -- jump-address 0x20207000 +``` +Wait until a drive icon appears on the computer (or mount it explicitly), and then run: +``` +python3 uf2conv.py --base 0x60000400 -f 0x4fb2d5bd +``` +You can put all of that in a script. Just add a short wait before the 3rd command to let the drive connect. + +5. Once the upload is finished, set the BOOTSEL DIP switches back to the 0/1 position and push reset. + +Using sudo is Linux specific. You may not need it at all, if the access rights are set properly, +and you will not need it for Windows. + +### 1.2 Deploy the firmware using a JTAG adapter. + +With a JTAG adapter the firmware can be easily installed. Appropriate tools are Segger JFlash Lite and +the Segger Edu Mini adapter. Just use the firmware.hex file for loading, which will be loaded at the +proper address. + + +## 2. Deploy the WiFi firmware. + +The NINA firmware in the NINA module has to be updated for use with MicroPython. That can be done +using MicroPython and two small Python scripts. + +The firmware binaries are available at +https://github.com/micropython/micropython-lib/tree/master/micropython/espflash +or https://github.com/robert-hh/Shared-Stuff. For the Metro M7 board, the +NINA_FW_v1.5.0_Airlift.bin file is needed. + +For firmware upload, the following connections to the WiFi module are required: + +- Pin Reset (as above) +- Pin GPIO0 +- UART RX +- UART TX + +The GPIO pins and UART device id varies between boards. At the Adafruit Metro M7 board, +the UART is UART(1), and the Pin names for reset and GPIO0 are ESP_RESET and ESP_GPIO0. +The firmware can be uploaded, using the espflash.py module, a short script +using espflash.py and mpremote. espflash.py is available at +https://github.com/micropython/micropython-lib/tree/master/micropython/espflash. +This place also holds the example script. + +``` +import espflash +from machine import Pin +from machine import UART +import sys +sys.path.append("/flash") + +reset = Pin("ESP_RESET", Pin.OUT) +gpio0 = Pin("ESP_GPIO0", Pin.OUT) +uart = UART(0, 115200, timeout=350) + +md5sum = b"b0b9ab23da820a469e597c41364acb3a" +path = "/remote/NINA_FW_v1.5.0_Airlift.bin" + +esp = espflash.ESPFlash(reset, gpio0, uart) +# Enter bootloader download mode, at 115200 +esp.bootloader() +# Can now change to higher/lower baud rate +esp.set_baudrate(921600) +# Must call this first before any flash functions. +esp.flash_attach() +# Read flash size +size = esp.flash_read_size() +# Configure flash parameters. +esp.flash_config(size) +# Write firmware image from internal storage. +esp.flash_write_file(path) +# Compares file and flash MD5 checksum. +esp.flash_verify_file(path, md5sum) +# Resets the ESP32 chip. +esp.reboot() +``` + +The script shows the set-up for the Metro M7 board. +The md5sum is the one of the WiFi firmware. It may change and +can be recalculated using e.g. the Linux `md5sum` command. It is used to +verify the firmware upload. To upload the firmware, place the firmware +and the above script (let's call it ninaflash.py) into the same directory +on your PC, and run the command: +``` +mpremote connect mount . run ninaflash.py +``` +After a while, the upload will start. A typical start sequence looks like: +``` +Local directory . is mounted at /remote +Failed to read response to command 8. +Failed to read response to command 8. +Changing baudrate => 921600 +Flash attached +Flash size 2.0 MBytes +Flash write size: 1310720 total_blocks: 320 block size: 4096 +Writing sequence number 0/320... +Writing sequence number 1/320... +Writing sequence number 2/320... +Writing sequence number 3/320... +Writing sequence number 4/320... +.... +.... +Writing sequence number 317/320... +Writing sequence number 318/320... +Writing sequence number 319/320... +Flash write finished +Flash verify: File MD5 b'b0b9ab23da820a469e597c41364acb3a' +Flash verify: Flash MD5 b'b0b9ab23da820a469e597c41364acb3a' +Firmware verified. +``` +The initial messages `Failed to read response to command 8.` +can be ignored. diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h new file mode 100644 index 0000000000..ac9cf97058 --- /dev/null +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h @@ -0,0 +1,65 @@ +#define MICROPY_HW_BOARD_NAME "Adafruit Metro M7" +#define MICROPY_HW_MCU_NAME "MIMXRT1011DAE5A" + +// i.MX RT1010 EVK has 1 board LED +#define MICROPY_HW_LED1_PIN (pin_GPIO_03) +#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin)) +#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) + +#define MICROPY_HW_NUM_PIN_IRQS (2 * 32) + +// Define mapping logical UART # to hardware UART # +// LPUART1 on USB_DBG -> 0 +// LPUART1 on D0/D1 -> 1 +// LPUART3 on A0/D4 -> 3 +// LPUART4 on D6/D7 -> 2 + +#define MICROPY_HW_UART_NUM (sizeof(uart_index_table) / sizeof(uart_index_table)[0]) +#define MICROPY_HW_UART_INDEX { 1, 1, 2, 4 } + +#define IOMUX_TABLE_UART \ + { IOMUXC_GPIO_10_LPUART1_TXD }, { IOMUXC_GPIO_09_LPUART1_RXD }, \ + { IOMUXC_GPIO_12_LPUART3_TXD }, { IOMUXC_GPIO_11_LPUART3_RXD }, \ + { 0 }, { 0 }, \ + { IOMUXC_GPIO_AD_02_LPUART4_TXD }, { IOMUXC_GPIO_AD_01_LPUART4_RXD }, + +#define MICROPY_HW_SPI_INDEX { 1 } + +#define IOMUX_TABLE_SPI \ + { IOMUXC_GPIO_AD_06_LPSPI1_SCK }, { IOMUXC_GPIO_AD_05_LPSPI1_PCS0 }, \ + { IOMUXC_GPIO_AD_04_LPSPI1_SDO }, { IOMUXC_GPIO_AD_03_LPSPI1_SDI }, \ + { IOMUXC_GPIO_AD_02_LPSPI1_PCS1 } + +#define DMA_REQ_SRC_RX { 0, kDmaRequestMuxLPSPI1Rx, kDmaRequestMuxLPSPI2Rx } +#define DMA_REQ_SRC_TX { 0, kDmaRequestMuxLPSPI1Tx, kDmaRequestMuxLPSPI2Tx } + +// Define mapping hardware I2C # to logical I2C # +// SDA/SCL HW-I2C Logical I2C +// D14/D15 LPI2C1 -> 0 +// D0/D1 LPI2C2 -> 1 +// D6/D7 LPI2C2 -> 1 Alternatively possible GPIO_AD_01, GPIO_AD_02 + +#define MICROPY_HW_I2C_INDEX { 1, 2 } + +#define IOMUX_TABLE_I2C \ + { IOMUXC_GPIO_02_LPI2C1_SCL }, { IOMUXC_GPIO_01_LPI2C1_SDA }, \ + { IOMUXC_GPIO_10_LPI2C2_SCL }, { IOMUXC_GPIO_09_LPI2C2_SDA }, + +// Wifi Deinitions +#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-metro-m7" + +#define MICROPY_HW_WIFI_SPI_ID (0) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (8000000) + +#define MICROPY_HW_NINA_ACK pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_ESP_BUSY)) +#define MICROPY_HW_NINA_CS pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_ESP_CS)) +#define MICROPY_HW_NINA_RESET pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_ESP_RESET)) + +// BLE definitions +#define MICROPY_PY_BLUETOOTH_NINAW10 (1) + +#define MICROPY_HW_BLE_UART_ID (1) +#define MICROPY_HW_BLE_UART_BAUDRATE (115200) + +#define MICROPY_HW_NINA_RTS pin_find(MP_OBJ_NEW_QSTR(MP_QSTR_MOSI)) +#define MICROPY_HW_NINA_CTS MICROPY_HW_NINA_ACK diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk new file mode 100644 index 0000000000..8617261d54 --- /dev/null +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk @@ -0,0 +1,11 @@ +MCU_SERIES = MIMXRT1011 +MCU_VARIANT = MIMXRT1011DAE5A + +MICROPY_FLOAT_IMPL = single +MICROPY_PY_MACHINE_SDCARD = 0 +MICROPY_HW_FLASH_TYPE ?= qspi_nor_flash +MICROPY_HW_FLASH_SIZE ?= 0x800000 # 8MB + +MICROPY_PY_NETWORK_NINAW10 ?= 1 +MICROPY_PY_USSL ?= 1 +MICROPY_SSL_MBEDTLS ?= 1 diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/pins.csv b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/pins.csv new file mode 100644 index 0000000000..65fbd68d50 --- /dev/null +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/pins.csv @@ -0,0 +1,31 @@ +D0,GPIO_09 +D1,GPIO_10 +D2,GPIO_13 +D3,GPIO_12 +D4,GPIO_SD_00 +D5,GPIO_SD_01 +D6,GPIO_SD_02 +D7,GPIO_11 +D8,GPIO_08 +D9,GPIO_07 +D10,GPIO_06 +D11,GPIO_05 +D12,GPIO_04 +D13,GPIO_03 +D14,GPIO_01 +D15,GPIO_02 +A0,GPIO_AD_02 +A1,GPIO_AD_01 +A2,GPIO_AD_00 +A3,GPIO_AD_05 +A4,GPIO_AD_10 +A5,GPIO_AD_08 +LED,GPIO_03 +NEOPIXEL,GPIO_00 +ESP_RESET,GPIO_AD_07 +ESP_BUSY,GPIO_AD_11 +ESP_CS,GPIO_AD_14 +ESP_GPIO0,GPIO_SD_05 +SCK,GPIO_AD_06 +MISO,GPIO_AD_03 +MOSI,GPIO_AD_04 From 0000eb27240037f7e95971f1f90e070c0a01d028 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 19 May 2023 22:05:49 +1000 Subject: [PATCH 111/565] docs/reference/speed_python: Remove 4-arg limit for viper. This limit was removed in a676b5acf6ee9c17926cf9786370d30a077d99c0. Signed-off-by: Jim Mussared --- docs/reference/speed_python.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/reference/speed_python.rst b/docs/reference/speed_python.rst index 834a53b0a7..0c68dd60bd 100644 --- a/docs/reference/speed_python.rst +++ b/docs/reference/speed_python.rst @@ -247,7 +247,6 @@ Python will interpret the result as 2**32 -1 rather than as -1. In addition to the restrictions imposed by the native emitter the following constraints apply: -* Functions may have up to four arguments. * Default argument values are not permitted. * Floating point may be used but is not optimised. From f4b4d05e49dff1be3d8935c1e47069023cb03eab Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 19 May 2023 16:11:05 +1000 Subject: [PATCH 112/565] stm32/usb: Fix USB support on STM32G4. Also fix MAX_ENDPOINT definition for G0, which follows G4. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/stm32/mpconfigboard_common.h | 2 +- ports/stm32/stm32_it.c | 2 +- ports/stm32/usb.c | 4 ++-- ports/stm32/usbd_conf.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h index b538f78235..0bb80f215e 100644 --- a/ports/stm32/mpconfigboard_common.h +++ b/ports/stm32/mpconfigboard_common.h @@ -559,7 +559,7 @@ #endif // Whether the USB peripheral is device-only, or multiple OTG -#if defined(STM32L0) || defined(STM32L432xx) || defined(STM32WB) +#if defined(STM32G4) || defined(STM32L0) || defined(STM32L432xx) || defined(STM32WB) #define MICROPY_HW_USB_IS_MULTI_OTG (0) #else #define MICROPY_HW_USB_IS_MULTI_OTG (1) diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c index ea9873094f..78e7f15190 100644 --- a/ports/stm32/stm32_it.c +++ b/ports/stm32/stm32_it.c @@ -312,7 +312,7 @@ void USB_IRQHandler(void) { } #endif -#elif defined(STM32WB) +#elif defined(STM32G4) || defined(STM32WB) #if MICROPY_HW_USB_FS void USB_LP_IRQHandler(void) { diff --git a/ports/stm32/usb.c b/ports/stm32/usb.c index 87306075a9..c9c29cc50c 100644 --- a/ports/stm32/usb.c +++ b/ports/stm32/usb.c @@ -59,7 +59,7 @@ #endif // Maximum number of endpoints (excluding EP0) -#if defined(STM32L0) || defined(STM32WB) +#if defined(STM32G0) || defined(STM32G4) || defined(STM32L0) || defined(STM32WB) #define MAX_ENDPOINT(dev_id) (7) #elif defined(STM32L4) #define MAX_ENDPOINT(dev_id) (5) @@ -67,7 +67,7 @@ #define MAX_ENDPOINT(dev_id) ((dev_id) == USB_PHY_FS_ID ? 3 : 5) #elif defined(STM32F7) #define MAX_ENDPOINT(dev_id) ((dev_id) == USB_PHY_FS_ID ? 5 : 8) -#elif defined(STM32G0) || defined(STM32H7) +#elif defined(STM32H7) #define MAX_ENDPOINT(dev_id) (8) #endif diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c index a643c1eb6f..371558d775 100644 --- a/ports/stm32/usbd_conf.c +++ b/ports/stm32/usbd_conf.c @@ -67,7 +67,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) { if (hpcd->Instance == USB_OTG_FS) { // Configure USB GPIO's. - #if defined(STM32G0) + #if defined(STM32G0) || defined(STM32G4) // These MCUs don't have an alternate function for USB but rather require // the pins to be disconnected from all peripherals, ie put in analog mode. @@ -146,7 +146,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) { #elif defined(STM32L432xx) NVIC_SetPriority(USB_FS_IRQn, IRQ_PRI_OTG_FS); HAL_NVIC_EnableIRQ(USB_FS_IRQn); - #elif defined(STM32WB) + #elif defined(STM32G4) || defined(STM32WB) NVIC_SetPriority(USB_LP_IRQn, IRQ_PRI_OTG_FS); HAL_NVIC_EnableIRQ(USB_LP_IRQn); #else From 0ba08e6299419523ef375515cbfc1c44dc54afbb Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 19 May 2023 16:11:05 +1000 Subject: [PATCH 113/565] stm32/boards/NUCLEO_G474RE: Make it easier to enable USB. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h index 72c395d493..31157dd2c4 100644 --- a/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h @@ -5,7 +5,7 @@ #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_HW_ENABLE_ADC (1) #define MICROPY_HW_ENABLE_DAC (1) // A4, A5 -#define MICROPY_HW_ENABLE_USB (0) // A12 (dp), A11 (dm) +#define MICROPY_HW_ENABLE_USB (0) // can be enabled if USB cable connected to PA11/PA12 (D-/D+) #define MICROPY_HW_HAS_SWITCH (1) #define MICROPY_HW_HAS_FLASH (0) // QSPI extflash not mounted @@ -84,7 +84,7 @@ #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) // USB config pin A12 (dp), A11 (dm) not mounted on Nucleo -// #define MICROPY_HW_USB_FS (1) +#define MICROPY_HW_USB_FS (1) // #define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9) // #define MICROPY_HW_USB_OTG_ID_PIN (pin_A10) From 87cf439e0da2162f6cc9fd866d3d87e69ac747bb Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 17 May 2023 11:44:23 +1000 Subject: [PATCH 114/565] stm32/adc: Add support for STM32L4A6 MCUs. Signed-off-by: Damien George --- ports/stm32/adc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c index ba09c612d7..fc966e822d 100644 --- a/ports/stm32/adc.c +++ b/ports/stm32/adc.c @@ -170,6 +170,7 @@ defined(STM32L451xx) || defined(STM32L452xx) || \ defined(STM32L462xx) || defined(STM32L475xx) || \ defined(STM32L476xx) || defined(STM32L496xx) || \ + defined(STM32L4A6xx) || \ defined(STM32WB55xx) #define VBAT_DIV (3) #elif defined(STM32L152xE) From b57b079bbee1d81c8b451c4e9f2728a47e979b87 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 17 May 2023 11:44:41 +1000 Subject: [PATCH 115/565] stm32/boards/NUCLEO_L4A6ZG: Add new board definition. Signed-off-by: Damien George --- ports/stm32/boards/NUCLEO_L4A6ZG/board.json | 15 ++++ .../boards/NUCLEO_L4A6ZG/mpconfigboard.h | 85 +++++++++++++++++++ .../boards/NUCLEO_L4A6ZG/mpconfigboard.mk | 5 ++ ports/stm32/boards/NUCLEO_L4A6ZG/pins.csv | 77 +++++++++++++++++ .../boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h | 20 +++++ 5 files changed, 202 insertions(+) create mode 100644 ports/stm32/boards/NUCLEO_L4A6ZG/board.json create mode 100644 ports/stm32/boards/NUCLEO_L4A6ZG/mpconfigboard.h create mode 100644 ports/stm32/boards/NUCLEO_L4A6ZG/mpconfigboard.mk create mode 100644 ports/stm32/boards/NUCLEO_L4A6ZG/pins.csv create mode 100644 ports/stm32/boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h diff --git a/ports/stm32/boards/NUCLEO_L4A6ZG/board.json b/ports/stm32/boards/NUCLEO_L4A6ZG/board.json new file mode 100644 index 0000000000..73b134eac2 --- /dev/null +++ b/ports/stm32/boards/NUCLEO_L4A6ZG/board.json @@ -0,0 +1,15 @@ +{ + "deploy": [ + "../deploy.md" + ], + "docs": "", + "features": [], + "images": [ + "nucleo_l4a6zg.jpg" + ], + "mcu": "stm32l4", + "product": "Nucleo L4A6ZG", + "thumbnail": "", + "url": "", + "vendor": "ST Microelectronics" +} diff --git a/ports/stm32/boards/NUCLEO_L4A6ZG/mpconfigboard.h b/ports/stm32/boards/NUCLEO_L4A6ZG/mpconfigboard.h new file mode 100644 index 0000000000..9696b1fb9d --- /dev/null +++ b/ports/stm32/boards/NUCLEO_L4A6ZG/mpconfigboard.h @@ -0,0 +1,85 @@ +#define MICROPY_HW_BOARD_NAME "NUCLEO-L4A6ZG" +#define MICROPY_HW_MCU_NAME "STM32L4A6ZG" + +#define MICROPY_HW_HAS_SWITCH (1) +#define MICROPY_HW_HAS_FLASH (1) +#define MICROPY_HW_ENABLE_RNG (1) +#define MICROPY_HW_ENABLE_RTC (1) +#define MICROPY_HW_ENABLE_USB (1) +#define MICROPY_HW_ENABLE_DAC (1) + +// MSI is used and is 4MHz +#define MICROPY_HW_CLK_PLLM (1) +#define MICROPY_HW_CLK_PLLN (40) +#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV7) +#define MICROPY_HW_CLK_PLLQ (RCC_PLLQ_DIV2) +#define MICROPY_HW_CLK_PLLR (RCC_PLLR_DIV2) + +#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_4 + +// The board has an external 32kHz crystal +#define MICROPY_HW_RTC_USE_LSE (1) + +// USART1 config +#define MICROPY_HW_UART1_TX (pin_A9) +#define MICROPY_HW_UART1_RX (pin_A10) +// USART2 config +#define MICROPY_HW_UART2_TX (pin_A2) +#define MICROPY_HW_UART2_RX (pin_A3) +#define MICROPY_HW_UART2_RTS (pin_A1) +#define MICROPY_HW_UART2_CTS (pin_A0) +// USART3 config +#define MICROPY_HW_UART3_TX (pin_C4) +#define MICROPY_HW_UART3_RX (pin_C5) +#define MICROPY_HW_UART3_RTS (pin_B14) +#define MICROPY_HW_UART3_CTS (pin_B13) +// UART4 config +#define MICROPY_HW_UART4_TX (pin_A0) +#define MICROPY_HW_UART4_RX (pin_A1) +// UART5 config +#define MICROPY_HW_UART5_TX (pin_C12) +#define MICROPY_HW_UART5_RX (pin_D2) +// LPUART config +#define MICROPY_HW_LPUART1_TX (pin_G7) +#define MICROPY_HW_LPUART1_RX (pin_G8) +// LPUART1 is connected to the virtual com portlon the ST-Link +#define MICROPY_HW_UART_REPL PYB_LPUART_1 +#define MICROPY_HW_UART_REPL_BAUD 115200 + +// I2C buses +#define MICROPY_HW_I2C1_SCL (pin_B8) +#define MICROPY_HW_I2C1_SDA (pin_B9) +#define MICROPY_HW_I2C2_SCL (pin_B10) +#define MICROPY_HW_I2C2_SDA (pin_B11) +#define MICROPY_HW_I2C3_SCL (pin_C0) +#define MICROPY_HW_I2C3_SDA (pin_C1) + +// SPI buses +#define MICROPY_HW_SPI1_NSS (pin_A4) +#define MICROPY_HW_SPI1_SCK (pin_B3) +#define MICROPY_HW_SPI1_MISO (pin_B4) +#define MICROPY_HW_SPI1_MOSI (pin_B5) +#define MICROPY_HW_SPI2_NSS (pin_B12) +#define MICROPY_HW_SPI2_SCK (pin_B13) +#define MICROPY_HW_SPI2_MISO (pin_B14) +#define MICROPY_HW_SPI2_MOSI (pin_B15) + +// CAN buses +#define MICROPY_HW_CAN1_TX (pin_A12) +#define MICROPY_HW_CAN1_RX (pin_A11) + +// USRSW is pulled low. Pressing the button makes the input go high. +#define MICROPY_HW_USRSW_PIN (pin_C13) +#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL) +#define MICROPY_HW_USRSW_EXTI_MODE (GPIO_MODE_IT_FALLING) +#define MICROPY_HW_USRSW_PRESSED (0) + +// LEDs +#define MICROPY_HW_LED1 (pin_C7) // Green LED on Nucleo +#define MICROPY_HW_LED2 (pin_B7) // Blue LED on Nucleo +#define MICROPY_HW_LED3 (pin_B14) // Red LED on Nucleo +#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin)) +#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) + +// USB config +#define MICROPY_HW_USB_FS (1) diff --git a/ports/stm32/boards/NUCLEO_L4A6ZG/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_L4A6ZG/mpconfigboard.mk new file mode 100644 index 0000000000..51caeaa3a1 --- /dev/null +++ b/ports/stm32/boards/NUCLEO_L4A6ZG/mpconfigboard.mk @@ -0,0 +1,5 @@ +MCU_SERIES = l4 +CMSIS_MCU = STM32L4A6xx +AF_FILE = boards/stm32l496_af.csv +LD_FILES = boards/stm32l496xg.ld boards/common_basic.ld +OPENOCD_CONFIG = boards/openocd_stm32l4.cfg diff --git a/ports/stm32/boards/NUCLEO_L4A6ZG/pins.csv b/ports/stm32/boards/NUCLEO_L4A6ZG/pins.csv new file mode 100644 index 0000000000..e7c3ef63ef --- /dev/null +++ b/ports/stm32/boards/NUCLEO_L4A6ZG/pins.csv @@ -0,0 +1,77 @@ +D0,PA3 +D1,PA2 +D2,PA10 +D3,PB3 +D4,PB5 +D5,PB4 +D6,PB10 +D7,PA8 +D8,PA9 +D9,PC7 +D10,PB6 +D11,PA7 +D12,PA6 +D13,PA5 +D14,PB9 +D15,PB8 +A0,PA0 +A1,PA1 +A2,PA4 +A3,PB0 +A4,PC1 +A5,PC0 +PA0,PA0 +PA1,PA1 +PA2,PA2 +PA3,PA3 +PA4,PA4 +PA5,PA5 +PA6,PA6 +PA7,PA7 +PA8,PA8 +PA9,PA9 +PA10,PA10 +PA11,PA11 +PA12,PA12 +PA15,PA15 +PB0,PB0 +PB1,PB1 +PB2,PB2 +PB3,PB3 +PB4,PB4 +PB5,PB5 +PB6,PB6 +PB7,PB7 +PB8,PB8 +PB9,PB9 +PB10,PB10 +PB11,PB11 +PB12,PB12 +PB13,PB13 +PB14,PB14 +PB15,PB15 +PC0,PC0 +PC1,PC1 +PC2,PC2 +PC3,PC3 +PC4,PC4 +PC5,PC5 +PC6,PC6 +PC7,PC7 +PC8,PC8 +PC9,PC9 +PC10,PC10 +PC11,PC11 +PC12,PC12 +PC13,PC13 +PC14,PC14 +PC15,PC15 +PD2,PD2 +PH0,PH0 +PH1,PH1 +LED_GREEN,PC7 +LED_RED,PB14 +LED_BLUE,PB7 +SW,PC13 +LPUART1_TX,PG7 +LPUART1_RX,PG8 diff --git a/ports/stm32/boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h new file mode 100644 index 0000000000..fd380ab735 --- /dev/null +++ b/ports/stm32/boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h @@ -0,0 +1,20 @@ +/* This file is part of the MicroPython project, http://micropython.org/ + * The MIT License (MIT) + * Copyright (c) 2019 Damien P. George + */ +#ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H +#define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H + +#include "boards/stm32l4xx_hal_conf_base.h" + +// Oscillator values in Hz +#define HSE_VALUE (8000000) +#define LSE_VALUE (32768) +#define EXTERNAL_SAI1_CLOCK_VALUE (48000) +#define EXTERNAL_SAI2_CLOCK_VALUE (48000) + +// Oscillator timeouts in ms +#define HSE_STARTUP_TIMEOUT (100) +#define LSE_STARTUP_TIMEOUT (5000) + +#endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H From 324d01eb527cc18c3696e2fa476f806dfe4a6527 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 May 2023 10:02:54 +1000 Subject: [PATCH 116/565] renesas-ra: Consolidate hal_entry.c code and remove hal_entry() func. The hal_entry.c code is duplicated across all boards, so consolidate it to a common ra_hal.c file. And remove the hal_entry() function because it simply calls main(). Signed-off-by: Damien George --- ports/renesas-ra/Makefile | 3 +- .../boards/EK_RA4M1/ra_gen/hal_data.h | 2 - .../renesas-ra/boards/EK_RA4M1/ra_gen/main.c | 6 -- .../boards/EK_RA4M1/src/hal_entry.c | 58 ------------------ .../boards/EK_RA4W1/ra_gen/hal_data.h | 2 - .../renesas-ra/boards/EK_RA4W1/ra_gen/main.c | 6 -- .../boards/EK_RA4W1/src/hal_entry.c | 59 ------------------- .../boards/EK_RA6M1/ra_gen/hal_data.h | 2 - .../renesas-ra/boards/EK_RA6M1/ra_gen/main.c | 6 -- .../boards/EK_RA6M1/src/hal_entry.c | 58 ------------------ .../boards/EK_RA6M2/ra_gen/hal_data.h | 1 - .../renesas-ra/boards/EK_RA6M2/ra_gen/main.c | 6 -- .../boards/EK_RA6M2/src/hal_entry.c | 58 ------------------ .../boards/RA4M1_CLICKER/ra_gen/hal_data.h | 1 - .../boards/RA4M1_CLICKER/ra_gen/main.c | 6 -- .../boards/RA4M1_CLICKER/src/hal_entry.c | 58 ------------------ ports/renesas-ra/main.c | 4 +- ports/renesas-ra/ra_hal.c | 36 +++++++++++ 18 files changed, 39 insertions(+), 333 deletions(-) delete mode 100644 ports/renesas-ra/boards/EK_RA4M1/ra_gen/main.c delete mode 100644 ports/renesas-ra/boards/EK_RA4M1/src/hal_entry.c delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/ra_gen/main.c delete mode 100644 ports/renesas-ra/boards/EK_RA4W1/src/hal_entry.c delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/ra_gen/main.c delete mode 100644 ports/renesas-ra/boards/EK_RA6M1/src/hal_entry.c delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/ra_gen/main.c delete mode 100644 ports/renesas-ra/boards/EK_RA6M2/src/hal_entry.c delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/main.c delete mode 100644 ports/renesas-ra/boards/RA4M1_CLICKER/src/hal_entry.c create mode 100644 ports/renesas-ra/ra_hal.c diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index 85ffd9a1e9..2c9f917f36 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -297,6 +297,7 @@ DRIVERS_SRC_C += $(addprefix drivers/,\ SRC_C += \ boardctrl.c \ main.c \ + ra_hal.c \ ra_it.c \ mphalport.c \ mpthreadport.c \ @@ -325,13 +326,11 @@ SRC_C += \ flashbdev.c \ storage.c \ fatfs_port.c \ - $(BOARD_DIR)/src/hal_entry.c \ $(wildcard $(BOARD_DIR)/*.c) SRC_C += $(addprefix $(BOARD_DIR)/ra_gen/,\ common_data.c \ hal_data.c \ - main.c \ pin_data.c \ vector_data.c \ ) diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h index 7b1e505f68..635af82c2c 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/hal_data.h @@ -27,7 +27,5 @@ extern const flash_cfg_t g_flash0_cfg; void NULL(flash_callback_args_t *p_args); #endif -void hal_entry(void); - FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/main.c b/ports/renesas-ra/boards/EK_RA4M1/ra_gen/main.c deleted file mode 100644 index 5b9f980559..0000000000 --- a/ports/renesas-ra/boards/EK_RA4M1/ra_gen/main.c +++ /dev/null @@ -1,6 +0,0 @@ -/* generated main source file - do not edit */ -#include "hal_data.h" -int main(void) { - hal_entry(); - return 0; -} diff --git a/ports/renesas-ra/boards/EK_RA4M1/src/hal_entry.c b/ports/renesas-ra/boards/EK_RA4M1/src/hal_entry.c deleted file mode 100644 index c922cfd17a..0000000000 --- a/ports/renesas-ra/boards/EK_RA4M1/src/hal_entry.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "hal_data.h" - -FSP_CPP_HEADER -void R_BSP_WarmStart(bsp_warm_start_event_t event); -FSP_CPP_FOOTER - -void ra_main(uint32_t reset_mode); - -/*******************************************************************************************************************//** - * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function - * is called by main() when no RTOS is used. - **********************************************************************************************************************/ -void hal_entry(void) { - /* TODO: add your own code here */ - - ra_main(1); - - #if BSP_TZ_SECURE_BUILD - /* Enter non-secure code */ - R_BSP_NonSecureEnter(); - #endif -} - -/*******************************************************************************************************************//** - * This function is called at various points during the startup process. This implementation uses the event that is - * called right before main() to set up the pins. - * - * @param[in] event Where at in the start up process the code is currently at - **********************************************************************************************************************/ -void R_BSP_WarmStart(bsp_warm_start_event_t event) { - if (BSP_WARM_START_RESET == event) { - #if BSP_FEATURE_FLASH_LP_VERSION != 0 - - /* Enable reading from data flash. */ - R_FACI_LP->DFLCTL = 1U; - - /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and - * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ - #endif - } - - if (BSP_WARM_START_POST_C == event) { - /* C runtime environment and system clocks are setup. */ - - /* Configure pins. */ - R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); - } -} - -#if BSP_TZ_SECURE_BUILD - -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable(); - -/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */ -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable() { - -} -#endif diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h index 7b1e505f68..635af82c2c 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/hal_data.h @@ -27,7 +27,5 @@ extern const flash_cfg_t g_flash0_cfg; void NULL(flash_callback_args_t *p_args); #endif -void hal_entry(void); - FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/main.c b/ports/renesas-ra/boards/EK_RA4W1/ra_gen/main.c deleted file mode 100644 index 5b9f980559..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/ra_gen/main.c +++ /dev/null @@ -1,6 +0,0 @@ -/* generated main source file - do not edit */ -#include "hal_data.h" -int main(void) { - hal_entry(); - return 0; -} diff --git a/ports/renesas-ra/boards/EK_RA4W1/src/hal_entry.c b/ports/renesas-ra/boards/EK_RA4W1/src/hal_entry.c deleted file mode 100644 index 3e53787c61..0000000000 --- a/ports/renesas-ra/boards/EK_RA4W1/src/hal_entry.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "stdbool.h" -#include "hal_data.h" - -FSP_CPP_HEADER -void R_BSP_WarmStart(bsp_warm_start_event_t event); -FSP_CPP_FOOTER - -void ra_main(uint32_t reset_mode); - -/*******************************************************************************************************************//** - * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function - * is called by main() when no RTOS is used. - **********************************************************************************************************************/ -void hal_entry(void) { - /* TODO: add your own code here */ - - ra_main(1); - - #if BSP_TZ_SECURE_BUILD - /* Enter non-secure code */ - R_BSP_NonSecureEnter(); - #endif -} - -/*******************************************************************************************************************//** - * This function is called at various points during the startup process. This implementation uses the event that is - * called right before main() to set up the pins. - * - * @param[in] event Where at in the start up process the code is currently at - **********************************************************************************************************************/ -void R_BSP_WarmStart(bsp_warm_start_event_t event) { - if (BSP_WARM_START_RESET == event) { - #if BSP_FEATURE_FLASH_LP_VERSION != 0 - - /* Enable reading from data flash. */ - R_FACI_LP->DFLCTL = 1U; - - /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and - * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ - #endif - } - - if (BSP_WARM_START_POST_C == event) { - /* C runtime environment and system clocks are setup. */ - - /* Configure pins. */ - R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); - } -} - -#if BSP_TZ_SECURE_BUILD - -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable(); - -/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */ -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable() { - -} -#endif diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h index c661dfb183..bd940785ee 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/hal_data.h @@ -27,7 +27,5 @@ extern const flash_cfg_t g_flash0_cfg; void NULL(flash_callback_args_t *p_args); #endif -void hal_entry(void); - FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/main.c b/ports/renesas-ra/boards/EK_RA6M1/ra_gen/main.c deleted file mode 100644 index 5b9f980559..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/ra_gen/main.c +++ /dev/null @@ -1,6 +0,0 @@ -/* generated main source file - do not edit */ -#include "hal_data.h" -int main(void) { - hal_entry(); - return 0; -} diff --git a/ports/renesas-ra/boards/EK_RA6M1/src/hal_entry.c b/ports/renesas-ra/boards/EK_RA6M1/src/hal_entry.c deleted file mode 100644 index c922cfd17a..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M1/src/hal_entry.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "hal_data.h" - -FSP_CPP_HEADER -void R_BSP_WarmStart(bsp_warm_start_event_t event); -FSP_CPP_FOOTER - -void ra_main(uint32_t reset_mode); - -/*******************************************************************************************************************//** - * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function - * is called by main() when no RTOS is used. - **********************************************************************************************************************/ -void hal_entry(void) { - /* TODO: add your own code here */ - - ra_main(1); - - #if BSP_TZ_SECURE_BUILD - /* Enter non-secure code */ - R_BSP_NonSecureEnter(); - #endif -} - -/*******************************************************************************************************************//** - * This function is called at various points during the startup process. This implementation uses the event that is - * called right before main() to set up the pins. - * - * @param[in] event Where at in the start up process the code is currently at - **********************************************************************************************************************/ -void R_BSP_WarmStart(bsp_warm_start_event_t event) { - if (BSP_WARM_START_RESET == event) { - #if BSP_FEATURE_FLASH_LP_VERSION != 0 - - /* Enable reading from data flash. */ - R_FACI_LP->DFLCTL = 1U; - - /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and - * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ - #endif - } - - if (BSP_WARM_START_POST_C == event) { - /* C runtime environment and system clocks are setup. */ - - /* Configure pins. */ - R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); - } -} - -#if BSP_TZ_SECURE_BUILD - -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable(); - -/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */ -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable() { - -} -#endif diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h index 51fe21a160..5bb21e8880 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/hal_data.h @@ -23,6 +23,5 @@ extern const flash_instance_t g_flash0; extern flash_hp_instance_ctrl_t g_flash0_ctrl; extern const flash_cfg_t g_flash0_cfg; -void hal_entry(void); FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/main.c b/ports/renesas-ra/boards/EK_RA6M2/ra_gen/main.c deleted file mode 100644 index 5b9f980559..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/ra_gen/main.c +++ /dev/null @@ -1,6 +0,0 @@ -/* generated main source file - do not edit */ -#include "hal_data.h" -int main(void) { - hal_entry(); - return 0; -} diff --git a/ports/renesas-ra/boards/EK_RA6M2/src/hal_entry.c b/ports/renesas-ra/boards/EK_RA6M2/src/hal_entry.c deleted file mode 100644 index c922cfd17a..0000000000 --- a/ports/renesas-ra/boards/EK_RA6M2/src/hal_entry.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "hal_data.h" - -FSP_CPP_HEADER -void R_BSP_WarmStart(bsp_warm_start_event_t event); -FSP_CPP_FOOTER - -void ra_main(uint32_t reset_mode); - -/*******************************************************************************************************************//** - * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function - * is called by main() when no RTOS is used. - **********************************************************************************************************************/ -void hal_entry(void) { - /* TODO: add your own code here */ - - ra_main(1); - - #if BSP_TZ_SECURE_BUILD - /* Enter non-secure code */ - R_BSP_NonSecureEnter(); - #endif -} - -/*******************************************************************************************************************//** - * This function is called at various points during the startup process. This implementation uses the event that is - * called right before main() to set up the pins. - * - * @param[in] event Where at in the start up process the code is currently at - **********************************************************************************************************************/ -void R_BSP_WarmStart(bsp_warm_start_event_t event) { - if (BSP_WARM_START_RESET == event) { - #if BSP_FEATURE_FLASH_LP_VERSION != 0 - - /* Enable reading from data flash. */ - R_FACI_LP->DFLCTL = 1U; - - /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and - * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ - #endif - } - - if (BSP_WARM_START_POST_C == event) { - /* C runtime environment and system clocks are setup. */ - - /* Configure pins. */ - R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); - } -} - -#if BSP_TZ_SECURE_BUILD - -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable(); - -/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */ -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable() { - -} -#endif diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.h b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.h index 41019e6dd6..bec40a3910 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/hal_data.h @@ -24,6 +24,5 @@ extern const flash_instance_t g_flash0; extern flash_lp_instance_ctrl_t g_flash0_ctrl; extern const flash_cfg_t g_flash0_cfg; -void hal_entry(void); FSP_FOOTER #endif /* HAL_DATA_H_ */ diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/main.c b/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/main.c deleted file mode 100644 index 5b9f980559..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/ra_gen/main.c +++ /dev/null @@ -1,6 +0,0 @@ -/* generated main source file - do not edit */ -#include "hal_data.h" -int main(void) { - hal_entry(); - return 0; -} diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/src/hal_entry.c b/ports/renesas-ra/boards/RA4M1_CLICKER/src/hal_entry.c deleted file mode 100644 index c922cfd17a..0000000000 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/src/hal_entry.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "hal_data.h" - -FSP_CPP_HEADER -void R_BSP_WarmStart(bsp_warm_start_event_t event); -FSP_CPP_FOOTER - -void ra_main(uint32_t reset_mode); - -/*******************************************************************************************************************//** - * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function - * is called by main() when no RTOS is used. - **********************************************************************************************************************/ -void hal_entry(void) { - /* TODO: add your own code here */ - - ra_main(1); - - #if BSP_TZ_SECURE_BUILD - /* Enter non-secure code */ - R_BSP_NonSecureEnter(); - #endif -} - -/*******************************************************************************************************************//** - * This function is called at various points during the startup process. This implementation uses the event that is - * called right before main() to set up the pins. - * - * @param[in] event Where at in the start up process the code is currently at - **********************************************************************************************************************/ -void R_BSP_WarmStart(bsp_warm_start_event_t event) { - if (BSP_WARM_START_RESET == event) { - #if BSP_FEATURE_FLASH_LP_VERSION != 0 - - /* Enable reading from data flash. */ - R_FACI_LP->DFLCTL = 1U; - - /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and - * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ - #endif - } - - if (BSP_WARM_START_POST_C == event) { - /* C runtime environment and system clocks are setup. */ - - /* Configure pins. */ - R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); - } -} - -#if BSP_TZ_SECURE_BUILD - -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable(); - -/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */ -BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable() { - -} -#endif diff --git a/ports/renesas-ra/main.c b/ports/renesas-ra/main.c index 6ba26cd7ba..8f4baa8e2a 100644 --- a/ports/renesas-ra/main.c +++ b/ports/renesas-ra/main.c @@ -210,7 +210,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) { } #endif -void ra_main(uint32_t reset_mode) { +int main(void) { // Hook for a board to run code at start up, for example check if a // bootloader should be entered instead of the main application. MICROPY_BOARD_STARTUP(); @@ -256,7 +256,7 @@ void ra_main(uint32_t reset_mode) { #endif boardctrl_state_t state; - state.reset_mode = reset_mode; + state.reset_mode = 1; state.log_soft_reset = false; MICROPY_BOARD_BEFORE_SOFT_RESET_LOOP(&state); diff --git a/ports/renesas-ra/ra_hal.c b/ports/renesas-ra/ra_hal.c new file mode 100644 index 0000000000..13eb53d121 --- /dev/null +++ b/ports/renesas-ra/ra_hal.c @@ -0,0 +1,36 @@ +#include "hal_data.h" + +void R_BSP_WarmStart(bsp_warm_start_event_t event); + +// This function is called at various points during the startup process. +// event: where in the start up process the code is currently at. +void R_BSP_WarmStart(bsp_warm_start_event_t event) { + if (BSP_WARM_START_RESET == event) { + #if BSP_FEATURE_FLASH_LP_VERSION != 0 + + // Enable reading from data flash. + R_FACI_LP->DFLCTL = 1U; + + // Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the + // enable here, before clock and C runtime initialization, should negate the need + // for a delay since the initialization will typically take more than 6us. + #endif + } + + if (BSP_WARM_START_POST_C == event) { + // At this point, C runtime environment and system clocks are set up. + + // Configure pins. + R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); + } +} + +#if BSP_TZ_SECURE_BUILD + +BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable(); + +// Trustzone Secure Projects require at least one nonsecure callable function in order to build. +BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable() { +} + +#endif From ed7a3b11d9a6c21a964d55ebfcdefeb392389d10 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 May 2023 18:00:42 +1000 Subject: [PATCH 117/565] tools/pydfu.py: Use getattr to retrieve getargspec function. Since Python 3.11, inspect.getargspec() has been removed. Signed-off-by: Damien George --- tools/pydfu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pydfu.py b/tools/pydfu.py index 05cdf92c99..a9da3a0f83 100755 --- a/tools/pydfu.py +++ b/tools/pydfu.py @@ -77,7 +77,7 @@ __DFU_INTERFACE = 0 # Python 3 deprecated getargspec in favour of getfullargspec, but # Python 2 doesn't have the latter, so detect which one to use -getargspec = getattr(inspect, "getfullargspec", inspect.getargspec) +getargspec = getattr(inspect, "getfullargspec", getattr(inspect, "getargspec", None)) if "length" in getargspec(usb.util.get_string).args: # PyUSB 1.0.0.b1 has the length argument From b85611dae8ac13aa4c1eb37377a58cd77d04424e Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 31 May 2023 12:10:21 +1000 Subject: [PATCH 118/565] shared/libc/printf: Fix stdout destination for putchar and puts. These functions should output to the same location as printf in this file. Signed-off-by: Damien George --- shared/libc/printf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/shared/libc/printf.c b/shared/libc/printf.c index 6b5373188f..715181229e 100644 --- a/shared/libc/printf.c +++ b/shared/libc/printf.c @@ -72,16 +72,14 @@ int vprintf(const char *fmt, va_list ap) { // need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a') int putchar(int c) { char chr = c; - mp_hal_stdout_tx_strn_cooked(&chr, 1); + MICROPY_INTERNAL_PRINTF_PRINTER->print_strn(MICROPY_INTERNAL_PRINTF_PRINTER->data, &chr, 1); return chr; } // need this because gcc optimises printf("string\n") -> puts("string") int puts(const char *s) { - mp_hal_stdout_tx_strn_cooked(s, strlen(s)); - char chr = '\n'; - mp_hal_stdout_tx_strn_cooked(&chr, 1); - return 1; + MICROPY_INTERNAL_PRINTF_PRINTER->print_strn(MICROPY_INTERNAL_PRINTF_PRINTER->data, s, strlen(s)); + return putchar('\n'); // will return 10, which is >0 per specs of puts } typedef struct _strn_print_env_t { From 5a991b4290bd4df608e342fcea563f29738de713 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 30 May 2023 21:44:36 +0200 Subject: [PATCH 119/565] extmod/moduos: Move os.sync() into extmod/moduos.c. Avoiding code duplication. To enable it, set MICROPY_PY_UOS_SYNC in the port's mpconfigport.h. It is operational only for FAT file system. For other filesystems it's a no-op. Signed-off-by: robert-hh --- extmod/moduos.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/extmod/moduos.c b/extmod/moduos.c index 87a611148d..a245ae7283 100644 --- a/extmod/moduos.c +++ b/extmod/moduos.c @@ -34,6 +34,10 @@ #if MICROPY_VFS_FAT #include "extmod/vfs_fat.h" +#if MICROPY_PY_UOS_SYNC +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" +#endif #endif #if MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2 @@ -58,6 +62,21 @@ #define MICROPY_BUILD_TYPE_PAREN #endif +#if MICROPY_PY_UOS_SYNC +// sync() +// Sync all filesystems. +STATIC mp_obj_t mp_uos_sync(void) { + #if MICROPY_VFS_FAT + for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { + // this assumes that vfs->obj is fs_user_mount_t with block device functions + disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL); + } + #endif + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_sync_obj, mp_uos_sync); +#endif + #if MICROPY_PY_UOS_UNAME #if MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC From 1c53bda27f8e7504e5895d3d32bc183e3503420e Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 31 May 2023 10:22:19 +0200 Subject: [PATCH 120/565] ports: Remove os.sync() implementation from stm32 and renesas-ra. Now that this code was moved to extmod/moduos.c. Signed-off-by: robert-hh --- ports/renesas-ra/moduos.c | 18 ------------------ ports/stm32/moduos.c | 18 ------------------ 2 files changed, 36 deletions(-) diff --git a/ports/renesas-ra/moduos.c b/ports/renesas-ra/moduos.c index ec1929fef1..6f524f119f 100644 --- a/ports/renesas-ra/moduos.c +++ b/ports/renesas-ra/moduos.c @@ -28,24 +28,6 @@ #include "py/runtime.h" #include "uart.h" -#if MICROPY_VFS_FAT -#include "lib/oofatfs/ff.h" -#include "lib/oofatfs/diskio.h" -#endif - -// sync() -// Sync all filesystems. -STATIC mp_obj_t mp_uos_sync(void) { - #if MICROPY_VFS_FAT - for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { - // this assumes that vfs->obj is fs_user_mount_t with block device functions - disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL); - } - #endif - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_sync_obj, mp_uos_sync); - bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream) { const mp_obj_type_t *type = mp_obj_get_type(stream); return type == &machine_uart_type; diff --git a/ports/stm32/moduos.c b/ports/stm32/moduos.c index 85d0edeca8..1f41e68bde 100644 --- a/ports/stm32/moduos.c +++ b/ports/stm32/moduos.c @@ -29,24 +29,6 @@ #include "usb.h" #include "uart.h" -#if MICROPY_VFS_FAT -#include "lib/oofatfs/ff.h" -#include "lib/oofatfs/diskio.h" -#endif - -// sync() -// Sync all filesystems. -STATIC mp_obj_t mp_uos_sync(void) { - #if MICROPY_VFS_FAT - for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { - // this assumes that vfs->obj is fs_user_mount_t with block device functions - disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL); - } - #endif - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_sync_obj, mp_uos_sync); - #if MICROPY_PY_UOS_URANDOM // urandom(n) // Return a bytes object with n random bytes, generated by the hardware From 73cc6b750e0709170183ce7da89af618eae40329 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 31 May 2023 10:32:55 +0200 Subject: [PATCH 121/565] ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51. These have by default FAT support. The SAMD21 build does not support FAT. The nrf port also implements os.sync(), but has it's own copy of moduos.c. Code size increases seen: 40 to 56 bytes. Signed-off-by: robert-hh --- ports/esp32/mpconfigport.h | 1 + ports/esp8266/mpconfigport.h | 1 + ports/mimxrt/mpconfigport.h | 1 + ports/rp2/mpconfigport.h | 1 + ports/samd/mcu/samd51/mpconfigmcu.h | 1 + 5 files changed, 5 insertions(+) diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index ea3487bcd8..4701040e66 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -91,6 +91,7 @@ #define MICROPY_PY_UOS_INCLUDEFILE "ports/esp32/moduos.c" #define MICROPY_PY_OS_DUPTERM (1) #define MICROPY_PY_UOS_DUPTERM_NOTIFY (1) +#define MICROPY_PY_UOS_SYNC (1) #define MICROPY_PY_UOS_UNAME (1) #define MICROPY_PY_UOS_URANDOM (1) #define MICROPY_PY_MACHINE (1) diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index 12ea3716d4..0cfb83f73e 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -87,6 +87,7 @@ #define MICROPY_PY_OS_DUPTERM (2) #define MICROPY_PY_UOS_DUPTERM_NOTIFY (1) #define MICROPY_PY_UOS_DUPTERM_STREAM_DETACHED_ATTACHED (1) +#define MICROPY_PY_UOS_SYNC (1) #define MICROPY_PY_UOS_UNAME (1) #define MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC (1) #define MICROPY_PY_UOS_URANDOM (1) diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 4482e54960..52301cf94b 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -76,6 +76,7 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_UOS_INCLUDEFILE "ports/mimxrt/moduos.c" #define MICROPY_PY_OS_DUPTERM (3) #define MICROPY_PY_UOS_DUPTERM_NOTIFY (1) +#define MICROPY_PY_UOS_SYNC (1) #define MICROPY_PY_UOS_UNAME (1) #define MICROPY_PY_UOS_URANDOM (1) #define MICROPY_PY_URANDOM_SEED_INIT_FUNC (trng_random_u32()) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index b4487a23d7..720e858f19 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -99,6 +99,7 @@ #ifndef MICROPY_PY_OS_DUPTERM #define MICROPY_PY_OS_DUPTERM (1) #endif +#define MICROPY_PY_UOS_SYNC (1) #define MICROPY_PY_UOS_UNAME (1) #define MICROPY_PY_UOS_URANDOM (1) #define MICROPY_PY_URE_MATCH_GROUPS (1) diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index 07d4696901..0c2d2370ff 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -27,6 +27,7 @@ #define MICROPY_PY_MACHINE_DHT_READINTO (1) #define MICROPY_PY_ONEWIRE (1) +#define MICROPY_PY_UOS_SYNC (1) #define MICROPY_PY_UOS_URANDOM (1) #define MICROPY_PY_URANDOM_SEED_INIT_FUNC (trng_random_u32()) unsigned long trng_random_u32(void); From 8f6315a279a7a5b2373902d6d9a868a1f8a4dbb2 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 25 May 2023 14:05:19 +0200 Subject: [PATCH 122/565] mimxrt/machine_pwm: Fix freq change, PWM print, and error checks. Three bugs have been fixed in this commit: 1. When the duty was set with duty_u16(), changing the freq with pwm.freq() would not keep relative duty rate, but the absolute pulse duration. 2. Fix another inconsistency when displaying the PWM pin's properties of a QTMR channel. 3. Improve the error checks for the second channel being a PWM pin and pin pairs to be a FLEXPWM A/B pair. Signed-off-by: robert-hh --- ports/mimxrt/machine_pwm.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ports/mimxrt/machine_pwm.c b/ports/mimxrt/machine_pwm.c index b8b526ae02..a50b67cc8c 100644 --- a/ports/mimxrt/machine_pwm.c +++ b/ports/mimxrt/machine_pwm.c @@ -91,7 +91,7 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p } else { mp_printf(print, "module, self->channel1, self->freq); - if (self->duty_ns == VALUE_NOT_SET) { + if (self->duty_ns != VALUE_NOT_SET) { mp_printf(print, "duty_ns=%d>", self->duty_ns); } else { mp_printf(print, "duty_u16=%d>", self->duty_u16); @@ -110,10 +110,6 @@ STATIC uint32_t duty_ns_to_duty_u16(uint32_t freq, uint32_t duty_ns) { return (uint32_t)duty; } -STATIC uint32_t duty_u16_to_duty_ns(machine_pwm_obj_t *self) { - return 1000000000ULL * (uint64_t)self->duty_u16 / self->freq / PWM_FULL_SCALE; -} - STATIC uint8_t module_decode(char channel) { switch (channel) { case '0': @@ -349,8 +345,6 @@ STATIC void configure_pwm(machine_pwm_obj_t *self) { if (self->freq != VALUE_NOT_SET && (self->duty_u16 != VALUE_NOT_SET || self->duty_ns != VALUE_NOT_SET)) { if (self->duty_ns != VALUE_NOT_SET) { self->duty_u16 = duty_ns_to_duty_u16(self->freq, self->duty_ns); - } else { - self->duty_ns = duty_u16_to_duty_ns(self); } if (self->is_flexpwm) { configure_flexpwm(self); @@ -489,6 +483,9 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args break; } } + if (af_obj2 == NULL) { + mp_raise_ValueError(MP_ERROR_TEXT("the second Pin doesn't support PWM")); + } } if (af_obj1 == NULL) { submodule1 = 0; @@ -504,12 +501,12 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args } #endif if (af_obj1 == NULL) { - mp_raise_ValueError(MP_ERROR_TEXT("the requested Pin(s) does not support PWM")); + mp_raise_ValueError(MP_ERROR_TEXT("the first Pin doesn't support PWM")); } } else { // is flexpwm, check for instance match is_flexpwm = true; - if (pin2 != NULL && af_obj1->instance != af_obj2->instance && submodule1 != submodule2) { + if (pin2 != NULL && (af_obj1->instance != af_obj2->instance || submodule1 != submodule2)) { mp_raise_ValueError(MP_ERROR_TEXT("the pins must be a A/B pair of a submodule")); } } From 6c0af30e385063e0e02a5bea6d3be521b62c3e80 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Mon, 29 May 2023 11:38:49 +0200 Subject: [PATCH 123/565] mimxrt/Makefile: Use a specific fsl_flexspi_nor_boot.c for mimxrt1062. This one sets the flash image length properly for the teensy loader, such that the file system is not erased. It was already set in commit 8e542251405d780f7aa0d6c9abaa30282dd360d5 but got lost when the MIMXRT1176 board was added. Signed-off-by: robert-hh --- ports/mimxrt/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index dd053b3dc1..cfef8ee0f9 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -140,7 +140,13 @@ SRC_HAL_IMX_C += \ $(MCU_DIR)/drivers/fsl_snvs_lp.c \ $(MCU_DIR)/drivers/fsl_wdog.c \ $(MCU_DIR)/system_$(MCU_SERIES)$(MCU_CORE).c \ - $(MCU_DIR)/xip/fsl_flexspi_nor_boot.c \ + +# Use a specific boot header for 1062 so the Teensy loader doesn't erase the filesystem. +ifeq ($(MCU_SERIES), MIMXRT1062) +SRC_HAL_IMX_C += hal/fsl_flexspi_nor_boot.c +else +SRC_HAL_IMX_C += $(MCU_DIR)/xip/fsl_flexspi_nor_boot.c +endif ifeq ($(MICROPY_HW_SDRAM_AVAIL),1) SRC_HAL_IMX_C += $(MCU_DIR)/drivers/fsl_semc.c From 74dda8023673264d0d113450d12c6bee1d880d62 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 25 May 2023 15:16:38 +0200 Subject: [PATCH 124/565] docs/mimxrt: Add the pin-out for the Adafruit Metro M7 board. Signed-off-by: robert-hh --- docs/mimxrt/pinout.rst | 102 +++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/docs/mimxrt/pinout.rst b/docs/mimxrt/pinout.rst index ef53fa63bf..b5a7fbbfe0 100644 --- a/docs/mimxrt/pinout.rst +++ b/docs/mimxrt/pinout.rst @@ -14,9 +14,9 @@ The pin assignment of UARTs to pins is fixed. The UARTs are numbered 0..8. The rx/tx pins are assigned according to the tables below: -================ =========== =========== =========== =========== +================= =========== =========== =========== =========== Board / Pin UART0 UART1 UART2 UART3 -================ =========== =========== =========== =========== +================= =========== =========== =========== =========== Teensy 4.0 - 0/1 7/8 14/15 Teensy 4.1 - 0/1 7/8 14/15 MIMXRT1010-EVK Debug USB D0/D1 D7/D6 - @@ -27,9 +27,10 @@ MIMXRT1050-EVKB Debug USB D0/D1 D7/D6 D8/D9 MIMXRT1060-EVK Debug USB D0/D1 D7/D6 D8/D9 MIMXRT1064-EVK Debug USB D0/D1 D7/D6 D8/D9 MIMXRT1170-EVK Debug USB D0/D1 D12/D11 D10/D13 +Adafruit Metro M7 - D0/D1 D7/D3 A1/A0 Olimex RT1010Py - RxD/TxD D5/D6 - -Seeed ARCH MIX - J3_19/J3_20 J4_16/J4_17 J4_06/J4_07 -================ =========== =========== =========== =========== +Seeed ARCH MIX - J3_19/J3_20 J4_16/J4_17 J4_06/J4_07 +================= =========== =========== =========== =========== | @@ -61,38 +62,38 @@ PWM pin assignment Pins are specified in the same way as for the Pin class. The following tables show the assignment of the board Pins to PWM modules: -=========== ========== ========== ====== ============== ====== -Pin/ MIMXRT 1010 1015 1020 1050/1060/1064 1170 -=========== ========== ========== ====== ============== ====== -D0 - Q1/1 F1/1/B - - -D1 - Q1/0 F1/1/A - - -D2 F1/3/B F1/3/A - F1/3/B - -D3 F1/3/A F1/0/A F2/3/B F4/0/A F1/2/A -D4 F1/3/A (*) Q1/2 Q2/1 F2/3/A Q4/2 -D5 F1/0/B (*) F1/0/B F2/3/A F1/3/A F1/2/B -D6 - F1/2/B F2/0/A Q3/2 F1/0/A -D7 - - F1/0/A Q3/3 - -D8 F1/0/A F1/1/B F1/0/B F1/1/X Q4/3 -D9 F1/1/B (*) F1/2/A F2/0/B F1/0/X F1/0/B -D10 F1/3/B - F2/2/B F1/0/B (*) F2/2/B -D11 F1/2/A - F2/1/A F1/1/A (*) - -D12 F1/2/B - F2/1/B F1/1/B (*) - -D13 F1/3/A - F2/2/A F1/0/A (*) F2/2/A -D14 F1/0/B - - F2/3/B - -D15 F1/0/A - - F2/3/A - -A0 - - F1/2/A - - -A1 F1/3/X F1/3/B F1/2/B - - -A2 F1/2/X F1/3/A F1/3/A - - -A3 - F1/2/A F1/3/B - - -A4 - - - Q3/1 - -A5 - - - Q3/0 - -D31 - - - - F1/2/B -D32 - - - - F1/2/A -D33 - - - - F1/1/B -D34 - - - - F1/1/A -D35 - - - - F1/0/B -D36 - - - - F1/0/A -=========== ========== ========== ====== ============== ====== +=========== ========== ========== ====== ========== ====== ======== +Pin/ MIMXRT 1010 1015 1020 1050/60/64 1170 Metro M7 +=========== ========== ========== ====== ========== ====== ======== +D0 - Q1/1 F1/1/B - - - +D1 - Q1/0 F1/1/A - - - +D2 F1/3/B F1/3/A - F1/3/B - - +D3 F1/3/A F1/0/A F2/3/B F4/0/A F1/2/A - +D4 F1/3/A (*) Q1/2 Q2/1 F2/3/A Q4/2 F1/0/B +D5 F1/0/B (*) F1/0/B F2/3/A F1/3/A F1/2/B F1/0/A +D6 - F1/2/B F2/0/A Q3/2 F1/0/A - +D7 - - F1/0/A Q3/3 - - +D8 F1/0/A F1/1/B F1/0/B F1/1/X Q4/3 F1/3/A +D9 F1/1/B (*) F1/2/A F2/0/B F1/0/X F1/0/B F1/3/B +D10 F1/3/B - F2/2/B F1/0/B (*) F2/2/B F1/2/A +D11 F1/2/A - F2/1/A F1/1/A (*) - F1/2/B +D12 F1/2/B - F2/1/B F1/1/B (*) - F1/1/A +D13 F1/3/A - F2/2/A F1/0/A (*) F2/2/A F1/1/B +D14 F1/0/B - - F2/3/B - F1/0/B +D15 F1/0/A - - F2/3/A - F1/0/A +A0 - - F1/2/A - - - +A1 F1/3/X F1/3/B F1/2/B - - - +A2 F1/2/X F1/3/A F1/3/A - - - +A3 - F1/2/A F1/3/B - - F1/3/B +A4 - - - Q3/1 - F1/2/X +A5 - - - Q3/0 - - +D31 - - - - F1/2/B - +D32 - - - - F1/2/A - +D33 - - - - F1/1/B - +D34 - - - - F1/1/A - +D35 - - - - F1/0/B - +D36 - - - - F1/0/A - +=========== ========== ========== ====== ========== ====== ======== Pins denoted with (*) are by default not wired at the board. @@ -318,6 +319,7 @@ MIXMXRT1050-EVKB D10/-/D11/D12/D13 (*) - - MIXMXRT1060-EVK D10/-/D11/D12/D13 (*) - - MIXMXRT1064-EVK D10/-/D11/D12/D13 (*) - - MIXMXRT1170-EVK D10/-/D11/D12/D13 D28/-/D25/D24/D26 -/-/D14/D15/D24 +Adafruit Metro M7 -/-/MOSI/MISO/SCK - - Olimex RT1010Py - CS0/-/SDO/SDI/SCK SDCARD with CS1 Seeed ARCH MIX J4_12/-/J4_14/J4_13/J4_15 J3_09/J3_05/J3_08_J3_11 ================= ========================= ======================= =============== @@ -350,6 +352,7 @@ MIXMXRT1050-EVKB A4/A5 D1/D0 - - - MIXMXRT1060-EVK A4/A5 D1/D0 - - - MIXMXRT1064-EVK A4/A5 D1/D0 - - - MIXMXRT1170-EVK D14/D15 D1/D0 A4/A5 D26/D25 D19/D18 +Adafruit Metro M7 D14/D15 D0/D1 Olimex RT1010Py - SDA1/SCL1 SDA2/SCL2 - - Seeed ARCH MIX J3_17/J3_16 J4_06/J4_07 J5_05/J5_04 - - ================= =========== =========== =========== ======= ======= @@ -364,18 +367,19 @@ Hardware I2S pin assignment Pin assignments for a few MIMXRT boards: -=============== == ===== ======== ======= ======= ======== ======= ======= -Board ID MCK SCK_TX WS_TX SD_TX SCK_RX WS_RX SD_RX -=============== == ===== ======== ======= ======= ======== ======= ======= -Teensy 4.0 1 23 26 27 7 21 20 8 -Teensy 4.0 2 33 4 3 2 - - 5 -Teensy 4.1 1 23 26 27 7 21 20 8 -Teensy 4.1 2 33 4 3 2 - - 5 -Seeed Arch MIX 1 J4_09 J4_14 J4_15 J14_13 J4_11 J4_10 J4_10 -Olimex RT1010Py 1 D8 D6 D7 D4 D1 D2 D3 -Olimex RT1010Py 3 - D10 D9 D11 - - - -MIMXRT_DEV 1 "MCK" "SCK_TX" "WS_TX" "SD_TX" "SCK_RX" "WS_RX" "SD_RX" -=============== == ===== ======== ======= ======= ======== ======= ======= +================= == ===== ======== ======= ======= ======== ======= ======= +Board ID MCK SCK_TX WS_TX SD_TX SCK_RX WS_RX SD_RX +================= == ===== ======== ======= ======= ======== ======= ======= +Teensy 4.0 1 23 26 27 7 21 20 8 +Teensy 4.0 2 33 4 3 2 - - 5 +Teensy 4.1 1 23 26 27 7 21 20 8 +Teensy 4.1 2 33 4 3 2 - - 5 +Seeed Arch MIX 1 J4_09 J4_14 J4_15 J14_13 J4_11 J4_10 J4_10 +Adafruit Metro M7 1 D8 D10 D9 D12 D14 D15 D13 +Olimex RT1010Py 1 D8 D6 D7 D4 D1 D2 D3 +Olimex RT1010Py 3 - D10 D9 D11 - - - +MIMXRT_DEV 1 "MCK" "SCK_TX" "WS_TX" "SD_TX" "SCK_RX" "WS_RX" "SD_RX" +================= == ===== ======== ======= ======= ======== ======= ======= Symbolic pin names are provided for the MIMXRT_10xx_DEV boards. -These are provided for the other boards as well. \ No newline at end of file +These are provided for the other boards as well. From 633408a4a5574402a22cf5fc720ac8ad7310151b Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 25 May 2023 16:03:42 +0200 Subject: [PATCH 125/565] docs/samd: Add the pin-out for the Adafruit Metro M4 Airlift board. Signed-off-by: robert-hh --- docs/samd/pinout.rst | 69 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/docs/samd/pinout.rst b/docs/samd/pinout.rst index 64db455eac..212275a014 100644 --- a/docs/samd/pinout.rst +++ b/docs/samd/pinout.rst @@ -334,6 +334,75 @@ The default devices at the board are: - SPI 1 at pins PA23/PA22/PA17, labelled MOSI, MISO and SCK - DAC output on pins PA02 and PA05, labelled A0 and A1 +Adafruit Metro M4 Airlift pin assignment table +---------------------------------------------- + +=== ==== ============ ==== ==== ==== ====== ====== ===== ===== ===== +Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM +=== ==== ============ ==== ==== ==== ====== ====== ===== ===== ===== + 2 PA02 A0 2 0 - - - - - - + 5 PA05 A1 5 5 - - 0/1 0/1 - - + 6 PA06 A2 6 6 - - 0/2 1/0 - - + 32 PB00 A3 9 12 - - 5/2 7/0 - - + 40 PB08 A4 8 2 0 - 4/0 4/0 - - + 41 PB09 A5 9 3 1 - 4/1 4/1 - - + 23 PA23 D0 7 - - 3/1 5/0 4/1 1/7 0/3 + 22 PA22 D1 6 - - 3/0 5/1 4/0 1/6 0/2 + 49 PB17 D2 1 - - 5/1 - 6/1 3/1 0/5 + 48 PB16 D3 0 - - 5/0 - 6/0 3/0 0/4 + 45 PB13 D4 13 - - 4/1 - 4/1 3/1 0/1 + 46 PB14 D5 14 - - 4/2 - 5/0 4/0 0/2 + 47 PB15 D6 15 - - 4/3 - 5/1 4/1 0/3 + 44 PB12 D7 12 - - 4/0 - 4/0 3/0 0/0 + 21 PA21 D8 5 - - 5/3 3/3 7/1 1/5 0/1 + 20 PA20 D9 4 - - 5/2 3/2 7/0 1/4 0/0 + 3 PA03 AREF 3 10 - - - - - - + 18 PA18 D10 2 - - 1/2 3/2 3/0 1/2 0/6 + 19 PA19 D11 3 - - 1/3 3/3 3/1 1/3 0/7 + 16 PA16 D13 0 - - 1/0 3/1 2/0 1/0 0/4 + 36 PB04 ESP_BUSY 4 - 6 - - - - - + 15 PA15 ESP_CS 15 - - 2/3 4/3 3/1 2/1 1/3 + 33 PB01 ESP_GPIO0 1 13 - - 5/3 7/1 - - + 37 PB05 ESP_RESET 5 - 7 - - - - - + 55 PB23 ESP_RTS 7 - - 1/3 5/3 7/1 - - + 7 PA07 ESP_RX 7 7 - - 0/3 1/1 - - + 4 PA04 ESP_TX 4 4 - - 0/0 0/0 - - + 43 PB11 FLASH_CS 12 - - - 4/3 5/1 0/5 1/1 + 11 PA11 FLASH_HOLD 11 11 - 0/3 2/3 1/1 0/3 1/7 + 9 PA09 FLASH_MISO 9 9 3 0/1 2/0 0/1 0/1 1/5 + 8 PA08 FLASH_MOSI - 8 2 0/0 2/1 0/0 0/0 1/4 + 42 PB10 FLASH_SCK 10 - - - 4/2 5/0 0/4 1/0 + 10 PA10 FLASH_WP 10 10 - 0/2 2/2 1/0 0/2 1/6 + 14 PA14 MISO 14 - - 2/2 4/2 3/0 2/0 1/2 + 12 PA12 MOSI 12 - - 2/0 4/1 2/0 0/6 1/2 + 54 PB22 NEOPIXEL 22 - - 1/2 5/2 7/0 - - + 38 PB06 RXLED 6 - 8 - - - - - + 13 PA13 SCK 13 - - 2/1 4/0 2/1 0/7 1/3 + 35 PB03 SCL 9 15 - - 5/1 6/1 - - + 34 PB02 SDA 2 14 - - 5/0 6/0 2/2 - + 30 PA30 SWCLK 14 - - 7/2 1/2 6/0 2/0 - + 31 PA31 SWDIO 15 - - 7/3 1/3 6/1 2/1 - + 62 PB30 SWO 14 - - 7/0 5/1 0/0 4/0 0/6 + 39 PB07 TXLED 7 - 9 - - - - - + 24 PA24 USB_DM 8 - - 3/2 5/2 5/0 2/2 - + 25 PA25 USB_DP 9 - - 3/3 5/3 5/1 - - + 17 PA17 USB_HOSTEN 1 - - 1/1 3/0 2/1 1/1 0/5 + 0 PA00 - 0 - - - 1/0 2/0 - - + 1 PA01 - 1 - - - 1/1 2/1 - - + 27 PA27 - 11 - - - - - - - + 63 PB31 - 15 - - 7/1 5/0 0/1 4/1 0/7 +=== ==== ============ ==== ==== ==== ====== ====== ===== ===== ===== + +For the definition of the table columns see the explanation at the table +for Adafruit ItsyBitsy M4 Express :ref:`samd51_pinout_table`. + +The default devices at the board are: + +- UART 3 at pins PA23/PA22, labelled D0/D1 resp. RX/TX +- I2C 5 at pins PB02/PB03, labelled SDA/SCL +- SPI 4 at pins PA12/PA14/PA13, labelled MOSI, MISO and SCK +- DAC output on pins PA02 and PA05, labelled A0 and A1 + SEEED XIAO pin assignment table ------------------------------- From 1f608411231e2a02318a24d64ebc4c9385674a84 Mon Sep 17 00:00:00 2001 From: Takeo Takahashi Date: Mon, 29 May 2023 19:23:52 +0900 Subject: [PATCH 126/565] renesas-ra/boards/make-pins.py: Fix PA/PB pins support. Signed-off-by: Takeo Takahashi --- ports/renesas-ra/boards/make-pins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/renesas-ra/boards/make-pins.py b/ports/renesas-ra/boards/make-pins.py index 98d7026c21..1b4588f02f 100644 --- a/ports/renesas-ra/boards/make-pins.py +++ b/ports/renesas-ra/boards/make-pins.py @@ -140,7 +140,7 @@ class Pins(object): for row in rows: try: cpu_pin_name = row[0] - cpu_pin_port = int(row[1]) + cpu_pin_port = int(row[1], 16) cpu_pin_bit = int(row[2]) except: continue From 3ae78e803b69c4f1fd5dfe7eb732de7075f12e6c Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Jun 2023 12:33:23 +1000 Subject: [PATCH 127/565] tests/basics: Remove __index__ and __inv__ from special methods tests. MicroPython does not support these special methods, and they may get in the way of other tests (eg indexing with __int__). Signed-off-by: Damien George --- tests/basics/special_methods.py | 6 ------ tests/basics/special_methods2.py | 6 ------ 2 files changed, 12 deletions(-) diff --git a/tests/basics/special_methods.py b/tests/basics/special_methods.py index d8af8e0797..fc3d9dd768 100644 --- a/tests/basics/special_methods.py +++ b/tests/basics/special_methods.py @@ -37,12 +37,6 @@ class Cud(): def __floordiv__(self, other): print("__floordiv__ called") - def __index__(self, other): - print("__index__ called") - - def __inv__(self): - print("__inv__ called") - def __invert__(self): print("__invert__ called") diff --git a/tests/basics/special_methods2.py b/tests/basics/special_methods2.py index 31f330ab42..8a47690b2e 100644 --- a/tests/basics/special_methods2.py +++ b/tests/basics/special_methods2.py @@ -38,12 +38,6 @@ class Cud(): def __floordiv__(self, other): print("__floordiv__ called") - def __index__(self, other): - print("__index__ called") - - def __inv__(self): - print("__inv__ called") - def __invert__(self): print("__invert__ called") From 48ffd6596e7a4c185a81be233b46d3c99a83a7ac Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 25 May 2023 10:57:08 +1000 Subject: [PATCH 128/565] py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE. To be consistent with MP_UNARY_OP_INT_FLOAT and MP_UNARY_OP_INT_COMPLEX, and allow int() to first check if a type supports __int__ before trying other things (as per CPython). Signed-off-by: Damien George --- extmod/moductypes.c | 2 +- py/obj.c | 15 +++------- py/objint.c | 11 ++++---- py/objint_longlong.c | 2 ++ py/objint_mpz.c | 2 ++ py/objtype.c | 4 +-- py/runtime.c | 39 +++++++++++++------------- py/runtime.h | 1 + py/runtime0.h | 2 +- tests/basics/int_big1.py | 3 ++ tests/basics/special_methods_intbig.py | 8 ++++++ 11 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 tests/basics/special_methods_intbig.py diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 15c36290a9..86d82f03ba 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -582,7 +582,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { - case MP_UNARY_OP_INT: + case MP_UNARY_OP_INT_MAYBE: if (mp_obj_is_type(self->desc, &mp_type_tuple)) { mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc); mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]); diff --git a/py/obj.c b/py/obj.c index 7e26d4c7fd..dc69194672 100644 --- a/py/obj.c +++ b/py/obj.c @@ -298,18 +298,11 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) { // This function essentially performs implicit type conversion to int // Note that Python does NOT provide implicit type conversion from // float to int in the core expression language, try some_list[1.0]. - if (arg == mp_const_false) { - return 0; - } else if (arg == mp_const_true) { - return 1; - } else if (mp_obj_is_small_int(arg)) { - return MP_OBJ_SMALL_INT_VALUE(arg); - } else if (mp_obj_is_exact_type(arg, &mp_type_int)) { - return mp_obj_int_get_checked(arg); - } else { - mp_obj_t res = mp_unary_op(MP_UNARY_OP_INT, (mp_obj_t)arg); - return mp_obj_int_get_checked(res); + mp_int_t val; + if (!mp_obj_get_int_maybe(arg, &val)) { + mp_raise_TypeError_int_conversion(arg); } + return val; } mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg) { diff --git a/py/objint.c b/py/objint.c index 1a3ad86947..e54cdb89b5 100644 --- a/py/objint.c +++ b/py/objint.c @@ -48,10 +48,10 @@ STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, case 0: return MP_OBJ_NEW_SMALL_INT(0); - case 1: - if (mp_obj_is_int(args[0])) { - // already an int (small or long), just return it - return args[0]; + case 1: { + mp_obj_t o = mp_unary_op(MP_UNARY_OP_INT_MAYBE, args[0]); + if (o != MP_OBJ_NULL) { + return o; } else if (mp_obj_is_str_or_bytes(args[0])) { // a string, parse it size_t l; @@ -62,8 +62,9 @@ STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, return mp_obj_new_int_from_float(mp_obj_float_get(args[0])); #endif } else { - return mp_unary_op(MP_UNARY_OP_INT, args[0]); + mp_raise_TypeError_int_conversion(args[0]); } + } case 2: default: { diff --git a/py/objint_longlong.c b/py/objint_longlong.c index 1c07588367..ee499e0265 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -119,6 +119,8 @@ mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) { self->val = -self->val; return MP_OBJ_FROM_PTR(self); } + case MP_UNARY_OP_INT_MAYBE: + return o_in; default: return MP_OBJ_NULL; // op not supported } diff --git a/py/objint_mpz.c b/py/objint_mpz.c index e9545149f8..8078441d66 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -165,6 +165,8 @@ mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mpz_abs_inpl(&self2->mpz, &self->mpz); return MP_OBJ_FROM_PTR(self2); } + case MP_UNARY_OP_INT_MAYBE: + return o_in; default: return MP_OBJ_NULL; // op not supported } diff --git a/py/objtype.c b/py/objtype.c index 04bdf5acd7..772f25d744 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -374,7 +374,7 @@ const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = { [MP_UNARY_OP_BOOL] = MP_QSTR___bool__, [MP_UNARY_OP_LEN] = MP_QSTR___len__, [MP_UNARY_OP_HASH] = MP_QSTR___hash__, - [MP_UNARY_OP_INT] = MP_QSTR___int__, + [MP_UNARY_OP_INT_MAYBE] = MP_QSTR___int__, #if MICROPY_PY_ALL_SPECIAL_METHODS [MP_UNARY_OP_POSITIVE] = MP_QSTR___pos__, [MP_UNARY_OP_NEGATIVE] = MP_QSTR___neg__, @@ -432,7 +432,7 @@ STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) { // __hash__ must return a small int val = MP_OBJ_NEW_SMALL_INT(mp_obj_get_int_truncated(val)); break; - case MP_UNARY_OP_INT: + case MP_UNARY_OP_INT_MAYBE: // Must return int if (!mp_obj_is_int(val)) { mp_raise_TypeError(NULL); diff --git a/py/runtime.c b/py/runtime.c index 3434d9cc48..99f7f6109b 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -277,7 +277,7 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) { case MP_UNARY_OP_HASH: return arg; case MP_UNARY_OP_POSITIVE: - case MP_UNARY_OP_INT: + case MP_UNARY_OP_INT_MAYBE: return arg; case MP_UNARY_OP_NEGATIVE: // check for overflow @@ -324,32 +324,23 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) { // if arg==mp_const_none. return mp_const_true; } - #if MICROPY_PY_BUILTINS_FLOAT - if (op == MP_UNARY_OP_FLOAT_MAYBE + if (op == MP_UNARY_OP_INT_MAYBE + #if MICROPY_PY_BUILTINS_FLOAT + || op == MP_UNARY_OP_FLOAT_MAYBE #if MICROPY_PY_BUILTINS_COMPLEX || op == MP_UNARY_OP_COMPLEX_MAYBE #endif + #endif ) { + // These operators may return MP_OBJ_NULL if they are not supported by the type. return MP_OBJ_NULL; } - #endif - // With MP_UNARY_OP_INT, mp_unary_op() becomes a fallback for mp_obj_get_int(). - // In this case provide a more focused error message to not confuse, e.g. chr(1.0) #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE - if (op == MP_UNARY_OP_INT) { - mp_raise_TypeError(MP_ERROR_TEXT("can't convert to int")); - } else { - mp_raise_TypeError(MP_ERROR_TEXT("unsupported type for operator")); - } + mp_raise_TypeError(MP_ERROR_TEXT("unsupported type for operator")); #else - if (op == MP_UNARY_OP_INT) { - mp_raise_msg_varg(&mp_type_TypeError, - MP_ERROR_TEXT("can't convert %s to int"), mp_obj_get_type_str(arg)); - } else { - mp_raise_msg_varg(&mp_type_TypeError, - MP_ERROR_TEXT("unsupported type for %q: '%s'"), - mp_unary_op_method_name[op], mp_obj_get_type_str(arg)); - } + mp_raise_msg_varg(&mp_type_TypeError, + MP_ERROR_TEXT("unsupported type for %q: '%s'"), + mp_unary_op_method_name[op], mp_obj_get_type_str(arg)); #endif } } @@ -1700,6 +1691,16 @@ NORETURN void mp_raise_StopIteration(mp_obj_t arg) { } } +NORETURN void mp_raise_TypeError_int_conversion(mp_const_obj_t arg) { + #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE + (void)arg; + mp_raise_TypeError(MP_ERROR_TEXT("can't convert to int")); + #else + mp_raise_msg_varg(&mp_type_TypeError, + MP_ERROR_TEXT("can't convert %s to int"), mp_obj_get_type_str(arg)); + #endif +} + NORETURN void mp_raise_OSError(int errno_) { mp_raise_type_arg(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno_)); } diff --git a/py/runtime.h b/py/runtime.h index d57c25c92c..9b99e594b0 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -198,6 +198,7 @@ NORETURN void mp_raise_NotImplementedError(mp_rom_error_text_t msg); NORETURN void mp_raise_type_arg(const mp_obj_type_t *exc_type, mp_obj_t arg); NORETURN void mp_raise_StopIteration(mp_obj_t arg); +NORETURN void mp_raise_TypeError_int_conversion(mp_const_obj_t arg); NORETURN void mp_raise_OSError(int errno_); NORETURN void mp_raise_OSError_with_filename(int errno_, const char *filename); NORETURN void mp_raise_recursion_depth(void); diff --git a/py/runtime0.h b/py/runtime0.h index c82a4717f4..6ef2d727c1 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -75,7 +75,7 @@ typedef enum { MP_UNARY_OP_LEN, // __len__ MP_UNARY_OP_HASH, // __hash__; must return a small int MP_UNARY_OP_ABS, // __abs__ - MP_UNARY_OP_INT, // __int__ + MP_UNARY_OP_INT_MAYBE, // __int__; must return MP_OBJ_NULL, or an object satisfying mp_obj_is_int() MP_UNARY_OP_FLOAT_MAYBE, // __float__ MP_UNARY_OP_COMPLEX_MAYBE, // __complex__ MP_UNARY_OP_SIZEOF, // for sys.getsizeof() diff --git a/tests/basics/int_big1.py b/tests/basics/int_big1.py index 5b35e3db4a..ea48372b28 100644 --- a/tests/basics/int_big1.py +++ b/tests/basics/int_big1.py @@ -10,6 +10,9 @@ print(y) print('%#X' % (x - x)) # print prefix print('{:#,}'.format(x)) # print with commas +# construction +print(int(x)) + # addition print(x + 1) print(x + y) diff --git a/tests/basics/special_methods_intbig.py b/tests/basics/special_methods_intbig.py new file mode 100644 index 0000000000..653422f213 --- /dev/null +++ b/tests/basics/special_methods_intbig.py @@ -0,0 +1,8 @@ +# Test class special methods, that use a bigint. + +class A: + def __int__(self): + return 1 << 100 + + +print(int(A())) From 66dc1397c92f6accf102bcd15c6395902fd46c8b Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Jun 2023 12:12:22 +1000 Subject: [PATCH 129/565] py/obj: Accept user types in mp_obj_get_int_maybe. This is possible now that MP_UNARY_OP_INT_MAYBE exists. As a consequence mp_obj_get_int now also supports user types, which was previously possible with MP_UNARY_OP_INT but no tests existed for it. Signed-off-by: Damien George --- py/obj.c | 7 ++++++- tests/basics/string_format_modulo.py | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/py/obj.c b/py/obj.c index dc69194672..64c52eeb76 100644 --- a/py/obj.c +++ b/py/obj.c @@ -326,7 +326,12 @@ bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value) { } else if (mp_obj_is_exact_type(arg, &mp_type_int)) { *value = mp_obj_int_get_checked(arg); } else { - return false; + arg = mp_unary_op(MP_UNARY_OP_INT_MAYBE, (mp_obj_t)arg); + if (arg != MP_OBJ_NULL) { + *value = mp_obj_int_get_checked(arg); + } else { + return false; + } } return true; } diff --git a/tests/basics/string_format_modulo.py b/tests/basics/string_format_modulo.py index 01f8e7ed24..14b4a6a484 100644 --- a/tests/basics/string_format_modulo.py +++ b/tests/basics/string_format_modulo.py @@ -13,6 +13,12 @@ print("=%s=" % [1, 2]) print("=%s=" % "str") print("=%r=" % "str") +# test calling __int__ +class A: + def __int__(self): + return 123 +print("%d" % A()) + try: print("=%s=%s=" % 1) except TypeError: From 69dd013919461272b3669a516ef98d60accd3165 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 May 2023 18:02:32 +1000 Subject: [PATCH 130/565] py/objint: Allow int() to parse anything with the buffer protocol. This generalises and simplifies the code and follows CPython behaviour. See similar change for floats in a07fc5b6403b9a8bf7e7cb64f857272e5346d7e2. Signed-off-by: Damien George --- py/objint.c | 9 ++++----- tests/basics/int_parse.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/basics/int_parse.py diff --git a/py/objint.c b/py/objint.c index e54cdb89b5..be5f4653a7 100644 --- a/py/objint.c +++ b/py/objint.c @@ -49,14 +49,13 @@ STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, return MP_OBJ_NEW_SMALL_INT(0); case 1: { + mp_buffer_info_t bufinfo; mp_obj_t o = mp_unary_op(MP_UNARY_OP_INT_MAYBE, args[0]); if (o != MP_OBJ_NULL) { return o; - } else if (mp_obj_is_str_or_bytes(args[0])) { - // a string, parse it - size_t l; - const char *s = mp_obj_str_get_data(args[0], &l); - return mp_parse_num_integer(s, l, 0, NULL); + } else if (mp_get_buffer(args[0], &bufinfo, MP_BUFFER_READ)) { + // a textual representation, parse it + return mp_parse_num_integer(bufinfo.buf, bufinfo.len, 0, NULL); #if MICROPY_PY_BUILTINS_FLOAT } else if (mp_obj_is_float(args[0])) { return mp_obj_new_int_from_float(mp_obj_float_get(args[0])); diff --git a/tests/basics/int_parse.py b/tests/basics/int_parse.py new file mode 100644 index 0000000000..cc41158c59 --- /dev/null +++ b/tests/basics/int_parse.py @@ -0,0 +1,12 @@ +# Test parsing ints. + +try: + bytearray + memoryview +except NameError: + print("SKIP") + raise SystemExit + +print(int(b"123")) +print(int(bytearray(b"123"))) +print(int(memoryview(b"123"))) From 42f3f66431bb3131f5ee78f3e121491e9d0fb91d Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 10 May 2023 13:02:09 +1000 Subject: [PATCH 131/565] py/builtinimport: Handle empty sys.path correctly. If sys.path is enabled, but empty, this will now no longer search the filesystem. Previously an empty sys.path was equivalent to having `sys.path=[""]`. This is a breaking change, but this behavior now matches CPython. This also provides an alternative mechanism to the u-prefix to force an import of a builtin module: ``` import sys _path = sys.path[:] sys.path.clear() import foo # Forces the built-in foo. sys.path.extend(_path) del _path ``` Code size diff is -32 bytes on PYBV11. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- py/builtinimport.c | 49 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/py/builtinimport.c b/py/builtinimport.c index e620c03774..025fff928c 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -117,8 +117,9 @@ STATIC mp_import_stat_t stat_dir_or_file(vstr_t *path) { return stat_file_py_or_mpy(path); } -// Given a top-level module, try and find it in each of the sys.path entries -// via stat_dir_or_file. +// Given a top-level module name, try and find it in each of the sys.path +// entries. Note: On success, the dest argument will be updated to the matching +// path (i.e. "/mod_name(.py)"). STATIC mp_import_stat_t stat_top_level_dir_or_file(qstr mod_name, vstr_t *dest) { DEBUG_printf("stat_top_level_dir_or_file: '%s'\n", qstr_str(mod_name)); #if MICROPY_PY_SYS @@ -126,32 +127,34 @@ STATIC mp_import_stat_t stat_top_level_dir_or_file(qstr mod_name, vstr_t *dest) mp_obj_t *path_items; mp_obj_list_get(mp_sys_path, &path_num, &path_items); - if (path_num > 0) { - // go through each path looking for a directory or file - for (size_t i = 0; i < path_num; i++) { - vstr_reset(dest); - size_t p_len; - const char *p = mp_obj_str_get_data(path_items[i], &p_len); - if (p_len > 0) { - vstr_add_strn(dest, p, p_len); - vstr_add_char(dest, PATH_SEP_CHAR[0]); - } - vstr_add_str(dest, qstr_str(mod_name)); - mp_import_stat_t stat = stat_dir_or_file(dest); - if (stat != MP_IMPORT_STAT_NO_EXIST) { - return stat; - } + // go through each sys.path entry, trying to import "/". + for (size_t i = 0; i < path_num; i++) { + vstr_reset(dest); + size_t p_len; + const char *p = mp_obj_str_get_data(path_items[i], &p_len); + if (p_len > 0) { + // Add the path separator (unless the entry is "", i.e. cwd). + vstr_add_strn(dest, p, p_len); + vstr_add_char(dest, PATH_SEP_CHAR[0]); + } + vstr_add_str(dest, qstr_str(mod_name)); + mp_import_stat_t stat = stat_dir_or_file(dest); + if (stat != MP_IMPORT_STAT_NO_EXIST) { + return stat; } - - // could not find a directory or file - return MP_IMPORT_STAT_NO_EXIST; } - #endif - // mp_sys_path is empty (or not enabled), so just stat the given path - // directly. + // sys.path was empty or no matches, do not search the filesystem or + // frozen code. + return MP_IMPORT_STAT_NO_EXIST; + + #else + + // mp_sys_path is not enabled, so just stat the given path directly. vstr_add_str(dest, qstr_str(mod_name)); return stat_dir_or_file(dest); + + #endif } #if MICROPY_MODULE_FROZEN_STR || MICROPY_ENABLE_COMPILER From 525557738cccb73d7b00d2048b9fd47e4caeeec6 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 10 May 2023 13:02:09 +1000 Subject: [PATCH 132/565] py/builtinimport: Optimise sub-package loading. This makes it so that sub-packages are resolved relative to their parent's `__path__`, rather than re-resolving each parent's filesystem path. The previous behavior was that `import foo.bar` would first re-search `sys.path` for `foo`, then use the resulting path to find `bar`. For already-loaded and u-prefixed modules, because we no longer need to build the path from level to level, we no longer unnecessarily search the filesystem. This should improve startup time. Explicitly makes the resolving process clear: - Loaded modules are returned immediately without touching the filesystem. - Exact-match of builtins are also returned immediately. - Then the filesystem search happens. - If that fails, then the weak-link handling is applied. This maintains the existing behavior: if a user writes `import time` they will get time.py if it exits, otherwise the built-in utime. Whereas `import utime` will always return the built-in. This also fixes a regression from a7fa18c203a241f670f12ab507aa8b349fcd45a1 where we search the filesystem for built-ins. It is now only possible to override u-prefixed builtins. This will remove a lot of filesystem stats at startup, as micropython-specific modules (e.g. `pyb`) will no longer attempt to look at the filesystem. Added several improvements to the comments and some minor renaming and refactoring to make it clearer how the import mechanism works. Overall code size diff is +56 bytes on STM32. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/unix/main.c | 4 +- py/builtinimport.c | 311 ++++++++++++++++++++++++++------------------- py/obj.h | 2 - py/objmodule.c | 32 +---- py/objmodule.h | 3 - py/runtime.c | 3 +- 6 files changed, 189 insertions(+), 166 deletions(-) diff --git a/ports/unix/main.c b/ports/unix/main.c index 95ed216e4b..21f59862ab 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -664,7 +664,9 @@ MP_NOINLINE int main_(int argc, char **argv) { return handle_uncaught_exception(nlr.ret_val) & 0xff; } - if (mp_obj_is_package(mod) && !subpkg_tried) { + mp_obj_t dest[2]; + mp_load_method_maybe(mod, MP_QSTR___path__, dest); + if (dest[0] != MP_OBJ_NULL && !subpkg_tried) { subpkg_tried = true; vstr_t vstr; int len = strlen(argv[a + 1]); diff --git a/py/builtinimport.c b/py/builtinimport.c index 025fff928c..d8127a66f0 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -62,39 +62,39 @@ STATIC qstr make_weak_link_name(vstr_t *buffer, qstr name) { // Virtual sys.path entry that maps to the frozen modules. #define MP_FROZEN_PATH_PREFIX ".frozen/" -bool mp_obj_is_package(mp_obj_t module) { - mp_obj_t dest[2]; - mp_load_method_maybe(module, MP_QSTR___path__, dest); - return dest[0] != MP_OBJ_NULL; -} - // Wrapper for mp_import_stat (which is provided by the port, and typically // uses mp_vfs_import_stat) to also search frozen modules. Given an exact // path to a file or directory (e.g. "foo/bar", foo/bar.py" or "foo/bar.mpy"), // will return whether the path is a file, directory, or doesn't exist. -STATIC mp_import_stat_t stat_path_or_frozen(const char *path) { +STATIC mp_import_stat_t stat_path(const char *path) { #if MICROPY_MODULE_FROZEN // Only try and load as a frozen module if it starts with .frozen/. const int frozen_path_prefix_len = strlen(MP_FROZEN_PATH_PREFIX); if (strncmp(path, MP_FROZEN_PATH_PREFIX, frozen_path_prefix_len) == 0) { + // Just stat (which is the return value), don't get the data. return mp_find_frozen_module(path + frozen_path_prefix_len, NULL, NULL); } #endif return mp_import_stat(path); } -// Given a path to a .py file, try and find this path as either a .py or .mpy -// in either the filesystem or frozen modules. +// Stat a given filesystem path to a .py file. If the file does not exist, +// then attempt to stat the corresponding .mpy file, and update the path +// argument. This is the logic that makes .py files take precedent over .mpy +// files. This uses stat_path above, rather than mp_import_stat directly, so +// that the .frozen path prefix is handled. STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { - mp_import_stat_t stat = stat_path_or_frozen(vstr_null_terminated_str(path)); + mp_import_stat_t stat = stat_path(vstr_null_terminated_str(path)); if (stat == MP_IMPORT_STAT_FILE) { return stat; } #if MICROPY_PERSISTENT_CODE_LOAD // Didn't find .py -- try the .mpy instead by inserting an 'm' into the '.py'. + // Note: There's no point doing this if it's a frozen path, but adding the check + // would be extra code, and no harm letting mp_find_frozen_module fail instead. vstr_ins_byte(path, path->len - 2, 'm'); - stat = stat_path_or_frozen(vstr_null_terminated_str(path)); + stat = stat_path(vstr_null_terminated_str(path)); if (stat == MP_IMPORT_STAT_FILE) { return stat; } @@ -104,15 +104,17 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { } // Given an import path (e.g. "foo/bar"), try and find "foo/bar" (a directory) -// or "foo/bar.(m)py" in either the filesystem or frozen modules. -STATIC mp_import_stat_t stat_dir_or_file(vstr_t *path) { - mp_import_stat_t stat = stat_path_or_frozen(vstr_null_terminated_str(path)); +// or "foo/bar.(m)py" in either the filesystem or frozen modules. If the +// result is a file, the path argument will be updated to include the file +// extension. +STATIC mp_import_stat_t stat_module(vstr_t *path) { + mp_import_stat_t stat = stat_path(vstr_null_terminated_str(path)); DEBUG_printf("stat %s: %d\n", vstr_str(path), stat); if (stat == MP_IMPORT_STAT_DIR) { return stat; } - // not a directory, add .py and try as a file + // Not a directory, add .py and try as a file. vstr_add_str(path, ".py"); return stat_file_py_or_mpy(path); } @@ -120,8 +122,8 @@ STATIC mp_import_stat_t stat_dir_or_file(vstr_t *path) { // Given a top-level module name, try and find it in each of the sys.path // entries. Note: On success, the dest argument will be updated to the matching // path (i.e. "/mod_name(.py)"). -STATIC mp_import_stat_t stat_top_level_dir_or_file(qstr mod_name, vstr_t *dest) { - DEBUG_printf("stat_top_level_dir_or_file: '%s'\n", qstr_str(mod_name)); +STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { + DEBUG_printf("stat_top_level: '%s'\n", qstr_str(mod_name)); #if MICROPY_PY_SYS size_t path_num; mp_obj_t *path_items; @@ -138,7 +140,7 @@ STATIC mp_import_stat_t stat_top_level_dir_or_file(qstr mod_name, vstr_t *dest) vstr_add_char(dest, PATH_SEP_CHAR[0]); } vstr_add_str(dest, qstr_str(mod_name)); - mp_import_stat_t stat = stat_dir_or_file(dest); + mp_import_stat_t stat = stat_module(dest); if (stat != MP_IMPORT_STAT_NO_EXIST) { return stat; } @@ -152,7 +154,7 @@ STATIC mp_import_stat_t stat_top_level_dir_or_file(qstr mod_name, vstr_t *dest) // mp_sys_path is not enabled, so just stat the given path directly. vstr_add_str(dest, qstr_str(mod_name)); - return stat_dir_or_file(dest); + return stat_module(dest); #endif } @@ -350,128 +352,168 @@ STATIC void evaluate_relative_import(mp_int_t level, const char **module_name, s } // Load a module at the specified absolute path, possibly as a submodule of the given outer module. -// full_mod_name: The full absolute path to this module (e.g. "foo.bar.baz"). +// full_mod_name: The full absolute path up to this level (e.g. "foo.bar.baz"). // level_mod_name: The final component of the path (e.g. "baz"). // outer_module_obj: The parent module (we need to store this module as an // attribute on it) (or MP_OBJ_NULL for top-level). -// path: The filesystem path where we found the parent module -// (or empty for a top level module). // override_main: Whether to set the __name__ to "__main__" (and use __main__ // for the actual path). -STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t outer_module_obj, vstr_t *path, bool override_main) { +STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t outer_module_obj, bool override_main) { + // Immediately return if the module at this level is already loaded. + mp_map_elem_t *elem; + + #if MICROPY_PY_SYS + // If sys.path is empty, the intention is to force using a built-in. This + // means we should also ignore any loaded modules with the same name + // which may have come from the filesystem. + size_t path_num; + mp_obj_t *path_items; + mp_obj_list_get(mp_sys_path, &path_num, &path_items); + if (path_num) + #endif + { + elem = mp_map_lookup(&MP_STATE_VM(mp_loaded_modules_dict).map, MP_OBJ_NEW_QSTR(full_mod_name), MP_MAP_LOOKUP); + if (elem) { + return elem->value; + } + } + + VSTR_FIXED(path, MICROPY_ALLOC_PATH_MAX); mp_import_stat_t stat = MP_IMPORT_STAT_NO_EXIST; - - // Exact-match of built-in (or already-loaded) takes priority. - mp_obj_t module_obj = mp_module_get_loaded_or_builtin(full_mod_name); - - // Even if we find the module, go through the motions of searching for it - // because we may actually be in the process of importing a sub-module. - // So we need to (re-)find the correct path to be finding the sub-module - // on the next iteration of process_import_at_level. + mp_obj_t module_obj; if (outer_module_obj == MP_OBJ_NULL) { DEBUG_printf("Searching for top-level module\n"); + // An exact match of a built-in will always bypass the filesystem. + // Note that CPython-compatible built-ins are named e.g. utime, so this + // means that an exact match is only for `import utime`, so `import + // time` will search the filesystem and failing that hit the weak + // link handling below. Whereas micropython-specific built-ins like + // `micropython`, `pyb`, `network`, etc will match exactly and cannot + // be overridden by the filesystem. + module_obj = mp_module_get_builtin(level_mod_name); + if (module_obj != MP_OBJ_NULL) { + return module_obj; + } + + #if MICROPY_PY_SYS + // Never allow sys to be overridden from the filesystem. If weak links + // are disabled, then this also provides a default weak link so that + // `import sys` is treated like `import usys` (and therefore bypasses + // the filesystem). + if (level_mod_name == MP_QSTR_sys) { + return MP_OBJ_FROM_PTR(&mp_module_sys); + } + #endif + // First module in the dotted-name; search for a directory or file // relative to all the locations in sys.path. - stat = stat_top_level_dir_or_file(full_mod_name, path); + stat = stat_top_level(level_mod_name, &path); - // If the module "foo" doesn't exist on the filesystem, and it's not a - // builtin, try and find "ufoo" as a built-in. (This feature was - // formerly known as "weak links"). #if MICROPY_MODULE_WEAK_LINKS - if (stat == MP_IMPORT_STAT_NO_EXIST && module_obj == MP_OBJ_NULL) { - qstr umodule_name = make_weak_link_name(path, level_mod_name); + if (stat == MP_IMPORT_STAT_NO_EXIST) { + // No match on the filesystem. (And not a built-in either). + // If "foo" was requested, then try "ufoo" as a built-in. This + // allows `import time` to use built-in `utime`, unless `time` + // exists on the filesystem. This feature was formerly known + // as "weak links". + qstr umodule_name = make_weak_link_name(&path, level_mod_name); module_obj = mp_module_get_builtin(umodule_name); - } - #elif MICROPY_PY_SYS - if (stat == MP_IMPORT_STAT_NO_EXIST && module_obj == MP_OBJ_NULL && level_mod_name == MP_QSTR_sys) { - module_obj = MP_OBJ_FROM_PTR(&mp_module_sys); + if (module_obj != MP_OBJ_NULL) { + return module_obj; + } } #endif } else { DEBUG_printf("Searching for sub-module\n"); - // Add the current part of the module name to the path. - vstr_add_char(path, PATH_SEP_CHAR[0]); - vstr_add_str(path, qstr_str(level_mod_name)); + // If the outer module is a package, it will have __path__ set. + // We can use that as the path to search inside. + mp_obj_t dest[2]; + mp_load_method_maybe(outer_module_obj, MP_QSTR___path__, dest); + if (dest[0] != MP_OBJ_NULL) { + // e.g. __path__ will be "/foo/bar" + vstr_add_str(&path, mp_obj_str_get_str(dest[0])); - // Because it's not top level, we already know which path the parent was found in. - stat = stat_dir_or_file(path); + // Add the level module name to the path to get "/foo/bar/baz". + vstr_add_char(&path, PATH_SEP_CHAR[0]); + vstr_add_str(&path, qstr_str(level_mod_name)); + + stat = stat_module(&path); + } } - DEBUG_printf("Current path: %.*s\n", (int)vstr_len(path), vstr_str(path)); - if (module_obj == MP_OBJ_NULL) { - // Not a built-in and not already-loaded. + // Not already loaded, and not a built-in, so look at the stat result from the filesystem/frozen. - if (stat == MP_IMPORT_STAT_NO_EXIST) { - // And the file wasn't found -- fail. - #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE - mp_raise_msg(&mp_type_ImportError, MP_ERROR_TEXT("module not found")); - #else - mp_raise_msg_varg(&mp_type_ImportError, MP_ERROR_TEXT("no module named '%q'"), full_mod_name); - #endif - } - - // Not a built-in but found on the filesystem, try and load it. - - DEBUG_printf("Found path: %.*s\n", (int)vstr_len(path), vstr_str(path)); - - // Prepare for loading from the filesystem. Create a new shell module. - module_obj = mp_obj_new_module(full_mod_name); - - #if MICROPY_MODULE_OVERRIDE_MAIN_IMPORT - // If this module is being loaded via -m on unix, then - // override __name__ to "__main__". Do this only for *modules* - // however - packages never have their names replaced, instead - // they're -m'ed using a special __main__ submodule in them. (This all - // apparently is done to not touch the package name itself, which is - // important for future imports). - if (override_main && stat != MP_IMPORT_STAT_DIR) { - mp_obj_module_t *o = MP_OBJ_TO_PTR(module_obj); - mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__)); - #if MICROPY_CPYTHON_COMPAT - // Store module as "__main__" in the dictionary of loaded modules (returned by sys.modules). - mp_obj_dict_store(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_loaded_modules_dict)), MP_OBJ_NEW_QSTR(MP_QSTR___main__), module_obj); - // Store real name in "__main__" attribute. Need this for - // resolving relative imports later. "__main__ was chosen - // semi-randonly, to reuse existing qstr's. - mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___main__), MP_OBJ_NEW_QSTR(full_mod_name)); - #endif - } - #endif // MICROPY_MODULE_OVERRIDE_MAIN_IMPORT - - if (stat == MP_IMPORT_STAT_DIR) { - // Directory -- execute "path/__init__.py". - DEBUG_printf("%.*s is dir\n", (int)vstr_len(path), vstr_str(path)); - // Store the __path__ attribute onto this module. - // https://docs.python.org/3/reference/import.html - // "Specifically, any module that contains a __path__ attribute is considered a package." - mp_store_attr(module_obj, MP_QSTR___path__, mp_obj_new_str(vstr_str(path), vstr_len(path))); - size_t orig_path_len = path->len; - vstr_add_str(path, PATH_SEP_CHAR "__init__.py"); - if (stat_file_py_or_mpy(path) == MP_IMPORT_STAT_FILE) { - do_load(MP_OBJ_TO_PTR(module_obj), path); - } else { - // No-op. Nothing to load. - // mp_warning("%s is imported as namespace package", vstr_str(&path)); - } - // Remove /__init__.py suffix. - path->len = orig_path_len; - } else { // MP_IMPORT_STAT_FILE - // File -- execute "path.(m)py". - do_load(MP_OBJ_TO_PTR(module_obj), path); - // Note: This should be the last component in the import path. If - // there are remaining components then it's an ImportError - // because the current path(the module that was just loaded) is - // not a package. This will be caught on the next iteration - // because the file will not exist. + if (stat == MP_IMPORT_STAT_NO_EXIST) { + // Not found -- fail. + #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE + mp_raise_msg(&mp_type_ImportError, MP_ERROR_TEXT("module not found")); + #else + mp_raise_msg_varg(&mp_type_ImportError, MP_ERROR_TEXT("no module named '%q'"), full_mod_name); + #endif + } + + // Module was found on the filesystem/frozen, try and load it. + DEBUG_printf("Found path to load: %.*s\n", (int)vstr_len(&path), vstr_str(&path)); + + // Prepare for loading from the filesystem. Create a new shell module. + module_obj = mp_obj_new_module(full_mod_name); + + #if MICROPY_MODULE_OVERRIDE_MAIN_IMPORT + // If this module is being loaded via -m on unix, then + // override __name__ to "__main__". Do this only for *modules* + // however - packages never have their names replaced, instead + // they're -m'ed using a special __main__ submodule in them. (This all + // apparently is done to not touch the package name itself, which is + // important for future imports). + if (override_main && stat != MP_IMPORT_STAT_DIR) { + mp_obj_module_t *o = MP_OBJ_TO_PTR(module_obj); + mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__)); + #if MICROPY_CPYTHON_COMPAT + // Store module as "__main__" in the dictionary of loaded modules (returned by sys.modules). + mp_obj_dict_store(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_loaded_modules_dict)), MP_OBJ_NEW_QSTR(MP_QSTR___main__), module_obj); + // Store real name in "__main__" attribute. Need this for + // resolving relative imports later. "__main__ was chosen + // semi-randonly, to reuse existing qstr's. + mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___main__), MP_OBJ_NEW_QSTR(full_mod_name)); + #endif + } + #endif // MICROPY_MODULE_OVERRIDE_MAIN_IMPORT + + if (stat == MP_IMPORT_STAT_DIR) { + // Directory (i.e. a package). + DEBUG_printf("%.*s is dir\n", (int)vstr_len(&path), vstr_str(&path)); + + // Store the __path__ attribute onto this module. + // https://docs.python.org/3/reference/import.html + // "Specifically, any module that contains a __path__ attribute is considered a package." + // This gets used later to locate any subpackages of this module. + mp_store_attr(module_obj, MP_QSTR___path__, mp_obj_new_str(vstr_str(&path), vstr_len(&path))); + size_t orig_path_len = path.len; + vstr_add_str(&path, PATH_SEP_CHAR "__init__.py"); + + // execute "path/__init__.py" (if available). + if (stat_file_py_or_mpy(&path) == MP_IMPORT_STAT_FILE) { + do_load(MP_OBJ_TO_PTR(module_obj), &path); + } else { + // No-op. Nothing to load. + // mp_warning("%s is imported as namespace package", vstr_str(&path)); } + // Remove /__init__.py suffix from path. + path.len = orig_path_len; + } else { // MP_IMPORT_STAT_FILE + // File -- execute "path.(m)py". + do_load(MP_OBJ_TO_PTR(module_obj), &path); + // Note: This should be the last component in the import path. If + // there are remaining components then in the next call to + // process_import_at_level will detect that it doesn't have + // a __path__ attribute, and not attempt to stat it. } if (outer_module_obj != MP_OBJ_NULL) { - // If it's a sub-module (not a built-in one), then make it available on - // the parent module. + // If it's a sub-module then make it available on the parent module. mp_store_attr(outer_module_obj, level_mod_name, module_obj); } @@ -504,7 +546,6 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) { // i.e. "from . import foo" --> level=1 // i.e. "from ...foo.bar import baz" --> level=3 mp_int_t level = 0; - if (n_args >= 4) { fromtuple = args[3]; if (n_args >= 5) { @@ -519,8 +560,10 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) { const char *module_name = mp_obj_str_get_data(module_name_obj, &module_name_len); if (level != 0) { - // Turn "foo.bar" into ".foo.bar". + // Turn "foo.bar" with level=3 into ".foo.bar". + // Current module name is extracted from globals().__name__. evaluate_relative_import(level, &module_name, &module_name_len); + // module_name is now an absolute module path. } if (module_name_len == 0) { @@ -529,11 +572,12 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) { DEBUG_printf("Starting module search for '%s'\n", module_name); - VSTR_FIXED(path, MICROPY_ALLOC_PATH_MAX) mp_obj_t top_module_obj = MP_OBJ_NULL; mp_obj_t outer_module_obj = MP_OBJ_NULL; - // Search for the end of each component. + // Iterate the absolute path, finding the end of each component of the path. + // foo.bar.baz + // ^ ^ ^ size_t current_component_start = 0; for (size_t i = 1; i <= module_name_len; i++) { if (i == module_name_len || module_name[i] == '.') { @@ -543,18 +587,18 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) { qstr level_mod_name = qstr_from_strn(module_name + current_component_start, i - current_component_start); DEBUG_printf("Processing module: '%s' at level '%s'\n", qstr_str(full_mod_name), qstr_str(level_mod_name)); - DEBUG_printf("Previous path: =%.*s=\n", (int)vstr_len(&path), vstr_str(&path)); #if MICROPY_MODULE_OVERRIDE_MAIN_IMPORT - // On unix, if this is being loaded via -m (magic mp_const_false), - // then handle that if it's the final component. + // On unix, if this is being loaded via -m (indicated by sentinel + // fromtuple=mp_const_false), then handle that if it's the final + // component. bool override_main = (i == module_name_len && fromtuple == mp_const_false); #else bool override_main = false; #endif // Import this module. - mp_obj_t module_obj = process_import_at_level(full_mod_name, level_mod_name, outer_module_obj, &path, override_main); + mp_obj_t module_obj = process_import_at_level(full_mod_name, level_mod_name, outer_module_obj, override_main); // Set this as the parent module, and remember the top-level module if it's the first. outer_module_obj = module_obj; @@ -577,31 +621,38 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) { #else // MICROPY_ENABLE_EXTERNAL_IMPORT -bool mp_obj_is_package(mp_obj_t module) { - return false; -} - mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) { - // Check that it's not a relative import + // Check that it's not a relative import. if (n_args >= 5 && MP_OBJ_SMALL_INT_VALUE(args[4]) != 0) { mp_raise_NotImplementedError(MP_ERROR_TEXT("relative import")); } - // Check if module already exists, and return it if it does + // Check if the module is already loaded. + mp_map_elem_t *elem = mp_map_lookup(&MP_STATE_VM(mp_loaded_modules_dict).map, args[0], MP_MAP_LOOKUP); + if (elem) { + return elem->value; + } + + // Try the name directly as a built-in. qstr module_name_qstr = mp_obj_str_get_qstr(args[0]); - mp_obj_t module_obj = mp_module_get_loaded_or_builtin(module_name_qstr); + mp_obj_t module_obj = mp_module_get_builtin(module_name_qstr); if (module_obj != MP_OBJ_NULL) { return module_obj; } #if MICROPY_MODULE_WEAK_LINKS - // Check if there is a weak link to this module + // Check if the u-prefixed name is a built-in. VSTR_FIXED(umodule_path, MICROPY_ALLOC_PATH_MAX); qstr umodule_name_qstr = make_weak_link_name(&umodule_path, module_name_qstr); - module_obj = mp_module_get_loaded_or_builtin(umodule_name_qstr); + module_obj = mp_module_get_builtin(umodule_name_qstr); if (module_obj != MP_OBJ_NULL) { return module_obj; } + #elif MICROPY_PY_SYS + // Special handling to make `import sys` work even if weak links aren't enabled. + if (module_name_qstr == MP_QSTR_sys) { + return MP_OBJ_FROM_PTR(&mp_module_sys); + } #endif // Couldn't find the module, so fail diff --git a/py/obj.h b/py/obj.h index 04c153f501..3735b72c22 100644 --- a/py/obj.h +++ b/py/obj.h @@ -1201,8 +1201,6 @@ typedef struct _mp_obj_module_t { static inline mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t module) { return ((mp_obj_module_t *)MP_OBJ_TO_PTR(module))->globals; } -// check if given module object is a package -bool mp_obj_is_package(mp_obj_t module); // staticmethod and classmethod types; defined here so we can make const versions // this structure is used for instances of both staticmethod and classmethod diff --git a/py/objmodule.c b/py/objmodule.c index 63e9fa4757..6f061a9408 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -176,35 +176,10 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table); -// Tries to find a loaded module, otherwise attempts to load a builtin, otherwise MP_OBJ_NULL. -mp_obj_t mp_module_get_loaded_or_builtin(qstr module_name) { - // First try loaded modules. - mp_map_elem_t *elem = mp_map_lookup(&MP_STATE_VM(mp_loaded_modules_dict).map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); - - if (!elem) { - #if MICROPY_MODULE_WEAK_LINKS - return mp_module_get_builtin(module_name); - #else - // Otherwise try builtin. - elem = mp_map_lookup((mp_map_t *)&mp_builtin_module_map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); - if (!elem) { - return MP_OBJ_NULL; - } - - #if MICROPY_MODULE_BUILTIN_INIT - // If found, it's a newly loaded built-in, so init it. - mp_module_call_init(MP_OBJ_NEW_QSTR(module_name), elem->value); - #endif - #endif - } - - return elem->value; -} - -#if MICROPY_MODULE_WEAK_LINKS -// Tries to find a loaded module, otherwise attempts to load a builtin, otherwise MP_OBJ_NULL. +// Attempts to find (and initialise) a builtin, otherwise returns MP_OBJ_NULL. +// This must only be called after first checking the loaded modules, +// otherwise the module will be re-initialised. mp_obj_t mp_module_get_builtin(qstr module_name) { - // Try builtin. mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)&mp_builtin_module_map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); if (!elem) { return MP_OBJ_NULL; @@ -217,7 +192,6 @@ mp_obj_t mp_module_get_builtin(qstr module_name) { return elem->value; } -#endif #if MICROPY_MODULE_BUILTIN_INIT STATIC void mp_module_register(mp_obj_t module_name, mp_obj_t module) { diff --git a/py/objmodule.h b/py/objmodule.h index d11d5bcd74..11bd7bb42f 100644 --- a/py/objmodule.h +++ b/py/objmodule.h @@ -33,10 +33,7 @@ extern const mp_map_t mp_builtin_module_map; -mp_obj_t mp_module_get_loaded_or_builtin(qstr module_name); -#if MICROPY_MODULE_WEAK_LINKS mp_obj_t mp_module_get_builtin(qstr module_name); -#endif void mp_module_generic_attr(qstr attr, mp_obj_t *dest, const uint16_t *keys, mp_obj_t *values); diff --git a/py/runtime.c b/py/runtime.c index 99f7f6109b..cbc7fb9311 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1531,7 +1531,8 @@ mp_obj_t mp_import_from(mp_obj_t module, qstr name) { #if MICROPY_ENABLE_EXTERNAL_IMPORT // See if it's a package, then can try FS import - if (!mp_obj_is_package(module)) { + mp_load_method_maybe(module, MP_QSTR___path__, dest); + if (dest[0] == MP_OBJ_NULL) { goto import_error; } From ed90f30dd5d39e958ce99c041f1dc1f9dbb63bb2 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 10 May 2023 13:22:54 +1000 Subject: [PATCH 133/565] py/builtinimport: Allow builtin modules to be packages. To use this: - Create a built-in module, and add the module object as a member of the parent module's globals dict. - The submodule can set its `__name__` to either `QSTR_foo_dot_bar` or `QSTR_bar`. The former requires using qstrdefs(port).h to make the qstr. Because `bar` is a member of `foo`'s globals, it is possible to write `import foo` and then immediately use `foo.bar` without importing it explicitly. This means that if `bar` has an `__init__`, it will not be called in this situation, and for that reason, sub-modules should not have `__init__` methods. If this is required, then all initalisation for sub-modules should be done by the top-level module's (i.e. `foo`'s) `__init__` method. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- py/builtinimport.c | 14 ++++++++++++++ py/mpconfig.h | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/py/builtinimport.c b/py/builtinimport.c index d8127a66f0..f6c2f7c348 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -428,6 +428,20 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, } else { DEBUG_printf("Searching for sub-module\n"); + #if MICROPY_MODULE_BUILTIN_SUBPACKAGES + // If the outer module is a built-in (because its map is in ROM), then + // treat it like a package if it contains this submodule in its + // globals dict. + mp_obj_module_t *mod = MP_OBJ_TO_PTR(outer_module_obj); + if (mod->globals->map.is_fixed) { + elem = mp_map_lookup(&mod->globals->map, MP_OBJ_NEW_QSTR(level_mod_name), MP_MAP_LOOKUP); + // Also verify that the entry in the globals dict is in fact a module. + if (elem && mp_obj_is_type(elem->value, &mp_type_module)) { + return elem->value; + } + } + #endif + // If the outer module is a package, it will have __path__ set. // We can use that as the path to search inside. mp_obj_t dest[2]; diff --git a/py/mpconfig.h b/py/mpconfig.h index f3d5ce557a..292fafb52e 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -850,6 +850,20 @@ typedef double mp_float_t; #define MICROPY_MODULE_BUILTIN_INIT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif +// Whether to allow built-in modules to have sub-packages (by making the +// sub-package a member of their locals dict). Sub-packages should not be +// registered with MP_REGISTER_MODULE, instead they should be added as +// members of the parent's globals dict. To match CPython behavior, +// their __name__ should be "foo.bar"(i.e. QSTR_foo_dot_bar) which will +// require an entry in qstrdefs, although it does also work to just call +// it "bar". Also, because subpackages can be accessed without being +// imported (e.g. as foo.bar after `import foo`), they should not +// have __init__ methods. Instead, the top-level package's __init__ should +// initialise all sub-packages. +#ifndef MICROPY_MODULE_BUILTIN_SUBPACKAGES +#define MICROPY_MODULE_BUILTIN_SUBPACKAGES (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) +#endif + // Whether to support module-level __getattr__ (see PEP 562) #ifndef MICROPY_MODULE_GETATTR #define MICROPY_MODULE_GETATTR (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) From 6a8114eee8ff486d812b4efc5a94880b565640f3 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 12 May 2023 17:07:24 +1000 Subject: [PATCH 134/565] py/objmodule: Don't use sys.modules to track a builtin __init__. This can lead to duplicate initialisations if a module can be imported via multiple names, so the module must track this itself anyway. This reduces code size (diff is -40 bytes), and avoids special treatment of builtin-modules-with-init with respect to sys.modules. No other builtin modules get put into sys.modules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- py/mpconfig.h | 4 +++- py/objmodule.c | 40 ++++++++++------------------------------ 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/py/mpconfig.h b/py/mpconfig.h index 292fafb52e..afef744ab5 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -845,7 +845,9 @@ typedef double mp_float_t; #define MICROPY_MODULE_ATTR_DELEGATION (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -// Whether to call __init__ when importing builtin modules for the first time +// Whether to call __init__ when importing builtin modules for the first time. +// Modules using this need to handle the possibility that __init__ might be +// called multiple times. #ifndef MICROPY_MODULE_BUILTIN_INIT #define MICROPY_MODULE_BUILTIN_INIT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif diff --git a/py/objmodule.c b/py/objmodule.c index 6f061a9408..7326fbe2d1 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -40,10 +40,6 @@ #include "genhdr/moduledefs.h" #endif -#if MICROPY_MODULE_BUILTIN_INIT -STATIC void mp_module_call_init(mp_obj_t module_name, mp_obj_t module_obj); -#endif - STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); @@ -176,9 +172,8 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table); -// Attempts to find (and initialise) a builtin, otherwise returns MP_OBJ_NULL. -// This must only be called after first checking the loaded modules, -// otherwise the module will be re-initialised. +// Attempts to find (and initialise) a builtin, otherwise returns +// MP_OBJ_NULL. mp_obj_t mp_module_get_builtin(qstr module_name) { mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)&mp_builtin_module_map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); if (!elem) { @@ -186,34 +181,19 @@ mp_obj_t mp_module_get_builtin(qstr module_name) { } #if MICROPY_MODULE_BUILTIN_INIT - // If found, it's a newly loaded built-in, so init it. - mp_module_call_init(MP_OBJ_NEW_QSTR(module_name), elem->value); + // If found, it's a newly loaded built-in, so init it. This can run + // multiple times, so the module must ensure that it handles being + // initialised multiple times. + mp_obj_t dest[2]; + mp_load_method_maybe(elem->value, MP_QSTR___init__, dest); + if (dest[0] != MP_OBJ_NULL) { + mp_call_method_n_kw(0, 0, dest); + } #endif return elem->value; } -#if MICROPY_MODULE_BUILTIN_INIT -STATIC void mp_module_register(mp_obj_t module_name, mp_obj_t module) { - mp_map_t *mp_loaded_modules_map = &MP_STATE_VM(mp_loaded_modules_dict).map; - mp_map_lookup(mp_loaded_modules_map, module_name, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = module; -} - -STATIC void mp_module_call_init(mp_obj_t module_name, mp_obj_t module_obj) { - // Look for __init__ and call it if it exists - mp_obj_t dest[2]; - mp_load_method_maybe(module_obj, MP_QSTR___init__, dest); - if (dest[0] != MP_OBJ_NULL) { - mp_call_method_n_kw(0, 0, dest); - // Register module so __init__ is not called again. - // If a module can be referenced by more than one name (eg due to weak links) - // then __init__ will still be called for each distinct import, and it's then - // up to the particular module to make sure it's __init__ code only runs once. - mp_module_register(module_name, module_obj); - } -} -#endif - void mp_module_generic_attr(qstr attr, mp_obj_t *dest, const uint16_t *keys, mp_obj_t *values) { for (size_t i = 0; keys[i] != MP_QSTRnull; ++i) { if (attr == keys[i]) { From 5e0452125146f3afed89c09f5813790156d24471 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 12 May 2023 17:03:14 +1000 Subject: [PATCH 135/565] examples/usercmodule: Add a sub-package example. This demonstrates how to add a sub-package in a user c module, as well as how to define the necessary qstrs and enable the feature in the build. This is used by the unix coverage build to test this feature. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- examples/usercmodule/cexample/examplemodule.c | 2 +- examples/usercmodule/cexample/micropython.mk | 7 +- .../usercmodule/cppexample/examplemodule.c | 2 +- examples/usercmodule/subpackage/README.md | 1 + .../usercmodule/subpackage/micropython.cmake | 19 +++++ .../usercmodule/subpackage/micropython.mk | 10 +++ .../subpackage/modexamplepackage.c | 84 +++++++++++++++++++ .../subpackage/qstrdefsexamplepackage.h | 2 + tests/unix/extra_coverage.py | 17 ++++ tests/unix/extra_coverage.py.exp | 25 ++++-- 10 files changed, 156 insertions(+), 13 deletions(-) create mode 100644 examples/usercmodule/subpackage/README.md create mode 100644 examples/usercmodule/subpackage/micropython.cmake create mode 100644 examples/usercmodule/subpackage/micropython.mk create mode 100644 examples/usercmodule/subpackage/modexamplepackage.c create mode 100644 examples/usercmodule/subpackage/qstrdefsexamplepackage.h diff --git a/examples/usercmodule/cexample/examplemodule.c b/examples/usercmodule/cexample/examplemodule.c index ccce03bcbd..9416613ba9 100644 --- a/examples/usercmodule/cexample/examplemodule.c +++ b/examples/usercmodule/cexample/examplemodule.c @@ -68,7 +68,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &example_Timer_locals_dict ); -// Define all properties of the module. +// Define all attributes of the module. // Table entries are key/value pairs of the attribute name (a string) // and the MicroPython object reference. // All identifiers and strings are written as MP_QSTR_xxx and will be diff --git a/examples/usercmodule/cexample/micropython.mk b/examples/usercmodule/cexample/micropython.mk index dbfe3c5cbd..d6801dac0b 100644 --- a/examples/usercmodule/cexample/micropython.mk +++ b/examples/usercmodule/cexample/micropython.mk @@ -1,9 +1,8 @@ -EXAMPLE_MOD_DIR := $(USERMOD_DIR) +CEXAMPLE_MOD_DIR := $(USERMOD_DIR) # Add all C files to SRC_USERMOD. -SRC_USERMOD += $(EXAMPLE_MOD_DIR)/examplemodule.c +SRC_USERMOD += $(CEXAMPLE_MOD_DIR)/examplemodule.c # We can add our module folder to include paths if needed # This is not actually needed in this example. -CFLAGS_USERMOD += -I$(EXAMPLE_MOD_DIR) -CEXAMPLE_MOD_DIR := $(USERMOD_DIR) +CFLAGS_USERMOD += -I$(CEXAMPLE_MOD_DIR) diff --git a/examples/usercmodule/cppexample/examplemodule.c b/examples/usercmodule/cppexample/examplemodule.c index 5c84eccd79..96a1a74438 100644 --- a/examples/usercmodule/cppexample/examplemodule.c +++ b/examples/usercmodule/cppexample/examplemodule.c @@ -4,7 +4,7 @@ // See example.cpp for the definition. STATIC MP_DEFINE_CONST_FUN_OBJ_2(cppfunc_obj, cppfunc); -// Define all properties of the module. +// Define all attributes of the module. // Table entries are key/value pairs of the attribute name (a string) // and the MicroPython object reference. // All identifiers and strings are written as MP_QSTR_xxx and will be diff --git a/examples/usercmodule/subpackage/README.md b/examples/usercmodule/subpackage/README.md new file mode 100644 index 0000000000..c7f2ee53a2 --- /dev/null +++ b/examples/usercmodule/subpackage/README.md @@ -0,0 +1 @@ +This is an example of a user C module that includes subpackages. diff --git a/examples/usercmodule/subpackage/micropython.cmake b/examples/usercmodule/subpackage/micropython.cmake new file mode 100644 index 0000000000..a51e7a8061 --- /dev/null +++ b/examples/usercmodule/subpackage/micropython.cmake @@ -0,0 +1,19 @@ +# Create an INTERFACE library for our C module. +add_library(usermod_subpackage_example INTERFACE) + +# Add our source files to the lib +target_sources(usermod_subpackage_example INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/examplemodule.c +) + +# Add the current directory as an include directory. +target_include_directories(usermod_subpackage_example INTERFACE + ${CMAKE_CURRENT_LIST_DIR} +) + +target_compile_definitions(usermod_subpackage_example INTERFACE + MICROPY_MODULE_BUILTIN_SUBPACKAGES=1 +) + +# Link our INTERFACE library to the usermod target. +target_link_libraries(usermod INTERFACE usermod_subpackage_example) diff --git a/examples/usercmodule/subpackage/micropython.mk b/examples/usercmodule/subpackage/micropython.mk new file mode 100644 index 0000000000..99ebf13ec1 --- /dev/null +++ b/examples/usercmodule/subpackage/micropython.mk @@ -0,0 +1,10 @@ +SUBPACKAGE_EXAMPLE_MOD_DIR := $(USERMOD_DIR) + +# Add all C files to SRC_USERMOD. +SRC_USERMOD += $(SUBPACKAGE_EXAMPLE_MOD_DIR)/modexamplepackage.c + +# We can add our module folder to include paths if needed +# This is not actually needed in this example. +CFLAGS_USERMOD += -I$(SUBPACKAGE_EXAMPLE_MOD_DIR) -DMICROPY_MODULE_BUILTIN_SUBPACKAGES=1 + +QSTR_DEFS += $(SUBPACKAGE_EXAMPLE_MOD_DIR)/qstrdefsexamplepackage.h diff --git a/examples/usercmodule/subpackage/modexamplepackage.c b/examples/usercmodule/subpackage/modexamplepackage.c new file mode 100644 index 0000000000..70e1e4005b --- /dev/null +++ b/examples/usercmodule/subpackage/modexamplepackage.c @@ -0,0 +1,84 @@ +// Include MicroPython API. +#include "py/runtime.h" + +// Define example_package.foo.bar.f() +STATIC mp_obj_t example_package_foo_bar_f(void) { + mp_printf(&mp_plat_print, "example_package.foo.bar.f\n"); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_bar_f_obj, example_package_foo_bar_f); + +// Define all attributes of the second-level sub-package (example_package.foo.bar). +STATIC const mp_rom_map_elem_t example_package_foo_bar_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package_dot_foo_dot_bar) }, + { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_foo_bar_f_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(example_package_foo_bar_globals, example_package_foo_bar_globals_table); + +// Define example_package.foo.bar module object. +const mp_obj_module_t example_package_foo_bar_user_cmodule = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&example_package_foo_bar_globals, +}; + +// Define example_package.foo.f() +STATIC mp_obj_t example_package_foo_f(void) { + mp_printf(&mp_plat_print, "example_package.foo.f\n"); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_f_obj, example_package_foo_f); + +// Define all attributes of the first-level sub-package (example_package.foo). +STATIC const mp_rom_map_elem_t example_package_foo_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package_dot_foo) }, + { MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&example_package_foo_bar_user_cmodule) }, + { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_foo_f_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(example_package_foo_globals, example_package_foo_globals_table); + +// Define example_package.foo module object. +const mp_obj_module_t example_package_foo_user_cmodule = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&example_package_foo_globals, +}; + +// Define example_package.f() +STATIC mp_obj_t example_package_f(void) { + mp_printf(&mp_plat_print, "example_package.f\n"); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_f_obj, example_package_f); + +STATIC mp_obj_t example_package___init__(void) { + if (!MP_STATE_VM(example_package_initialised)) { + // __init__ for builtins is called each time the module is imported, + // so ensure that initialisation only happens once. + MP_STATE_VM(example_package_initialised) = true; + mp_printf(&mp_plat_print, "example_package.__init__\n"); + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package___init___obj, example_package___init__); + +// The "initialised" state is stored on mp_state so that it is cleared on soft +// reset. +MP_REGISTER_ROOT_POINTER(int example_package_initialised); + +// Define all attributes of the top-level package (example_package). +STATIC const mp_rom_map_elem_t example_package_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package) }, + { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&example_package___init___obj) }, + { MP_ROM_QSTR(MP_QSTR_foo), MP_ROM_PTR(&example_package_foo_user_cmodule) }, + { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_f_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(example_package_globals, example_package_globals_table); + +// Define module object. +const mp_obj_module_t example_package_user_cmodule = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&example_package_globals, +}; + +// Register the module to make it available in Python. +// Note: subpackages should not be registered with MP_REGISTER_MODULE. +MP_REGISTER_MODULE(MP_QSTR_example_package, example_package_user_cmodule); diff --git a/examples/usercmodule/subpackage/qstrdefsexamplepackage.h b/examples/usercmodule/subpackage/qstrdefsexamplepackage.h new file mode 100644 index 0000000000..057ec5279d --- /dev/null +++ b/examples/usercmodule/subpackage/qstrdefsexamplepackage.h @@ -0,0 +1,2 @@ +Q(example_package.foo) +Q(example_package.foo.bar) diff --git a/tests/unix/extra_coverage.py b/tests/unix/extra_coverage.py index a51b5b856a..3c12b26923 100644 --- a/tests/unix/extra_coverage.py +++ b/tests/unix/extra_coverage.py @@ -96,3 +96,20 @@ print(returns_NULL()) import frozentest print(frozentest.__file__) + +# test for builtin sub-packages +from example_package.foo import bar + +print(bar) +bar.f() +import example_package + +print(example_package, example_package.foo, example_package.foo.bar) +example_package.f() +example_package.foo.f() +example_package.foo.bar.f() +print(bar == example_package.foo.bar) +from example_package.foo import f as foo_f + +foo_f() +print(foo_f == example_package.foo.f) diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index ab6d497723..7ea2599c91 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -52,13 +52,14 @@ mport builtins micropython _thread _uasyncio btree cexample cmath cppexample -ffi framebuf gc math -termios uarray ubinascii ucollections -ucryptolib uctypes uerrno uhashlib -uheapq uio ujson umachine -uos urandom ure uselect -usocket ussl ustruct usys -utime utimeq uwebsocket uzlib +example_package ffi framebuf +gc math termios uarray +ubinascii ucollections ucryptolib uctypes +uerrno uhashlib uheapq uio +ujson umachine uos urandom +ure uselect usocket ussl +ustruct usys utime utimeq +uwebsocket uzlib ime utime utimeq @@ -211,3 +212,13 @@ b'bytes 1234\x01' 2 3 frozentest.py +example_package.__init__ + +example_package.foo.bar.f + +example_package.f +example_package.foo.f +example_package.foo.bar.f +True +example_package.foo.f +True From dfa7677e2fb1ff2314be04b5ea05346ac168fe84 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 12 May 2023 17:10:07 +1000 Subject: [PATCH 136/565] tests/import/builtin_ext.py: Add test for built-in module override. This verifies the behavior: - Exact matches of built-ins bypass filesystem. - u-prefix modules can be overridden from the filesystem. - Builtin import can be forced using either u-prefix or sys.path=[]. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/import/builtin_ext.py | 36 +++++++++++++++++++++++++++++++++ tests/import/builtin_ext.py.exp | 10 +++++++++ tests/import/ext/micropython.py | 2 ++ tests/import/ext/os.py | 5 +++++ tests/import/ext/sys.py | 2 ++ tests/import/ext/time.py | 14 +++++++++++++ tests/import/ext/usys.py | 3 +++ 7 files changed, 72 insertions(+) create mode 100644 tests/import/builtin_ext.py create mode 100644 tests/import/builtin_ext.py.exp create mode 100644 tests/import/ext/micropython.py create mode 100644 tests/import/ext/os.py create mode 100644 tests/import/ext/sys.py create mode 100644 tests/import/ext/time.py create mode 100644 tests/import/ext/usys.py diff --git a/tests/import/builtin_ext.py b/tests/import/builtin_ext.py new file mode 100644 index 0000000000..dd8f95cbc1 --- /dev/null +++ b/tests/import/builtin_ext.py @@ -0,0 +1,36 @@ +import sys + +print(sys, hasattr(sys, "__file__")) + +sys.path.clear() +sys.path.append("ext") + +# All three should only get builtins, despite sys.py, usys.py, and +# micropython.py being in the path. +import micropython + +print(micropython, hasattr(micropython, "__file__")) +import sys + +print(sys, hasattr(sys, "__file__")) +import usys + +print(usys, hasattr(usys, "__file__")) + +# This should get os.py, which uses uos to get the builtin. +import os + +print(os, hasattr(os, "__file__"), os.sep, os.extra) + +# This should get time.py, which uses empty sys.path to get the builtin. +import time + +print(time, hasattr(time, "__file__"), time.sleep, time.extra) + +# These should get the builtins. +import uos + +print(uos, hasattr(uos, "__file__"), hasattr(uos, "extra")) +import utime + +print(utime, hasattr(utime, "__file__"), hasattr(utime, "extra")) diff --git a/tests/import/builtin_ext.py.exp b/tests/import/builtin_ext.py.exp new file mode 100644 index 0000000000..08496e14b7 --- /dev/null +++ b/tests/import/builtin_ext.py.exp @@ -0,0 +1,10 @@ + False + False + False + False +os from filesystem + True / 1 +time from filesystem + True 1 + False False + False False diff --git a/tests/import/ext/micropython.py b/tests/import/ext/micropython.py new file mode 100644 index 0000000000..88c8b770e1 --- /dev/null +++ b/tests/import/ext/micropython.py @@ -0,0 +1,2 @@ +# micropython is always builtin and cannot be overriden by the filesystem. +print("ERROR: micropython from filesystem") diff --git a/tests/import/ext/os.py b/tests/import/ext/os.py new file mode 100644 index 0000000000..e1448805d0 --- /dev/null +++ b/tests/import/ext/os.py @@ -0,0 +1,5 @@ +print("os from filesystem") + +from uos import * + +extra = 1 diff --git a/tests/import/ext/sys.py b/tests/import/ext/sys.py new file mode 100644 index 0000000000..71ee633e11 --- /dev/null +++ b/tests/import/ext/sys.py @@ -0,0 +1,2 @@ +# sys is always builtin and cannot be overriden by the filesystem. +print("ERROR: sys from filesystem") diff --git a/tests/import/ext/time.py b/tests/import/ext/time.py new file mode 100644 index 0000000000..6f2d4a42c0 --- /dev/null +++ b/tests/import/ext/time.py @@ -0,0 +1,14 @@ +print("time from filesystem") + +# Tests the CPython-compatible / non-u-prefix way of forcing a builtin +# import. +import sys + +_path = sys.path[:] +sys.path.clear() +from time import * + +sys.path.extend(_path) +del _path + +extra = 1 diff --git a/tests/import/ext/usys.py b/tests/import/ext/usys.py new file mode 100644 index 0000000000..d7629a4499 --- /dev/null +++ b/tests/import/ext/usys.py @@ -0,0 +1,3 @@ +# usys (and any u-prefix) is always builtin and cannot be overriden by the +# filesystem. +print("ERROR: usys from filesystem") From 99a0c45aef6f0fd64f86a2048b999bdb7d74377c Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 23 May 2023 22:03:50 +1000 Subject: [PATCH 137/565] tests/import/import_pkg9.py: Add test for subpackage attribute. When foo.bar is imported, bar is added as an attribute to foo. Previously this happened on every import, but should only happen on first import. This verifies the behavior for relative imports and overriding. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/import/import_pkg9.py | 16 ++++++++++++++++ tests/import/pkg9/__init__.py | 5 +++++ tests/import/pkg9/mod1.py | 2 ++ tests/import/pkg9/mod2.py | 1 + 4 files changed, 24 insertions(+) create mode 100644 tests/import/import_pkg9.py create mode 100644 tests/import/pkg9/__init__.py create mode 100644 tests/import/pkg9/mod1.py create mode 100644 tests/import/pkg9/mod2.py diff --git a/tests/import/import_pkg9.py b/tests/import/import_pkg9.py new file mode 100644 index 0000000000..4de028494f --- /dev/null +++ b/tests/import/import_pkg9.py @@ -0,0 +1,16 @@ +# tests that import only sets subpackage attribute on first import + +import pkg9 + +pkg9.mod1() +pkg9.mod2() + +import pkg9.mod1 + +pkg9.mod1() +pkg9.mod2() + +import pkg9.mod2 + +pkg9.mod1() +print(pkg9.mod2.__name__, type(pkg9.mod2).__name__) diff --git a/tests/import/pkg9/__init__.py b/tests/import/pkg9/__init__.py new file mode 100644 index 0000000000..5d08d4b4a9 --- /dev/null +++ b/tests/import/pkg9/__init__.py @@ -0,0 +1,5 @@ +from .mod1 import mod1 + + +def mod2(): + print("mod2") diff --git a/tests/import/pkg9/mod1.py b/tests/import/pkg9/mod1.py new file mode 100644 index 0000000000..7e7066bada --- /dev/null +++ b/tests/import/pkg9/mod1.py @@ -0,0 +1,2 @@ +def mod1(): + print("mod1") diff --git a/tests/import/pkg9/mod2.py b/tests/import/pkg9/mod2.py new file mode 100644 index 0000000000..f4b3e265fb --- /dev/null +++ b/tests/import/pkg9/mod2.py @@ -0,0 +1 @@ +from . import mod2 From 952a78f88af5809b2fbf30ed9fa86649cc71c2aa Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 24 May 2023 17:06:08 +1000 Subject: [PATCH 138/565] unix/main: Add NLR scope for checking module __path__. If the module has a user-defined getattr, this could raise. Signed-off-by: Jim Mussared --- ports/unix/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/unix/main.c b/ports/unix/main.c index 21f59862ab..fc0f6da7b8 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -664,8 +664,9 @@ MP_NOINLINE int main_(int argc, char **argv) { return handle_uncaught_exception(nlr.ret_val) & 0xff; } + // If this module is a package, see if it has a `__main__.py`. mp_obj_t dest[2]; - mp_load_method_maybe(mod, MP_QSTR___path__, dest); + mp_load_method_protected(mod, MP_QSTR___path__, dest, true); if (dest[0] != MP_OBJ_NULL && !subpkg_tried) { subpkg_tried = true; vstr_t vstr; From 5159304ca1ded5eb94338234afffcef0210b545a Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 31 May 2023 15:59:07 +1000 Subject: [PATCH 139/565] docs/library/index: Update built-in extension docs. - Make the docs match the new behavior which only allows certain modules to be extended. - List the modules that currently have the u-prefix. - Add a note about the sys.path method for forcing a built-in import. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- docs/library/index.rst | 66 ++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/docs/library/index.rst b/docs/library/index.rst index 8d7d8c563b..985a7ad770 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -8,15 +8,17 @@ MicroPython libraries Important summary of this section * MicroPython provides built-in modules that mirror the functionality of the - Python standard library (e.g. :mod:`os`, :mod:`time`), as well as - MicroPython-specific modules (e.g. :mod:`bluetooth`, :mod:`machine`). - * Most standard library modules implement a subset of the functionality of - the equivalent Python module, and in a few cases provide some - MicroPython-specific extensions (e.g. :mod:`array`, :mod:`os`) + :ref:`Python standard library ` (e.g. :mod:`os`, + :mod:`time`), as well as :ref:`MicroPython-specific modules ` + (e.g. :mod:`bluetooth`, :mod:`machine`). + * Most Python standard library modules implement a subset of the + functionality of the equivalent Python module, and in a few cases provide + some MicroPython-specific extensions (e.g. :mod:`array`, :mod:`os`) * Due to resource constraints or other limitations, some ports or firmware versions may not include all the functionality documented here. - * To allow for extensibility, the built-in modules can be extended from - Python code loaded onto the device. + * To allow for extensibility, some built-in modules can be + :ref:`extended from Python code ` loaded onto + the device filesystem. This chapter describes modules (function and class libraries) which are built into MicroPython. This documentation in general aspires to describe all modules @@ -41,6 +43,8 @@ Beyond the built-in libraries described in this documentation, many more modules from the Python standard library, as well as further MicroPython extensions to it, can be found in :term:`micropython-lib`. +.. _micropython_lib_python: + Python standard libraries and micro-libraries --------------------------------------------- @@ -77,6 +81,7 @@ library. zlib.rst _thread.rst +.. _micropython_lib_micropython: MicroPython-specific libraries ------------------------------ @@ -181,23 +186,48 @@ The following libraries are specific to the Zephyr port. zephyr.rst +.. _micropython_lib_extending: + Extending built-in libraries from Python ---------------------------------------- -In most cases, the above modules are actually named ``umodule`` rather than -``module``, but MicroPython will alias any module prefixed with a ``u`` to the -non-``u`` version. However a file (or :term:`frozen module`) named -``module.py`` will take precedence over this alias. +Many built-in modules are actually named ``umodule`` rather than ``module``, but +MicroPython will alias any module prefixed with a ``u`` to the non-``u`` +version. This means that, for example, ``import time`` will first attempt to +resolve from the filesystem, and then failing that will fall back to the +built-in ``utime``. On the other hand, ``import utime`` will always go directly +to the built-in. This allows the user to provide an extended implementation of a built-in library -(perhaps to provide additional CPython compatibility). The user-provided module -(in ``module.py``) can still use the built-in functionality by importing -``umodule`` directly. This is used extensively in :term:`micropython-lib`. See -:ref:`packages` for more information. +(perhaps to provide additional CPython compatibility or missing functionality). +The user-provided module (in ``module.py``) can still use the built-in +functionality by importing ``umodule`` directly (e.g. typically an extension +module ``time.py`` will do ``from utime import *``). This is used extensively +in :term:`micropython-lib`. See :ref:`packages` for more information. -This applies to both the Python standard libraries (e.g. ``os``, ``time``, etc), -but also the MicroPython libraries too (e.g. ``machine``, ``bluetooth``, etc). -The main exception is the port-specific libraries (``pyb``, ``esp``, etc). +This extensibility applies to the following Python standard library modules +which are built-in to the firmware: ``array``, ``binascii``, ``collections``, +``errno``, ``hashlib``, ``heapq``, ``io``, ``json``, ``os``, ``platform``, +``random``, ``re``, ``select``, ``socket``, ``ssl``, ``struct``, ``sys``, +``time``, ``zlib``, as well as the MicroPython-specific libraries: ``bluepy``, +``bluetooth``, ``machine``, ``timeq``, ``websocket``. All other built-in +modules cannot be extended from the filesystem. *Other than when you specifically want to force the use of the built-in module, we recommend always using* ``import module`` *rather than* ``import umodule``. + +**Note:** In MicroPython v1.21.0 and higher, it is now possible to force an +import of the built-in module by clearing ``sys.path`` during the import. For +example, in ``time.py``, you can write:: + + _path = sys.path + sys.path = () + try: + from time import * + finally: + sys.path = _path + del _path + +This is now the preferred way (instead of ``from utime import *``), as the +``u``-prefix will be removed from the names of built-in modules in a future +version of MicroPython. From 7a17596e1aa8b10ea3e1cce42d73b46f9bf06078 Mon Sep 17 00:00:00 2001 From: Jonas Scharpf Date: Sat, 27 May 2023 17:44:26 +0200 Subject: [PATCH 140/565] docs/reference/packages: Add GitHub repo to package example dependency. Signed-off-by: Jonas Scharpf --- docs/reference/packages.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/reference/packages.rst b/docs/reference/packages.rst index 1ddbecb582..c9deedea77 100644 --- a/docs/reference/packages.rst +++ b/docs/reference/packages.rst @@ -53,7 +53,7 @@ can be downloaded by specifying the path to their ``package.json``. If no json file is specified, then "package.json" is implicitly added:: >>> mip.install("http://example.com/x/") - >>> mip.install("github:org/repo") + >>> mip.install("github:org/repo") # Uses default branch of that repo >>> mip.install("github:org/repo", version="branch-or-tag") @@ -108,9 +108,9 @@ https://github.com/micropython/micropython-lib for more information. To write a "self-hosted" package that can be downloaded by ``mip`` or ``mpremote``, you need a static webserver (or GitHub) to host either a -single .py file, or a package.json file alongside your .py files. +single .py file, or a ``package.json`` file alongside your .py files. -A typical package.json for an example ``mlx90640`` library looks like:: +A typical ``package.json`` for an example ``mlx90640`` library looks like:: { "urls": [ @@ -119,7 +119,8 @@ A typical package.json for an example ``mlx90640`` library looks like:: ], "deps": [ ["collections-defaultdict", "latest"], - ["os-path", "latest"] + ["os-path", "latest"], + ["github:org/micropython-additions", "main"] ], "version": "0.2" } @@ -127,7 +128,9 @@ A typical package.json for an example ``mlx90640`` library looks like:: This includes two files, hosted at a GitHub repo named ``org/micropython-mlx90640``, which install into the ``mlx90640`` directory on the device. It depends on ``collections-defaultdict`` and ``os-path`` which will -be installed automatically. +be installed automatically from the :term:`micropython-lib`. The third +dependency installs the content as defined by the ``package.json`` file of the +``main`` branch of the GitHub repo ``org/micropython-additions``. Freezing packages ----------------- From 1d4b4f0ce27a44be132971ed690189e470af28ce Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 31 May 2023 16:37:23 +1000 Subject: [PATCH 141/565] ports: Standardise docs link in help text. Updates all `help()` output to use the phrase: `For online docs please visit http://docs.micropython.org/` Some ports previously used different wording, some pointed to the wrong link. Also make all ports use `help.c` for consistency. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/cc3200/misc/help.c | 2 +- ports/esp32/help.c | 2 +- ports/esp8266/help.c | 3 +- ports/mimxrt/Makefile | 1 + ports/mimxrt/help.c | 74 ++++++++++++++++++++++++++++++++++++++ ports/mimxrt/main.c | 47 ------------------------ ports/nrf/help.c | 2 +- ports/renesas-ra/help.c | 2 +- ports/rp2/CMakeLists.txt | 1 + ports/rp2/help.c | 64 +++++++++++++++++++++++++++++++++ ports/rp2/main.c | 37 ------------------- ports/samd/help.c | 2 +- ports/stm32/factoryreset.c | 2 +- ports/stm32/help.c | 2 +- ports/teensy/help.c | 2 +- ports/zephyr/help.c | 2 ++ 16 files changed, 152 insertions(+), 93 deletions(-) create mode 100644 ports/mimxrt/help.c create mode 100644 ports/rp2/help.c diff --git a/ports/cc3200/misc/help.c b/ports/cc3200/misc/help.c index ea0c9501db..213950c8ed 100644 --- a/ports/cc3200/misc/help.c +++ b/ports/cc3200/misc/help.c @@ -28,5 +28,5 @@ #include "py/builtin.h" const char cc3200_help_text[] = "Welcome to MicroPython!\n" - "For online help please visit http://micropython.org/help/.\n" + "For online docs please visit http://docs.micropython.org/\n" "For further help on a specific object, type help(obj)\n"; diff --git a/ports/esp32/help.c b/ports/esp32/help.c index 2336d97f84..2351d7dc73 100644 --- a/ports/esp32/help.c +++ b/ports/esp32/help.c @@ -31,7 +31,7 @@ const char esp32_help_text[] = "Welcome to MicroPython on the ESP32!\n" "\n" - "For generic online docs please visit http://docs.micropython.org/\n" + "For online docs please visit http://docs.micropython.org/\n" "\n" "For access to the hardware use the 'machine' module:\n" "\n" diff --git a/ports/esp8266/help.c b/ports/esp8266/help.c index a755a10a76..a9cb27bad5 100644 --- a/ports/esp8266/help.c +++ b/ports/esp8266/help.c @@ -29,7 +29,8 @@ const char esp_help_text[] = "Welcome to MicroPython!\n" "\n" - "For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .\n" + "For online docs please visit http://docs.micropython.org/\n" + "\n" "For diagnostic information to include in bug reports execute 'import port_diag'.\n" "\n" "Basic WiFi configuration:\n" diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index cfef8ee0f9..63cba7d7a6 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -191,6 +191,7 @@ SRC_C += \ fatfs_port.c \ flash.c \ hal/pwm_backport.c \ + help.c \ led.c \ machine_adc.c \ machine_bitstream.c \ diff --git a/ports/mimxrt/help.c b/ports/mimxrt/help.c new file mode 100644 index 0000000000..10627aff7f --- /dev/null +++ b/ports/mimxrt/help.c @@ -0,0 +1,74 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Damien P. George + * + * 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 "py/builtin.h" + +const char mimxrt_help_text[] = + "Welcome to MicroPython!\n" + "\n" + "For online docs please visit http://docs.micropython.org/\n" + "\n" + "For access to the hardware use the 'machine' module. \n" + "\n" + "Quick overview of some objects:\n" + " machine.Pin(pin) -- get a pin, eg machine.Pin(0)\n" + " machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n" + " methods: init(..), value([v]), high(), low())\n" + "\n" + " Pins are numbered board specific, either 0-n, or 'D0'-'Dn', or 'A0' - 'An',\n" + " according to the boards's pinout sheet.\n" + " Pin IO modes are: Pin.IN, Pin.OUT, Pin.OPEN_DRAIN\n" + " Pin pull modes are: Pin.PULL_UP, Pin.PULL_UP_47K, Pin.PULL_UP_22K, Pin.PULL_DOWN, Pin.PULL_HOLD\n" + " machine.ADC(pin) -- make an analog object from a pin\n" + " methods: read_u16()\n" + " machine.UART(id, baudrate=115200) -- create an UART object (id=1 - 8, board-specific)\n" + " methods: init(), write(buf), any()\n" + " buf=read(n), readinto(buf), buf=readline()\n" + " The RX and TX pins are fixed and board-specific.\n" + " machine.SoftI2C() -- create a Soft I2C object\n" + " machine.I2C(id) -- create a HW I2C object\n" + " methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)\n" + " readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)\n" + " SoftI2C allows to use any pin for sda and scl, HW I2C id's and pins are fixed\n" + " machine.SoftSPI(baudrate=1000000) -- create a Soft SPI object\n" + " machine.SPI(id, baudrate=1000000) -- create a HW SPI object\n" + " methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)\n" + " SoftSPI allows to use any pin for SPI, HW SPI id's and pins are fixed\n" + " machine.Timer(id, freq, callback) -- create a hardware timer object (id=0,1,2)\n" + " eg: machine.Timer(freq=1, callback=lambda t:print(t))\n" + " machine.RTC() -- create a Real Time Clock object\n" + " methods: init(), datetime([dateime_tuple]), now()\n" + " machine.PWM(pin, freq, duty_u16[, kw_opts]) -- create a PWM object\n" + " methods: init(), duty_u16([value]), duty_ns([value]), freq([value])\n" + "\n" + "Useful control commands:\n" + " CTRL-C -- interrupt a running program\n" + " CTRL-D -- on a blank line, do a soft reset of the board\n" + " CTRL-E -- on a blank line, enter paste mode\n" + "\n" + "For further help on a specific object, type help(obj)\n" + "For a list of available modules, type help('modules')\n" +; diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index 8f8ecd91d4..9ac46e4814 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -151,50 +151,3 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c } } #endif - -const char mimxrt_help_text[] = - "Welcome to MicroPython!\n" - "\n" - "For online help please visit https://micropython.org/help/.\n" - "\n" - "For access to the hardware use the 'machine' module. \n" - "\n" - "Quick overview of some objects:\n" - " machine.Pin(pin) -- get a pin, eg machine.Pin(0)\n" - " machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n" - " methods: init(..), value([v]), high(), low())\n" - "\n" - " Pins are numbered board specific, either 0-n, or 'D0'-'Dn', or 'A0' - 'An',\n" - " according to the boards's pinout sheet.\n" - " Pin IO modes are: Pin.IN, Pin.OUT, Pin.OPEN_DRAIN\n" - " Pin pull modes are: Pin.PULL_UP, Pin.PULL_UP_47K, Pin.PULL_UP_22K, Pin.PULL_DOWN, Pin.PULL_HOLD\n" - " machine.ADC(pin) -- make an analog object from a pin\n" - " methods: read_u16()\n" - " machine.UART(id, baudrate=115200) -- create an UART object (id=1 - 8, board-specific)\n" - " methods: init(), write(buf), any()\n" - " buf=read(n), readinto(buf), buf=readline()\n" - " The RX and TX pins are fixed and board-specific.\n" - " machine.SoftI2C() -- create a Soft I2C object\n" - " machine.I2C(id) -- create a HW I2C object\n" - " methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)\n" - " readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)\n" - " SoftI2C allows to use any pin for sda and scl, HW I2C id's and pins are fixed\n" - " machine.SoftSPI(baudrate=1000000) -- create a Soft SPI object\n" - " machine.SPI(id, baudrate=1000000) -- create a HW SPI object\n" - " methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)\n" - " SoftSPI allows to use any pin for SPI, HW SPI id's and pins are fixed\n" - " machine.Timer(id, freq, callback) -- create a hardware timer object (id=0,1,2)\n" - " eg: machine.Timer(freq=1, callback=lambda t:print(t))\n" - " machine.RTC() -- create a Real Time Clock object\n" - " methods: init(), datetime([dateime_tuple]), now()\n" - " machine.PWM(pin, freq, duty_u16[, kw_opts]) -- create a PWM object\n" - " methods: init(), duty_u16([value]), duty_ns([value]), freq([value])\n" - "\n" - "Useful control commands:\n" - " CTRL-C -- interrupt a running program\n" - " CTRL-D -- on a blank line, do a soft reset of the board\n" - " CTRL-E -- on a blank line, enter paste mode\n" - "\n" - "For further help on a specific object, type help(obj)\n" - "For a list of available modules, type help('modules')\n" -; diff --git a/ports/nrf/help.c b/ports/nrf/help.c index afc979130f..b9ab16da62 100644 --- a/ports/nrf/help.c +++ b/ports/nrf/help.c @@ -34,7 +34,7 @@ const char nrf5_help_text[] = "Welcome to MicroPython!\n" "\n" - "For online help please visit http://micropython.org/help/.\n" + "For online docs please visit http://docs.micropython.org/\n" "\n" "Quick overview of commands for the board:\n" #if MICROPY_HW_HAS_LED diff --git a/ports/renesas-ra/help.c b/ports/renesas-ra/help.c index 3bce504d9c..48a06af348 100644 --- a/ports/renesas-ra/help.c +++ b/ports/renesas-ra/help.c @@ -30,7 +30,7 @@ const char ra_help_text[] = "Welcome to MicroPython for Renesas RA!\n" "\n" - "For online docs please visit http://docs.micropython.org/.\n" + "For online docs please visit http://docs.micropython.org/\n" "\n" "For access to hardware please use machine module.\n" "import machine\n" diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 4d0de92182..3dff0d54c6 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -114,6 +114,7 @@ set(MICROPY_SOURCE_DRIVERS set(MICROPY_SOURCE_PORT fatfs_port.c + help.c machine_adc.c machine_bitstream.c machine_i2c.c diff --git a/ports/rp2/help.c b/ports/rp2/help.c new file mode 100644 index 0000000000..5546411e6d --- /dev/null +++ b/ports/rp2/help.c @@ -0,0 +1,64 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Damien P. George + * + * 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 "py/builtin.h" + +const char rp2_help_text[] = + "Welcome to MicroPython!\n" + "\n" + "For online docs please visit http://docs.micropython.org/\n" + "\n" + "For access to the hardware use the 'machine' module. RP2 specific commands\n" + "are in the 'rp2' module.\n" + "\n" + "Quick overview of some objects:\n" + " machine.Pin(pin) -- get a pin, eg machine.Pin(0)\n" + " machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n" + " methods: init(..), value([v]), high(), low(), irq(handler)\n" + " machine.ADC(pin) -- make an analog object from a pin\n" + " methods: read_u16()\n" + " machine.PWM(pin) -- make a PWM object from a pin\n" + " methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d])\n" + " machine.I2C(id) -- create an I2C object (id=0,1)\n" + " methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)\n" + " readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)\n" + " machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1)\n" + " methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)\n" + " machine.Timer(freq, callback) -- create a software timer object\n" + " eg: machine.Timer(freq=1, callback=lambda t:print(t))\n" + "\n" + "Pins are numbered 0-29, and 26-29 have ADC capabilities\n" + "Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT\n" + "Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN\n" + "\n" + "Useful control commands:\n" + " CTRL-C -- interrupt a running program\n" + " CTRL-D -- on a blank line, do a soft reset of the board\n" + " CTRL-E -- on a blank line, enter paste mode\n" + "\n" + "For further help on a specific object, type help(obj)\n" + "For a list of available modules, type help('modules')\n" +; diff --git a/ports/rp2/main.c b/ports/rp2/main.c index 0ecc09b346..c5118857a4 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -260,40 +260,3 @@ uint32_t rosc_random_u32(void) { } return value; } - -const char rp2_help_text[] = - "Welcome to MicroPython!\n" - "\n" - "For online help please visit https://micropython.org/help/.\n" - "\n" - "For access to the hardware use the 'machine' module. RP2 specific commands\n" - "are in the 'rp2' module.\n" - "\n" - "Quick overview of some objects:\n" - " machine.Pin(pin) -- get a pin, eg machine.Pin(0)\n" - " machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n" - " methods: init(..), value([v]), high(), low(), irq(handler)\n" - " machine.ADC(pin) -- make an analog object from a pin\n" - " methods: read_u16()\n" - " machine.PWM(pin) -- make a PWM object from a pin\n" - " methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d])\n" - " machine.I2C(id) -- create an I2C object (id=0,1)\n" - " methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)\n" - " readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)\n" - " machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1)\n" - " methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)\n" - " machine.Timer(freq, callback) -- create a software timer object\n" - " eg: machine.Timer(freq=1, callback=lambda t:print(t))\n" - "\n" - "Pins are numbered 0-29, and 26-29 have ADC capabilities\n" - "Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT\n" - "Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN\n" - "\n" - "Useful control commands:\n" - " CTRL-C -- interrupt a running program\n" - " CTRL-D -- on a blank line, do a soft reset of the board\n" - " CTRL-E -- on a blank line, enter paste mode\n" - "\n" - "For further help on a specific object, type help(obj)\n" - "For a list of available modules, type help('modules')\n" -; diff --git a/ports/samd/help.c b/ports/samd/help.c index 577d153b53..c7d96ad2d9 100644 --- a/ports/samd/help.c +++ b/ports/samd/help.c @@ -29,7 +29,7 @@ const char samd_help_text[] = "Welcome to MicroPython!\n" "\n" - "For online docs please visit http://docs.micropython.org/en/latest/samd/ .\n" + "For online docs please visit http://docs.micropython.org/\n" "\n" "Control commands:\n" " CTRL-A -- on a blank line, enter raw REPL mode\n" diff --git a/ports/stm32/factoryreset.c b/ports/stm32/factoryreset.c index 2ac656db59..50854a908b 100644 --- a/ports/stm32/factoryreset.c +++ b/ports/stm32/factoryreset.c @@ -75,7 +75,7 @@ static const char fresh_readme_txt[] = " - Mac OS X: use the command: screen /dev/tty.usbmodem*\r\n" " - Linux: use the command: screen /dev/ttyACM0\r\n" "\r\n" - "Please visit http://micropython.org/help/ for further help.\r\n" + "For online docs please visit http://docs.micropython.org/\r\n" ; #endif diff --git a/ports/stm32/help.c b/ports/stm32/help.c index fba0a6937f..0b824e7b37 100644 --- a/ports/stm32/help.c +++ b/ports/stm32/help.c @@ -29,7 +29,7 @@ const char stm32_help_text[] = "Welcome to MicroPython!\n" "\n" - "For online help please visit http://micropython.org/help/.\n" + "For online docs please visit http://docs.micropython.org/\n" "\n" "Quick overview of commands for the board:\n" " pyb.info() -- print some general information\n" diff --git a/ports/teensy/help.c b/ports/teensy/help.c index 11625afc5a..e2857aedfd 100644 --- a/ports/teensy/help.c +++ b/ports/teensy/help.c @@ -29,7 +29,7 @@ const char teensy_help_text[] = "Welcome to MicroPython!\n" "\n" - "For online help please visit http://micropython.org/help/.\n" + "For online docs please visit http://docs.micropython.org/\n" "\n" "Quick overview of commands for the board:\n" " pyb.info() -- print some general information\n" diff --git a/ports/zephyr/help.c b/ports/zephyr/help.c index 4ee674b9d2..0b977fa033 100644 --- a/ports/zephyr/help.c +++ b/ports/zephyr/help.c @@ -29,6 +29,8 @@ const char zephyr_help_text[] = "Welcome to MicroPython!\n" "\n" + "For online docs please visit http://docs.micropython.org/\n" + "\n" "Control commands:\n" " CTRL-A -- on a blank line, enter raw REPL mode\n" " CTRL-B -- on a blank line, enter normal REPL mode\n" From aac8744671b690e22088a2960339b43c0bd45d88 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 31 May 2023 16:41:07 +1000 Subject: [PATCH 142/565] stm32/help: Don't include unavailable features in help(). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/stm32/help.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ports/stm32/help.c b/ports/stm32/help.c index 0b824e7b37..7bdb8e67a9 100644 --- a/ports/stm32/help.c +++ b/ports/stm32/help.c @@ -35,24 +35,38 @@ const char stm32_help_text[] = " pyb.info() -- print some general information\n" " pyb.delay(n) -- wait for n milliseconds\n" " pyb.millis() -- get number of milliseconds since hard reset\n" + #if MICROPY_HW_HAS_SWITCH " pyb.Switch() -- create a switch object\n" " Switch methods: (), callback(f)\n" + #endif " pyb.LED(n) -- create an LED object for LED n (n=1,2,3,4)\n" " LED methods: on(), off(), toggle(), intensity()\n" " pyb.Pin(pin) -- get a pin, eg pyb.Pin('X1')\n" " pyb.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n" " Pin methods: init(..), value([v]), high(), low()\n" " pyb.ExtInt(pin, m, p, callback) -- create an external interrupt object\n" + #if MICROPY_HW_ENABLE_ADC " pyb.ADC(pin) -- make an analog object from a pin\n" " ADC methods: read(), read_timed(buf, freq)\n" + #endif + #if MICROPY_HW_ENABLE_DAC " pyb.DAC(port) -- make a DAC object\n" " DAC methods: triangle(freq), write(n), write_timed(buf, freq)\n" + #endif + #if MICROPY_HW_ENABLE_RTC " pyb.RTC() -- make an RTC object; methods: datetime([val])\n" + #endif + #if MICROPY_HW_ENABLE_RNG " pyb.rng() -- get a 30-bit hardware random number\n" + #endif + #if MICROPY_HW_ENABLE_SERVO " pyb.Servo(n) -- create Servo object for servo n (n=1,2,3,4)\n" " Servo methods: calibration(..), angle([x, [t]]), speed([x, [t]])\n" + #endif + #if MICROPY_HW_HAS_MMA7660 " pyb.Accel() -- create an Accelerometer object\n" " Accelerometer methods: x(), y(), z(), tilt(), filtered_xyz()\n" + #endif "\n" "Pins are numbered X1-X12, X17-X22, Y1-Y12, or by their MCU name\n" "Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT_PP, pyb.Pin.OUT_OD\n" From e4886dda859d873e77b1ff5f5b8d4a3aa0f3d517 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2023 12:43:58 +1000 Subject: [PATCH 143/565] stm32/help: Exclude legacy entries from help, and adjust constant names. Signed-off-by: Damien George --- ports/stm32/help.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ports/stm32/help.c b/ports/stm32/help.c index 7bdb8e67a9..4d4f89caea 100644 --- a/ports/stm32/help.c +++ b/ports/stm32/help.c @@ -32,9 +32,11 @@ const char stm32_help_text[] = "For online docs please visit http://docs.micropython.org/\n" "\n" "Quick overview of commands for the board:\n" + #if MICROPY_PY_PYB_LEGACY " pyb.info() -- print some general information\n" " pyb.delay(n) -- wait for n milliseconds\n" " pyb.millis() -- get number of milliseconds since hard reset\n" + #endif #if MICROPY_HW_HAS_SWITCH " pyb.Switch() -- create a switch object\n" " Switch methods: (), callback(f)\n" @@ -69,8 +71,8 @@ const char stm32_help_text[] = #endif "\n" "Pins are numbered X1-X12, X17-X22, Y1-Y12, or by their MCU name\n" - "Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT_PP, pyb.Pin.OUT_OD\n" - "Pin pull modes are: pyb.Pin.PULL_NONE, pyb.Pin.PULL_UP, pyb.Pin.PULL_DOWN\n" + "Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT, pyb.Pin.OPEN_DRAIN\n" + "Pin pull modes are: None, pyb.Pin.PULL_UP, pyb.Pin.PULL_DOWN\n" "Additional serial bus objects: pyb.I2C(n), pyb.SPI(n), pyb.UART(n)\n" "\n" "Control commands:\n" From 7c2c9ea21cd320ac4044847f889ad3eeef7f8c7b Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 30 May 2023 13:23:12 +1000 Subject: [PATCH 144/565] tools/mpremote: Add `sleep` command. This allows the sequence to be paused (e.g. wait for device, etc). Also removes the t_ms arg in reset/bootloader, because these arguments don't really need to be changed, and keeping them would mean inconsistent units used for time delays. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tools/mpremote/mpremote/main.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index eafa5b97e3..50a4e334bd 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -18,7 +18,7 @@ MicroPython device over a serial connection. Commands supported are: """ import argparse -import os, sys +import os, sys, time from collections.abc import Mapping from textwrap import dedent @@ -42,6 +42,10 @@ from .repl import do_repl _PROG = "mpremote" +def do_sleep(state, args): + time.sleep(args.ms[0]) + + def do_help(state, _args=None): def print_commands_help(cmds, help_key): max_command_len = max(len(cmd) for cmd in cmds.keys()) @@ -98,6 +102,12 @@ def argparse_connect(): return cmd_parser +def argparse_sleep(): + cmd_parser = argparse.ArgumentParser(description="sleep before executing next command") + cmd_parser.add_argument("ms", nargs=1, type=float, help="milliseconds to sleep for") + return cmd_parser + + def argparse_edit(): cmd_parser = argparse.ArgumentParser(description="edit files on the device") cmd_parser.add_argument("files", nargs="+", help="list of remote paths") @@ -212,6 +222,10 @@ _COMMANDS = { do_connect, argparse_connect, ), + "sleep": ( + do_sleep, + argparse_sleep, + ), "disconnect": ( do_disconnect, argparse_none("disconnect current device"), @@ -294,19 +308,19 @@ _BUILTIN_COMMAND_EXPANSIONS = { "import uos\nprint('mount \\tsize \\tused \\tavail \\tuse%')\nfor _m in [''] + uos.listdir('/'):\n _s = uos.stat('/' + _m)\n if not _s[0] & 1 << 14: continue\n _s = uos.statvfs(_m)\n if _s[0]:\n _size = _s[0] * _s[2]; _free = _s[0] * _s[3]; print(_m, _size, _size - _free, _free, int(100 * (_size - _free) / _size), sep='\\t')", ], # Other shortcuts. - "reset t_ms=100": { + "reset": { "command": [ "exec", "--no-follow", - "import utime, machine; utime.sleep_ms(t_ms); machine.reset()", + "import time, machine; time.sleep_ms(100); machine.reset()", ], - "help": "reset the device after delay", + "help": "hard reset the device", }, - "bootloader t_ms=100": { + "bootloader": { "command": [ "exec", "--no-follow", - "import utime, machine; utime.sleep_ms(t_ms); machine.bootloader()", + "import time, machine; time.sleep_ms(100); machine.bootloader()", ], "help": "make the device enter its bootloader", }, From d736a2f3f3ea77359d077aaae537410814e86992 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 30 May 2023 13:25:29 +1000 Subject: [PATCH 145/565] tools/mpremote: Allow terminator for shortcut commands. For example, the `reset` shortcut previously allowed an optional delay, but the argument handling cannot handle `reset next-command` as `next-command` will be interpreted as the delay argument. The fix in this commit allows `reset + next-command`. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tools/mpremote/mpremote/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index 50a4e334bd..e1caee13a3 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -406,6 +406,8 @@ def do_command_expansion(args): cmd = args.pop(0) exp_args, exp_sub, _ = _command_expansions[cmd] for exp_arg in exp_args: + if args and args[0] == "+": + break exp_arg_name = exp_arg[0] if args and "=" not in args[0]: # Argument given without a name. From 46715e370d3f283fcc2683f05e7898d54a66b59c Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 30 May 2023 13:45:45 +1000 Subject: [PATCH 146/565] tools/mpremote: Add `rtc` commands to get and set the RTC. Replaces the existing functionality provided by the `setrtc` alias to use the current time, rather than a hard-coded date/time. Use `rtc` to query the current time. Use `rtc --set` to set it. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tools/mpremote/mpremote/commands.py | 20 ++++++++++++++++++++ tools/mpremote/mpremote/main.py | 16 ++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 8bcb73b6ff..805fcd4fc0 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -236,3 +236,23 @@ def do_resume(state, _args=None): def do_soft_reset(state, _args=None): state.ensure_raw_repl(soft_reset=True) + + +def do_rtc(state, args): + if args.set: + import datetime + + now = datetime.datetime.now() + timetuple = "({}, {}, {}, {}, {}, {}, {}, {})".format( + now.year, + now.month, + now.day, + now.weekday(), + now.hour, + now.minute, + now.second, + now.microsecond, + ) + _do_execbuffer(state, "import machine; machine.RTC().datetime({})".format(timetuple), True) + else: + _do_execbuffer(state, "import machine; print(machine.RTC().datetime())", True) diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index e1caee13a3..dad14b78be 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -34,6 +34,7 @@ from .commands import ( do_eval, do_run, do_resume, + do_rtc, do_soft_reset, ) from .mip import do_mip @@ -172,6 +173,12 @@ def argparse_run(): return cmd_parser +def argparse_rtc(): + cmd_parser = argparse.ArgumentParser(description="get (default) or set the device RTC") + _bool_flag(cmd_parser, "set", "s", False, "set the RTC to the current local time") + return cmd_parser + + def argparse_filesystem(): cmd_parser = argparse.ArgumentParser(description="execute filesystem commands on the device") _bool_flag(cmd_parser, "recursive", "r", False, "recursive copy (for cp command only)") @@ -266,6 +273,10 @@ _COMMANDS = { do_run, argparse_run, ), + "rtc": ( + do_rtc, + argparse_rtc, + ), "fs": ( do_filesystem, argparse_filesystem, @@ -324,10 +335,7 @@ _BUILTIN_COMMAND_EXPANSIONS = { ], "help": "make the device enter its bootloader", }, - "setrtc": [ - "exec", - "import machine; machine.RTC().datetime((2020, 1, 1, 0, 10, 0, 0, 0))", - ], + # Simple aliases. "--help": "help", "--version": "version", } From b6b19798c21f8d8da6230c2c588a74997a71a853 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 31 May 2023 11:16:34 +1000 Subject: [PATCH 147/565] tools/mpremote: Handle `cp` without destination. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tools/pyboard.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/pyboard.py b/tools/pyboard.py index 7b546b99d1..0ce2d291e6 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -686,6 +686,10 @@ def filesystem_command(pyb, args, progress_callback=None, verbose=False): args = args[1:] try: if cmd == "cp": + if len(args) == 1: + raise PyboardError( + "cp: missing destination file operand after '{}'".format(args[0]) + ) srcs = args[:-1] dest = args[-1] if dest.startswith(":"): From bd5d0163c4aa11fda2afad19396c741e40843a5f Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 30 May 2023 17:31:05 +1000 Subject: [PATCH 148/565] docs/reference/mpremote.rst: Extend the mpremote guide. Changes in this commit: - Add a extra detail to each of the commands. - Add more about handling options and arguments. - Include shortcut commands that behave like real commands to the command list (e.g. bootloader, rtc). - Add extra information and reword to address common misconceptions, in particular how commands chain together. - Add additional examples showing some more interesting combinations. - Add descriptions to each of the examples. - Add pipx installation instructions. - Describe how user-configuration works. This work was sponsored by Google Season of Docs. Signed-off-by: Jim Mussared --- docs/reference/mpremote.rst | 546 +++++++++++++++++++++++++++----- tools/mpremote/mpremote/main.py | 3 +- 2 files changed, 476 insertions(+), 73 deletions(-) diff --git a/docs/reference/mpremote.rst b/docs/reference/mpremote.rst index e96b32cbbe..b826725360 100644 --- a/docs/reference/mpremote.rst +++ b/docs/reference/mpremote.rst @@ -4,46 +4,88 @@ MicroPython remote control: mpremote ==================================== The ``mpremote`` command line tool provides an integrated set of utilities to -remotely interact with and automate a MicroPython device over a serial -connection. +remotely interact with, manage the filesystem on, and automate a MicroPython +device over a serial connection. -To use mpremote install it via ``pip``: +To use mpremote, first install it via ``pip``: .. code-block:: bash - $ pip install mpremote + $ pip install --user mpremote + +Or via `pipx `_: + +.. code-block:: bash + + $ pipx install mpremote The simplest way to use this tool is just by invoking it without any arguments: .. code-block:: bash - mpremote + $ mpremote This command automatically detects and connects to the first available USB -serial device and provides an interactive REPL. Serial ports are opened in -exclusive mode, so running a second (or third, etc) instance of ``mpremote`` -will connect to subsequent serial devices, if any are available. +serial device and provides an interactive terminal that you can use to access +the REPL and your program's output. Serial ports are opened in exclusive mode, +so running a second (or third, etc) instance of ``mpremote`` will connect to +subsequent serial devices, if any are available. +Additionally ``pipx`` also allows you to directly run ``mpremote`` without +installing first: + +.. code-block:: bash + + $ pipx run mpremote ...args Commands -------- -For REPL access, running ``mpremote`` without any arguments is usually all that -is needed. ``mpremote`` also supports a set of commands given at the command -line which will perform various actions on remote MicroPython devices. +``mpremote`` supports being given a series of commands given at the command line +which will perform various actions in sequence on a remote MicroPython device. +See the :ref:`examples section ` below to get an idea of how +this works and for some common combinations of commands. -For commands that support multiple arguments (e.g. a list of files), the -argument list can be terminated with ``+``. +Each command is of the form `` [--options] [args...]``. For commands +that support multiple arguments (e.g. a list of files), the argument list can +be terminated with ``+``. + +If no command is specified, the default command is ``repl``. Additionally, if +any command needs to access the device, and no earlier ``connect`` has been +specified, then an implicit ``connect auto`` is added. + +In order to get the device into a known state for any action command +(except ``repl``), once connected ``mpremote`` will stop any running program +and soft-reset the device before running the first command. You can control +this behavior using the ``resume`` and ``soft-reset`` commands. +See :ref:`auto-connection and auto-soft-reset ` for more details. + +Multiple commands can be specified and they will be run sequentially. The full list of supported commands are: -- connect to a specified device via a device-name shortcut: +- `connect ` +- `disconnect ` +- `resume ` +- `soft_reset ` +- `repl ` +- `eval ` +- `exec ` +- `run ` +- `fs ` +- `df ` +- `edit ` +- `mip ` +- `mount ` +- `unmount ` +- `rtc ` +- `sleep ` +- `reset ` +- `bootloader ` - .. code-block:: bash +.. _mpremote_command_connect: - $ mpremote - -- connect to specified device via name: +- **connect** -- connect to specified device via name: .. code-block:: bash @@ -54,41 +96,60 @@ The full list of supported commands are: - ``list``: list available devices - ``auto``: connect to the first available USB serial port - ``id:``: connect to the device with USB serial number - ```` (the second entry in the output from the ``connect list`` - command) - - ``port:``: connect to the device with the given path + ```` (the second column from the ``connect list`` + command output) + - ``port:``: connect to the device with the given path (the first column + from the ``connect list`` command output - any valid device name/path, to connect to that device -- disconnect current device: + **Note:** Instead of using the ``connect`` command, there are several + :ref:`pre-defined shortcuts ` for common device paths. For + example the ``a0`` shortcut command is equivalent to + ``connect /dev/ttyACM0`` (Linux), or ``c0`` for ``COM0`` (Windows). + + **Note:** The ``auto`` option will only detect USB serial ports, i.e. a serial + port that has an associated USB VID/PID (i.e. CDC/ACM or FTDI-style + devices). Other types of serial ports + +.. _mpremote_command_disconnect: + +- **disconnect** -- disconnect current device: .. code-block:: bash $ mpremote disconnect - After a disconnect, auto soft-reset is enabled. + After a disconnect, :ref:`auto-soft-reset ` is enabled. -- resume a previous ``mpremote`` session: +.. _mpremote_command_resume: + +- **resume** -- maintain existing interpreter state for subsequent commands: .. code-block:: bash $ mpremote resume - This disables auto soft-reset. + This disables :ref:`auto-soft-reset `. This is useful if you + want to run a subsequent command on a board without first soft-resetting it. -- perform a soft-reset of the device: +.. _mpremote_command_soft_reset: + +- **soft-reset** -- perform a soft-reset of the device: .. code-block:: bash $ mpremote soft-reset This will clear out the Python heap and restart the interpreter. It also - disables auto soft-reset. + prevents the subsequent command from triggering :ref:`auto-soft-reset `. -- enter the REPL on the connected device: +.. _mpremote_command_repl: + +- **repl** -- enter the REPL on the connected device: .. code-block:: bash - $ mpremote repl [options] + $ mpremote repl [--options] Options are: @@ -96,47 +157,121 @@ The full list of supported commands are: - ``--capture ``, to capture output of the REPL session to the given file - ``--inject-code ``, to specify characters to inject at the REPL when - Ctrl-J is pressed + ``Ctrl-J`` is pressed. This allows you to automate a common command. - ``--inject-file ``, to specify a file to inject at the REPL when - Ctrl-K is pressed + ``Ctrl-K`` is pressed. This allows you to run a file (e.g. containing some + useful setup code, or even the program you are currently working on). -- evaluate and print the result of a Python expression: + While the ``repl`` command running, you can use ``Ctrl-]`` or ``Ctrl-x`` to + exit. + + **Note:** The name "REPL" here reflects that the common usage of this command + to access the Read Eval Print Loop that is running on the MicroPython + device. Strictly, the ``repl`` command is just functioning as a terminal + (or "serial monitor") to access the device. Because this command does not + trigger the :ref:`auto-reset behavior `, this means that if + a program is currently running, you will first need to interrupt it with + ``Ctrl-C`` to get to the REPL, which will then allow you to access program + state. You can also use ``mpremote soft-reset repl`` to get a "clean" REPL + with all program state cleared. + +.. _mpremote_command_eval: + +- **eval** -- evaluate and print the result of a Python expression: .. code-block:: bash $ mpremote eval -- execute the given Python code: +.. _mpremote_command_exec: + +- **exec** -- execute the given Python code: .. code-block:: bash $ mpremote exec -- run a script from the local filesystem: + By default, ``mpremote exec`` will display any output from the expression until it + terminates. The ``--no-follow`` flag can be specified to return immediately and leave + the device running the expression in the background. + +.. _mpremote_command_run: + +- **run** -- run a script from the local filesystem: .. code-block:: bash - $ mpremote run + $ mpremote run -- execute filesystem commands on the device: + This will execute the file directly from RAM on the device without copying it + to the filesystem. This is a very useful way to iterate on the development of + a single piece of code without having to worry about deploying it to the + filesystem. + + By default, ``mpremote run`` will display any output from the script until it + terminates. The ``--no-follow`` flag can be specified to return immediately and leave + the device running the script in the background. + +.. _mpremote_command_fs: + +- **fs** -- execute filesystem commands on the device: .. code-block:: bash - $ mpremote fs + $ mpremote fs - ```` may be: + ```` may be: - ``cat `` to show the contents of a file or files on the device - ``ls`` to list the current directory - ``ls `` to list the given directories - - ``cp [-r] `` to copy files; use ":" as a prefix to specify - a file on the device + - ``cp [-r] `` to copy files - ``rm `` to remove files on the device - ``mkdir `` to create directories on the device - ``rmdir `` to remove directories on the device - ``touch `` to create the files (if they don't already exist) -- edit a file on the device: + The ``cp`` command uses a convention where a leading ``:`` represents a remote + path. Without a leading ``:`` means a local path. This is based on the + convention used by the `Secure Copy Protocol (scp) client + `_. All other commands + implicitly assume the path is a remote path, but the ``:`` can be optionally + used for clarity. + + So for example, ``mpremote fs cp main.py :main.py`` copies ``main.py`` from + the current local directory to the remote filesystem, whereas + ``mpremote fs cp :main.py main.py`` copies ``main.py`` from the device back + to the current directory. + + All of the filesystem sub-commands take multiple path arguments, so if there + is another command in the sequence, you must use ``+`` to terminate the + arguments, e.g. + + .. code-block:: bash + + $ mpremote fs cp main.py :main.py + repl + + This will copy the file to the device then enter the REPL. The ``+`` prevents + ``"repl"`` being interpreted as a path. + + **Note:** For convenience, all of the filesystem sub-commands are also + :ref:`aliased as regular commands `, i.e. you can write + ``mpremote cp ...`` instead of ``mpremote fs cp ...``. + +.. _mpremote_command_df: + +- **df** -- query device free/used space + + .. code-block:: bash + + $ mpremote df + + The ``df`` command will print size/used/free statistics for the device + filesystem, similar to the Unix ``df`` command. + +.. _mpremote_command_edit: + +- **edit** -- edit a file on the device: .. code-block:: bash @@ -147,7 +282,9 @@ The full list of supported commands are: variable ``$EDITOR``). If the editor exits successfully, the updated file will be copied back to the device. -- install packages from :term:`micropython-lib` (or GitHub) using the ``mip`` tool: +.. _mpremote_command_mip: + +- **mip** -- install packages from :term:`micropython-lib` (or GitHub) using the ``mip`` tool: .. code-block:: bash @@ -155,16 +292,34 @@ The full list of supported commands are: See :ref:`packages` for more information. -- mount the local directory on the remote device: +.. _mpremote_command_mount: + +- **mount** -- mount the local directory on the remote device: .. code-block:: bash $ mpremote mount [options] - During usage, Ctrl-D will soft-reboot and normally reconnect the mount automatically. - If the unit has a main.py running at startup however the remount cannot occur. - In this case a raw mode soft reboot can be used: Ctrl-A Ctrl-D to reboot, - then Ctrl-B to get back to normal repl at which point the mount will be ready. + This allows the remote device to see the local host directory as if it were + its own filesystem. This is useful for development, and avoids the need to + copy files to the device while you are working on them. + + The device installs a filesystem driver, which is then mounted in the + :ref:`device VFS ` as ``/remote``, which uses the serial + connection to ``mpremote`` as a side-channel to access files. The device + will have its current working directory (via ``os.chdir``) set to + ``/remote`` so that imports and file access will occur there instead of the + default filesystem path while the mount is active. + + **Note:** If the ``mount`` command is not followed by another action in the + sequence, a ``repl`` command will be implicitly added to the end of the + sequence. + + During usage, Ctrl-D will trigger a soft-reset as normal, but the mount will + automatically be re-connected. If the unit has a main.py running at startup + however the remount cannot occur. In this case a raw mode soft reboot can be + used: Ctrl-A Ctrl-D to reboot, then Ctrl-B to get back to normal repl at + which point the mount will be ready. Options are: @@ -173,22 +328,74 @@ The full list of supported commands are: local directory that is mounted. This option disables this check for symbolic links, allowing the device to follow symbolic links outside of the local directory. -- unmount the local directory from the remote device: +.. _mpremote_command_unmount: + +- **unmount** -- unmount the local directory from the remote device: .. code-block:: bash $ mpremote umount -Multiple commands can be specified and they will be run sequentially. + This happens automatically when ``mpremote`` terminates, but it can be used + in a sequence to unmount an earlier mount before subsequent command are run. +.. _mpremote_command_rtc: + +- **rtc** -- set/get the device clock (RTC): + + .. code-block:: bash + + $ mpremote rtc + + This will query the device RTC for the current time and print it as a datetime + tuple. + + .. code-block:: bash + + $ mpremote rtc --set + + This will set the device RTC to the host PC's current time. + +.. _mpremote_command_sleep: + +- **sleep** -- sleep (delay) before executing the next command + + .. code-block:: bash + + $ mpremote sleep 0.5 + + This will pause execution of the command sequence for the specified duration + in seconds, e.g. to wait for the device to do something. + +.. _mpremote_command_reset: + +- **reset** -- hard reset the device + + .. code-block:: bash + + $ mpremote reset + + **Note:** hard reset is equivalent to :func:`machine.reset`. + +.. _mpremote_command_bootloader: + +- **bootloader** enter the bootloader + + .. code-block:: bash + + $ mpremote bootloader + + This will make the device enter its bootloader. The bootloader is port- and + board-specific (e.g. DFU on stm32, UF2 on rp2040/Pico). + +.. _mpremote_reset: Auto connection and soft-reset ------------------------------ Connection and disconnection will be done automatically at the start and end of the execution of the tool, if such commands are not explicitly given. Automatic -connection will search for the first available USB serial device. If no action -is specified then the REPL will be entered. +connection will search for the first available USB serial device. Once connected to a device, ``mpremote`` will automatically soft-reset the device if needed. This clears the Python heap and restarts the interpreter, @@ -198,38 +405,60 @@ executed: ``mount``, ``eval``, ``exec``, ``run``, ``fs``. After doing a soft-reset for the first time, it will not be done again automatically, until a ``disconnect`` command is issued. -Auto soft-reset behaviour can be controlled by the ``resume`` command. And the -``soft-reset`` command can be used to perform an explicit soft reset. +Auto-soft-reset behaviour can be controlled by the ``resume`` command. This +might be useful to use the ``eval`` command to inspect the state of of the +device. The ``soft-reset`` command can be used to perform an explicit soft +reset in the middle of a sequence of commands. +.. _mpremote_shortcuts: Shortcuts --------- -Shortcuts can be defined using the macro system. Built-in shortcuts are:: +Shortcuts can be defined using the macro system. Built-in shortcuts are: -- ``devs``: list available devices (shortcut for ``connect list``) +- ``devs``: Alias for ``connect list`` -- ``a0``, ``a1``, ``a2``, ``a3``: connect to /dev/ttyACM? +- ``a0``, ``a1``, ``a2``, ``a3``: Aliases for ``connect /dev/ttyACMn`` -- ``u0``, ``u1``, ``u2``, ``u3``: connect to /dev/ttyUSB? +- ``u0``, ``u1``, ``u2``, ``u3``: Aliases for ``connect /dev/ttyUSBn`` -- ``c0``, ``c1``, ``c2``, ``c3``: connect to COM? +- ``c0``, ``c1``, ``c2``, ``c3``: Aliases for ``connect COMn`` -- ``cat``, ``ls``, ``cp``, ``rm``, ``mkdir``, ``rmdir``, ``touch``, ``df``: - filesystem commands +- ``cat``, ``edit``, ``ls``, ``cp``, ``rm``, ``mkdir``, ``rmdir``, ``touch``: Aliases for ``fs `` -- ``reset``: reset the device +Additional shortcuts can be defined by in user-configuration files, which is +located at ``.config/mpremote/config.py``. This file should define a +dictionary named ``commands``. The keys of this dictionary are the shortcuts +and the values are either a string or a list-of-strings: -- ``bootloader``: make the device enter its bootloader +.. code-block:: python3 -Any user configuration, including user-defined shortcuts, can be placed in the file -``.config/mpremote/config.py``. For example: + "c33": "connect id:334D335C3138", + +The command ``c33`` is replaced by ``connect id:334D335C3138``. + +.. code-block:: python3 + + "test": ["mount", ".", "exec", "import test"], + +The command ``test`` is replaced by ``mount . exec "import test"``. + +Shortcuts can also accept arguments. For example: + +.. code-block:: python3 + + "multiply x=4 y=7": "eval x*y", + +Running ``mpremote times 3 7`` will set ``x`` and ``y`` as variables on the device, then evaluate the expression ``x*y``. + +An example ``config.py`` might look like: .. code-block:: python3 commands = { - "c33": "connect id:334D335C3138", - "bl": "bootloader", + "c33": "connect id:334D335C3138", # Connect to a specific device by ID. + "bl": "bootloader", # Shorter alias for bootloader. "double x=4": "eval x*2", # x is an argument, with default 4 "wl_scan": ["exec", """ import network @@ -237,10 +466,16 @@ Any user configuration, including user-defined shortcuts, can be placed in the f wl.active(1) for ap in wl.scan(): print(ap) - """,], - "test": ["mount", ".", "exec", "import test"], + """,], # Print out nearby WiFi networks. + "wl_ifconfig": [ + "exec", + "import network; sta_if = network.WLAN(network.STA_IF); print(sta_if.ifconfig())", + """,], # Print ip address of station interface. + "test": ["mount", ".", "exec", "import test"], # Mount current directory and run test.py. + "demo": ["run", "path/to/demo.py"], # Execute demo.py on the device. } +.. _mpremote_examples: Examples -------- @@ -249,38 +484,205 @@ Examples mpremote +Connect to the first available device and implicitly run the ``repl`` command. + +.. code-block:: bash + mpremote a1 - mpremote connect /dev/ttyUSB0 repl +Connect to the device at ``/dev/ttyACM1`` (Linux) and implicitly run the +``repl`` command. See :ref:`shortcuts ` above. - mpremote ls +.. code-block:: bash + + mpremote c1 + +Connect to the device at ``COM1`` (Windows) and implicitly run the ``repl`` +command. See :ref:`shortcuts ` above. + +.. code-block:: bash + + mpremote connect /dev/ttyUSB0 + +Explicitly specify which device to connect to, and as above, implicitly run the +``repl`` command. + +.. code-block:: bash mpremote a1 ls +Connect to the device at ``/dev/ttyACM0`` and then run the ``ls`` command. + +It is equivalent to ``mpremote connect /dev/ttyACM1 fs ls``. + +.. code-block:: bash + mpremote exec "import micropython; micropython.mem_info()" +Run the specified Python command and display any output. This is equivalent to +typing the command at the REPL prompt. + +.. code-block:: bash + mpremote eval 1/2 eval 3/4 +Evaluate each expression in turn and print the results. + +.. code-block:: bash + + mpremote a0 eval 1/2 a1 eval 3/4 + +Evaluate ``1/2`` on the device at ``/dev/ttyACM0``, then ``3/4`` on the +device at ``/dev/ttyACM1``, printing each result. + +.. code-block:: bash + + mpremote resume exec "print_state_info()" soft-reset + +Connect to the device without triggering a soft reset and execute the +``print_state_info()`` function (e.g. to find out information about the current +program state), then trigger a soft reset. + +.. code-block:: bash + + mpremote reset sleep 0.5 bootloader + +Hard-reset the device, wait 500ms for it to become available, then enter the +bootloader. + +.. code-block:: bash + + mpremote cp utils/driver.py :utils/driver.py + run test.py + +Update the copy of utils/driver.py on the device, then execute the local +``test.py`` script on the device. ``test.py`` is never copied to the device +filesystem, rather it is run from RAM. + +.. code-block:: bash + + mpremote cp utils/driver.py :utils/driver.py + exec "import app" + +Update the copy of utils/driver.py on the device, then execute app.py on the +device. + +This is a common development workflow to update a single file and then re-start +your program. In this scenario, your ``main.py`` on the device would also do +``import app``. + +.. code-block:: bash + + mpremote cp utils/driver.py :utils/driver.py + soft-reset repl + +Update the copy of utils/driver.py on the device, then trigger a soft-reset to +restart your program, and then monitor the output via the ``repl`` command. + +.. code-block:: bash + + mpremote cp -r utils/ :utils/ + soft-reset repl + +Same as above, but update the entire utils directory first. + +.. code-block:: bash + mpremote mount . - mpremote mount . exec "import local_script" +Mount the current local directory at ``/remote`` on the device and starts a +``repl`` session which will use ``/remote`` as the working directory. - mpremote ls +.. code-block:: bash + + mpremote mount . exec "import demo" + +After mounting the current local directory, executes ``demo.py`` from the +mounted directory. + +.. code-block:: bash + + mpremote mount app run test.py + +After mounting the local directory ``app`` as ``/remote`` on the device, +executes the local ``test.py`` from the host's current directory without +copying it to the filesystem. + +.. code-block:: bash + + mpremote mount . repl --inject-code "import demo" + +After mounting the current local directory, executes ``demo.py`` from the +mounted directory each time ``Ctrl-J`` is pressed. + +You will first need to press ``Ctrl-D`` to reset the interpreter state +(which will preserve the mount) before pressing ``Ctrl-J`` to re-import +``demo.py``. + +.. code-block:: bash + + mpremote mount app repl --inject-file demo.py + +Same as above, but executes the contents of the local file demo.py at the REPL +every time ``Ctrl-K`` is pressed. As above, use Ctrl-D to reset the interpreter +state first. + +.. code-block:: bash mpremote cat boot.py +Displays the contents of ``boot.py`` on the device. + +.. code-block:: bash + + mpremote edit utils/driver.py + +Edit ``utils/driver.py`` on the device using your local ``$EDITOR``. + +.. code-block:: bash + mpremote cp :main.py . +Copy ``main.py`` from the device to the local directory. + +.. code-block:: bash + mpremote cp main.py : +Copy ``main.py`` from the local directory to the device. + +.. code-block:: bash + mpremote cp :a.py :b.py +Copy ``a.py`` on the device to ``b.py`` on the device. + +.. code-block:: bash + mpremote cp -r dir/ : +Recursively copy the local directory ``dir`` to the remote device. + +.. code-block:: bash + mpremote cp a.py b.py : + repl +Copy ``a.py`` and ``b.py`` from the local directory to the device, then run the +``repl`` command. + +.. code-block:: bash + mpremote mip install aioble +Install the ``aioble`` package from :term:`micropython-lib` to the device. +See :ref:`packages`. + +.. code-block:: bash + mpremote mip install github:org/repo@branch +Install the package from the specified branch at org/repo on GitHub to the +device. See :ref:`packages`. + +.. code-block:: bash + mpremote mip install --target /flash/third-party functools + +Install the ``functools`` package from :term:`micropython-lib` to the +``/flash/third-party`` directory on the device. See :ref:`packages`. diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index dad14b78be..cb96369a53 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -306,7 +306,7 @@ _BUILTIN_COMMAND_EXPANSIONS = { "command": "connect list", "help": "list available serial ports", }, - # Filesystem shortcuts. + # Filesystem shortcuts (use `cp` instead of `fs cp`). "cat": "fs cat", "ls": "fs ls", "cp": "fs cp", @@ -314,6 +314,7 @@ _BUILTIN_COMMAND_EXPANSIONS = { "touch": "fs touch", "mkdir": "fs mkdir", "rmdir": "fs rmdir", + # Disk used/free. "df": [ "exec", "import uos\nprint('mount \\tsize \\tused \\tavail \\tuse%')\nfor _m in [''] + uos.listdir('/'):\n _s = uos.stat('/' + _m)\n if not _s[0] & 1 << 14: continue\n _s = uos.statvfs(_m)\n if _s[0]:\n _size = _s[0] * _s[2]; _free = _s[0] * _s[3]; print(_m, _size, _size - _free, _free, int(100 * (_size - _free) / _size), sep='\\t')", From b4d785fa201bb2e9ecf5abb47e0cba21a9d8b6f7 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 31 May 2023 14:19:14 +1000 Subject: [PATCH 149/565] tools/mpremote: Detach mpremote from pyboard.py. This commit just takes the necessary parts of pyboard.py and merges them with pyboardextended.py to make a new transport_serial.py, and updates the rest of mpremote to use this instead. It is difficult to continue to add features to mpremote (which usually requires modification to pyboard.py) while also maintaining backwards compatibility for pyboard.py. The idea is that this provides a starting point for further refactoring of mpremote to allow different transports (webrepl, BLE, etc). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tools/mpremote/mpremote/commands.py | 68 +- tools/mpremote/mpremote/main.py | 12 +- tools/mpremote/mpremote/mip.py | 42 +- tools/mpremote/mpremote/repl.py | 24 +- tools/mpremote/mpremote/transport.py | 33 + ...pyboardextended.py => transport_serial.py} | 711 +++++++++++++++--- tools/mpremote/pyproject.toml | 6 - 7 files changed, 708 insertions(+), 188 deletions(-) create mode 100644 tools/mpremote/mpremote/transport.py rename tools/mpremote/mpremote/{pyboardextended.py => transport_serial.py} (50%) diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 805fcd4fc0..9e05aca376 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -4,7 +4,8 @@ import tempfile import serial.tools.list_ports -from . import pyboardextended as pyboard +from .transport import TransportError +from .transport_serial import SerialTransport class CommandError(Exception): @@ -36,28 +37,28 @@ def do_connect(state, args=None): for p in sorted(serial.tools.list_ports.comports()): if p.vid is not None and p.pid is not None: try: - state.pyb = pyboard.PyboardExtended(p.device, baudrate=115200) + state.transport = SerialTransport(p.device, baudrate=115200) return - except pyboard.PyboardError as er: + except TransportError as er: if not er.args[0].startswith("failed to access"): raise er - raise pyboard.PyboardError("no device found") + raise TransportError("no device found") elif dev.startswith("id:"): # Search for a device with the given serial number. serial_number = dev[len("id:") :] dev = None for p in serial.tools.list_ports.comports(): if p.serial_number == serial_number: - state.pyb = pyboard.PyboardExtended(p.device, baudrate=115200) + state.transport = SerialTransport(p.device, baudrate=115200) return - raise pyboard.PyboardError("no device with serial number {}".format(serial_number)) + raise TransportError("no device with serial number {}".format(serial_number)) else: # Connect to the given device. if dev.startswith("port:"): dev = dev[len("port:") :] - state.pyb = pyboard.PyboardExtended(dev, baudrate=115200) + state.transport = SerialTransport(dev, baudrate=115200) return - except pyboard.PyboardError as er: + except TransportError as er: msg = er.args[0] if msg.startswith("failed to access"): msg += " (it may be in use by another program)" @@ -66,23 +67,23 @@ def do_connect(state, args=None): def do_disconnect(state, _args=None): - if not state.pyb: + if not state.transport: return try: - if state.pyb.mounted: - if not state.pyb.in_raw_repl: - state.pyb.enter_raw_repl(soft_reset=False) - state.pyb.umount_local() - if state.pyb.in_raw_repl: - state.pyb.exit_raw_repl() + if state.transport.mounted: + if not state.transport.in_raw_repl: + state.transport.enter_raw_repl(soft_reset=False) + state.transport.umount_local() + if state.transport.in_raw_repl: + state.transport.exit_raw_repl() except OSError: # Ignore any OSError exceptions when shutting down, eg: # - pyboard.filesystem_command will close the connection if it had an error # - umounting will fail if serial port disappeared pass - state.pyb.close() - state.pyb = None + state.transport.close() + state.transport = None state._auto_soft_reset = True @@ -136,16 +137,17 @@ def do_filesystem(state, args): raise CommandError("'cp -r' source files must be local") _list_recursive(src_files, path) known_dirs = {""} - state.pyb.exec_("import uos") + state.transport.exec_("import uos") for dir, file in src_files: dir_parts = dir.split("/") for i in range(len(dir_parts)): d = "/".join(dir_parts[: i + 1]) if d not in known_dirs: - state.pyb.exec_("try:\n uos.mkdir('%s')\nexcept OSError as e:\n print(e)" % d) + state.transport.exec_( + "try:\n uos.mkdir('%s')\nexcept OSError as e:\n print(e)" % d + ) known_dirs.add(d) - pyboard.filesystem_command( - state.pyb, + state.transport.filesystem_command( ["cp", "/".join((dir, file)), ":" + dir + "/"], progress_callback=show_progress_bar, verbose=verbose, @@ -154,8 +156,8 @@ def do_filesystem(state, args): if args.recursive: raise CommandError("'-r' only supported for 'cp'") try: - pyboard.filesystem_command( - state.pyb, [command] + paths, progress_callback=show_progress_bar, verbose=verbose + state.transport.filesystem_command( + [command] + paths, progress_callback=show_progress_bar, verbose=verbose ) except OSError as er: raise CommandError(er) @@ -166,17 +168,17 @@ def do_edit(state, args): state.did_action() if not os.getenv("EDITOR"): - raise pyboard.PyboardError("edit: $EDITOR not set") + raise TransportError("edit: $EDITOR not set") for src in args.files: src = src.lstrip(":") dest_fd, dest = tempfile.mkstemp(suffix=os.path.basename(src)) try: print("edit :%s" % (src,)) os.close(dest_fd) - state.pyb.fs_touch(src) - state.pyb.fs_get(src, dest, progress_callback=show_progress_bar) + state.transport.fs_touch(src) + state.transport.fs_get(src, dest, progress_callback=show_progress_bar) if os.system('%s "%s"' % (os.getenv("EDITOR"), dest)) == 0: - state.pyb.fs_put(dest, src, progress_callback=show_progress_bar) + state.transport.fs_put(dest, src, progress_callback=show_progress_bar) finally: os.unlink(dest) @@ -186,13 +188,15 @@ def _do_execbuffer(state, buf, follow): state.did_action() try: - state.pyb.exec_raw_no_follow(buf) + state.transport.exec_raw_no_follow(buf) if follow: - ret, ret_err = state.pyb.follow(timeout=None, data_consumer=pyboard.stdout_write_bytes) + ret, ret_err = state.transport.follow( + timeout=None, data_consumer=pyboard.stdout_write_bytes + ) if ret_err: pyboard.stdout_write_bytes(ret_err) sys.exit(1) - except pyboard.PyboardError as er: + except TransportError as er: print(er) sys.exit(1) except KeyboardInterrupt: @@ -221,13 +225,13 @@ def do_run(state, args): def do_mount(state, args): state.ensure_raw_repl() path = args.path[0] - state.pyb.mount_local(path, unsafe_links=args.unsafe_links) + state.transport.mount_local(path, unsafe_links=args.unsafe_links) print(f"Local directory {path} is mounted at /remote") def do_umount(state, path): state.ensure_raw_repl() - state.pyb.umount_local() + state.transport.umount_local() def do_resume(state, _args=None): diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index cb96369a53..6689266098 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -449,7 +449,7 @@ def do_command_expansion(args): class State: def __init__(self): - self.pyb = None + self.transport = None self._did_action = False self._auto_soft_reset = True @@ -460,20 +460,20 @@ class State: return not self._did_action def ensure_connected(self): - if self.pyb is None: + if self.transport is None: do_connect(self) def ensure_raw_repl(self, soft_reset=None): self.ensure_connected() soft_reset = self._auto_soft_reset if soft_reset is None else soft_reset - if soft_reset or not self.pyb.in_raw_repl: - self.pyb.enter_raw_repl(soft_reset=soft_reset) + if soft_reset or not self.transport.in_raw_repl: + self.transport.enter_raw_repl(soft_reset=soft_reset) self._auto_soft_reset = False def ensure_friendly_repl(self): self.ensure_connected() - if self.pyb.in_raw_repl: - self.pyb.exit_raw_repl() + if self.transport.in_raw_repl: + self.transport.exit_raw_repl() def main(): diff --git a/tools/mpremote/mpremote/mip.py b/tools/mpremote/mpremote/mip.py index 99ca9ff7e3..f42c7a0b42 100644 --- a/tools/mpremote/mpremote/mip.py +++ b/tools/mpremote/mpremote/mip.py @@ -16,7 +16,7 @@ _CHUNK_SIZE = 128 # This implements os.makedirs(os.dirname(path)) -def _ensure_path_exists(pyb, path): +def _ensure_path_exists(transport, path): import os split = path.split("/") @@ -29,8 +29,8 @@ def _ensure_path_exists(pyb, path): prefix = "" for i in range(len(split) - 1): prefix += split[i] - if not pyb.fs_exists(prefix): - pyb.fs_mkdir(prefix) + if not transport.fs_exists(prefix): + transport.fs_mkdir(prefix) prefix += "/" @@ -68,7 +68,7 @@ def _rewrite_url(url, branch=None): return url -def _download_file(pyb, url, dest): +def _download_file(transport, url, dest): try: with urllib.request.urlopen(url) as src: fd, path = tempfile.mkstemp() @@ -76,8 +76,8 @@ def _download_file(pyb, url, dest): print("Installing:", dest) with os.fdopen(fd, "wb") as f: _chunk(src, f.write, src.length) - _ensure_path_exists(pyb, dest) - pyb.fs_put(path, dest, progress_callback=show_progress_bar) + _ensure_path_exists(transport, dest) + transport.fs_put(path, dest, progress_callback=show_progress_bar) finally: os.unlink(path) except urllib.error.HTTPError as e: @@ -89,7 +89,7 @@ def _download_file(pyb, url, dest): raise CommandError(f"{e.reason} requesting {url}") -def _install_json(pyb, package_json_url, index, target, version, mpy): +def _install_json(transport, package_json_url, index, target, version, mpy): try: with urllib.request.urlopen(_rewrite_url(package_json_url, version)) as response: package_json = json.load(response) @@ -103,15 +103,15 @@ def _install_json(pyb, package_json_url, index, target, version, mpy): for target_path, short_hash in package_json.get("hashes", ()): fs_target_path = target + "/" + target_path file_url = f"{index}/file/{short_hash[:2]}/{short_hash}" - _download_file(pyb, file_url, fs_target_path) + _download_file(transport, file_url, fs_target_path) for target_path, url in package_json.get("urls", ()): fs_target_path = target + "/" + target_path - _download_file(pyb, _rewrite_url(url, version), fs_target_path) + _download_file(transport, _rewrite_url(url, version), fs_target_path) for dep, dep_version in package_json.get("deps", ()): - _install_package(pyb, dep, index, target, dep_version, mpy) + _install_package(transport, dep, index, target, dep_version, mpy) -def _install_package(pyb, package, index, target, version, mpy): +def _install_package(transport, package, index, target, version, mpy): if ( package.startswith("http://") or package.startswith("https://") @@ -120,7 +120,7 @@ def _install_package(pyb, package, index, target, version, mpy): if package.endswith(".py") or package.endswith(".mpy"): print(f"Downloading {package} to {target}") _download_file( - pyb, _rewrite_url(package, version), target + "/" + package.rsplit("/")[-1] + transport, _rewrite_url(package, version), target + "/" + package.rsplit("/")[-1] ) return else: @@ -136,14 +136,15 @@ def _install_package(pyb, package, index, target, version, mpy): mpy_version = "py" if mpy: - pyb.exec("import sys") + transport.exec("import sys") mpy_version = ( - int(pyb.eval("getattr(sys.implementation, '_mpy', 0) & 0xFF").decode()) or "py" + int(transport.eval("getattr(sys.implementation, '_mpy', 0) & 0xFF").decode()) + or "py" ) package = f"{index}/package/{mpy_version}/{package}/{version}.json" - _install_json(pyb, package, index, target, version, mpy) + _install_json(transport, package, index, target, version, mpy) def do_mip(state, args): @@ -163,9 +164,9 @@ def do_mip(state, args): args.index = _PACKAGE_INDEX if args.target is None: - state.pyb.exec("import sys") + state.transport.exec("import sys") lib_paths = ( - state.pyb.eval("'\\n'.join(p for p in sys.path if p.endswith('/lib'))") + state.transport.eval("'\\n'.join(p for p in sys.path if p.endswith('/lib'))") .decode() .split("\n") ) @@ -181,7 +182,12 @@ def do_mip(state, args): try: _install_package( - state.pyb, package, args.index.rstrip("/"), args.target, version, args.mpy + state.transport, + package, + args.index.rstrip("/"), + args.target, + version, + args.mpy, ) except CommandError: print("Package may be partially installed") diff --git a/tools/mpremote/mpremote/repl.py b/tools/mpremote/mpremote/repl.py index 239e267d75..d24a7774ac 100644 --- a/tools/mpremote/mpremote/repl.py +++ b/tools/mpremote/mpremote/repl.py @@ -1,45 +1,45 @@ from .console import Console, ConsolePosix -from . import pyboardextended as pyboard +from .transport import TransportError def do_repl_main_loop( state, console_in, console_out_write, *, escape_non_printable, code_to_inject, file_to_inject ): while True: - console_in.waitchar(state.pyb.serial) + console_in.waitchar(state.transport.serial) c = console_in.readchar() if c: if c in (b"\x1d", b"\x18"): # ctrl-] or ctrl-x, quit break elif c == b"\x04": # ctrl-D # special handling needed for ctrl-D if filesystem is mounted - state.pyb.write_ctrl_d(console_out_write) + state.transport.write_ctrl_d(console_out_write) elif c == b"\x0a" and code_to_inject is not None: # ctrl-j, inject code - state.pyb.serial.write(code_to_inject) + state.transport.serial.write(code_to_inject) elif c == b"\x0b" and file_to_inject is not None: # ctrl-k, inject script console_out_write(bytes("Injecting %s\r\n" % file_to_inject, "utf8")) - state.pyb.enter_raw_repl(soft_reset=False) + state.transport.enter_raw_repl(soft_reset=False) with open(file_to_inject, "rb") as f: pyfile = f.read() try: - state.pyb.exec_raw_no_follow(pyfile) - except pyboard.PyboardError as er: + state.transport.exec_raw_no_follow(pyfile) + except TransportError as er: console_out_write(b"Error:\r\n") console_out_write(er) - state.pyb.exit_raw_repl() + state.transport.exit_raw_repl() else: - state.pyb.serial.write(c) + state.transport.serial.write(c) try: - n = state.pyb.serial.inWaiting() + n = state.transport.serial.inWaiting() except OSError as er: if er.args[0] == 5: # IO error, device disappeared print("device disconnected") break if n > 0: - dev_data_in = state.pyb.serial.read(n) + dev_data_in = state.transport.serial.read(n) if dev_data_in is not None: if escape_non_printable: # Pass data through to the console, with escaping of non-printables. @@ -63,7 +63,7 @@ def do_repl(state, args): code_to_inject = args.inject_code file_to_inject = args.inject_file - print("Connected to MicroPython at %s" % state.pyb.device_name) + print("Connected to MicroPython at %s" % state.transport.device_name) print("Use Ctrl-] or Ctrl-x to exit this shell") if escape_non_printable: print("Escaping non-printable bytes/characters by printing their hex code") diff --git a/tools/mpremote/mpremote/transport.py b/tools/mpremote/mpremote/transport.py new file mode 100644 index 0000000000..6e9a77b2bb --- /dev/null +++ b/tools/mpremote/mpremote/transport.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# +# This file is part of the MicroPython project, http://micropython.org/ +# +# The MIT License (MIT) +# +# Copyright (c) 2023 Jim Mussared +# +# 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. + + +class TransportError(Exception): + pass + + +class Transport: + pass diff --git a/tools/mpremote/mpremote/pyboardextended.py b/tools/mpremote/mpremote/transport_serial.py similarity index 50% rename from tools/mpremote/mpremote/pyboardextended.py rename to tools/mpremote/mpremote/transport_serial.py index b9dbd1e3b1..84822fe69c 100644 --- a/tools/mpremote/mpremote/pyboardextended.py +++ b/tools/mpremote/mpremote/transport_serial.py @@ -1,14 +1,604 @@ -import io, os, re, struct, time +#!/usr/bin/env python3 +# +# This file is part of the MicroPython project, http://micropython.org/ +# +# The MIT License (MIT) +# +# Copyright (c) 2014-2021 Damien P. George +# Copyright (c) 2017 Paul Sokolovsky +# Copyright (c) 2023 Jim Mussared +# +# 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. + +# This is based on the serial-only parts of tools/pyboard.py, with Python 2 +# support removed, and is currently in the process of being refactored to +# support multiple transports (webrepl, socket, BLE, etc). At the moment, +# SerialTransport is just the old Pyboard+PyboardExtended class without any +# of this refactoring. The API is going to change significantly. + +# Once the API is stabilised, the idea is that mpremote can be used both +# as a command line tool and a library for interacting with devices. + +import ast, io, errno, os, re, struct, sys, time +from collections import namedtuple from errno import EPERM from .console import VT_ENABLED +from .transport import TransportError, Transport -try: - from .pyboard import Pyboard, PyboardError, stdout_write_bytes, filesystem_command -except ImportError: - import sys - sys.path.append(os.path.dirname(__file__) + "/../..") - from pyboard import Pyboard, PyboardError, stdout_write_bytes, filesystem_command +def stdout_write_bytes(b): + b = b.replace(b"\x04", b"") + sys.stdout.buffer.write(b) + sys.stdout.buffer.flush() + + +listdir_result = namedtuple("dir_result", ["name", "st_mode", "st_ino", "st_size"]) + + +def reraise_filesystem_error(e, info): + if len(e.args) >= 3: + if b"OSError" in e.args[2] and b"ENOENT" in e.args[2]: + raise FileNotFoundError(info) + raise + + +class SerialTransport(Transport): + def __init__(self, device, baudrate=115200, wait=0, exclusive=True): + self.in_raw_repl = False + self.use_raw_paste = True + self.device_name = device + self.mounted = False + + import serial + import serial.tools.list_ports + + # Set options, and exclusive if pyserial supports it + serial_kwargs = {"baudrate": baudrate, "interCharTimeout": 1} + if serial.__version__ >= "3.3": + serial_kwargs["exclusive"] = exclusive + + delayed = False + for attempt in range(wait + 1): + try: + if os.name == "nt": + self.serial = serial.Serial(**serial_kwargs) + self.serial.port = device + portinfo = list(serial.tools.list_ports.grep(device)) # type: ignore + if portinfo and portinfo[0].manufacturer != "Microsoft": + # ESP8266/ESP32 boards use RTS/CTS for flashing and boot mode selection. + # DTR False: to avoid using the reset button will hang the MCU in bootloader mode + # RTS False: to prevent pulses on rts on serial.close() that would POWERON_RESET an ESPxx + self.serial.dtr = False # DTR False = gpio0 High = Normal boot + self.serial.rts = False # RTS False = EN High = MCU enabled + self.serial.open() + else: + self.serial = serial.Serial(device, **serial_kwargs) + break + except OSError: + if wait == 0: + continue + if attempt == 0: + sys.stdout.write("Waiting {} seconds for pyboard ".format(wait)) + delayed = True + time.sleep(1) + sys.stdout.write(".") + sys.stdout.flush() + else: + if delayed: + print("") + raise TransportError("failed to access " + device) + if delayed: + print("") + + def close(self): + self.serial.close() + + def read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None): + # if data_consumer is used then data is not accumulated and the ending must be 1 byte long + assert data_consumer is None or len(ending) == 1 + + data = self.serial.read(min_num_bytes) + if data_consumer: + data_consumer(data) + timeout_count = 0 + while True: + if data.endswith(ending): + break + elif self.serial.inWaiting() > 0: + new_data = self.serial.read(1) + if data_consumer: + data_consumer(new_data) + data = new_data + else: + data = data + new_data + timeout_count = 0 + else: + timeout_count += 1 + if timeout is not None and timeout_count >= 100 * timeout: + break + time.sleep(0.01) + return data + + def enter_raw_repl(self, soft_reset=True): + self.serial.write(b"\r\x03\x03") # ctrl-C twice: interrupt any running program + + # flush input (without relying on serial.flushInput()) + n = self.serial.inWaiting() + while n > 0: + self.serial.read(n) + n = self.serial.inWaiting() + + self.serial.write(b"\r\x01") # ctrl-A: enter raw REPL + + if soft_reset: + data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n>") + if not data.endswith(b"raw REPL; CTRL-B to exit\r\n>"): + print(data) + raise TransportError("could not enter raw repl") + + self.serial.write(b"\x04") # ctrl-D: soft reset + + # Waiting for "soft reboot" independently to "raw REPL" (done below) + # allows boot.py to print, which will show up after "soft reboot" + # and before "raw REPL". + data = self.read_until(1, b"soft reboot\r\n") + if not data.endswith(b"soft reboot\r\n"): + print(data) + raise TransportError("could not enter raw repl") + + data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n") + if not data.endswith(b"raw REPL; CTRL-B to exit\r\n"): + print(data) + raise TransportError("could not enter raw repl") + + self.in_raw_repl = True + + def exit_raw_repl(self): + self.serial.write(b"\r\x02") # ctrl-B: enter friendly REPL + self.in_raw_repl = False + + def follow(self, timeout, data_consumer=None): + # wait for normal output + data = self.read_until(1, b"\x04", timeout=timeout, data_consumer=data_consumer) + if not data.endswith(b"\x04"): + raise TransportError("timeout waiting for first EOF reception") + data = data[:-1] + + # wait for error output + data_err = self.read_until(1, b"\x04", timeout=timeout) + if not data_err.endswith(b"\x04"): + raise TransportError("timeout waiting for second EOF reception") + data_err = data_err[:-1] + + # return normal and error output + return data, data_err + + def raw_paste_write(self, command_bytes): + # Read initial header, with window size. + data = self.serial.read(2) + window_size = struct.unpack("") + if not data.endswith(b">"): + raise TransportError("could not enter raw repl") + + if self.use_raw_paste: + # Try to enter raw-paste mode. + self.serial.write(b"\x05A\x01") + data = self.serial.read(2) + if data == b"R\x00": + # Device understood raw-paste command but doesn't support it. + pass + elif data == b"R\x01": + # Device supports raw-paste mode, write out the command using this mode. + return self.raw_paste_write(command_bytes) + else: + # Device doesn't support raw-paste, fall back to normal raw REPL. + data = self.read_until(1, b"w REPL; CTRL-B to exit\r\n>") + if not data.endswith(b"w REPL; CTRL-B to exit\r\n>"): + print(data) + raise TransportError("could not enter raw repl") + # Don't try to use raw-paste mode again for this connection. + self.use_raw_paste = False + + # Write command using standard raw REPL, 256 bytes every 10ms. + for i in range(0, len(command_bytes), 256): + self.serial.write(command_bytes[i : min(i + 256, len(command_bytes))]) + time.sleep(0.01) + self.serial.write(b"\x04") + + # check if we could exec command + data = self.serial.read(2) + if data != b"OK": + raise TransportError("could not exec command (response: %r)" % data) + + def exec_raw(self, command, timeout=10, data_consumer=None): + self.exec_raw_no_follow(command) + return self.follow(timeout, data_consumer) + + def eval(self, expression, parse=False): + if parse: + ret = self.exec("print(repr({}))".format(expression)) + ret = ret.strip() + return ast.literal_eval(ret.decode()) + else: + ret = self.exec("print({})".format(expression)) + ret = ret.strip() + return ret + + def exec(self, command, data_consumer=None): + ret, ret_err = self.exec_raw(command, data_consumer=data_consumer) + if ret_err: + raise TransportError("exception", ret, ret_err) + return ret + + def execfile(self, filename): + with open(filename, "rb") as f: + pyfile = f.read() + return self.exec(pyfile) + + def fs_exists(self, src): + try: + self.exec("import uos\nuos.stat(%s)" % (("'%s'" % src) if src else "")) + return True + except TransportError: + return False + + def fs_ls(self, src): + cmd = ( + "import uos\nfor f in uos.ilistdir(%s):\n" + " print('{:12} {}{}'.format(f[3]if len(f)>3 else 0,f[0],'/'if f[1]&0x4000 else ''))" + % (("'%s'" % src) if src else "") + ) + self.exec(cmd, data_consumer=stdout_write_bytes) + + def fs_listdir(self, src=""): + buf = bytearray() + + def repr_consumer(b): + buf.extend(b.replace(b"\x04", b"")) + + cmd = "import uos\nfor f in uos.ilistdir(%s):\n" " print(repr(f), end=',')" % ( + ("'%s'" % src) if src else "" + ) + try: + buf.extend(b"[") + self.exec(cmd, data_consumer=repr_consumer) + buf.extend(b"]") + except TransportError as e: + reraise_filesystem_error(e, src) + + return [ + listdir_result(*f) if len(f) == 4 else listdir_result(*(f + (0,))) + for f in ast.literal_eval(buf.decode()) + ] + + def fs_stat(self, src): + try: + self.exec("import uos") + return os.stat_result(self.eval("uos.stat(%s)" % (("'%s'" % src)), parse=True)) + except TransportError as e: + reraise_filesystem_error(e, src) + + def fs_cat(self, src, chunk_size=256): + cmd = ( + "with open('%s') as f:\n while 1:\n" + " b=f.read(%u)\n if not b:break\n print(b,end='')" % (src, chunk_size) + ) + self.exec(cmd, data_consumer=stdout_write_bytes) + + def fs_readfile(self, src, chunk_size=256): + buf = bytearray() + + def repr_consumer(b): + buf.extend(b.replace(b"\x04", b"")) + + cmd = ( + "with open('%s', 'rb') as f:\n while 1:\n" + " b=f.read(%u)\n if not b:break\n print(b,end='')" % (src, chunk_size) + ) + try: + self.exec(cmd, data_consumer=repr_consumer) + except TransportError as e: + reraise_filesystem_error(e, src) + return ast.literal_eval(buf.decode()) + + def fs_writefile(self, dest, data, chunk_size=256): + self.exec("f=open('%s','wb')\nw=f.write" % dest) + while data: + chunk = data[:chunk_size] + self.exec("w(" + repr(chunk) + ")") + data = data[len(chunk) :] + self.exec("f.close()") + + def fs_cp(self, src, dest, chunk_size=256, progress_callback=None): + if progress_callback: + src_size = self.fs_stat(src).st_size + written = 0 + self.exec("fr=open('%s','rb')\nr=fr.read\nfw=open('%s','wb')\nw=fw.write" % (src, dest)) + while True: + data_len = int(self.exec("d=r(%u)\nw(d)\nprint(len(d))" % chunk_size)) + if not data_len: + break + if progress_callback: + written += data_len + progress_callback(written, src_size) + self.exec("fr.close()\nfw.close()") + + def fs_get(self, src, dest, chunk_size=256, progress_callback=None): + if progress_callback: + src_size = self.fs_stat(src).st_size + written = 0 + self.exec("f=open('%s','rb')\nr=f.read" % src) + with open(dest, "wb") as f: + while True: + data = bytearray() + self.exec("print(r(%u))" % chunk_size, data_consumer=lambda d: data.extend(d)) + assert data.endswith(b"\r\n\x04") + try: + data = ast.literal_eval(str(data[:-3], "ascii")) + if not isinstance(data, bytes): + raise ValueError("Not bytes") + except (UnicodeError, ValueError) as e: + raise TransportError("fs_get: Could not interpret received data: %s" % str(e)) + if not data: + break + f.write(data) + if progress_callback: + written += len(data) + progress_callback(written, src_size) + self.exec("f.close()") + + def fs_put(self, src, dest, chunk_size=256, progress_callback=None): + if progress_callback: + src_size = os.path.getsize(src) + written = 0 + self.exec("f=open('%s','wb')\nw=f.write" % dest) + with open(src, "rb") as f: + while True: + data = f.read(chunk_size) + if not data: + break + if sys.version_info < (3,): + self.exec("w(b" + repr(data) + ")") + else: + self.exec("w(" + repr(data) + ")") + if progress_callback: + written += len(data) + progress_callback(written, src_size) + self.exec("f.close()") + + def fs_mkdir(self, dir): + self.exec("import uos\nuos.mkdir('%s')" % dir) + + def fs_rmdir(self, dir): + self.exec("import uos\nuos.rmdir('%s')" % dir) + + def fs_rm(self, src): + self.exec("import uos\nuos.remove('%s')" % src) + + def fs_touch(self, src): + self.exec("f=open('%s','a')\nf.close()" % src) + + def filesystem_command(self, args, progress_callback=None, verbose=False): + def fname_remote(src): + if src.startswith(":"): + src = src[1:] + # Convert all path separators to "/", because that's what a remote device uses. + return src.replace(os.path.sep, "/") + + def fname_cp_dest(src, dest): + _, src = os.path.split(src) + if dest is None or dest == "": + dest = src + elif dest == ".": + dest = "./" + src + elif dest.endswith("/"): + dest += src + return dest + + cmd = args[0] + args = args[1:] + try: + if cmd == "cp": + srcs = args[:-1] + dest = args[-1] + if dest.startswith(":"): + op_remote_src = self.fs_cp + op_local_src = self.fs_put + else: + op_remote_src = self.fs_get + op_local_src = lambda src, dest, **_: __import__("shutil").copy(src, dest) + for src in srcs: + if verbose: + print("cp %s %s" % (src, dest)) + if src.startswith(":"): + op = op_remote_src + else: + op = op_local_src + src2 = fname_remote(src) + dest2 = fname_cp_dest(src2, fname_remote(dest)) + op(src2, dest2, progress_callback=progress_callback) + else: + ops = { + "cat": self.fs_cat, + "ls": self.fs_ls, + "mkdir": self.fs_mkdir, + "rm": self.fs_rm, + "rmdir": self.fs_rmdir, + "touch": self.fs_touch, + } + if cmd not in ops: + raise TransportError("'{}' is not a filesystem command".format(cmd)) + if cmd == "ls" and not args: + args = [""] + for src in args: + src = fname_remote(src) + if verbose: + print("%s :%s" % (cmd, src)) + ops[cmd](src) + except TransportError as er: + if len(er.args) > 1: + print(str(er.args[2], "ascii")) + else: + print(er) + self.exit_raw_repl() + self.close() + sys.exit(1) + + def mount_local(self, path, unsafe_links=False): + fout = self.serial + if self.eval('"RemoteFS" in globals()') == b"False": + self.exec(fs_hook_code) + self.exec("__mount()") + self.mounted = True + self.cmd = PyboardCommand(self.serial, fout, path, unsafe_links=unsafe_links) + self.serial = SerialIntercept(self.serial, self.cmd) + + def write_ctrl_d(self, out_callback): + self.serial.write(b"\x04") + if not self.mounted: + return + + # Read response from the device until it is quiet (with a timeout). + INITIAL_TIMEOUT = 0.5 + BANNER_TIMEOUT = 2 + QUIET_TIMEOUT = 0.1 + FULL_TIMEOUT = 5 + t_start = t_last_activity = time.monotonic() + data_all = b"" + soft_reboot_started = False + soft_reboot_banner = False + while True: + t = time.monotonic() + n = self.serial.inWaiting() + if n > 0: + data = self.serial.read(n) + out_callback(data) + data_all += data + t_last_activity = t + else: + if len(data_all) == 0: + if t - t_start > INITIAL_TIMEOUT: + return + else: + if t - t_start > FULL_TIMEOUT: + if soft_reboot_started: + break + return + + next_data_timeout = QUIET_TIMEOUT + + if not soft_reboot_started and data_all.find(b"MPY: soft reboot") != -1: + soft_reboot_started = True + + if soft_reboot_started and not soft_reboot_banner: + # Once soft reboot has been initiated, give some more time for the startup + # banner to be shown + if data_all.find(b"\nMicroPython ") != -1: + soft_reboot_banner = True + elif data_all.find(b"\nraw REPL; CTRL-B to exit\r\n") != -1: + soft_reboot_banner = True + else: + next_data_timeout = BANNER_TIMEOUT + + if t - t_last_activity > next_data_timeout: + break + + if not soft_reboot_started: + return + + if not soft_reboot_banner: + out_callback(b"Warning: Could not remount local filesystem\r\n") + return + + # Determine type of prompt + if data_all.endswith(b">"): + in_friendly_repl = False + prompt = b">" + else: + in_friendly_repl = True + prompt = data_all.rsplit(b"\r\n", 1)[-1] + + # Clear state while board remounts, it will be re-set once mounted. + self.mounted = False + self.serial = self.serial.orig_serial + + # Provide a message about the remount. + out_callback(bytes(f"\r\nRemount local directory {self.cmd.root} at /remote\r\n", "utf8")) + + # Enter raw REPL and re-mount the remote filesystem. + self.serial.write(b"\x01") + self.exec(fs_hook_code) + self.exec("__mount()") + self.mounted = True + + # Exit raw REPL if needed, and wait for the friendly REPL prompt. + if in_friendly_repl: + self.exit_raw_repl() + self.read_until(len(prompt), prompt) + out_callback(prompt) + self.serial = SerialIntercept(self.serial, self.cmd) + + def umount_local(self): + if self.mounted: + self.exec('uos.umount("/remote")') + self.mounted = False + self.serial = self.serial.orig_serial + fs_hook_cmds = { "CMD_STAT": 1, @@ -617,110 +1207,3 @@ class SerialIntercept: def write(self, buf): self.orig_serial.write(buf) - - -class PyboardExtended(Pyboard): - def __init__(self, dev, *args, **kwargs): - super().__init__(dev, *args, **kwargs) - self.device_name = dev - self.mounted = False - - def mount_local(self, path, unsafe_links=False): - fout = self.serial - if self.eval('"RemoteFS" in globals()') == b"False": - self.exec_(fs_hook_code) - self.exec_("__mount()") - self.mounted = True - self.cmd = PyboardCommand(self.serial, fout, path, unsafe_links=unsafe_links) - self.serial = SerialIntercept(self.serial, self.cmd) - - def write_ctrl_d(self, out_callback): - self.serial.write(b"\x04") - if not self.mounted: - return - - # Read response from the device until it is quiet (with a timeout). - INITIAL_TIMEOUT = 0.5 - BANNER_TIMEOUT = 2 - QUIET_TIMEOUT = 0.1 - FULL_TIMEOUT = 5 - t_start = t_last_activity = time.monotonic() - data_all = b"" - soft_reboot_started = False - soft_reboot_banner = False - while True: - t = time.monotonic() - n = self.serial.inWaiting() - if n > 0: - data = self.serial.read(n) - out_callback(data) - data_all += data - t_last_activity = t - else: - if len(data_all) == 0: - if t - t_start > INITIAL_TIMEOUT: - return - else: - if t - t_start > FULL_TIMEOUT: - if soft_reboot_started: - break - return - - next_data_timeout = QUIET_TIMEOUT - - if not soft_reboot_started and data_all.find(b"MPY: soft reboot") != -1: - soft_reboot_started = True - - if soft_reboot_started and not soft_reboot_banner: - # Once soft reboot has been initiated, give some more time for the startup - # banner to be shown - if data_all.find(b"\nMicroPython ") != -1: - soft_reboot_banner = True - elif data_all.find(b"\nraw REPL; CTRL-B to exit\r\n") != -1: - soft_reboot_banner = True - else: - next_data_timeout = BANNER_TIMEOUT - - if t - t_last_activity > next_data_timeout: - break - - if not soft_reboot_started: - return - - if not soft_reboot_banner: - out_callback(b"Warning: Could not remount local filesystem\r\n") - return - - # Determine type of prompt - if data_all.endswith(b">"): - in_friendly_repl = False - prompt = b">" - else: - in_friendly_repl = True - prompt = data_all.rsplit(b"\r\n", 1)[-1] - - # Clear state while board remounts, it will be re-set once mounted. - self.mounted = False - self.serial = self.serial.orig_serial - - # Provide a message about the remount. - out_callback(bytes(f"\r\nRemount local directory {self.cmd.root} at /remote\r\n", "utf8")) - - # Enter raw REPL and re-mount the remote filesystem. - self.serial.write(b"\x01") - self.exec_(fs_hook_code) - self.exec_("__mount()") - self.mounted = True - - # Exit raw REPL if needed, and wait for the friendly REPL prompt. - if in_friendly_repl: - self.exit_raw_repl() - self.read_until(len(prompt), prompt) - out_callback(prompt) - self.serial = SerialIntercept(self.serial, self.cmd) - - def umount_local(self): - if self.mounted: - self.exec_('uos.umount("/remote")') - self.mounted = False - self.serial = self.serial.orig_serial diff --git a/tools/mpremote/pyproject.toml b/tools/mpremote/pyproject.toml index 1b6c2173d2..b01385c3d5 100644 --- a/tools/mpremote/pyproject.toml +++ b/tools/mpremote/pyproject.toml @@ -44,11 +44,5 @@ raw-options = { root = "../..", version_scheme = "post-release" } [tool.hatch.build] packages = ["mpremote"] -# Also grab pyboard.py from /tools and add it to the package for both wheel and sdist. -[tool.hatch.build.force-include] -"../pyboard.py" = "mpremote/pyboard.py" - -# Workaround to allow `python -m build` to work. [tool.hatch.build.targets.sdist.force-include] -"../pyboard.py" = "mpremote/pyboard.py" "requirements.txt" = "requirements.txt" From ef497dc9243919c44c22b412f46143d78a6cdd3f Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2023 17:48:31 +1000 Subject: [PATCH 150/565] LICENSE: Move wiznet5k entry from drivers to lib. It was removed from drivers in 71dcb21e24064d1150094e66a904877402cdd157 Signed-off-by: Damien George --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 3a2f15d1f4..31eb9813f2 100644 --- a/LICENSE +++ b/LICENSE @@ -36,7 +36,6 @@ used during the build process and is not part of the compiled source code. / (MIT) /drivers /cc3100 (BSD-3-clause) - /wiznet5k (BSD-3-clause) /lib /asf4 (Apache-2.0) /axtls (BSD-3-clause) @@ -61,6 +60,7 @@ used during the build process and is not part of the compiled source code. /tinytest (BSD-3-clause) /tinyusb (MIT) /uzlib (Zlib) + /wiznet5k (MIT) /logo (uses OFL-1.1) /ports /cc3200 From a61d40e5e80e33172b41961ee5dcad6fb9a1f4a9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2023 18:01:47 +1000 Subject: [PATCH 151/565] tools/mpremote: Fix use of stdout_write_bytes function. Signed-off-by: Damien George --- tools/mpremote/mpremote/commands.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 9e05aca376..45acb8da19 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -5,7 +5,7 @@ import tempfile import serial.tools.list_ports from .transport import TransportError -from .transport_serial import SerialTransport +from .transport_serial import SerialTransport, stdout_write_bytes class CommandError(Exception): @@ -79,7 +79,7 @@ def do_disconnect(state, _args=None): state.transport.exit_raw_repl() except OSError: # Ignore any OSError exceptions when shutting down, eg: - # - pyboard.filesystem_command will close the connection if it had an error + # - filesystem_command will close the connection if it had an error # - umounting will fail if serial port disappeared pass state.transport.close() @@ -190,11 +190,9 @@ def _do_execbuffer(state, buf, follow): try: state.transport.exec_raw_no_follow(buf) if follow: - ret, ret_err = state.transport.follow( - timeout=None, data_consumer=pyboard.stdout_write_bytes - ) + ret, ret_err = state.transport.follow(timeout=None, data_consumer=stdout_write_bytes) if ret_err: - pyboard.stdout_write_bytes(ret_err) + stdout_write_bytes(ret_err) sys.exit(1) except TransportError as er: print(er) From 24aa81e1da6385b636cbaef364ba2c67d977b7ec Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2023 11:19:44 +1000 Subject: [PATCH 152/565] py/nlrsetjmp: Use MP_NLR_JUMP_HEAD macro to simplify code. Signed-off-by: Damien George --- py/nlrsetjmp.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/py/nlrsetjmp.c b/py/nlrsetjmp.c index 960dd86f52..73fbe81261 100644 --- a/py/nlrsetjmp.c +++ b/py/nlrsetjmp.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013-2017 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,14 +29,7 @@ #if MICROPY_NLR_SETJMP void nlr_jump(void *val) { - nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top); - nlr_buf_t *top = *top_ptr; - if (top == NULL) { - nlr_jump_fail(val); - } - top->ret_val = val; - MP_NLR_RESTORE_PYSTACK(top); - *top_ptr = top->prev; + MP_NLR_JUMP_HEAD(val, top); longjmp(top->jmpbuf, 1); } From f36ae5edcb5556c35b2dfe10be7ba54a21da0c9b Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2023 17:52:40 +1000 Subject: [PATCH 153/565] py/nlr: Remove commented-out debugging code. Also remove the unnecessary include of mpstate.h. Signed-off-by: Damien George --- py/nlr.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/py/nlr.h b/py/nlr.h index 09ef66ef72..b37370b224 100644 --- a/py/nlr.h +++ b/py/nlr.h @@ -171,11 +171,9 @@ NORETURN void nlr_jump_fail(void *val); #ifndef MICROPY_DEBUG_NLR #define nlr_raise(val) nlr_jump(MP_OBJ_TO_PTR(val)) #else -#include "mpstate.h" + #define nlr_raise(val) \ do { \ - /*printf("nlr_raise: nlr_top=%p\n", MP_STATE_THREAD(nlr_top)); \ - fflush(stdout);*/ \ void *_val = MP_OBJ_TO_PTR(val); \ assert(_val != NULL); \ assert(mp_obj_is_exception_instance(val)); \ @@ -185,11 +183,6 @@ NORETURN void nlr_jump_fail(void *val); #if !MICROPY_NLR_SETJMP #define nlr_push(val) \ assert(MP_STATE_THREAD(nlr_top) != val), nlr_push(val) - -/* -#define nlr_push(val) \ - printf("nlr_push: before: nlr_top=%p, val=%p\n", MP_STATE_THREAD(nlr_top), val),assert(MP_STATE_THREAD(nlr_top) != val),nlr_push(val) -*/ #endif #endif From 2757acf6ed1fe165e4d8aa72ba8090fb9bc60c31 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 9 May 2023 11:03:04 +1000 Subject: [PATCH 154/565] py/nlr: Implement jump callbacks. NLR buffers are usually quite large (use lots of C stack) and expensive to push and pop. Some of the time they are only needed to perform clean up if an exception happens, and then they re-raise the exception. This commit allows optimizing that scenario by introducing a linked-list of NLR callbacks that are called automatically when an exception is raised. They are essentially a light-weight NLR handler that can implement a "finally" block, i.e. clean-up when an exception is raised, or (by passing `true` to nlr_pop_jump_callback) when execution leaves the scope. Signed-off-by: Damien George --- py/mpstate.h | 1 + py/nlr.c | 32 +++++++++++++++++++++++++++++++- py/nlr.h | 25 ++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/py/mpstate.h b/py/mpstate.h index f6b911af56..80b49cb6b6 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -271,6 +271,7 @@ typedef struct _mp_state_thread_t { mp_obj_dict_t *dict_globals; nlr_buf_t *nlr_top; + nlr_jump_callback_node_t *nlr_jump_callback_top; // pending exception object (MP_OBJ_NULL if not pending) volatile mp_obj_t mp_pending_exception; diff --git a/py/nlr.c b/py/nlr.c index 92db8ffb19..7ab0c0955a 100644 --- a/py/nlr.c +++ b/py/nlr.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013-2017 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -50,6 +50,36 @@ void nlr_pop(void) { *top = (*top)->prev; } +void nlr_push_jump_callback(nlr_jump_callback_node_t *node, nlr_jump_callback_fun_t fun) { + nlr_jump_callback_node_t **top = &MP_STATE_THREAD(nlr_jump_callback_top); + node->prev = *top; + node->fun = fun; + *top = node; +} + +void nlr_pop_jump_callback(bool run_callback) { + nlr_jump_callback_node_t **top = &MP_STATE_THREAD(nlr_jump_callback_top); + nlr_jump_callback_node_t *cur = *top; + *top = (*top)->prev; + if (run_callback) { + cur->fun(cur); + } +} + +// This function pops and runs all callbacks that were registered after `nlr` +// was pushed (via nlr_push). It assumes: +// - a descending C stack, +// - that all nlr_jump_callback_node_t's in the linked-list pointed to by +// nlr_jump_callback_top are on the C stack +// It works by popping each node in turn until the next node is NULL or above +// the `nlr` pointer on the C stack (and so pushed before `nlr` was pushed). +void nlr_call_jump_callbacks(nlr_buf_t *nlr) { + nlr_jump_callback_node_t **top = &MP_STATE_THREAD(nlr_jump_callback_top); + while (*top != NULL && (void *)*top < (void *)nlr) { + nlr_pop_jump_callback(true); + } +} + #if MICROPY_ENABLE_VM_ABORT NORETURN void nlr_jump_abort(void) { MP_STATE_THREAD(nlr_top) = MP_STATE_VM(nlr_abort); diff --git a/py/nlr.h b/py/nlr.h index b37370b224..62972dba62 100644 --- a/py/nlr.h +++ b/py/nlr.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2013-2023 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,6 +31,7 @@ #include #include +#include #include "py/mpconfig.h" @@ -123,6 +124,15 @@ struct _nlr_buf_t { #endif }; +typedef void (*nlr_jump_callback_fun_t)(void *ctx); + +typedef struct _nlr_jump_callback_node_t nlr_jump_callback_node_t; + +struct _nlr_jump_callback_node_t { + nlr_jump_callback_node_t *prev; + nlr_jump_callback_fun_t fun; +}; + // Helper macros to save/restore the pystack state #if MICROPY_ENABLE_PYSTACK #define MP_NLR_SAVE_PYSTACK(nlr_buf) (nlr_buf)->pystack = MP_STATE_THREAD(pystack_cur) @@ -140,6 +150,7 @@ struct _nlr_buf_t { nlr_jump_fail(val); \ } \ top->ret_val = val; \ + nlr_call_jump_callbacks(top); \ MP_NLR_RESTORE_PYSTACK(top); \ *_top_ptr = top->prev; \ @@ -187,4 +198,16 @@ NORETURN void nlr_jump_fail(void *val); #endif +// Push a callback on to the linked-list of NLR jump callbacks. The `node` pointer must +// be on the C stack. The `fun` callback will be executed if an NLR jump is taken which +// unwinds the C stack through this `node`. +void nlr_push_jump_callback(nlr_jump_callback_node_t *node, nlr_jump_callback_fun_t fun); + +// Pop a callback from the linked-list of NLR jump callbacks. The corresponding function +// will be called if `run_callback` is true. +void nlr_pop_jump_callback(bool run_callback); + +// Pop and call all NLR jump callbacks that were registered after `nlr` buffer was pushed. +void nlr_call_jump_callbacks(nlr_buf_t *nlr); + #endif // MICROPY_INCLUDED_PY_NLR_H From ce31e5a2dc0736ebc7976098f1fdf520b2c32892 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 9 May 2023 11:03:17 +1000 Subject: [PATCH 155/565] py: Use nlr jump callbacks to optimise compile/execute functions. The changed functions now use less stack, and don't have any issues with local variables needing to be declared volatile. Testing on a PYBv1.0, imports (of .py, .mpy and frozen code) now use 64 less bytes of C stack per import depth. Signed-off-by: Damien George --- py/builtinevex.c | 32 ++++++++++++++--------------- py/builtinimport.c | 27 ++++++++++--------------- py/runtime.c | 50 ++++++++++++++++++++++++---------------------- py/runtime.h | 9 +++++++++ 4 files changed, 62 insertions(+), 56 deletions(-) diff --git a/py/builtinevex.c b/py/builtinevex.c index 173978ef52..97eab7fad9 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -45,12 +45,18 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj_dict_t *locals) { - // save context and set new context - mp_obj_dict_t *old_globals = mp_globals_get(); - mp_obj_dict_t *old_locals = mp_locals_get(); + // save context + nlr_jump_callback_node_globals_locals_t ctx; + ctx.globals = mp_globals_get(); + ctx.locals = mp_locals_get(); + + // set new context mp_globals_set(globals); mp_locals_set(locals); + // set exception handler to restore context if an exception is raised + nlr_push_jump_callback(&ctx.callback, mp_globals_locals_set_from_nlr_jump_callback); + // a bit of a hack: fun_bc will re-set globals, so need to make sure it's // the correct one if (mp_obj_is_type(self->module_fun, &mp_type_fun_bc)) { @@ -59,19 +65,13 @@ STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj } // execute code - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - mp_obj_t ret = mp_call_function_0(self->module_fun); - nlr_pop(); - mp_globals_set(old_globals); - mp_locals_set(old_locals); - return ret; - } else { - // exception; restore context and re-raise same exception - mp_globals_set(old_globals); - mp_locals_set(old_locals); - nlr_jump(nlr.ret_val); - } + mp_obj_t ret = mp_call_function_0(self->module_fun); + + // deregister exception handler and restore context + nlr_pop_jump_callback(true); + + // return value + return ret; } STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) { diff --git a/py/builtinimport.c b/py/builtinimport.c index f6c2f7c348..de4ea17f38 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -184,28 +184,23 @@ STATIC void do_execute_raw_code(const mp_module_context_t *context, const mp_raw mp_obj_dict_t *mod_globals = context->module.globals; // save context - mp_obj_dict_t *volatile old_globals = mp_globals_get(); - mp_obj_dict_t *volatile old_locals = mp_locals_get(); + nlr_jump_callback_node_globals_locals_t ctx; + ctx.globals = mp_globals_get(); + ctx.locals = mp_locals_get(); // set new context mp_globals_set(mod_globals); mp_locals_set(mod_globals); - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - mp_obj_t module_fun = mp_make_function_from_raw_code(rc, context, NULL); - mp_call_function_0(module_fun); + // set exception handler to restore context if an exception is raised + nlr_push_jump_callback(&ctx.callback, mp_globals_locals_set_from_nlr_jump_callback); - // finish nlr block, restore context - nlr_pop(); - mp_globals_set(old_globals); - mp_locals_set(old_locals); - } else { - // exception; restore context and re-raise same exception - mp_globals_set(old_globals); - mp_locals_set(old_locals); - nlr_jump(nlr.ret_val); - } + // make and execute the function + mp_obj_t module_fun = mp_make_function_from_raw_code(rc, context, NULL); + mp_call_function_0(module_fun); + + // deregister exception handler and restore context + nlr_pop_jump_callback(true); } #endif diff --git a/py/runtime.c b/py/runtime.c index cbc7fb9311..2326dfb3ca 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -188,6 +188,12 @@ void mp_deinit(void) { #endif } +void mp_globals_locals_set_from_nlr_jump_callback(void *ctx_in) { + nlr_jump_callback_node_globals_locals_t *ctx = ctx_in; + mp_globals_set(ctx->globals); + mp_locals_set(ctx->locals); +} + mp_obj_t MICROPY_WRAP_MP_LOAD_NAME(mp_load_name)(qstr qst) { // logic: search locals, globals, builtins DEBUG_OP_printf("load name %s\n", qstr_str(qst)); @@ -1582,39 +1588,35 @@ void mp_import_all(mp_obj_t module) { mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_input_kind, mp_obj_dict_t *globals, mp_obj_dict_t *locals) { // save context - mp_obj_dict_t *volatile old_globals = mp_globals_get(); - mp_obj_dict_t *volatile old_locals = mp_locals_get(); + nlr_jump_callback_node_globals_locals_t ctx; + ctx.globals = mp_globals_get(); + ctx.locals = mp_locals_get(); // set new context mp_globals_set(globals); mp_locals_set(locals); - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - qstr source_name = lex->source_name; - mp_parse_tree_t parse_tree = mp_parse(lex, parse_input_kind); - mp_obj_t module_fun = mp_compile(&parse_tree, source_name, parse_input_kind == MP_PARSE_SINGLE_INPUT); + // set exception handler to restore context if an exception is raised + nlr_push_jump_callback(&ctx.callback, mp_globals_locals_set_from_nlr_jump_callback); - mp_obj_t ret; - if (MICROPY_PY_BUILTINS_COMPILE && globals == NULL) { - // for compile only, return value is the module function - ret = module_fun; - } else { - // execute module function and get return value - ret = mp_call_function_0(module_fun); - } + qstr source_name = lex->source_name; + mp_parse_tree_t parse_tree = mp_parse(lex, parse_input_kind); + mp_obj_t module_fun = mp_compile(&parse_tree, source_name, parse_input_kind == MP_PARSE_SINGLE_INPUT); - // finish nlr block, restore context and return value - nlr_pop(); - mp_globals_set(old_globals); - mp_locals_set(old_locals); - return ret; + mp_obj_t ret; + if (MICROPY_PY_BUILTINS_COMPILE && globals == NULL) { + // for compile only, return value is the module function + ret = module_fun; } else { - // exception; restore context and re-raise same exception - mp_globals_set(old_globals); - mp_locals_set(old_locals); - nlr_jump(nlr.ret_val); + // execute module function and get return value + ret = mp_call_function_0(module_fun); } + + // deregister exception handler and restore context + nlr_pop_jump_callback(true); + + // return value + return ret; } #endif // MICROPY_ENABLE_COMPILER diff --git a/py/runtime.h b/py/runtime.h index 9b99e594b0..78194973d6 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -66,6 +66,13 @@ typedef struct _mp_sched_node_t { struct _mp_sched_node_t *next; } mp_sched_node_t; +// For use with mp_globals_locals_set_from_nlr_jump_callback. +typedef struct _nlr_jump_callback_node_globals_locals_t { + nlr_jump_callback_node_t callback; + mp_obj_dict_t *globals; + mp_obj_dict_t *locals; +} nlr_jump_callback_node_globals_locals_t; + // Tables mapping operator enums to qstrs, defined in objtype.c extern const byte mp_unary_op_method_name[]; extern const byte mp_binary_op_method_name[]; @@ -113,6 +120,8 @@ static inline void mp_globals_set(mp_obj_dict_t *d) { MP_STATE_THREAD(dict_globals) = d; } +void mp_globals_locals_set_from_nlr_jump_callback(void *ctx_in); + mp_obj_t mp_load_name(qstr qst); mp_obj_t mp_load_global(qstr qst); mp_obj_t mp_load_build_class(void); From a79a6ab3641e3536e509278706e7ac4de01a8126 Mon Sep 17 00:00:00 2001 From: David Grayson Date: Sun, 4 Jun 2023 19:55:41 -0700 Subject: [PATCH 156/565] py/builtinimport: Remove partially-loaded modules from sys.modules. Prior to this commit, importing a module that exists but has a syntax error or some other problem that happens at import time would result in a potentially-incomplete module object getting added to sys.modules. Subsequent imports would use that object, resulting in confusing error messages that hide the root cause of the problem. This commit fixes that issue by removing the failed module from sys.modules using the new NLR callback mechanism. Note that it is still important to add the module to sys.modules while the import is happening so that we can support circular imports just like CPython does. Fixes issue #967. Signed-off-by: David Grayson --- py/builtinimport.c | 20 +++++++++++++++- tests/cpydiff/core_import_prereg.py | 18 -------------- tests/import/broken/pkg2_and_zerodiv.py | 2 ++ tests/import/broken/zerodiv.py | 1 + tests/import/circular/main.py | 4 ++++ tests/import/circular/sub.py | 3 +++ tests/import/import_broken.py | 32 +++++++++++++++++++++++++ tests/import/import_circular.py | 1 + 8 files changed, 62 insertions(+), 19 deletions(-) delete mode 100644 tests/cpydiff/core_import_prereg.py create mode 100644 tests/import/broken/pkg2_and_zerodiv.py create mode 100644 tests/import/broken/zerodiv.py create mode 100644 tests/import/circular/main.py create mode 100644 tests/import/circular/sub.py create mode 100644 tests/import/import_broken.py create mode 100644 tests/import/import_circular.py diff --git a/py/builtinimport.c b/py/builtinimport.c index de4ea17f38..8827be6123 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -346,6 +346,17 @@ STATIC void evaluate_relative_import(mp_int_t level, const char **module_name, s *module_name_len = new_module_name_len; } +typedef struct _nlr_jump_callback_node_unregister_module_t { + nlr_jump_callback_node_t callback; + qstr name; +} nlr_jump_callback_node_unregister_module_t; + +STATIC void unregister_module_from_nlr_jump_callback(void *ctx_in) { + nlr_jump_callback_node_unregister_module_t *ctx = ctx_in; + mp_map_t *mp_loaded_modules_map = &MP_STATE_VM(mp_loaded_modules_dict).map; + mp_map_lookup(mp_loaded_modules_map, MP_OBJ_NEW_QSTR(ctx->name), MP_MAP_LOOKUP_REMOVE_IF_FOUND); +} + // Load a module at the specified absolute path, possibly as a submodule of the given outer module. // full_mod_name: The full absolute path up to this level (e.g. "foo.bar.baz"). // level_mod_name: The final component of the path (e.g. "baz"). @@ -467,8 +478,13 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, // Module was found on the filesystem/frozen, try and load it. DEBUG_printf("Found path to load: %.*s\n", (int)vstr_len(&path), vstr_str(&path)); - // Prepare for loading from the filesystem. Create a new shell module. + // Prepare for loading from the filesystem. Create a new shell module + // and register it in sys.modules. Also make sure we remove it if + // there is any problem below. module_obj = mp_obj_new_module(full_mod_name); + nlr_jump_callback_node_unregister_module_t ctx; + ctx.name = full_mod_name; + nlr_push_jump_callback(&ctx.callback, unregister_module_from_nlr_jump_callback); #if MICROPY_MODULE_OVERRIDE_MAIN_IMPORT // If this module is being loaded via -m on unix, then @@ -526,6 +542,8 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_store_attr(outer_module_obj, level_mod_name, module_obj); } + nlr_pop_jump_callback(false); + return module_obj; } diff --git a/tests/cpydiff/core_import_prereg.py b/tests/cpydiff/core_import_prereg.py deleted file mode 100644 index 3ce2340c68..0000000000 --- a/tests/cpydiff/core_import_prereg.py +++ /dev/null @@ -1,18 +0,0 @@ -""" -categories: Core,import -description: Failed to load modules are still registered as loaded -cause: To make module handling more efficient, it's not wrapped with exception handling. -workaround: Test modules before production use; during development, use ``del sys.modules["name"]``, or just soft or hard reset the board. -""" -import sys - -try: - from modules import foo -except NameError as e: - print(e) -try: - from modules import foo - - print("Should not get here") -except NameError as e: - print(e) diff --git a/tests/import/broken/pkg2_and_zerodiv.py b/tests/import/broken/pkg2_and_zerodiv.py new file mode 100644 index 0000000000..3580628ff5 --- /dev/null +++ b/tests/import/broken/pkg2_and_zerodiv.py @@ -0,0 +1,2 @@ +import pkg2 +import broken.zerodiv diff --git a/tests/import/broken/zerodiv.py b/tests/import/broken/zerodiv.py new file mode 100644 index 0000000000..72dca4d5e4 --- /dev/null +++ b/tests/import/broken/zerodiv.py @@ -0,0 +1 @@ +1 / 0 diff --git a/tests/import/circular/main.py b/tests/import/circular/main.py new file mode 100644 index 0000000000..5d63d507c3 --- /dev/null +++ b/tests/import/circular/main.py @@ -0,0 +1,4 @@ +x = 1 +import circular.sub + +print(circular.sub.y) diff --git a/tests/import/circular/sub.py b/tests/import/circular/sub.py new file mode 100644 index 0000000000..50d7afe07b --- /dev/null +++ b/tests/import/circular/sub.py @@ -0,0 +1,3 @@ +from circular.main import x + +y = x + 20 diff --git a/tests/import/import_broken.py b/tests/import/import_broken.py new file mode 100644 index 0000000000..3c7cf4a498 --- /dev/null +++ b/tests/import/import_broken.py @@ -0,0 +1,32 @@ +import sys, pkg + +# Modules we import are usually added to sys.modules. +print("pkg" in sys.modules) + +try: + from broken.zerodiv import x +except Exception as e: + print(e.__class__.__name__) + +# The broken module we tried to import should not be in sys.modules. +print("broken.zerodiv" in sys.modules) + +# If we try to import the module again, the code should +# run again and we should get the same error. +try: + from broken.zerodiv import x +except Exception as e: + print(e.__class__.__name__) + +# Import a module that successfully imports some other modules +# before importing the problematic module. +try: + import broken.pkg2_and_zerodiv +except ZeroDivisionError: + pass + +print("pkg2" in sys.modules) +print("pkg2.mod1" in sys.modules) +print("pkg2.mod2" in sys.modules) +print("broken.zerodiv" in sys.modules) +print("broken.pkg2_and_zerodiv" in sys.modules) diff --git a/tests/import/import_circular.py b/tests/import/import_circular.py new file mode 100644 index 0000000000..388efdd130 --- /dev/null +++ b/tests/import/import_circular.py @@ -0,0 +1 @@ +import circular.main From bf7d3ad8c69431d7bb8d1188484996af94e78990 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 24 May 2023 16:13:01 +0200 Subject: [PATCH 157/565] samd/boards: Rename flash pins consistently for QSPI and SPI. For SAMD21 devices, the board flash signals must be named in pins.csv as FLASH_MOSI, FLASH_MISO, FLASH_SCK, FLASH_CS for creating the SPI object. And rename the QSPI pins to QSPI_xxxx instead of FLASH_xxx. Signed-off-by: robert-hh --- docs/samd/pinout.rst | 48 +++++++++---------- .../ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv | 6 +-- .../ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv | 13 ++--- .../ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv | 13 ++--- ports/samd/boards/MINISAM_M4/pins.csv | 9 ++++ ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv | 7 +++ 6 files changed, 57 insertions(+), 39 deletions(-) diff --git a/docs/samd/pinout.rst b/docs/samd/pinout.rst index 212275a014..5fe1e14ecb 100644 --- a/docs/samd/pinout.rst +++ b/docs/samd/pinout.rst @@ -160,14 +160,14 @@ Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM 22 PA22 D13 6 - - 3/0 5/1 4/0 1/6 0/2 34 PB02 DOTSTAR_CLK 2 14 - - 5/0 6/0 2/2 - 35 PB03 DOTSTAR_DATA 9 15 - - 5/1 6/1 - - - 43 PB11 FLASH_CS 12 - - - 4/3 5/1 0/5 1/1 - 11 PA11 FLASH_HOLD 11 11 - 0/3 2/3 1/1 0/3 1/7 - 9 PA09 FLASH_MISO 9 9 3 0/1 2/0 0/1 0/1 1/5 - 8 PA08 FLASH_MOSI - 8 2 0/0 2/1 0/0 0/0 1/4 - 42 PB10 FLASH_SCK 10 - - - 4/2 5/0 0/4 1/0 - 10 PA10 FLASH_WP 10 10 - 0/2 2/2 1/0 0/2 1/6 55 PB23 MISO 7 - - 1/3 5/3 7/1 - - 0 PA00 MOSI 0 - - - 1/0 2/0 - - + 43 PB11 QSPI_CS 12 - - - 4/3 5/1 0/5 1/1 + 8 PA08 QSPI_D0 - 8 2 0/0 2/1 0/0 0/0 1/4 + 9 PA09 QSPI_D1 9 9 3 0/1 2/0 0/1 0/1 1/5 + 10 PA10 QSPI_D2 10 10 - 0/2 2/2 1/0 0/2 1/6 + 11 PA11 QSPI_D3 11 11 - 0/3 2/3 1/1 0/3 1/7 + 42 PB10 QSPI_SCK 10 - - - 4/2 5/0 0/4 1/0 1 PA01 SCK 1 - - - 1/1 2/1 - - 13 PA13 SCL 13 - - 2/1 4/0 2/1 0/7 1/3 12 PA12 SDA 12 - - 2/0 4/1 2/0 0/6 1/2 @@ -288,15 +288,15 @@ Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM 21 PA21 D11 5 - - 5/3 3/3 7/1 1/5 0/1 22 PA22 D12 6 - - 3/0 5/1 4/0 1/6 0/2 23 PA23 D13 7 - - 3/1 5/0 4/1 1/7 0/3 - 43 PB11 FLASH_CS 12 - - - 4/3 5/1 0/5 1/1 - 11 PA11 FLASH_HOLD 11 11 - 0/3 2/3 1/1 0/3 1/7 - 9 PA09 FLASH_MISO 9 9 3 0/1 2/0 0/1 0/1 1/5 - 8 PA08 FLASH_MOSI - 8 2 0/0 2/1 0/0 0/0 1/4 - 42 PB10 FLASH_SCK 10 - - - 4/2 5/0 0/4 1/0 - 10 PA10 FLASH_WP 10 10 - 0/2 2/2 1/0 0/2 1/6 54 PB22 MISO 22 - - 1/2 5/2 7/0 - - 55 PB23 MOSI 7 - - 1/3 5/3 7/1 - - 35 PB03 NEOPIXEL 9 15 - - 5/1 6/1 - - + 43 PB11 QSPI_CS 12 - - - 4/3 5/1 0/5 1/1 + 8 PA08 QSPI_D0 - 8 2 0/0 2/1 0/0 0/0 1/4 + 9 PA09 QSPI_D1 9 9 3 0/1 2/0 0/1 0/1 1/5 + 10 PA10 QSPI_D2 10 10 - 0/2 2/2 1/0 0/2 1/6 + 11 PA11 QSPI_D3 11 11 - 0/3 2/3 1/1 0/3 1/7 + 42 PB10 QSPI_SCK 10 - - - 4/2 5/0 0/4 1/0 17 PA17 SCK 1 - - 1/1 3/0 2/1 1/1 0/5 13 PA13 SCL 13 - - 2/1 4/0 2/1 0/7 1/3 12 PA12 SDA 12 - - 2/0 4/1 2/0 0/6 1/2 @@ -650,6 +650,12 @@ Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM 15 PA15 LED 15 - - 2/3 4/3 3/1 2/1 1/3 55 PB23 MISO 7 - - 1/3 5/3 7/1 - - 54 PB22 MOSI 22 - - 1/2 5/2 7/0 - - + 43 PB11 QSPI_CS 12 - - - 4/3 5/1 0/5 1/1 + 8 PA08 QSPI_D0 - 8 2 0/0 2/1 0/0 0/0 1/4 + 9 PA09 QSPI_D1 9 9 3 0/1 2/0 0/1 0/1 1/5 + 10 PA10 QSPI_D2 10 10 - 0/2 2/2 1/0 0/2 1/6 + 11 PA11 QSPI_D3 11 11 - 0/3 2/3 1/1 0/3 1/7 + 42 PB10 QSPI_SCK 10 - - - 4/2 5/0 0/4 1/0 1 PA01 SCK 1 - - - 1/1 2/1 - - 13 PA13 SCL 13 - - 2/1 4/0 2/1 0/7 1/3 12 PA12 SDA 12 - - 2/0 4/1 2/0 0/6 1/2 @@ -657,17 +663,11 @@ Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM 31 PA31 SWDIO 15 - - 7/3 1/3 6/1 2/1 - 24 PA24 USB_DM 8 - - 3/2 5/2 5/0 2/2 - 25 PA25 USB_DP 9 - - 3/3 5/3 5/1 - - - 8 PA08 - - 8 2 0/0 2/1 0/0 0/0 1/4 - 9 PA09 - 9 9 3 0/1 2/0 0/1 0/1 1/5 - 10 PA10 - 10 10 - 0/2 2/2 1/0 0/2 1/6 - 11 PA11 - 11 11 - 0/3 2/3 1/1 0/3 1/7 14 PA14 - 14 - - 2/2 4/2 3/0 2/0 1/2 18 PA18 - 2 - - 1/2 3/2 3/0 1/2 0/6 22 PA22 - 6 - - 3/0 5/1 4/0 1/6 0/2 23 PA23 - 7 - - 3/1 5/0 4/1 1/7 0/3 27 PA27 - 11 - - - - - - - - 42 PB10 - 10 - - - 4/2 5/0 0/4 1/0 - 43 PB11 - 12 - - - 4/3 5/1 0/5 1/1 === ==== ============ ==== ==== ==== ====== ====== ===== ===== ===== For the definition of the table columns see the explanation at the table for @@ -734,6 +734,12 @@ Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM 117 PD21 SD_DET 11 - - 1/3 3/3 - 1/1 - 83 PC19 SD_CS 3 - - 6/3 0/3 - 0/3 - 82 PC18 SD_MISO 2 - - 6/2 0/2 - 0/2 - + 43 PB11 QSPI_CS 12 - - - 4/3 5/1 0/5 1/1 + 8 PA08 QSPI_D0 - 8 2 0/0 2/1 0/0 0/0 1/4 + 9 PA09 QSPI_D1 9 9 3 0/1 2/0 0/1 0/1 1/5 + 10 PA10 QSPI_D2 10 10 - 0/2 2/2 1/0 0/2 1/6 + 11 PA11 QSPI_D3 11 11 - 0/3 2/3 1/1 0/3 1/7 + 42 PB10 QSPI_SCK 10 - - - 4/2 5/0 0/4 1/0 80 PC16 SD_MOSI 0 - - 6/0 0/1 - 0/0 - 81 PC17 SD_SCK 1 - - 6/1 0/0 - 0/1 - 30 PA30 SWCLK 14 - - 7/2 1/2 6/0 2/0 - @@ -750,17 +756,11 @@ Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM 2 PA02 - 2 0 - - - - - - 3 PA03 - 3 10 - - - - - - 5 PA05 - 5 5 - - 0/1 0/1 - - - 8 PA08 - - 8 2 0/0 2/1 0/0 0/0 1/4 - 9 PA09 - 9 9 3 0/1 2/0 0/1 0/1 1/5 - 10 PA10 - 10 10 - 0/2 2/2 1/0 0/2 1/6 - 11 PA11 - 11 11 - 0/3 2/3 1/1 0/3 1/7 14 PA14 - 14 - - 2/2 4/2 3/0 2/0 1/2 18 PA18 - 2 - - 1/2 3/2 3/0 1/2 0/6 19 PA19 - 3 - - 1/3 3/3 3/1 1/3 0/7 23 PA23 - 7 - - 3/1 5/0 4/1 1/7 0/3 27 PA27 - 11 - - - - - - - - 42 PB10 - 10 - - - 4/2 5/0 0/4 1/0 - 43 PB11 - 12 - - - 4/3 5/1 0/5 1/1 46 PB14 - 14 - - 4/2 - 5/0 4/0 0/2 49 PB17 - 1 - - 5/1 - 6/1 3/1 0/5 54 PB22 - 22 - - 1/2 5/2 7/0 - - diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv index 35b6d1fd4e..6536277062 100644 --- a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv +++ b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.csv @@ -8,9 +8,9 @@ PIN_PB03,LED_RX PIN_PA11,D0 PIN_PA10,D1 -PIN_PA14,D2 -PIN_PA09,D3 -PIN_PA08,D4 +PIN_PA08,FLASH_MOSI +PIN_PA14,FLASH_MISO +PIN_PA09,FLASH_SCK PIN_PA15,D5 PIN_PA20,D6 PIN_PA21,D7 diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv index ad8449ac9e..df3373f246 100644 --- a/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv +++ b/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/pins.csv @@ -28,12 +28,13 @@ PIN_PA17,SCK PIN_PB01,VDIV PIN_PA03,AREF PIN_PB03,NEOPIXEL -PIN_PB11,FLASH_CS -PIN_PB10,FLASH_SCK -PIN_PA08,FLASH_MOSI -PIN_PA09,FLASH_MISO -PIN_PA10,FLASH_WP -PIN_PA11,FLASH_HOLD + +PIN_PB11,QSPI_CS +PIN_PB10,QSPI_SCK +PIN_PA08,QSPI_D0 +PIN_PA09,QSPI_D1 +PIN_PA10,QSPI_D2 +PIN_PA11,QSPI_D3 PIN_PA24,USB_DM PIN_PA25,USB_DP diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv index 43c8e9a64a..b63a1f4b13 100644 --- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv +++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.csv @@ -28,12 +28,13 @@ PIN_PB23,MISO PIN_PA01,SCK PIN_PB02,DOTSTAR_CLK PIN_PB03,DOTSTAR_DATA -PIN_PB11,FLASH_CS -PIN_PB10,FLASH_SCK -PIN_PA08,FLASH_MOSI -PIN_PA09,FLASH_MISO -PIN_PA10,FLASH_WP -PIN_PA11,FLASH_HOLD + +PIN_PB11,QSPI_CS +PIN_PB10,QSPI_SCK +PIN_PA08,QSPI_D0 +PIN_PA09,QSPI_D1 +PIN_PA10,QSPI_D2 +PIN_PA11,QSPI_D3 PIN_PA24,USB_DM PIN_PA25,USB_DP diff --git a/ports/samd/boards/MINISAM_M4/pins.csv b/ports/samd/boards/MINISAM_M4/pins.csv index 793e523fcd..3ea5f85cba 100644 --- a/ports/samd/boards/MINISAM_M4/pins.csv +++ b/ports/samd/boards/MINISAM_M4/pins.csv @@ -26,6 +26,15 @@ PIN_PA01,SCK PIN_PB03,DOTSTAR_DATA PIN_PB02,DOTSTAR_CLK +PIN_PB11,QSPI_CS +PIN_PB10,QSPI_SCK +PIN_PA08,QSPI_D0 +PIN_PA09,QSPI_D1 +PIN_PA10,QSPI_D2 +PIN_PA11,QSPI_D3 + +PIN_PA15,LED + PIN_PA24,USB_DM PIN_PA25,USB_DP PIN_PA26,USB_SOF diff --git a/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv b/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv index 55cbb5bf04..c32108b9f7 100644 --- a/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv +++ b/ports/samd/boards/SEEED_WIO_TERMINAL/pins.csv @@ -58,6 +58,13 @@ PIN_PC13,LCD_YD PIN_PC30,MIC PIN_PD11,BUZZER +PIN_PB11,QSPI_CS +PIN_PB10,QSPI_SCK +PIN_PA08,QSPI_D0 +PIN_PA09,QSPI_D1 +PIN_PA10,QSPI_D2 +PIN_PA11,QSPI_D3 + PIN_PA15,LED_BLUE PIN_PC05,LED_LCD From 5561130c3f220e52fc878b683fc90ecb031427e6 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 24 May 2023 16:14:47 +0200 Subject: [PATCH 158/565] samd/samd_spiflash: Add SPI flash driver and configure it accordingly. The SPI flash driver includes the block device for being used as a filesystem. It provides the same methods as the driver for the internal flash. Signed-off-by: robert-hh --- .../mpconfigboard.h | 3 + .../mpconfigboard.h | 3 + ports/samd/samd_spiflash.c | 299 ++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 ports/samd/samd_spiflash.c diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h index 815597899c..880df8d200 100644 --- a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h +++ b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h @@ -2,3 +2,6 @@ #define MICROPY_HW_MCU_NAME "SAMD21G18A" #define MICROPY_HW_XOSC32K (1) + +#define MICROPY_HW_SPIFLASH (1) +#define MICROPY_HW_SPIFLASH_ID (2) diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.h index 160c61ea2a..16018fdc56 100644 --- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.h +++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.h @@ -2,3 +2,6 @@ #define MICROPY_HW_MCU_NAME "SAMD21G18A" #define MICROPY_HW_DFLL_USB_SYNC (1) + +#define MICROPY_HW_SPIFLASH (1) +#define MICROPY_HW_SPIFLASH_ID (5) diff --git a/ports/samd/samd_spiflash.c b/ports/samd/samd_spiflash.c new file mode 100644 index 0000000000..eaa0ec1434 --- /dev/null +++ b/ports/samd/samd_spiflash.c @@ -0,0 +1,299 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019-2020 Peter Hinch + * Copyright (c) 2023 Robert Hammelrath + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * 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 +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "extmod/machine_spi.h" +#include "extmod/vfs.h" +#include "modmachine.h" +#include "pin_af.h" + +#if MICROPY_HW_SPIFLASH + +#define _READ_INDEX (0) +#define _PROGRAM_PAGE_INDEX (1) +#define _SECTOR_ERASE_INDEX (2) + +const uint8_t _COMMANDS_24BIT[] = {0x03, 0x02, 0x20}; // READ, PROGRAM_PAGE, ERASE_4K +const uint8_t _COMMANDS_32BIT[] = {0x13, 0x12, 0x21}; // READ, PROGRAM_PAGE, ERASE_4K + +#define COMMAND_JEDEC_ID (0x9F) +#define COMMAND_READ_STATUS (0x05) +#define COMMAND_WRITE_ENABLE (0x06) +#define COMMAND_READ_SFDP (0x5A) +#define PAGE_SIZE (256) +#define SECTOR_SIZE (4096) + +typedef struct _spiflash_obj_t { + mp_obj_base_t base; + mp_obj_base_t *spi; + mp_hal_pin_obj_t cs; + bool addr_is_32bit; + uint16_t pagesize; + uint16_t sectorsize; + const uint8_t *commands; + uint32_t size; +} spiflash_obj_t; + +extern const mp_obj_type_t samd_spiflash_type; + +// The SPIflash object is a singleton +static spiflash_obj_t spiflash_obj = { + { &samd_spiflash_type }, NULL, 0, false, PAGE_SIZE, SECTOR_SIZE, NULL, 0 +}; + +static void spi_transfer(mp_obj_base_t *spi, size_t len, const uint8_t *src, uint8_t *dest) { + mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(spi->type, protocol); + spi_p->transfer(spi, len, src, dest); +} + +static void wait(spiflash_obj_t *self) { + uint8_t msg[2]; + uint32_t timeout = 100000; + + // each loop takes at least about 5us @ 120Mhz. So a timeout of + // 100000 wait 500ms max. at 120Mhz. Sector erase lasts about + // 100ms worst case, page write is < 1ms. + do { + msg[0] = COMMAND_READ_STATUS; + mp_hal_pin_write(self->cs, 0); + spi_transfer((mp_obj_base_t *)self->spi, 2, msg, msg); + mp_hal_pin_write(self->cs, 1); + } while (msg[1] != 0 && timeout-- > 0); +} + +static void get_id(spiflash_obj_t *self, uint8_t id[3]) { + uint8_t msg[1]; + + msg[0] = COMMAND_JEDEC_ID; + mp_hal_pin_write(self->cs, 0); + spi_transfer(self->spi, 1, msg, NULL); + spi_transfer(self->spi, 3, id, id); + mp_hal_pin_write(self->cs, 1); +} +static void write_addr(spiflash_obj_t *self, uint8_t cmd, uint32_t addr) { + uint8_t msg[5]; + uint8_t index = 1; + msg[0] = cmd; + if (self->addr_is_32bit) { + msg[index++] = addr >> 24; + } + msg[index++] = (addr >> 16) & 0xff; + msg[index++] = (addr >> 8) & 0xff; + msg[index++] = addr & 0xff; + mp_hal_pin_write(self->cs, 0); + spi_transfer(self->spi, self->addr_is_32bit ? 5 : 4, msg, msg); +} + +static void write_enable(spiflash_obj_t *self) { + uint8_t msg[1]; + + msg[0] = COMMAND_WRITE_ENABLE; + mp_hal_pin_write(self->cs, 0); + spi_transfer(self->spi, 1, msg, NULL); + mp_hal_pin_write(self->cs, 1); +} + +static void get_sfdp(spiflash_obj_t *self, uint32_t addr, uint8_t *buffer, int size) { + uint8_t dummy[1]; + write_addr(self, COMMAND_READ_SFDP, addr); + spi_transfer(self->spi, 1, dummy, NULL); + spi_transfer(self->spi, size, buffer, buffer); + mp_hal_pin_write(self->cs, 1); +} + +STATIC mp_obj_t spiflash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_arg_check_num(n_args, n_kw, 0, 0, false); + + // Set up the object + spiflash_obj_t *self = &spiflash_obj; + + mp_obj_t spi_args[] = { + MP_OBJ_NEW_SMALL_INT(MICROPY_HW_SPIFLASH_ID), + MP_OBJ_NEW_SMALL_INT(24000000), // baudrate + MP_OBJ_NEW_QSTR(MP_QSTR_mosi), MP_OBJ_NEW_QSTR(MP_QSTR_FLASH_MOSI), + MP_OBJ_NEW_QSTR(MP_QSTR_miso), MP_OBJ_NEW_QSTR(MP_QSTR_FLASH_MISO), + MP_OBJ_NEW_QSTR(MP_QSTR_sck), MP_OBJ_NEW_QSTR(MP_QSTR_FLASH_SCK), + }; + self->spi = MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, make_new)((mp_obj_t)&machine_spi_type, 2, 3, spi_args); + + mp_obj_t pin_args[] = { + MP_OBJ_NEW_QSTR(MP_QSTR_FLASH_CS), + MP_ROM_INT(1), + }; + machine_pin_obj_t *cs = MP_OBJ_TYPE_GET_SLOT(&machine_pin_type, make_new)((mp_obj_t)&machine_pin_type, 2, 0, pin_args); + self->cs = cs->pin_id; + mp_hal_pin_write(self->cs, 1); + + wait(self); + + // Get the flash size from the device ID (default) + uint8_t id[3]; + get_id(self, id); + if (id[1] == 0x84 && id[2] == 1) { // Adesto + self->size = 512 * 1024; + } else if (id[1] == 0x1f && id[2] == 1) { // Atmel / Renesas + self->size = 1024 * 1024; + } else { + self->size = 1 << id[2]; + } + + // Get the addr_is_32bit flag and the sector size + uint8_t buffer[128]; + get_sfdp(self, 0, buffer, 16); // get the header + int len = MIN(buffer[11] * 4, sizeof(buffer)); + if (len >= 29) { + int addr = buffer[12] + (buffer[13] << 8) + (buffer[14] << 16); + get_sfdp(self, addr, buffer, len); // Get the JEDEC mandatory table + self->sectorsize = 1 << buffer[28]; + self->addr_is_32bit = ((buffer[2] >> 1) & 0x03) != 0; + } + self->commands = self->addr_is_32bit ? _COMMANDS_32BIT : _COMMANDS_24BIT; + + return self; +} + +STATIC mp_obj_t spiflash_read(spiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) { + if (len > 0) { + write_addr(self, self->commands[_READ_INDEX], addr); + spi_transfer(self->spi, len, dest, dest); + mp_hal_pin_write(self->cs, 1); + } + + return mp_const_none; +} + +STATIC mp_obj_t spiflash_write(spiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) { + uint32_t length = len; + uint32_t pos = 0; + uint8_t *buf = src; + + while (pos < length) { + uint16_t maxsize = self->pagesize - pos % self->pagesize; + uint16_t size = (length - pos) > maxsize ? maxsize : length - pos; + + write_enable(self); + write_addr(self, self->commands[_PROGRAM_PAGE_INDEX], addr); + spi_transfer(self->spi, size, buf + pos, NULL); + mp_hal_pin_write(self->cs, 1); + wait(self); + + addr += size; + pos += size; + } + + return mp_const_none; +} + +STATIC mp_obj_t spiflash_erase(spiflash_obj_t *self, uint32_t addr) { + write_enable(self); + write_addr(self, self->commands[_SECTOR_ERASE_INDEX], addr); + mp_hal_pin_write(self->cs, 1); + wait(self); + + return mp_const_none; +} + +STATIC mp_obj_t spiflash_readblocks(size_t n_args, const mp_obj_t *args) { + spiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]); + uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE); + if (n_args == 4) { + offset += mp_obj_get_int(args[3]); + } + + // Read data to flash (adf4 API) + spiflash_read(self, offset, bufinfo.buf, bufinfo.len); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_readblocks_obj, 3, 4, spiflash_readblocks); + +STATIC mp_obj_t spiflash_writeblocks(size_t n_args, const mp_obj_t *args) { + spiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]); + uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); + if (n_args == 3) { + spiflash_erase(self, offset); + // TODO check return value + } else { + offset += mp_obj_get_int(args[3]); + } + // Write data to flash (adf4 API) + spiflash_write(self, offset, bufinfo.buf, bufinfo.len); + // TODO check return value + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_writeblocks_obj, 3, 4, spiflash_writeblocks); + +STATIC mp_obj_t spiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { + spiflash_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_int_t cmd = mp_obj_get_int(cmd_in); + + switch (cmd) { + case MP_BLOCKDEV_IOCTL_INIT: + return MP_OBJ_NEW_SMALL_INT(0); + case MP_BLOCKDEV_IOCTL_DEINIT: + return MP_OBJ_NEW_SMALL_INT(0); + case MP_BLOCKDEV_IOCTL_SYNC: + return MP_OBJ_NEW_SMALL_INT(0); + case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: + return MP_OBJ_NEW_SMALL_INT(self->size / self->sectorsize); + case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: + return MP_OBJ_NEW_SMALL_INT(self->sectorsize); + case MP_BLOCKDEV_IOCTL_BLOCK_ERASE: { + spiflash_erase(self, mp_obj_get_int(arg_in) * self->sectorsize); + // TODO check return value + return MP_OBJ_NEW_SMALL_INT(0); + } + default: + return mp_const_none; + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(spiflash_ioctl_obj, spiflash_ioctl); + +STATIC const mp_rom_map_elem_t spiflash_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&spiflash_readblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&spiflash_writeblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&spiflash_ioctl_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(spiflash_locals_dict, spiflash_locals_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + samd_spiflash_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + make_new, spiflash_make_new, + locals_dict, &spiflash_locals_dict + ); + +#endif // #if MICROPY_HW_SPIFLASH From 2b5a5a0f35b325e14268f8f48ac8b5022da87691 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 24 May 2023 16:16:40 +0200 Subject: [PATCH 159/565] samd/samd_qspiflash: Add QSPI flash driver and configure it accordingly. The QSPI driver provides the interface for using an on-board QSPI flash for the filesystem. It provides the same methods as the driver for the internal flash and uses the same name. Therefore, only one of the drivers for internal flash, SPI flash and QSPI flash must be enabled at a time. Signed-off-by: robert-hh --- drivers/memory/external_flash_device.h | 461 ++++++++++++++++ .../mpconfigboard.h | 2 + .../mpconfigboard.h | 2 + ports/samd/boards/MINISAM_M4/mpconfigboard.h | 2 + .../boards/SEEED_WIO_TERMINAL/mpconfigboard.h | 2 + .../mpconfigboard.h | 5 + ports/samd/pin_af.h | 3 + ports/samd/samd_qspiflash.c | 491 ++++++++++++++++++ 8 files changed, 968 insertions(+) create mode 100644 drivers/memory/external_flash_device.h create mode 100644 ports/samd/samd_qspiflash.c diff --git a/drivers/memory/external_flash_device.h b/drivers/memory/external_flash_device.h new file mode 100644 index 0000000000..0379844603 --- /dev/null +++ b/drivers/memory/external_flash_device.h @@ -0,0 +1,461 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries LLC + * + * 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. + */ +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H +#define MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H + +#include +#include + +typedef struct { + uint32_t total_size; + uint16_t start_up_time_us; + + // Three response bytes to 0x9f JEDEC ID command. + uint8_t manufacturer_id; + uint8_t memory_type; + uint8_t capacity; + + // Max clock speed for all operations and the fastest read mode. + uint8_t max_clock_speed_mhz; + + // Bitmask for Quad Enable bit if present. 0x00 otherwise. This is for the highest byte in the + // status register. + uint8_t quad_enable_bit_mask; + + bool has_sector_protection : 1; + + // Supports the 0x0b fast read command with 8 dummy cycles. + bool supports_fast_read : 1; + + // Supports the fast read, quad output command 0x6b with 8 dummy cycles. + bool supports_qspi : 1; + + // Supports the quad input page program command 0x32. This is known as 1-1-4 because it only + // uses all four lines for data. + bool supports_qspi_writes : 1; + + // Requires a separate command 0x31 to write to the second byte of the status register. + // Otherwise two byte are written via 0x01. + bool write_status_register_split : 1; + + // True when the status register is a single byte. This implies the Quad Enable bit is in the + // first byte and the Read Status Register 2 command (0x35) is unsupported. + bool single_status_byte : 1; +} external_flash_device; + +// Settings for the Adesto Tech AT25DF081A 1MiB SPI flash. Its on the SAMD21 +// Xplained board. +// Datasheet: https://www.adestotech.com/wp-content/uploads/doc8715.pdf +#define AT25DF081A { \ + .total_size = (1 << 20), /* 1 MiB */ \ + .start_up_time_us = 10000, \ + .manufacturer_id = 0x1f, \ + .memory_type = 0x45, \ + .capacity = 0x01, \ + .max_clock_speed_mhz = 85, \ + .quad_enable_bit_mask = 0x00, \ + .has_sector_protection = true, \ + .supports_fast_read = true, \ + .supports_qspi = false, \ + .supports_qspi_writes = false, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Gigadevice GD25Q16C 2MiB SPI flash. +// Datasheet: http://www.gigadevice.com/datasheet/gd25q16c/ +#define GD25Q16C { \ + .total_size = (1 << 21), /* 2 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xc8, \ + .memory_type = 0x40, \ + .capacity = 0x15, \ + .max_clock_speed_mhz = 104, /* if we need 120 then we can turn on high performance mode */ \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Gigadevice GD25Q64C 8MiB SPI flash. +// Datasheet: http://www.elm-tech.com/en/products/spi-flash-memory/gd25q64/gd25q64.pdf +#define GD25Q64C { \ + .total_size = (1 << 23), /* 8 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xc8, \ + .memory_type = 0x40, \ + .capacity = 0x17, \ + .max_clock_speed_mhz = 104, /* if we need 120 then we can turn on high performance mode */ \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = true, \ + .single_status_byte = false, \ +} + +// Settings for the Cypress (was Spansion) S25FL064L 8MiB SPI flash. +// Datasheet: http://www.cypress.com/file/316661/download +#define S25FL064L { \ + .total_size = (1 << 23), /* 8 MiB */ \ + .start_up_time_us = 300, \ + .manufacturer_id = 0x01, \ + .memory_type = 0x60, \ + .capacity = 0x17, \ + .max_clock_speed_mhz = 108, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Cypress (was Spansion) S25FL116K 2MiB SPI flash. +// Datasheet: http://www.cypress.com/file/196886/download +#define S25FL116K { \ + .total_size = (1 << 21), /* 2 MiB */ \ + .start_up_time_us = 10000, \ + .manufacturer_id = 0x01, \ + .memory_type = 0x40, \ + .capacity = 0x15, \ + .max_clock_speed_mhz = 108, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = false, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Cypress (was Spansion) S25FL216K 2MiB SPI flash. +// Datasheet: http://www.cypress.com/file/197346/download +#define S25FL216K { \ + .total_size = (1 << 21), /* 2 MiB */ \ + .start_up_time_us = 10000, \ + .manufacturer_id = 0x01, \ + .memory_type = 0x40, \ + .capacity = 0x15, \ + .max_clock_speed_mhz = 65, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = false, \ + .supports_qspi_writes = false, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Winbond W25Q16FW 2MiB SPI flash. +// Datasheet: https://www.winbond.com/resource-files/w25q16fw%20revj%2005182017%20sfdp.pdf +#define W25Q16FW { \ + .total_size = (1 << 21), /* 2 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x60, \ + .capacity = 0x15, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Winbond W25Q16JV-IQ 2MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) +// Datasheet: https://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf +#define W25Q16JV_IQ { \ + .total_size = (1 << 21), /* 2 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x40, \ + .capacity = 0x15, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Winbond W25Q16JV-IM 2MiB SPI flash. Note that JV-IQ has a different .memory_type (0x40) +// Datasheet: https://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf +#define W25Q16JV_IM { \ + .total_size = (1 << 21), /* 2 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x70, \ + .capacity = 0x15, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ +} + +// Settings for the Winbond W25Q32BV 4MiB SPI flash. +// Datasheet: https://www.winbond.com/resource-files/w25q32bv_revi_100413_wo_automotive.pdf +#define W25Q32BV { \ + .total_size = (1 << 22), /* 4 MiB */ \ + .start_up_time_us = 10000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x60, \ + .capacity = 0x16, \ + .max_clock_speed_mhz = 104, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = false, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} +// Settings for the Winbond W25Q32JV-IM 4MiB SPI flash. +// Datasheet: https://www.winbond.com/resource-files/w25q32jv%20revg%2003272018%20plus.pdf +#define W25Q32JV_IM { \ + .total_size = (1 << 22), /* 4 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x70, \ + .capacity = 0x16, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ +} + +// Settings for the Winbond W25Q32JV-IM 4MiB SPI flash. +// Datasheet: https://www.winbond.com/resource-files/w25q32jv%20revg%2003272018%20plus.pdf +#define W25Q32JV_IQ { \ + .total_size = (1 << 22), /* 4 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x40, \ + .capacity = 0x16, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ +} + +// Settings for the Winbond W25Q64JV-IM 8MiB SPI flash. Note that JV-IQ has a different .memory_type (0x40) +// Datasheet: http://www.winbond.com/resource-files/w25q64jv%20revj%2003272018%20plus.pdf +#define W25Q64JV_IM { \ + .total_size = (1 << 23), /* 8 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x70, \ + .capacity = 0x17, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Winbond W25Q64JV-IQ 8MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) +// Datasheet: http://www.winbond.com/resource-files/w25q64jv%20revj%2003272018%20plus.pdf +#define W25Q64JV_IQ { \ + .total_size = (1 << 23), /* 8 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x40, \ + .capacity = 0x17, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Winbond W25Q80DL 1MiB SPI flash. +// Datasheet: https://www.winbond.com/resource-files/w25q80dv%20dl_revh_10022015.pdf +#define W25Q80DL { \ + .total_size = (1 << 20), /* 1 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x60, \ + .capacity = 0x14, \ + .max_clock_speed_mhz = 104, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = false, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + + +// Settings for the Winbond W25Q128JV-SQ 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) +// Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf +#define W25Q128JV_SQ { \ + .total_size = (1 << 24), /* 16 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x40, \ + .capacity = 0x18, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for the Macronix MX25L1606 2MiB SPI flash. +// Datasheet: +#define MX25L1606 { \ + .total_size = (1 << 21), /* 2 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xc2, \ + .memory_type = 0x20, \ + .capacity = 0x15, \ + .max_clock_speed_mhz = 8, \ + .quad_enable_bit_mask = 0x40, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = true, \ +} + +// Settings for the Macronix MX25L3233F 4MiB SPI flash. +// Datasheet: http://www.macronix.com/Lists/Datasheet/Attachments/7426/MX25L3233F,%203V,%2032Mb,%20v1.6.pdf +#define MX25L3233F { \ + .total_size = (1 << 22), /* 4 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xc2, \ + .memory_type = 0x20, \ + .capacity = 0x16, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x40, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = true, \ +} + +// Settings for the Macronix MX25R6435F 8MiB SPI flash. +// Datasheet: http://www.macronix.com/Lists/Datasheet/Attachments/7428/MX25R6435F,%20Wide%20Range,%2064Mb,%20v1.4.pdf +// By default its in lower power mode which can only do 8mhz. In high power mode it can do 80mhz. +#define MX25R6435F { \ + .total_size = (1 << 23), /* 8 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xc2, \ + .memory_type = 0x28, \ + .capacity = 0x17, \ + .max_clock_speed_mhz = 8, \ + .quad_enable_bit_mask = 0x40, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = true, \ +} + +// Settings for the Winbond W25Q128JV-PM 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) +// Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf +#define W25Q128JV_PM { \ + .total_size = (1 << 24), /* 16 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x70, \ + .capacity = 0x18, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ +} + +// Settings for the Winbond W25Q32FV 4MiB SPI flash. +// Datasheet:http://www.winbond.com/resource-files/w25q32fv%20revj%2006032016.pdf?__locale=en +#define W25Q32FV { \ + .total_size = (1 << 22), /* 4 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x40, \ + .capacity = 0x16, \ + .max_clock_speed_mhz = 104, \ + .quad_enable_bit_mask = 0x00, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = false, \ + .supports_qspi_writes = false, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + +// Settings for a GENERIC device with the most common setting +#define GENERIC { \ + .total_size = (1 << 21), /* 2 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0x00, \ + .memory_type = 0x40, \ + .capacity = 0x15, \ + .max_clock_speed_mhz = 48, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} +#endif // MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.h index b78c003b19..a9f7d518e2 100644 --- a/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.h +++ b/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.h @@ -3,3 +3,5 @@ #define MICROPY_HW_XOSC32K (1) #define MICROPY_HW_MCU_OSC32KULP (1) + +#define MICROPY_HW_QSPIFLASH GD25Q16C diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h index f53481d631..2f246c60b1 100644 --- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h +++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h @@ -2,3 +2,5 @@ #define MICROPY_HW_MCU_NAME "SAMD51G19A" #define MICROPY_HW_DFLL_USB_SYNC (1) + +#define MICROPY_HW_QSPIFLASH GD25Q16C diff --git a/ports/samd/boards/MINISAM_M4/mpconfigboard.h b/ports/samd/boards/MINISAM_M4/mpconfigboard.h index 6715a16f01..2dc403bad6 100644 --- a/ports/samd/boards/MINISAM_M4/mpconfigboard.h +++ b/ports/samd/boards/MINISAM_M4/mpconfigboard.h @@ -1,2 +1,4 @@ #define MICROPY_HW_BOARD_NAME "Mini SAM M4" #define MICROPY_HW_MCU_NAME "SAMD51G19A" + +#define MICROPY_HW_QSPIFLASH GD25Q16C diff --git a/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h b/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h index 8260992101..062f69ae4e 100644 --- a/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h +++ b/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h @@ -2,3 +2,5 @@ #define MICROPY_HW_MCU_NAME "SAMD51P19A" #define MICROPY_HW_XOSC32K (1) + +#define MICROPY_HW_QSPIFLASH W25Q32JV_IQ diff --git a/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h b/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h index a51b71c363..706fc3c64c 100644 --- a/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h +++ b/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h @@ -8,3 +8,8 @@ // 256k. Since the SAMD51x20A has 256k RAM, the loader symbol is at that address // and so there is a fix here using the previous definition. #define DBL_TAP_ADDR_ALT ((volatile uint32_t *)(HSRAM_ADDR + HSRAM_SIZE - 0x10000 - 4)) + +// Enabling both two lines below will set the boot file system to +// the board's external flash. +#define MICROPY_HW_SPIFLASH (1) +#define MICROPY_HW_SPIFLASH_ID (0) diff --git a/ports/samd/pin_af.h b/ports/samd/pin_af.h index edab72aaed..3a15ae7f35 100644 --- a/ports/samd/pin_af.h +++ b/ports/samd/pin_af.h @@ -65,6 +65,9 @@ typedef struct _machine_pin_obj_t { #define ALT_FCT_TC 4 #define ALT_FCT_TCC1 5 #define ALT_FCT_TCC2 6 +#define ALT_FCT_QSPI 7 +#define ALT_FCT_CAN1 7 +#define ALT_FCT_USB 7 #endif diff --git a/ports/samd/samd_qspiflash.c b/ports/samd/samd_qspiflash.c new file mode 100644 index 0000000000..9bb79de5c5 --- /dev/null +++ b/ports/samd/samd_qspiflash.c @@ -0,0 +1,491 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Adafruit Industries + * Copyright (c) 2023 Robert Hammelrath + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * 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. + * + * Port of the Adafruit QSPIflash driver for SAMD devices + * + */ + +#include +#include +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "py/mperrno.h" +#include "modmachine.h" +#include "extmod/machine_spi.h" +#include "extmod/vfs.h" +#include "pin_af.h" +#include "clock_config.h" +#include "sam.h" + +#ifdef MICROPY_HW_QSPIFLASH + +#include "drivers/memory/external_flash_device.h" + +// QSPI command codes +enum +{ + QSPI_CMD_READ = 0x03, + QSPI_CMD_READ_4B = 0x13, + QSPI_CMD_QUAD_READ = 0x6B,// 1 line address, 4 line data + + QSPI_CMD_READ_JEDEC_ID = 0x9f, + + QSPI_CMD_PAGE_PROGRAM = 0x02, + QSPI_CMD_PAGE_PROGRAM_4B = 0x12, + QSPI_CMD_QUAD_PAGE_PROGRAM = 0x32, // 1 line address, 4 line data + + QSPI_CMD_READ_STATUS = 0x05, + QSPI_CMD_READ_STATUS2 = 0x35, + + QSPI_CMD_WRITE_STATUS = 0x01, + QSPI_CMD_WRITE_STATUS2 = 0x31, + + QSPI_CMD_ENABLE_RESET = 0x66, + QSPI_CMD_RESET = 0x99, + + QSPI_CMD_WRITE_ENABLE = 0x06, + QSPI_CMD_WRITE_DISABLE = 0x04, + + QSPI_CMD_ERASE_SECTOR = 0x20, + QSPI_CMD_ERASE_SECTOR_4B = 0x21, + QSPI_CMD_ERASE_BLOCK = 0xD8, + QSPI_CMD_ERASE_CHIP = 0xC7, + + QSPI_CMD_READ_SFDP_PARAMETER = 0x5A, +}; + +// QSPI flash pins are: CS=PB11, SCK=PB10, IO0-IO3=PA08, PA09, PA10 and PA11. +#define PIN_CS (43) +#define PIN_SCK (42) +#define PIN_IO0 (8) +#define PIN_IO1 (9) +#define PIN_IO2 (10) +#define PIN_IO3 (11) + +#define PAGE_SIZE (256) +#define SECTOR_SIZE (4096) + +typedef struct _samd_qspiflash_obj_t { + mp_obj_base_t base; + uint16_t pagesize; + uint16_t sectorsize; + uint32_t size; + uint8_t phase; + uint8_t polarity; +} samd_qspiflash_obj_t; + +/// List of all possible flash devices used by Adafruit boards +static const external_flash_device possible_devices[] = { + MICROPY_HW_QSPIFLASH +}; + +#define EXTERNAL_FLASH_DEVICE_COUNT MP_ARRAY_SIZE(possible_devices) +static external_flash_device const *flash_device; +static external_flash_device generic_config = GENERIC; +extern const mp_obj_type_t samd_qspiflash_type; + +// The QSPIflash object is a singleton +static samd_qspiflash_obj_t qspiflash_obj = { { &samd_qspiflash_type } }; + +// Turn off cache and invalidate all data in it. +static void samd_peripherals_disable_and_clear_cache(void) { + CMCC->CTRL.bit.CEN = 0; + while (CMCC->SR.bit.CSTS) { + } + CMCC->MAINT0.bit.INVALL = 1; +} + +// Enable cache +static void samd_peripherals_enable_cache(void) { + CMCC->CTRL.bit.CEN = 1; +} + +// Run a single QSPI instruction. +// Parameters are: +// - command instruction code +// - iframe iframe register value (configured by caller according to command code) +// - addr the address to read or write from. If the instruction doesn't require an address, this parameter is meaningless. +// - buffer pointer to the data to be written or stored depending on the type is Read or Write +// - size the number of bytes to read or write. +bool run_instruction(uint8_t command, uint32_t iframe, uint32_t addr, uint8_t *buffer, uint32_t size) { + + samd_peripherals_disable_and_clear_cache(); + + uint8_t *qspi_mem = (uint8_t *)QSPI_AHB; + if (addr) { + qspi_mem += addr; + } + + QSPI->INSTRCTRL.bit.INSTR = command; + QSPI->INSTRADDR.reg = addr; + QSPI->INSTRFRAME.reg = iframe; + + // Dummy read of INSTRFRAME needed to synchronize. + // See Instruction Transmission Flow Diagram, figure 37.9, page 995 + // and Example 4, page 998, section 37.6.8.5. + (volatile uint32_t)QSPI->INSTRFRAME.reg; + + if (buffer && size) { + uint32_t const tfr_type = iframe & QSPI_INSTRFRAME_TFRTYPE_Msk; + if ((tfr_type == QSPI_INSTRFRAME_TFRTYPE_READ) || (tfr_type == QSPI_INSTRFRAME_TFRTYPE_READMEMORY)) { + memcpy(buffer, qspi_mem, size); + } else { + memcpy(qspi_mem, buffer, size); + } + } + + __asm volatile ("dsb"); + __asm volatile ("isb"); + + QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER; + while (!QSPI->INTFLAG.bit.INSTREND) { + } + QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND; + + samd_peripherals_enable_cache(); + return true; +} + +bool run_command(uint8_t command) { + uint32_t iframe = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_READ | QSPI_INSTRFRAME_INSTREN; + return run_instruction(command, iframe, 0, NULL, 0); +} + +bool read_command(uint8_t command, uint8_t *response, uint32_t len) { + uint32_t iframe = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_READ | QSPI_INSTRFRAME_INSTREN | QSPI_INSTRFRAME_DATAEN; + return run_instruction(command, iframe, 0, response, len); +} + +bool read_memory_single(uint8_t command, uint32_t addr, uint8_t *response, uint32_t len) { + uint32_t iframe = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_READ | QSPI_INSTRFRAME_INSTREN | QSPI_INSTRFRAME_ADDREN | + QSPI_INSTRFRAME_DATAEN | QSPI_INSTRFRAME_DUMMYLEN(8); + return run_instruction(command, iframe, addr, response, len); +} + +bool write_command(uint8_t command, uint8_t const *data, uint32_t len) { + uint32_t iframe = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_WRITE | QSPI_INSTRFRAME_INSTREN | (data != NULL ? QSPI_INSTRFRAME_DATAEN : 0); + return run_instruction(command, iframe, 0, (uint8_t *)data, len); +} + +bool erase_command(uint8_t command, uint32_t address) { + // Sector Erase + uint32_t iframe = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_WRITE | QSPI_INSTRFRAME_INSTREN | QSPI_INSTRFRAME_ADDREN; + return run_instruction(command, iframe, address, NULL, 0); +} + +bool read_memory_quad(uint8_t command, uint32_t addr, uint8_t *data, uint32_t len) { + uint32_t iframe = QSPI_INSTRFRAME_WIDTH_QUAD_OUTPUT | QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_READMEMORY | QSPI_INSTRFRAME_INSTREN | QSPI_INSTRFRAME_ADDREN | QSPI_INSTRFRAME_DATAEN | + /*QSPI_INSTRFRAME_CRMODE |*/ QSPI_INSTRFRAME_DUMMYLEN(8); + return run_instruction(command, iframe, addr, data, len); +} + +bool write_memory_quad(uint8_t command, uint32_t addr, uint8_t *data, uint32_t len) { + uint32_t iframe = QSPI_INSTRFRAME_WIDTH_QUAD_OUTPUT | QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_WRITEMEMORY | QSPI_INSTRFRAME_INSTREN | QSPI_INSTRFRAME_ADDREN | QSPI_INSTRFRAME_DATAEN; + return run_instruction(command, iframe, addr, data, len); +} + +static uint8_t read_status(void) { + uint8_t r; + read_command(QSPI_CMD_READ_STATUS, &r, 1); + return r; +} + +static uint8_t read_status2(void) { + uint8_t r; + read_command(QSPI_CMD_READ_STATUS2, &r, 1); + return r; +} + +static bool write_enable(void) { + return run_command(QSPI_CMD_WRITE_ENABLE); +} + +static void wait_for_flash_ready(void) { + // both WIP and WREN bit should be clear + while (read_status() & 0x03) { + } +} + +static uint8_t get_baud(int32_t freq_mhz) { + int baud = get_peripheral_freq() / (freq_mhz * 1000000) - 1; + if (baud < 1) { + baud = 1; + } + if (baud > 255) { + baud = 255; + } + return baud; +} + +int get_sfdp_table(uint8_t *table, int maxlen) { + uint8_t header[16]; + read_memory_single(QSPI_CMD_READ_SFDP_PARAMETER, 0, header, sizeof(header)); + int len = MIN(header[11] * 4, maxlen); + int addr = header[12] + (header[13] << 8) + (header[14] << 16); + read_memory_single(QSPI_CMD_READ_SFDP_PARAMETER, addr, table, len); + return len; +} + +STATIC mp_obj_t samd_qspiflash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_arg_check_num(n_args, n_kw, 0, 0, false); + + // The QSPI is a singleton + samd_qspiflash_obj_t *self = &qspiflash_obj; + self->phase = 0; + self->polarity = 0; + self->pagesize = PAGE_SIZE; + self->sectorsize = SECTOR_SIZE; + + // Enable the device clock + MCLK->AHBMASK.reg |= MCLK_AHBMASK_QSPI; + MCLK->AHBMASK.reg |= MCLK_AHBMASK_QSPI_2X; + MCLK->APBCMASK.reg |= MCLK_APBCMASK_QSPI; + + // Configure the pins. + mp_hal_set_pin_mux(PIN_CS, ALT_FCT_QSPI); + mp_hal_set_pin_mux(PIN_SCK, ALT_FCT_QSPI); + mp_hal_set_pin_mux(PIN_IO0, ALT_FCT_QSPI); + mp_hal_set_pin_mux(PIN_IO1, ALT_FCT_QSPI); + mp_hal_set_pin_mux(PIN_IO2, ALT_FCT_QSPI); + mp_hal_set_pin_mux(PIN_IO3, ALT_FCT_QSPI); + + // Configure the QSPI interface + QSPI->CTRLA.bit.SWRST = 1; + mp_hal_delay_us(1000); // Maybe not required. + + QSPI->CTRLB.reg = QSPI_CTRLB_MODE_MEMORY | + QSPI_CTRLB_CSMODE_NORELOAD | + QSPI_CTRLB_DATALEN_8BITS | + QSPI_CTRLB_CSMODE_LASTXFER; + // start with low 4Mhz, Mode 0 + QSPI->BAUD.reg = QSPI_BAUD_BAUD(get_baud(4)) | + (self->phase << QSPI_BAUD_CPHA_Pos) | + (self->polarity << QSPI_BAUD_CPOL_Pos); + QSPI->CTRLA.bit.ENABLE = 1; + + uint8_t jedec_ids[3]; + read_command(QSPI_CMD_READ_JEDEC_ID, jedec_ids, sizeof(jedec_ids)); + + // Read the common sfdp table + // Check the device addr length, support of 1-1-4 mode and get the sector size + uint8_t sfdp_table[128]; + int len = get_sfdp_table(sfdp_table, sizeof(sfdp_table)); + if (len >= 29) { + self->sectorsize = 1 << sfdp_table[28]; + bool addr4b = ((sfdp_table[2] >> 1) & 0x03) == 0x02; + bool supports_qspi_114 = (sfdp_table[2] & 0x40) != 0; + if (addr4b || !supports_qspi_114) { + mp_raise_ValueError(MP_ERROR_TEXT("QSPI mode not supported")); + } + } + + // Check, if the flash device is known and get it's properties. + flash_device = NULL; + for (uint8_t i = 0; i < EXTERNAL_FLASH_DEVICE_COUNT; i++) { + const external_flash_device *possible_device = &possible_devices[i]; + if (jedec_ids[0] == possible_device->manufacturer_id && + jedec_ids[1] == possible_device->memory_type && + jedec_ids[2] == possible_device->capacity) { + flash_device = possible_device; + break; + } + } + + // If the flash device is not known, try generic config options + if (flash_device == NULL) { + if (jedec_ids[0] == 0xc2) { // Macronix devices + generic_config.quad_enable_bit_mask = 0x04; + generic_config.single_status_byte = true; + } + generic_config.total_size = 1 << jedec_ids[2]; + flash_device = &generic_config; + } + + self->size = flash_device->total_size; + + // The write in progress bit should be low. + while (read_status() & 0x01) { + } + // The suspended write/erase bit should be low. + while (read_status2() & 0x80) { + } + run_command(QSPI_CMD_ENABLE_RESET); + run_command(QSPI_CMD_RESET); + // Wait 30us for the reset + mp_hal_delay_us(30); + // Speed up the frequency + QSPI->BAUD.bit.BAUD = get_baud(flash_device->max_clock_speed_mhz); + + // Enable Quad Mode if available + uint8_t status = 0; + if (flash_device->quad_enable_bit_mask) { + // Verify that QSPI mode is enabled. + status = flash_device->single_status_byte ? read_status() : read_status2(); + } + + // Check the quad enable bit. + if ((status & flash_device->quad_enable_bit_mask) == 0) { + write_enable(); + uint8_t full_status[2] = {0x00, flash_device->quad_enable_bit_mask}; + + if (flash_device->write_status_register_split) { + write_command(QSPI_CMD_WRITE_STATUS2, full_status + 1, 1); + } else if (flash_device->single_status_byte) { + write_command(QSPI_CMD_WRITE_STATUS, full_status + 1, 1); + } else { + write_command(QSPI_CMD_WRITE_STATUS, full_status, 2); + } + } + // Turn off writes in case this is a microcontroller only reset. + run_command(QSPI_CMD_WRITE_DISABLE); + wait_for_flash_ready(); + + return self; +} + +STATIC mp_obj_t samd_qspiflash_read(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) { + if (len > 0) { + wait_for_flash_ready(); + // Command 0x6B 1 line address, 4 line Data + // with Continuous Read Mode and Quad output mode, read memory type + read_memory_quad(QSPI_CMD_QUAD_READ, addr, dest, len); + } + + return mp_const_none; +} + +STATIC mp_obj_t samd_qspiflash_write(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) { + uint32_t length = len; + uint32_t pos = 0; + uint8_t *buf = src; + + while (pos < length) { + uint16_t maxsize = self->pagesize - pos % self->pagesize; + uint16_t size = (length - pos) > maxsize ? maxsize : length - pos; + + wait_for_flash_ready(); + write_enable(); + write_memory_quad(QSPI_CMD_QUAD_PAGE_PROGRAM, addr, buf + pos, size); + + addr += size; + pos += size; + } + + return mp_const_none; +} + +STATIC mp_obj_t samd_qspiflash_erase(uint32_t addr) { + wait_for_flash_ready(); + write_enable(); + erase_command(QSPI_CMD_ERASE_SECTOR, addr); + + return mp_const_none; +} + +STATIC mp_obj_t samd_qspiflash_readblocks(size_t n_args, const mp_obj_t *args) { + samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]); + uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE); + if (n_args == 4) { + offset += mp_obj_get_int(args[3]); + } + + // Read data to flash (adf4 API) + samd_qspiflash_read(self, offset, bufinfo.buf, bufinfo.len); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_readblocks_obj, 3, 4, samd_qspiflash_readblocks); + +STATIC mp_obj_t samd_qspiflash_writeblocks(size_t n_args, const mp_obj_t *args) { + samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]); + uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); + if (n_args == 3) { + samd_qspiflash_erase(offset); + // TODO check return value + } else { + offset += mp_obj_get_int(args[3]); + } + // Write data to flash (adf4 API) + samd_qspiflash_write(self, offset, bufinfo.buf, bufinfo.len); + // TODO check return value + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_writeblocks_obj, 3, 4, samd_qspiflash_writeblocks); + +STATIC mp_obj_t samd_qspiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { + samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_int_t cmd = mp_obj_get_int(cmd_in); + + switch (cmd) { + case MP_BLOCKDEV_IOCTL_INIT: + return MP_OBJ_NEW_SMALL_INT(0); + case MP_BLOCKDEV_IOCTL_DEINIT: + return MP_OBJ_NEW_SMALL_INT(0); + case MP_BLOCKDEV_IOCTL_SYNC: + return MP_OBJ_NEW_SMALL_INT(0); + case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: + return MP_OBJ_NEW_SMALL_INT(self->size / self->sectorsize); + case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: + return MP_OBJ_NEW_SMALL_INT(self->sectorsize); + case MP_BLOCKDEV_IOCTL_BLOCK_ERASE: { + samd_qspiflash_erase(mp_obj_get_int(arg_in) * self->sectorsize); + // TODO check return value + return MP_OBJ_NEW_SMALL_INT(0); + } + default: + return mp_const_none; + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(samd_qspiflash_ioctl_obj, samd_qspiflash_ioctl); + +STATIC const mp_rom_map_elem_t samd_qspiflash_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&samd_qspiflash_readblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&samd_qspiflash_writeblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&samd_qspiflash_ioctl_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(samd_qspiflash_locals_dict, samd_qspiflash_locals_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + samd_qspiflash_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + make_new, samd_qspiflash_make_new, + locals_dict, &samd_qspiflash_locals_dict + ); + +#endif // MICROPY_HW_QSPI_FLASH From 69cb5e8f2ac6ffd1b4e2127eb31321bff240a654 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 24 May 2023 16:19:33 +0200 Subject: [PATCH 160/565] samd: Adapt existing samd.Flash and integrate with (Q)SPI flash in boot. Checks are added to ensure, that only one of the flash drivers is selected. Signed-off-by: robert-hh --- ports/samd/Makefile | 2 ++ ports/samd/modsamd.c | 13 ++++++++++++- ports/samd/modules/_boot.py | 10 +++++----- ports/samd/mpconfigport.h | 5 +++++ ports/samd/samd_flash.c | 38 +++++++++++++++---------------------- 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 6f7c8fbd85..211607650b 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -113,7 +113,9 @@ SRC_C += \ pin_af.c \ samd_flash.c \ samd_isr.c \ + samd_qspiflash.c \ samd_soc.c \ + samd_spiflash.c \ tusb_port.c \ SHARED_SRC_C += \ diff --git a/ports/samd/modsamd.c b/ports/samd/modsamd.c index 7593a7bb0d..307de62af5 100644 --- a/ports/samd/modsamd.c +++ b/ports/samd/modsamd.c @@ -32,7 +32,18 @@ #include "pin_af.h" #include "samd_soc.h" +#if MICROPY_HW_MCUFLASH extern const mp_obj_type_t samd_flash_type; +#define SPIFLASH_TYPE samd_flash_type +#endif +#ifdef MICROPY_HW_QSPIFLASH +extern const mp_obj_type_t samd_qspiflash_type; +#define SPIFLASH_TYPE samd_qspiflash_type +#endif +#if MICROPY_HW_SPIFLASH +extern const mp_obj_type_t samd_spiflash_type; +#define SPIFLASH_TYPE samd_spiflash_type +#endif STATIC mp_obj_t samd_pininfo(mp_obj_t pin_obj) { const machine_pin_obj_t *pin_af = pin_find(pin_obj); @@ -67,7 +78,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(samd_pininfo_obj, samd_pininfo); STATIC const mp_rom_map_elem_t samd_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_samd) }, - { MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&samd_flash_type) }, + { MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&SPIFLASH_TYPE) }, { MP_ROM_QSTR(MP_QSTR_pininfo), MP_ROM_PTR(&samd_pininfo_obj) }, }; STATIC MP_DEFINE_CONST_DICT(samd_module_globals, samd_module_globals_table); diff --git a/ports/samd/modules/_boot.py b/ports/samd/modules/_boot.py index e183125f2e..5fe2bc640c 100644 --- a/ports/samd/modules/_boot.py +++ b/ports/samd/modules/_boot.py @@ -2,18 +2,18 @@ import gc import uos import samd -samd.Flash.flash_init() bdev = samd.Flash() # Try to mount the filesystem, and format the flash if it doesn't exist. fs_type = uos.VfsLfs2 if hasattr(uos, "VfsLfs2") else uos.VfsLfs1 try: - vfs = fs_type(bdev) + vfs = fs_type(bdev, progsize=256) except: - fs_type.mkfs(bdev) - vfs = fs_type(bdev) + fs_type.mkfs(bdev, progsize=256) + vfs = fs_type(bdev, progsize=256) uos.mount(vfs, "/") +del vfs, fs_type, bdev, uos, samd gc.collect() -del uos, vfs, gc +del gc diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index bf03b5f7bd..7392b03059 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -136,6 +136,11 @@ #define MICROPY_BOARD_PENDSV_ENTRIES #endif +// Use internal flash for the file system if no flash file system is selected. +#if !defined(MICROPY_HW_MCUFLASH) && !defined(MICROPY_HW_QSPIFLASH) && !(defined(MICROPY_HW_SPIFLASH) && defined(MICROPY_HW_SPIFLASH_ID)) +#define MICROPY_HW_MCUFLASH (1) +#endif // !defined(MICROPY_HW_MCUFLASH) .... + // Miscellaneous settings __attribute__((always_inline)) static inline void enable_irq(uint32_t state) { __set_PRIMASK(state); diff --git a/ports/samd/samd_flash.c b/ports/samd/samd_flash.c index 6d9ee96895..b00b4af603 100644 --- a/ports/samd/samd_flash.c +++ b/ports/samd/samd_flash.c @@ -29,7 +29,8 @@ #include "py/runtime.h" #include "extmod/vfs.h" #include "samd_soc.h" -#include "hal_flash.h" + +#if MICROPY_HW_MCUFLASH // ASF 4 #include "hal_flash.h" @@ -62,18 +63,9 @@ STATIC samd_flash_obj_t samd_flash_obj = { .flash_size = (uint32_t)&_sflash_fs, // Get from MCU-Specific loader script. }; -// FLASH stuff -STATIC mp_obj_t samd_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - // No args required. bdev=Flash(). Start Addr & Size defined in samd_flash_obj. - mp_arg_check_num(n_args, n_kw, 0, 0, false); - - // Return singleton object. - return MP_OBJ_FROM_PTR(&samd_flash_obj); -} - // Flash init (from cctpy) // Method is needed for when MP starts up in _boot.py -STATIC mp_obj_t samd_flash_init(void) { +STATIC void samd_flash_init(void) { #ifdef SAMD51 hri_mclk_set_AHBMASK_NVMCTRL_bit(MCLK); #endif @@ -82,9 +74,17 @@ STATIC mp_obj_t samd_flash_init(void) { #endif flash_init(&flash_desc, NVMCTRL); - return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(samd_flash_init_obj, samd_flash_init); + +STATIC mp_obj_t samd_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + // No args required. bdev=Flash(). Start Addr & Size defined in samd_flash_obj. + mp_arg_check_num(n_args, n_kw, 0, 0, false); + + samd_flash_init(); + + // Return singleton object. + return MP_OBJ_FROM_PTR(&samd_flash_obj); +} // Function for ioctl. STATIC mp_obj_t eraseblock(uint32_t sector_in) { @@ -102,14 +102,6 @@ STATIC mp_obj_t samd_flash_version(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(samd_flash_version_obj, samd_flash_version); -STATIC mp_obj_t samd_flash_size(void) { - // ASF4 API calls - mp_int_t PAGES = flash_get_total_pages(&flash_desc); - mp_int_t PAGE_SIZE = flash_get_page_size(&flash_desc); - return MP_OBJ_NEW_SMALL_INT(PAGES * PAGE_SIZE); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(samd_flash_size_obj, samd_flash_size); - STATIC mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) { uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + samd_flash_obj.flash_base; mp_buffer_info_t bufinfo; @@ -171,8 +163,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(samd_flash_ioctl_obj, samd_flash_ioctl); STATIC const mp_rom_map_elem_t samd_flash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_flash_version), MP_ROM_PTR(&samd_flash_version_obj) }, - { MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&samd_flash_size_obj) }, - { MP_ROM_QSTR(MP_QSTR_flash_init), MP_ROM_PTR(&samd_flash_init_obj) }, { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&samd_flash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&samd_flash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&samd_flash_ioctl_obj) }, @@ -186,3 +176,5 @@ MP_DEFINE_CONST_OBJ_TYPE( make_new, samd_flash_make_new, locals_dict, &samd_flash_locals_dict ); + +#endif // MICROPY_HW_MCUFLASH From db5444f68aaca1bec2c90df0ed5afe36bce94cfc Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 24 May 2023 16:21:35 +0200 Subject: [PATCH 161/565] samd/boards: Extend the code size limit for boards with external flash. Code size limits are charged to: - SAMD21: 184K -> 248K - SAMD51x19: 368K -> 496K - SAMD51x20: 368K -> 1008K Signed-off-by: robert-hh --- ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.mk | 1 + ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.mk | 1 + ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.mk | 1 + ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.mk | 1 + ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk | 1 + ports/samd/boards/MINISAM_M4/mpconfigboard.mk | 1 + ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.mk | 1 + ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.mk | 1 + 8 files changed, 8 insertions(+) diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.mk b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.mk index a760cf047e..aa3fbd35da 100644 --- a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.mk +++ b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.mk @@ -6,3 +6,4 @@ TEXT0 = 0x2000 # The ?='s allow overriding in mpconfigboard.mk. # MicroPython settings MICROPY_VFS_LFS1 ?= 1 +MICROPY_HW_CODESIZE ?= 248K diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.mk b/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.mk index 781faa2410..70d73ee6fa 100644 --- a/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.mk +++ b/ports/samd/boards/ADAFRUIT_FEATHER_M4_EXPRESS/mpconfigboard.mk @@ -6,3 +6,4 @@ TEXT0 = 0x4000 # The ?='s allow overriding in mpconfigboard.mk. # MicroPython settings MICROPY_VFS_LFS1 ?= 1 +MICROPY_HW_CODESIZE ?= 496K diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.mk b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.mk index a760cf047e..aa3fbd35da 100644 --- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.mk +++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M0_EXPRESS/mpconfigboard.mk @@ -6,3 +6,4 @@ TEXT0 = 0x2000 # The ?='s allow overriding in mpconfigboard.mk. # MicroPython settings MICROPY_VFS_LFS1 ?= 1 +MICROPY_HW_CODESIZE ?= 248K diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.mk b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.mk index da3e47589a..7ef411431d 100644 --- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.mk +++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.mk @@ -6,3 +6,4 @@ TEXT0 = 0x4000 # The ?='s allow overriding in mpconfigboard.mk. # MicroPython settings MICROPY_VFS_LFS1 ?= 1 +MICROPY_HW_CODESIZE ?= 496K diff --git a/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk index 238ca0055d..a196612539 100644 --- a/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk +++ b/ports/samd/boards/ADAFRUIT_METRO_M4_EXPRESS/mpconfigboard.mk @@ -10,3 +10,4 @@ MICROPY_PY_NETWORK ?= 1 MICROPY_PY_NETWORK_NINAW10 ?= 1 BOARD_VARIANTS += "wlan" +MICROPY_HW_CODESIZE ?= 496K diff --git a/ports/samd/boards/MINISAM_M4/mpconfigboard.mk b/ports/samd/boards/MINISAM_M4/mpconfigboard.mk index 73afb02104..4ccbf92c7e 100644 --- a/ports/samd/boards/MINISAM_M4/mpconfigboard.mk +++ b/ports/samd/boards/MINISAM_M4/mpconfigboard.mk @@ -7,3 +7,4 @@ TEXT0 = 0x4000 # The ?='s allow overriding in mpconfigboard.mk. # MicroPython settings MICROPY_VFS_LFS1 ?= 1 +MICROPY_HW_CODESIZE ?= 496K diff --git a/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.mk b/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.mk index c2c4da6152..03f97e138c 100644 --- a/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.mk +++ b/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.mk @@ -6,3 +6,4 @@ TEXT0 = 0x4000 # The ?='s allow overriding in mpconfigboard.mk. # MicroPython settings MICROPY_VFS_LFS1 ?= 1 +MICROPY_HW_CODESIZE ?= 496K diff --git a/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.mk b/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.mk index 9e5cf887df..65b1ba7a33 100644 --- a/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.mk +++ b/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.mk @@ -6,3 +6,4 @@ TEXT0 = 0x4000 # The ?='s allow overriding in mpconfigboard.mk. # MicroPython settings MICROPY_VFS_LFS1 ?= 1 +MICROPY_HW_CODESIZE ?= 1008K From d080d427ebcc263ac6ff792271cec1506e5c81fc Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 2 Jun 2023 13:21:39 -0400 Subject: [PATCH 162/565] top: Add "mis" to list of ignore words for codespell. Observed with codespell 2.2.5.dev57+gdc7e98d9: $ codespell ./ports/rp2/machine_uart.c:163: mis ==> miss, mist ./ports/rp2/machine_uart.c:168: mis ==> miss, mist 2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a52796860a..dfd26bd8c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ line-length = 99 [tool.codespell] count = "" ignore-regex = '\b[A-Z]{3}\b' -ignore-words-list = "ans,asend,deques,dout,extint,hsi,iput,numer,technic,ure" +ignore-words-list = "ans,asend,deques,dout,extint,hsi,iput,mis,numer,technic,ure" quiet-level = 3 skip = """ */build*,\ From 30628d1bb782006c88325a086ddfcd5c2e5ddbb4 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 17 Aug 2022 16:18:31 +1000 Subject: [PATCH 163/565] all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere. This renames the builtin-modules, such that help('modules') and printing the module object will show "module" rather than "umodule". This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- examples/natmod/uheapq/uheapq.c | 2 +- examples/natmod/urandom/urandom.c | 2 +- examples/natmod/ure/ure.c | 2 +- examples/natmod/uzlib/uzlib.c | 2 +- extmod/modbluetooth.c | 4 ++-- extmod/modlwip.c | 2 +- extmod/modubinascii.c | 4 ++-- extmod/moducryptolib.c | 4 ++-- extmod/moduhashlib.c | 4 ++-- extmod/moduheapq.c | 4 ++-- extmod/modujson.c | 4 ++-- extmod/moduos.c | 6 +++--- extmod/moduplatform.c | 4 ++-- extmod/modurandom.c | 4 ++-- extmod/modure.c | 6 +++--- extmod/moduselect.c | 4 ++-- extmod/modusocket.c | 4 ++-- extmod/modussl_axtls.c | 8 ++++---- extmod/modussl_mbedtls.c | 8 ++++---- extmod/modutime.c | 4 ++-- extmod/modutimeq.c | 8 ++++---- extmod/moduwebsocket.c | 4 ++-- extmod/moduzlib.c | 4 ++-- ports/cc3200/mods/modmachine.c | 4 ++-- ports/cc3200/mods/moduhashlib.c | 2 +- ports/cc3200/mods/moduos.c | 4 ++-- ports/cc3200/mods/modusocket.c | 4 ++-- ports/cc3200/mods/modussl.c | 6 +++--- ports/cc3200/mpconfigport.h | 2 +- ports/esp32/modmachine.c | 4 ++-- ports/esp32/modsocket.c | 4 ++-- ports/esp8266/modmachine.c | 4 ++-- ports/mimxrt/modmachine.c | 4 ++-- ports/nrf/modules/machine/modmachine.c | 4 ++-- ports/nrf/modules/uos/moduos.c | 4 ++-- ports/qemu-arm/modmachine.c | 4 ++-- ports/renesas-ra/README.md | 4 ++-- ports/renesas-ra/modmachine.c | 4 ++-- ports/renesas-ra/mpconfigport.h | 2 +- ports/rp2/README.md | 4 ++-- ports/rp2/modmachine.c | 4 ++-- ports/samd/modmachine.c | 4 ++-- ports/stm32/modmachine.c | 4 ++-- ports/stm32/mpconfigport.h | 2 +- ports/unix/modmachine.c | 4 ++-- ports/unix/moduselect.c | 4 ++-- ports/unix/modusocket.c | 4 ++-- ports/zephyr/README.md | 4 ++-- ports/zephyr/modmachine.c | 4 ++-- ports/zephyr/modusocket.c | 4 ++-- py/modarray.c | 4 ++-- py/modcollections.c | 4 ++-- py/modio.c | 4 ++-- py/modstruct.c | 4 ++-- py/modsys.c | 2 +- py/moduerrno.c | 4 ++-- 56 files changed, 111 insertions(+), 111 deletions(-) diff --git a/examples/natmod/uheapq/uheapq.c b/examples/natmod/uheapq/uheapq.c index 9da6bb4ada..75f00e15cb 100644 --- a/examples/natmod/uheapq/uheapq.c +++ b/examples/natmod/uheapq/uheapq.c @@ -7,7 +7,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY - mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_uheapq)); + mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_heapq)); mp_store_global(MP_QSTR_heappush, MP_OBJ_FROM_PTR(&mod_uheapq_heappush_obj)); mp_store_global(MP_QSTR_heappop, MP_OBJ_FROM_PTR(&mod_uheapq_heappop_obj)); mp_store_global(MP_QSTR_heapify, MP_OBJ_FROM_PTR(&mod_uheapq_heapify_obj)); diff --git a/examples/natmod/urandom/urandom.c b/examples/natmod/urandom/urandom.c index e1fed6a554..bb41bf3f8e 100644 --- a/examples/natmod/urandom/urandom.c +++ b/examples/natmod/urandom/urandom.c @@ -16,7 +16,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a yasmarang_n = 69; yasmarang_d = 233; - mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_urandom)); + mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_random)); mp_store_global(MP_QSTR_getrandbits, MP_OBJ_FROM_PTR(&mod_urandom_getrandbits_obj)); mp_store_global(MP_QSTR_seed, MP_OBJ_FROM_PTR(&mod_urandom_seed_obj)); #if MICROPY_PY_URANDOM_EXTRA_FUNCS diff --git a/examples/natmod/ure/ure.c b/examples/natmod/ure/ure.c index d4bd680abd..c51df2a475 100644 --- a/examples/natmod/ure/ure.c +++ b/examples/natmod/ure/ure.c @@ -63,7 +63,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a MP_OBJ_TYPE_SET_SLOT(&match_type, locals_dict, (void*)&match_locals_dict, 1); re_type.base.type = (void*)&mp_fun_table.type_type; - re_type.name = MP_QSTR_ure; + re_type.name = MP_QSTR_re; MP_OBJ_TYPE_SET_SLOT(&re_type, print, re_print, 0); re_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_match), MP_OBJ_FROM_PTR(&re_match_obj) }; re_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_search), MP_OBJ_FROM_PTR(&re_search_obj) }; diff --git a/examples/natmod/uzlib/uzlib.c b/examples/natmod/uzlib/uzlib.c index 9cf58b10e7..06b24f4b81 100644 --- a/examples/natmod/uzlib/uzlib.c +++ b/examples/natmod/uzlib/uzlib.c @@ -27,7 +27,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a decompio_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_readline), MP_OBJ_FROM_PTR(&mp_stream_unbuffered_readline_obj) }; MP_OBJ_TYPE_SET_SLOT(&decompio_type, locals_dict, (void*)&decompio_locals_dict, 2); - mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_uzlib)); + mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_zlib)); mp_store_global(MP_QSTR_decompress, MP_OBJ_FROM_PTR(&mod_uzlib_decompress_obj)); mp_store_global(MP_QSTR_DecompIO, MP_OBJ_FROM_PTR(&decompio_type)); diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index e65851d6b4..35ba745e31 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -985,7 +985,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); STATIC const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluetooth) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bluetooth) }, { MP_ROM_QSTR(MP_QSTR_BLE), MP_ROM_PTR(&mp_type_bluetooth_ble) }, { MP_ROM_QSTR(MP_QSTR_UUID), MP_ROM_PTR(&mp_type_bluetooth_uuid) }, @@ -1004,7 +1004,7 @@ const mp_obj_module_t mp_module_ubluetooth = { .globals = (mp_obj_dict_t *)&mp_module_bluetooth_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ubluetooth, mp_module_ubluetooth); +MP_REGISTER_MODULE(MP_QSTR_bluetooth, mp_module_ubluetooth); // Helpers diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 734722f83a..19df1ea503 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -1802,7 +1802,7 @@ const mp_obj_module_t mp_module_lwip = { MP_REGISTER_MODULE(MP_QSTR_lwip, mp_module_lwip); // On LWIP-ports, this is the usocket module (replaces extmod/modusocket.c). -MP_REGISTER_MODULE(MP_QSTR_usocket, mp_module_lwip); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_lwip); MP_REGISTER_ROOT_POINTER(mp_obj_t lwip_slip_stream); diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c index 45a39c58d4..85205bc3d1 100644 --- a/extmod/modubinascii.c +++ b/extmod/modubinascii.c @@ -184,7 +184,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj, 1, 2, mod_bin #endif STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubinascii) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_binascii) }, #if MICROPY_PY_BUILTINS_BYTES_HEX { MP_ROM_QSTR(MP_QSTR_hexlify), MP_ROM_PTR(&bytes_hex_as_bytes_obj) }, { MP_ROM_QSTR(MP_QSTR_unhexlify), MP_ROM_PTR(&bytes_fromhex_obj) }, @@ -203,6 +203,6 @@ const mp_obj_module_t mp_module_ubinascii = { .globals = (mp_obj_dict_t *)&mp_module_binascii_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ubinascii, mp_module_ubinascii); +MP_REGISTER_MODULE(MP_QSTR_binascii, mp_module_ubinascii); #endif // MICROPY_PY_UBINASCII diff --git a/extmod/moducryptolib.c b/extmod/moducryptolib.c index fc3fcfd90d..730ae4c6f5 100644 --- a/extmod/moducryptolib.c +++ b/extmod/moducryptolib.c @@ -357,7 +357,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); STATIC const mp_rom_map_elem_t mp_module_ucryptolib_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ucryptolib) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cryptolib) }, { MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&ucryptolib_aes_type) }, #if MICROPY_PY_UCRYPTOLIB_CONSTS { MP_ROM_QSTR(MP_QSTR_MODE_ECB), MP_ROM_INT(UCRYPTOLIB_MODE_ECB) }, @@ -375,6 +375,6 @@ const mp_obj_module_t mp_module_ucryptolib = { .globals = (mp_obj_dict_t *)&mp_module_ucryptolib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ucryptolib, mp_module_ucryptolib); +MP_REGISTER_MODULE(MP_QSTR_cryptolib, mp_module_ucryptolib); #endif // MICROPY_PY_UCRYPTOLIB diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 64e15c444d..addf094765 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -355,7 +355,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #endif // MICROPY_PY_UHASHLIB_MD5 STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uhashlib) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) }, #if MICROPY_PY_UHASHLIB_SHA256 { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&uhashlib_sha256_type) }, #endif @@ -374,6 +374,6 @@ const mp_obj_module_t mp_module_uhashlib = { .globals = (mp_obj_dict_t *)&mp_module_uhashlib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uhashlib, mp_module_uhashlib); +MP_REGISTER_MODULE(MP_QSTR_hashlib, mp_module_uhashlib); #endif // MICROPY_PY_UHASHLIB diff --git a/extmod/moduheapq.c b/extmod/moduheapq.c index bfa6ba608d..9c3df65258 100644 --- a/extmod/moduheapq.c +++ b/extmod/moduheapq.c @@ -105,7 +105,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_uheapq_heapify_obj, mod_uheapq_heapify); #if !MICROPY_ENABLE_DYNRUNTIME STATIC const mp_rom_map_elem_t mp_module_uheapq_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uheapq) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_heapq) }, { MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_uheapq_heappush_obj) }, { MP_ROM_QSTR(MP_QSTR_heappop), MP_ROM_PTR(&mod_uheapq_heappop_obj) }, { MP_ROM_QSTR(MP_QSTR_heapify), MP_ROM_PTR(&mod_uheapq_heapify_obj) }, @@ -118,7 +118,7 @@ const mp_obj_module_t mp_module_uheapq = { .globals = (mp_obj_dict_t *)&mp_module_uheapq_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uheapq, mp_module_uheapq); +MP_REGISTER_MODULE(MP_QSTR_heapq, mp_module_uheapq); #endif #endif // MICROPY_PY_UHEAPQ diff --git a/extmod/modujson.c b/extmod/modujson.c index 4e992e2245..106595aab6 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -367,7 +367,7 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_loads_obj, mod_ujson_loads); STATIC const mp_rom_map_elem_t mp_module_ujson_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ujson) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) }, { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_ujson_dump_obj) }, { MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_ujson_dumps_obj) }, { MP_ROM_QSTR(MP_QSTR_load), MP_ROM_PTR(&mod_ujson_load_obj) }, @@ -381,6 +381,6 @@ const mp_obj_module_t mp_module_ujson = { .globals = (mp_obj_dict_t *)&mp_module_ujson_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ujson, mp_module_ujson); +MP_REGISTER_MODULE(MP_QSTR_json, mp_module_ujson); #endif // MICROPY_PY_UJSON diff --git a/extmod/moduos.c b/extmod/moduos.c index a245ae7283..a7d15ef966 100644 --- a/extmod/moduos.c +++ b/extmod/moduos.c @@ -122,7 +122,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_uname_obj, mp_uos_uname); #endif STATIC const mp_rom_map_elem_t os_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, #if MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV { MP_ROM_QSTR(MP_QSTR_getenv), MP_ROM_PTR(&mp_uos_getenv_obj) }, @@ -141,7 +141,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { #if MICROPY_PY_UOS_UNAME { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&mp_uos_uname_obj) }, #endif - #if MICROPY_PY_UOS_URANDOM + #if MICROPY_PY_OS_URANDOM { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&mp_uos_urandom_obj) }, #endif @@ -195,6 +195,6 @@ const mp_obj_module_t mp_module_uos = { .globals = (mp_obj_dict_t *)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uos, mp_module_uos); +MP_REGISTER_MODULE(MP_QSTR_os, mp_module_uos); #endif // MICROPY_PY_UOS diff --git a/extmod/moduplatform.c b/extmod/moduplatform.c index 1b35b08aa7..079e275362 100644 --- a/extmod/moduplatform.c +++ b/extmod/moduplatform.c @@ -62,7 +62,7 @@ STATIC mp_obj_t platform_libc_ver(size_t n_args, const mp_obj_t *pos_args, mp_ma STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_libc_ver_obj, 0, platform_libc_ver); STATIC const mp_rom_map_elem_t modplatform_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uplatform) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_platform) }, { MP_ROM_QSTR(MP_QSTR_platform), MP_ROM_PTR(&platform_platform_obj) }, { MP_ROM_QSTR(MP_QSTR_python_compiler), MP_ROM_PTR(&platform_python_compiler_obj) }, { MP_ROM_QSTR(MP_QSTR_libc_ver), MP_ROM_PTR(&platform_libc_ver_obj) }, @@ -75,6 +75,6 @@ const mp_obj_module_t mp_module_uplatform = { .globals = (mp_obj_dict_t *)&modplatform_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uplatform, mp_module_uplatform); +MP_REGISTER_MODULE(MP_QSTR_platform, mp_module_uplatform); #endif // MICROPY_PY_UPLATFORM diff --git a/extmod/modurandom.c b/extmod/modurandom.c index b661627190..6b59c0ae39 100644 --- a/extmod/modurandom.c +++ b/extmod/modurandom.c @@ -231,7 +231,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom___init___obj, mod_urandom___init__) #if !MICROPY_ENABLE_DYNRUNTIME STATIC const mp_rom_map_elem_t mp_module_urandom_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_urandom) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_random) }, #if SEED_ON_IMPORT { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_urandom___init___obj) }, #endif @@ -255,7 +255,7 @@ const mp_obj_module_t mp_module_urandom = { .globals = (mp_obj_dict_t *)&mp_module_urandom_globals, }; -MP_REGISTER_MODULE(MP_QSTR_urandom, mp_module_urandom); +MP_REGISTER_MODULE(MP_QSTR_random, mp_module_urandom); #endif #endif // MICROPY_PY_URANDOM diff --git a/extmod/modure.c b/extmod/modure.c index 801e5df897..c27125bf1c 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -414,7 +414,7 @@ STATIC MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); STATIC MP_DEFINE_CONST_OBJ_TYPE( re_type, - MP_QSTR_ure, + MP_QSTR_re, MP_TYPE_FLAG_NONE, print, re_print, locals_dict, &re_locals_dict @@ -451,7 +451,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_compile_obj, 1, 2, mod_re_compile); #if !MICROPY_ENABLE_DYNRUNTIME STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ure) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_re) }, { MP_ROM_QSTR(MP_QSTR_compile), MP_ROM_PTR(&mod_re_compile_obj) }, { MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&re_match_obj) }, { MP_ROM_QSTR(MP_QSTR_search), MP_ROM_PTR(&re_search_obj) }, @@ -470,7 +470,7 @@ const mp_obj_module_t mp_module_ure = { .globals = (mp_obj_dict_t *)&mp_module_re_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ure, mp_module_ure); +MP_REGISTER_MODULE(MP_QSTR_re, mp_module_ure); #endif // Source files #include'd here to make sure they're compiled in diff --git a/extmod/moduselect.c b/extmod/moduselect.c index 128154a4b6..4df0f4d561 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -355,7 +355,7 @@ STATIC mp_obj_t select_poll(void) { MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll); STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uselect) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_select) }, #if MICROPY_PY_USELECT_SELECT { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) }, #endif @@ -373,6 +373,6 @@ const mp_obj_module_t mp_module_uselect = { .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uselect, mp_module_uselect); +MP_REGISTER_MODULE(MP_QSTR_select, mp_module_uselect); #endif // MICROPY_PY_USELECT diff --git a/extmod/modusocket.c b/extmod/modusocket.c index 2aa6010884..6d14ebdfb0 100644 --- a/extmod/modusocket.c +++ b/extmod/modusocket.c @@ -616,7 +616,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(size_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_usocket_getaddrinfo_obj, 2, 6, mod_usocket_getaddrinfo); STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_usocket_getaddrinfo_obj) }, @@ -653,6 +653,6 @@ const mp_obj_module_t mp_module_usocket = { .globals = (mp_obj_dict_t *)&mp_module_usocket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_usocket, mp_module_usocket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_usocket); #endif // MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c index 77e942ec12..393a945fac 100644 --- a/extmod/modussl_axtls.c +++ b/extmod/modussl_axtls.c @@ -316,9 +316,9 @@ STATIC const mp_stream_p_t ussl_socket_stream_p = { STATIC MP_DEFINE_CONST_OBJ_TYPE( ussl_socket_type, - MP_QSTR_ussl, - MP_TYPE_FLAG_NONE, // Save on qstr's, reuse same as for module + MP_QSTR_ssl, + MP_TYPE_FLAG_NONE, print, ussl_socket_print, protocol, &ussl_socket_stream_p, locals_dict, &ussl_socket_locals_dict @@ -346,7 +346,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 1, mod_ssl_wrap_socket); STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ussl) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssl) }, { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) }, }; @@ -357,6 +357,6 @@ const mp_obj_module_t mp_module_ussl = { .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ussl, mp_module_ussl); +MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ussl); #endif // MICROPY_PY_USSL && MICROPY_SSL_AXTLS diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index 74a59fdb67..c12c943d8a 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -461,9 +461,9 @@ STATIC const mp_stream_p_t ussl_socket_stream_p = { STATIC MP_DEFINE_CONST_OBJ_TYPE( ussl_socket_type, - MP_QSTR_ussl, - MP_TYPE_FLAG_NONE, // Save on qstr's, reuse same as for module + MP_QSTR_ssl, + MP_TYPE_FLAG_NONE, print, socket_print, protocol, &ussl_socket_stream_p, locals_dict, &ussl_socket_locals_dict @@ -493,7 +493,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 1, mod_ssl_wrap_socket); STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ussl) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssl) }, { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) }, { MP_ROM_QSTR(MP_QSTR_CERT_NONE), MP_ROM_INT(MBEDTLS_SSL_VERIFY_NONE) }, { MP_ROM_QSTR(MP_QSTR_CERT_OPTIONAL), MP_ROM_INT(MBEDTLS_SSL_VERIFY_OPTIONAL) }, @@ -507,6 +507,6 @@ const mp_obj_module_t mp_module_ussl = { .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ussl, mp_module_ussl); +MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ussl); #endif // MICROPY_PY_USSL && MICROPY_SSL_MBEDTLS diff --git a/extmod/modutime.c b/extmod/modutime.c index d82ac6a27c..5d8148f98a 100644 --- a/extmod/modutime.c +++ b/extmod/modutime.c @@ -197,7 +197,7 @@ STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj, time_ticks_add); STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time) }, #if MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mp_utime_localtime_obj) }, @@ -231,6 +231,6 @@ const mp_obj_module_t mp_module_utime = { .globals = (mp_obj_dict_t *)&mp_module_time_globals, }; -MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime); +MP_REGISTER_MODULE(MP_QSTR_time, mp_module_utime); #endif // MICROPY_PY_UTIME diff --git a/extmod/modutimeq.c b/extmod/modutimeq.c index 1a38104eaf..4aa572934f 100644 --- a/extmod/modutimeq.c +++ b/extmod/modutimeq.c @@ -211,7 +211,7 @@ STATIC MP_DEFINE_CONST_DICT(utimeq_locals_dict, utimeq_locals_dict_table); STATIC MP_DEFINE_CONST_OBJ_TYPE( utimeq_type, - MP_QSTR_utimeq, + MP_QSTR_timeq, MP_TYPE_FLAG_NONE, make_new, utimeq_make_new, unary_op, utimeq_unary_op, @@ -219,8 +219,8 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); STATIC const mp_rom_map_elem_t mp_module_utimeq_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utimeq) }, - { MP_ROM_QSTR(MP_QSTR_utimeq), MP_ROM_PTR(&utimeq_type) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_timeq) }, + { MP_ROM_QSTR(MP_QSTR_timeq), MP_ROM_PTR(&utimeq_type) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_utimeq_globals, mp_module_utimeq_globals_table); @@ -230,6 +230,6 @@ const mp_obj_module_t mp_module_utimeq = { .globals = (mp_obj_dict_t *)&mp_module_utimeq_globals, }; -MP_REGISTER_MODULE(MP_QSTR_utimeq, mp_module_utimeq); +MP_REGISTER_MODULE(MP_QSTR_timeq, mp_module_utimeq); #endif // MICROPY_PY_UTIMEQ diff --git a/extmod/moduwebsocket.c b/extmod/moduwebsocket.c index 9b12fc8635..ca7152bb13 100644 --- a/extmod/moduwebsocket.c +++ b/extmod/moduwebsocket.c @@ -300,7 +300,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); STATIC const mp_rom_map_elem_t uwebsocket_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uwebsocket) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_websocket) }, { MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) }, }; @@ -311,6 +311,6 @@ const mp_obj_module_t mp_module_uwebsocket = { .globals = (mp_obj_dict_t *)&uwebsocket_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uwebsocket, mp_module_uwebsocket); +MP_REGISTER_MODULE(MP_QSTR_websocket, mp_module_uwebsocket); #endif // MICROPY_PY_UWEBSOCKET diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index 14d15321a3..f41ca2b012 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -211,7 +211,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_u #if !MICROPY_ENABLE_DYNRUNTIME STATIC const mp_rom_map_elem_t mp_module_uzlib_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uzlib) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zlib) }, { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_uzlib_decompress_obj) }, { MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) }, }; @@ -224,7 +224,7 @@ const mp_obj_module_t mp_module_uzlib = { }; -MP_REGISTER_MODULE(MP_QSTR_uzlib, mp_module_uzlib); +MP_REGISTER_MODULE(MP_QSTR_zlib, mp_module_uzlib); #endif // Source files #include'd here to make sure they're compiled in diff --git a/ports/cc3200/mods/modmachine.c b/ports/cc3200/mods/modmachine.c index 3e483e0a23..c5b06f5077 100644 --- a/ports/cc3200/mods/modmachine.c +++ b/ports/cc3200/mods/modmachine.c @@ -162,7 +162,7 @@ STATIC mp_obj_t machine_wake_reason (void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, #ifdef DEBUG @@ -214,5 +214,5 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t*)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); MP_REGISTER_ROOT_POINTER(mp_obj_t machine_config_main); diff --git a/ports/cc3200/mods/moduhashlib.c b/ports/cc3200/mods/moduhashlib.c index 302ff335ff..5424a6c0fb 100644 --- a/ports/cc3200/mods/moduhashlib.c +++ b/ports/cc3200/mods/moduhashlib.c @@ -194,7 +194,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uhashlib) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) }, //{ MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&md5_type) }, { MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&sha1_type) }, { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&sha256_type) }, diff --git a/ports/cc3200/mods/moduos.c b/ports/cc3200/mods/moduos.c index e284e9eb1f..b3f3bbf8d8 100644 --- a/ports/cc3200/mods/moduos.c +++ b/ports/cc3200/mods/moduos.c @@ -146,7 +146,7 @@ STATIC mp_obj_t os_dupterm(uint n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_dupterm_obj, 0, 1, os_dupterm); STATIC const mp_rom_map_elem_t os_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) }, @@ -180,4 +180,4 @@ const mp_obj_module_t mp_module_uos = { .globals = (mp_obj_dict_t*)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uos, mp_module_uos); +MP_REGISTER_MODULE(MP_QSTR_os, mp_module_uos); diff --git a/ports/cc3200/mods/modusocket.c b/ports/cc3200/mods/modusocket.c index cd1489fb4a..311a4395fb 100644 --- a/ports/cc3200/mods/modusocket.c +++ b/ports/cc3200/mods/modusocket.c @@ -795,7 +795,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_usocket_getaddrinfo_obj, mod_usocket_getaddrinfo); STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_usocket_getaddrinfo_obj) }, @@ -818,4 +818,4 @@ const mp_obj_module_t mp_module_usocket = { .globals = (mp_obj_dict_t*)&mp_module_usocket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_usocket, mp_module_usocket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_usocket); diff --git a/ports/cc3200/mods/modussl.c b/ports/cc3200/mods/modussl.c index 118cbd06f8..e2de7b05cb 100644 --- a/ports/cc3200/mods/modussl.c +++ b/ports/cc3200/mods/modussl.c @@ -62,7 +62,7 @@ STATIC const mp_obj_type_t ssl_socket_type; // locals and stream methods STATIC MP_DEFINE_CONST_OBJ_TYPE( ssl_socket_type, - MP_QSTR_ussl, + MP_QSTR_ssl, MP_TYPE_FLAG_NONE, protocol, &socket_stream_p, locals_dict, &socket_locals_dict @@ -136,7 +136,7 @@ arg_error: STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket); STATIC const mp_rom_map_elem_t mp_module_ussl_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ussl) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssl) }, { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) }, // class exceptions @@ -160,4 +160,4 @@ const mp_obj_module_t mp_module_ussl = { .globals = (mp_obj_dict_t*)&mp_module_ussl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ussl, mp_module_ussl); +MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ussl); diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index cb71a28f34..6bdaa9b553 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -136,7 +136,7 @@ // extra constants #define MICROPY_PORT_CONSTANTS \ - { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ + { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \ #define MP_STATE_PORT MP_STATE_VM diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index 37d4f424d4..a863f716c7 100644 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -272,7 +272,7 @@ STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) { MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, @@ -353,6 +353,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 9812eb3476..5e07d1f4f5 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -844,7 +844,7 @@ STATIC mp_obj_t esp_socket_initialize() { STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_socket_initialize_obj, esp_socket_initialize); STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&esp_socket_initialize_obj) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&esp_socket_getaddrinfo_obj) }, @@ -872,4 +872,4 @@ const mp_obj_module_t mp_module_usocket = { // Note: This port doesn't define MICROPY_PY_USOCKET or MICROPY_PY_LWIP so // this will not conflict with the common implementation provided by // extmod/mod{lwip,usocket}.c. -MP_REGISTER_MODULE(MP_QSTR_usocket, mp_module_usocket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_usocket); diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c index 3c75a2d7ff..383f46dda7 100644 --- a/ports/esp8266/modmachine.c +++ b/ports/esp8266/modmachine.c @@ -396,7 +396,7 @@ mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t } STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, { MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) }, @@ -456,6 +456,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/mimxrt/modmachine.c b/ports/mimxrt/modmachine.c index 7b00470cca..098c3b949a 100644 --- a/ports/mimxrt/modmachine.c +++ b/ports/mimxrt/modmachine.c @@ -130,7 +130,7 @@ NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, @@ -185,6 +185,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/nrf/modules/machine/modmachine.c b/ports/nrf/modules/machine/modmachine.c index b080a526cf..b7cbdc7b2d 100644 --- a/ports/nrf/modules/machine/modmachine.c +++ b/ports/nrf/modules/machine/modmachine.c @@ -205,7 +205,7 @@ STATIC mp_obj_t machine_disable_irq(void) { MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) }, @@ -266,6 +266,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t*)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/nrf/modules/uos/moduos.c b/ports/nrf/modules/uos/moduos.c index 402096aacd..bb49012707 100644 --- a/ports/nrf/modules/uos/moduos.c +++ b/ports/nrf/modules/uos/moduos.c @@ -138,7 +138,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_os_dupterm_obj, 0, 1, os_dupterm); #endif // MICROPY_PY_MACHINE_UART STATIC const mp_rom_map_elem_t os_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) }, @@ -197,4 +197,4 @@ const mp_obj_module_t mp_module_uos = { .globals = (mp_obj_dict_t*)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uos, mp_module_uos); +MP_REGISTER_MODULE(MP_QSTR_os, mp_module_uos); diff --git a/ports/qemu-arm/modmachine.c b/ports/qemu-arm/modmachine.c index 515452f41d..1f9151ff74 100644 --- a/ports/qemu-arm/modmachine.c +++ b/ports/qemu-arm/modmachine.c @@ -31,7 +31,7 @@ #if MICROPY_PY_MACHINE STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, @@ -48,6 +48,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/renesas-ra/README.md b/ports/renesas-ra/README.md index 896d465d2d..1e5e2ed0cf 100644 --- a/ports/renesas-ra/README.md +++ b/ports/renesas-ra/README.md @@ -4,8 +4,8 @@ This is a port of MicroPython to the Renesas RA family of microcontrollers. Currently supported features are: - Filesystem on the internal flash using FatFs. -- `utime` module with sleep, time, and ticks functions. -- `uos` module with VFS support. +- `time` module with sleep, time, and ticks functions. +- `os` module with VFS support. - `machine` module with the following classes: `Pin`, `ADC`, `I2C`, `SPI`, `SoftI2C`, `SoftSPI`, `UART`, `RTC` - sdcard driver if frozen driver is installed. diff --git a/ports/renesas-ra/modmachine.c b/ports/renesas-ra/modmachine.c index ecb028983c..07e6103aaa 100644 --- a/ports/renesas-ra/modmachine.c +++ b/ports/renesas-ra/modmachine.c @@ -251,7 +251,7 @@ STATIC mp_obj_t machine_reset_cause(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, @@ -307,6 +307,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index 7dbe941c0e..42834c1fbc 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -139,7 +139,7 @@ #if MICROPY_PY_MACHINE #define MACHINE_BUILTIN_MODULE_CONSTANTS \ - { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ + { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, #else #define MACHINE_BUILTIN_MODULE_CONSTANTS diff --git a/ports/rp2/README.md b/ports/rp2/README.md index 078919ce81..3f152b8181 100644 --- a/ports/rp2/README.md +++ b/ports/rp2/README.md @@ -6,8 +6,8 @@ Currently supported features are: - REPL over USB VCP, and optionally over UART (on GP0/GP1). - Filesystem on the internal flash, using littlefs2. - Support for native code generation and inline assembler. -- `utime` module with sleep, time and ticks functions. -- `uos` module with VFS support. +- `time` module with sleep, time and ticks functions. +- `os` module with VFS support. - `machine` module with the following classes: `Pin`, `ADC`, `PWM`, `I2C`, `SPI`, `SoftI2C`, `SoftSPI`, `Timer`, `UART`, `WDT`. - `rp2` module with programmable IO (PIO) support. diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c index 81154c94ce..61b91bda0a 100644 --- a/ports/rp2/modmachine.c +++ b/ports/rp2/modmachine.c @@ -229,7 +229,7 @@ STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) { MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, @@ -278,6 +278,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index 58ca895b45..7e231b28b4 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -224,7 +224,7 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj, 0, 1, machine_lightsleep); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, { MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, @@ -297,6 +297,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index dee9689e3b..e6eb73f9cb 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -386,7 +386,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause); #if MICROPY_PY_MACHINE STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, @@ -471,6 +471,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index fd5254082d..62784dccf1 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -170,7 +170,7 @@ extern const struct _mp_obj_module_t stm_module; #if MICROPY_PY_MACHINE #define MACHINE_BUILTIN_MODULE_CONSTANTS \ - { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ + { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, #else #define MACHINE_BUILTIN_MODULE_CONSTANTS diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index 542ff50025..29ac532d2b 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -86,7 +86,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); #endif STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, @@ -110,6 +110,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/unix/moduselect.c b/ports/unix/moduselect.c index 8f71813e70..9b205d333f 100644 --- a/ports/unix/moduselect.c +++ b/ports/unix/moduselect.c @@ -336,7 +336,7 @@ STATIC mp_obj_t select_poll(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_poll_obj, 0, 1, select_poll); STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uselect) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_select) }, { MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mp_select_poll_obj) }, { MP_ROM_QSTR(MP_QSTR_POLLIN), MP_ROM_INT(POLLIN) }, { MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_ROM_INT(POLLOUT) }, @@ -351,6 +351,6 @@ const mp_obj_module_t mp_module_uselect = { .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uselect, mp_module_uselect); +MP_REGISTER_MODULE(MP_QSTR_select, mp_module_uselect); #endif // MICROPY_PY_USELECT_POSIX diff --git a/ports/unix/modusocket.c b/ports/unix/modusocket.c index a32fc60163..2d4eeec346 100644 --- a/ports/unix/modusocket.c +++ b/ports/unix/modusocket.c @@ -674,7 +674,7 @@ STATIC mp_obj_t mod_socket_sockaddr(mp_obj_t sockaddr_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_sockaddr_obj, mod_socket_sockaddr); STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_type_socket) }, { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_socket_getaddrinfo_obj) }, { MP_ROM_QSTR(MP_QSTR_inet_pton), MP_ROM_PTR(&mod_socket_inet_pton_obj) }, @@ -708,6 +708,6 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_usocket, mp_module_socket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_SOCKET diff --git a/ports/zephyr/README.md b/ports/zephyr/README.md index f9bd45344b..3de793b2fe 100644 --- a/ports/zephyr/README.md +++ b/ports/zephyr/README.md @@ -12,11 +12,11 @@ should work with MicroPython (but not all were tested). Features supported at this time: * REPL (interactive prompt) over Zephyr UART console. -* `utime` module for time measurements and delays. +* `time` module for time measurements and delays. * `machine.Pin` class for GPIO control, with IRQ support. * `machine.I2C` class for I2C control. * `machine.SPI` class for SPI control. -* `usocket` module for networking (IPv4/IPv6). +* `socket` module for networking (IPv4/IPv6). * "Frozen modules" support to allow to bundle Python modules together with firmware. Including complete applications, including with run-on-boot capability. diff --git a/ports/zephyr/modmachine.c b/ports/zephyr/modmachine.c index 95a66c5119..6f4bbbdab6 100644 --- a/ports/zephyr/modmachine.c +++ b/ports/zephyr/modmachine.c @@ -61,7 +61,7 @@ STATIC mp_obj_t machine_idle(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, #ifdef CONFIG_REBOOT { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, #endif @@ -89,6 +89,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_umachine, mp_module_machine); +MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/zephyr/modusocket.c b/ports/zephyr/modusocket.c index c79f73a9d2..98dff7e8e8 100644 --- a/ports/zephyr/modusocket.c +++ b/ports/zephyr/modusocket.c @@ -449,7 +449,7 @@ STATIC mp_obj_t pkt_get_info(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(pkt_get_info_obj, pkt_get_info); STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, // objects { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, // class constants @@ -473,6 +473,6 @@ const mp_obj_module_t mp_module_usocket = { .globals = (mp_obj_dict_t *)&mp_module_usocket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_usocket, mp_module_usocket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_usocket); #endif // MICROPY_PY_USOCKET diff --git a/py/modarray.c b/py/modarray.c index d9f7a04528..c91e92f798 100644 --- a/py/modarray.c +++ b/py/modarray.c @@ -29,7 +29,7 @@ #if MICROPY_PY_ARRAY STATIC const mp_rom_map_elem_t mp_module_array_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uarray) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_array) }, { MP_ROM_QSTR(MP_QSTR_array), MP_ROM_PTR(&mp_type_array) }, }; @@ -40,6 +40,6 @@ const mp_obj_module_t mp_module_uarray = { .globals = (mp_obj_dict_t *)&mp_module_array_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uarray, mp_module_uarray); +MP_REGISTER_MODULE(MP_QSTR_array, mp_module_uarray); #endif diff --git a/py/modcollections.c b/py/modcollections.c index 8c62f34db7..a56fe069ea 100644 --- a/py/modcollections.c +++ b/py/modcollections.c @@ -29,7 +29,7 @@ #if MICROPY_PY_COLLECTIONS STATIC const mp_rom_map_elem_t mp_module_collections_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ucollections) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_collections) }, #if MICROPY_PY_COLLECTIONS_DEQUE { MP_ROM_QSTR(MP_QSTR_deque), MP_ROM_PTR(&mp_type_deque) }, #endif @@ -46,6 +46,6 @@ const mp_obj_module_t mp_module_collections = { .globals = (mp_obj_dict_t *)&mp_module_collections_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ucollections, mp_module_collections); +MP_REGISTER_MODULE(MP_QSTR_collections, mp_module_collections); #endif // MICROPY_PY_COLLECTIONS diff --git a/py/modio.c b/py/modio.c index 9ec6bbcc4e..3462611d71 100644 --- a/py/modio.c +++ b/py/modio.c @@ -203,7 +203,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #endif // MICROPY_PY_IO_BUFFEREDWRITER STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uio) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_io) }, // Note: mp_builtin_open_obj should be defined by port, it's not // part of the core. { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, @@ -226,6 +226,6 @@ const mp_obj_module_t mp_module_io = { .globals = (mp_obj_dict_t *)&mp_module_io_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uio, mp_module_io); +MP_REGISTER_MODULE(MP_QSTR_io, mp_module_io); #endif diff --git a/py/modstruct.c b/py/modstruct.c index ec86d4b9c2..78c7d53e4b 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -251,7 +251,7 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_into_obj, 3, MP_OBJ_FUN_ARGS_MAX, struct_pack_into); STATIC const mp_rom_map_elem_t mp_module_struct_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ustruct) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_struct) }, { MP_ROM_QSTR(MP_QSTR_calcsize), MP_ROM_PTR(&struct_calcsize_obj) }, { MP_ROM_QSTR(MP_QSTR_pack), MP_ROM_PTR(&struct_pack_obj) }, { MP_ROM_QSTR(MP_QSTR_pack_into), MP_ROM_PTR(&struct_pack_into_obj) }, @@ -266,6 +266,6 @@ const mp_obj_module_t mp_module_ustruct = { .globals = (mp_obj_dict_t *)&mp_module_struct_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ustruct, mp_module_ustruct); +MP_REGISTER_MODULE(MP_QSTR_struct, mp_module_ustruct); #endif diff --git a/py/modsys.c b/py/modsys.c index 35af761a08..09bdfefc63 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -294,7 +294,7 @@ const mp_obj_module_t mp_module_sys = { .globals = (mp_obj_dict_t *)&mp_module_sys_globals, }; -MP_REGISTER_MODULE(MP_QSTR_usys, mp_module_sys); +MP_REGISTER_MODULE(MP_QSTR_sys, mp_module_sys); // If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is not enabled then these two lists // must be initialised after the call to mp_init. diff --git a/py/moduerrno.c b/py/moduerrno.c index 1b16fd9d9e..e197f921e1 100644 --- a/py/moduerrno.c +++ b/py/moduerrno.c @@ -82,7 +82,7 @@ STATIC const mp_obj_dict_t errorcode_dict = { #endif STATIC const mp_rom_map_elem_t mp_module_uerrno_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uerrno) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_errno) }, #if MICROPY_PY_UERRNO_ERRORCODE { MP_ROM_QSTR(MP_QSTR_errorcode), MP_ROM_PTR(&errorcode_dict) }, #endif @@ -99,7 +99,7 @@ const mp_obj_module_t mp_module_uerrno = { .globals = (mp_obj_dict_t *)&mp_module_uerrno_globals, }; -MP_REGISTER_MODULE(MP_QSTR_uerrno, mp_module_uerrno); +MP_REGISTER_MODULE(MP_QSTR_errno, mp_module_uerrno); qstr mp_errno_to_str(mp_obj_t errno_val) { #if MICROPY_PY_UERRNO_ERRORCODE From dfe232d0003b9f381643050c06c547fc3093e9e1 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 17 Aug 2022 16:21:03 +1000 Subject: [PATCH 164/565] py/builtinimport: Remove weak links. In order to keep "import umodule" working, the existing mechanism is replaced with a simple fallback to drop the "u". This makes importing of built-ins no longer touch the filesystem, which makes a typical built-in import take ~0.15ms rather than 3-5ms. (Weak links were added in c14a81662c1df812c0c6b4299f97966302f16477) This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- docs/develop/porting.rst | 3 --- ports/cc3200/mpconfigport.h | 1 - ports/nrf/mpconfigport.h | 1 - ports/samd/mpconfigport.h | 1 - ports/windows/mpconfigport.h | 1 - ports/zephyr/mpconfigport.h | 1 - py/builtinimport.c | 50 ++++-------------------------------- py/mpconfig.h | 5 ---- py/objmodule.c | 1 - 9 files changed, 5 insertions(+), 59 deletions(-) diff --git a/docs/develop/porting.rst b/docs/develop/porting.rst index fab8a751b8..63919b97a6 100644 --- a/docs/develop/porting.rst +++ b/docs/develop/porting.rst @@ -151,9 +151,6 @@ The following is an example of an ``mpconfigport.h`` file: #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) - // Enable u-modules to be imported with their standard name, like sys. - #define MICROPY_MODULE_WEAK_LINKS (1) - // Fine control over Python builtins, classes, modules, etc. #define MICROPY_PY_ASYNC_AWAIT (0) #define MICROPY_PY_BUILTINS_SET (0) diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index 6bdaa9b553..aa78005d68 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -71,7 +71,6 @@ #define MICROPY_FATFS_SYNC_T SemaphoreHandle_t #define MICROPY_STREAMS_NON_BLOCK (1) -#define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1) #define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_VFS (1) diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 23f7e560dc..3d482f4fe1 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -137,7 +137,6 @@ #define MICROPY_PY_UOS (0) #define MICROPY_STREAMS_NON_BLOCK (1) -#define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1) #define MICROPY_USE_INTERNAL_ERRNO (1) #if MICROPY_HW_USB_CDC_1200BPS_TOUCH diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 7392b03059..a0a58a2fd7 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -59,7 +59,6 @@ #define MICROPY_PY_BUILTINS_HELP_MODULES (1) #define MICROPY_ENABLE_SCHEDULER (1) #define MICROPY_SCHEDULER_STATIC_NODES (1) -#define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_HW_ENABLE_USBDEV (1) #define MICROPY_HW_USB_CDC_1200BPS_TOUCH (1) diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index fd3a76408c..5e56923d93 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -72,7 +72,6 @@ #endif #define MICROPY_STREAMS_POSIX_API (1) #define MICROPY_OPT_COMPUTED_GOTO (0) -#define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_MODULE_OVERRIDE_MAIN_IMPORT (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1) #ifndef MICROPY_ENABLE_SCHEDULER diff --git a/ports/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h index d3ef4375c7..30ccccb627 100644 --- a/ports/zephyr/mpconfigport.h +++ b/ports/zephyr/mpconfigport.h @@ -69,7 +69,6 @@ #define MICROPY_PY_MACHINE_SPI_MSB (SPI_TRANSFER_MSB) #define MICROPY_PY_MACHINE_SPI_LSB (SPI_TRANSFER_LSB) #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new -#define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_PY_STRUCT (0) #ifdef CONFIG_NETWORKING // If we have networking, we likely want errno comfort diff --git a/py/builtinimport.c b/py/builtinimport.c index 8827be6123..299877de63 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -45,15 +45,6 @@ #define DEBUG_printf(...) (void)0 #endif -#if MICROPY_MODULE_WEAK_LINKS -STATIC qstr make_weak_link_name(vstr_t *buffer, qstr name) { - vstr_reset(buffer); - vstr_add_char(buffer, 'u'); - vstr_add_str(buffer, qstr_str(name)); - return qstr_from_strn(buffer->buf, buffer->len); -} -#endif - #if MICROPY_ENABLE_EXTERNAL_IMPORT // Must be a string of one byte. @@ -391,13 +382,8 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, if (outer_module_obj == MP_OBJ_NULL) { DEBUG_printf("Searching for top-level module\n"); - // An exact match of a built-in will always bypass the filesystem. - // Note that CPython-compatible built-ins are named e.g. utime, so this - // means that an exact match is only for `import utime`, so `import - // time` will search the filesystem and failing that hit the weak - // link handling below. Whereas micropython-specific built-ins like - // `micropython`, `pyb`, `network`, etc will match exactly and cannot - // be overridden by the filesystem. + // An import of a non-extensible built-in will always bypass the + // filesystem. e.g. `import micropython` or `import pyb`. module_obj = mp_module_get_builtin(level_mod_name); if (module_obj != MP_OBJ_NULL) { return module_obj; @@ -417,20 +403,9 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, // relative to all the locations in sys.path. stat = stat_top_level(level_mod_name, &path); - #if MICROPY_MODULE_WEAK_LINKS - if (stat == MP_IMPORT_STAT_NO_EXIST) { - // No match on the filesystem. (And not a built-in either). - // If "foo" was requested, then try "ufoo" as a built-in. This - // allows `import time` to use built-in `utime`, unless `time` - // exists on the filesystem. This feature was formerly known - // as "weak links". - qstr umodule_name = make_weak_link_name(&path, level_mod_name); - module_obj = mp_module_get_builtin(umodule_name); - if (module_obj != MP_OBJ_NULL) { - return module_obj; - } - } - #endif + // TODO: If stat failed, now try extensible built-in modules. + + // TODO: If importing `ufoo`, try `foo`. } else { DEBUG_printf("Searching for sub-module\n"); @@ -667,21 +642,6 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) { return module_obj; } - #if MICROPY_MODULE_WEAK_LINKS - // Check if the u-prefixed name is a built-in. - VSTR_FIXED(umodule_path, MICROPY_ALLOC_PATH_MAX); - qstr umodule_name_qstr = make_weak_link_name(&umodule_path, module_name_qstr); - module_obj = mp_module_get_builtin(umodule_name_qstr); - if (module_obj != MP_OBJ_NULL) { - return module_obj; - } - #elif MICROPY_PY_SYS - // Special handling to make `import sys` work even if weak links aren't enabled. - if (module_name_qstr == MP_QSTR_sys) { - return MP_OBJ_FROM_PTR(&mp_module_sys); - } - #endif - // Couldn't find the module, so fail #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE mp_raise_msg(&mp_type_ImportError, MP_ERROR_TEXT("module not found")); diff --git a/py/mpconfig.h b/py/mpconfig.h index afef744ab5..9f4d88ec09 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -871,11 +871,6 @@ typedef double mp_float_t; #define MICROPY_MODULE_GETATTR (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) #endif -// Whether module weak links are supported -#ifndef MICROPY_MODULE_WEAK_LINKS -#define MICROPY_MODULE_WEAK_LINKS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) -#endif - // Whether to enable importing foo.py with __name__ set to '__main__' // Used by the unix port for the -m flag. #ifndef MICROPY_MODULE_OVERRIDE_MAIN_IMPORT diff --git a/py/objmodule.c b/py/objmodule.c index 7326fbe2d1..e63fb18a1e 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -169,7 +169,6 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { // builtin modules declared with MP_REGISTER_MODULE() MICROPY_REGISTERED_MODULES }; - MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table); // Attempts to find (and initialise) a builtin, otherwise returns From 1bf2dcb15ecf4ba37211327f4378b164a5aaf567 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 18 Aug 2022 14:47:56 +1000 Subject: [PATCH 165/565] all: Rename mp_umodule*, mp_module_umodule* to remove the "u" prefix. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- extmod/misc.h | 16 ++--- extmod/modbluetooth.c | 4 +- extmod/modubinascii.c | 4 +- extmod/moducryptolib.c | 10 +-- extmod/moduhashlib.c | 10 +-- extmod/moduheapq.c | 10 +-- extmod/modujson.c | 10 +-- extmod/moduos.c | 66 ++++++++++---------- extmod/moduplatform.c | 4 +- extmod/modurandom.c | 10 +-- extmod/modure.c | 4 +- extmod/moduselect.c | 4 +- extmod/modusocket.c | 10 +-- extmod/modussl_axtls.c | 4 +- extmod/modussl_mbedtls.c | 4 +- extmod/modutime.c | 60 +++++++++--------- extmod/modutime.h | 20 +++--- extmod/modutimeq.c | 10 +-- extmod/moduwebsocket.c | 4 +- extmod/moduzlib.c | 10 +-- extmod/uos_dupterm.c | 26 ++++---- extmod/utime_mphal.c | 0 ports/cc3200/mods/moduhashlib.c | 2 +- ports/cc3200/mods/moduos.c | 4 +- ports/cc3200/mods/modusocket.c | 10 +-- ports/cc3200/mods/modussl.c | 10 +-- ports/cc3200/mods/modutime.c | 4 +- ports/esp32/modsocket.c | 4 +- ports/esp32/moduos.c | 10 +-- ports/esp32/modutime.c | 4 +- ports/esp32/mphalport.c | 2 +- ports/esp8266/esp_mphal.c | 6 +- ports/esp8266/main.c | 2 +- ports/esp8266/moduos.c | 12 ++-- ports/esp8266/modutime.c | 4 +- ports/mimxrt/moduos.c | 10 +-- ports/mimxrt/modutime.c | 4 +- ports/mimxrt/mphalport.c | 6 +- ports/nrf/modules/uos/moduos.c | 4 +- ports/renesas-ra/moduos.c | 4 +- ports/renesas-ra/modutime.c | 4 +- ports/renesas-ra/mphalport.c | 6 +- ports/rp2/moduos.c | 4 +- ports/rp2/modutime.c | 4 +- ports/rp2/mphalport.c | 6 +- ports/samd/moduos.c | 12 ++-- ports/samd/modutime.c | 4 +- ports/samd/mphalport.c | 6 +- ports/stm32/modpyb.c | 10 +-- ports/stm32/moduos.c | 8 +-- ports/stm32/modutime.c | 4 +- ports/stm32/mphalport.c | 6 +- ports/stm32/portmodules.h | 4 +- ports/unix/main.c | 2 +- ports/unix/moduos.c | 24 +++---- ports/unix/moduselect.c | 4 +- ports/unix/modutime.c | 4 +- ports/unix/mpconfigport.h | 2 +- ports/unix/unix_mphal.c | 2 +- ports/unix/variants/mpconfigvariant_common.h | 2 +- ports/zephyr/modusocket.c | 10 +-- ports/zephyr/modutime.c | 2 +- py/builtin.h | 2 +- py/modarray.c | 4 +- py/modstruct.c | 4 +- py/moduerrno.c | 16 ++--- py/parse.c | 2 +- 67 files changed, 280 insertions(+), 280 deletions(-) create mode 100644 extmod/utime_mphal.c diff --git a/extmod/misc.h b/extmod/misc.h index a9392aa10b..80e5b59a08 100644 --- a/extmod/misc.h +++ b/extmod/misc.h @@ -32,17 +32,17 @@ #include #include "py/runtime.h" -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_dupterm_obj); #if MICROPY_PY_OS_DUPTERM -bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream); -void mp_uos_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached); -uintptr_t mp_uos_dupterm_poll(uintptr_t poll_flags); -int mp_uos_dupterm_rx_chr(void); -void mp_uos_dupterm_tx_strn(const char *str, size_t len); -void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc); +bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream); +void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached); +uintptr_t mp_os_dupterm_poll(uintptr_t poll_flags); +int mp_os_dupterm_rx_chr(void); +void mp_os_dupterm_tx_strn(const char *str, size_t len); +void mp_os_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc); #else -#define mp_uos_dupterm_tx_strn(s, l) +#define mp_os_dupterm_tx_strn(s, l) #endif #endif // MICROPY_INCLUDED_EXTMOD_MISC_H diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 35ba745e31..628c643a58 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -999,12 +999,12 @@ STATIC const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_bluetooth_globals, mp_module_bluetooth_globals_table); -const mp_obj_module_t mp_module_ubluetooth = { +const mp_obj_module_t mp_module_bluetooth = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_bluetooth_globals, }; -MP_REGISTER_MODULE(MP_QSTR_bluetooth, mp_module_ubluetooth); +MP_REGISTER_MODULE(MP_QSTR_bluetooth, mp_module_bluetooth); // Helpers diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c index 85205bc3d1..bfb8195d91 100644 --- a/extmod/modubinascii.c +++ b/extmod/modubinascii.c @@ -198,11 +198,11 @@ STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table); -const mp_obj_module_t mp_module_ubinascii = { +const mp_obj_module_t mp_module_binascii = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_binascii_globals, }; -MP_REGISTER_MODULE(MP_QSTR_binascii, mp_module_ubinascii); +MP_REGISTER_MODULE(MP_QSTR_binascii, mp_module_binascii); #endif // MICROPY_PY_UBINASCII diff --git a/extmod/moducryptolib.c b/extmod/moducryptolib.c index 730ae4c6f5..e727f50548 100644 --- a/extmod/moducryptolib.c +++ b/extmod/moducryptolib.c @@ -356,7 +356,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &ucryptolib_aes_locals_dict ); -STATIC const mp_rom_map_elem_t mp_module_ucryptolib_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_cryptolib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cryptolib) }, { MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&ucryptolib_aes_type) }, #if MICROPY_PY_UCRYPTOLIB_CONSTS @@ -368,13 +368,13 @@ STATIC const mp_rom_map_elem_t mp_module_ucryptolib_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ucryptolib_globals, mp_module_ucryptolib_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_cryptolib_globals, mp_module_cryptolib_globals_table); -const mp_obj_module_t mp_module_ucryptolib = { +const mp_obj_module_t mp_module_cryptolib = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_ucryptolib_globals, + .globals = (mp_obj_dict_t *)&mp_module_cryptolib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_cryptolib, mp_module_ucryptolib); +MP_REGISTER_MODULE(MP_QSTR_cryptolib, mp_module_cryptolib); #endif // MICROPY_PY_UCRYPTOLIB diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index addf094765..ef1a29fc78 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -354,7 +354,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif // MICROPY_PY_UHASHLIB_MD5 -STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) }, #if MICROPY_PY_UHASHLIB_SHA256 { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&uhashlib_sha256_type) }, @@ -367,13 +367,13 @@ STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_uhashlib_globals, mp_module_uhashlib_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table); -const mp_obj_module_t mp_module_uhashlib = { +const mp_obj_module_t mp_module_hashlib = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_uhashlib_globals, + .globals = (mp_obj_dict_t *)&mp_module_hashlib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_hashlib, mp_module_uhashlib); +MP_REGISTER_MODULE(MP_QSTR_hashlib, mp_module_hashlib); #endif // MICROPY_PY_UHASHLIB diff --git a/extmod/moduheapq.c b/extmod/moduheapq.c index 9c3df65258..fb6cb81182 100644 --- a/extmod/moduheapq.c +++ b/extmod/moduheapq.c @@ -104,21 +104,21 @@ STATIC mp_obj_t mod_uheapq_heapify(mp_obj_t heap_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_uheapq_heapify_obj, mod_uheapq_heapify); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_uheapq_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_heapq_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_heapq) }, { MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_uheapq_heappush_obj) }, { MP_ROM_QSTR(MP_QSTR_heappop), MP_ROM_PTR(&mod_uheapq_heappop_obj) }, { MP_ROM_QSTR(MP_QSTR_heapify), MP_ROM_PTR(&mod_uheapq_heapify_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_uheapq_globals, mp_module_uheapq_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_heapq_globals, mp_module_heapq_globals_table); -const mp_obj_module_t mp_module_uheapq = { +const mp_obj_module_t mp_module_heapq = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_uheapq_globals, + .globals = (mp_obj_dict_t *)&mp_module_heapq_globals, }; -MP_REGISTER_MODULE(MP_QSTR_heapq, mp_module_uheapq); +MP_REGISTER_MODULE(MP_QSTR_heapq, mp_module_heapq); #endif #endif // MICROPY_PY_UHEAPQ diff --git a/extmod/modujson.c b/extmod/modujson.c index 106595aab6..44dd316b69 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -366,7 +366,7 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_loads_obj, mod_ujson_loads); -STATIC const mp_rom_map_elem_t mp_module_ujson_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) }, { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_ujson_dump_obj) }, { MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_ujson_dumps_obj) }, @@ -374,13 +374,13 @@ STATIC const mp_rom_map_elem_t mp_module_ujson_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_loads), MP_ROM_PTR(&mod_ujson_loads_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ujson_globals, mp_module_ujson_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table); -const mp_obj_module_t mp_module_ujson = { +const mp_obj_module_t mp_module_json = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_ujson_globals, + .globals = (mp_obj_dict_t *)&mp_module_json_globals, }; -MP_REGISTER_MODULE(MP_QSTR_json, mp_module_ujson); +MP_REGISTER_MODULE(MP_QSTR_json, mp_module_json); #endif // MICROPY_PY_UJSON diff --git a/extmod/moduos.c b/extmod/moduos.c index a7d15ef966..8c40f45370 100644 --- a/extmod/moduos.c +++ b/extmod/moduos.c @@ -65,7 +65,7 @@ #if MICROPY_PY_UOS_SYNC // sync() // Sync all filesystems. -STATIC mp_obj_t mp_uos_sync(void) { +STATIC mp_obj_t mp_os_sync(void) { #if MICROPY_VFS_FAT for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { // this assumes that vfs->obj is fs_user_mount_t with block device functions @@ -74,7 +74,7 @@ STATIC mp_obj_t mp_uos_sync(void) { #endif return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_sync_obj, mp_uos_sync); +MP_DEFINE_CONST_FUN_OBJ_0(mp_os_sync_obj, mp_os_sync); #endif #if MICROPY_PY_UOS_UNAME @@ -85,39 +85,39 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_sync_obj, mp_uos_sync); #define CONST_RELEASE const #endif -STATIC const qstr mp_uos_uname_info_fields[] = { +STATIC const qstr mp_os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM); -STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM); -STATIC CONST_RELEASE MP_DEFINE_STR_OBJ(mp_uos_uname_info_release_obj, MICROPY_VERSION_STRING); -STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN); -STATIC const MP_DEFINE_STR_OBJ(mp_uos_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); +STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM); +STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM); +STATIC CONST_RELEASE MP_DEFINE_STR_OBJ(mp_os_uname_info_release_obj, MICROPY_VERSION_STRING); +STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN); +STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); STATIC MP_DEFINE_ATTRTUPLE( - mp_uos_uname_info_obj, - mp_uos_uname_info_fields, + mp_os_uname_info_obj, + mp_os_uname_info_fields, 5, - MP_ROM_PTR(&mp_uos_uname_info_sysname_obj), - MP_ROM_PTR(&mp_uos_uname_info_nodename_obj), - MP_ROM_PTR(&mp_uos_uname_info_release_obj), - MP_ROM_PTR(&mp_uos_uname_info_version_obj), - MP_ROM_PTR(&mp_uos_uname_info_machine_obj) + MP_ROM_PTR(&mp_os_uname_info_sysname_obj), + MP_ROM_PTR(&mp_os_uname_info_nodename_obj), + MP_ROM_PTR(&mp_os_uname_info_release_obj), + MP_ROM_PTR(&mp_os_uname_info_version_obj), + MP_ROM_PTR(&mp_os_uname_info_machine_obj) ); -STATIC mp_obj_t mp_uos_uname(void) { +STATIC mp_obj_t mp_os_uname(void) { #if MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC - const char *release = mp_uos_uname_release(); - mp_uos_uname_info_release_obj.len = strlen(release); - mp_uos_uname_info_release_obj.data = (const byte *)release; + const char *release = mp_os_uname_release(); + mp_os_uname_info_release_obj.len = strlen(release); + mp_os_uname_info_release_obj.data = (const byte *)release; #endif - return MP_OBJ_FROM_PTR(&mp_uos_uname_info_obj); + return MP_OBJ_FROM_PTR(&mp_os_uname_info_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_uname_obj, mp_uos_uname); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_os_uname_obj, mp_os_uname); #endif @@ -125,24 +125,24 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, #if MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV - { MP_ROM_QSTR(MP_QSTR_getenv), MP_ROM_PTR(&mp_uos_getenv_obj) }, - { MP_ROM_QSTR(MP_QSTR_putenv), MP_ROM_PTR(&mp_uos_putenv_obj) }, - { MP_ROM_QSTR(MP_QSTR_unsetenv), MP_ROM_PTR(&mp_uos_unsetenv_obj) }, + { MP_ROM_QSTR(MP_QSTR_getenv), MP_ROM_PTR(&mp_os_getenv_obj) }, + { MP_ROM_QSTR(MP_QSTR_putenv), MP_ROM_PTR(&mp_os_putenv_obj) }, + { MP_ROM_QSTR(MP_QSTR_unsetenv), MP_ROM_PTR(&mp_os_unsetenv_obj) }, #endif #if MICROPY_PY_UOS_SEP { MP_ROM_QSTR(MP_QSTR_sep), MP_ROM_QSTR(MP_QSTR__slash_) }, #endif #if MICROPY_PY_UOS_SYNC - { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mp_uos_sync_obj) }, + { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mp_os_sync_obj) }, #endif #if MICROPY_PY_UOS_SYSTEM - { MP_ROM_QSTR(MP_QSTR_system), MP_ROM_PTR(&mp_uos_system_obj) }, + { MP_ROM_QSTR(MP_QSTR_system), MP_ROM_PTR(&mp_os_system_obj) }, #endif #if MICROPY_PY_UOS_UNAME - { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&mp_uos_uname_obj) }, + { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&mp_os_uname_obj) }, #endif #if MICROPY_PY_OS_URANDOM - { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&mp_uos_urandom_obj) }, + { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&mp_os_urandom_obj) }, #endif #if MICROPY_VFS @@ -161,13 +161,13 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { // The following are MicroPython extensions. #if MICROPY_PY_OS_DUPTERM - { MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_uos_dupterm_obj) }, + { MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_os_dupterm_obj) }, #endif #if MICROPY_PY_UOS_DUPTERM_NOTIFY - { MP_ROM_QSTR(MP_QSTR_dupterm_notify), MP_ROM_PTR(&mp_uos_dupterm_notify_obj) }, + { MP_ROM_QSTR(MP_QSTR_dupterm_notify), MP_ROM_PTR(&mp_os_dupterm_notify_obj) }, #endif #if MICROPY_PY_UOS_ERRNO - { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_uos_errno_obj) }, + { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_os_errno_obj) }, #endif #if MICROPY_VFS @@ -190,11 +190,11 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { }; STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); -const mp_obj_module_t mp_module_uos = { +const mp_obj_module_t mp_module_os = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_uos); +MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); #endif // MICROPY_PY_UOS diff --git a/extmod/moduplatform.c b/extmod/moduplatform.c index 079e275362..791ae8344d 100644 --- a/extmod/moduplatform.c +++ b/extmod/moduplatform.c @@ -70,11 +70,11 @@ STATIC const mp_rom_map_elem_t modplatform_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(modplatform_globals, modplatform_globals_table); -const mp_obj_module_t mp_module_uplatform = { +const mp_obj_module_t mp_module_platform = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&modplatform_globals, }; -MP_REGISTER_MODULE(MP_QSTR_platform, mp_module_uplatform); +MP_REGISTER_MODULE(MP_QSTR_platform, mp_module_platform); #endif // MICROPY_PY_UPLATFORM diff --git a/extmod/modurandom.c b/extmod/modurandom.c index 6b59c0ae39..86e3a872c5 100644 --- a/extmod/modurandom.c +++ b/extmod/modurandom.c @@ -230,7 +230,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom___init___obj, mod_urandom___init__) #endif #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_urandom_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_random) }, #if SEED_ON_IMPORT { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_urandom___init___obj) }, @@ -248,14 +248,14 @@ STATIC const mp_rom_map_elem_t mp_module_urandom_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_urandom_globals, mp_module_urandom_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_random_globals, mp_module_random_globals_table); -const mp_obj_module_t mp_module_urandom = { +const mp_obj_module_t mp_module_random = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_urandom_globals, + .globals = (mp_obj_dict_t *)&mp_module_random_globals, }; -MP_REGISTER_MODULE(MP_QSTR_random, mp_module_urandom); +MP_REGISTER_MODULE(MP_QSTR_random, mp_module_random); #endif #endif // MICROPY_PY_URANDOM diff --git a/extmod/modure.c b/extmod/modure.c index c27125bf1c..4798f07b0b 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -465,12 +465,12 @@ STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table); -const mp_obj_module_t mp_module_ure = { +const mp_obj_module_t mp_module_re = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_re_globals, }; -MP_REGISTER_MODULE(MP_QSTR_re, mp_module_ure); +MP_REGISTER_MODULE(MP_QSTR_re, mp_module_re); #endif // Source files #include'd here to make sure they're compiled in diff --git a/extmod/moduselect.c b/extmod/moduselect.c index 4df0f4d561..5bb5f4f48d 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -368,11 +368,11 @@ STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table); -const mp_obj_module_t mp_module_uselect = { +const mp_obj_module_t mp_module_select = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; -MP_REGISTER_MODULE(MP_QSTR_select, mp_module_uselect); +MP_REGISTER_MODULE(MP_QSTR_select, mp_module_select); #endif // MICROPY_PY_USELECT diff --git a/extmod/modusocket.c b/extmod/modusocket.c index 6d14ebdfb0..6c2b4ff06f 100644 --- a/extmod/modusocket.c +++ b/extmod/modusocket.c @@ -615,7 +615,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_usocket_getaddrinfo_obj, 2, 6, mod_usocket_getaddrinfo); -STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, @@ -646,13 +646,13 @@ STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { */ }; -STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); -const mp_obj_module_t mp_module_usocket = { +const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_usocket_globals, + .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_usocket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c index 393a945fac..6e490a594a 100644 --- a/extmod/modussl_axtls.c +++ b/extmod/modussl_axtls.c @@ -352,11 +352,11 @@ STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table); -const mp_obj_module_t mp_module_ussl = { +const mp_obj_module_t mp_module_ssl = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ussl); +MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); #endif // MICROPY_PY_USSL && MICROPY_SSL_AXTLS diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index c12c943d8a..117a06b6b2 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -502,11 +502,11 @@ STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table); -const mp_obj_module_t mp_module_ussl = { +const mp_obj_module_t mp_module_ssl = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ussl); +MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); #endif // MICROPY_PY_USSL && MICROPY_SSL_MBEDTLS diff --git a/extmod/modutime.c b/extmod/modutime.c index 5d8148f98a..9731f5ff0b 100644 --- a/extmod/modutime.c +++ b/extmod/modutime.c @@ -55,7 +55,7 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { if (n_args == 0 || args[0] == mp_const_none) { // Get current date and time. - return mp_utime_localtime_get(); + return mp_time_localtime_get(); } else { // Convert given seconds to tuple. mp_int_t seconds = mp_obj_get_int(args[0]); @@ -74,7 +74,7 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { return mp_obj_new_tuple(8, tuple); } } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_utime_localtime_obj, 0, 1, time_localtime); +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_time_localtime_obj, 0, 1, time_localtime); // mktime() // This is the inverse function of localtime. Its argument is a full 8-tuple @@ -94,7 +94,7 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) { mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); } -MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_mktime_obj, time_mktime); +MP_DEFINE_CONST_FUN_OBJ_1(mp_time_mktime_obj, time_mktime); #endif // MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME @@ -103,22 +103,22 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_mktime_obj, time_mktime); // time() // Return the number of seconds since the Epoch. STATIC mp_obj_t time_time(void) { - return mp_utime_time_get(); + return mp_time_time_get(); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_time_obj, time_time); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_obj, time_time); // time_ns() // Returns the number of nanoseconds since the Epoch, as an integer. STATIC mp_obj_t time_time_ns(void) { return mp_obj_new_int_from_ull(mp_hal_time_ns()); } -MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_time_ns_obj, time_time_ns); +MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_ns_obj, time_time_ns); #endif // MICROPY_PY_UTIME_TIME_TIME_NS STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { #ifdef MICROPY_PY_UTIME_CUSTOM_SLEEP - mp_utime_sleep(seconds_o); + mp_time_sleep(seconds_o); #else #if MICROPY_PY_BUILTINS_FLOAT mp_hal_delay_ms((mp_uint_t)(1000 * mp_obj_get_float(seconds_o))); @@ -128,7 +128,7 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { #endif return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep); +MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_obj, time_sleep); STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { mp_int_t ms = mp_obj_get_int(arg); @@ -137,7 +137,7 @@ STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj, time_sleep_ms); +MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_ms_obj, time_sleep_ms); STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { mp_int_t us = mp_obj_get_int(arg); @@ -146,22 +146,22 @@ STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_us_obj, time_sleep_us); +MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_us_obj, time_sleep_us); STATIC mp_obj_t time_ticks_ms(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); } -MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_ms_obj, time_ticks_ms); +MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_ms_obj, time_ticks_ms); STATIC mp_obj_t time_ticks_us(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); } -MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj, time_ticks_us); +MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_us_obj, time_ticks_us); STATIC mp_obj_t time_ticks_cpu(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); } -MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj, time_ticks_cpu); +MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_cpu_obj, time_ticks_cpu); STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { // we assume that the arguments come from ticks_xx so are small ints @@ -173,7 +173,7 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { - MICROPY_PY_UTIME_TICKS_PERIOD / 2; return MP_OBJ_NEW_SMALL_INT(diff); } -MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj, time_ticks_diff); +MP_DEFINE_CONST_FUN_OBJ_2(mp_time_ticks_diff_obj, time_ticks_diff); STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { // we assume that first argument come from ticks_xx so is small int @@ -194,31 +194,31 @@ STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { return MP_OBJ_NEW_SMALL_INT((ticks + delta) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); } -MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj, time_ticks_add); +MP_DEFINE_CONST_FUN_OBJ_2(mp_time_ticks_add_obj, time_ticks_add); STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time) }, #if MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME - { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mp_utime_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mp_utime_localtime_obj) }, - { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_utime_mktime_obj) }, + { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mp_time_localtime_obj) }, + { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mp_time_localtime_obj) }, + { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_time_mktime_obj) }, #endif #if MICROPY_PY_UTIME_TIME_TIME_NS - { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_utime_time_obj) }, - { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) }, + { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_time_time_obj) }, + { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_time_time_ns_obj) }, #endif - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, + { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_time_sleep_obj) }, + { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_time_sleep_ms_obj) }, + { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_time_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, - { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_time_ticks_ms_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_time_ticks_us_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_time_ticks_cpu_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_time_ticks_add_obj) }, + { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_time_ticks_diff_obj) }, #ifdef MICROPY_PY_UTIME_EXTRA_GLOBALS MICROPY_PY_UTIME_EXTRA_GLOBALS @@ -226,11 +226,11 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { }; STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); -const mp_obj_module_t mp_module_utime = { +const mp_obj_module_t mp_module_time = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_time_globals, }; -MP_REGISTER_MODULE(MP_QSTR_time, mp_module_utime); +MP_REGISTER_MODULE(MP_QSTR_time, mp_module_time); #endif // MICROPY_PY_UTIME diff --git a/extmod/modutime.h b/extmod/modutime.h index 2e10afb89b..f5ea6b55bf 100644 --- a/extmod/modutime.h +++ b/extmod/modutime.h @@ -29,15 +29,15 @@ #include "py/obj.h" -MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_mktime_obj); -MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_obj); -MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj); -MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_us_obj); -MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_ms_obj); -MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj); -MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj); -MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj); -MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj); -MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_time_ns_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_time_mktime_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_time_sleep_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_time_sleep_ms_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_time_sleep_us_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_time_ticks_ms_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_time_ticks_us_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_time_ticks_cpu_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_time_ticks_diff_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_time_ticks_add_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_time_time_ns_obj); #endif // MICROPY_INCLUDED_EXTMOD_MODUTIME_H diff --git a/extmod/modutimeq.c b/extmod/modutimeq.c index 4aa572934f..8187fa2b23 100644 --- a/extmod/modutimeq.c +++ b/extmod/modutimeq.c @@ -218,18 +218,18 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &utimeq_locals_dict ); -STATIC const mp_rom_map_elem_t mp_module_utimeq_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_timeq_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_timeq) }, { MP_ROM_QSTR(MP_QSTR_timeq), MP_ROM_PTR(&utimeq_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_utimeq_globals, mp_module_utimeq_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_timeq_globals, mp_module_timeq_globals_table); -const mp_obj_module_t mp_module_utimeq = { +const mp_obj_module_t mp_module_timeq = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_utimeq_globals, + .globals = (mp_obj_dict_t *)&mp_module_timeq_globals, }; -MP_REGISTER_MODULE(MP_QSTR_timeq, mp_module_utimeq); +MP_REGISTER_MODULE(MP_QSTR_timeq, mp_module_timeq); #endif // MICROPY_PY_UTIMEQ diff --git a/extmod/moduwebsocket.c b/extmod/moduwebsocket.c index ca7152bb13..301f72fba0 100644 --- a/extmod/moduwebsocket.c +++ b/extmod/moduwebsocket.c @@ -306,11 +306,11 @@ STATIC const mp_rom_map_elem_t uwebsocket_module_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(uwebsocket_module_globals, uwebsocket_module_globals_table); -const mp_obj_module_t mp_module_uwebsocket = { +const mp_obj_module_t mp_module_websocket = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&uwebsocket_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_websocket, mp_module_uwebsocket); +MP_REGISTER_MODULE(MP_QSTR_websocket, mp_module_websocket); #endif // MICROPY_PY_UWEBSOCKET diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index f41ca2b012..504c637c3c 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -210,21 +210,21 @@ error: STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_uzlib_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_zlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zlib) }, { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_uzlib_decompress_obj) }, { MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_uzlib_globals, mp_module_uzlib_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_zlib_globals, mp_module_zlib_globals_table); -const mp_obj_module_t mp_module_uzlib = { +const mp_obj_module_t mp_module_zlib = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_uzlib_globals, + .globals = (mp_obj_dict_t *)&mp_module_zlib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_zlib, mp_module_uzlib); +MP_REGISTER_MODULE(MP_QSTR_zlib, mp_module_zlib); #endif // Source files #include'd here to make sure they're compiled in diff --git a/extmod/uos_dupterm.c b/extmod/uos_dupterm.c index 981d05a638..c72b365bea 100644 --- a/extmod/uos_dupterm.c +++ b/extmod/uos_dupterm.c @@ -38,7 +38,7 @@ #include "shared/runtime/interrupt_char.h" -void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) { +void mp_os_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) { mp_obj_t term = MP_STATE_VM(dupterm_objs[dupterm_idx]); MP_STATE_VM(dupterm_objs[dupterm_idx]) = MP_OBJ_NULL; mp_printf(&mp_plat_print, msg); @@ -54,7 +54,7 @@ void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) { } } -uintptr_t mp_uos_dupterm_poll(uintptr_t poll_flags) { +uintptr_t mp_os_dupterm_poll(uintptr_t poll_flags) { uintptr_t poll_flags_out = 0; for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) { @@ -67,7 +67,7 @@ uintptr_t mp_uos_dupterm_poll(uintptr_t poll_flags) { mp_uint_t ret = 0; const mp_stream_p_t *stream_p = mp_get_stream(s); #if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM - if (mp_uos_dupterm_is_builtin_stream(s)) { + if (mp_os_dupterm_is_builtin_stream(s)) { ret = stream_p->ioctl(s, MP_STREAM_POLL, poll_flags, &errcode); } else #endif @@ -93,14 +93,14 @@ uintptr_t mp_uos_dupterm_poll(uintptr_t poll_flags) { return poll_flags_out; } -int mp_uos_dupterm_rx_chr(void) { +int mp_os_dupterm_rx_chr(void) { for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) { if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) { continue; } #if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM - if (mp_uos_dupterm_is_builtin_stream(MP_STATE_VM(dupterm_objs[idx]))) { + if (mp_os_dupterm_is_builtin_stream(MP_STATE_VM(dupterm_objs[idx]))) { byte buf[1]; int errcode = 0; const mp_stream_p_t *stream_p = mp_get_stream(MP_STATE_VM(dupterm_objs[idx])); @@ -121,7 +121,7 @@ int mp_uos_dupterm_rx_chr(void) { mp_uint_t out_sz = stream_p->read(MP_STATE_VM(dupterm_objs[idx]), buf, 1, &errcode); if (out_sz == 0) { nlr_pop(); - mp_uos_deactivate(idx, "dupterm: EOF received, deactivating\n", MP_OBJ_NULL); + mp_os_deactivate(idx, "dupterm: EOF received, deactivating\n", MP_OBJ_NULL); } else if (out_sz == MP_STREAM_ERROR) { // errcode is valid if (mp_is_nonblocking_error(errcode)) { @@ -140,7 +140,7 @@ int mp_uos_dupterm_rx_chr(void) { return buf[0]; } } else { - mp_uos_deactivate(idx, "dupterm: Exception in read() method, deactivating: ", MP_OBJ_FROM_PTR(nlr.ret_val)); + mp_os_deactivate(idx, "dupterm: Exception in read() method, deactivating: ", MP_OBJ_FROM_PTR(nlr.ret_val)); } } @@ -148,14 +148,14 @@ int mp_uos_dupterm_rx_chr(void) { return -1; } -void mp_uos_dupterm_tx_strn(const char *str, size_t len) { +void mp_os_dupterm_tx_strn(const char *str, size_t len) { for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) { if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) { continue; } #if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM - if (mp_uos_dupterm_is_builtin_stream(MP_STATE_VM(dupterm_objs[idx]))) { + if (mp_os_dupterm_is_builtin_stream(MP_STATE_VM(dupterm_objs[idx]))) { int errcode = 0; const mp_stream_p_t *stream_p = mp_get_stream(MP_STATE_VM(dupterm_objs[idx])); stream_p->write(MP_STATE_VM(dupterm_objs[idx]), str, len, &errcode); @@ -168,12 +168,12 @@ void mp_uos_dupterm_tx_strn(const char *str, size_t len) { mp_stream_write(MP_STATE_VM(dupterm_objs[idx]), str, len, MP_STREAM_RW_WRITE); nlr_pop(); } else { - mp_uos_deactivate(idx, "dupterm: Exception in write() method, deactivating: ", MP_OBJ_FROM_PTR(nlr.ret_val)); + mp_os_deactivate(idx, "dupterm: Exception in write() method, deactivating: ", MP_OBJ_FROM_PTR(nlr.ret_val)); } } } -STATIC mp_obj_t mp_uos_dupterm(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t mp_os_dupterm(size_t n_args, const mp_obj_t *args) { mp_int_t idx = 0; if (n_args == 2) { idx = mp_obj_get_int(args[1]); @@ -195,12 +195,12 @@ STATIC mp_obj_t mp_uos_dupterm(size_t n_args, const mp_obj_t *args) { } #if MICROPY_PY_UOS_DUPTERM_STREAM_DETACHED_ATTACHED - mp_uos_dupterm_stream_detached_attached(previous_obj, args[0]); + mp_os_dupterm_stream_detached_attached(previous_obj, args[0]); #endif return previous_obj; } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj, 1, 2, mp_uos_dupterm); +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_dupterm_obj, 1, 2, mp_os_dupterm); MP_REGISTER_ROOT_POINTER(mp_obj_t dupterm_objs[MICROPY_PY_OS_DUPTERM]); diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/cc3200/mods/moduhashlib.c b/ports/cc3200/mods/moduhashlib.c index 5424a6c0fb..de56e114af 100644 --- a/ports/cc3200/mods/moduhashlib.c +++ b/ports/cc3200/mods/moduhashlib.c @@ -202,7 +202,7 @@ STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table); -const mp_obj_module_t mp_module_uhashlib = { +const mp_obj_module_t mp_module_hashlib = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&mp_module_hashlib_globals, }; diff --git a/ports/cc3200/mods/moduos.c b/ports/cc3200/mods/moduos.c index b3f3bbf8d8..a6e4ef50a7 100644 --- a/ports/cc3200/mods/moduos.c +++ b/ports/cc3200/mods/moduos.c @@ -175,9 +175,9 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); -const mp_obj_module_t mp_module_uos = { +const mp_obj_module_t mp_module_os = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_uos); +MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); diff --git a/ports/cc3200/mods/modusocket.c b/ports/cc3200/mods/modusocket.c index 311a4395fb..53682743a9 100644 --- a/ports/cc3200/mods/modusocket.c +++ b/ports/cc3200/mods/modusocket.c @@ -794,7 +794,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_usocket_getaddrinfo_obj, mod_usocket_getaddrinfo); -STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, @@ -811,11 +811,11 @@ STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_IPPROTO_UDP), MP_ROM_INT(SL_IPPROTO_UDP) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); -const mp_obj_module_t mp_module_usocket = { +const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&mp_module_usocket_globals, + .globals = (mp_obj_dict_t*)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_usocket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); diff --git a/ports/cc3200/mods/modussl.c b/ports/cc3200/mods/modussl.c index e2de7b05cb..dda6725e66 100644 --- a/ports/cc3200/mods/modussl.c +++ b/ports/cc3200/mods/modussl.c @@ -135,7 +135,7 @@ arg_error: } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket); -STATIC const mp_rom_map_elem_t mp_module_ussl_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssl) }, { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) }, @@ -153,11 +153,11 @@ STATIC const mp_rom_map_elem_t mp_module_ussl_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLSv1_2), MP_ROM_INT(SL_SO_SEC_METHOD_TLSV1_2) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ussl_globals, mp_module_ussl_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table); -const mp_obj_module_t mp_module_ussl = { +const mp_obj_module_t mp_module_ssl = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&mp_module_ussl_globals, + .globals = (mp_obj_dict_t*)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ussl); +MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); diff --git a/ports/cc3200/mods/modutime.c b/ports/cc3200/mods/modutime.c index 52eb1a6029..6fa98296d2 100644 --- a/ports/cc3200/mods/modutime.c +++ b/ports/cc3200/mods/modutime.c @@ -30,7 +30,7 @@ #include "pybrtc.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_utime_localtime_get(void) { +STATIC mp_obj_t mp_time_localtime_get(void) { timeutils_struct_time_t tm; // get the seconds from the RTC @@ -49,6 +49,6 @@ STATIC mp_obj_t mp_utime_localtime_get(void) { } // Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { return mp_obj_new_int(pyb_rtc_get_seconds()); } diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 5e07d1f4f5..8199304457 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -864,7 +864,7 @@ STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); -const mp_obj_module_t mp_module_usocket = { +const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; @@ -872,4 +872,4 @@ const mp_obj_module_t mp_module_usocket = { // Note: This port doesn't define MICROPY_PY_USOCKET or MICROPY_PY_LWIP so // this will not conflict with the common implementation provided by // extmod/mod{lwip,usocket}.c. -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_usocket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); diff --git a/ports/esp32/moduos.c b/ports/esp32/moduos.c index bdfd19c5d2..6a5a26c256 100644 --- a/ports/esp32/moduos.c +++ b/ports/esp32/moduos.c @@ -33,7 +33,7 @@ #include "py/mphal.h" #include "extmod/misc.h" -STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { +STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -47,13 +47,13 @@ STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_urandom_obj, mp_uos_urandom); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #if MICROPY_PY_UOS_DUPTERM_NOTIFY -STATIC mp_obj_t mp_uos_dupterm_notify(mp_obj_t obj_in) { +STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; for (;;) { - int c = mp_uos_dupterm_rx_chr(); + int c = mp_os_dupterm_rx_chr(); if (c < 0) { break; } @@ -61,5 +61,5 @@ STATIC mp_obj_t mp_uos_dupterm_notify(mp_obj_t obj_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_dupterm_notify_obj, mp_uos_dupterm_notify); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify); #endif diff --git a/ports/esp32/modutime.c b/ports/esp32/modutime.c index 7b833a194d..7a2b215086 100644 --- a/ports/esp32/modutime.c +++ b/ports/esp32/modutime.c @@ -32,7 +32,7 @@ #include "shared/timeutils/timeutils.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_utime_localtime_get(void) { +STATIC mp_obj_t mp_time_localtime_get(void) { struct timeval tv; gettimeofday(&tv, NULL); timeutils_struct_time_t tm; @@ -51,7 +51,7 @@ STATIC mp_obj_t mp_utime_localtime_get(void) { } // Return the number of seconds since the Epoch. -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { struct timeval tv; gettimeofday(&tv, NULL); return mp_obj_new_int(tv.tv_sec); diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c index b187b422d5..61e9fd563e 100644 --- a/ports/esp32/mphalport.c +++ b/ports/esp32/mphalport.c @@ -121,7 +121,7 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) { if (release_gil) { MP_THREAD_GIL_ENTER(); } - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); } uint32_t mp_hal_ticks_ms(void) { diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c index 219e614841..7606bd4f63 100644 --- a/ports/esp8266/esp_mphal.c +++ b/ports/esp8266/esp_mphal.c @@ -63,7 +63,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { ret |= MP_STREAM_POLL_RD; } if (poll_flags & MP_STREAM_POLL_WR) { - ret |= mp_uos_dupterm_poll(poll_flags); + ret |= mp_os_dupterm_poll(poll_flags); } return ret; } @@ -95,7 +95,7 @@ void mp_hal_debug_str(const char *str) { #endif void mp_hal_stdout_tx_strn(const char *str, uint32_t len) { - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); } void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len) { @@ -146,7 +146,7 @@ STATIC void dupterm_task_handler(os_event_t *evt) { } lock = 1; while (1) { - int c = mp_uos_dupterm_rx_chr(); + int c = mp_os_dupterm_rx_chr(); if (c < 0) { break; } diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c index 2aa81aba05..3083fe364e 100644 --- a/ports/esp8266/main.c +++ b/ports/esp8266/main.c @@ -74,7 +74,7 @@ STATIC void mp_reset(void) { args[1] = MP_OBJ_NEW_SMALL_INT(115200); args[0] = MP_OBJ_TYPE_GET_SLOT(&pyb_uart_type, make_new)(&pyb_uart_type, 2, 0, args); args[1] = MP_OBJ_NEW_SMALL_INT(1); - mp_uos_dupterm_obj.fun.var(2, args); + mp_os_dupterm_obj.fun.var(2, args); } #if MICROPY_ESPNOW diff --git a/ports/esp8266/moduos.c b/ports/esp8266/moduos.c index a023796fd3..78072d4f44 100644 --- a/ports/esp8266/moduos.c +++ b/ports/esp8266/moduos.c @@ -37,11 +37,11 @@ #include "esp_mphal.h" #include "user_interface.h" -STATIC const char *mp_uos_uname_release(void) { +STATIC const char *mp_os_uname_release(void) { return system_get_sdk_version(); } -STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { +STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -50,9 +50,9 @@ STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_urandom_obj, mp_uos_urandom); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); -void mp_uos_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) { +void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) { if (mp_obj_get_type(stream_attached) == &pyb_uart_type) { ++uart_attached_to_dupterm; } @@ -61,9 +61,9 @@ void mp_uos_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t } } -STATIC mp_obj_t mp_uos_dupterm_notify(mp_obj_t obj_in) { +STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; mp_hal_signal_dupterm_input(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_dupterm_notify_obj, mp_uos_dupterm_notify); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify); diff --git a/ports/esp8266/modutime.c b/ports/esp8266/modutime.c index b90763371b..21dd3cbcd9 100644 --- a/ports/esp8266/modutime.c +++ b/ports/esp8266/modutime.c @@ -30,7 +30,7 @@ #include "modmachine.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_utime_localtime_get(void) { +STATIC mp_obj_t mp_time_localtime_get(void) { mp_int_t seconds = pyb_rtc_get_us_since_epoch() / 1000 / 1000; timeutils_struct_time_t tm; timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); @@ -48,7 +48,7 @@ STATIC mp_obj_t mp_utime_localtime_get(void) { } // Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { // get date and time return mp_obj_new_int(pyb_rtc_get_us_since_epoch() / 1000 / 1000); } diff --git a/ports/mimxrt/moduos.c b/ports/mimxrt/moduos.c index b3f97693fa..8ae8019aae 100644 --- a/ports/mimxrt/moduos.c +++ b/ports/mimxrt/moduos.c @@ -96,7 +96,7 @@ uint32_t trng_random_u32(void) { } #if MICROPY_PY_UOS_URANDOM -STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { +STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -106,14 +106,14 @@ STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_urandom_obj, mp_uos_urandom); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif #if MICROPY_PY_UOS_DUPTERM_NOTIFY -STATIC mp_obj_t mp_uos_dupterm_notify(mp_obj_t obj_in) { +STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; for (;;) { - int c = mp_uos_dupterm_rx_chr(); + int c = mp_os_dupterm_rx_chr(); if (c < 0) { break; } @@ -121,5 +121,5 @@ STATIC mp_obj_t mp_uos_dupterm_notify(mp_obj_t obj_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_dupterm_notify_obj, mp_uos_dupterm_notify); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify); #endif diff --git a/ports/mimxrt/modutime.c b/ports/mimxrt/modutime.c index 5872e9d8d6..b0c927899f 100644 --- a/ports/mimxrt/modutime.c +++ b/ports/mimxrt/modutime.c @@ -30,7 +30,7 @@ #include "fsl_snvs_lp.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_utime_localtime_get(void) { +STATIC mp_obj_t mp_time_localtime_get(void) { // Get current date and time. snvs_lp_srtc_datetime_t t; SNVS_LP_SRTC_GetDatetime(SNVS, &t); @@ -48,7 +48,7 @@ STATIC mp_obj_t mp_utime_localtime_get(void) { } // Return the number of seconds since the Epoch. -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { snvs_lp_srtc_datetime_t t; SNVS_LP_SRTC_GetDatetime(SNVS, &t); // EPOCH is 1970 for this port, which leads to the following trouble: diff --git a/ports/mimxrt/mphalport.c b/ports/mimxrt/mphalport.c index beb471ab80..2114baaae4 100644 --- a/ports/mimxrt/mphalport.c +++ b/ports/mimxrt/mphalport.c @@ -90,7 +90,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { ret |= MP_STREAM_POLL_WR; } #if MICROPY_PY_OS_DUPTERM - ret |= mp_uos_dupterm_poll(poll_flags); + ret |= mp_os_dupterm_poll(poll_flags); #endif return ret; } @@ -103,7 +103,7 @@ int mp_hal_stdin_rx_chr(void) { return c; } #if MICROPY_PY_OS_DUPTERM - int dupterm_c = mp_uos_dupterm_rx_chr(); + int dupterm_c = mp_os_dupterm_rx_chr(); if (dupterm_c >= 0) { return dupterm_c; } @@ -134,7 +134,7 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { } } #if MICROPY_PY_OS_DUPTERM - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); #endif } diff --git a/ports/nrf/modules/uos/moduos.c b/ports/nrf/modules/uos/moduos.c index bb49012707..b718150613 100644 --- a/ports/nrf/modules/uos/moduos.c +++ b/ports/nrf/modules/uos/moduos.c @@ -192,9 +192,9 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); -const mp_obj_module_t mp_module_uos = { +const mp_obj_module_t mp_module_os = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_uos); +MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); diff --git a/ports/renesas-ra/moduos.c b/ports/renesas-ra/moduos.c index 6f524f119f..e6aadd9ebc 100644 --- a/ports/renesas-ra/moduos.c +++ b/ports/renesas-ra/moduos.c @@ -28,12 +28,12 @@ #include "py/runtime.h" #include "uart.h" -bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream) { +bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) { const mp_obj_type_t *type = mp_obj_get_type(stream); return type == &machine_uart_type; } -void mp_uos_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) { +void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) { if (mp_obj_get_type(stream_detached) == &machine_uart_type) { uart_attach_to_repl(MP_OBJ_TO_PTR(stream_detached), false); } diff --git a/ports/renesas-ra/modutime.c b/ports/renesas-ra/modutime.c index 49dcfd589d..1ab51e336d 100644 --- a/ports/renesas-ra/modutime.c +++ b/ports/renesas-ra/modutime.c @@ -29,7 +29,7 @@ #include "rtc.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_utime_localtime_get(void) { +STATIC mp_obj_t mp_time_localtime_get(void) { // get current date and time rtc_init_finalise(); ra_rtc_t time; @@ -48,7 +48,7 @@ STATIC mp_obj_t mp_utime_localtime_get(void) { } // Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { // get date and time rtc_init_finalise(); ra_rtc_t time; diff --git a/ports/renesas-ra/mphalport.c b/ports/renesas-ra/mphalport.c index 6e6a83aa26..b35ab75714 100644 --- a/ports/renesas-ra/mphalport.c +++ b/ports/renesas-ra/mphalport.c @@ -54,7 +54,7 @@ MP_WEAK uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { const mp_stream_p_t *stream_p = mp_get_stream(pyb_stdio_uart); ret = stream_p->ioctl(pyb_stdio_uart, MP_STREAM_POLL, poll_flags, &errcode); } - return ret | mp_uos_dupterm_poll(poll_flags); + return ret | mp_os_dupterm_poll(poll_flags); } #if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE @@ -69,7 +69,7 @@ MP_WEAK int mp_hal_stdin_rx_chr(void) { if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) { return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart)); } - int dupterm_c = mp_uos_dupterm_rx_chr(); + int dupterm_c = mp_os_dupterm_rx_chr(); if (dupterm_c >= 0) { return dupterm_c; } @@ -81,7 +81,7 @@ MP_WEAK void mp_hal_stdout_tx_strn(const char *str, size_t len) { if (MP_STATE_PORT(pyb_stdio_uart) != NULL) { uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len); } - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); } void mp_hal_ticks_cpu_enable(void) { diff --git a/ports/rp2/moduos.c b/ports/rp2/moduos.c index 398ec28d92..77f980a731 100644 --- a/ports/rp2/moduos.c +++ b/ports/rp2/moduos.c @@ -28,7 +28,7 @@ uint8_t rosc_random_u8(size_t cycles); -STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { +STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -37,4 +37,4 @@ STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_urandom_obj, mp_uos_urandom); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); diff --git a/ports/rp2/modutime.c b/ports/rp2/modutime.c index 9859295d1a..b4120be7c3 100644 --- a/ports/rp2/modutime.c +++ b/ports/rp2/modutime.c @@ -29,7 +29,7 @@ #include "hardware/rtc.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_utime_localtime_get(void) { +STATIC mp_obj_t mp_time_localtime_get(void) { datetime_t t; rtc_get_datetime(&t); mp_obj_t tuple[8] = { @@ -46,7 +46,7 @@ STATIC mp_obj_t mp_utime_localtime_get(void) { } // Return the number of seconds since the Epoch. -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { datetime_t t; rtc_get_datetime(&t); return mp_obj_new_int_from_ull(timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec)); diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index 84a34b2a40..52d55198b7 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -109,7 +109,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { } #endif #if MICROPY_PY_OS_DUPTERM - ret |= mp_uos_dupterm_poll(poll_flags); + ret |= mp_os_dupterm_poll(poll_flags); #endif return ret; } @@ -126,7 +126,7 @@ int mp_hal_stdin_rx_chr(void) { return c; } #if MICROPY_PY_OS_DUPTERM - int dupterm_c = mp_uos_dupterm_rx_chr(); + int dupterm_c = mp_os_dupterm_rx_chr(); if (dupterm_c >= 0) { return dupterm_c; } @@ -164,7 +164,7 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { #endif #if MICROPY_PY_OS_DUPTERM - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); #endif } diff --git a/ports/samd/moduos.c b/ports/samd/moduos.c index 3404919d24..4438bf3c7b 100644 --- a/ports/samd/moduos.c +++ b/ports/samd/moduos.c @@ -70,7 +70,7 @@ uint32_t trng_random_u32(int delay) { #endif #if MICROPY_PY_UOS_URANDOM -STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { +STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -86,22 +86,22 @@ STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_urandom_obj, mp_uos_urandom); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif // MICROPY_PY_UOS_URANDOM #if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM -bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream) { +bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) { const mp_obj_type_t *type = mp_obj_get_type(stream); return type == &machine_uart_type; } #endif #if MICROPY_PY_UOS_DUPTERM_NOTIFY -STATIC mp_obj_t mp_uos_dupterm_notify(mp_obj_t obj_in) { +STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; for (;;) { - int c = mp_uos_dupterm_rx_chr(); + int c = mp_os_dupterm_rx_chr(); if (c < 0) { break; } @@ -109,5 +109,5 @@ STATIC mp_obj_t mp_uos_dupterm_notify(mp_obj_t obj_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_dupterm_notify_obj, mp_uos_dupterm_notify); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify); #endif diff --git a/ports/samd/modutime.c b/ports/samd/modutime.c index db90a22822..aa5bd33609 100644 --- a/ports/samd/modutime.c +++ b/ports/samd/modutime.c @@ -29,7 +29,7 @@ #include "modmachine.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_utime_localtime_get(void) { +STATIC mp_obj_t mp_time_localtime_get(void) { timeutils_struct_time_t tm; rtc_gettime(&tm); tm.tm_wday = timeutils_calc_weekday(tm.tm_year, tm.tm_mon, tm.tm_mday); @@ -48,7 +48,7 @@ STATIC mp_obj_t mp_utime_localtime_get(void) { } // Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { timeutils_struct_time_t tm; rtc_gettime(&tm); return mp_obj_new_int_from_uint(timeutils_mktime( diff --git a/ports/samd/mphalport.c b/ports/samd/mphalport.c index 3dc6b70a8d..dc38ea2964 100644 --- a/ports/samd/mphalport.c +++ b/ports/samd/mphalport.c @@ -167,7 +167,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { } #if MICROPY_PY_OS_DUPTERM - ret |= mp_uos_dupterm_poll(poll_flags); + ret |= mp_os_dupterm_poll(poll_flags); #endif return ret; } @@ -182,7 +182,7 @@ int mp_hal_stdin_rx_chr(void) { } #if MICROPY_PY_OS_DUPTERM - int dupterm_c = mp_uos_dupterm_rx_chr(); + int dupterm_c = mp_os_dupterm_rx_chr(); if (dupterm_c >= 0) { return dupterm_c; } @@ -212,6 +212,6 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { } } #if MICROPY_PY_OS_DUPTERM - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); #endif } diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c index b148898f16..88eafafb0a 100644 --- a/ports/stm32/modpyb.c +++ b/ports/stm32/modpyb.c @@ -178,13 +178,13 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = { #endif #if MICROPY_PY_PYB_LEGACY - { MP_ROM_QSTR(MP_QSTR_millis), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, + { MP_ROM_QSTR(MP_QSTR_millis), MP_ROM_PTR(&mp_time_ticks_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_elapsed_millis), MP_ROM_PTR(&pyb_elapsed_millis_obj) }, - { MP_ROM_QSTR(MP_QSTR_micros), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, + { MP_ROM_QSTR(MP_QSTR_micros), MP_ROM_PTR(&mp_time_ticks_us_obj) }, { MP_ROM_QSTR(MP_QSTR_elapsed_micros), MP_ROM_PTR(&pyb_elapsed_micros_obj) }, - { MP_ROM_QSTR(MP_QSTR_delay), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_udelay), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, - { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mp_uos_sync_obj) }, + { MP_ROM_QSTR(MP_QSTR_delay), MP_ROM_PTR(&mp_time_sleep_ms_obj) }, + { MP_ROM_QSTR(MP_QSTR_udelay), MP_ROM_PTR(&mp_time_sleep_us_obj) }, + { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mp_os_sync_obj) }, { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) }, #endif diff --git a/ports/stm32/moduos.c b/ports/stm32/moduos.c index 1f41e68bde..bfbb868e2f 100644 --- a/ports/stm32/moduos.c +++ b/ports/stm32/moduos.c @@ -33,7 +33,7 @@ // urandom(n) // Return a bytes object with n random bytes, generated by the hardware // random number generator. -STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { +STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -42,10 +42,10 @@ STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_urandom_obj, mp_uos_urandom); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif -bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream) { +bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) { const mp_obj_type_t *type = mp_obj_get_type(stream); return type == &pyb_uart_type #if MICROPY_HW_ENABLE_USB @@ -54,7 +54,7 @@ bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream) { ; } -void mp_uos_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) { +void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) { if (mp_obj_get_type(stream_detached) == &pyb_uart_type) { uart_attach_to_repl(MP_OBJ_TO_PTR(stream_detached), false); } diff --git a/ports/stm32/modutime.c b/ports/stm32/modutime.c index 4eda59f81e..e7160cd5b2 100644 --- a/ports/stm32/modutime.c +++ b/ports/stm32/modutime.c @@ -29,7 +29,7 @@ #include "rtc.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_utime_localtime_get(void) { +STATIC mp_obj_t mp_time_localtime_get(void) { // get current date and time // note: need to call get time then get date to correctly access the registers rtc_init_finalise(); @@ -51,7 +51,7 @@ STATIC mp_obj_t mp_utime_localtime_get(void) { } // Returns the number of seconds, as an integer, since 1/1/2000. -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { // get date and time // note: need to call get time then get date to correctly access the registers rtc_init_finalise(); diff --git a/ports/stm32/mphalport.c b/ports/stm32/mphalport.c index 092d63e1bb..727517f5bd 100644 --- a/ports/stm32/mphalport.c +++ b/ports/stm32/mphalport.c @@ -28,7 +28,7 @@ MP_WEAK uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { const mp_stream_p_t *stream_p = mp_get_stream(pyb_stdio_uart); ret = stream_p->ioctl(pyb_stdio_uart, MP_STREAM_POLL, poll_flags, &errcode); } - return ret | mp_uos_dupterm_poll(poll_flags); + return ret | mp_os_dupterm_poll(poll_flags); } MP_WEAK int mp_hal_stdin_rx_chr(void) { @@ -45,7 +45,7 @@ MP_WEAK int mp_hal_stdin_rx_chr(void) { if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) { return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart)); } - int dupterm_c = mp_uos_dupterm_rx_chr(); + int dupterm_c = mp_os_dupterm_rx_chr(); if (dupterm_c >= 0) { return dupterm_c; } @@ -60,7 +60,7 @@ MP_WEAK void mp_hal_stdout_tx_strn(const char *str, size_t len) { #if 0 && defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD lcd_print_strn(str, len); #endif - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); } #if __CORTEX_M >= 0x03 diff --git a/ports/stm32/portmodules.h b/ports/stm32/portmodules.h index f6edef3987..87f97f3170 100644 --- a/ports/stm32/portmodules.h +++ b/ports/stm32/portmodules.h @@ -28,13 +28,13 @@ extern const mp_obj_module_t pyb_module; extern const mp_obj_module_t stm_module; -extern const mp_obj_module_t mp_module_usocket; +extern const mp_obj_module_t mp_module_socket; // additional helper functions exported by the modules MP_DECLARE_CONST_FUN_OBJ_1(time_sleep_ms_obj); MP_DECLARE_CONST_FUN_OBJ_1(time_sleep_us_obj); -MP_DECLARE_CONST_FUN_OBJ_0(mp_uos_sync_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_os_sync_obj); #endif // MICROPY_INCLUDED_STM32_PORTMODULES_H diff --git a/ports/unix/main.c b/ports/unix/main.c index fc0f6da7b8..392ce59dde 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -73,7 +73,7 @@ STATIC void stderr_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t ret; MP_HAL_RETRY_SYSCALL(ret, write(STDERR_FILENO, str, len), {}); - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); } const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; diff --git a/ports/unix/moduos.c b/ports/unix/moduos.c index e44ceb677b..1d5e2afef4 100644 --- a/ports/unix/moduos.c +++ b/ports/unix/moduos.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "py/mphal.h" -STATIC mp_obj_t mp_uos_getenv(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t mp_os_getenv(size_t n_args, const mp_obj_t *args) { const char *s = getenv(mp_obj_str_get_str(args[0])); if (s == NULL) { if (n_args == 2) { @@ -42,9 +42,9 @@ STATIC mp_obj_t mp_uos_getenv(size_t n_args, const mp_obj_t *args) { } return mp_obj_new_str(s, strlen(s)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_getenv_obj, 1, 2, mp_uos_getenv); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_getenv_obj, 1, 2, mp_os_getenv); -STATIC mp_obj_t mp_uos_putenv(mp_obj_t key_in, mp_obj_t value_in) { +STATIC mp_obj_t mp_os_putenv(mp_obj_t key_in, mp_obj_t value_in) { const char *key = mp_obj_str_get_str(key_in); const char *value = mp_obj_str_get_str(value_in); int ret; @@ -60,9 +60,9 @@ STATIC mp_obj_t mp_uos_putenv(mp_obj_t key_in, mp_obj_t value_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_uos_putenv_obj, mp_uos_putenv); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_os_putenv_obj, mp_os_putenv); -STATIC mp_obj_t mp_uos_unsetenv(mp_obj_t key_in) { +STATIC mp_obj_t mp_os_unsetenv(mp_obj_t key_in) { const char *key = mp_obj_str_get_str(key_in); int ret; @@ -77,9 +77,9 @@ STATIC mp_obj_t mp_uos_unsetenv(mp_obj_t key_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_unsetenv_obj, mp_uos_unsetenv); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_unsetenv_obj, mp_os_unsetenv); -STATIC mp_obj_t mp_uos_system(mp_obj_t cmd_in) { +STATIC mp_obj_t mp_os_system(mp_obj_t cmd_in) { const char *cmd = mp_obj_str_get_str(cmd_in); MP_THREAD_GIL_EXIT(); @@ -90,18 +90,18 @@ STATIC mp_obj_t mp_uos_system(mp_obj_t cmd_in) { return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_system_obj, mp_uos_system); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_system_obj, mp_os_system); -STATIC mp_obj_t mp_uos_urandom(mp_obj_t num) { +STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); mp_hal_get_random(n, vstr.buf); return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_uos_urandom_obj, mp_uos_urandom); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); -STATIC mp_obj_t mp_uos_errno(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t mp_os_errno(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return MP_OBJ_NEW_SMALL_INT(errno); } @@ -109,4 +109,4 @@ STATIC mp_obj_t mp_uos_errno(size_t n_args, const mp_obj_t *args) { errno = mp_obj_get_int(args[0]); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_errno_obj, 0, 1, mp_uos_errno); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_errno_obj, 0, 1, mp_os_errno); diff --git a/ports/unix/moduselect.c b/ports/unix/moduselect.c index 9b205d333f..9f7f452a12 100644 --- a/ports/unix/moduselect.c +++ b/ports/unix/moduselect.c @@ -346,11 +346,11 @@ STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table); -const mp_obj_module_t mp_module_uselect = { +const mp_obj_module_t mp_module_select = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; -MP_REGISTER_MODULE(MP_QSTR_select, mp_module_uselect); +MP_REGISTER_MODULE(MP_QSTR_select, mp_module_select); #endif // MICROPY_PY_USELECT_POSIX diff --git a/ports/unix/modutime.c b/ports/unix/modutime.c index dade99295d..26c2fbdb90 100644 --- a/ports/unix/modutime.c +++ b/ports/unix/modutime.c @@ -61,7 +61,7 @@ static inline int msec_sleep_tv(struct timeval *tv) { #error Unsupported clock() implementation #endif -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { #if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE struct timeval tv; gettimeofday(&tv, NULL); @@ -85,7 +85,7 @@ STATIC mp_obj_t mod_time_clock(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); -STATIC mp_obj_t mp_utime_sleep(mp_obj_t arg) { +STATIC mp_obj_t mp_time_sleep(mp_obj_t arg) { #if MICROPY_PY_BUILTINS_FLOAT struct timeval tv; mp_float_t val = mp_obj_get_float(arg); diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 8eafb6119b..0588e100d6 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -184,7 +184,7 @@ void mp_unix_mark_exec(void); #ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC #include void mp_hal_get_random(size_t n, void *buf); -static inline unsigned long mp_urandom_seed_init(void) { +static inline unsigned long mp_random_seed_init(void) { unsigned long r; mp_hal_get_random(sizeof(r), &r); return r; diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index 6f2def8903..5478b69ad4 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -187,7 +187,7 @@ main_term:; void mp_hal_stdout_tx_strn(const char *str, size_t len) { ssize_t ret; MP_HAL_RETRY_SYSCALL(ret, write(STDOUT_FILENO, str, len), {}); - mp_uos_dupterm_tx_strn(str, len); + mp_os_dupterm_tx_strn(str, len); } // cooked is same as uncooked because the terminal does some postprocessing diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index e4e0c0c5d3..9a8a524a22 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -58,7 +58,7 @@ #endif // Seed random on import. -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (mp_urandom_seed_init()) +#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (mp_random_seed_init()) // Allow exception details in low-memory conditions. #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) diff --git a/ports/zephyr/modusocket.c b/ports/zephyr/modusocket.c index 98dff7e8e8..c3356189ab 100644 --- a/ports/zephyr/modusocket.c +++ b/ports/zephyr/modusocket.c @@ -448,7 +448,7 @@ STATIC mp_obj_t pkt_get_info(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(pkt_get_info_obj, pkt_get_info); -STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, // objects { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, @@ -466,13 +466,13 @@ STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_pkt_get_info), MP_ROM_PTR(&pkt_get_info_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); -const mp_obj_module_t mp_module_usocket = { +const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_usocket_globals, + .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_usocket); +MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_USOCKET diff --git a/ports/zephyr/modutime.c b/ports/zephyr/modutime.c index c02460ba01..65ba1e6e69 100644 --- a/ports/zephyr/modutime.c +++ b/ports/zephyr/modutime.c @@ -29,7 +29,7 @@ #include "py/obj.h" -STATIC mp_obj_t mp_utime_time_get(void) { +STATIC mp_obj_t mp_time_time_get(void) { /* The absence of FP support is deliberate. The Zephyr port uses * single precision floats so the fraction component will start to * lose precision on devices with a long uptime. diff --git a/py/builtin.h b/py/builtin.h index 7232142b77..81d0789802 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -133,7 +133,7 @@ extern const mp_obj_module_t mp_module_builtins; extern const mp_obj_module_t mp_module_sys; // Modules needed by the parser when MICROPY_COMP_MODULE_CONST is enabled. -extern const mp_obj_module_t mp_module_uerrno; +extern const mp_obj_module_t mp_module_errno; extern const mp_obj_module_t mp_module_uctypes; extern const mp_obj_module_t mp_module_machine; diff --git a/py/modarray.c b/py/modarray.c index c91e92f798..cfed0fbb59 100644 --- a/py/modarray.c +++ b/py/modarray.c @@ -35,11 +35,11 @@ STATIC const mp_rom_map_elem_t mp_module_array_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_array_globals, mp_module_array_globals_table); -const mp_obj_module_t mp_module_uarray = { +const mp_obj_module_t mp_module_array = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_array_globals, }; -MP_REGISTER_MODULE(MP_QSTR_array, mp_module_uarray); +MP_REGISTER_MODULE(MP_QSTR_array, mp_module_array); #endif diff --git a/py/modstruct.c b/py/modstruct.c index 78c7d53e4b..e908c73e1d 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -261,11 +261,11 @@ STATIC const mp_rom_map_elem_t mp_module_struct_globals_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table); -const mp_obj_module_t mp_module_ustruct = { +const mp_obj_module_t mp_module_struct = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&mp_module_struct_globals, }; -MP_REGISTER_MODULE(MP_QSTR_struct, mp_module_ustruct); +MP_REGISTER_MODULE(MP_QSTR_struct, mp_module_struct); #endif diff --git a/py/moduerrno.c b/py/moduerrno.c index e197f921e1..ed172ae4d6 100644 --- a/py/moduerrno.c +++ b/py/moduerrno.c @@ -81,7 +81,7 @@ STATIC const mp_obj_dict_t errorcode_dict = { }; #endif -STATIC const mp_rom_map_elem_t mp_module_uerrno_globals_table[] = { +STATIC const mp_rom_map_elem_t mp_module_errno_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_errno) }, #if MICROPY_PY_UERRNO_ERRORCODE { MP_ROM_QSTR(MP_QSTR_errorcode), MP_ROM_PTR(&errorcode_dict) }, @@ -92,14 +92,14 @@ STATIC const mp_rom_map_elem_t mp_module_uerrno_globals_table[] = { #undef X }; -STATIC MP_DEFINE_CONST_DICT(mp_module_uerrno_globals, mp_module_uerrno_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_errno_globals, mp_module_errno_globals_table); -const mp_obj_module_t mp_module_uerrno = { +const mp_obj_module_t mp_module_errno = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_uerrno_globals, + .globals = (mp_obj_dict_t *)&mp_module_errno_globals, }; -MP_REGISTER_MODULE(MP_QSTR_errno, mp_module_uerrno); +MP_REGISTER_MODULE(MP_QSTR_errno, mp_module_errno); qstr mp_errno_to_str(mp_obj_t errno_val) { #if MICROPY_PY_UERRNO_ERRORCODE @@ -112,9 +112,9 @@ qstr mp_errno_to_str(mp_obj_t errno_val) { } #else // We don't have the errorcode dict so do a simple search in the modules dict - for (size_t i = 0; i < MP_ARRAY_SIZE(mp_module_uerrno_globals_table); ++i) { - if (errno_val == mp_module_uerrno_globals_table[i].value) { - return MP_OBJ_QSTR_VALUE(mp_module_uerrno_globals_table[i].key); + for (size_t i = 0; i < MP_ARRAY_SIZE(mp_module_errno_globals_table); ++i) { + if (errno_val == mp_module_errno_globals_table[i].value) { + return MP_OBJ_QSTR_VALUE(mp_module_errno_globals_table[i].key); } } return MP_QSTRnull; diff --git a/py/parse.c b/py/parse.c index 86198224fd..a271aa0ea3 100644 --- a/py/parse.c +++ b/py/parse.c @@ -637,7 +637,7 @@ STATIC void push_result_token(parser_t *parser, uint8_t rule_id) { #if MICROPY_COMP_MODULE_CONST STATIC const mp_rom_map_elem_t mp_constants_table[] = { #if MICROPY_PY_UERRNO - { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, + { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_errno) }, #endif #if MICROPY_PY_UCTYPES { MP_ROM_QSTR(MP_QSTR_uctypes), MP_ROM_PTR(&mp_module_uctypes) }, From 7f5d5c72718af773db751269c6ae14037b9c0727 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 18 Aug 2022 14:49:57 +1000 Subject: [PATCH 166/565] all: Rename mod_umodule*, ^umodule* to remove the "u" prefix. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- examples/natmod/uheapq/uheapq.c | 6 +- examples/natmod/urandom/urandom.c | 14 +-- examples/natmod/uzlib/uzlib.c | 2 +- extmod/modlwip.c | 2 +- extmod/moducryptolib.c | 26 +++--- extmod/moduhashlib.c | 138 ++++++++++++++--------------- extmod/moduheapq.c | 38 ++++---- extmod/modujson.c | 50 +++++------ extmod/modurandom.c | 50 +++++------ extmod/modure.c | 6 +- extmod/modusocket.c | 10 +-- extmod/modussl_axtls.c | 48 +++++----- extmod/modussl_mbedtls.c | 16 ++-- extmod/modutimeq.c | 74 ++++++++-------- extmod/moduwebsocket.c | 6 +- extmod/moduzlib.c | 10 +-- ports/cc3200/mods/modusocket.c | 16 ++-- ports/cc3200/mpconfigport.h | 2 +- ports/esp32/main.c | 2 +- ports/esp32/modnetwork.h | 2 +- ports/esp32/modsocket.c | 38 ++++---- ports/esp32/mpconfigport.h | 2 +- ports/nrf/main.c | 8 +- ports/nrf/modules/uos/microbitfs.c | 70 +++++++-------- ports/nrf/modules/uos/microbitfs.h | 14 +-- ports/nrf/modules/uos/moduos.c | 10 +-- ports/nrf/mpconfigport.h | 2 +- ports/nrf/qstrdefsport.h | 2 +- ports/renesas-ra/qstrdefsport.h | 2 +- ports/samd/modmachine.c | 2 +- ports/stm32/modpyb.c | 2 +- ports/stm32/qstrdefsport.h | 2 +- ports/stm32/rng.c | 2 +- ports/unix/coverage.c | 2 +- ports/unix/modusocket.c | 17 ++-- ports/unix/unix_mphal.c | 2 +- py/mpconfig.h | 20 ++--- 37 files changed, 357 insertions(+), 358 deletions(-) diff --git a/examples/natmod/uheapq/uheapq.c b/examples/natmod/uheapq/uheapq.c index 75f00e15cb..ff70bef479 100644 --- a/examples/natmod/uheapq/uheapq.c +++ b/examples/natmod/uheapq/uheapq.c @@ -8,9 +8,9 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a MP_DYNRUNTIME_INIT_ENTRY mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_heapq)); - mp_store_global(MP_QSTR_heappush, MP_OBJ_FROM_PTR(&mod_uheapq_heappush_obj)); - mp_store_global(MP_QSTR_heappop, MP_OBJ_FROM_PTR(&mod_uheapq_heappop_obj)); - mp_store_global(MP_QSTR_heapify, MP_OBJ_FROM_PTR(&mod_uheapq_heapify_obj)); + mp_store_global(MP_QSTR_heappush, MP_OBJ_FROM_PTR(&mod_heapq_heappush_obj)); + mp_store_global(MP_QSTR_heappop, MP_OBJ_FROM_PTR(&mod_heapq_heappop_obj)); + mp_store_global(MP_QSTR_heapify, MP_OBJ_FROM_PTR(&mod_heapq_heapify_obj)); MP_DYNRUNTIME_INIT_EXIT } diff --git a/examples/natmod/urandom/urandom.c b/examples/natmod/urandom/urandom.c index bb41bf3f8e..0c4e88c77e 100644 --- a/examples/natmod/urandom/urandom.c +++ b/examples/natmod/urandom/urandom.c @@ -17,15 +17,15 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a yasmarang_d = 233; mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_random)); - mp_store_global(MP_QSTR_getrandbits, MP_OBJ_FROM_PTR(&mod_urandom_getrandbits_obj)); - mp_store_global(MP_QSTR_seed, MP_OBJ_FROM_PTR(&mod_urandom_seed_obj)); + mp_store_global(MP_QSTR_getrandbits, MP_OBJ_FROM_PTR(&mod_random_getrandbits_obj)); + mp_store_global(MP_QSTR_seed, MP_OBJ_FROM_PTR(&mod_random_seed_obj)); #if MICROPY_PY_URANDOM_EXTRA_FUNCS - mp_store_global(MP_QSTR_randrange, MP_OBJ_FROM_PTR(&mod_urandom_randrange_obj)); - mp_store_global(MP_QSTR_randint, MP_OBJ_FROM_PTR(&mod_urandom_randint_obj)); - mp_store_global(MP_QSTR_choice, MP_OBJ_FROM_PTR(&mod_urandom_choice_obj)); + mp_store_global(MP_QSTR_randrange, MP_OBJ_FROM_PTR(&mod_random_randrange_obj)); + mp_store_global(MP_QSTR_randint, MP_OBJ_FROM_PTR(&mod_random_randint_obj)); + mp_store_global(MP_QSTR_choice, MP_OBJ_FROM_PTR(&mod_random_choice_obj)); #if MICROPY_PY_BUILTINS_FLOAT - mp_store_global(MP_QSTR_random, MP_OBJ_FROM_PTR(&mod_urandom_random_obj)); - mp_store_global(MP_QSTR_uniform, MP_OBJ_FROM_PTR(&mod_urandom_uniform_obj)); + mp_store_global(MP_QSTR_random, MP_OBJ_FROM_PTR(&mod_random_random_obj)); + mp_store_global(MP_QSTR_uniform, MP_OBJ_FROM_PTR(&mod_random_uniform_obj)); #endif #endif diff --git a/examples/natmod/uzlib/uzlib.c b/examples/natmod/uzlib/uzlib.c index 06b24f4b81..ea21235102 100644 --- a/examples/natmod/uzlib/uzlib.c +++ b/examples/natmod/uzlib/uzlib.c @@ -28,7 +28,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a MP_OBJ_TYPE_SET_SLOT(&decompio_type, locals_dict, (void*)&decompio_locals_dict, 2); mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_zlib)); - mp_store_global(MP_QSTR_decompress, MP_OBJ_FROM_PTR(&mod_uzlib_decompress_obj)); + mp_store_global(MP_QSTR_decompress, MP_OBJ_FROM_PTR(&mod_zlib_decompress_obj)); mp_store_global(MP_QSTR_DecompIO, MP_OBJ_FROM_PTR(&decompio_type)); MP_DYNRUNTIME_INIT_EXIT diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 19df1ea503..c66a1de196 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -1801,7 +1801,7 @@ const mp_obj_module_t mp_module_lwip = { MP_REGISTER_MODULE(MP_QSTR_lwip, mp_module_lwip); -// On LWIP-ports, this is the usocket module (replaces extmod/modusocket.c). +// On LWIP-ports, this is the socket module (replaces extmod/modusocket.c). MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_lwip); MP_REGISTER_ROOT_POINTER(mp_obj_t lwip_slip_stream); diff --git a/extmod/moducryptolib.c b/extmod/moducryptolib.c index e727f50548..0c9701024e 100644 --- a/extmod/moducryptolib.c +++ b/extmod/moducryptolib.c @@ -211,7 +211,7 @@ STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t * #endif -STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t cryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 3, false); const mp_int_t block_mode = mp_obj_get_int(args[1]); @@ -332,33 +332,33 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) { return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC mp_obj_t ucryptolib_aes_encrypt(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t cryptolib_aes_encrypt(size_t n_args, const mp_obj_t *args) { return aes_process(n_args, args, true); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ucryptolib_aes_encrypt_obj, 2, 3, ucryptolib_aes_encrypt); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cryptolib_aes_encrypt_obj, 2, 3, cryptolib_aes_encrypt); -STATIC mp_obj_t ucryptolib_aes_decrypt(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t cryptolib_aes_decrypt(size_t n_args, const mp_obj_t *args) { return aes_process(n_args, args, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ucryptolib_aes_decrypt_obj, 2, 3, ucryptolib_aes_decrypt); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cryptolib_aes_decrypt_obj, 2, 3, cryptolib_aes_decrypt); -STATIC const mp_rom_map_elem_t ucryptolib_aes_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_encrypt), MP_ROM_PTR(&ucryptolib_aes_encrypt_obj) }, - { MP_ROM_QSTR(MP_QSTR_decrypt), MP_ROM_PTR(&ucryptolib_aes_decrypt_obj) }, +STATIC const mp_rom_map_elem_t cryptolib_aes_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_encrypt), MP_ROM_PTR(&cryptolib_aes_encrypt_obj) }, + { MP_ROM_QSTR(MP_QSTR_decrypt), MP_ROM_PTR(&cryptolib_aes_decrypt_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ucryptolib_aes_locals_dict, ucryptolib_aes_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(cryptolib_aes_locals_dict, cryptolib_aes_locals_dict_table); STATIC MP_DEFINE_CONST_OBJ_TYPE( - ucryptolib_aes_type, + cryptolib_aes_type, MP_QSTR_aes, MP_TYPE_FLAG_NONE, - make_new, ucryptolib_aes_make_new, - locals_dict, &ucryptolib_aes_locals_dict + make_new, cryptolib_aes_make_new, + locals_dict, &cryptolib_aes_locals_dict ); STATIC const mp_rom_map_elem_t mp_module_cryptolib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cryptolib) }, - { MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&ucryptolib_aes_type) }, + { MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&cryptolib_aes_type) }, #if MICROPY_PY_UCRYPTOLIB_CONSTS { MP_ROM_QSTR(MP_QSTR_MODE_ECB), MP_ROM_INT(UCRYPTOLIB_MODE_ECB) }, { MP_ROM_QSTR(MP_QSTR_MODE_CBC), MP_ROM_INT(UCRYPTOLIB_MODE_CBC) }, diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index ef1a29fc78..0e01b4f27f 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -64,14 +64,14 @@ typedef struct _mp_obj_hash_t { uintptr_t state[0]; // must be aligned to a machine word } mp_obj_hash_t; -static void uhashlib_ensure_not_final(mp_obj_hash_t *self) { +static void hashlib_ensure_not_final(mp_obj_hash_t *self) { if (self->final) { mp_raise_ValueError(MP_ERROR_TEXT("hash is final")); } } #if MICROPY_PY_UHASHLIB_SHA256 -STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); +STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_MBEDTLS @@ -81,30 +81,30 @@ STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); #define mbedtls_sha256_finish_ret mbedtls_sha256_finish #endif -STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context), type); o->final = false; mbedtls_sha256_init((mbedtls_sha256_context *)&o->state); mbedtls_sha256_starts_ret((mbedtls_sha256_context *)&o->state, 0); if (n_args == 1) { - uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]); + hashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]); } return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { +STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); mbedtls_sha256_update_ret((mbedtls_sha256_context *)&self->state, bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) { +STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); self->final = true; vstr_t vstr; vstr_init_len(&vstr, 32); @@ -116,29 +116,29 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) { #include "lib/crypto-algorithms/sha256.c" -STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX), type); o->final = false; sha256_init((CRYAL_SHA256_CTX *)o->state); if (n_args == 1) { - uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]); + hashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]); } return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { +STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); sha256_update((CRYAL_SHA256_CTX *)self->state, bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) { +STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); self->final = true; vstr_t vstr; vstr_init_len(&vstr, SHA256_BLOCK_SIZE); @@ -147,52 +147,52 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) { } #endif -STATIC MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_sha256_update_obj, uhashlib_sha256_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_sha256_digest_obj, uhashlib_sha256_digest); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha256_update_obj, hashlib_sha256_update); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha256_digest_obj, hashlib_sha256_digest); -STATIC const mp_rom_map_elem_t uhashlib_sha256_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_sha256_update_obj) }, - { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_sha256_digest_obj) }, +STATIC const mp_rom_map_elem_t hashlib_sha256_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_sha256_update_obj) }, + { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_sha256_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(uhashlib_sha256_locals_dict, uhashlib_sha256_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(hashlib_sha256_locals_dict, hashlib_sha256_locals_dict_table); STATIC MP_DEFINE_CONST_OBJ_TYPE( - uhashlib_sha256_type, + hashlib_sha256_type, MP_QSTR_sha256, MP_TYPE_FLAG_NONE, make_new, uhashlib_sha256_make_new, - locals_dict, &uhashlib_sha256_locals_dict + locals_dict, &hashlib_sha256_locals_dict ); #endif #if MICROPY_PY_UHASHLIB_SHA1 -STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); +STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS -STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(SHA1_CTX), type); o->final = false; SHA1_Init((SHA1_CTX *)o->state); if (n_args == 1) { - uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]); + hashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]); } return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { +STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); SHA1_Update((SHA1_CTX *)self->state, bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) { +STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); self->final = true; vstr_t vstr; vstr_init_len(&vstr, SHA1_SIZE); @@ -209,30 +209,30 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) { #define mbedtls_sha1_finish_ret mbedtls_sha1_finish #endif -STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context), type); o->final = false; mbedtls_sha1_init((mbedtls_sha1_context *)o->state); mbedtls_sha1_starts_ret((mbedtls_sha1_context *)o->state); if (n_args == 1) { - uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]); + hashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]); } return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { +STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); mbedtls_sha1_update_ret((mbedtls_sha1_context *)self->state, bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) { +STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); self->final = true; vstr_t vstr; vstr_init_len(&vstr, 20); @@ -242,51 +242,51 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) { } #endif -STATIC MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_sha1_update_obj, uhashlib_sha1_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_sha1_digest_obj, uhashlib_sha1_digest); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha1_update_obj, hashlib_sha1_update); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha1_digest_obj, hashlib_sha1_digest); -STATIC const mp_rom_map_elem_t uhashlib_sha1_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_sha1_update_obj) }, - { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_sha1_digest_obj) }, +STATIC const mp_rom_map_elem_t hashlib_sha1_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_sha1_update_obj) }, + { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_sha1_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(uhashlib_sha1_locals_dict, uhashlib_sha1_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(hashlib_sha1_locals_dict, hashlib_sha1_locals_dict_table); STATIC MP_DEFINE_CONST_OBJ_TYPE( - uhashlib_sha1_type, + hashlib_sha1_type, MP_QSTR_sha1, MP_TYPE_FLAG_NONE, - make_new, uhashlib_sha1_make_new, - locals_dict, &uhashlib_sha1_locals_dict + make_new, hashlib_sha1_make_new, + locals_dict, &hashlib_sha1_locals_dict ); #endif #if MICROPY_PY_UHASHLIB_MD5 -STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg); +STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS -STATIC mp_obj_t uhashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(MD5_CTX), type); o->final = false; MD5_Init((MD5_CTX *)o->state); if (n_args == 1) { - uhashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]); + hashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]); } return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { +STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); MD5_Update((MD5_CTX *)self->state, bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) { +STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); self->final = true; vstr_t vstr; vstr_init_len(&vstr, MD5_SIZE); @@ -303,30 +303,30 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) { #define mbedtls_md5_finish_ret mbedtls_md5_finish #endif -STATIC mp_obj_t uhashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context), type); o->final = false; mbedtls_md5_init((mbedtls_md5_context *)o->state); mbedtls_md5_starts_ret((mbedtls_md5_context *)o->state); if (n_args == 1) { - uhashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]); + hashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]); } return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { +STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); mbedtls_md5_update_ret((mbedtls_md5_context *)self->state, bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) { +STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); - uhashlib_ensure_not_final(self); + hashlib_ensure_not_final(self); self->final = true; vstr_t vstr; vstr_init_len(&vstr, 16); @@ -336,34 +336,34 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) { } #endif // MICROPY_SSL_MBEDTLS -STATIC MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_md5_update_obj, uhashlib_md5_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_md5_digest_obj, uhashlib_md5_digest); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_md5_update_obj, hashlib_md5_update); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_md5_digest_obj, hashlib_md5_digest); -STATIC const mp_rom_map_elem_t uhashlib_md5_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_md5_update_obj) }, - { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_md5_digest_obj) }, +STATIC const mp_rom_map_elem_t hashlib_md5_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_md5_update_obj) }, + { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_md5_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(uhashlib_md5_locals_dict, uhashlib_md5_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(hashlib_md5_locals_dict, hashlib_md5_locals_dict_table); STATIC MP_DEFINE_CONST_OBJ_TYPE( - uhashlib_md5_type, + hashlib_md5_type, MP_QSTR_md5, MP_TYPE_FLAG_NONE, - make_new, uhashlib_md5_make_new, - locals_dict, &uhashlib_md5_locals_dict + make_new, hashlib_md5_make_new, + locals_dict, &hashlib_md5_locals_dict ); #endif // MICROPY_PY_UHASHLIB_MD5 STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) }, #if MICROPY_PY_UHASHLIB_SHA256 - { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&uhashlib_sha256_type) }, + { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&hashlib_sha256_type) }, #endif #if MICROPY_PY_UHASHLIB_SHA1 - { MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&uhashlib_sha1_type) }, + { MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&hashlib_sha1_type) }, #endif #if MICROPY_PY_UHASHLIB_MD5 - { MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&uhashlib_md5_type) }, + { MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&hashlib_md5_type) }, #endif }; diff --git a/extmod/moduheapq.c b/extmod/moduheapq.c index fb6cb81182..59277813e9 100644 --- a/extmod/moduheapq.c +++ b/extmod/moduheapq.c @@ -31,14 +31,14 @@ // the algorithm here is modelled on CPython's heapq.py -STATIC mp_obj_list_t *uheapq_get_heap(mp_obj_t heap_in) { +STATIC mp_obj_list_t *heapq_get_heap(mp_obj_t heap_in) { if (!mp_obj_is_type(heap_in, &mp_type_list)) { mp_raise_TypeError(MP_ERROR_TEXT("heap must be a list")); } return MP_OBJ_TO_PTR(heap_in); } -STATIC void uheapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) { +STATIC void heapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) { mp_obj_t item = heap->items[pos]; while (pos > start_pos) { mp_uint_t parent_pos = (pos - 1) >> 1; @@ -53,7 +53,7 @@ STATIC void uheapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_ui heap->items[pos] = item; } -STATIC void uheapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { +STATIC void heapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { mp_uint_t start_pos = pos; mp_uint_t end_pos = heap->len; mp_obj_t item = heap->items[pos]; @@ -67,19 +67,19 @@ STATIC void uheapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { pos = child_pos; } heap->items[pos] = item; - uheapq_heap_siftdown(heap, start_pos, pos); + heapq_heap_siftdown(heap, start_pos, pos); } -STATIC mp_obj_t mod_uheapq_heappush(mp_obj_t heap_in, mp_obj_t item) { - mp_obj_list_t *heap = uheapq_get_heap(heap_in); +STATIC mp_obj_t mod_heapq_heappush(mp_obj_t heap_in, mp_obj_t item) { + mp_obj_list_t *heap = heapq_get_heap(heap_in); mp_obj_list_append(heap_in, item); - uheapq_heap_siftdown(heap, 0, heap->len - 1); + heapq_heap_siftdown(heap, 0, heap->len - 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_uheapq_heappush_obj, mod_uheapq_heappush); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_heapq_heappush_obj, mod_heapq_heappush); -STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) { - mp_obj_list_t *heap = uheapq_get_heap(heap_in); +STATIC mp_obj_t mod_heapq_heappop(mp_obj_t heap_in) { + mp_obj_list_t *heap = heapq_get_heap(heap_in); if (heap->len == 0) { mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap")); } @@ -88,27 +88,27 @@ STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) { heap->items[0] = heap->items[heap->len]; heap->items[heap->len] = MP_OBJ_NULL; // so we don't retain a pointer if (heap->len) { - uheapq_heap_siftup(heap, 0); + heapq_heap_siftup(heap, 0); } return item; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_uheapq_heappop_obj, mod_uheapq_heappop); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heappop_obj, mod_heapq_heappop); -STATIC mp_obj_t mod_uheapq_heapify(mp_obj_t heap_in) { - mp_obj_list_t *heap = uheapq_get_heap(heap_in); +STATIC mp_obj_t mod_heapq_heapify(mp_obj_t heap_in) { + mp_obj_list_t *heap = heapq_get_heap(heap_in); for (mp_uint_t i = heap->len / 2; i > 0;) { - uheapq_heap_siftup(heap, --i); + heapq_heap_siftup(heap, --i); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_uheapq_heapify_obj, mod_uheapq_heapify); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heapify_obj, mod_heapq_heapify); #if !MICROPY_ENABLE_DYNRUNTIME STATIC const mp_rom_map_elem_t mp_module_heapq_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_heapq) }, - { MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_uheapq_heappush_obj) }, - { MP_ROM_QSTR(MP_QSTR_heappop), MP_ROM_PTR(&mod_uheapq_heappop_obj) }, - { MP_ROM_QSTR(MP_QSTR_heapify), MP_ROM_PTR(&mod_uheapq_heapify_obj) }, + { MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_heapq_heappush_obj) }, + { MP_ROM_QSTR(MP_QSTR_heappop), MP_ROM_PTR(&mod_heapq_heappop_obj) }, + { MP_ROM_QSTR(MP_QSTR_heapify), MP_ROM_PTR(&mod_heapq_heapify_obj) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_heapq_globals, mp_module_heapq_globals_table); diff --git a/extmod/modujson.c b/extmod/modujson.c index 44dd316b69..e67761e1a9 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -41,7 +41,7 @@ enum { DUMP_MODE_TO_STREAM = 2, }; -STATIC mp_obj_t mod_ujson_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) { +STATIC mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) { enum { ARG_separators }; static const mp_arg_t allowed_args[] = { { MP_QSTR_separators, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -78,34 +78,34 @@ STATIC mp_obj_t mod_ujson_dump_helper(size_t n_args, const mp_obj_t *pos_args, m } } -STATIC mp_obj_t mod_ujson_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - return mod_ujson_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM); +STATIC mp_obj_t mod_json_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ujson_dump_obj, 2, mod_ujson_dump); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dump_obj, 2, mod_json_dump); -STATIC mp_obj_t mod_ujson_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - return mod_ujson_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING); +STATIC mp_obj_t mod_json_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ujson_dumps_obj, 1, mod_ujson_dumps); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dumps_obj, 1, mod_json_dumps); #else -STATIC mp_obj_t mod_ujson_dump(mp_obj_t obj, mp_obj_t stream) { +STATIC mp_obj_t mod_json_dump(mp_obj_t obj, mp_obj_t stream) { mp_get_stream_raise(stream, MP_STREAM_OP_WRITE); mp_print_t print = {MP_OBJ_TO_PTR(stream), mp_stream_write_adaptor}; mp_obj_print_helper(&print, obj, PRINT_JSON); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ujson_dump_obj, mod_ujson_dump); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_json_dump_obj, mod_json_dump); -STATIC mp_obj_t mod_ujson_dumps(mp_obj_t obj) { +STATIC mp_obj_t mod_json_dumps(mp_obj_t obj) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 8, &print); mp_obj_print_helper(&print, obj, PRINT_JSON); return mp_obj_new_str_from_utf8_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_dumps_obj, mod_json_dumps); #endif @@ -122,19 +122,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps); // strings). It does 1 pass over the input stream. It tries to be fast and // small in code size, while not using more RAM than necessary. -typedef struct _ujson_stream_t { +typedef struct _json_stream_t { mp_obj_t stream_obj; mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode); int errcode; byte cur; -} ujson_stream_t; +} json_stream_t; #define S_EOF (0) // null is not allowed in json stream so is ok as EOF marker #define S_END(s) ((s).cur == S_EOF) #define S_CUR(s) ((s).cur) -#define S_NEXT(s) (ujson_stream_next(&(s))) +#define S_NEXT(s) (json_stream_next(&(s))) -STATIC byte ujson_stream_next(ujson_stream_t *s) { +STATIC byte json_stream_next(json_stream_t *s) { mp_uint_t ret = s->read(s->stream_obj, &s->cur, 1, &s->errcode); if (s->errcode != 0) { mp_raise_OSError(s->errcode); @@ -145,9 +145,9 @@ STATIC byte ujson_stream_next(ujson_stream_t *s) { return s->cur; } -STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) { +STATIC mp_obj_t mod_json_load(mp_obj_t stream_obj) { const mp_stream_p_t *stream_p = mp_get_stream_raise(stream_obj, MP_STREAM_OP_READ); - ujson_stream_t s = {stream_obj, stream_p->read, 0, 0}; + json_stream_t s = {stream_obj, stream_p->read, 0, 0}; vstr_t vstr; vstr_init(&vstr, 8); mp_obj_list_t stack; // we use a list as a simple stack for nested JSON @@ -355,23 +355,23 @@ success: fail: mp_raise_ValueError(MP_ERROR_TEXT("syntax error in JSON")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_load_obj, mod_json_load); -STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { +STATIC mp_obj_t mod_json_loads(mp_obj_t obj) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(obj, &bufinfo, MP_BUFFER_READ); vstr_t vstr = {bufinfo.len, bufinfo.len, (char *)bufinfo.buf, true}; mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0, MP_OBJ_NULL}; - return mod_ujson_load(MP_OBJ_FROM_PTR(&sio)); + return mod_json_load(MP_OBJ_FROM_PTR(&sio)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_loads_obj, mod_ujson_loads); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_loads_obj, mod_json_loads); STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) }, - { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_ujson_dump_obj) }, - { MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_ujson_dumps_obj) }, - { MP_ROM_QSTR(MP_QSTR_load), MP_ROM_PTR(&mod_ujson_load_obj) }, - { MP_ROM_QSTR(MP_QSTR_loads), MP_ROM_PTR(&mod_ujson_loads_obj) }, + { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_json_dump_obj) }, + { MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_json_dumps_obj) }, + { MP_ROM_QSTR(MP_QSTR_load), MP_ROM_PTR(&mod_json_load_obj) }, + { MP_ROM_QSTR(MP_QSTR_loads), MP_ROM_PTR(&mod_json_loads_obj) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table); diff --git a/extmod/modurandom.c b/extmod/modurandom.c index 86e3a872c5..f69f7f4193 100644 --- a/extmod/modurandom.c +++ b/extmod/modurandom.c @@ -85,7 +85,7 @@ STATIC uint32_t yasmarang_randbelow(uint32_t n) { #endif -STATIC mp_obj_t mod_urandom_getrandbits(mp_obj_t num_in) { +STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) { int n = mp_obj_get_int(num_in); if (n > 32 || n < 0) { mp_raise_ValueError(MP_ERROR_TEXT("bits must be 32 or less")); @@ -98,9 +98,9 @@ STATIC mp_obj_t mod_urandom_getrandbits(mp_obj_t num_in) { mask >>= (32 - n); return mp_obj_new_int_from_uint(yasmarang() & mask); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_urandom_getrandbits_obj, mod_urandom_getrandbits); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_getrandbits_obj, mod_random_getrandbits); -STATIC mp_obj_t mod_urandom_seed(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { mp_uint_t seed; if (n_args == 0 || args[0] == mp_const_none) { #ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC @@ -117,11 +117,11 @@ STATIC mp_obj_t mod_urandom_seed(size_t n_args, const mp_obj_t *args) { yasmarang_dat = 0; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_urandom_seed_obj, 0, 1, mod_urandom_seed); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_seed_obj, 0, 1, mod_random_seed); #if MICROPY_PY_URANDOM_EXTRA_FUNCS -STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { mp_int_t start = mp_obj_get_int(args[0]); if (n_args == 1) { // range(stop) @@ -161,9 +161,9 @@ STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) { error: mp_raise_ValueError(NULL); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_urandom_randrange_obj, 1, 3, mod_urandom_randrange); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_randrange_obj, 1, 3, mod_random_randrange); -STATIC mp_obj_t mod_urandom_randint(mp_obj_t a_in, mp_obj_t b_in) { +STATIC mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) { mp_int_t a = mp_obj_get_int(a_in); mp_int_t b = mp_obj_get_int(b_in); if (a <= b) { @@ -172,9 +172,9 @@ STATIC mp_obj_t mod_urandom_randint(mp_obj_t a_in, mp_obj_t b_in) { mp_raise_ValueError(NULL); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_randint_obj, mod_urandom_randint); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint); -STATIC mp_obj_t mod_urandom_choice(mp_obj_t seq) { +STATIC mp_obj_t mod_random_choice(mp_obj_t seq) { mp_int_t len = mp_obj_get_int(mp_obj_len(seq)); if (len > 0) { return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL); @@ -182,7 +182,7 @@ STATIC mp_obj_t mod_urandom_choice(mp_obj_t seq) { mp_raise_type(&mp_type_IndexError); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_urandom_choice_obj, mod_urandom_choice); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_choice_obj, mod_random_choice); #if MICROPY_PY_BUILTINS_FLOAT @@ -199,51 +199,51 @@ STATIC mp_float_t yasmarang_float(void) { return u.f - 1; } -STATIC mp_obj_t mod_urandom_random(void) { +STATIC mp_obj_t mod_random_random(void) { return mp_obj_new_float(yasmarang_float()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom_random_obj, mod_urandom_random); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random_random_obj, mod_random_random); -STATIC mp_obj_t mod_urandom_uniform(mp_obj_t a_in, mp_obj_t b_in) { +STATIC mp_obj_t mod_random_uniform(mp_obj_t a_in, mp_obj_t b_in) { mp_float_t a = mp_obj_get_float(a_in); mp_float_t b = mp_obj_get_float(b_in); return mp_obj_new_float(a + (b - a) * yasmarang_float()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_uniform_obj, mod_urandom_uniform); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_uniform_obj, mod_random_uniform); #endif #endif // MICROPY_PY_URANDOM_EXTRA_FUNCS #if SEED_ON_IMPORT -STATIC mp_obj_t mod_urandom___init__(void) { +STATIC mp_obj_t mod_random___init__(void) { // This module may be imported by more than one name so need to ensure // that it's only ever seeded once. static bool seeded = false; if (!seeded) { seeded = true; - mod_urandom_seed(0, NULL); + mod_random_seed(0, NULL); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom___init___obj, mod_urandom___init__); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random___init___obj, mod_random___init__); #endif #if !MICROPY_ENABLE_DYNRUNTIME STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_random) }, #if SEED_ON_IMPORT - { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_urandom___init___obj) }, + { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_random___init___obj) }, #endif - { MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_urandom_getrandbits_obj) }, - { MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_urandom_seed_obj) }, + { MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_random_getrandbits_obj) }, + { MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_random_seed_obj) }, #if MICROPY_PY_URANDOM_EXTRA_FUNCS - { MP_ROM_QSTR(MP_QSTR_randrange), MP_ROM_PTR(&mod_urandom_randrange_obj) }, - { MP_ROM_QSTR(MP_QSTR_randint), MP_ROM_PTR(&mod_urandom_randint_obj) }, - { MP_ROM_QSTR(MP_QSTR_choice), MP_ROM_PTR(&mod_urandom_choice_obj) }, + { MP_ROM_QSTR(MP_QSTR_randrange), MP_ROM_PTR(&mod_random_randrange_obj) }, + { MP_ROM_QSTR(MP_QSTR_randint), MP_ROM_PTR(&mod_random_randint_obj) }, + { MP_ROM_QSTR(MP_QSTR_choice), MP_ROM_PTR(&mod_random_choice_obj) }, #if MICROPY_PY_BUILTINS_FLOAT - { MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&mod_urandom_random_obj) }, - { MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_urandom_uniform_obj) }, + { MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&mod_random_random_obj) }, + { MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_random_uniform_obj) }, #endif #endif }; diff --git a/extmod/modure.c b/extmod/modure.c index 4798f07b0b..a6fad3cf4e 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -194,7 +194,7 @@ STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t mp_printf(print, "", self); } -STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { +STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { (void)n_args; mp_obj_re_t *self; if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) { @@ -223,12 +223,12 @@ STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { } STATIC mp_obj_t re_match(size_t n_args, const mp_obj_t *args) { - return ure_exec(true, n_args, args); + return re_exec(true, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_match_obj, 2, 4, re_match); STATIC mp_obj_t re_search(size_t n_args, const mp_obj_t *args) { - return ure_exec(false, n_args, args); + return re_exec(false, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_search_obj, 2, 4, re_search); diff --git a/extmod/modusocket.c b/extmod/modusocket.c index 6c2b4ff06f..c8695f1044 100644 --- a/extmod/modusocket.c +++ b/extmod/modusocket.c @@ -540,10 +540,10 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); /******************************************************************************/ -// usocket module +// socket module -// function usocket.getaddrinfo(host, port) -STATIC mp_obj_t mod_usocket_getaddrinfo(size_t n_args, const mp_obj_t *args) { +// function socket.getaddrinfo(host, port) +STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { size_t hlen; const char *host = mp_obj_str_get_data(args[0], &hlen); mp_int_t port = mp_obj_get_int(args[1]); @@ -613,13 +613,13 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(size_t n_args, const mp_obj_t *args) { tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_BIG); return mp_obj_new_list(1, (mp_obj_t *)&tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_usocket_getaddrinfo_obj, 2, 6, mod_usocket_getaddrinfo); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, - { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_usocket_getaddrinfo_obj) }, + { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_socket_getaddrinfo_obj) }, // class constants { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) }, diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c index 6e490a594a..c09059cae8 100644 --- a/extmod/modussl_axtls.c +++ b/extmod/modussl_axtls.c @@ -53,7 +53,7 @@ struct ssl_args { mp_arg_val_t do_handshake; }; -STATIC const mp_obj_type_t ussl_socket_type; +STATIC const mp_obj_type_t ssl_socket_type; // Table of error strings corresponding to SSL_xxx error codes. STATIC const char *const ssl_error_tab1[] = { @@ -84,7 +84,7 @@ STATIC const char *const ssl_error_tab2[] = { "NOT_SUPPORTED", }; -STATIC NORETURN void ussl_raise_error(int err) { +STATIC NORETURN void ssl_raise_error(int err) { MP_STATIC_ASSERT(SSL_NOT_OK - 3 == SSL_EAGAIN); MP_STATIC_ASSERT(SSL_ERROR_CONN_LOST - 18 == SSL_ERROR_NOT_SUPPORTED); @@ -117,13 +117,13 @@ STATIC NORETURN void ussl_raise_error(int err) { } -STATIC mp_obj_ssl_socket_t *ussl_socket_new(mp_obj_t sock, struct ssl_args *args) { +STATIC mp_obj_ssl_socket_t *ssl_socket_new(mp_obj_t sock, struct ssl_args *args) { #if MICROPY_PY_USSL_FINALISER mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t); #else mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t); #endif - o->base.type = &ussl_socket_type; + o->base.type = &ssl_socket_type; o->buf = NULL; o->bytes_left = 0; o->sock = sock; @@ -175,7 +175,7 @@ STATIC mp_obj_ssl_socket_t *ussl_socket_new(mp_obj_t sock, struct ssl_args *args } else if (r == SSL_EAGAIN) { r = MP_EAGAIN; } - ussl_raise_error(r); + ssl_raise_error(r); } } @@ -184,13 +184,13 @@ STATIC mp_obj_ssl_socket_t *ussl_socket_new(mp_obj_t sock, struct ssl_args *args return o; } -STATIC void ussl_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +STATIC void ssl_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "<_SSLSocket %p>", self->ssl_sock); } -STATIC mp_uint_t ussl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +STATIC mp_uint_t ssl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); if (o->ssl_sock == NULL) { @@ -239,7 +239,7 @@ STATIC mp_uint_t ussl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int return size; } -STATIC mp_uint_t ussl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +STATIC mp_uint_t ssl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); if (o->ssl_sock == NULL) { @@ -251,7 +251,7 @@ STATIC mp_uint_t ussl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t siz eagain: r = ssl_write(o->ssl_sock, buf, size); if (r == 0) { - // see comment in ussl_socket_read above + // see comment in ssl_socket_read above if (o->blocking) { goto eagain; } else { @@ -271,7 +271,7 @@ eagain: return r; } -STATIC mp_uint_t ussl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +STATIC mp_uint_t ssl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in); if (request == MP_STREAM_CLOSE && self->ssl_sock != NULL) { ssl_free(self->ssl_sock); @@ -282,7 +282,7 @@ STATIC mp_uint_t ussl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t a return mp_get_stream(self->sock)->ioctl(self->sock, request, arg, errcode); } -STATIC mp_obj_t ussl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { +STATIC mp_obj_t ssl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in); mp_obj_t sock = o->sock; mp_obj_t dest[3]; @@ -292,36 +292,36 @@ STATIC mp_obj_t ussl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { o->blocking = mp_obj_is_true(flag_in); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ussl_socket_setblocking_obj, ussl_socket_setblocking); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(ssl_socket_setblocking_obj, ssl_socket_setblocking); -STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = { +STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, - { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&ussl_socket_setblocking_obj) }, + { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&ssl_socket_setblocking_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, #if MICROPY_PY_USSL_FINALISER { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table); -STATIC const mp_stream_p_t ussl_socket_stream_p = { - .read = ussl_socket_read, - .write = ussl_socket_write, - .ioctl = ussl_socket_ioctl, +STATIC const mp_stream_p_t ssl_socket_stream_p = { + .read = ssl_socket_read, + .write = ssl_socket_write, + .ioctl = ssl_socket_ioctl, }; STATIC MP_DEFINE_CONST_OBJ_TYPE( - ussl_socket_type, + ssl_socket_type, // Save on qstr's, reuse same as for module MP_QSTR_ssl, MP_TYPE_FLAG_NONE, - print, ussl_socket_print, - protocol, &ussl_socket_stream_p, - locals_dict, &ussl_socket_locals_dict + print, ssl_socket_print, + protocol, &ssl_socket_stream_p, + locals_dict, &ssl_socket_locals_dict ); STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -341,7 +341,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args); - return MP_OBJ_FROM_PTR(ussl_socket_new(sock, &args)); + return MP_OBJ_FROM_PTR(ssl_socket_new(sock, &args)); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 1, mod_ssl_wrap_socket); diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index 117a06b6b2..dbe802f75b 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -73,7 +73,7 @@ struct ssl_args { mp_arg_val_t do_handshake; }; -STATIC const mp_obj_type_t ussl_socket_type; +STATIC const mp_obj_type_t ssl_socket_type; #ifdef MBEDTLS_DEBUG_C STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) { @@ -168,7 +168,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) { #else mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t); #endif - o->base.type = &ussl_socket_type; + o->base.type = &ssl_socket_type; o->sock = sock; o->poll_mask = 0; o->last_error = 0; @@ -435,7 +435,7 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i return ret; } -STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = { +STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -451,22 +451,22 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table); -STATIC const mp_stream_p_t ussl_socket_stream_p = { +STATIC const mp_stream_p_t ssl_socket_stream_p = { .read = socket_read, .write = socket_write, .ioctl = socket_ioctl, }; STATIC MP_DEFINE_CONST_OBJ_TYPE( - ussl_socket_type, + ssl_socket_type, // Save on qstr's, reuse same as for module MP_QSTR_ssl, MP_TYPE_FLAG_NONE, print, socket_print, - protocol, &ussl_socket_stream_p, - locals_dict, &ussl_socket_locals_dict + protocol, &ssl_socket_stream_p, + locals_dict, &ssl_socket_locals_dict ); STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { diff --git a/extmod/modutimeq.c b/extmod/modutimeq.c index 8187fa2b23..643aef5d6d 100644 --- a/extmod/modutimeq.c +++ b/extmod/modutimeq.c @@ -46,16 +46,16 @@ struct qentry { mp_obj_t args; }; -typedef struct _mp_obj_utimeq_t { +typedef struct _mp_obj_timeq_t { mp_obj_base_t base; mp_uint_t alloc; mp_uint_t len; struct qentry items[]; -} mp_obj_utimeq_t; +} mp_obj_timeq_t; -STATIC mp_uint_t utimeq_id; +STATIC mp_uint_t timeq_id; -STATIC mp_obj_utimeq_t *utimeq_get_heap(mp_obj_t heap_in) { +STATIC mp_obj_timeq_t *timeq_get_heap(mp_obj_t heap_in) { return MP_OBJ_TO_PTR(heap_in); } @@ -74,17 +74,17 @@ STATIC bool time_less_than(struct qentry *item, struct qentry *parent) { return res && res < (MODULO / 2); } -STATIC mp_obj_t utimeq_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t timeq_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_uint_t alloc = mp_obj_get_int(args[0]); - mp_obj_utimeq_t *o = mp_obj_malloc_var(mp_obj_utimeq_t, struct qentry, alloc, type); + mp_obj_timeq_t *o = mp_obj_malloc_var(mp_obj_timeq_t, struct qentry, alloc, type); memset(o->items, 0, sizeof(*o->items) * alloc); o->alloc = alloc; o->len = 0; return MP_OBJ_FROM_PTR(o); } -STATIC void utimeq_heap_siftdown(mp_obj_utimeq_t *heap, mp_uint_t start_pos, mp_uint_t pos) { +STATIC void timeq_heap_siftdown(mp_obj_timeq_t *heap, mp_uint_t start_pos, mp_uint_t pos) { struct qentry item = heap->items[pos]; while (pos > start_pos) { mp_uint_t parent_pos = (pos - 1) >> 1; @@ -100,7 +100,7 @@ STATIC void utimeq_heap_siftdown(mp_obj_utimeq_t *heap, mp_uint_t start_pos, mp_ heap->items[pos] = item; } -STATIC void utimeq_heap_siftup(mp_obj_utimeq_t *heap, mp_uint_t pos) { +STATIC void timeq_heap_siftup(mp_obj_timeq_t *heap, mp_uint_t pos) { mp_uint_t start_pos = pos; mp_uint_t end_pos = heap->len; struct qentry item = heap->items[pos]; @@ -117,29 +117,29 @@ STATIC void utimeq_heap_siftup(mp_obj_utimeq_t *heap, mp_uint_t pos) { pos = child_pos; } heap->items[pos] = item; - utimeq_heap_siftdown(heap, start_pos, pos); + timeq_heap_siftdown(heap, start_pos, pos); } -STATIC mp_obj_t mod_utimeq_heappush(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t mod_timeq_heappush(size_t n_args, const mp_obj_t *args) { (void)n_args; mp_obj_t heap_in = args[0]; - mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in); + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); if (heap->len == heap->alloc) { mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("queue overflow")); } mp_uint_t l = heap->len; heap->items[l].time = MP_OBJ_SMALL_INT_VALUE(args[1]); - heap->items[l].id = utimeq_id++; + heap->items[l].id = timeq_id++; heap->items[l].callback = args[2]; heap->items[l].args = args[3]; - utimeq_heap_siftdown(heap, 0, heap->len); + timeq_heap_siftdown(heap, 0, heap->len); heap->len++; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_utimeq_heappush_obj, 4, 4, mod_utimeq_heappush); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_timeq_heappush_obj, 4, 4, mod_timeq_heappush); -STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) { - mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in); +STATIC mp_obj_t mod_timeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) { + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); if (heap->len == 0) { mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap")); } @@ -157,14 +157,14 @@ STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) { heap->items[heap->len].callback = MP_OBJ_NULL; // so we don't retain a pointer heap->items[heap->len].args = MP_OBJ_NULL; if (heap->len) { - utimeq_heap_siftup(heap, 0); + timeq_heap_siftup(heap, 0); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_utimeq_heappop_obj, mod_utimeq_heappop); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_timeq_heappop_obj, mod_timeq_heappop); -STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) { - mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in); +STATIC mp_obj_t mod_timeq_peektime(mp_obj_t heap_in) { + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); if (heap->len == 0) { mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap")); } @@ -172,22 +172,22 @@ STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) { struct qentry *item = &heap->items[0]; return MP_OBJ_NEW_SMALL_INT(item->time); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_peektime_obj, mod_utimeq_peektime); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_timeq_peektime_obj, mod_timeq_peektime); #if DEBUG -STATIC mp_obj_t mod_utimeq_dump(mp_obj_t heap_in) { - mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in); +STATIC mp_obj_t mod_timeq_dump(mp_obj_t heap_in) { + mp_obj_timeq_t *heap = timeq_get_heap(heap_in); for (int i = 0; i < heap->len; i++) { printf(UINT_FMT "\t%p\t%p\n", heap->items[i].time, MP_OBJ_TO_PTR(heap->items[i].callback), MP_OBJ_TO_PTR(heap->items[i].args)); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_dump_obj, mod_utimeq_dump); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_timeq_dump_obj, mod_timeq_dump); #endif -STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) { - mp_obj_utimeq_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t timeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) { + mp_obj_timeq_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0); @@ -198,29 +198,29 @@ STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC const mp_rom_map_elem_t utimeq_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_push), MP_ROM_PTR(&mod_utimeq_heappush_obj) }, - { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&mod_utimeq_heappop_obj) }, - { MP_ROM_QSTR(MP_QSTR_peektime), MP_ROM_PTR(&mod_utimeq_peektime_obj) }, +STATIC const mp_rom_map_elem_t timeq_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_push), MP_ROM_PTR(&mod_timeq_heappush_obj) }, + { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&mod_timeq_heappop_obj) }, + { MP_ROM_QSTR(MP_QSTR_peektime), MP_ROM_PTR(&mod_timeq_peektime_obj) }, #if DEBUG - { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_utimeq_dump_obj) }, + { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_timeq_dump_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(utimeq_locals_dict, utimeq_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(timeq_locals_dict, timeq_locals_dict_table); STATIC MP_DEFINE_CONST_OBJ_TYPE( - utimeq_type, + timeq_type, MP_QSTR_timeq, MP_TYPE_FLAG_NONE, - make_new, utimeq_make_new, - unary_op, utimeq_unary_op, - locals_dict, &utimeq_locals_dict + make_new, timeq_make_new, + unary_op, timeq_unary_op, + locals_dict, &timeq_locals_dict ); STATIC const mp_rom_map_elem_t mp_module_timeq_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_timeq) }, - { MP_ROM_QSTR(MP_QSTR_timeq), MP_ROM_PTR(&utimeq_type) }, + { MP_ROM_QSTR(MP_QSTR_timeq), MP_ROM_PTR(&timeq_type) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_timeq_globals, mp_module_timeq_globals_table); diff --git a/extmod/moduwebsocket.c b/extmod/moduwebsocket.c index 301f72fba0..76330f3125 100644 --- a/extmod/moduwebsocket.c +++ b/extmod/moduwebsocket.c @@ -299,16 +299,16 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &websocket_locals_dict ); -STATIC const mp_rom_map_elem_t uwebsocket_module_globals_table[] = { +STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_websocket) }, { MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) }, }; -STATIC MP_DEFINE_CONST_DICT(uwebsocket_module_globals, uwebsocket_module_globals_table); +STATIC MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_table); const mp_obj_module_t mp_module_websocket = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&uwebsocket_module_globals, + .globals = (mp_obj_dict_t *)&websocket_module_globals, }; MP_REGISTER_MODULE(MP_QSTR_websocket, mp_module_websocket); diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index 504c637c3c..e840bdcbfd 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -150,7 +150,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t mod_zlib_decompress(size_t n_args, const mp_obj_t *args) { mp_obj_t data = args[0]; mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); @@ -164,7 +164,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { decomp->dest = dest_buf; decomp->dest_limit = dest_buf + dest_buf_size; - DEBUG_printf("uzlib: Initial out buffer: " UINT_FMT " bytes\n", dest_buf_size); + DEBUG_printf("zlib: Initial out buffer: " UINT_FMT " bytes\n", dest_buf_size); decomp->source = bufinfo.buf; decomp->source_limit = (byte *)bufinfo.buf + bufinfo.len; @@ -198,7 +198,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { } mp_uint_t final_sz = decomp->dest - dest_buf; - DEBUG_printf("uzlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz); + DEBUG_printf("zlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz); dest_buf = (byte *)m_renew(byte, dest_buf, dest_buf_size, final_sz); mp_obj_t res = mp_obj_new_bytearray_by_ref(final_sz, dest_buf); m_del_obj(TINF_DATA, decomp); @@ -207,12 +207,12 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { error: mp_raise_type_arg(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_zlib_decompress_obj, 1, 3, mod_zlib_decompress); #if !MICROPY_ENABLE_DYNRUNTIME STATIC const mp_rom_map_elem_t mp_module_zlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zlib) }, - { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_uzlib_decompress_obj) }, + { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_zlib_decompress_obj) }, { MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) }, }; diff --git a/ports/cc3200/mods/modusocket.c b/ports/cc3200/mods/modusocket.c index 53682743a9..da756296fc 100644 --- a/ports/cc3200/mods/modusocket.c +++ b/ports/cc3200/mods/modusocket.c @@ -41,14 +41,14 @@ /******************************************************************************/ // The following set of macros and functions provide a glue between the CC3100 -// simplelink layer and the functions/methods provided by the usocket module. -// They were historically in a separate file because usocket was designed to +// simplelink layer and the functions/methods provided by the socket module. +// They were historically in a separate file because socket was designed to // work with multiple NICs, and the wlan_XXX functions just provided one // particular NIC implementation (that of the CC3100). But the CC3200 port only // supports a single NIC (being the CC3100) so it's unnecessary and inefficient // to provide an intermediate wrapper layer. Hence the wlan_XXX functions // are provided below as static functions so they can be inlined directly by -// the corresponding usocket calls. +// the corresponding socket calls. #define WLAN_MAX_RX_SIZE 16000 #define WLAN_MAX_TX_SIZE 1476 @@ -769,11 +769,11 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); /******************************************************************************/ -// usocket module +// socket module -// function usocket.getaddrinfo(host, port) +// function socket.getaddrinfo(host, port) /// \function getaddrinfo(host, port) -STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { +STATIC mp_obj_t mod_socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { size_t hlen; const char *host = mp_obj_str_get_data(host_in, &hlen); mp_int_t port = mp_obj_get_int(port_in); @@ -792,13 +792,13 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_LITTLE); return mp_obj_new_list(1, (mp_obj_t*)&tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_usocket_getaddrinfo_obj, mod_usocket_getaddrinfo); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_getaddrinfo_obj, mod_socket_getaddrinfo); STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, - { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_usocket_getaddrinfo_obj) }, + { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_socket_getaddrinfo_obj) }, // class constants { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(SL_AF_INET) }, diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index aa78005d68..8026f7b757 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -125,7 +125,7 @@ #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) #define MICROPY_KBD_EXCEPTION (1) -// We define our own list of errno constants to include in uerrno module +// We define our own list of errno constants to include in errno module #define MICROPY_PY_UERRNO_LIST \ X(EPERM) \ X(EIO) \ diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 0d876eb5f7..b3d467a80e 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -225,7 +225,7 @@ soft_reset_exit: machine_pins_deinit(); machine_deinit(); #if MICROPY_PY_USOCKET_EVENTS - usocket_events_deinit(); + socket_events_deinit(); #endif mp_deinit(); diff --git a/ports/esp32/modnetwork.h b/ports/esp32/modnetwork.h index 80537ea473..ac6321d8f6 100644 --- a/ports/esp32/modnetwork.h +++ b/ports/esp32/modnetwork.h @@ -63,7 +63,7 @@ static inline void esp_exceptions(esp_err_t e) { } } -void usocket_events_deinit(void); +void socket_events_deinit(void); void network_wlan_event_handler(system_event_t *event); void esp_initialise_wifi(void); diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 8199304457..114629a9d7 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -87,22 +87,22 @@ void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms); // This divisor is used to reduce the load on the system, so it doesn't poll sockets too often #define USOCKET_EVENTS_DIVISOR (8) -STATIC uint8_t usocket_events_divisor; -STATIC socket_obj_t *usocket_events_head; +STATIC uint8_t socket_events_divisor; +STATIC socket_obj_t *socket_events_head; -void usocket_events_deinit(void) { - usocket_events_head = NULL; +void socket_events_deinit(void) { + socket_events_head = NULL; } // Assumes the socket is not already in the linked list, and adds it -STATIC void usocket_events_add(socket_obj_t *sock) { - sock->events_next = usocket_events_head; - usocket_events_head = sock; +STATIC void socket_events_add(socket_obj_t *sock) { + sock->events_next = socket_events_head; + socket_events_head = sock; } // Assumes the socket is already in the linked list, and removes it -STATIC void usocket_events_remove(socket_obj_t *sock) { - for (socket_obj_t **s = &usocket_events_head;; s = &(*s)->events_next) { +STATIC void socket_events_remove(socket_obj_t *sock) { + for (socket_obj_t **s = &socket_events_head;; s = &(*s)->events_next) { if (*s == sock) { *s = (*s)->events_next; return; @@ -111,20 +111,20 @@ STATIC void usocket_events_remove(socket_obj_t *sock) { } // Polls all registered sockets for readability and calls their callback if they are readable -void usocket_events_handler(void) { - if (usocket_events_head == NULL) { +void socket_events_handler(void) { + if (socket_events_head == NULL) { return; } - if (--usocket_events_divisor) { + if (--socket_events_divisor) { return; } - usocket_events_divisor = USOCKET_EVENTS_DIVISOR; + socket_events_divisor = USOCKET_EVENTS_DIVISOR; fd_set rfds; FD_ZERO(&rfds); int max_fd = 0; - for (socket_obj_t *s = usocket_events_head; s != NULL; s = s->events_next) { + for (socket_obj_t *s = socket_events_head; s != NULL; s = s->events_next) { FD_SET(s->fd, &rfds); max_fd = MAX(max_fd, s->fd); } @@ -137,7 +137,7 @@ void usocket_events_handler(void) { } // Call the callbacks - for (socket_obj_t *s = usocket_events_head; s != NULL; s = s->events_next) { + for (socket_obj_t *s = socket_events_head; s != NULL; s = s->events_next) { if (FD_ISSET(s->fd, &rfds)) { mp_call_function_1_protected(s->events_callback, s); } @@ -402,12 +402,12 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { case 20: { if (args[3] == mp_const_none) { if (self->events_callback != MP_OBJ_NULL) { - usocket_events_remove(self); + socket_events_remove(self); self->events_callback = MP_OBJ_NULL; } } else { if (self->events_callback == MP_OBJ_NULL) { - usocket_events_add(self); + socket_events_add(self); } self->events_callback = args[3]; } @@ -736,7 +736,7 @@ STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintpt if (socket->fd >= 0) { #if MICROPY_PY_USOCKET_EVENTS if (socket->events_callback != MP_OBJ_NULL) { - usocket_events_remove(socket); + socket_events_remove(socket); socket->events_callback = MP_OBJ_NULL; } #endif @@ -871,5 +871,5 @@ const mp_obj_module_t mp_module_socket = { // Note: This port doesn't define MICROPY_PY_USOCKET or MICROPY_PY_LWIP so // this will not conflict with the common implementation provided by -// extmod/mod{lwip,usocket}.c. +// extmod/mod{lwip,socket}.c. MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 4701040e66..d6aaa98787 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -170,7 +170,7 @@ void *esp_native_code_commit(void *, size_t, void *); #define MICROPY_END_ATOMIC_SECTION(state) portEXIT_CRITICAL_NESTED(state) #if MICROPY_PY_USOCKET_EVENTS -#define MICROPY_PY_USOCKET_EVENTS_HANDLER extern void usocket_events_handler(void); usocket_events_handler(); +#define MICROPY_PY_USOCKET_EVENTS_HANDLER extern void socket_events_handler(void); socket_events_handler(); #else #define MICROPY_PY_USOCKET_EVENTS_HANDLER #endif diff --git a/ports/nrf/main.c b/ports/nrf/main.c index f64107f890..7f35c7f1b3 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -43,7 +43,7 @@ #include "gccollect.h" #include "modmachine.h" #include "modmusic.h" -#include "modules/uos/microbitfs.h" +#include "modules/os/microbitfs.h" #include "led.h" #include "uart.h" #include "nrf.h" @@ -301,15 +301,15 @@ soft_reset: #if MICROPY_MBFS // Use micro:bit filesystem mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - return uos_mbfs_new_reader(filename); + return os_mbfs_new_reader(filename); } mp_import_stat_t mp_import_stat(const char *path) { - return uos_mbfs_import_stat(path); + return os_mbfs_import_stat(path); } mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - return uos_mbfs_open(n_args, args); + return os_mbfs_open(n_args, args); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); diff --git a/ports/nrf/modules/uos/microbitfs.c b/ports/nrf/modules/uos/microbitfs.c index f4c2d20a09..5ffe837efe 100644 --- a/ports/nrf/modules/uos/microbitfs.c +++ b/ports/nrf/modules/uos/microbitfs.c @@ -121,8 +121,8 @@ typedef struct _persistent_config_t { uint8_t marker; // Should always be PERSISTENT_DATA_MARKER } persistent_config_t; -extern const mp_obj_type_t uos_mbfs_fileio_type; -extern const mp_obj_type_t uos_mbfs_textio_type; +extern const mp_obj_type_t os_mbfs_fileio_type; +extern const mp_obj_type_t os_mbfs_textio_type; // Page indexes count down from the end of ROM. STATIC uint8_t first_page_index; @@ -360,7 +360,7 @@ STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len } STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) { - file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &uos_mbfs_fileio_type : &uos_mbfs_textio_type); + file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &os_mbfs_fileio_type : &os_mbfs_textio_type); res->start_chunk = start_chunk; res->seek_chunk = start_chunk; res->seek_offset = file_system_chunks[start_chunk].header.name_len+2; @@ -511,9 +511,9 @@ STATIC mp_uint_t file_read_byte(file_descriptor_obj *fd) { return res; } -// Now follows the code to integrate this filesystem into the uos module. +// Now follows the code to integrate this filesystem into the os module. -mp_lexer_t *uos_mbfs_new_reader(const char *filename) { +mp_lexer_t *os_mbfs_new_reader(const char *filename) { file_descriptor_obj *fd = microbit_file_open(filename, strlen(filename), false, false); if (fd == NULL) { mp_raise_OSError(MP_ENOENT); @@ -525,7 +525,7 @@ mp_lexer_t *uos_mbfs_new_reader(const char *filename) { return mp_lexer_new(qstr_from_str(filename), reader); } -mp_import_stat_t uos_mbfs_import_stat(const char *path) { +mp_import_stat_t os_mbfs_import_stat(const char *path) { uint8_t chunk = microbit_find_file(path, strlen(path)); if (chunk == FILE_NOT_FOUND) { return MP_IMPORT_STAT_NO_EXIST; @@ -534,38 +534,38 @@ mp_import_stat_t uos_mbfs_import_stat(const char *path) { } } -STATIC mp_obj_t uos_mbfs_file_name(mp_obj_t self) { +STATIC mp_obj_t os_mbfs_file_name(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; return microbit_file_name(fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_file_name_obj, uos_mbfs_file_name); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name); -STATIC mp_obj_t uos_mbfs_file_close(mp_obj_t self) { +STATIC mp_obj_t os_mbfs_file_close(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; microbit_file_close(fd); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_file_close_obj, uos_mbfs_file_close); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close); -STATIC mp_obj_t uos_mbfs_remove(mp_obj_t name) { +STATIC mp_obj_t os_mbfs_remove(mp_obj_t name) { return microbit_remove(name); } -MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_remove_obj, uos_mbfs_remove); +MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_remove_obj, os_mbfs_remove); -STATIC mp_obj_t uos_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; - return uos_mbfs_file_close(args[0]); + return os_mbfs_file_close(args[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(uos_mbfs_file___exit___obj, 4, 4, uos_mbfs_file___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__); typedef struct { mp_obj_base_t base; mp_fun_1_t iternext; uint8_t index; -} uos_mbfs_ilistdir_it_t; +} os_mbfs_ilistdir_it_t; -STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { - uos_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { + os_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); // Read until the next FILE_START chunk. for (; self->index <= chunks_in_file_system; self->index++) { @@ -589,27 +589,27 @@ STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t uos_mbfs_ilistdir(void) { - uos_mbfs_ilistdir_it_t *iter = mp_obj_malloc(uos_mbfs_ilistdir_it_t, &mp_type_polymorph_iter); - iter->iternext = uos_mbfs_ilistdir_it_iternext; +STATIC mp_obj_t os_mbfs_ilistdir(void) { + os_mbfs_ilistdir_it_t *iter = mp_obj_malloc(os_mbfs_ilistdir_it_t, &mp_type_polymorph_iter); + iter->iternext = os_mbfs_ilistdir_it_iternext; iter->index = 1; return MP_OBJ_FROM_PTR(iter); } -MP_DEFINE_CONST_FUN_OBJ_0(uos_mbfs_ilistdir_obj, uos_mbfs_ilistdir); +MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj, os_mbfs_ilistdir); -MP_DEFINE_CONST_FUN_OBJ_0(uos_mbfs_listdir_obj, microbit_file_list); +MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj, microbit_file_list); STATIC mp_obj_t microbit_file_writable(mp_obj_t self) { return mp_obj_new_bool(((file_descriptor_obj *)self)->writable); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable); -STATIC const mp_map_elem_t uos_mbfs_file_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&uos_mbfs_file_close_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&uos_mbfs_file_name_obj }, +STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&os_mbfs_file_close_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&os_mbfs_file_name_obj }, { MP_ROM_QSTR(MP_QSTR___enter__), (mp_obj_t)&mp_identity_obj }, - { MP_ROM_QSTR(MP_QSTR___exit__), (mp_obj_t)&uos_mbfs_file___exit___obj }, + { MP_ROM_QSTR(MP_QSTR___exit__), (mp_obj_t)&os_mbfs_file___exit___obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_writable), (mp_obj_t)µbit_file_writable_obj }, /* Stream methods */ { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, @@ -617,7 +617,7 @@ STATIC const mp_map_elem_t uos_mbfs_file_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj}, }; -STATIC MP_DEFINE_CONST_DICT(uos_mbfs_file_locals_dict, uos_mbfs_file_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table); STATIC const mp_stream_p_t textio_stream_p = { @@ -627,11 +627,11 @@ STATIC const mp_stream_p_t textio_stream_p = { }; MP_DEFINE_CONST_OBJ_TYPE( - uos_mbfs_textio_type, + os_mbfs_textio_type, MP_QSTR_TextIO, MP_TYPE_FLAG_NONE, protocol, &textio_stream_p, - locals_dict, &uos_mbfs_file_locals_dict + locals_dict, &os_mbfs_file_locals_dict ); @@ -641,15 +641,15 @@ STATIC const mp_stream_p_t fileio_stream_p = { }; MP_DEFINE_CONST_OBJ_TYPE( - uos_mbfs_fileio_type, + os_mbfs_fileio_type, MP_QSTR_FileIO, MP_TYPE_FLAG_NONE, protocol, &fileio_stream_p, - locals_dict, &uos_mbfs_file_locals_dict + locals_dict, &os_mbfs_file_locals_dict ); // From micro:bit fileobj.c -mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) { +mp_obj_t os_mbfs_open(size_t n_args, const mp_obj_t *args) { /// -1 means default; 0 explicitly false; 1 explicitly true. int read = -1; int text = -1; @@ -683,7 +683,7 @@ mode_error: mp_raise_ValueError(MP_ERROR_TEXT("illegal mode")); } -STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) { +STATIC mp_obj_t os_mbfs_stat(mp_obj_t filename) { mp_obj_t file_size = microbit_file_size(filename); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL)); @@ -699,6 +699,6 @@ STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) { t->items[9] = MP_OBJ_NEW_SMALL_INT(0); // st_ctime return MP_OBJ_FROM_PTR(t); } -MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_stat_obj, uos_mbfs_stat); +MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_stat_obj, os_mbfs_stat); #endif // MICROPY_MBFS diff --git a/ports/nrf/modules/uos/microbitfs.h b/ports/nrf/modules/uos/microbitfs.h index 645a1e3289..56d111383e 100644 --- a/ports/nrf/modules/uos/microbitfs.h +++ b/ports/nrf/modules/uos/microbitfs.h @@ -40,14 +40,14 @@ #define MBFS_LOG_CHUNK_SIZE 7 #endif -mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args); +mp_obj_t os_mbfs_open(size_t n_args, const mp_obj_t *args); void microbit_filesystem_init(void); -mp_lexer_t *uos_mbfs_new_reader(const char *filename); -mp_import_stat_t uos_mbfs_import_stat(const char *path); +mp_lexer_t *os_mbfs_new_reader(const char *filename); +mp_import_stat_t os_mbfs_import_stat(const char *path); -MP_DECLARE_CONST_FUN_OBJ_0(uos_mbfs_listdir_obj); -MP_DECLARE_CONST_FUN_OBJ_0(uos_mbfs_ilistdir_obj); -MP_DECLARE_CONST_FUN_OBJ_1(uos_mbfs_remove_obj); -MP_DECLARE_CONST_FUN_OBJ_1(uos_mbfs_stat_obj); +MP_DECLARE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj); +MP_DECLARE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj); +MP_DECLARE_CONST_FUN_OBJ_1(os_mbfs_remove_obj); +MP_DECLARE_CONST_FUN_OBJ_1(os_mbfs_stat_obj); #endif // __MICROPY_INCLUDED_FILESYSTEM_H__ diff --git a/ports/nrf/modules/uos/moduos.c b/ports/nrf/modules/uos/moduos.c index b718150613..7c54f28ab4 100644 --- a/ports/nrf/modules/uos/moduos.c +++ b/ports/nrf/modules/uos/moduos.c @@ -33,7 +33,7 @@ #include "py/objstr.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" -#include "modules/uos/microbitfs.h" +#include "modules/os/microbitfs.h" #include "extmod/vfs.h" #include "extmod/vfs_fat.h" #include "extmod/vfs_lfs.h" @@ -158,10 +158,10 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_os_sync_obj) }, #elif MICROPY_MBFS - { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&uos_mbfs_listdir_obj) }, - { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&uos_mbfs_ilistdir_obj) }, // uses ~136 bytes - { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&uos_mbfs_stat_obj) }, // uses ~228 bytes - { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&uos_mbfs_remove_obj) }, + { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_mbfs_listdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&os_mbfs_ilistdir_obj) }, // uses ~136 bytes + { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_mbfs_stat_obj) }, // uses ~228 bytes + { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_mbfs_remove_obj) }, #endif /// \constant sep - separation character used in paths diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 3d482f4fe1..0799000b90 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -133,7 +133,7 @@ #define MICROPY_FATFS_MAX_SS (4096) #endif -// Use port specific uos module rather than extmod variant. +// Use port specific os module rather than extmod variant. #define MICROPY_PY_UOS (0) #define MICROPY_STREAMS_NON_BLOCK (1) diff --git a/ports/nrf/qstrdefsport.h b/ports/nrf/qstrdefsport.h index 3cc2f1e646..f12cf40efa 100644 --- a/ports/nrf/qstrdefsport.h +++ b/ports/nrf/qstrdefsport.h @@ -30,7 +30,7 @@ // Entries for sys.path Q(/flash) -// For uos.sep +// For os.sep Q(/) Q(a) diff --git a/ports/renesas-ra/qstrdefsport.h b/ports/renesas-ra/qstrdefsport.h index bc07f2752a..7f5743bbdc 100644 --- a/ports/renesas-ra/qstrdefsport.h +++ b/ports/renesas-ra/qstrdefsport.h @@ -33,7 +33,7 @@ Q(/flash/lib) Q(/sd) Q(/sd/lib) -// For uos.sep +// For os.sep Q(/) #if MICROPY_HW_ENABLE_USB diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index 7e231b28b4..9890e3b590 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -116,7 +116,7 @@ STATIC mp_obj_t machine_unique_id(void) { // 0x0080a040: 50534b54 332e3120 ff091645 // // MicroPython (this code and same order as shown in Arduino IDE) - // >>> ubinascii.hexlify(machine.unique_id()) + // >>> binascii.hexlify(machine.unique_id()) // b'6e27f15f50534b54332e3120ff091645' #if defined(MCU_SAMD21) diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c index 88eafafb0a..b7d6fe7e6a 100644 --- a/ports/stm32/modpyb.c +++ b/ports/stm32/modpyb.c @@ -89,7 +89,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros); MP_DECLARE_CONST_FUN_OBJ_KW(pyb_main_obj); // defined in main.c // Get or set the UART object that the REPL is repeated on. -// This is a legacy function, use of uos.dupterm is preferred. +// This is a legacy function, use of os.dupterm is preferred. STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { if (MP_STATE_PORT(pyb_stdio_uart) == NULL) { diff --git a/ports/stm32/qstrdefsport.h b/ports/stm32/qstrdefsport.h index e7d84cbec0..d44388ebd2 100644 --- a/ports/stm32/qstrdefsport.h +++ b/ports/stm32/qstrdefsport.h @@ -33,7 +33,7 @@ Q(/flash/lib) Q(/sd) Q(/sd/lib) -// For uos.sep +// For os.sep Q(/) #if MICROPY_HW_ENABLE_USB diff --git a/ports/stm32/rng.c b/ports/stm32/rng.c index eea02f7265..5d6ddf6d62 100644 --- a/ports/stm32/rng.c +++ b/ports/stm32/rng.c @@ -66,7 +66,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get); // For MCUs that don't have an RNG we still need to provide a rng_get() function, // eg for lwIP and random.seed(). A pseudo-RNG is not really ideal but we go with // it for now, seeding with numbers which will be somewhat different each time. We -// don't want to use urandom's pRNG because then the user won't see a reproducible +// don't want to use random's pRNG because then the user won't see a reproducible // random stream. // Yasmarang random number generator by Ilya Levin diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index f059c21be4..ab06c0fb39 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -364,7 +364,7 @@ STATIC mp_obj_t extra_coverage(void) { mp_repl_autocomplete("import ", 7, &mp_plat_print, &str); len = mp_repl_autocomplete("import ut", 9, &mp_plat_print, &str); mp_printf(&mp_plat_print, "%.*s\n", (int)len, str); - mp_repl_autocomplete("import utime", 12, &mp_plat_print, &str); + mp_repl_autocomplete("import time", 12, &mp_plat_print, &str); mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0))); mp_repl_autocomplete("sys.", 4, &mp_plat_print, &str); diff --git a/ports/unix/modusocket.c b/ports/unix/modusocket.c index 2d4eeec346..d8a615b469 100644 --- a/ports/unix/modusocket.c +++ b/ports/unix/modusocket.c @@ -54,11 +54,10 @@ /* The idea of this module is to implement reasonable minimum of socket-related functions to write typical clients and servers. - The module named "usocket" on purpose, to allow to make - Python-level module more (or fully) compatible with CPython - "socket", e.g.: + It's then possible to make a Python-level module more (or fully) + compatible with CPython "socket", e.g.: ---- socket.py ---- - from usocket import * + from socket import * from socket_more_funcs import * from socket_more_funcs2 import * ------------------- @@ -487,7 +486,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, siz return MP_OBJ_FROM_PTR(socket_new(fd)); } -STATIC const mp_rom_map_elem_t usocket_locals_dict_table[] = { +STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_fileno), MP_ROM_PTR(&socket_fileno_obj) }, { MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&socket_makefile_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, @@ -508,9 +507,9 @@ STATIC const mp_rom_map_elem_t usocket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(usocket_locals_dict, usocket_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); -STATIC const mp_stream_p_t usocket_stream_p = { +STATIC const mp_stream_p_t socket_stream_p = { .read = socket_read, .write = socket_write, .ioctl = socket_ioctl, @@ -522,8 +521,8 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_TYPE_FLAG_NONE, make_new, socket_make_new, print, socket_print, - protocol, &usocket_stream_p, - locals_dict, &usocket_locals_dict + protocol, &socket_stream_p, + locals_dict, &socket_locals_dict ); #define BINADDR_MAX_LEN sizeof(struct in6_addr) diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index 5478b69ad4..eafc915ca4 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -255,7 +255,7 @@ void mp_hal_get_random(size_t n, void *buf) { #ifdef _HAVE_GETRANDOM RAISE_ERRNO(getrandom(buf, n, 0), errno); #else - int fd = open("/dev/urandom", O_RDONLY); + int fd = open("/dev/random", O_RDONLY); RAISE_ERRNO(fd, errno); RAISE_ERRNO(read(fd, buf, n), errno); close(fd); diff --git a/py/mpconfig.h b/py/mpconfig.h index 9f4d88ec09..fbe8ba54e2 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1273,7 +1273,7 @@ typedef double mp_float_t; #define MICROPY_PY_COLLECTIONS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) #endif -// Whether to provide "ucollections.deque" type +// Whether to provide "collections.deque" type #ifndef MICROPY_PY_COLLECTIONS_DEQUE #define MICROPY_PY_COLLECTIONS_DEQUE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif @@ -1458,44 +1458,44 @@ typedef double mp_float_t; #define MICROPY_PY_SYS_ATTR_DELEGATION (MICROPY_PY_SYS_PS1_PS2 || MICROPY_PY_SYS_TRACEBACKLIMIT) #endif -// Whether to provide "uerrno" module +// Whether to provide "errno" module #ifndef MICROPY_PY_UERRNO #define MICROPY_PY_UERRNO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -// Whether to provide the uerrno.errorcode dict +// Whether to provide the errno.errorcode dict #ifndef MICROPY_PY_UERRNO_ERRORCODE #define MICROPY_PY_UERRNO_ERRORCODE (1) #endif -// Whether to provide "uselect" module (baremetal implementation) +// Whether to provide "select" module (baremetal implementation) #ifndef MICROPY_PY_USELECT #define MICROPY_PY_USELECT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -// Whether to enable the select() function in the "uselect" module (baremetal +// Whether to enable the select() function in the "select" module (baremetal // implementation). This is present for compatibility but can be disabled to // save space. #ifndef MICROPY_PY_USELECT_SELECT #define MICROPY_PY_USELECT_SELECT (1) #endif -// Whether to provide the "utime" module +// Whether to provide the "time" module #ifndef MICROPY_PY_UTIME #define MICROPY_PY_UTIME (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_BASIC_FEATURES) #endif -// Whether to provide utime.gmtime/localtime/mktime functions +// Whether to provide time.gmtime/localtime/mktime functions #ifndef MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME #define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (0) #endif -// Whether to provide utime.time/time_ns functions +// Whether to provide time.time/time_ns functions #ifndef MICROPY_PY_UTIME_TIME_TIME_NS #define MICROPY_PY_UTIME_TIME_TIME_NS (0) #endif -// Period of values returned by utime.ticks_ms(), ticks_us(), ticks_cpu() +// Period of values returned by time.ticks_ms(), ticks_us(), ticks_cpu() // functions. Should be power of two. All functions above use the same // period, so if underlying hardware/API has different periods, the // minimum of them should be used. The value below is the maximum value @@ -1686,7 +1686,7 @@ typedef double mp_float_t; #define MICROPY_PY_USSL (0) #endif -// Whether to add finaliser code to ussl objects +// Whether to add finaliser code to ssl objects #ifndef MICROPY_PY_USSL_FINALISER #define MICROPY_PY_USSL_FINALISER (0) #endif From f5f9edf6457624bf32e71b0c2fdcfbfa5d5753a6 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 18 Aug 2022 15:01:26 +1000 Subject: [PATCH 167/565] all: Rename UMODULE to MODULE in preprocessor/Makefile vars. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- docs/library/random.rst | 4 +- examples/natmod/uheapq/uheapq.c | 2 +- examples/natmod/urandom/urandom.c | 6 +- examples/natmod/ure/ure.c | 8 +- examples/natmod/uzlib/uzlib.c | 2 +- extmod/extmod.mk | 4 +- extmod/modlwip.c | 2 +- extmod/modnetwork.h | 2 +- extmod/moduasyncio.c | 6 +- extmod/modubinascii.c | 8 +- extmod/moducryptolib.c | 18 +-- extmod/moduhashlib.c | 24 +-- extmod/moduheapq.c | 4 +- extmod/modujson.c | 6 +- extmod/moduos.c | 34 ++--- extmod/moduplatform.c | 4 +- extmod/moduplatform.h | 2 +- extmod/modurandom.c | 18 +-- extmod/modure.c | 26 ++-- extmod/moduselect.c | 10 +- extmod/modusocket.c | 14 +- extmod/modussl_axtls.c | 8 +- extmod/modussl_mbedtls.c | 8 +- extmod/modutime.c | 40 ++--- extmod/modutimeq.c | 6 +- extmod/moduwebsocket.c | 4 +- extmod/moduzlib.c | 4 +- extmod/uos_dupterm.c | 8 +- extmod/vfs_posix.c | 4 +- extmod/vfs_posix_file.c | 2 +- ports/cc3200/mods/modusocket.c | 2 +- ports/cc3200/mpconfigport.h | 28 ++-- ports/esp32/main.c | 2 +- ports/esp32/modsocket.c | 14 +- ports/esp32/moduos.c | 2 +- ports/esp32/mpconfigport.h | 46 +++--- ports/esp32/mphalport.c | 2 +- ports/esp8266/Makefile | 2 +- ports/esp8266/boards/GENERIC/mpconfigboard.h | 2 +- .../esp8266/boards/GENERIC_1M/mpconfigboard.h | 2 +- .../boards/GENERIC_512K/mpconfigboard.h | 2 +- ports/esp8266/mpconfigport.h | 30 ++-- .../boards/ADAFRUIT_METRO_M7/mpconfigboard.mk | 2 +- .../boards/MIMXRT1020_EVK/mpconfigboard.mk | 2 +- .../boards/MIMXRT1050_EVK/mpconfigboard.mk | 2 +- .../boards/MIMXRT1060_EVK/mpconfigboard.mk | 2 +- .../boards/MIMXRT1064_EVK/mpconfigboard.mk | 2 +- .../boards/MIMXRT1170_EVK/mpconfigboard.mk | 2 +- .../boards/OLIMEX_RT1010/mpconfigboard.h | 2 +- .../boards/SEEED_ARCH_MIX/mpconfigboard.mk | 2 +- ports/mimxrt/boards/TEENSY41/mpconfigboard.mk | 2 +- ports/mimxrt/moduos.c | 4 +- ports/mimxrt/mpconfigport.h | 36 ++--- ports/nrf/boards/evk_nina_b3/mpconfigboard.h | 4 +- ports/nrf/mpconfigport.h | 14 +- ports/qemu-arm/mpconfigport.h | 18 +-- .../boards/EK_RA4M1/mpconfigboard.h | 4 +- .../boards/EK_RA4W1/mpconfigboard.h | 4 +- .../boards/EK_RA6M1/mpconfigboard.h | 4 +- .../boards/EK_RA6M2/mpconfigboard.h | 4 +- .../boards/RA4M1_CLICKER/mpconfigboard.h | 4 +- ports/renesas-ra/mpconfigport.h | 28 ++-- .../mpconfigboard.h | 2 +- ports/rp2/mpconfigport.h | 40 ++--- ports/samd/mcu/samd21/mpconfigmcu.h | 8 +- ports/samd/mcu/samd51/mpconfigmcu.h | 6 +- ports/samd/moduos.c | 8 +- ports/samd/mpconfigport.h | 22 +-- .../boards/ARDUINO_GIGA/mpconfigboard.mk | 2 +- .../ARDUINO_NICLA_VISION/mpconfigboard.mk | 2 +- .../ARDUINO_PORTENTA_H7/mpconfigboard.mk | 2 +- .../boards/B_L072Z_LRWAN1/mpconfigboard.h | 6 +- .../boards/ESPRUINO_PICO/mpconfigboard.h | 2 +- .../boards/NUCLEO_F091RC/mpconfigboard.h | 6 +- .../boards/NUCLEO_F429ZI/mpconfigboard.mk | 2 +- .../boards/NUCLEO_F439ZI/mpconfigboard.mk | 2 +- .../boards/NUCLEO_F746ZG/mpconfigboard.mk | 2 +- .../boards/NUCLEO_F756ZG/mpconfigboard.mk | 2 +- .../boards/NUCLEO_F767ZI/mpconfigboard.mk | 2 +- .../boards/NUCLEO_G474RE/mpconfigboard.h | 12 +- .../boards/NUCLEO_H723ZG/mpconfigboard.mk | 2 +- .../boards/NUCLEO_H743ZI/mpconfigboard.mk | 2 +- .../boards/NUCLEO_L073RZ/mpconfigboard.h | 6 +- .../boards/NUCLEO_L432KC/mpconfigboard.h | 6 +- .../boards/NUCLEO_L452RE/mpconfigboard.h | 2 +- .../stm32/boards/NUCLEO_WL55/mpconfigboard.h | 6 +- .../stm32/boards/OLIMEX_E407/mpconfigboard.mk | 2 +- ports/stm32/boards/PYBD_SF2/mpconfigboard.mk | 2 +- ports/stm32/boards/PYBD_SF3/mpconfigboard.mk | 2 +- ports/stm32/boards/PYBD_SF6/mpconfigboard.mk | 2 +- .../boards/STM32F769DISC/mpconfigboard.mk | 2 +- .../stm32/boards/STM32F7DISC/mpconfigboard.mk | 2 +- .../boards/VCC_GND_F407ZG/mpconfigboard.mk | 2 +- ports/stm32/moduos.c | 2 +- ports/stm32/mpconfigport.h | 46 +++--- ports/unix/Makefile | 2 +- ports/unix/README.md | 2 +- ports/unix/mbedtls/mbedtls_config.h | 2 +- ports/unix/moduselect.c | 8 +- ports/unix/modusocket.c | 4 +- ports/unix/modutime.c | 2 +- ports/unix/mpconfigport.h | 4 +- ports/unix/mpconfigport.mk | 4 +- .../unix/variants/coverage/mpconfigvariant.h | 2 +- ports/unix/variants/minimal/mpconfigvariant.h | 2 +- .../unix/variants/minimal/mpconfigvariant.mk | 2 +- ports/unix/variants/mpconfigvariant_common.h | 42 ++--- ports/windows/mpconfigport.h | 44 +++--- ports/windows/variants/dev/mpconfigvariant.h | 4 +- ports/zephyr/modusocket.c | 6 +- ports/zephyr/modzsensor.c | 2 +- ports/zephyr/mpconfigport.h | 16 +- ports/zephyr/prj.conf | 2 +- py/moduerrno.c | 18 +-- py/mpconfig.h | 144 +++++++++--------- py/mperrno.h | 2 +- py/objbool.c | 2 +- py/objdict.c | 6 +- py/objexcept.c | 2 +- py/objlist.c | 4 +- py/objnone.c | 2 +- py/objstr.c | 4 +- py/objstrunicode.c | 2 +- py/objtuple.c | 6 +- py/parse.c | 2 +- tools/ci.sh | 4 +- 126 files changed, 563 insertions(+), 563 deletions(-) diff --git a/docs/library/random.rst b/docs/library/random.rst index dd8b47c80f..be56eb088e 100644 --- a/docs/library/random.rst +++ b/docs/library/random.rst @@ -24,7 +24,7 @@ This module implements a pseudo-random number generator (PRNG). .. note:: The :func:`randrange`, :func:`randint` and :func:`choice` functions are only - available if the ``MICROPY_PY_URANDOM_EXTRA_FUNCS`` configuration option is + available if the ``MICROPY_PY_RANDOM_EXTRA_FUNCS`` configuration option is enabled. @@ -73,7 +73,7 @@ Other Functions supported by the port) initialise the PRNG with a true random number (usually a hardware generated random number). - The ``None`` case only works if ``MICROPY_PY_URANDOM_SEED_INIT_FUNC`` is + The ``None`` case only works if ``MICROPY_PY_RANDOM_SEED_INIT_FUNC`` is enabled by the port, otherwise it raises ``ValueError``. .. function:: choice(sequence) diff --git a/examples/natmod/uheapq/uheapq.c b/examples/natmod/uheapq/uheapq.c index ff70bef479..e339ccafd7 100644 --- a/examples/natmod/uheapq/uheapq.c +++ b/examples/natmod/uheapq/uheapq.c @@ -1,4 +1,4 @@ -#define MICROPY_PY_UHEAPQ (1) +#define MICROPY_PY_HEAPQ (1) #include "py/dynruntime.h" diff --git a/examples/natmod/urandom/urandom.c b/examples/natmod/urandom/urandom.c index 0c4e88c77e..ed46651b34 100644 --- a/examples/natmod/urandom/urandom.c +++ b/examples/natmod/urandom/urandom.c @@ -1,5 +1,5 @@ -#define MICROPY_PY_URANDOM (1) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) +#define MICROPY_PY_RANDOM (1) +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (1) #include "py/dynruntime.h" @@ -19,7 +19,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_random)); mp_store_global(MP_QSTR_getrandbits, MP_OBJ_FROM_PTR(&mod_random_getrandbits_obj)); mp_store_global(MP_QSTR_seed, MP_OBJ_FROM_PTR(&mod_random_seed_obj)); - #if MICROPY_PY_URANDOM_EXTRA_FUNCS + #if MICROPY_PY_RANDOM_EXTRA_FUNCS mp_store_global(MP_QSTR_randrange, MP_OBJ_FROM_PTR(&mod_random_randrange_obj)); mp_store_global(MP_QSTR_randint, MP_OBJ_FROM_PTR(&mod_random_randint_obj)); mp_store_global(MP_QSTR_choice, MP_OBJ_FROM_PTR(&mod_random_choice_obj)); diff --git a/examples/natmod/ure/ure.c b/examples/natmod/ure/ure.c index c51df2a475..79eca90ab9 100644 --- a/examples/natmod/ure/ure.c +++ b/examples/natmod/ure/ure.c @@ -1,8 +1,8 @@ #define MICROPY_STACK_CHECK (1) -#define MICROPY_PY_URE (1) -#define MICROPY_PY_URE_MATCH_GROUPS (1) -#define MICROPY_PY_URE_MATCH_SPAN_START_END (1) -#define MICROPY_PY_URE_SUB (0) // requires vstr interface +#define MICROPY_PY_RE (1) +#define MICROPY_PY_RE_MATCH_GROUPS (1) +#define MICROPY_PY_RE_MATCH_SPAN_START_END (1) +#define MICROPY_PY_RE_SUB (0) // requires vstr interface #include #include "py/dynruntime.h" diff --git a/examples/natmod/uzlib/uzlib.c b/examples/natmod/uzlib/uzlib.c index ea21235102..9a3ec0af3c 100644 --- a/examples/natmod/uzlib/uzlib.c +++ b/examples/natmod/uzlib/uzlib.c @@ -1,4 +1,4 @@ -#define MICROPY_PY_UZLIB (1) +#define MICROPY_PY_ZLIB (1) #include "py/dynruntime.h" diff --git a/extmod/extmod.mk b/extmod/extmod.mk index ee9372e18d..2f9bd3b065 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -108,8 +108,8 @@ endif ################################################################################ # ussl -ifeq ($(MICROPY_PY_USSL),1) -CFLAGS_EXTMOD += -DMICROPY_PY_USSL=1 +ifeq ($(MICROPY_PY_SSL),1) +CFLAGS_EXTMOD += -DMICROPY_PY_SSL=1 ifeq ($(MICROPY_SSL_AXTLS),1) AXTLS_DIR = lib/axtls GIT_SUBMODULES += $(AXTLS_DIR) diff --git a/extmod/modlwip.c b/extmod/modlwip.c index c66a1de196..a902e8fb0f 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -918,7 +918,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_bind_obj, lwip_socket_bind); STATIC mp_obj_t lwip_socket_listen(size_t n_args, const mp_obj_t *args) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(args[0]); - mp_int_t backlog = MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT; + mp_int_t backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; if (n_args > 1) { backlog = mp_obj_get_int(args[1]); backlog = (backlog < 0) ? 0 : backlog; diff --git a/extmod/modnetwork.h b/extmod/modnetwork.h index 11691140fd..4786596e9b 100644 --- a/extmod/modnetwork.h +++ b/extmod/modnetwork.h @@ -101,7 +101,7 @@ typedef struct _mod_network_socket_obj_t { int32_t timeout; mp_obj_t callback; int32_t state : 8; - #if MICROPY_PY_USOCKET_EXTENDED_STATE + #if MICROPY_PY_SOCKET_EXTENDED_STATE // Extended socket state for NICs/ports that need it. void *_private; #endif diff --git a/extmod/moduasyncio.c b/extmod/moduasyncio.c index 021e0da1be..c05a8dfc60 100644 --- a/extmod/moduasyncio.c +++ b/extmod/moduasyncio.c @@ -64,14 +64,14 @@ STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, si // Ticks for task ordering in pairing heap STATIC mp_obj_t ticks(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); + return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in); mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in); - mp_int_t diff = ((t1 - t0 + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)) - - MICROPY_PY_UTIME_TICKS_PERIOD / 2; + mp_int_t diff = ((t1 - t0 + MICROPY_PY_TIME_TICKS_PERIOD / 2) & (MICROPY_PY_TIME_TICKS_PERIOD - 1)) + - MICROPY_PY_TIME_TICKS_PERIOD / 2; return diff; } diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c index bfb8195d91..af8eab79f0 100644 --- a/extmod/modubinascii.c +++ b/extmod/modubinascii.c @@ -32,7 +32,7 @@ #include "py/binary.h" #include "py/objstr.h" -#if MICROPY_PY_UBINASCII +#if MICROPY_PY_BINASCII #if MICROPY_PY_BUILTINS_BYTES_HEX STATIC mp_obj_t bytes_hex_as_bytes(size_t n_args, const mp_obj_t *args) { @@ -170,7 +170,7 @@ STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args, } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b2a_base64); -#if MICROPY_PY_UBINASCII_CRC32 +#if MICROPY_PY_BINASCII_CRC32 #include "lib/uzlib/tinf.h" STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) { @@ -191,7 +191,7 @@ STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { #endif { MP_ROM_QSTR(MP_QSTR_a2b_base64), MP_ROM_PTR(&mod_binascii_a2b_base64_obj) }, { MP_ROM_QSTR(MP_QSTR_b2a_base64), MP_ROM_PTR(&mod_binascii_b2a_base64_obj) }, - #if MICROPY_PY_UBINASCII_CRC32 + #if MICROPY_PY_BINASCII_CRC32 { MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_binascii_crc32_obj) }, #endif }; @@ -205,4 +205,4 @@ const mp_obj_module_t mp_module_binascii = { MP_REGISTER_MODULE(MP_QSTR_binascii, mp_module_binascii); -#endif // MICROPY_PY_UBINASCII +#endif // MICROPY_PY_BINASCII diff --git a/extmod/moducryptolib.c b/extmod/moducryptolib.c index 0c9701024e..2299477259 100644 --- a/extmod/moducryptolib.c +++ b/extmod/moducryptolib.c @@ -27,7 +27,7 @@ #include "py/mpconfig.h" -#if MICROPY_PY_UCRYPTOLIB +#if MICROPY_PY_CRYPTOLIB #include #include @@ -90,7 +90,7 @@ typedef struct _mp_obj_aes_t { } mp_obj_aes_t; static inline bool is_ctr_mode(int block_mode) { - #if MICROPY_PY_UCRYPTOLIB_CTR + #if MICROPY_PY_CRYPTOLIB_CTR return block_mode == UCRYPTOLIB_MODE_CTR; #else return false; @@ -140,7 +140,7 @@ STATIC void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t * } } -#if MICROPY_PY_UCRYPTOLIB_CTR +#if MICROPY_PY_CRYPTOLIB_CTR // axTLS doesn't have CTR support out of the box. This implements the counter part using the ECB primitive. STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, struct ctr_params *ctr_params) { size_t n = ctr_params->offset; @@ -203,7 +203,7 @@ STATIC void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t * mbedtls_aes_crypt_cbc(&ctx->u.mbedtls_ctx, encrypt ? MBEDTLS_AES_ENCRYPT : MBEDTLS_AES_DECRYPT, in_len, ctx->iv, in, out); } -#if MICROPY_PY_UCRYPTOLIB_CTR +#if MICROPY_PY_CRYPTOLIB_CTR STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, struct ctr_params *ctr_params) { mbedtls_aes_crypt_ctr(&ctx->u.mbedtls_ctx, in_len, &ctr_params->offset, ctx->iv, ctr_params->encrypted_counter, in, out); } @@ -219,7 +219,7 @@ STATIC mp_obj_t cryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, switch (block_mode) { case UCRYPTOLIB_MODE_ECB: case UCRYPTOLIB_MODE_CBC: - #if MICROPY_PY_UCRYPTOLIB_CTR + #if MICROPY_PY_CRYPTOLIB_CTR case UCRYPTOLIB_MODE_CTR: #endif break; @@ -318,7 +318,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) { aes_process_cbc_impl(&self->ctx, in_bufinfo.buf, out_buf_ptr, in_bufinfo.len, encrypt); break; - #if MICROPY_PY_UCRYPTOLIB_CTR + #if MICROPY_PY_CRYPTOLIB_CTR case UCRYPTOLIB_MODE_CTR: aes_process_ctr_impl(&self->ctx, in_bufinfo.buf, out_buf_ptr, in_bufinfo.len, ctr_params_from_aes(self)); @@ -359,10 +359,10 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( STATIC const mp_rom_map_elem_t mp_module_cryptolib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cryptolib) }, { MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&cryptolib_aes_type) }, - #if MICROPY_PY_UCRYPTOLIB_CONSTS + #if MICROPY_PY_CRYPTOLIB_CONSTS { MP_ROM_QSTR(MP_QSTR_MODE_ECB), MP_ROM_INT(UCRYPTOLIB_MODE_ECB) }, { MP_ROM_QSTR(MP_QSTR_MODE_CBC), MP_ROM_INT(UCRYPTOLIB_MODE_CBC) }, - #if MICROPY_PY_UCRYPTOLIB_CTR + #if MICROPY_PY_CRYPTOLIB_CTR { MP_ROM_QSTR(MP_QSTR_MODE_CTR), MP_ROM_INT(UCRYPTOLIB_MODE_CTR) }, #endif #endif @@ -377,4 +377,4 @@ const mp_obj_module_t mp_module_cryptolib = { MP_REGISTER_MODULE(MP_QSTR_cryptolib, mp_module_cryptolib); -#endif // MICROPY_PY_UCRYPTOLIB +#endif // MICROPY_PY_CRYPTOLIB diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 0e01b4f27f..1b94cc01a0 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -29,13 +29,13 @@ #include "py/runtime.h" -#if MICROPY_PY_UHASHLIB +#if MICROPY_PY_HASHLIB #if MICROPY_SSL_MBEDTLS #include "mbedtls/version.h" #endif -#if MICROPY_PY_UHASHLIB_SHA256 +#if MICROPY_PY_HASHLIB_SHA256 #if MICROPY_SSL_MBEDTLS #include "mbedtls/sha256.h" @@ -45,7 +45,7 @@ #endif -#if MICROPY_PY_UHASHLIB_SHA1 || MICROPY_PY_UHASHLIB_MD5 +#if MICROPY_PY_HASHLIB_SHA1 || MICROPY_PY_HASHLIB_MD5 #if MICROPY_SSL_AXTLS #include "lib/axtls/crypto/crypto.h" @@ -70,7 +70,7 @@ static void hashlib_ensure_not_final(mp_obj_hash_t *self) { } } -#if MICROPY_PY_UHASHLIB_SHA256 +#if MICROPY_PY_HASHLIB_SHA256 STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_MBEDTLS @@ -161,12 +161,12 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( hashlib_sha256_type, MP_QSTR_sha256, MP_TYPE_FLAG_NONE, - make_new, uhashlib_sha256_make_new, + make_new, hashlib_sha256_make_new, locals_dict, &hashlib_sha256_locals_dict ); #endif -#if MICROPY_PY_UHASHLIB_SHA1 +#if MICROPY_PY_HASHLIB_SHA1 STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS @@ -260,7 +260,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -#if MICROPY_PY_UHASHLIB_MD5 +#if MICROPY_PY_HASHLIB_MD5 STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS @@ -352,17 +352,17 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( make_new, hashlib_md5_make_new, locals_dict, &hashlib_md5_locals_dict ); -#endif // MICROPY_PY_UHASHLIB_MD5 +#endif // MICROPY_PY_HASHLIB_MD5 STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) }, - #if MICROPY_PY_UHASHLIB_SHA256 + #if MICROPY_PY_HASHLIB_SHA256 { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&hashlib_sha256_type) }, #endif - #if MICROPY_PY_UHASHLIB_SHA1 + #if MICROPY_PY_HASHLIB_SHA1 { MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&hashlib_sha1_type) }, #endif - #if MICROPY_PY_UHASHLIB_MD5 + #if MICROPY_PY_HASHLIB_MD5 { MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&hashlib_md5_type) }, #endif }; @@ -376,4 +376,4 @@ const mp_obj_module_t mp_module_hashlib = { MP_REGISTER_MODULE(MP_QSTR_hashlib, mp_module_hashlib); -#endif // MICROPY_PY_UHASHLIB +#endif // MICROPY_PY_HASHLIB diff --git a/extmod/moduheapq.c b/extmod/moduheapq.c index 59277813e9..79a12c2b9c 100644 --- a/extmod/moduheapq.c +++ b/extmod/moduheapq.c @@ -27,7 +27,7 @@ #include "py/objlist.h" #include "py/runtime.h" -#if MICROPY_PY_UHEAPQ +#if MICROPY_PY_HEAPQ // the algorithm here is modelled on CPython's heapq.py @@ -121,4 +121,4 @@ const mp_obj_module_t mp_module_heapq = { MP_REGISTER_MODULE(MP_QSTR_heapq, mp_module_heapq); #endif -#endif // MICROPY_PY_UHEAPQ +#endif // MICROPY_PY_HEAPQ diff --git a/extmod/modujson.c b/extmod/modujson.c index e67761e1a9..1b475543e1 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -32,9 +32,9 @@ #include "py/runtime.h" #include "py/stream.h" -#if MICROPY_PY_UJSON +#if MICROPY_PY_JSON -#if MICROPY_PY_UJSON_SEPARATORS +#if MICROPY_PY_JSON_SEPARATORS enum { DUMP_MODE_TO_STRING = 1, @@ -383,4 +383,4 @@ const mp_obj_module_t mp_module_json = { MP_REGISTER_MODULE(MP_QSTR_json, mp_module_json); -#endif // MICROPY_PY_UJSON +#endif // MICROPY_PY_JSON diff --git a/extmod/moduos.c b/extmod/moduos.c index 8c40f45370..e962a6c171 100644 --- a/extmod/moduos.c +++ b/extmod/moduos.c @@ -27,14 +27,14 @@ #include "py/objstr.h" #include "py/runtime.h" -#if MICROPY_PY_UOS +#if MICROPY_PY_OS #include "extmod/misc.h" #include "extmod/vfs.h" #if MICROPY_VFS_FAT #include "extmod/vfs_fat.h" -#if MICROPY_PY_UOS_SYNC +#if MICROPY_PY_OS_SYNC #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #endif @@ -48,12 +48,12 @@ #include "extmod/vfs_posix.h" #endif -#if MICROPY_PY_UOS_UNAME +#if MICROPY_PY_OS_UNAME #include "genhdr/mpversion.h" #endif -#ifdef MICROPY_PY_UOS_INCLUDEFILE -#include MICROPY_PY_UOS_INCLUDEFILE +#ifdef MICROPY_PY_OS_INCLUDEFILE +#include MICROPY_PY_OS_INCLUDEFILE #endif #ifdef MICROPY_BUILD_TYPE @@ -62,7 +62,7 @@ #define MICROPY_BUILD_TYPE_PAREN #endif -#if MICROPY_PY_UOS_SYNC +#if MICROPY_PY_OS_SYNC // sync() // Sync all filesystems. STATIC mp_obj_t mp_os_sync(void) { @@ -77,9 +77,9 @@ STATIC mp_obj_t mp_os_sync(void) { MP_DEFINE_CONST_FUN_OBJ_0(mp_os_sync_obj, mp_os_sync); #endif -#if MICROPY_PY_UOS_UNAME +#if MICROPY_PY_OS_UNAME -#if MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC +#if MICROPY_PY_OS_UNAME_RELEASE_DYNAMIC #define CONST_RELEASE #else #define CONST_RELEASE const @@ -110,7 +110,7 @@ STATIC MP_DEFINE_ATTRTUPLE( ); STATIC mp_obj_t mp_os_uname(void) { - #if MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC + #if MICROPY_PY_OS_UNAME_RELEASE_DYNAMIC const char *release = mp_os_uname_release(); mp_os_uname_info_release_obj.len = strlen(release); mp_os_uname_info_release_obj.data = (const byte *)release; @@ -124,21 +124,21 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_os_uname_obj, mp_os_uname); STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, - #if MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV + #if MICROPY_PY_OS_GETENV_PUTENV_UNSETENV { MP_ROM_QSTR(MP_QSTR_getenv), MP_ROM_PTR(&mp_os_getenv_obj) }, { MP_ROM_QSTR(MP_QSTR_putenv), MP_ROM_PTR(&mp_os_putenv_obj) }, { MP_ROM_QSTR(MP_QSTR_unsetenv), MP_ROM_PTR(&mp_os_unsetenv_obj) }, #endif - #if MICROPY_PY_UOS_SEP + #if MICROPY_PY_OS_SEP { MP_ROM_QSTR(MP_QSTR_sep), MP_ROM_QSTR(MP_QSTR__slash_) }, #endif - #if MICROPY_PY_UOS_SYNC + #if MICROPY_PY_OS_SYNC { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mp_os_sync_obj) }, #endif - #if MICROPY_PY_UOS_SYSTEM + #if MICROPY_PY_OS_SYSTEM { MP_ROM_QSTR(MP_QSTR_system), MP_ROM_PTR(&mp_os_system_obj) }, #endif - #if MICROPY_PY_UOS_UNAME + #if MICROPY_PY_OS_UNAME { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&mp_os_uname_obj) }, #endif #if MICROPY_PY_OS_URANDOM @@ -163,10 +163,10 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { #if MICROPY_PY_OS_DUPTERM { MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_os_dupterm_obj) }, #endif - #if MICROPY_PY_UOS_DUPTERM_NOTIFY + #if MICROPY_PY_OS_DUPTERM_NOTIFY { MP_ROM_QSTR(MP_QSTR_dupterm_notify), MP_ROM_PTR(&mp_os_dupterm_notify_obj) }, #endif - #if MICROPY_PY_UOS_ERRNO + #if MICROPY_PY_OS_ERRNO { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_os_errno_obj) }, #endif @@ -197,4 +197,4 @@ const mp_obj_module_t mp_module_os = { MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); -#endif // MICROPY_PY_UOS +#endif // MICROPY_PY_OS diff --git a/extmod/moduplatform.c b/extmod/moduplatform.c index 791ae8344d..d5f919fc5e 100644 --- a/extmod/moduplatform.c +++ b/extmod/moduplatform.c @@ -32,7 +32,7 @@ #include "extmod/moduplatform.h" #include "genhdr/mpversion.h" -#if MICROPY_PY_UPLATFORM +#if MICROPY_PY_PLATFORM // platform - Access to underlying platform's identifying data @@ -77,4 +77,4 @@ const mp_obj_module_t mp_module_platform = { MP_REGISTER_MODULE(MP_QSTR_platform, mp_module_platform); -#endif // MICROPY_PY_UPLATFORM +#endif // MICROPY_PY_PLATFORM diff --git a/extmod/moduplatform.h b/extmod/moduplatform.h index 3597f7559f..7ca4297788 100644 --- a/extmod/moduplatform.h +++ b/extmod/moduplatform.h @@ -30,7 +30,7 @@ #include "py/mpconfig.h" // Preprocessor directives identifying the platform. -// The (u)platform module itself is guarded by MICROPY_PY_UPLATFORM, see the +// The platform module itself is guarded by MICROPY_PY_PLATFORM, see the // .c file, but these are made available because they're generally usable. // TODO: Add more architectures, compilers and libraries. // See: https://sourceforge.net/p/predef/wiki/Home/ diff --git a/extmod/modurandom.c b/extmod/modurandom.c index f69f7f4193..1c697aec70 100644 --- a/extmod/modurandom.c +++ b/extmod/modurandom.c @@ -29,10 +29,10 @@ #include "py/runtime.h" -#if MICROPY_PY_URANDOM +#if MICROPY_PY_RANDOM // Work out if the seed will be set on import or not. -#if MICROPY_MODULE_BUILTIN_INIT && defined(MICROPY_PY_URANDOM_SEED_INIT_FUNC) +#if MICROPY_MODULE_BUILTIN_INIT && defined(MICROPY_PY_RANDOM_SEED_INIT_FUNC) #define SEED_ON_IMPORT (1) #else #define SEED_ON_IMPORT (0) @@ -67,7 +67,7 @@ STATIC uint32_t yasmarang(void) { // End of Yasmarang -#if MICROPY_PY_URANDOM_EXTRA_FUNCS +#if MICROPY_PY_RANDOM_EXTRA_FUNCS // returns an unsigned integer below the given argument // n must not be zero @@ -103,8 +103,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_getrandbits_obj, mod_random_getrandb STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { mp_uint_t seed; if (n_args == 0 || args[0] == mp_const_none) { - #ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC - seed = MICROPY_PY_URANDOM_SEED_INIT_FUNC; + #ifdef MICROPY_PY_RANDOM_SEED_INIT_FUNC + seed = MICROPY_PY_RANDOM_SEED_INIT_FUNC; #else mp_raise_ValueError(MP_ERROR_TEXT("no default seed")); #endif @@ -119,7 +119,7 @@ STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_seed_obj, 0, 1, mod_random_seed); -#if MICROPY_PY_URANDOM_EXTRA_FUNCS +#if MICROPY_PY_RANDOM_EXTRA_FUNCS STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { mp_int_t start = mp_obj_get_int(args[0]); @@ -213,7 +213,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_uniform_obj, mod_random_uniform); #endif -#endif // MICROPY_PY_URANDOM_EXTRA_FUNCS +#endif // MICROPY_PY_RANDOM_EXTRA_FUNCS #if SEED_ON_IMPORT STATIC mp_obj_t mod_random___init__(void) { @@ -237,7 +237,7 @@ STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = { #endif { MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_random_getrandbits_obj) }, { MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_random_seed_obj) }, - #if MICROPY_PY_URANDOM_EXTRA_FUNCS + #if MICROPY_PY_RANDOM_EXTRA_FUNCS { MP_ROM_QSTR(MP_QSTR_randrange), MP_ROM_PTR(&mod_random_randrange_obj) }, { MP_ROM_QSTR(MP_QSTR_randint), MP_ROM_PTR(&mod_random_randint_obj) }, { MP_ROM_QSTR(MP_QSTR_choice), MP_ROM_PTR(&mod_random_choice_obj) }, @@ -258,4 +258,4 @@ const mp_obj_module_t mp_module_random = { MP_REGISTER_MODULE(MP_QSTR_random, mp_module_random); #endif -#endif // MICROPY_PY_URANDOM +#endif // MICROPY_PY_RANDOM diff --git a/extmod/modure.c b/extmod/modure.c index a6fad3cf4e..c8a019be89 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -37,7 +37,7 @@ #include "py/unicode.h" #endif -#if MICROPY_PY_URE +#if MICROPY_PY_RE #define re1_5_stack_chk() MP_STACK_CHECK() @@ -85,7 +85,7 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) { } MP_DEFINE_CONST_FUN_OBJ_2(match_group_obj, match_group); -#if MICROPY_PY_URE_MATCH_GROUPS +#if MICROPY_PY_RE_MATCH_GROUPS STATIC mp_obj_t match_groups(mp_obj_t self_in) { mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in); @@ -102,7 +102,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(match_groups_obj, match_groups); #endif -#if MICROPY_PY_URE_MATCH_SPAN_START_END +#if MICROPY_PY_RE_MATCH_SPAN_START_END STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span[2]) { mp_obj_match_t *self = MP_OBJ_TO_PTR(args[0]); @@ -167,10 +167,10 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(match_end_obj, 1, 2, match_end); #if !MICROPY_ENABLE_DYNRUNTIME STATIC const mp_rom_map_elem_t match_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_group), MP_ROM_PTR(&match_group_obj) }, - #if MICROPY_PY_URE_MATCH_GROUPS + #if MICROPY_PY_RE_MATCH_GROUPS { MP_ROM_QSTR(MP_QSTR_groups), MP_ROM_PTR(&match_groups_obj) }, #endif - #if MICROPY_PY_URE_MATCH_SPAN_START_END + #if MICROPY_PY_RE_MATCH_SPAN_START_END { MP_ROM_QSTR(MP_QSTR_span), MP_ROM_PTR(&match_span_obj) }, { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&match_start_obj) }, { MP_ROM_QSTR(MP_QSTR_end), MP_ROM_PTR(&match_end_obj) }, @@ -277,7 +277,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_split_obj, 2, 3, re_split); -#if MICROPY_PY_URE_SUB +#if MICROPY_PY_RE_SUB STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) { mp_obj_re_t *self; @@ -405,7 +405,7 @@ STATIC const mp_rom_map_elem_t re_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&re_match_obj) }, { MP_ROM_QSTR(MP_QSTR_search), MP_ROM_PTR(&re_search_obj) }, { MP_ROM_QSTR(MP_QSTR_split), MP_ROM_PTR(&re_split_obj) }, - #if MICROPY_PY_URE_SUB + #if MICROPY_PY_RE_SUB { MP_ROM_QSTR(MP_QSTR_sub), MP_ROM_PTR(&re_sub_obj) }, #endif }; @@ -429,7 +429,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { goto error; } mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, (mp_obj_type_t *)&re_type); - #if MICROPY_PY_URE_DEBUG + #if MICROPY_PY_RE_DEBUG int flags = 0; if (n_args > 1) { flags = mp_obj_get_int(args[1]); @@ -440,7 +440,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { error: mp_raise_ValueError(MP_ERROR_TEXT("error in regex")); } - #if MICROPY_PY_URE_DEBUG + #if MICROPY_PY_RE_DEBUG if (flags & FLAG_DEBUG) { re1_5_dumpcode(&o->re); } @@ -455,10 +455,10 @@ STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_compile), MP_ROM_PTR(&mod_re_compile_obj) }, { MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&re_match_obj) }, { MP_ROM_QSTR(MP_QSTR_search), MP_ROM_PTR(&re_search_obj) }, - #if MICROPY_PY_URE_SUB + #if MICROPY_PY_RE_SUB { MP_ROM_QSTR(MP_QSTR_sub), MP_ROM_PTR(&re_sub_obj) }, #endif - #if MICROPY_PY_URE_DEBUG + #if MICROPY_PY_RE_DEBUG { MP_ROM_QSTR(MP_QSTR_DEBUG), MP_ROM_INT(FLAG_DEBUG) }, #endif }; @@ -482,11 +482,11 @@ MP_REGISTER_MODULE(MP_QSTR_re, mp_module_re); #include "lib/re1.5/recursiveloop.c" #include "lib/re1.5/charclass.c" -#if MICROPY_PY_URE_DEBUG +#if MICROPY_PY_RE_DEBUG // Make sure the output print statements go to the same output as other Python output. #define printf(...) mp_printf(&mp_plat_print, __VA_ARGS__) #include "lib/re1.5/dumpcode.c" #undef printf #endif -#endif // MICROPY_PY_URE +#endif // MICROPY_PY_RE diff --git a/extmod/moduselect.c b/extmod/moduselect.c index 5bb5f4f48d..011d5cb832 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -26,7 +26,7 @@ */ #include "py/mpconfig.h" -#if MICROPY_PY_USELECT +#if MICROPY_PY_SELECT #include @@ -107,7 +107,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, size_t *rwx_num) { return n_ready; } -#if MICROPY_PY_USELECT_SELECT +#if MICROPY_PY_SELECT_SELECT // select(rlist, wlist, xlist[, timeout]) STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { // get array data from tuple/list arguments @@ -174,7 +174,7 @@ STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { } } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select); -#endif // MICROPY_PY_USELECT_SELECT +#endif // MICROPY_PY_SELECT_SELECT typedef struct _mp_obj_poll_t { mp_obj_base_t base; @@ -356,7 +356,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll); STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_select) }, - #if MICROPY_PY_USELECT_SELECT + #if MICROPY_PY_SELECT_SELECT { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) }, #endif { MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mp_select_poll_obj) }, @@ -375,4 +375,4 @@ const mp_obj_module_t mp_module_select = { MP_REGISTER_MODULE(MP_QSTR_select, mp_module_select); -#endif // MICROPY_PY_USELECT +#endif // MICROPY_PY_SELECT diff --git a/extmod/modusocket.c b/extmod/modusocket.c index c8695f1044..316a578ac2 100644 --- a/extmod/modusocket.c +++ b/extmod/modusocket.c @@ -33,7 +33,7 @@ #include "py/stream.h" #include "py/mperrno.h" -#if MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP +#if MICROPY_PY_NETWORK && MICROPY_PY_SOCKET && !MICROPY_PY_LWIP #include "shared/netutils/netutils.h" #include "modnetwork.h" @@ -75,7 +75,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t s->timeout = -1; s->callback = MP_OBJ_NULL; s->state = MOD_NETWORK_SS_NEW; - #if MICROPY_PY_USOCKET_EXTENDED_STATE + #if MICROPY_PY_SOCKET_EXTENDED_STATE s->_private = NULL; #endif @@ -94,7 +94,7 @@ STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) { mp_raise_OSError(_errno); } - #if MICROPY_PY_USOCKET_EXTENDED_STATE + #if MICROPY_PY_SOCKET_EXTENDED_STATE // if a timeout was set before binding a NIC, call settimeout to reset it if (self->timeout != -1 && self->nic_protocol->settimeout(self, self->timeout, &_errno) != 0) { mp_raise_OSError(_errno); @@ -134,7 +134,7 @@ STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { mp_raise_OSError(MP_ENOTCONN); } - mp_int_t backlog = MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT; + mp_int_t backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; if (n_args > 1) { backlog = mp_obj_get_int(args[1]); backlog = (backlog < 0) ? 0 : backlog; @@ -177,7 +177,7 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { socket2->timeout = -1; socket2->callback = MP_OBJ_NULL; socket2->state = MOD_NETWORK_SS_NEW; - #if MICROPY_PY_USOCKET_EXTENDED_STATE + #if MICROPY_PY_SOCKET_EXTENDED_STATE socket2->_private = NULL; #endif @@ -420,7 +420,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { #endif } if (self->nic == MP_OBJ_NULL) { - #if MICROPY_PY_USOCKET_EXTENDED_STATE + #if MICROPY_PY_SOCKET_EXTENDED_STATE // store the timeout in the socket state until a NIC is bound self->timeout = timeout; #else @@ -655,4 +655,4 @@ const mp_obj_module_t mp_module_socket = { MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); -#endif // MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP +#endif // MICROPY_PY_NETWORK && MICROPY_PY_SOCKET && !MICROPY_PY_LWIP diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c index c09059cae8..1c9caf76eb 100644 --- a/extmod/modussl_axtls.c +++ b/extmod/modussl_axtls.c @@ -31,7 +31,7 @@ #include "py/stream.h" #include "py/objstr.h" -#if MICROPY_PY_USSL && MICROPY_SSL_AXTLS +#if MICROPY_PY_SSL && MICROPY_SSL_AXTLS #include "ssl.h" @@ -118,7 +118,7 @@ STATIC NORETURN void ssl_raise_error(int err) { STATIC mp_obj_ssl_socket_t *ssl_socket_new(mp_obj_t sock, struct ssl_args *args) { - #if MICROPY_PY_USSL_FINALISER + #if MICROPY_PY_SSL_FINALISER mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t); #else mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t); @@ -301,7 +301,7 @@ STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&ssl_socket_setblocking_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, - #if MICROPY_PY_USSL_FINALISER + #if MICROPY_PY_SSL_FINALISER { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, #endif }; @@ -359,4 +359,4 @@ const mp_obj_module_t mp_module_ssl = { MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); -#endif // MICROPY_PY_USSL && MICROPY_SSL_AXTLS +#endif // MICROPY_PY_SSL && MICROPY_SSL_AXTLS diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index dbe802f75b..d724e0a08a 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -26,7 +26,7 @@ */ #include "py/mpconfig.h" -#if MICROPY_PY_USSL && MICROPY_SSL_MBEDTLS +#if MICROPY_PY_SSL && MICROPY_SSL_MBEDTLS #include #include @@ -163,7 +163,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) { // Verify the socket object has the full stream protocol mp_get_stream_raise(sock, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL); - #if MICROPY_PY_USSL_FINALISER + #if MICROPY_PY_SSL_FINALISER mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t); #else mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t); @@ -442,7 +442,7 @@ STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, - #if MICROPY_PY_USSL_FINALISER + #if MICROPY_PY_SSL_FINALISER { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, #endif #if MICROPY_UNIX_COVERAGE @@ -509,4 +509,4 @@ const mp_obj_module_t mp_module_ssl = { MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); -#endif // MICROPY_PY_USSL && MICROPY_SSL_MBEDTLS +#endif // MICROPY_PY_SSL && MICROPY_SSL_MBEDTLS diff --git a/extmod/modutime.c b/extmod/modutime.c index 9731f5ff0b..1dfd7aa2c0 100644 --- a/extmod/modutime.c +++ b/extmod/modutime.c @@ -30,13 +30,13 @@ #include "py/smallint.h" #include "extmod/modutime.h" -#if MICROPY_PY_UTIME +#if MICROPY_PY_TIME -#ifdef MICROPY_PY_UTIME_INCLUDEFILE -#include MICROPY_PY_UTIME_INCLUDEFILE +#ifdef MICROPY_PY_TIME_INCLUDEFILE +#include MICROPY_PY_TIME_INCLUDEFILE #endif -#if MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME +#if MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME #include "shared/timeutils/timeutils.h" @@ -96,9 +96,9 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_time_mktime_obj, time_mktime); -#endif // MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME +#endif // MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME -#if MICROPY_PY_UTIME_TIME_TIME_NS +#if MICROPY_PY_TIME_TIME_TIME_NS // time() // Return the number of seconds since the Epoch. @@ -114,10 +114,10 @@ STATIC mp_obj_t time_time_ns(void) { } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_ns_obj, time_time_ns); -#endif // MICROPY_PY_UTIME_TIME_TIME_NS +#endif // MICROPY_PY_TIME_TIME_TIME_NS STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { - #ifdef MICROPY_PY_UTIME_CUSTOM_SLEEP + #ifdef MICROPY_PY_TIME_CUSTOM_SLEEP mp_time_sleep(seconds_o); #else #if MICROPY_PY_BUILTINS_FLOAT @@ -149,17 +149,17 @@ STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_us_obj, time_sleep_us); STATIC mp_obj_t time_ticks_ms(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); + return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_ms_obj, time_ticks_ms); STATIC mp_obj_t time_ticks_us(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); + return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_us_obj, time_ticks_us); STATIC mp_obj_t time_ticks_cpu(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); + return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_cpu_obj, time_ticks_cpu); @@ -169,8 +169,8 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { mp_uint_t end = MP_OBJ_SMALL_INT_VALUE(end_in); // Optimized formula avoiding if conditions. We adjust difference "forward", // wrap it around and adjust back. - mp_int_t diff = ((end - start + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)) - - MICROPY_PY_UTIME_TICKS_PERIOD / 2; + mp_int_t diff = ((end - start + MICROPY_PY_TIME_TICKS_PERIOD / 2) & (MICROPY_PY_TIME_TICKS_PERIOD - 1)) + - MICROPY_PY_TIME_TICKS_PERIOD / 2; return MP_OBJ_NEW_SMALL_INT(diff); } MP_DEFINE_CONST_FUN_OBJ_2(mp_time_ticks_diff_obj, time_ticks_diff); @@ -188,24 +188,24 @@ STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { // // This unsigned comparison is equivalent to a signed comparison of: // delta <= -TICKS_PERIOD/2 || delta >= TICKS_PERIOD/2 - if (delta + MICROPY_PY_UTIME_TICKS_PERIOD / 2 - 1 >= MICROPY_PY_UTIME_TICKS_PERIOD - 1) { + if (delta + MICROPY_PY_TIME_TICKS_PERIOD / 2 - 1 >= MICROPY_PY_TIME_TICKS_PERIOD - 1) { mp_raise_msg(&mp_type_OverflowError, MP_ERROR_TEXT("ticks interval overflow")); } - return MP_OBJ_NEW_SMALL_INT((ticks + delta) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); + return MP_OBJ_NEW_SMALL_INT((ticks + delta) & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_2(mp_time_ticks_add_obj, time_ticks_add); STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time) }, - #if MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME + #if MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mp_time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mp_time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mp_time_mktime_obj) }, #endif - #if MICROPY_PY_UTIME_TIME_TIME_NS + #if MICROPY_PY_TIME_TIME_TIME_NS { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_time_time_obj) }, { MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_time_time_ns_obj) }, #endif @@ -220,8 +220,8 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_time_ticks_add_obj) }, { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_time_ticks_diff_obj) }, - #ifdef MICROPY_PY_UTIME_EXTRA_GLOBALS - MICROPY_PY_UTIME_EXTRA_GLOBALS + #ifdef MICROPY_PY_TIME_EXTRA_GLOBALS + MICROPY_PY_TIME_EXTRA_GLOBALS #endif }; STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); @@ -233,4 +233,4 @@ const mp_obj_module_t mp_module_time = { MP_REGISTER_MODULE(MP_QSTR_time, mp_module_time); -#endif // MICROPY_PY_UTIME +#endif // MICROPY_PY_TIME diff --git a/extmod/modutimeq.c b/extmod/modutimeq.c index 643aef5d6d..7c037ea0a9 100644 --- a/extmod/modutimeq.c +++ b/extmod/modutimeq.c @@ -31,9 +31,9 @@ #include "py/runtime.h" #include "py/smallint.h" -#if MICROPY_PY_UTIMEQ +#if MICROPY_PY_TIMEQ -#define MODULO MICROPY_PY_UTIME_TICKS_PERIOD +#define MODULO MICROPY_PY_TIME_TICKS_PERIOD #define DEBUG 0 @@ -232,4 +232,4 @@ const mp_obj_module_t mp_module_timeq = { MP_REGISTER_MODULE(MP_QSTR_timeq, mp_module_timeq); -#endif // MICROPY_PY_UTIMEQ +#endif // MICROPY_PY_TIMEQ diff --git a/extmod/moduwebsocket.c b/extmod/moduwebsocket.c index 76330f3125..ac90dea8b3 100644 --- a/extmod/moduwebsocket.c +++ b/extmod/moduwebsocket.c @@ -32,7 +32,7 @@ #include "py/stream.h" #include "extmod/moduwebsocket.h" -#if MICROPY_PY_UWEBSOCKET +#if MICROPY_PY_WEBSOCKET enum { FRAME_HEADER, FRAME_OPT, PAYLOAD, CONTROL }; @@ -313,4 +313,4 @@ const mp_obj_module_t mp_module_websocket = { MP_REGISTER_MODULE(MP_QSTR_websocket, mp_module_websocket); -#endif // MICROPY_PY_UWEBSOCKET +#endif // MICROPY_PY_WEBSOCKET diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index e840bdcbfd..a912f113ce 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -31,7 +31,7 @@ #include "py/stream.h" #include "py/mperrno.h" -#if MICROPY_PY_UZLIB +#if MICROPY_PY_ZLIB #include "lib/uzlib/tinf.h" @@ -236,4 +236,4 @@ MP_REGISTER_MODULE(MP_QSTR_zlib, mp_module_zlib); #include "lib/uzlib/adler32.c" #include "lib/uzlib/crc32.c" -#endif // MICROPY_PY_UZLIB +#endif // MICROPY_PY_ZLIB diff --git a/extmod/uos_dupterm.c b/extmod/uos_dupterm.c index c72b365bea..cfd1c62616 100644 --- a/extmod/uos_dupterm.c +++ b/extmod/uos_dupterm.c @@ -66,7 +66,7 @@ uintptr_t mp_os_dupterm_poll(uintptr_t poll_flags) { int errcode = 0; mp_uint_t ret = 0; const mp_stream_p_t *stream_p = mp_get_stream(s); - #if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM + #if MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM if (mp_os_dupterm_is_builtin_stream(s)) { ret = stream_p->ioctl(s, MP_STREAM_POLL, poll_flags, &errcode); } else @@ -99,7 +99,7 @@ int mp_os_dupterm_rx_chr(void) { continue; } - #if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM + #if MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM if (mp_os_dupterm_is_builtin_stream(MP_STATE_VM(dupterm_objs[idx]))) { byte buf[1]; int errcode = 0; @@ -154,7 +154,7 @@ void mp_os_dupterm_tx_strn(const char *str, size_t len) { continue; } - #if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM + #if MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM if (mp_os_dupterm_is_builtin_stream(MP_STATE_VM(dupterm_objs[idx]))) { int errcode = 0; const mp_stream_p_t *stream_p = mp_get_stream(MP_STATE_VM(dupterm_objs[idx])); @@ -194,7 +194,7 @@ STATIC mp_obj_t mp_os_dupterm(size_t n_args, const mp_obj_t *args) { MP_STATE_VM(dupterm_objs[idx]) = args[0]; } - #if MICROPY_PY_UOS_DUPTERM_STREAM_DETACHED_ATTACHED + #if MICROPY_PY_OS_DUPTERM_STREAM_DETACHED_ATTACHED mp_os_dupterm_stream_detached_attached(previous_obj, args[0]); #endif diff --git a/extmod/vfs_posix.c b/extmod/vfs_posix.c index 9b856e1f01..d63bb5be7b 100644 --- a/extmod/vfs_posix.c +++ b/extmod/vfs_posix.c @@ -332,7 +332,7 @@ STATIC mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat); -#if MICROPY_PY_UOS_STATVFS +#if MICROPY_PY_OS_STATVFS #ifdef __ANDROID__ #define USE_STATFS 1 @@ -390,7 +390,7 @@ STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&vfs_posix_rename_obj) }, { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&vfs_posix_rmdir_obj) }, { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&vfs_posix_stat_obj) }, - #if MICROPY_PY_UOS_STATVFS + #if MICROPY_PY_OS_STATVFS { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&vfs_posix_statvfs_obj) }, #endif }; diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index ea19de7fd0..1d89e3ca09 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -194,7 +194,7 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_ return 0; case MP_STREAM_GET_FILENO: return o->fd; - #if MICROPY_PY_USELECT + #if MICROPY_PY_SELECT case MP_STREAM_POLL: { #ifdef _WIN32 mp_raise_NotImplementedError(MP_ERROR_TEXT("poll on file not available on win32")); diff --git a/ports/cc3200/mods/modusocket.c b/ports/cc3200/mods/modusocket.c index da756296fc..9b614c6d34 100644 --- a/ports/cc3200/mods/modusocket.c +++ b/ports/cc3200/mods/modusocket.c @@ -489,7 +489,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { mod_network_socket_obj_t *self = args[0]; - int32_t backlog = MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT; + int32_t backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; if (n_args > 1) { backlog = mp_obj_get_int(args[1]); backlog = (backlog < 0) ? 0 : backlog; diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index 8026f7b757..af10c63531 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -104,29 +104,29 @@ #define MICROPY_PY_SYS_STDFILES (1) #define MICROPY_PY_CMATH (0) #define MICROPY_PY_IO (1) -#define MICROPY_PY_UERRNO (1) -#define MICROPY_PY_UERRNO_ERRORCODE (0) +#define MICROPY_PY_ERRNO (1) +#define MICROPY_PY_ERRNO_ERRORCODE (0) #define MICROPY_PY_THREAD (1) #define MICROPY_PY_THREAD_GIL (1) -#define MICROPY_PY_UBINASCII (1) +#define MICROPY_PY_BINASCII (1) #define MICROPY_PY_UCTYPES (0) -#define MICROPY_PY_UZLIB (0) -#define MICROPY_PY_UJSON (1) -#define MICROPY_PY_URE (1) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UHASHLIB (0) -#define MICROPY_PY_USELECT (1) -#define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/cc3200/mods/modutime.c" +#define MICROPY_PY_ZLIB (0) +#define MICROPY_PY_JSON (1) +#define MICROPY_PY_RE (1) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_HASHLIB (0) +#define MICROPY_PY_SELECT (1) +#define MICROPY_PY_TIME (1) +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/cc3200/mods/modtime.c" #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) #define MICROPY_KBD_EXCEPTION (1) // We define our own list of errno constants to include in errno module -#define MICROPY_PY_UERRNO_LIST \ +#define MICROPY_PY_ERRNO_LIST \ X(EPERM) \ X(EIO) \ X(ENODEV) \ diff --git a/ports/esp32/main.c b/ports/esp32/main.c index b3d467a80e..3e7c9ee162 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -224,7 +224,7 @@ soft_reset_exit: // TODO: machine_rmt_deinit_all(); machine_pins_deinit(); machine_deinit(); - #if MICROPY_PY_USOCKET_EVENTS + #if MICROPY_PY_SOCKET_EVENTS socket_events_deinit(); #endif diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 114629a9d7..0b2d40e333 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -73,7 +73,7 @@ typedef struct _socket_obj_t { uint8_t proto; uint8_t state; unsigned int retries; - #if MICROPY_PY_USOCKET_EVENTS + #if MICROPY_PY_SOCKET_EVENTS mp_obj_t events_callback; struct _socket_obj_t *events_next; #endif @@ -81,7 +81,7 @@ typedef struct _socket_obj_t { void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms); -#if MICROPY_PY_USOCKET_EVENTS +#if MICROPY_PY_SOCKET_EVENTS // Support for callbacks on asynchronous socket events (when socket becomes readable) // This divisor is used to reduce the load on the system, so it doesn't poll sockets too often @@ -144,7 +144,7 @@ void socket_events_handler(void) { } } -#endif // MICROPY_PY_USOCKET_EVENTS +#endif // MICROPY_PY_SOCKET_EVENTS static inline void check_for_exceptions(void) { mp_handle_pending(true); @@ -299,7 +299,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); - int backlog = MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT; + int backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; if (n_args > 1) { backlog = mp_obj_get_int(args[1]); backlog = (backlog < 0) ? 0 : backlog; @@ -396,7 +396,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { break; } - #if MICROPY_PY_USOCKET_EVENTS + #if MICROPY_PY_SOCKET_EVENTS // level: SOL_SOCKET // special "register callback" option case 20: { @@ -734,7 +734,7 @@ STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintpt return ret; } else if (request == MP_STREAM_CLOSE) { if (socket->fd >= 0) { - #if MICROPY_PY_USOCKET_EVENTS + #if MICROPY_PY_SOCKET_EVENTS if (socket->events_callback != MP_OBJ_NULL) { socket_events_remove(socket); socket->events_callback = MP_OBJ_NULL; @@ -869,7 +869,7 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -// Note: This port doesn't define MICROPY_PY_USOCKET or MICROPY_PY_LWIP so +// Note: This port doesn't define MICROPY_PY_SOCKET or MICROPY_PY_LWIP so // this will not conflict with the common implementation provided by // extmod/mod{lwip,socket}.c. MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); diff --git a/ports/esp32/moduos.c b/ports/esp32/moduos.c index 6a5a26c256..287f1d9900 100644 --- a/ports/esp32/moduos.c +++ b/ports/esp32/moduos.c @@ -49,7 +49,7 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); -#if MICROPY_PY_UOS_DUPTERM_NOTIFY +#if MICROPY_PY_OS_DUPTERM_NOTIFY STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; for (;;) { diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index d6aaa98787..d25a5c2734 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -62,9 +62,9 @@ #define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (1) #define MICROPY_PY_BUILTINS_HELP_TEXT esp32_help_text #define MICROPY_PY_IO_BUFFEREDWRITER (1) -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/esp32/modutime.c" +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/esp32/modtime.c" #define MICROPY_PY_THREAD (1) #define MICROPY_PY_THREAD_GIL (1) #define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32) @@ -83,17 +83,17 @@ #define MICROPY_BLUETOOTH_NIMBLE (1) #define MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY (1) #endif -#define MICROPY_PY_UTIMEQ (1) -#define MICROPY_PY_UHASHLIB_SHA1 (1) -#define MICROPY_PY_UHASHLIB_SHA256 (1) -#define MICROPY_PY_UCRYPTOLIB (1) -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (esp_random()) -#define MICROPY_PY_UOS_INCLUDEFILE "ports/esp32/moduos.c" +#define MICROPY_PY_TIMEQ (1) +#define MICROPY_PY_HASHLIB_SHA1 (1) +#define MICROPY_PY_HASHLIB_SHA256 (1) +#define MICROPY_PY_CRYPTOLIB (1) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (esp_random()) +#define MICROPY_PY_OS_INCLUDEFILE "ports/esp32/moduos.c" #define MICROPY_PY_OS_DUPTERM (1) -#define MICROPY_PY_UOS_DUPTERM_NOTIFY (1) -#define MICROPY_PY_UOS_SYNC (1) -#define MICROPY_PY_UOS_UNAME (1) -#define MICROPY_PY_UOS_URANDOM (1) +#define MICROPY_PY_OS_DUPTERM_NOTIFY (1) +#define MICROPY_PY_OS_SYNC (1) +#define MICROPY_PY_OS_UNAME (1) +#define MICROPY_PY_OS_URANDOM (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new #define MICROPY_PY_MACHINE_BITSTREAM (1) @@ -136,14 +136,14 @@ #endif #define MICROPY_HW_SOFTSPI_MIN_DELAY (0) #define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (ets_get_cpu_frequency() * 1000000 / 200) // roughly -#define MICROPY_PY_USSL (1) +#define MICROPY_PY_SSL (1) #define MICROPY_SSL_MBEDTLS (1) -#define MICROPY_PY_USSL_FINALISER (1) -#define MICROPY_PY_UWEBSOCKET (1) +#define MICROPY_PY_SSL_FINALISER (1) +#define MICROPY_PY_WEBSOCKET (1) #define MICROPY_PY_WEBREPL (1) #define MICROPY_PY_ONEWIRE (1) -#define MICROPY_PY_UPLATFORM (1) -#define MICROPY_PY_USOCKET_EVENTS (MICROPY_PY_WEBREPL) +#define MICROPY_PY_PLATFORM (1) +#define MICROPY_PY_SOCKET_EVENTS (MICROPY_PY_WEBREPL) #define MICROPY_PY_BLUETOOTH_RANDOM_ADDR (1) #define MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME ("ESP32") @@ -169,10 +169,10 @@ void *esp_native_code_commit(void *, size_t, void *); #define MICROPY_BEGIN_ATOMIC_SECTION() portENTER_CRITICAL_NESTED() #define MICROPY_END_ATOMIC_SECTION(state) portEXIT_CRITICAL_NESTED(state) -#if MICROPY_PY_USOCKET_EVENTS -#define MICROPY_PY_USOCKET_EVENTS_HANDLER extern void socket_events_handler(void); socket_events_handler(); +#if MICROPY_PY_SOCKET_EVENTS +#define MICROPY_PY_SOCKET_EVENTS_HANDLER extern void socket_events_handler(void); socket_events_handler(); #else -#define MICROPY_PY_USOCKET_EVENTS_HANDLER +#define MICROPY_PY_SOCKET_EVENTS_HANDLER #endif #if MICROPY_PY_THREAD @@ -180,7 +180,7 @@ void *esp_native_code_commit(void *, size_t, void *); do { \ extern void mp_handle_pending(bool); \ mp_handle_pending(true); \ - MICROPY_PY_USOCKET_EVENTS_HANDLER \ + MICROPY_PY_SOCKET_EVENTS_HANDLER \ MP_THREAD_GIL_EXIT(); \ ulTaskNotifyTake(pdFALSE, 1); \ MP_THREAD_GIL_ENTER(); \ @@ -190,7 +190,7 @@ void *esp_native_code_commit(void *, size_t, void *); do { \ extern void mp_handle_pending(bool); \ mp_handle_pending(true); \ - MICROPY_PY_USOCKET_EVENTS_HANDLER \ + MICROPY_PY_SOCKET_EVENTS_HANDLER \ asm ("waiti 0"); \ } while (0); #endif diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c index 61e9fd563e..4c8fa012f4 100644 --- a/ports/esp32/mphalport.c +++ b/ports/esp32/mphalport.c @@ -138,7 +138,7 @@ void mp_hal_delay_ms(uint32_t ms) { uint64_t t0 = esp_timer_get_time(); for (;;) { mp_handle_pending(true); - MICROPY_PY_USOCKET_EVENTS_HANDLER + MICROPY_PY_SOCKET_EVENTS_HANDLER MP_THREAD_GIL_EXIT(); uint64_t t1 = esp_timer_get_time(); dt = t1 - t0; diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile index e3727dfeda..e4db811f24 100644 --- a/ports/esp8266/Makefile +++ b/ports/esp8266/Makefile @@ -27,7 +27,7 @@ QSTR_GLOBAL_DEPENDENCIES = $(BOARD_DIR)/mpconfigboard.h # MicroPython feature configurations MICROPY_ROM_TEXT_COMPRESSION ?= 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_AXTLS = 1 AXTLS_DEFS_EXTRA = -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096 BTREE_DEFS_EXTRA = -DDEFPSIZE=1024 -DMINCACHE=3 diff --git a/ports/esp8266/boards/GENERIC/mpconfigboard.h b/ports/esp8266/boards/GENERIC/mpconfigboard.h index 1d9b8e6f70..52c93f83a3 100644 --- a/ports/esp8266/boards/GENERIC/mpconfigboard.h +++ b/ports/esp8266/boards/GENERIC/mpconfigboard.h @@ -11,4 +11,4 @@ #define MICROPY_READER_VFS (MICROPY_VFS) #define MICROPY_VFS (1) -#define MICROPY_PY_UCRYPTOLIB (1) +#define MICROPY_PY_CRYPTOLIB (1) diff --git a/ports/esp8266/boards/GENERIC_1M/mpconfigboard.h b/ports/esp8266/boards/GENERIC_1M/mpconfigboard.h index cf5127686c..f811f70592 100644 --- a/ports/esp8266/boards/GENERIC_1M/mpconfigboard.h +++ b/ports/esp8266/boards/GENERIC_1M/mpconfigboard.h @@ -14,4 +14,4 @@ #define MICROPY_PY_FSTRINGS (0) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0) #define MICROPY_PY_UASYNCIO (0) -#define MICROPY_PY_UCRYPTOLIB (1) +#define MICROPY_PY_CRYPTOLIB (1) diff --git a/ports/esp8266/boards/GENERIC_512K/mpconfigboard.h b/ports/esp8266/boards/GENERIC_512K/mpconfigboard.h index b0adb7081c..fc933cd3eb 100644 --- a/ports/esp8266/boards/GENERIC_512K/mpconfigboard.h +++ b/ports/esp8266/boards/GENERIC_512K/mpconfigboard.h @@ -9,5 +9,5 @@ #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0) #define MICROPY_PY_SYS_STDIO_BUFFER (0) #define MICROPY_PY_UASYNCIO (0) -#define MICROPY_PY_URE_SUB (0) +#define MICROPY_PY_RE_SUB (0) #define MICROPY_PY_FRAMEBUF (0) diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index 0cfb83f73e..9985d59dd3 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -36,8 +36,8 @@ #define MICROPY_PY_MATH_FACTORIAL (0) #define MICROPY_PY_MATH_ISCLOSE (0) #define MICROPY_PY_SYS_PS1_PS2 (0) -#define MICROPY_PY_UBINASCII_CRC32 (0) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0) +#define MICROPY_PY_BINASCII_CRC32 (0) +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (0) // Configure other options. #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C) @@ -54,11 +54,11 @@ #define MICROPY_REPL_EVENT_DRIVEN (0) #define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_PY_BUILTINS_HELP_TEXT esp_help_text -#define MICROPY_PY_UHASHLIB_SHA1 (MICROPY_PY_USSL && MICROPY_SSL_AXTLS) -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (*WDEV_HWRNG) -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/esp8266/modutime.c" +#define MICROPY_PY_HASHLIB_SHA1 (MICROPY_PY_SSL && MICROPY_SSL_AXTLS) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (*WDEV_HWRNG) +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/esp8266/modutime.c" #define MICROPY_PY_LWIP (1) #define MICROPY_PY_LWIP_SOCK_RAW (1) #define MICROPY_PY_MACHINE (1) @@ -78,19 +78,19 @@ #endif #define MICROPY_PY_NETWORK_INCLUDEFILE "ports/esp8266/modnetwork.h" #define MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE "ports/esp8266/modnetwork_globals.h" -#define MICROPY_PY_UWEBSOCKET (1) +#define MICROPY_PY_WEBSOCKET (1) #define MICROPY_PY_ONEWIRE (1) #define MICROPY_PY_WEBREPL (1) #define MICROPY_PY_WEBREPL_DELAY (20) #define MICROPY_PY_WEBREPL_STATIC_FILEBUF (1) -#define MICROPY_PY_UOS_INCLUDEFILE "ports/esp8266/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/esp8266/modos.c" #define MICROPY_PY_OS_DUPTERM (2) -#define MICROPY_PY_UOS_DUPTERM_NOTIFY (1) -#define MICROPY_PY_UOS_DUPTERM_STREAM_DETACHED_ATTACHED (1) -#define MICROPY_PY_UOS_SYNC (1) -#define MICROPY_PY_UOS_UNAME (1) -#define MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC (1) -#define MICROPY_PY_UOS_URANDOM (1) +#define MICROPY_PY_OS_DUPTERM_NOTIFY (1) +#define MICROPY_PY_OS_DUPTERM_STREAM_DETACHED_ATTACHED (1) +#define MICROPY_PY_OS_SYNC (1) +#define MICROPY_PY_OS_UNAME (1) +#define MICROPY_PY_OS_UNAME_RELEASE_DYNAMIC (1) +#define MICROPY_PY_OS_URANDOM (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_WARNINGS (1) diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk index 8617261d54..236db27c87 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk @@ -7,5 +7,5 @@ MICROPY_HW_FLASH_TYPE ?= qspi_nor_flash MICROPY_HW_FLASH_SIZE ?= 0x800000 # 8MB MICROPY_PY_NETWORK_NINAW10 ?= 1 -MICROPY_PY_USSL ?= 1 +MICROPY_PY_SSL ?= 1 MICROPY_SSL_MBEDTLS ?= 1 diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk index 85bc1f71b6..547b88d57d 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk @@ -10,7 +10,7 @@ MICROPY_HW_SDRAM_AVAIL = 1 MICROPY_HW_SDRAM_SIZE = 0x2000000 # 32MB MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk index 8e4213569a..0cf2a34804 100644 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk @@ -10,7 +10,7 @@ MICROPY_HW_SDRAM_AVAIL = 1 MICROPY_HW_SDRAM_SIZE = 0x2000000 # 32MB MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk index 22cd5356d9..c2556a2724 100644 --- a/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk @@ -10,7 +10,7 @@ MICROPY_HW_SDRAM_AVAIL = 1 MICROPY_HW_SDRAM_SIZE = 0x2000000 # 32MB MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk index b0bd7ec6ac..d3ba752419 100644 --- a/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk @@ -10,7 +10,7 @@ MICROPY_HW_SDRAM_AVAIL = 1 MICROPY_HW_SDRAM_SIZE = 0x2000000 # 32MB MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk index dc44b93bd0..25747a52c6 100644 --- a/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk @@ -12,7 +12,7 @@ MICROPY_HW_SDRAM_AVAIL = 1 MICROPY_HW_SDRAM_SIZE = 0x4000000 # 64MB MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h index d63c0dc403..3d080ff25f 100644 --- a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h +++ b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h @@ -3,7 +3,7 @@ #define MICROPY_HW_USB_MANUFACTURER_STRING "Olimex Ltd." #define MICROPY_HW_USB_VID 0x15ba #define MICROPY_HW_USB_PID 0x0046 -#define MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM (0) +#define MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM (0) // Olimex RT1010-Py has 1 board LED #define MICROPY_HW_LED1_PIN (pin_GPIO_11) diff --git a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk index 8e530ac558..ca27dff55f 100644 --- a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk +++ b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk @@ -10,7 +10,7 @@ MICROPY_HW_SDRAM_AVAIL = 1 MICROPY_HW_SDRAM_SIZE = 0x2000000 # 32MB MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk index ca7e10b5e4..cf07144668 100755 --- a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk @@ -8,7 +8,7 @@ MICROPY_HW_FLASH_SIZE = 0x800000 # 8MB MICROPY_HW_FLASH_RESERVED ?= 0x1000 # 4KB MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py diff --git a/ports/mimxrt/moduos.c b/ports/mimxrt/moduos.c index 8ae8019aae..ecfc3712d7 100644 --- a/ports/mimxrt/moduos.c +++ b/ports/mimxrt/moduos.c @@ -95,7 +95,7 @@ uint32_t trng_random_u32(void) { return rngval; } -#if MICROPY_PY_UOS_URANDOM +#if MICROPY_PY_OS_URANDOM STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; @@ -109,7 +109,7 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif -#if MICROPY_PY_UOS_DUPTERM_NOTIFY +#if MICROPY_PY_OS_DUPTERM_NOTIFY STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; for (;;) { diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 52301cf94b..be086cb552 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -69,17 +69,17 @@ uint32_t trng_random_u32(void); // Extended modules #define MICROPY_EPOCH_IS_1970 (1) -#define MICROPY_PY_USSL_FINALISER (MICROPY_PY_USSL) -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/mimxrt/modutime.c" -#define MICROPY_PY_UOS_INCLUDEFILE "ports/mimxrt/moduos.c" +#define MICROPY_PY_SSL_FINALISER (MICROPY_PY_SSL) +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/mimxrt/modutime.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/mimxrt/moduos.c" #define MICROPY_PY_OS_DUPTERM (3) -#define MICROPY_PY_UOS_DUPTERM_NOTIFY (1) -#define MICROPY_PY_UOS_SYNC (1) -#define MICROPY_PY_UOS_UNAME (1) -#define MICROPY_PY_UOS_URANDOM (1) -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (trng_random_u32()) +#define MICROPY_PY_OS_DUPTERM_NOTIFY (1) +#define MICROPY_PY_OS_SYNC (1) +#define MICROPY_PY_OS_UNAME (1) +#define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32()) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new #define MICROPY_PY_MACHINE_BITSTREAM (1) @@ -96,7 +96,7 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_MACHINE_TIMER (1) #define MICROPY_SOFT_TIMER_TICKS_MS systick_ms #define MICROPY_PY_ONEWIRE (1) -#define MICROPY_PY_UPLATFORM (1) +#define MICROPY_PY_PLATFORM (1) // fatfs configuration used in ffconf.h #define MICROPY_FATFS_ENABLE_LFN (1) @@ -107,16 +107,16 @@ uint32_t trng_random_u32(void); #ifndef MICROPY_PY_NETWORK #define MICROPY_PY_NETWORK (1) #endif -#ifndef MICROPY_PY_USOCKET -#define MICROPY_PY_USOCKET (1) +#ifndef MICROPY_PY_SOCKET +#define MICROPY_PY_SOCKET (1) #endif -#define MICROPY_PY_UWEBSOCKET (MICROPY_PY_LWIP) +#define MICROPY_PY_WEBSOCKET (MICROPY_PY_LWIP) #define MICROPY_PY_WEBREPL (MICROPY_PY_LWIP) #define MICROPY_PY_LWIP_SOCK_RAW (MICROPY_PY_LWIP) -#define MICROPY_PY_USSL_FINALISER (MICROPY_PY_USSL) -// #define MICROPY_PY_UHASHLIB_MD5 (MICROPY_PY_USSL) -#define MICROPY_PY_UHASHLIB_SHA1 (MICROPY_PY_USSL) -// #define MICROPY_PY_UCRYPTOLIB (MICROPY_PY_USSL) +#define MICROPY_PY_SSL_FINALISER (MICROPY_PY_SSL) +// #define MICROPY_PY_HASHLIB_MD5 (MICROPY_PY_SSL) +#define MICROPY_PY_HASHLIB_SHA1 (MICROPY_PY_SSL) +// #define MICROPY_PY_CRYPTOLIB (MICROPY_PY_SSL) // Prevent the "LWIP task" from running. #define MICROPY_PY_LWIP_ENTER MICROPY_PY_PENDSV_ENTER diff --git a/ports/nrf/boards/evk_nina_b3/mpconfigboard.h b/ports/nrf/boards/evk_nina_b3/mpconfigboard.h index eab232848b..d4ce93a0ac 100644 --- a/ports/nrf/boards/evk_nina_b3/mpconfigboard.h +++ b/ports/nrf/boards/evk_nina_b3/mpconfigboard.h @@ -41,8 +41,8 @@ #define MICROPY_EMIT_INLINE_THUMB (1) // Enable optional modules -#define MICROPY_PY_UERRNO (1) -#define MICROPY_PY_UHASHLIB (1) +#define MICROPY_PY_ERRNO (1) +#define MICROPY_PY_HASHLIB (1) // Peripherals Config #define MICROPY_PY_MACHINE_UART (1) diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 0799000b90..3a311fe5d9 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -80,8 +80,8 @@ #define MICROPY_PY_SYS_STDFILES (CORE_FEAT) #endif -#ifndef MICROPY_PY_UBINASCII -#define MICROPY_PY_UBINASCII (CORE_FEAT) +#ifndef MICROPY_PY_BINASCII +#define MICROPY_PY_BINASCII (CORE_FEAT) #endif #ifndef MICROPY_PY_NRF @@ -134,7 +134,7 @@ #endif // Use port specific os module rather than extmod variant. -#define MICROPY_PY_UOS (0) +#define MICROPY_PY_OS (0) #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1) @@ -155,9 +155,9 @@ #define MICROPY_MODULE_BUILTIN_INIT (1) #define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_PY_SYS_MAXSIZE (1) -#define MICROPY_PY_URANDOM (1) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) -#define MICROPY_PY_UTIME (1) +#define MICROPY_PY_RANDOM (1) +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (1) +#define MICROPY_PY_TIME (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PULSE (0) #define MICROPY_PY_MACHINE_SOFTI2C (MICROPY_PY_MACHINE_I2C) @@ -286,7 +286,7 @@ typedef unsigned int mp_uint_t; // must be pointer size typedef long mp_off_t; #if MICROPY_HW_ENABLE_RNG -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (rng_generate_random_word()) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rng_generate_random_word()) long unsigned int rng_generate_random_word(void); #endif diff --git a/ports/qemu-arm/mpconfigport.h b/ports/qemu-arm/mpconfigport.h index 972dce61b4..0eada5a529 100644 --- a/ports/qemu-arm/mpconfigport.h +++ b/ports/qemu-arm/mpconfigport.h @@ -36,16 +36,16 @@ #define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_MAXSIZE (1) #define MICROPY_PY_SYS_PLATFORM "qemu-arm" -#define MICROPY_PY_UERRNO (1) -#define MICROPY_PY_UBINASCII (1) -#define MICROPY_PY_URANDOM (1) +#define MICROPY_PY_ERRNO (1) +#define MICROPY_PY_BINASCII (1) +#define MICROPY_PY_RANDOM (1) #define MICROPY_PY_UCTYPES (1) -#define MICROPY_PY_UZLIB (1) -#define MICROPY_PY_UJSON (1) -#define MICROPY_PY_UOS (1) -#define MICROPY_PY_URE (1) -#define MICROPY_PY_UHEAPQ (1) -#define MICROPY_PY_UHASHLIB (1) +#define MICROPY_PY_ZLIB (1) +#define MICROPY_PY_JSON (1) +#define MICROPY_PY_OS (1) +#define MICROPY_PY_RE (1) +#define MICROPY_PY_HEAPQ (1) +#define MICROPY_PY_HASHLIB (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_USE_INTERNAL_PRINTF (1) diff --git a/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h index cd699e51bd..4845c0c09e 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h @@ -10,8 +10,8 @@ #define MICROPY_PY_BUILTINS_COMPLEX (0) #define MICROPY_PY_GENERATOR_PEND_THROW (0) #define MICROPY_PY_MATH (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UTIMEQ (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_TIMEQ (0) #define MICROPY_PY_THREAD (0) // peripheral config diff --git a/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.h index 5fd2d1c6a3..d8d22ad72f 100644 --- a/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA4W1/mpconfigboard.h @@ -10,8 +10,8 @@ #define MICROPY_PY_BUILTINS_COMPLEX (1) #define MICROPY_PY_GENERATOR_PEND_THROW (1) #define MICROPY_PY_MATH (1) -#define MICROPY_PY_UHEAPQ (1) -#define MICROPY_PY_UTIMEQ (1) +#define MICROPY_PY_HEAPQ (1) +#define MICROPY_PY_TIMEQ (1) #define MICROPY_PY_THREAD (0) // disable ARM_THUMB_FP using vldr due to RA has single float only // peripheral config diff --git a/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.h index b6f76a062e..d746dbdfc2 100644 --- a/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA6M1/mpconfigboard.h @@ -10,8 +10,8 @@ #define MICROPY_PY_BUILTINS_COMPLEX (1) #define MICROPY_PY_GENERATOR_PEND_THROW (1) #define MICROPY_PY_MATH (1) -#define MICROPY_PY_UHEAPQ (1) -#define MICROPY_PY_UTIMEQ (1) +#define MICROPY_PY_HEAPQ (1) +#define MICROPY_PY_TIMEQ (1) #define MICROPY_PY_THREAD (0) // disable ARM_THUMB_FP using vldr due to RA has single float only // peripheral config diff --git a/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.h index 9e3c462eec..b6ecfe6d49 100644 --- a/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA6M2/mpconfigboard.h @@ -10,8 +10,8 @@ #define MICROPY_PY_BUILTINS_COMPLEX (1) #define MICROPY_PY_GENERATOR_PEND_THROW (1) #define MICROPY_PY_MATH (1) -#define MICROPY_PY_UHEAPQ (1) -#define MICROPY_PY_UTIMEQ (1) +#define MICROPY_PY_HEAPQ (1) +#define MICROPY_PY_TIMEQ (1) #define MICROPY_PY_THREAD (0) // disable ARM_THUMB_FP using vldr due to RA has single float only // peripheral config diff --git a/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.h b/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.h index 7b8ccb1445..3934dd264b 100644 --- a/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.h +++ b/ports/renesas-ra/boards/RA4M1_CLICKER/mpconfigboard.h @@ -10,8 +10,8 @@ #define MICROPY_PY_BUILTINS_COMPLEX (0) #define MICROPY_PY_GENERATOR_PEND_THROW (0) #define MICROPY_PY_MATH (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UTIMEQ (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_TIMEQ (0) #define MICROPY_PY_THREAD (0) // peripheral config diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index 42834c1fbc..1886d31541 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -91,19 +91,19 @@ #endif // extended modules -#define MICROPY_PY_UOS_INCLUDEFILE "ports/renesas-ra/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/renesas-ra/moduos.c" #define MICROPY_PY_OS_DUPTERM (3) -#define MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM (1) -#define MICROPY_PY_UOS_DUPTERM_STREAM_DETACHED_ATTACHED (1) -#define MICROPY_PY_UOS_SEP (1) -#define MICROPY_PY_UOS_SYNC (1) -#define MICROPY_PY_UOS_UNAME (1) -#define MICROPY_PY_UOS_URANDOM (MICROPY_HW_ENABLE_RNG) -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/renesas-ra/modutime.c" -#ifndef MICROPY_PY_UTIMEQ -#define MICROPY_PY_UTIMEQ (1) +#define MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM (1) +#define MICROPY_PY_OS_DUPTERM_STREAM_DETACHED_ATTACHED (1) +#define MICROPY_PY_OS_SEP (1) +#define MICROPY_PY_OS_SYNC (1) +#define MICROPY_PY_OS_UNAME (1) +#define MICROPY_PY_OS_URANDOM (MICROPY_HW_ENABLE_RNG) +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/renesas-ra/modtime.c" +#ifndef MICROPY_PY_TIMEQ +#define MICROPY_PY_TIMEQ (1) #endif #ifndef MICROPY_PY_MACHINE #define MICROPY_PY_MACHINE (1) @@ -126,8 +126,8 @@ #ifndef MICROPY_PY_ONEWIRE #define MICROPY_PY_ONEWIRE (1) #endif -#ifndef MICROPY_PY_UPLATFORM -#define MICROPY_PY_UPLATFORM (1) +#ifndef MICROPY_PY_PLATFORM +#define MICROPY_PY_PLATFORM (1) #endif // fatfs configuration used in ffconf.h diff --git a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h index a4fb8b7c8c..98b9c0f6fa 100644 --- a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h +++ b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h @@ -8,7 +8,7 @@ #define MICROPY_PY_NETWORK (1) // Enable MD5 hash. -#define MICROPY_PY_UHASHLIB_MD5 (1) +#define MICROPY_PY_HASHLIB_MD5 (1) // Disable internal error numbers. #define MICROPY_USE_INTERNAL_ERRNO (0) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 720e858f19..de05a281bd 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -95,21 +95,21 @@ // Extended modules #define MICROPY_EPOCH_IS_1970 (1) -#define MICROPY_PY_UOS_INCLUDEFILE "ports/rp2/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/rp2/moduos.c" #ifndef MICROPY_PY_OS_DUPTERM #define MICROPY_PY_OS_DUPTERM (1) #endif -#define MICROPY_PY_UOS_SYNC (1) -#define MICROPY_PY_UOS_UNAME (1) -#define MICROPY_PY_UOS_URANDOM (1) -#define MICROPY_PY_URE_MATCH_GROUPS (1) -#define MICROPY_PY_URE_MATCH_SPAN_START_END (1) -#define MICROPY_PY_UHASHLIB_SHA1 (1) -#define MICROPY_PY_UCRYPTOLIB (1) -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/rp2/modutime.c" -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (rosc_random_u32()) +#define MICROPY_PY_OS_SYNC (1) +#define MICROPY_PY_OS_UNAME (1) +#define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_PY_RE_MATCH_GROUPS (1) +#define MICROPY_PY_RE_MATCH_SPAN_START_END (1) +#define MICROPY_PY_HASHLIB_SHA1 (1) +#define MICROPY_PY_CRYPTOLIB (1) +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/rp2/modutime.c" +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rosc_random_u32()) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new #define MICROPY_PY_MACHINE_BITSTREAM (1) @@ -151,14 +151,14 @@ #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-rp2" #endif -#ifndef MICROPY_PY_USOCKET -#define MICROPY_PY_USOCKET (1) +#ifndef MICROPY_PY_SOCKET +#define MICROPY_PY_SOCKET (1) #endif -#ifndef MICROPY_PY_USSL -#define MICROPY_PY_USSL (1) +#ifndef MICROPY_PY_SSL +#define MICROPY_PY_SSL (1) #endif -#ifndef MICROPY_PY_UWEBSOCKET -#define MICROPY_PY_UWEBSOCKET (1) +#ifndef MICROPY_PY_WEBSOCKET +#define MICROPY_PY_WEBSOCKET (1) #endif #ifndef MICROPY_PY_WEBREPL #define MICROPY_PY_WEBREPL (1) @@ -181,8 +181,8 @@ extern const struct _mp_obj_type_t mp_network_cyw43_type; #if MICROPY_PY_NETWORK_NINAW10 // This Network interface requires the extended socket state. -#ifndef MICROPY_PY_USOCKET_EXTENDED_STATE -#define MICROPY_PY_USOCKET_EXTENDED_STATE (1) +#ifndef MICROPY_PY_SOCKET_EXTENDED_STATE +#define MICROPY_PY_SOCKET_EXTENDED_STATE (1) #endif extern const struct _mp_obj_type_t mod_network_nic_type_nina; #define MICROPY_HW_NIC_NINAW10 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_nina) }, diff --git a/ports/samd/mcu/samd21/mpconfigmcu.h b/ports/samd/mcu/samd21/mpconfigmcu.h index df94b9682d..f70981acd5 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.h +++ b/ports/samd/mcu/samd21/mpconfigmcu.h @@ -14,8 +14,8 @@ #define MICROPY_PY_BUILTINS_COMPLEX (0) #endif -#ifndef MICROPY_PY_UTIME -#define MICROPY_PY_UTIME (1) +#ifndef MICROPY_PY_TIME +#define MICROPY_PY_TIME (1) #endif #ifndef MICROPY_PY_MATH @@ -26,7 +26,7 @@ #define MICROPY_PY_CMATH (0) #endif -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (trng_random_u32(300)) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32(300)) unsigned long trng_random_u32(int delay); #define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages; @@ -35,7 +35,7 @@ unsigned long trng_random_u32(int delay); #define MICROPY_HW_UART_TXBUF (1) #endif -#define MICROPY_PY_UOS_URANDOM (1) +#define MICROPY_PY_OS_URANDOM (1) #ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU #define MICROPY_PY_MACHINE_PIN_BOARD_CPU (1) diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index 0c2d2370ff..1569e5624d 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -27,9 +27,9 @@ #define MICROPY_PY_MACHINE_DHT_READINTO (1) #define MICROPY_PY_ONEWIRE (1) -#define MICROPY_PY_UOS_SYNC (1) -#define MICROPY_PY_UOS_URANDOM (1) -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (trng_random_u32()) +#define MICROPY_PY_OS_SYNC (1) +#define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32()) unsigned long trng_random_u32(void); #ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU diff --git a/ports/samd/moduos.c b/ports/samd/moduos.c index 4438bf3c7b..f9df0cd996 100644 --- a/ports/samd/moduos.c +++ b/ports/samd/moduos.c @@ -69,7 +69,7 @@ uint32_t trng_random_u32(int delay) { #define TRNG_RANDOM_U32 trng_random_u32(10) #endif -#if MICROPY_PY_UOS_URANDOM +#if MICROPY_PY_OS_URANDOM STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; @@ -88,16 +88,16 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); -#endif // MICROPY_PY_UOS_URANDOM +#endif // MICROPY_PY_OS_URANDOM -#if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM +#if MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) { const mp_obj_type_t *type = mp_obj_get_type(stream); return type == &machine_uart_type; } #endif -#if MICROPY_PY_UOS_DUPTERM_NOTIFY +#if MICROPY_PY_OS_DUPTERM_NOTIFY STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; for (;;) { diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index a0a58a2fd7..8a9947468e 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -77,21 +77,21 @@ #define MICROPY_PY_IO_IOBASE (1) // Extended modules -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/samd/modutime.c" +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/samd/modtime.c" #define MICROPY_PY_MACHINE (1) -#define MICROPY_PY_UOS (1) -#define MICROPY_PY_UOS_INCLUDEFILE "ports/samd/moduos.c" +#define MICROPY_PY_OS (1) +#define MICROPY_PY_OS_INCLUDEFILE "ports/samd/modos.c" #define MICROPY_READER_VFS (1) #define MICROPY_VFS (1) -#define MICROPY_PY_UJSON (1) -#define MICROPY_PY_URE (1) -#define MICROPY_PY_UBINASCII (1) +#define MICROPY_PY_JSON (1) +#define MICROPY_PY_RE (1) +#define MICROPY_PY_BINASCII (1) #define MICROPY_PY_UCTYPES (1) -#define MICROPY_PY_UHEAPQ (1) -#define MICROPY_PY_URANDOM (1) -#define MICROPY_PY_UZLIB (1) +#define MICROPY_PY_HEAPQ (1) +#define MICROPY_PY_RANDOM (1) +#define MICROPY_PY_ZLIB (1) #define MICROPY_PY_UASYNCIO (1) #define MICROPY_PY_MACHINE_RTC (1) #ifndef MICROPY_PY_MACHINE_ADC diff --git a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk index 135b12b8c8..b927388c55 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk +++ b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk @@ -21,7 +21,7 @@ MICROPY_BLUETOOTH_NIMBLE = 1 MICROPY_BLUETOOTH_BTSTACK = 0 MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk index ebe9775e80..2c48c17f38 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk @@ -21,7 +21,7 @@ MICROPY_BLUETOOTH_NIMBLE = 1 MICROPY_BLUETOOTH_BTSTACK = 0 MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk index 3bfd40dc92..cf4d40e5fe 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk @@ -21,7 +21,7 @@ MICROPY_BLUETOOTH_NIMBLE = 1 MICROPY_BLUETOOTH_BTSTACK = 0 MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h b/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h index dfcca72afb..165284f31a 100644 --- a/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h +++ b/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h @@ -12,13 +12,13 @@ #define MICROPY_PY_GENERATOR_PEND_THROW (0) #define MICROPY_PY_MATH (0) #define MICROPY_PY_FRAMEBUF (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) #define MICROPY_PY_ONEWIRE (0) #define MICROPY_PY_STM (0) #define MICROPY_PY_PYB_LEGACY (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UTIMEQ (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_TIMEQ (0) #define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0) #define MICROPY_HW_ENABLE_RTC (1) diff --git a/ports/stm32/boards/ESPRUINO_PICO/mpconfigboard.h b/ports/stm32/boards/ESPRUINO_PICO/mpconfigboard.h index ed8178d7d4..cfc46491e0 100644 --- a/ports/stm32/boards/ESPRUINO_PICO/mpconfigboard.h +++ b/ports/stm32/boards/ESPRUINO_PICO/mpconfigboard.h @@ -4,7 +4,7 @@ #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) #define MICROPY_PY_BUILTINS_COMPLEX (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) #define MICROPY_HW_HAS_SWITCH (1) diff --git a/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h b/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h index d44bfb0bb6..39d0082d7b 100644 --- a/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h @@ -5,12 +5,12 @@ #define MICROPY_EMIT_INLINE_THUMB (0) #define MICROPY_OPT_COMPUTED_GOTO (0) #define MICROPY_PY_BUILTINS_COMPLEX (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) #define MICROPY_PY_STM (0) #define MICROPY_PY_PYB_LEGACY (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UTIMEQ (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_TIMEQ (0) #define MICROPY_PY_FRAMEBUF (0) #define MICROPY_HW_ENABLE_RTC (1) diff --git a/ports/stm32/boards/NUCLEO_F429ZI/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F429ZI/mpconfigboard.mk index 9e82be1dc7..e5fc89ab47 100644 --- a/ports/stm32/boards/NUCLEO_F429ZI/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_F429ZI/mpconfigboard.mk @@ -7,7 +7,7 @@ TEXT1_ADDR = 0x08020000 # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/NUCLEO_F439ZI/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F439ZI/mpconfigboard.mk index 69b0f80a2d..b8666755b0 100644 --- a/ports/stm32/boards/NUCLEO_F439ZI/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_F439ZI/mpconfigboard.mk @@ -7,7 +7,7 @@ TEXT1_ADDR = 0x08020000 # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/NUCLEO_F746ZG/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F746ZG/mpconfigboard.mk index 9506b67595..20acc63f16 100644 --- a/ports/stm32/boards/NUCLEO_F746ZG/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_F746ZG/mpconfigboard.mk @@ -7,7 +7,7 @@ TEXT1_ADDR = 0x08020000 # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/NUCLEO_F756ZG/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F756ZG/mpconfigboard.mk index 90fc242f9a..ab3eada5b0 100644 --- a/ports/stm32/boards/NUCLEO_F756ZG/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_F756ZG/mpconfigboard.mk @@ -7,7 +7,7 @@ TEXT1_ADDR = 0x08020000 # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/NUCLEO_F767ZI/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F767ZI/mpconfigboard.mk index 6ef9d42f9d..22c4098159 100644 --- a/ports/stm32/boards/NUCLEO_F767ZI/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_F767ZI/mpconfigboard.mk @@ -8,7 +8,7 @@ TEXT1_ADDR = 0x08020000 # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h index 31157dd2c4..336d95c42c 100644 --- a/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h @@ -10,13 +10,13 @@ #define MICROPY_HW_HAS_FLASH (0) // QSPI extflash not mounted #define MICROPY_PY_UASYNCIO (0) -#define MICROPY_PY_UZLIB (0) -#define MICROPY_PY_UBINASCII (0) -#define MICROPY_PY_UHASHLIB (0) -#define MICROPY_PY_UJSON (0) -#define MICROPY_PY_URE (0) +#define MICROPY_PY_ZLIB (0) +#define MICROPY_PY_BINASCII (0) +#define MICROPY_PY_HASHLIB (0) +#define MICROPY_PY_JSON (0) +#define MICROPY_PY_RE (0) #define MICROPY_PY_FRAMEBUF (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) // The board has an 24MHz HSE, the following gives 170MHz CPU speed diff --git a/ports/stm32/boards/NUCLEO_H723ZG/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_H723ZG/mpconfigboard.mk index 287b51f6d8..6d512ec0ed 100644 --- a/ports/stm32/boards/NUCLEO_H723ZG/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_H723ZG/mpconfigboard.mk @@ -18,7 +18,7 @@ endif # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 MICROPY_VFS_LFS2 = 1 diff --git a/ports/stm32/boards/NUCLEO_H743ZI/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_H743ZI/mpconfigboard.mk index ea95fd0074..cbdf48c52a 100644 --- a/ports/stm32/boards/NUCLEO_H743ZI/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_H743ZI/mpconfigboard.mk @@ -18,7 +18,7 @@ endif # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 MICROPY_VFS_LFS2 = 1 diff --git a/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h b/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h index c8c809eb48..1d6b303260 100644 --- a/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h @@ -12,13 +12,13 @@ #define MICROPY_PY_GENERATOR_PEND_THROW (0) #define MICROPY_PY_MATH (0) #define MICROPY_PY_FRAMEBUF (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) #define MICROPY_PY_ONEWIRE (0) #define MICROPY_PY_STM (0) #define MICROPY_PY_PYB_LEGACY (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UTIMEQ (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_TIMEQ (0) #define MICROPY_PY_MACHINE_BITSTREAM (0) diff --git a/ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.h b/ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.h index 5e05053cdd..ba843c8a61 100644 --- a/ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.h @@ -6,13 +6,13 @@ #define MICROPY_OPT_COMPUTED_GOTO (0) #define MICROPY_PY_BUILTINS_COMPLEX (0) #define MICROPY_PY_GENERATOR_PEND_THROW (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) #define MICROPY_PY_ONEWIRE (0) #define MICROPY_PY_STM (0) #define MICROPY_PY_PYB_LEGACY (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UTIMEQ (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_TIMEQ (0) #define MICROPY_HW_ENABLE_RTC (1) #define MICROPY_HW_ENABLE_ADC (1) diff --git a/ports/stm32/boards/NUCLEO_L452RE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_L452RE/mpconfigboard.h index 1b5827d5ae..b0fab45956 100644 --- a/ports/stm32/boards/NUCLEO_L452RE/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_L452RE/mpconfigboard.h @@ -1,7 +1,7 @@ #define MICROPY_HW_BOARD_NAME "NUCLEO-L452RE" #define MICROPY_HW_MCU_NAME "STM32L452RE" -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) #define MICROPY_HW_ENABLE_RTC (1) diff --git a/ports/stm32/boards/NUCLEO_WL55/mpconfigboard.h b/ports/stm32/boards/NUCLEO_WL55/mpconfigboard.h index baf1f023be..2bb368adcc 100644 --- a/ports/stm32/boards/NUCLEO_WL55/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_WL55/mpconfigboard.h @@ -11,13 +11,13 @@ #define MICROPY_PY_GENERATOR_PEND_THROW (0) #define MICROPY_PY_MATH (0) #define MICROPY_PY_FRAMEBUF (0) -#define MICROPY_PY_USOCKET (0) +#define MICROPY_PY_SOCKET (0) #define MICROPY_PY_NETWORK (0) #define MICROPY_PY_ONEWIRE (0) #define MICROPY_PY_STM (0) #define MICROPY_PY_PYB_LEGACY (0) -#define MICROPY_PY_UHEAPQ (0) -#define MICROPY_PY_UTIMEQ (0) +#define MICROPY_PY_HEAPQ (0) +#define MICROPY_PY_TIMEQ (0) #define MICROPY_HW_HAS_FLASH (1) #define MICROPY_HW_ENABLE_RTC (1) diff --git a/ports/stm32/boards/OLIMEX_E407/mpconfigboard.mk b/ports/stm32/boards/OLIMEX_E407/mpconfigboard.mk index 0d3eee83be..aa11fd5492 100644 --- a/ports/stm32/boards/OLIMEX_E407/mpconfigboard.mk +++ b/ports/stm32/boards/OLIMEX_E407/mpconfigboard.mk @@ -7,5 +7,5 @@ TEXT1_ADDR = 0x08020000 # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 diff --git a/ports/stm32/boards/PYBD_SF2/mpconfigboard.mk b/ports/stm32/boards/PYBD_SF2/mpconfigboard.mk index 6615a44a53..ee481e344f 100644 --- a/ports/stm32/boards/PYBD_SF2/mpconfigboard.mk +++ b/ports/stm32/boards/PYBD_SF2/mpconfigboard.mk @@ -15,7 +15,7 @@ MICROPY_BLUETOOTH_NIMBLE ?= 1 MICROPY_BLUETOOTH_BTSTACK ?= 0 MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 MICROPY_VFS_LFS2 = 1 diff --git a/ports/stm32/boards/PYBD_SF3/mpconfigboard.mk b/ports/stm32/boards/PYBD_SF3/mpconfigboard.mk index 550094b743..cb8c44361c 100644 --- a/ports/stm32/boards/PYBD_SF3/mpconfigboard.mk +++ b/ports/stm32/boards/PYBD_SF3/mpconfigboard.mk @@ -15,7 +15,7 @@ MICROPY_BLUETOOTH_NIMBLE ?= 1 MICROPY_BLUETOOTH_BTSTACK ?= 0 MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 MICROPY_VFS_LFS2 = 1 diff --git a/ports/stm32/boards/PYBD_SF6/mpconfigboard.mk b/ports/stm32/boards/PYBD_SF6/mpconfigboard.mk index 9db2210559..943ddf60d3 100644 --- a/ports/stm32/boards/PYBD_SF6/mpconfigboard.mk +++ b/ports/stm32/boards/PYBD_SF6/mpconfigboard.mk @@ -12,7 +12,7 @@ MICROPY_BLUETOOTH_NIMBLE ?= 1 MICROPY_BLUETOOTH_BTSTACK ?= 0 MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 MICROPY_VFS_LFS2 = 1 diff --git a/ports/stm32/boards/STM32F769DISC/mpconfigboard.mk b/ports/stm32/boards/STM32F769DISC/mpconfigboard.mk index 6457fc6046..712906747c 100644 --- a/ports/stm32/boards/STM32F769DISC/mpconfigboard.mk +++ b/ports/stm32/boards/STM32F769DISC/mpconfigboard.mk @@ -42,7 +42,7 @@ endif # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/STM32F7DISC/mpconfigboard.mk b/ports/stm32/boards/STM32F7DISC/mpconfigboard.mk index 9506b67595..20acc63f16 100644 --- a/ports/stm32/boards/STM32F7DISC/mpconfigboard.mk +++ b/ports/stm32/boards/STM32F7DISC/mpconfigboard.mk @@ -7,7 +7,7 @@ TEXT1_ADDR = 0x08020000 # MicroPython settings MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/boards/VCC_GND_F407ZG/mpconfigboard.mk b/ports/stm32/boards/VCC_GND_F407ZG/mpconfigboard.mk index a30a6137d3..2d3e4cec4f 100644 --- a/ports/stm32/boards/VCC_GND_F407ZG/mpconfigboard.mk +++ b/ports/stm32/boards/VCC_GND_F407ZG/mpconfigboard.mk @@ -6,7 +6,7 @@ TEXT0_ADDR = 0x08000000 TEXT1_ADDR = 0x08020000 MICROPY_PY_LWIP = 1 -MICROPY_PY_USSL = 1 +MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py diff --git a/ports/stm32/moduos.c b/ports/stm32/moduos.c index bfbb868e2f..43543aa55e 100644 --- a/ports/stm32/moduos.c +++ b/ports/stm32/moduos.c @@ -29,7 +29,7 @@ #include "usb.h" #include "uart.h" -#if MICROPY_PY_UOS_URANDOM +#if MICROPY_PY_OS_URANDOM // urandom(n) // Return a bytes object with n random bytes, generated by the hardware // random number generator. diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index 62784dccf1..49a8a03405 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -92,24 +92,24 @@ #endif // extended modules -#define MICROPY_PY_USSL_FINALISER (MICROPY_PY_USSL) -#define MICROPY_PY_UHASHLIB_MD5 (MICROPY_PY_USSL) -#define MICROPY_PY_UHASHLIB_SHA1 (MICROPY_PY_USSL) -#define MICROPY_PY_UCRYPTOLIB (MICROPY_PY_USSL) -#define MICROPY_PY_UOS_INCLUDEFILE "ports/stm32/moduos.c" +#define MICROPY_PY_SSL_FINALISER (MICROPY_PY_SSL) +#define MICROPY_PY_HASHLIB_MD5 (MICROPY_PY_SSL) +#define MICROPY_PY_HASHLIB_SHA1 (MICROPY_PY_SSL) +#define MICROPY_PY_CRYPTOLIB (MICROPY_PY_SSL) +#define MICROPY_PY_OS_INCLUDEFILE "ports/stm32/moduos.c" #define MICROPY_PY_OS_DUPTERM (3) -#define MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM (1) -#define MICROPY_PY_UOS_DUPTERM_STREAM_DETACHED_ATTACHED (1) -#define MICROPY_PY_UOS_SEP (1) -#define MICROPY_PY_UOS_SYNC (1) -#define MICROPY_PY_UOS_UNAME (1) -#define MICROPY_PY_UOS_URANDOM (MICROPY_HW_ENABLE_RNG) -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (rng_get()) -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/stm32/modutime.c" -#ifndef MICROPY_PY_UTIMEQ -#define MICROPY_PY_UTIMEQ (1) +#define MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM (1) +#define MICROPY_PY_OS_DUPTERM_STREAM_DETACHED_ATTACHED (1) +#define MICROPY_PY_OS_SEP (1) +#define MICROPY_PY_OS_SYNC (1) +#define MICROPY_PY_OS_UNAME (1) +#define MICROPY_PY_OS_URANDOM (MICROPY_HW_ENABLE_RNG) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rng_get()) +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/stm32/modutime.c" +#ifndef MICROPY_PY_TIMEQ +#define MICROPY_PY_TIMEQ (1) #endif #define MICROPY_PY_LWIP_SOCK_RAW (MICROPY_PY_LWIP) #ifndef MICROPY_PY_MACHINE @@ -130,10 +130,10 @@ #endif #define MICROPY_HW_SOFTSPI_MIN_DELAY (0) #define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (HAL_RCC_GetSysClockFreq() / 48) -#define MICROPY_PY_UWEBSOCKET (MICROPY_PY_LWIP) +#define MICROPY_PY_WEBSOCKET (MICROPY_PY_LWIP) #define MICROPY_PY_WEBREPL (MICROPY_PY_LWIP) -#ifndef MICROPY_PY_USOCKET -#define MICROPY_PY_USOCKET (1) +#ifndef MICROPY_PY_SOCKET +#define MICROPY_PY_SOCKET (1) #endif #ifndef MICROPY_PY_NETWORK #define MICROPY_PY_NETWORK (1) @@ -141,8 +141,8 @@ #ifndef MICROPY_PY_ONEWIRE #define MICROPY_PY_ONEWIRE (1) #endif -#ifndef MICROPY_PY_UPLATFORM -#define MICROPY_PY_UPLATFORM (1) +#ifndef MICROPY_PY_PLATFORM +#define MICROPY_PY_PLATFORM (1) #endif // fatfs configuration used in ffconf.h @@ -324,5 +324,5 @@ static inline mp_uint_t disable_irq(void) { // We need to provide a declaration/definition of alloca() #include -// Needed for MICROPY_PY_URANDOM_SEED_INIT_FUNC. +// Needed for MICROPY_PY_RANDOM_SEED_INIT_FUNC. uint32_t rng_get(void); diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 0ff2e4b6e8..9ff19aab98 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -138,7 +138,7 @@ CFLAGS += -DMICROPY_PY_THREAD=1 -DMICROPY_PY_THREAD_GIL=0 LDFLAGS += $(LIBPTHREAD) endif -ifeq ($(MICROPY_PY_USSL),1) +ifeq ($(MICROPY_PY_SSL),1) ifeq ($(MICROPY_SSL_AXTLS),1) endif diff --git a/ports/unix/README.md b/ports/unix/README.md index a3a0dba75a..a3159a3262 100644 --- a/ports/unix/README.md +++ b/ports/unix/README.md @@ -70,5 +70,5 @@ or not). If you intend to build MicroPython with additional options (like cross-compiling), the same set of options should be passed to `make deplibs`. To actually enable/disable use of dependencies, edit the `ports/unix/mpconfigport.mk` file, which has inline descriptions of the -options. For example, to build the SSL module, `MICROPY_PY_USSL` should be +options. For example, to build the SSL module, `MICROPY_PY_SSL` should be set to 1. diff --git a/ports/unix/mbedtls/mbedtls_config.h b/ports/unix/mbedtls/mbedtls_config.h index c8ffab0832..629064abcf 100644 --- a/ports/unix/mbedtls/mbedtls_config.h +++ b/ports/unix/mbedtls/mbedtls_config.h @@ -27,7 +27,7 @@ #define MICROPY_INCLUDED_MBEDTLS_CONFIG_H // Set mbedtls configuration -#define MBEDTLS_CIPHER_MODE_CTR // needed for MICROPY_PY_UCRYPTOLIB_CTR +#define MBEDTLS_CIPHER_MODE_CTR // needed for MICROPY_PY_CRYPTOLIB_CTR // Enable mbedtls modules #define MBEDTLS_HAVEGE_C diff --git a/ports/unix/moduselect.c b/ports/unix/moduselect.c index 9f7f452a12..97c3602e4b 100644 --- a/ports/unix/moduselect.c +++ b/ports/unix/moduselect.c @@ -27,10 +27,10 @@ #include "py/mpconfig.h" -#if MICROPY_PY_USELECT_POSIX +#if MICROPY_PY_SELECT_POSIX -#if MICROPY_PY_USELECT -#error "Can't have both MICROPY_PY_USELECT and MICROPY_PY_USELECT_POSIX." +#if MICROPY_PY_SELECT +#error "Can't have both MICROPY_PY_SELECT and MICROPY_PY_SELECT_POSIX." #endif #include @@ -353,4 +353,4 @@ const mp_obj_module_t mp_module_select = { MP_REGISTER_MODULE(MP_QSTR_select, mp_module_select); -#endif // MICROPY_PY_USELECT_POSIX +#endif // MICROPY_PY_SELECT_POSIX diff --git a/ports/unix/modusocket.c b/ports/unix/modusocket.c index d8a615b469..9854f3cbce 100644 --- a/ports/unix/modusocket.c +++ b/ports/unix/modusocket.c @@ -146,7 +146,7 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i case MP_STREAM_GET_FILENO: return self->fd; - #if MICROPY_PY_USELECT + #if MICROPY_PY_SELECT case MP_STREAM_POLL: { mp_uint_t ret = 0; uint8_t pollevents = 0; @@ -227,7 +227,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]); - int backlog = MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT; + int backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; if (n_args > 1) { backlog = (int)mp_obj_get_int(args[1]); backlog = (backlog < 0) ? 0 : backlog; diff --git a/ports/unix/modutime.c b/ports/unix/modutime.c index 26c2fbdb90..b6fbae0d1c 100644 --- a/ports/unix/modutime.c +++ b/ports/unix/modutime.c @@ -200,7 +200,7 @@ STATIC mp_obj_t mod_time_mktime(mp_obj_t tuple) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_time_mktime_obj, mod_time_mktime); -#define MICROPY_PY_UTIME_EXTRA_GLOBALS \ +#define MICROPY_PY_TIME_EXTRA_GLOBALS \ { MP_ROM_QSTR(MP_QSTR_clock), MP_ROM_PTR(&mod_time_clock_obj) }, \ { MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mod_time_gmtime_obj) }, \ { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mod_time_localtime_obj) }, \ diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 0588e100d6..58aba9700b 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -160,7 +160,7 @@ typedef long mp_off_t; // Enable sys.executable. #define MICROPY_PY_SYS_EXECUTABLE (1) -#define MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT (SOMAXCONN < 128 ? SOMAXCONN : 128) +#define MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT (SOMAXCONN < 128 ? SOMAXCONN : 128) // Bare-metal ports don't have stderr. Printing debug to stderr may give tests // which check stdout a chance to pass, etc. @@ -181,7 +181,7 @@ void mp_unix_mark_exec(void); #endif // If enabled, configure how to seed random on init. -#ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC +#ifdef MICROPY_PY_RANDOM_SEED_INIT_FUNC #include void mp_hal_get_random(size_t n, void *buf); static inline unsigned long mp_random_seed_init(void) { diff --git a/ports/unix/mpconfigport.mk b/ports/unix/mpconfigport.mk index ce6183c133..c8ade0b7e2 100644 --- a/ports/unix/mpconfigport.mk +++ b/ports/unix/mpconfigport.mk @@ -23,8 +23,8 @@ MICROPY_PY_SOCKET = 1 # ffi module requires libffi (libffi-dev Debian package) MICROPY_PY_FFI = 1 -# ussl module requires one of the TLS libraries below -MICROPY_PY_USSL = 1 +# ssl module requires one of the TLS libraries below +MICROPY_PY_SSL = 1 # axTLS has minimal size but implements only a subset of modern TLS # functionality, so may have problems with some servers. MICROPY_SSL_AXTLS = 0 diff --git a/ports/unix/variants/coverage/mpconfigvariant.h b/ports/unix/variants/coverage/mpconfigvariant.h index 2a48e57e7f..e24e0f1b14 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.h +++ b/ports/unix/variants/coverage/mpconfigvariant.h @@ -41,4 +41,4 @@ #define MICROPY_DEBUG_PARSE_RULE_NAME (1) #define MICROPY_TRACKED_ALLOC (1) #define MICROPY_WARNINGS_CATEGORY (1) -#define MICROPY_PY_UCRYPTOLIB_CTR (1) +#define MICROPY_PY_CRYPTOLIB_CTR (1) diff --git a/ports/unix/variants/minimal/mpconfigvariant.h b/ports/unix/variants/minimal/mpconfigvariant.h index 6b107e7790..0dbfbb3d1c 100644 --- a/ports/unix/variants/minimal/mpconfigvariant.h +++ b/ports/unix/variants/minimal/mpconfigvariant.h @@ -63,7 +63,7 @@ // Enable just the sys and os built-in modules. #define MICROPY_PY_SYS (1) -#define MICROPY_PY_UOS (1) +#define MICROPY_PY_OS (1) // The minimum sets this to 1 to save flash. #define MICROPY_QSTR_BYTES_IN_HASH (2) diff --git a/ports/unix/variants/minimal/mpconfigvariant.mk b/ports/unix/variants/minimal/mpconfigvariant.mk index d5c2a52e9a..19b3460ed5 100644 --- a/ports/unix/variants/minimal/mpconfigvariant.mk +++ b/ports/unix/variants/minimal/mpconfigvariant.mk @@ -7,7 +7,7 @@ MICROPY_PY_FFI = 0 MICROPY_PY_SOCKET = 0 MICROPY_PY_THREAD = 0 MICROPY_PY_TERMIOS = 0 -MICROPY_PY_USSL = 0 +MICROPY_PY_SSL = 0 MICROPY_USE_READLINE = 0 MICROPY_VFS_FAT = 0 diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index 9a8a524a22..cc50d426ce 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -58,7 +58,7 @@ #endif // Seed random on import. -#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (mp_random_seed_init()) +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (mp_random_seed_init()) // Allow exception details in low-memory conditions. #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) @@ -87,39 +87,39 @@ #define MICROPY_PY_SYS_EXC_INFO (1) // Configure the "os" module with extra unix features. -#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c" -#define MICROPY_PY_UOS_ERRNO (1) -#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1) -#define MICROPY_PY_UOS_SEP (1) -#define MICROPY_PY_UOS_SYSTEM (1) -#define MICROPY_PY_UOS_URANDOM (1) +#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/moduos.c" +#define MICROPY_PY_OS_ERRNO (1) +#define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1) +#define MICROPY_PY_OS_SEP (1) +#define MICROPY_PY_OS_SYSTEM (1) +#define MICROPY_PY_OS_URANDOM (1) // Enable the unix-specific "time" module. -#define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_CUSTOM_SLEEP (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/unix/modutime.c" +#define MICROPY_PY_TIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_CUSTOM_SLEEP (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/unix/modutime.c" // Enable the utimeq module used by the previous (v2) version of uasyncio. -#define MICROPY_PY_UTIMEQ (1) +#define MICROPY_PY_TIMEQ (1) -#if MICROPY_PY_USSL -#define MICROPY_PY_UHASHLIB_MD5 (1) -#define MICROPY_PY_UHASHLIB_SHA1 (1) -#define MICROPY_PY_UCRYPTOLIB (1) +#if MICROPY_PY_SSL +#define MICROPY_PY_HASHLIB_MD5 (1) +#define MICROPY_PY_HASHLIB_SHA1 (1) +#define MICROPY_PY_CRYPTOLIB (1) #endif // Use the posix implementation of the "select" module (unless the variant // specifically asks for the MicroPython version). -#ifndef MICROPY_PY_USELECT -#define MICROPY_PY_USELECT (0) +#ifndef MICROPY_PY_SELECT +#define MICROPY_PY_SELECT (0) #endif -#ifndef MICROPY_PY_USELECT_POSIX -#define MICROPY_PY_USELECT_POSIX (!MICROPY_PY_USELECT) +#ifndef MICROPY_PY_SELECT_POSIX +#define MICROPY_PY_SELECT_POSIX (!MICROPY_PY_SELECT) #endif // Enable the "websocket" module. -#define MICROPY_PY_UWEBSOCKET (1) +#define MICROPY_PY_WEBSOCKET (1) // Enable the "machine" module, mostly for machine.mem*. #define MICROPY_PY_MACHINE (1) diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index 5e56923d93..87e12562b1 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -130,29 +130,29 @@ #define MICROPY_STACKLESS_STRICT (0) #endif -#define MICROPY_PY_UOS (1) -#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c" -#define MICROPY_PY_UOS_ERRNO (1) -#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1) -#define MICROPY_PY_UOS_SEP (1) -#define MICROPY_PY_UOS_STATVFS (0) -#define MICROPY_PY_UOS_SYSTEM (1) -#define MICROPY_PY_UOS_URANDOM (1) -#define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_CUSTOM_SLEEP (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/unix/modutime.c" -#define MICROPY_PY_UERRNO (1) +#define MICROPY_PY_OS (1) +#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/moduos.c" +#define MICROPY_PY_OS_ERRNO (1) +#define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1) +#define MICROPY_PY_OS_SEP (1) +#define MICROPY_PY_OS_STATVFS (0) +#define MICROPY_PY_OS_SYSTEM (1) +#define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_PY_TIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_CUSTOM_SLEEP (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/unix/modutime.c" +#define MICROPY_PY_ERRNO (1) #define MICROPY_PY_UCTYPES (1) -#define MICROPY_PY_UZLIB (1) -#define MICROPY_PY_UJSON (1) -#define MICROPY_PY_URE (1) -#define MICROPY_PY_UHEAPQ (1) -#define MICROPY_PY_UTIMEQ (1) -#define MICROPY_PY_UHASHLIB (1) -#define MICROPY_PY_UBINASCII (1) -#define MICROPY_PY_UBINASCII_CRC32 (1) -#define MICROPY_PY_URANDOM (1) +#define MICROPY_PY_ZLIB (1) +#define MICROPY_PY_JSON (1) +#define MICROPY_PY_RE (1) +#define MICROPY_PY_HEAPQ (1) +#define MICROPY_PY_TIMEQ (1) +#define MICROPY_PY_HASHLIB (1) +#define MICROPY_PY_BINASCII (1) +#define MICROPY_PY_BINASCII_CRC32 (1) +#define MICROPY_PY_RANDOM (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr diff --git a/ports/windows/variants/dev/mpconfigvariant.h b/ports/windows/variants/dev/mpconfigvariant.h index abf43a0da9..d6ce7bf36f 100644 --- a/ports/windows/variants/dev/mpconfigvariant.h +++ b/ports/windows/variants/dev/mpconfigvariant.h @@ -34,9 +34,9 @@ #define MICROPY_PY_SYS_SETTRACE (1) #define MICROPY_PERSISTENT_CODE_SAVE (1) #define MICROPY_COMP_CONST (0) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (1) #define MICROPY_PY_BUILTINS_SLICE_INDICES (1) -#define MICROPY_PY_USELECT (1) +#define MICROPY_PY_SELECT (1) #ifndef MICROPY_PY_UASYNCIO #define MICROPY_PY_UASYNCIO (1) diff --git a/ports/zephyr/modusocket.c b/ports/zephyr/modusocket.c index c3356189ab..8d4197410c 100644 --- a/ports/zephyr/modusocket.c +++ b/ports/zephyr/modusocket.c @@ -25,7 +25,7 @@ */ #include "py/mpconfig.h" -#ifdef MICROPY_PY_USOCKET +#ifdef MICROPY_PY_SOCKET #include "py/runtime.h" #include "py/stream.h" @@ -190,7 +190,7 @@ STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { socket_obj_t *socket = args[0]; socket_check_closed(socket); - mp_int_t backlog = MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT; + mp_int_t backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; if (n_args > 1) { backlog = mp_obj_get_int(args[1]); backlog = (backlog < 0) ? 0 : backlog; @@ -475,4 +475,4 @@ const mp_obj_module_t mp_module_socket = { MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); -#endif // MICROPY_PY_USOCKET +#endif // MICROPY_PY_SOCKET diff --git a/ports/zephyr/modzsensor.c b/ports/zephyr/modzsensor.c index e35a1716f4..5b55f0ebba 100644 --- a/ports/zephyr/modzsensor.c +++ b/ports/zephyr/modzsensor.c @@ -145,4 +145,4 @@ const mp_obj_module_t mp_module_zsensor = { MP_REGISTER_MODULE(MP_QSTR_zsensor, mp_module_zsensor); -#endif // MICROPY_PY_UHASHLIB +#endif // MICROPY_PY_HASHLIB diff --git a/ports/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h index 30ccccb627..ec759bda77 100644 --- a/ports/zephyr/mpconfigport.h +++ b/ports/zephyr/mpconfigport.h @@ -72,8 +72,8 @@ #define MICROPY_PY_STRUCT (0) #ifdef CONFIG_NETWORKING // If we have networking, we likely want errno comfort -#define MICROPY_PY_UERRNO (1) -#define MICROPY_PY_USOCKET (1) +#define MICROPY_PY_ERRNO (1) +#define MICROPY_PY_SOCKET (1) #endif #ifdef CONFIG_BT #define MICROPY_PY_BLUETOOTH (1) @@ -82,12 +82,12 @@ #endif #define MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT (0) #endif -#define MICROPY_PY_UBINASCII (1) -#define MICROPY_PY_UHASHLIB (1) -#define MICROPY_PY_UOS (1) -#define MICROPY_PY_UTIME (1) -#define MICROPY_PY_UTIME_TIME_TIME_NS (1) -#define MICROPY_PY_UTIME_INCLUDEFILE "ports/zephyr/modutime.c" +#define MICROPY_PY_BINASCII (1) +#define MICROPY_PY_HASHLIB (1) +#define MICROPY_PY_OS (1) +#define MICROPY_PY_TIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/zephyr/modutime.c" #define MICROPY_PY_ZEPHYR (1) #define MICROPY_PY_ZSENSOR (1) #define MICROPY_PY_SYS_MODULES (0) diff --git a/ports/zephyr/prj.conf b/ports/zephyr/prj.conf index 90211e3657..6046690197 100644 --- a/ports/zephyr/prj.conf +++ b/ports/zephyr/prj.conf @@ -57,7 +57,7 @@ CONFIG_THREAD_ANALYZER=y CONFIG_THREAD_ANALYZER_USE_PRINTK=y CONFIG_THREAD_NAME=y -# Required for usocket.pkt_get_info() +# Required for socket.pkt_get_info() CONFIG_NET_BUF_POOL_USAGE=y # Required for zephyr.shell_exec() diff --git a/py/moduerrno.c b/py/moduerrno.c index ed172ae4d6..99ca101bd6 100644 --- a/py/moduerrno.c +++ b/py/moduerrno.c @@ -30,12 +30,12 @@ #include "py/obj.h" #include "py/mperrno.h" -#if MICROPY_PY_UERRNO +#if MICROPY_PY_ERRNO // This list can be defined per port in mpconfigport.h to tailor it to a // specific port's needs. If it's not defined then we provide a default. -#ifndef MICROPY_PY_UERRNO_LIST -#define MICROPY_PY_UERRNO_LIST \ +#ifndef MICROPY_PY_ERRNO_LIST +#define MICROPY_PY_ERRNO_LIST \ X(EPERM) \ X(ENOENT) \ X(EIO) \ @@ -61,10 +61,10 @@ #endif -#if MICROPY_PY_UERRNO_ERRORCODE +#if MICROPY_PY_ERRNO_ERRORCODE STATIC const mp_rom_map_elem_t errorcode_table[] = { #define X(e) { MP_ROM_INT(MP_##e), MP_ROM_QSTR(MP_QSTR_##e) }, - MICROPY_PY_UERRNO_LIST + MICROPY_PY_ERRNO_LIST #undef X }; @@ -83,12 +83,12 @@ STATIC const mp_obj_dict_t errorcode_dict = { STATIC const mp_rom_map_elem_t mp_module_errno_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_errno) }, - #if MICROPY_PY_UERRNO_ERRORCODE + #if MICROPY_PY_ERRNO_ERRORCODE { MP_ROM_QSTR(MP_QSTR_errorcode), MP_ROM_PTR(&errorcode_dict) }, #endif #define X(e) { MP_ROM_QSTR(MP_QSTR_##e), MP_ROM_INT(MP_##e) }, - MICROPY_PY_UERRNO_LIST + MICROPY_PY_ERRNO_LIST #undef X }; @@ -102,7 +102,7 @@ const mp_obj_module_t mp_module_errno = { MP_REGISTER_MODULE(MP_QSTR_errno, mp_module_errno); qstr mp_errno_to_str(mp_obj_t errno_val) { - #if MICROPY_PY_UERRNO_ERRORCODE + #if MICROPY_PY_ERRNO_ERRORCODE // We have the errorcode dict so can do a lookup using the hash map mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)&errorcode_dict.map, errno_val, MP_MAP_LOOKUP); if (elem == NULL) { @@ -121,4 +121,4 @@ qstr mp_errno_to_str(mp_obj_t errno_val) { #endif } -#endif // MICROPY_PY_UERRNO +#endif // MICROPY_PY_ERRNO diff --git a/py/mpconfig.h b/py/mpconfig.h index fbe8ba54e2..a004f548ad 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1459,40 +1459,40 @@ typedef double mp_float_t; #endif // Whether to provide "errno" module -#ifndef MICROPY_PY_UERRNO -#define MICROPY_PY_UERRNO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_ERRNO +#define MICROPY_PY_ERRNO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif // Whether to provide the errno.errorcode dict -#ifndef MICROPY_PY_UERRNO_ERRORCODE -#define MICROPY_PY_UERRNO_ERRORCODE (1) +#ifndef MICROPY_PY_ERRNO_ERRORCODE +#define MICROPY_PY_ERRNO_ERRORCODE (1) #endif // Whether to provide "select" module (baremetal implementation) -#ifndef MICROPY_PY_USELECT -#define MICROPY_PY_USELECT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_SELECT +#define MICROPY_PY_SELECT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif // Whether to enable the select() function in the "select" module (baremetal // implementation). This is present for compatibility but can be disabled to // save space. -#ifndef MICROPY_PY_USELECT_SELECT -#define MICROPY_PY_USELECT_SELECT (1) +#ifndef MICROPY_PY_SELECT_SELECT +#define MICROPY_PY_SELECT_SELECT (1) #endif // Whether to provide the "time" module -#ifndef MICROPY_PY_UTIME -#define MICROPY_PY_UTIME (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_BASIC_FEATURES) +#ifndef MICROPY_PY_TIME +#define MICROPY_PY_TIME (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_BASIC_FEATURES) #endif // Whether to provide time.gmtime/localtime/mktime functions -#ifndef MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME -#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (0) +#ifndef MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (0) #endif // Whether to provide time.time/time_ns functions -#ifndef MICROPY_PY_UTIME_TIME_TIME_NS -#define MICROPY_PY_UTIME_TIME_TIME_NS (0) +#ifndef MICROPY_PY_TIME_TIME_TIME_NS +#define MICROPY_PY_TIME_TIME_TIME_NS (0) #endif // Period of values returned by time.ticks_ms(), ticks_us(), ticks_cpu() @@ -1501,8 +1501,8 @@ typedef double mp_float_t; // minimum of them should be used. The value below is the maximum value // this parameter can take (corresponding to 30 bit tick values on 32-bit // system). -#ifndef MICROPY_PY_UTIME_TICKS_PERIOD -#define MICROPY_PY_UTIME_TICKS_PERIOD (MP_SMALL_INT_POSITIVE_MASK + 1) +#ifndef MICROPY_PY_TIME_TICKS_PERIOD +#define MICROPY_PY_TIME_TICKS_PERIOD (MP_SMALL_INT_POSITIVE_MASK + 1) #endif // Whether to provide "_thread" module @@ -1538,101 +1538,101 @@ typedef double mp_float_t; #define MICROPY_PY_UCTYPES_NATIVE_C_TYPES (1) #endif -#ifndef MICROPY_PY_UZLIB -#define MICROPY_PY_UZLIB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_ZLIB +#define MICROPY_PY_ZLIB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -#ifndef MICROPY_PY_UJSON -#define MICROPY_PY_UJSON (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_JSON +#define MICROPY_PY_JSON (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif // Whether to support the "separators" argument to dump, dumps -#ifndef MICROPY_PY_UJSON_SEPARATORS -#define MICROPY_PY_UJSON_SEPARATORS (1) +#ifndef MICROPY_PY_JSON_SEPARATORS +#define MICROPY_PY_JSON_SEPARATORS (1) #endif -#ifndef MICROPY_PY_UOS -#define MICROPY_PY_UOS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_OS +#define MICROPY_PY_OS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -#ifndef MICROPY_PY_UOS_STATVFS -#define MICROPY_PY_UOS_STATVFS (MICROPY_PY_UOS) +#ifndef MICROPY_PY_OS_STATVFS +#define MICROPY_PY_OS_STATVFS (MICROPY_PY_OS) #endif -#ifndef MICROPY_PY_URE -#define MICROPY_PY_URE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_RE +#define MICROPY_PY_RE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -#ifndef MICROPY_PY_URE_DEBUG -#define MICROPY_PY_URE_DEBUG (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) +#ifndef MICROPY_PY_RE_DEBUG +#define MICROPY_PY_RE_DEBUG (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) #endif -#ifndef MICROPY_PY_URE_MATCH_GROUPS -#define MICROPY_PY_URE_MATCH_GROUPS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) +#ifndef MICROPY_PY_RE_MATCH_GROUPS +#define MICROPY_PY_RE_MATCH_GROUPS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) #endif -#ifndef MICROPY_PY_URE_MATCH_SPAN_START_END -#define MICROPY_PY_URE_MATCH_SPAN_START_END (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) +#ifndef MICROPY_PY_RE_MATCH_SPAN_START_END +#define MICROPY_PY_RE_MATCH_SPAN_START_END (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) #endif -#ifndef MICROPY_PY_URE_SUB -#define MICROPY_PY_URE_SUB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_RE_SUB +#define MICROPY_PY_RE_SUB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -#ifndef MICROPY_PY_UHEAPQ -#define MICROPY_PY_UHEAPQ (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_HEAPQ +#define MICROPY_PY_HEAPQ (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif // Optimized heap queue for relative timestamps (only used by uasyncio v2) -#ifndef MICROPY_PY_UTIMEQ -#define MICROPY_PY_UTIMEQ (0) +#ifndef MICROPY_PY_TIMEQ +#define MICROPY_PY_TIMEQ (0) #endif -#ifndef MICROPY_PY_UHASHLIB -#define MICROPY_PY_UHASHLIB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_HASHLIB +#define MICROPY_PY_HASHLIB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -#ifndef MICROPY_PY_UHASHLIB_MD5 -#define MICROPY_PY_UHASHLIB_MD5 (0) +#ifndef MICROPY_PY_HASHLIB_MD5 +#define MICROPY_PY_HASHLIB_MD5 (0) #endif -#ifndef MICROPY_PY_UHASHLIB_SHA1 -#define MICROPY_PY_UHASHLIB_SHA1 (0) +#ifndef MICROPY_PY_HASHLIB_SHA1 +#define MICROPY_PY_HASHLIB_SHA1 (0) #endif -#ifndef MICROPY_PY_UHASHLIB_SHA256 -#define MICROPY_PY_UHASHLIB_SHA256 (1) +#ifndef MICROPY_PY_HASHLIB_SHA256 +#define MICROPY_PY_HASHLIB_SHA256 (1) #endif -#ifndef MICROPY_PY_UCRYPTOLIB -#define MICROPY_PY_UCRYPTOLIB (0) +#ifndef MICROPY_PY_CRYPTOLIB +#define MICROPY_PY_CRYPTOLIB (0) #endif -// Depends on MICROPY_PY_UCRYPTOLIB -#ifndef MICROPY_PY_UCRYPTOLIB_CTR -#define MICROPY_PY_UCRYPTOLIB_CTR (0) +// Depends on MICROPY_PY_CRYPTOLIB +#ifndef MICROPY_PY_CRYPTOLIB_CTR +#define MICROPY_PY_CRYPTOLIB_CTR (0) #endif -#ifndef MICROPY_PY_UCRYPTOLIB_CONSTS -#define MICROPY_PY_UCRYPTOLIB_CONSTS (0) +#ifndef MICROPY_PY_CRYPTOLIB_CONSTS +#define MICROPY_PY_CRYPTOLIB_CONSTS (0) #endif -#ifndef MICROPY_PY_UBINASCII -#define MICROPY_PY_UBINASCII (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_BINASCII +#define MICROPY_PY_BINASCII (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -// Depends on MICROPY_PY_UZLIB -#ifndef MICROPY_PY_UBINASCII_CRC32 -#define MICROPY_PY_UBINASCII_CRC32 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +// Depends on MICROPY_PY_ZLIB +#ifndef MICROPY_PY_BINASCII_CRC32 +#define MICROPY_PY_BINASCII_CRC32 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -#ifndef MICROPY_PY_URANDOM -#define MICROPY_PY_URANDOM (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_RANDOM +#define MICROPY_PY_RANDOM (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif // Whether to include: randrange, randint, choice, random, uniform -#ifndef MICROPY_PY_URANDOM_EXTRA_FUNCS -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_RANDOM_EXTRA_FUNCS +#define MICROPY_PY_RANDOM_EXTRA_FUNCS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif #ifndef MICROPY_PY_MACHINE @@ -1678,21 +1678,21 @@ typedef double mp_float_t; #endif // The default backlog value for socket.listen(backlog) -#ifndef MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT -#define MICROPY_PY_USOCKET_LISTEN_BACKLOG_DEFAULT (2) +#ifndef MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT +#define MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT (2) #endif -#ifndef MICROPY_PY_USSL -#define MICROPY_PY_USSL (0) +#ifndef MICROPY_PY_SSL +#define MICROPY_PY_SSL (0) #endif // Whether to add finaliser code to ssl objects -#ifndef MICROPY_PY_USSL_FINALISER -#define MICROPY_PY_USSL_FINALISER (0) +#ifndef MICROPY_PY_SSL_FINALISER +#define MICROPY_PY_SSL_FINALISER (0) #endif -#ifndef MICROPY_PY_UWEBSOCKET -#define MICROPY_PY_UWEBSOCKET (0) +#ifndef MICROPY_PY_WEBSOCKET +#define MICROPY_PY_WEBSOCKET (0) #endif #ifndef MICROPY_PY_FRAMEBUF diff --git a/py/mperrno.h b/py/mperrno.h index 6f6d816b8f..be2a65a088 100644 --- a/py/mperrno.h +++ b/py/mperrno.h @@ -141,7 +141,7 @@ #endif -#if MICROPY_PY_UERRNO +#if MICROPY_PY_ERRNO #include "py/obj.h" diff --git a/py/objbool.c b/py/objbool.c index 3267ff98bb..96f0e60dd1 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -45,7 +45,7 @@ typedef struct _mp_obj_bool_t { STATIC void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bool value = BOOL_VALUE(self_in); - if (MICROPY_PY_UJSON && kind == PRINT_JSON) { + if (MICROPY_PY_JSON && kind == PRINT_JSON) { if (value) { mp_print_str(print, "true"); } else { diff --git a/py/objdict.c b/py/objdict.c index a621c4feaf..8aafe607d6 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -75,10 +75,10 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ bool first = true; const char *item_separator = ", "; const char *key_separator = ": "; - if (!(MICROPY_PY_UJSON && kind == PRINT_JSON)) { + if (!(MICROPY_PY_JSON && kind == PRINT_JSON)) { kind = PRINT_REPR; } else { - #if MICROPY_PY_UJSON_SEPARATORS + #if MICROPY_PY_JSON_SEPARATORS item_separator = MP_PRINT_GET_EXT(print)->item_separator; key_separator = MP_PRINT_GET_EXT(print)->key_separator; #endif @@ -94,7 +94,7 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ mp_print_str(print, item_separator); } first = false; - bool add_quote = MICROPY_PY_UJSON && kind == PRINT_JSON && !mp_obj_is_str_or_bytes(next->key); + bool add_quote = MICROPY_PY_JSON && kind == PRINT_JSON && !mp_obj_is_str_or_bytes(next->key); if (add_quote) { mp_print_str(print, "\""); } diff --git a/py/objexcept.c b/py/objexcept.c index cc0ddd9dc5..a90405c525 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -178,7 +178,7 @@ void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin return; } - #if MICROPY_PY_UERRNO + #if MICROPY_PY_ERRNO // try to provide a nice OSError error message if (o->base.type == &mp_type_OSError && o->args->len > 0 && o->args->len < 3 && mp_obj_is_small_int(o->args->items[0])) { qstr qst = mp_errno_to_str(o->args->items[0]); diff --git a/py/objlist.c b/py/objlist.c index 18da91ba3a..1423cb1dee 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -45,10 +45,10 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_list_t *o = MP_OBJ_TO_PTR(o_in); const char *item_separator = ", "; - if (!(MICROPY_PY_UJSON && kind == PRINT_JSON)) { + if (!(MICROPY_PY_JSON && kind == PRINT_JSON)) { kind = PRINT_REPR; } else { - #if MICROPY_PY_UJSON_SEPARATORS + #if MICROPY_PY_JSON_SEPARATORS item_separator = MP_PRINT_GET_EXT(print)->item_separator; #endif } diff --git a/py/objnone.c b/py/objnone.c index 4b0696d3a1..5b25cd38c4 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_none_t { STATIC void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)self_in; - if (MICROPY_PY_UJSON && kind == PRINT_JSON) { + if (MICROPY_PY_JSON && kind == PRINT_JSON) { mp_print_str(print, "null"); } else { mp_print_str(print, "None"); diff --git a/py/objstr.c b/py/objstr.c index e6c5ee71cf..b966a70169 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -109,7 +109,7 @@ void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, size_t s mp_printf(print, "%c", quote_char); } -#if MICROPY_PY_UJSON +#if MICROPY_PY_JSON void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str_len) { // for JSON spec, see http://www.ietf.org/rfc/rfc4627.txt // if we are given a valid utf8-encoded string, we will print it in a JSON-conforming way @@ -137,7 +137,7 @@ void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str STATIC void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { GET_STR_DATA_LEN(self_in, str_data, str_len); - #if MICROPY_PY_UJSON + #if MICROPY_PY_JSON if (kind == PRINT_JSON) { mp_str_print_json(print, str_data, str_len); return; diff --git a/py/objstrunicode.c b/py/objstrunicode.c index 93383b3c19..cbc797de29 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -85,7 +85,7 @@ STATIC void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint STATIC void uni_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { GET_STR_DATA_LEN(self_in, str_data, str_len); - #if MICROPY_PY_UJSON + #if MICROPY_PY_JSON if (kind == PRINT_JSON) { mp_str_print_json(print, str_data, str_len); return; diff --git a/py/objtuple.c b/py/objtuple.c index 9d6797b4ff..0318a35db6 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -40,9 +40,9 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_tuple_t *o = MP_OBJ_TO_PTR(o_in); const char *item_separator = ", "; - if (MICROPY_PY_UJSON && kind == PRINT_JSON) { + if (MICROPY_PY_JSON && kind == PRINT_JSON) { mp_print_str(print, "["); - #if MICROPY_PY_UJSON_SEPARATORS + #if MICROPY_PY_JSON_SEPARATORS item_separator = MP_PRINT_GET_EXT(print)->item_separator; #endif } else { @@ -55,7 +55,7 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t } mp_obj_print_helper(print, o->items[i], kind); } - if (MICROPY_PY_UJSON && kind == PRINT_JSON) { + if (MICROPY_PY_JSON && kind == PRINT_JSON) { mp_print_str(print, "]"); } else { if (o->len == 1) { diff --git a/py/parse.c b/py/parse.c index a271aa0ea3..0dd56e4554 100644 --- a/py/parse.c +++ b/py/parse.c @@ -636,7 +636,7 @@ STATIC void push_result_token(parser_t *parser, uint8_t rule_id) { #if MICROPY_COMP_MODULE_CONST STATIC const mp_rom_map_elem_t mp_constants_table[] = { - #if MICROPY_PY_UERRNO + #if MICROPY_PY_ERRNO { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_errno) }, #endif #if MICROPY_PY_UCTYPES diff --git a/tools/ci.sh b/tools/ci.sh index e8c4021f37..8d361e2b39 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -395,14 +395,14 @@ function ci_teensy_build { CI_UNIX_OPTS_SYS_SETTRACE=( MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 - MICROPY_PY_USSL=0 + MICROPY_PY_SSL=0 CFLAGS_EXTRA="-DMICROPY_PY_SYS_SETTRACE=1" ) CI_UNIX_OPTS_SYS_SETTRACE_STACKLESS=( MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 - MICROPY_PY_USSL=0 + MICROPY_PY_SSL=0 CFLAGS_EXTRA="-DMICROPY_STACKLESS=1 -DMICROPY_STACKLESS_STRICT=1 -DMICROPY_PY_SYS_SETTRACE=1" ) From 0ceccd4cf809ef067feea8c42614b1bd07984451 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 18 Aug 2022 15:07:24 +1000 Subject: [PATCH 168/565] all: Rename *umodule*.h to remove the "u" prefix. This work was funded through GitHub Sponsors. Also updates #includes. Signed-off-by: Jim Mussared --- extmod/{moduplatform.h => modplatform.h} | 6 +++--- extmod/{modutime.h => modtime.h} | 0 extmod/moduplatform.c | 2 +- extmod/modutime.c | 2 +- extmod/moduwebsocket.c | 2 +- extmod/moduwebsocket.h | 10 ---------- extmod/modwebrepl.c | 2 +- extmod/modwebsocket.h | 10 ++++++++++ extmod/utime_mphal.h | 1 + ports/cc3200/ftp/ftp.c | 4 ++-- ports/cc3200/hal/cc3200_hal.c | 2 +- ports/cc3200/mods/modmachine.c | 2 +- ports/cc3200/mods/{moduos.h => modos.h} | 6 +++--- ports/cc3200/mods/{modusocket.h => modsocket.h} | 6 +++--- ports/cc3200/mods/moduos.c | 2 +- ports/cc3200/mods/modusocket.c | 2 +- ports/cc3200/mods/modussl.c | 2 +- ports/cc3200/mods/modwlan.c | 2 +- ports/cc3200/mods/pybuart.c | 2 +- ports/cc3200/mptask.c | 4 ++-- ports/cc3200/serverstask.c | 2 +- ports/cc3200/telnet/telnet.c | 2 +- ports/stm32/modpyb.c | 2 +- ports/unix/main.c | 2 +- py/modsys.c | 2 +- 25 files changed, 40 insertions(+), 39 deletions(-) rename extmod/{moduplatform.h => modplatform.h} (96%) rename extmod/{modutime.h => modtime.h} (100%) delete mode 100644 extmod/moduwebsocket.h create mode 100644 extmod/modwebsocket.h create mode 100644 extmod/utime_mphal.h rename ports/cc3200/mods/{moduos.h => modos.h} (92%) rename ports/cc3200/mods/{modusocket.h => modsocket.h} (91%) diff --git a/extmod/moduplatform.h b/extmod/modplatform.h similarity index 96% rename from extmod/moduplatform.h rename to extmod/modplatform.h index 7ca4297788..95bf073fbd 100644 --- a/extmod/moduplatform.h +++ b/extmod/modplatform.h @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_MODUPLATFORM_H -#define MICROPY_INCLUDED_MODUPLATFORM_H +#ifndef MICROPY_INCLUDED_MODPLATFORM_H +#define MICROPY_INCLUDED_MODPLATFORM_H #include "py/misc.h" // For MP_STRINGIFY. #include "py/mpconfig.h" @@ -102,4 +102,4 @@ #define MICROPY_PLATFORM_VERSION "" #endif -#endif // MICROPY_INCLUDED_MODUPLATFORM_H +#endif // MICROPY_INCLUDED_MODPLATFORM_H diff --git a/extmod/modutime.h b/extmod/modtime.h similarity index 100% rename from extmod/modutime.h rename to extmod/modtime.h diff --git a/extmod/moduplatform.c b/extmod/moduplatform.c index d5f919fc5e..4d10bdb4df 100644 --- a/extmod/moduplatform.c +++ b/extmod/moduplatform.c @@ -29,7 +29,7 @@ #include "py/objtuple.h" #include "py/objstr.h" #include "py/mphal.h" -#include "extmod/moduplatform.h" +#include "extmod/modplatform.h" #include "genhdr/mpversion.h" #if MICROPY_PY_PLATFORM diff --git a/extmod/modutime.c b/extmod/modutime.c index 1dfd7aa2c0..163b874d5e 100644 --- a/extmod/modutime.c +++ b/extmod/modutime.c @@ -28,7 +28,7 @@ #include "py/mphal.h" #include "py/runtime.h" #include "py/smallint.h" -#include "extmod/modutime.h" +#include "extmod/modtime.h" #if MICROPY_PY_TIME diff --git a/extmod/moduwebsocket.c b/extmod/moduwebsocket.c index ac90dea8b3..3bf50cc58c 100644 --- a/extmod/moduwebsocket.c +++ b/extmod/moduwebsocket.c @@ -30,7 +30,7 @@ #include "py/runtime.h" #include "py/stream.h" -#include "extmod/moduwebsocket.h" +#include "extmod/modwebsocket.h" #if MICROPY_PY_WEBSOCKET diff --git a/extmod/moduwebsocket.h b/extmod/moduwebsocket.h deleted file mode 100644 index c1ea291ed7..0000000000 --- a/extmod/moduwebsocket.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H -#define MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H - -#define FRAME_OPCODE_MASK 0x0f -enum { - FRAME_CONT, FRAME_TXT, FRAME_BIN, - FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG -}; - -#endif // MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c index d86f358962..64276b5a8f 100644 --- a/extmod/modwebrepl.c +++ b/extmod/modwebrepl.c @@ -34,7 +34,7 @@ #ifdef MICROPY_PY_WEBREPL_DELAY #include "py/mphal.h" #endif -#include "extmod/moduwebsocket.h" +#include "extmod/modwebsocket.h" #if MICROPY_PY_WEBREPL diff --git a/extmod/modwebsocket.h b/extmod/modwebsocket.h new file mode 100644 index 0000000000..2720147dfd --- /dev/null +++ b/extmod/modwebsocket.h @@ -0,0 +1,10 @@ +#ifndef MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H +#define MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H + +#define FRAME_OPCODE_MASK 0x0f +enum { + FRAME_CONT, FRAME_TXT, FRAME_BIN, + FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG +}; + +#endif // MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H diff --git a/extmod/utime_mphal.h b/extmod/utime_mphal.h new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/extmod/utime_mphal.h @@ -0,0 +1 @@ + diff --git a/ports/cc3200/ftp/ftp.c b/ports/cc3200/ftp/ftp.c index 173bb7c2c0..5d4fc6fb5f 100644 --- a/ports/cc3200/ftp/ftp.c +++ b/ports/cc3200/ftp/ftp.c @@ -42,13 +42,13 @@ #include "simplelink.h" #include "modnetwork.h" #include "modwlan.h" -#include "modusocket.h" +#include "modsocket.h" #include "debug.h" #include "serverstask.h" #include "fifo.h" #include "socketfifo.h" #include "updater.h" -#include "moduos.h" +#include "modos.h" /****************************************************************************** DEFINE PRIVATE CONSTANTS diff --git a/ports/cc3200/hal/cc3200_hal.c b/ports/cc3200/hal/cc3200_hal.c index 4694235eeb..4d9d7647d3 100644 --- a/ports/cc3200/hal/cc3200_hal.c +++ b/ports/cc3200/hal/cc3200_hal.c @@ -49,7 +49,7 @@ #include "pybuart.h" #include "utils.h" #include "irq.h" -#include "moduos.h" +#include "modos.h" #ifdef USE_FREERTOS #include "FreeRTOS.h" diff --git a/ports/cc3200/mods/modmachine.c b/ports/cc3200/mods/modmachine.c index c5b06f5077..a695fdccae 100644 --- a/ports/cc3200/mods/modmachine.c +++ b/ports/cc3200/mods/modmachine.c @@ -43,7 +43,7 @@ #include "simplelink.h" #include "modnetwork.h" #include "modwlan.h" -#include "moduos.h" +#include "modos.h" #include "FreeRTOS.h" #include "portable.h" #include "task.h" diff --git a/ports/cc3200/mods/moduos.h b/ports/cc3200/mods/modos.h similarity index 92% rename from ports/cc3200/mods/moduos.h rename to ports/cc3200/mods/modos.h index f183715c90..5fa2a967d4 100644 --- a/ports/cc3200/mods/moduos.h +++ b/ports/cc3200/mods/modos.h @@ -24,8 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_CC3200_MODS_MODUOS_H -#define MICROPY_INCLUDED_CC3200_MODS_MODUOS_H +#ifndef MICROPY_INCLUDED_CC3200_MODS_MODOS_H +#define MICROPY_INCLUDED_CC3200_MODS_MODOS_H #include "py/obj.h" @@ -44,4 +44,4 @@ typedef struct _os_term_dup_obj_t { ******************************************************************************/ void osmount_unmount_all (void); -#endif // MICROPY_INCLUDED_CC3200_MODS_MODUOS_H +#endif // MICROPY_INCLUDED_CC3200_MODS_MODOS_H diff --git a/ports/cc3200/mods/modusocket.h b/ports/cc3200/mods/modsocket.h similarity index 91% rename from ports/cc3200/mods/modusocket.h rename to ports/cc3200/mods/modsocket.h index aaee04ce19..8eb4cb50ac 100644 --- a/ports/cc3200/mods/modusocket.h +++ b/ports/cc3200/mods/modsocket.h @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H -#define MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H +#ifndef MICROPY_INCLUDED_CC3200_MODS_MODSOCKET_H +#define MICROPY_INCLUDED_CC3200_MODS_MODSOCKET_H #include "py/stream.h" @@ -37,4 +37,4 @@ extern void modusocket_socket_delete (int16_t sd); extern void modusocket_enter_sleep (void); extern void modusocket_close_all_user_sockets (void); -#endif // MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H +#endif // MICROPY_INCLUDED_CC3200_MODS_MODSOCKET_H diff --git a/ports/cc3200/mods/moduos.c b/ports/cc3200/mods/moduos.c index a6e4ef50a7..7b1e8d79fd 100644 --- a/ports/cc3200/mods/moduos.c +++ b/ports/cc3200/mods/moduos.c @@ -35,7 +35,7 @@ #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "genhdr/mpversion.h" -#include "moduos.h" +#include "modos.h" #include "sflash_diskio.h" #include "extmod/vfs.h" #include "extmod/vfs_fat.h" diff --git a/ports/cc3200/mods/modusocket.c b/ports/cc3200/mods/modusocket.c index 9b614c6d34..fd09cd6a41 100644 --- a/ports/cc3200/mods/modusocket.c +++ b/ports/cc3200/mods/modusocket.c @@ -37,7 +37,7 @@ #include "py/mphal.h" #include "shared/netutils/netutils.h" #include "modnetwork.h" -#include "modusocket.h" +#include "modsocket.h" /******************************************************************************/ // The following set of macros and functions provide a glue between the CC3100 diff --git a/ports/cc3200/mods/modussl.c b/ports/cc3200/mods/modussl.c index dda6725e66..eb3aea1f85 100644 --- a/ports/cc3200/mods/modussl.c +++ b/ports/cc3200/mods/modussl.c @@ -32,7 +32,7 @@ #include "py/objstr.h" #include "py/runtime.h" #include "modnetwork.h" -#include "modusocket.h" +#include "modsocket.h" /****************************************************************************** DEFINE CONSTANTS diff --git a/ports/cc3200/mods/modwlan.c b/ports/cc3200/mods/modwlan.c index bf243ce7b9..8d98dd0421 100644 --- a/ports/cc3200/mods/modwlan.c +++ b/ports/cc3200/mods/modwlan.c @@ -38,7 +38,7 @@ #include "shared/timeutils/timeutils.h" #include "shared/netutils/netutils.h" #include "modnetwork.h" -#include "modusocket.h" +#include "modsocket.h" #include "modwlan.h" #include "pybrtc.h" #include "debug.h" diff --git a/ports/cc3200/mods/pybuart.c b/ports/cc3200/mods/pybuart.c index 424ca251ec..5d6ad07527 100644 --- a/ports/cc3200/mods/pybuart.c +++ b/ports/cc3200/mods/pybuart.c @@ -50,7 +50,7 @@ #include "pin.h" #include "pybpin.h" #include "pins.h" -#include "moduos.h" +#include "modos.h" /// \moduleref pyb /// \class UART - duplex serial communication bus diff --git a/ports/cc3200/mptask.c b/ports/cc3200/mptask.c index a9dbf3c4c3..abf8484b0d 100644 --- a/ports/cc3200/mptask.c +++ b/ports/cc3200/mptask.c @@ -55,7 +55,7 @@ #include "mperror.h" #include "simplelink.h" #include "modnetwork.h" -#include "modusocket.h" +#include "modsocket.h" #include "modwlan.h" #include "serverstask.h" #include "telnet.h" @@ -70,7 +70,7 @@ #include "cryptohash.h" #include "mpirq.h" #include "updater.h" -#include "moduos.h" +#include "modos.h" #include "antenna.h" #include "task.h" diff --git a/ports/cc3200/serverstask.c b/ports/cc3200/serverstask.c index 4d852447f4..de782f5e7a 100644 --- a/ports/cc3200/serverstask.c +++ b/ports/cc3200/serverstask.c @@ -37,7 +37,7 @@ #include "telnet.h" #include "ftp.h" #include "pybwdt.h" -#include "modusocket.h" +#include "modsocket.h" #include "modnetwork.h" #include "modwlan.h" diff --git a/ports/cc3200/telnet/telnet.c b/ports/cc3200/telnet/telnet.c index df1fd1c22d..86843c78f6 100644 --- a/ports/cc3200/telnet/telnet.c +++ b/ports/cc3200/telnet/telnet.c @@ -33,7 +33,7 @@ #include "simplelink.h" #include "modnetwork.h" #include "modwlan.h" -#include "modusocket.h" +#include "modsocket.h" #include "debug.h" #include "serverstask.h" #include "genhdr/mpversion.h" diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c index b7d6fe7e6a..831ece74a9 100644 --- a/ports/stm32/modpyb.c +++ b/ports/stm32/modpyb.c @@ -54,7 +54,7 @@ #include "modmachine.h" #include "extmod/modnetwork.h" #include "extmod/vfs.h" -#include "extmod/modutime.h" +#include "extmod/modtime.h" #if MICROPY_PY_PYB diff --git a/ports/unix/main.c b/ports/unix/main.c index 392ce59dde..16f663de19 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -48,7 +48,7 @@ #include "py/mphal.h" #include "py/mpthread.h" #include "extmod/misc.h" -#include "extmod/moduplatform.h" +#include "extmod/modplatform.h" #include "extmod/vfs.h" #include "extmod/vfs_posix.h" #include "genhdr/mpversion.h" diff --git a/py/modsys.c b/py/modsys.c index 09bdfefc63..1cfc09ecfb 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -36,7 +36,7 @@ #include "py/smallint.h" #include "py/runtime.h" #include "py/persistentcode.h" -#include "extmod/moduplatform.h" +#include "extmod/modplatform.h" #include "genhdr/mpversion.h" #if MICROPY_PY_SYS_SETTRACE From 45ac651d1a2801bccbdc32fddaa9b029ed4ce879 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 18 Aug 2022 16:24:27 +1000 Subject: [PATCH 169/565] all: Rename *umodule*.c to remove the "u" prefix. Updates any includes, and references from Makefiles/CMake. This essentially reverts what was done long ago in commit 136b5cbd7669e8318f8455fc2706da97a5b7994c This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- .../embedding/Makefile.upylib | 0 examples/natmod/uheapq/uheapq.c | 2 +- examples/natmod/urandom/urandom.c | 2 +- examples/natmod/ure/ure.c | 2 +- examples/natmod/uzlib/uzlib.c | 2 +- extmod/extmod.cmake | 36 +++++++++---------- extmod/extmod.mk | 36 +++++++++---------- extmod/{modubinascii.c => modbinascii.c} | 0 extmod/{moducryptolib.c => modcryptolib.c} | 0 extmod/{moduhashlib.c => modhashlib.c} | 0 extmod/{moduheapq.c => modheapq.c} | 0 extmod/{modujson.c => modjson.c} | 0 extmod/modlwip.c | 2 +- extmod/{moduos.c => modos.c} | 0 extmod/{moduplatform.c => modplatform.c} | 0 extmod/{modurandom.c => modrandom.c} | 0 extmod/{modure.c => modre.c} | 0 extmod/{moduselect.c => modselect.c} | 0 extmod/{modusocket.c => modsocket.c} | 0 extmod/{modussl_axtls.c => modssl_axtls.c} | 0 .../{modussl_mbedtls.c => modssl_mbedtls.c} | 0 extmod/{modutime.c => modtime.c} | 0 extmod/{modutimeq.c => modtimeq.c} | 0 extmod/{moduwebsocket.c => modwebsocket.c} | 0 extmod/{moduzlib.c => modzlib.c} | 0 extmod/{uos_dupterm.c => os_dupterm.c} | 0 ports/cc3200/application.mk | 6 ++-- .../mods/{moduhashlib.c => modhashlib.c} | 0 ports/cc3200/mods/{moduos.c => modos.c} | 0 .../cc3200/mods/{modusocket.c => modsocket.c} | 0 ports/cc3200/mods/{modussl.c => modssl.c} | 0 ports/cc3200/mods/{modutime.c => modtime.c} | 0 ports/embed/embed.mk | 2 +- ports/esp32/{moduos.c => modos.c} | 0 ports/esp32/{modutime.c => modtime.c} | 0 ports/esp32/mpconfigport.h | 2 +- ports/esp8266/boards/esp8266_common.ld | 2 +- ports/esp8266/{moduos.c => modos.c} | 0 ports/esp8266/{modutime.c => modtime.c} | 0 ports/esp8266/mpconfigport.h | 2 +- ports/mimxrt/{moduos.c => modos.c} | 0 ports/mimxrt/{modutime.c => modtime.c} | 0 ports/mimxrt/mpconfigport.h | 4 +-- ports/nrf/Makefile | 4 +-- ports/nrf/modules/{uos => os}/microbitfs.c | 0 ports/nrf/modules/{uos => os}/microbitfs.h | 0 .../nrf/modules/{uos/moduos.c => os/modos.c} | 0 ports/renesas-ra/{moduos.c => modos.c} | 0 ports/renesas-ra/{modutime.c => modtime.c} | 0 ports/renesas-ra/mpconfigport.h | 2 +- ports/rp2/CMakeLists.txt | 2 +- ports/rp2/{moduos.c => modos.c} | 0 ports/rp2/{modutime.c => modtime.c} | 0 ports/rp2/mpconfigport.h | 4 +-- ports/samd/{moduos.c => modos.c} | 0 ports/samd/{modutime.c => modtime.c} | 0 ports/stm32/{moduos.c => modos.c} | 0 ports/stm32/{modutime.c => modtime.c} | 0 ports/stm32/mpconfigport.h | 4 +-- ports/unix/Makefile | 4 +-- ports/unix/{moduos.c => modos.c} | 0 ports/unix/{moduselect.c => modselect.c} | 0 ports/unix/{modusocket.c => modsocket.c} | 0 ports/unix/{modutime.c => modtime.c} | 0 ports/unix/variants/mpconfigvariant_common.h | 4 +-- ports/windows/mpconfigport.h | 4 +-- ports/windows/msvc/sources.props | 22 ++++++------ ports/zephyr/CMakeLists.txt | 2 +- ports/zephyr/{modusocket.c => modsocket.c} | 0 ports/zephyr/{modutime.c => modtime.c} | 0 ports/zephyr/mpconfigport.h | 2 +- py/{moduerrno.c => moderrno.c} | 0 py/py.cmake | 2 +- py/py.mk | 2 +- tools/codeformat.py | 4 +-- 75 files changed, 81 insertions(+), 81 deletions(-) rename extmod/utime_mphal.c => examples/embedding/Makefile.upylib (100%) rename extmod/{modubinascii.c => modbinascii.c} (100%) rename extmod/{moducryptolib.c => modcryptolib.c} (100%) rename extmod/{moduhashlib.c => modhashlib.c} (100%) rename extmod/{moduheapq.c => modheapq.c} (100%) rename extmod/{modujson.c => modjson.c} (100%) rename extmod/{moduos.c => modos.c} (100%) rename extmod/{moduplatform.c => modplatform.c} (100%) rename extmod/{modurandom.c => modrandom.c} (100%) rename extmod/{modure.c => modre.c} (100%) rename extmod/{moduselect.c => modselect.c} (100%) rename extmod/{modusocket.c => modsocket.c} (100%) rename extmod/{modussl_axtls.c => modssl_axtls.c} (100%) rename extmod/{modussl_mbedtls.c => modssl_mbedtls.c} (100%) rename extmod/{modutime.c => modtime.c} (100%) rename extmod/{modutimeq.c => modtimeq.c} (100%) rename extmod/{moduwebsocket.c => modwebsocket.c} (100%) rename extmod/{moduzlib.c => modzlib.c} (100%) rename extmod/{uos_dupterm.c => os_dupterm.c} (100%) rename ports/cc3200/mods/{moduhashlib.c => modhashlib.c} (100%) rename ports/cc3200/mods/{moduos.c => modos.c} (100%) rename ports/cc3200/mods/{modusocket.c => modsocket.c} (100%) rename ports/cc3200/mods/{modussl.c => modssl.c} (100%) rename ports/cc3200/mods/{modutime.c => modtime.c} (100%) rename ports/esp32/{moduos.c => modos.c} (100%) rename ports/esp32/{modutime.c => modtime.c} (100%) rename ports/esp8266/{moduos.c => modos.c} (100%) rename ports/esp8266/{modutime.c => modtime.c} (100%) rename ports/mimxrt/{moduos.c => modos.c} (100%) rename ports/mimxrt/{modutime.c => modtime.c} (100%) rename ports/nrf/modules/{uos => os}/microbitfs.c (100%) rename ports/nrf/modules/{uos => os}/microbitfs.h (100%) rename ports/nrf/modules/{uos/moduos.c => os/modos.c} (100%) rename ports/renesas-ra/{moduos.c => modos.c} (100%) rename ports/renesas-ra/{modutime.c => modtime.c} (100%) rename ports/rp2/{moduos.c => modos.c} (100%) rename ports/rp2/{modutime.c => modtime.c} (100%) rename ports/samd/{moduos.c => modos.c} (100%) rename ports/samd/{modutime.c => modtime.c} (100%) rename ports/stm32/{moduos.c => modos.c} (100%) rename ports/stm32/{modutime.c => modtime.c} (100%) rename ports/unix/{moduos.c => modos.c} (100%) rename ports/unix/{moduselect.c => modselect.c} (100%) rename ports/unix/{modusocket.c => modsocket.c} (100%) rename ports/unix/{modutime.c => modtime.c} (100%) rename ports/zephyr/{modusocket.c => modsocket.c} (100%) rename ports/zephyr/{modutime.c => modtime.c} (100%) rename py/{moduerrno.c => moderrno.c} (100%) diff --git a/extmod/utime_mphal.c b/examples/embedding/Makefile.upylib similarity index 100% rename from extmod/utime_mphal.c rename to examples/embedding/Makefile.upylib diff --git a/examples/natmod/uheapq/uheapq.c b/examples/natmod/uheapq/uheapq.c index e339ccafd7..ed19652a66 100644 --- a/examples/natmod/uheapq/uheapq.c +++ b/examples/natmod/uheapq/uheapq.c @@ -2,7 +2,7 @@ #include "py/dynruntime.h" -#include "extmod/moduheapq.c" +#include "extmod/modheapq.c" mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY diff --git a/examples/natmod/urandom/urandom.c b/examples/natmod/urandom/urandom.c index ed46651b34..92257b8bc6 100644 --- a/examples/natmod/urandom/urandom.c +++ b/examples/natmod/urandom/urandom.c @@ -7,7 +7,7 @@ uint32_t yasmarang_pad, yasmarang_n, yasmarang_d; uint8_t yasmarang_dat; -#include "extmod/modurandom.c" +#include "extmod/modrandom.c" mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY diff --git a/examples/natmod/ure/ure.c b/examples/natmod/ure/ure.c index 79eca90ab9..df89ea8353 100644 --- a/examples/natmod/ure/ure.c +++ b/examples/natmod/ure/ure.c @@ -35,7 +35,7 @@ void *memmove(void *dest, const void *src, size_t n) { mp_obj_full_type_t match_type; mp_obj_full_type_t re_type; -#include "extmod/modure.c" +#include "extmod/modre.c" mp_map_elem_t match_locals_dict_table[5]; STATIC MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); diff --git a/examples/natmod/uzlib/uzlib.c b/examples/natmod/uzlib/uzlib.c index 9a3ec0af3c..2b0dbd5ca0 100644 --- a/examples/natmod/uzlib/uzlib.c +++ b/examples/natmod/uzlib/uzlib.c @@ -10,7 +10,7 @@ void *memset(void *s, int c, size_t n) { mp_obj_full_type_t decompio_type; -#include "extmod/moduzlib.c" +#include "extmod/modzlib.c" mp_map_elem_t decompio_locals_dict_table[3]; STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table); diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index 675a4c6ecc..2bb89423c9 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -19,30 +19,30 @@ set(MICROPY_SOURCE_EXTMOD ${MICROPY_EXTMOD_DIR}/modnetwork.c ${MICROPY_EXTMOD_DIR}/modonewire.c ${MICROPY_EXTMOD_DIR}/moduasyncio.c - ${MICROPY_EXTMOD_DIR}/modubinascii.c - ${MICROPY_EXTMOD_DIR}/moducryptolib.c + ${MICROPY_EXTMOD_DIR}/modbinascii.c + ${MICROPY_EXTMOD_DIR}/modcryptolib.c ${MICROPY_EXTMOD_DIR}/moductypes.c - ${MICROPY_EXTMOD_DIR}/moduhashlib.c - ${MICROPY_EXTMOD_DIR}/moduheapq.c - ${MICROPY_EXTMOD_DIR}/modujson.c - ${MICROPY_EXTMOD_DIR}/moduos.c - ${MICROPY_EXTMOD_DIR}/moduplatform.c - ${MICROPY_EXTMOD_DIR}/modurandom.c - ${MICROPY_EXTMOD_DIR}/modure.c - ${MICROPY_EXTMOD_DIR}/moduselect.c - ${MICROPY_EXTMOD_DIR}/modusocket.c - ${MICROPY_EXTMOD_DIR}/modussl_axtls.c - ${MICROPY_EXTMOD_DIR}/modussl_mbedtls.c - ${MICROPY_EXTMOD_DIR}/modutime.c - ${MICROPY_EXTMOD_DIR}/modutimeq.c - ${MICROPY_EXTMOD_DIR}/moduwebsocket.c - ${MICROPY_EXTMOD_DIR}/moduzlib.c + ${MICROPY_EXTMOD_DIR}/modhashlib.c + ${MICROPY_EXTMOD_DIR}/modheapq.c + ${MICROPY_EXTMOD_DIR}/modjson.c + ${MICROPY_EXTMOD_DIR}/modos.c + ${MICROPY_EXTMOD_DIR}/modplatform.c + ${MICROPY_EXTMOD_DIR}/modrandom.c + ${MICROPY_EXTMOD_DIR}/modre.c + ${MICROPY_EXTMOD_DIR}/modselect.c + ${MICROPY_EXTMOD_DIR}/modsocket.c + ${MICROPY_EXTMOD_DIR}/modssl_axtls.c + ${MICROPY_EXTMOD_DIR}/modssl_mbedtls.c + ${MICROPY_EXTMOD_DIR}/modtime.c + ${MICROPY_EXTMOD_DIR}/modtimeq.c + ${MICROPY_EXTMOD_DIR}/modwebsocket.c + ${MICROPY_EXTMOD_DIR}/modzlib.c ${MICROPY_EXTMOD_DIR}/modwebrepl.c ${MICROPY_EXTMOD_DIR}/network_cyw43.c ${MICROPY_EXTMOD_DIR}/network_lwip.c ${MICROPY_EXTMOD_DIR}/network_ninaw10.c ${MICROPY_EXTMOD_DIR}/network_wiznet5k.c - ${MICROPY_EXTMOD_DIR}/uos_dupterm.c + ${MICROPY_EXTMOD_DIR}/os_dupterm.c ${MICROPY_EXTMOD_DIR}/vfs.c ${MICROPY_EXTMOD_DIR}/vfs_blockdev.c ${MICROPY_EXTMOD_DIR}/vfs_fat.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 2f9bd3b065..a573da4c60 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -11,37 +11,37 @@ SRC_EXTMOD_C += \ extmod/machine_signal.c \ extmod/machine_spi.c \ extmod/machine_timer.c \ + extmod/modbinascii.c \ extmod/modbluetooth.c \ extmod/modbtree.c \ + extmod/modcryptolib.c \ extmod/modframebuf.c \ + extmod/modhashlib.c \ + extmod/modheapq.c \ + extmod/modjson.c \ extmod/modlwip.c \ extmod/modnetwork.c \ extmod/modonewire.c \ + extmod/modos.c \ + extmod/modplatform.c\ + extmod/modrandom.c \ + extmod/modre.c \ + extmod/modselect.c \ + extmod/modsocket.c \ + extmod/modssl_axtls.c \ + extmod/modssl_mbedtls.c \ + extmod/modtime.c \ + extmod/modtimeq.c \ extmod/moduasyncio.c \ - extmod/modubinascii.c \ - extmod/moducryptolib.c \ extmod/moductypes.c \ - extmod/moduhashlib.c \ - extmod/moduheapq.c \ - extmod/modujson.c \ - extmod/moduos.c \ - extmod/moduplatform.c\ - extmod/modurandom.c \ - extmod/modure.c \ - extmod/moduselect.c \ - extmod/modusocket.c \ - extmod/modussl_axtls.c \ - extmod/modussl_mbedtls.c \ - extmod/modutime.c \ - extmod/modutimeq.c \ - extmod/moduwebsocket.c \ - extmod/moduzlib.c \ extmod/modwebrepl.c \ + extmod/modwebsocket.c \ + extmod/modzlib.c \ extmod/network_cyw43.c \ extmod/network_lwip.c \ extmod/network_ninaw10.c \ extmod/network_wiznet5k.c \ - extmod/uos_dupterm.c \ + extmod/os_dupterm.c \ extmod/vfs.c \ extmod/vfs_blockdev.c \ extmod/vfs_fat.c \ diff --git a/extmod/modubinascii.c b/extmod/modbinascii.c similarity index 100% rename from extmod/modubinascii.c rename to extmod/modbinascii.c diff --git a/extmod/moducryptolib.c b/extmod/modcryptolib.c similarity index 100% rename from extmod/moducryptolib.c rename to extmod/modcryptolib.c diff --git a/extmod/moduhashlib.c b/extmod/modhashlib.c similarity index 100% rename from extmod/moduhashlib.c rename to extmod/modhashlib.c diff --git a/extmod/moduheapq.c b/extmod/modheapq.c similarity index 100% rename from extmod/moduheapq.c rename to extmod/modheapq.c diff --git a/extmod/modujson.c b/extmod/modjson.c similarity index 100% rename from extmod/modujson.c rename to extmod/modjson.c diff --git a/extmod/modlwip.c b/extmod/modlwip.c index a902e8fb0f..24047b0a98 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -1801,7 +1801,7 @@ const mp_obj_module_t mp_module_lwip = { MP_REGISTER_MODULE(MP_QSTR_lwip, mp_module_lwip); -// On LWIP-ports, this is the socket module (replaces extmod/modusocket.c). +// On LWIP-ports, this is the socket module (replaces extmod/modsocket.c). MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_lwip); MP_REGISTER_ROOT_POINTER(mp_obj_t lwip_slip_stream); diff --git a/extmod/moduos.c b/extmod/modos.c similarity index 100% rename from extmod/moduos.c rename to extmod/modos.c diff --git a/extmod/moduplatform.c b/extmod/modplatform.c similarity index 100% rename from extmod/moduplatform.c rename to extmod/modplatform.c diff --git a/extmod/modurandom.c b/extmod/modrandom.c similarity index 100% rename from extmod/modurandom.c rename to extmod/modrandom.c diff --git a/extmod/modure.c b/extmod/modre.c similarity index 100% rename from extmod/modure.c rename to extmod/modre.c diff --git a/extmod/moduselect.c b/extmod/modselect.c similarity index 100% rename from extmod/moduselect.c rename to extmod/modselect.c diff --git a/extmod/modusocket.c b/extmod/modsocket.c similarity index 100% rename from extmod/modusocket.c rename to extmod/modsocket.c diff --git a/extmod/modussl_axtls.c b/extmod/modssl_axtls.c similarity index 100% rename from extmod/modussl_axtls.c rename to extmod/modssl_axtls.c diff --git a/extmod/modussl_mbedtls.c b/extmod/modssl_mbedtls.c similarity index 100% rename from extmod/modussl_mbedtls.c rename to extmod/modssl_mbedtls.c diff --git a/extmod/modutime.c b/extmod/modtime.c similarity index 100% rename from extmod/modutime.c rename to extmod/modtime.c diff --git a/extmod/modutimeq.c b/extmod/modtimeq.c similarity index 100% rename from extmod/modutimeq.c rename to extmod/modtimeq.c diff --git a/extmod/moduwebsocket.c b/extmod/modwebsocket.c similarity index 100% rename from extmod/moduwebsocket.c rename to extmod/modwebsocket.c diff --git a/extmod/moduzlib.c b/extmod/modzlib.c similarity index 100% rename from extmod/moduzlib.c rename to extmod/modzlib.c diff --git a/extmod/uos_dupterm.c b/extmod/os_dupterm.c similarity index 100% rename from extmod/uos_dupterm.c rename to extmod/os_dupterm.c diff --git a/ports/cc3200/application.mk b/ports/cc3200/application.mk index 78c2b8044a..5021e4ff3c 100644 --- a/ports/cc3200/application.mk +++ b/ports/cc3200/application.mk @@ -78,9 +78,9 @@ APP_MISC_SRC_C = $(addprefix misc/,\ APP_MODS_SRC_C = $(addprefix mods/,\ modmachine.c \ modnetwork.c \ - moduos.c \ - modusocket.c \ - modussl.c \ + modos.c \ + modsocket.c \ + modssl.c \ modwipy.c \ modwlan.c \ pybadc.c \ diff --git a/ports/cc3200/mods/moduhashlib.c b/ports/cc3200/mods/modhashlib.c similarity index 100% rename from ports/cc3200/mods/moduhashlib.c rename to ports/cc3200/mods/modhashlib.c diff --git a/ports/cc3200/mods/moduos.c b/ports/cc3200/mods/modos.c similarity index 100% rename from ports/cc3200/mods/moduos.c rename to ports/cc3200/mods/modos.c diff --git a/ports/cc3200/mods/modusocket.c b/ports/cc3200/mods/modsocket.c similarity index 100% rename from ports/cc3200/mods/modusocket.c rename to ports/cc3200/mods/modsocket.c diff --git a/ports/cc3200/mods/modussl.c b/ports/cc3200/mods/modssl.c similarity index 100% rename from ports/cc3200/mods/modussl.c rename to ports/cc3200/mods/modssl.c diff --git a/ports/cc3200/mods/modutime.c b/ports/cc3200/mods/modtime.c similarity index 100% rename from ports/cc3200/mods/modutime.c rename to ports/cc3200/mods/modtime.c diff --git a/ports/embed/embed.mk b/ports/embed/embed.mk index 7fb344d704..84d45accd2 100644 --- a/ports/embed/embed.mk +++ b/ports/embed/embed.mk @@ -52,7 +52,7 @@ micropython-embed-package: $(GENHDR_OUTPUT) $(ECHO) "- py" $(Q)$(CP) $(TOP)/py/*.[ch] $(PACKAGE_DIR)/py $(ECHO) "- extmod" - $(Q)$(CP) $(TOP)/extmod/moduplatform.h $(PACKAGE_DIR)/extmod + $(Q)$(CP) $(TOP)/extmod/modplatform.h $(PACKAGE_DIR)/extmod $(ECHO) "- shared" $(Q)$(CP) $(TOP)/shared/runtime/gchelper.h $(PACKAGE_DIR)/shared/runtime $(Q)$(CP) $(TOP)/shared/runtime/gchelper_generic.c $(PACKAGE_DIR)/shared/runtime diff --git a/ports/esp32/moduos.c b/ports/esp32/modos.c similarity index 100% rename from ports/esp32/moduos.c rename to ports/esp32/modos.c diff --git a/ports/esp32/modutime.c b/ports/esp32/modtime.c similarity index 100% rename from ports/esp32/modutime.c rename to ports/esp32/modtime.c diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index d25a5c2734..217a9ec297 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -88,7 +88,7 @@ #define MICROPY_PY_HASHLIB_SHA256 (1) #define MICROPY_PY_CRYPTOLIB (1) #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (esp_random()) -#define MICROPY_PY_OS_INCLUDEFILE "ports/esp32/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/esp32/modos.c" #define MICROPY_PY_OS_DUPTERM (1) #define MICROPY_PY_OS_DUPTERM_NOTIFY (1) #define MICROPY_PY_OS_SYNC (1) diff --git a/ports/esp8266/boards/esp8266_common.ld b/ports/esp8266/boards/esp8266_common.ld index 7e230fd42a..083e84d9af 100644 --- a/ports/esp8266/boards/esp8266_common.ld +++ b/ports/esp8266/boards/esp8266_common.ld @@ -164,7 +164,7 @@ SECTIONS *machine_hspi.o(.literal*, .text*) *hspi.o(.literal*, .text*) *modesp.o(.literal* .text*) - *moduos.o(.literal* .text*) + *modos.o(.literal* .text*) *modlwip.o(.literal* .text*) *modsocket.o(.literal* .text*) *modonewire.o(.literal* .text*) diff --git a/ports/esp8266/moduos.c b/ports/esp8266/modos.c similarity index 100% rename from ports/esp8266/moduos.c rename to ports/esp8266/modos.c diff --git a/ports/esp8266/modutime.c b/ports/esp8266/modtime.c similarity index 100% rename from ports/esp8266/modutime.c rename to ports/esp8266/modtime.c diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index 9985d59dd3..37a794f44b 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -58,7 +58,7 @@ #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (*WDEV_HWRNG) #define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) -#define MICROPY_PY_TIME_INCLUDEFILE "ports/esp8266/modutime.c" +#define MICROPY_PY_TIME_INCLUDEFILE "ports/esp8266/modtime.c" #define MICROPY_PY_LWIP (1) #define MICROPY_PY_LWIP_SOCK_RAW (1) #define MICROPY_PY_MACHINE (1) diff --git a/ports/mimxrt/moduos.c b/ports/mimxrt/modos.c similarity index 100% rename from ports/mimxrt/moduos.c rename to ports/mimxrt/modos.c diff --git a/ports/mimxrt/modutime.c b/ports/mimxrt/modtime.c similarity index 100% rename from ports/mimxrt/modutime.c rename to ports/mimxrt/modtime.c diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index be086cb552..b1cd84f265 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -72,8 +72,8 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_SSL_FINALISER (MICROPY_PY_SSL) #define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) -#define MICROPY_PY_TIME_INCLUDEFILE "ports/mimxrt/modutime.c" -#define MICROPY_PY_OS_INCLUDEFILE "ports/mimxrt/moduos.c" +#define MICROPY_PY_TIME_INCLUDEFILE "ports/mimxrt/modtime.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/mimxrt/modos.c" #define MICROPY_PY_OS_DUPTERM (3) #define MICROPY_PY_OS_DUPTERM_NOTIFY (1) #define MICROPY_PY_OS_SYNC (1) diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 54701adacb..89bb03dfae 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -329,8 +329,8 @@ DRIVERS_SRC_C += $(addprefix modules/,\ machine/timer.c \ machine/rtcounter.c \ machine/temp.c \ - uos/moduos.c \ - uos/microbitfs.c \ + os/modos.c \ + os/microbitfs.c \ board/modboard.c \ board/led.c \ ubluepy/modubluepy.c \ diff --git a/ports/nrf/modules/uos/microbitfs.c b/ports/nrf/modules/os/microbitfs.c similarity index 100% rename from ports/nrf/modules/uos/microbitfs.c rename to ports/nrf/modules/os/microbitfs.c diff --git a/ports/nrf/modules/uos/microbitfs.h b/ports/nrf/modules/os/microbitfs.h similarity index 100% rename from ports/nrf/modules/uos/microbitfs.h rename to ports/nrf/modules/os/microbitfs.h diff --git a/ports/nrf/modules/uos/moduos.c b/ports/nrf/modules/os/modos.c similarity index 100% rename from ports/nrf/modules/uos/moduos.c rename to ports/nrf/modules/os/modos.c diff --git a/ports/renesas-ra/moduos.c b/ports/renesas-ra/modos.c similarity index 100% rename from ports/renesas-ra/moduos.c rename to ports/renesas-ra/modos.c diff --git a/ports/renesas-ra/modutime.c b/ports/renesas-ra/modtime.c similarity index 100% rename from ports/renesas-ra/modutime.c rename to ports/renesas-ra/modtime.c diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index 1886d31541..42ce0b6827 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -91,7 +91,7 @@ #endif // extended modules -#define MICROPY_PY_OS_INCLUDEFILE "ports/renesas-ra/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/renesas-ra/modos.c" #define MICROPY_PY_OS_DUPTERM (3) #define MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM (1) #define MICROPY_PY_OS_DUPTERM_STREAM_DETACHED_ATTACHED (1) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 3dff0d54c6..55c542173a 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -157,7 +157,7 @@ set(MICROPY_SOURCE_QSTR ${PROJECT_SOURCE_DIR}/machine_wdt.c ${PROJECT_SOURCE_DIR}/modmachine.c ${PROJECT_SOURCE_DIR}/modrp2.c - ${PROJECT_SOURCE_DIR}/moduos.c + ${PROJECT_SOURCE_DIR}/modos.c ${PROJECT_SOURCE_DIR}/rp2_flash.c ${PROJECT_SOURCE_DIR}/rp2_pio.c ${CMAKE_BINARY_DIR}/pins_${MICROPY_BOARD}.c diff --git a/ports/rp2/moduos.c b/ports/rp2/modos.c similarity index 100% rename from ports/rp2/moduos.c rename to ports/rp2/modos.c diff --git a/ports/rp2/modutime.c b/ports/rp2/modtime.c similarity index 100% rename from ports/rp2/modutime.c rename to ports/rp2/modtime.c diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index de05a281bd..28b06fa3a8 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -95,7 +95,7 @@ // Extended modules #define MICROPY_EPOCH_IS_1970 (1) -#define MICROPY_PY_OS_INCLUDEFILE "ports/rp2/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/rp2/modos.c" #ifndef MICROPY_PY_OS_DUPTERM #define MICROPY_PY_OS_DUPTERM (1) #endif @@ -108,7 +108,7 @@ #define MICROPY_PY_CRYPTOLIB (1) #define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) -#define MICROPY_PY_TIME_INCLUDEFILE "ports/rp2/modutime.c" +#define MICROPY_PY_TIME_INCLUDEFILE "ports/rp2/modtime.c" #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rosc_random_u32()) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new diff --git a/ports/samd/moduos.c b/ports/samd/modos.c similarity index 100% rename from ports/samd/moduos.c rename to ports/samd/modos.c diff --git a/ports/samd/modutime.c b/ports/samd/modtime.c similarity index 100% rename from ports/samd/modutime.c rename to ports/samd/modtime.c diff --git a/ports/stm32/moduos.c b/ports/stm32/modos.c similarity index 100% rename from ports/stm32/moduos.c rename to ports/stm32/modos.c diff --git a/ports/stm32/modutime.c b/ports/stm32/modtime.c similarity index 100% rename from ports/stm32/modutime.c rename to ports/stm32/modtime.c diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index 49a8a03405..c0a95cf5d5 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -96,7 +96,7 @@ #define MICROPY_PY_HASHLIB_MD5 (MICROPY_PY_SSL) #define MICROPY_PY_HASHLIB_SHA1 (MICROPY_PY_SSL) #define MICROPY_PY_CRYPTOLIB (MICROPY_PY_SSL) -#define MICROPY_PY_OS_INCLUDEFILE "ports/stm32/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/stm32/modos.c" #define MICROPY_PY_OS_DUPTERM (3) #define MICROPY_PY_OS_DUPTERM_BUILTIN_STREAM (1) #define MICROPY_PY_OS_DUPTERM_STREAM_DETACHED_ATTACHED (1) @@ -107,7 +107,7 @@ #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rng_get()) #define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) -#define MICROPY_PY_TIME_INCLUDEFILE "ports/stm32/modutime.c" +#define MICROPY_PY_TIME_INCLUDEFILE "ports/stm32/modtime.c" #ifndef MICROPY_PY_TIMEQ #define MICROPY_PY_TIMEQ (1) #endif diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 9ff19aab98..a8981e8f5c 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -201,7 +201,7 @@ SRC_C += \ mpthreadport.c \ input.c \ modmachine.c \ - moduselect.c \ + modselect.c \ alloc.c \ fatfs_port.c \ mpbthciport.c \ @@ -210,7 +210,7 @@ SRC_C += \ mpbtstackport_usb.c \ mpnimbleport.c \ modtermios.c \ - modusocket.c \ + modsocket.c \ modffi.c \ modjni.c \ $(wildcard $(VARIANT_DIR)/*.c) diff --git a/ports/unix/moduos.c b/ports/unix/modos.c similarity index 100% rename from ports/unix/moduos.c rename to ports/unix/modos.c diff --git a/ports/unix/moduselect.c b/ports/unix/modselect.c similarity index 100% rename from ports/unix/moduselect.c rename to ports/unix/modselect.c diff --git a/ports/unix/modusocket.c b/ports/unix/modsocket.c similarity index 100% rename from ports/unix/modusocket.c rename to ports/unix/modsocket.c diff --git a/ports/unix/modutime.c b/ports/unix/modtime.c similarity index 100% rename from ports/unix/modutime.c rename to ports/unix/modtime.c diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index cc50d426ce..afdd313134 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -87,7 +87,7 @@ #define MICROPY_PY_SYS_EXC_INFO (1) // Configure the "os" module with extra unix features. -#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/modos.c" #define MICROPY_PY_OS_ERRNO (1) #define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1) #define MICROPY_PY_OS_SEP (1) @@ -98,7 +98,7 @@ #define MICROPY_PY_TIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) #define MICROPY_PY_TIME_CUSTOM_SLEEP (1) -#define MICROPY_PY_TIME_INCLUDEFILE "ports/unix/modutime.c" +#define MICROPY_PY_TIME_INCLUDEFILE "ports/unix/modtime.c" // Enable the utimeq module used by the previous (v2) version of uasyncio. #define MICROPY_PY_TIMEQ (1) diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index 87e12562b1..239dcfec91 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -131,7 +131,7 @@ #endif #define MICROPY_PY_OS (1) -#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/moduos.c" +#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/modos.c" #define MICROPY_PY_OS_ERRNO (1) #define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1) #define MICROPY_PY_OS_SEP (1) @@ -141,7 +141,7 @@ #define MICROPY_PY_TIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) #define MICROPY_PY_TIME_CUSTOM_SLEEP (1) -#define MICROPY_PY_TIME_INCLUDEFILE "ports/unix/modutime.c" +#define MICROPY_PY_TIME_INCLUDEFILE "ports/unix/modtime.c" #define MICROPY_PY_ERRNO (1) #define MICROPY_PY_UCTYPES (1) #define MICROPY_PY_ZLIB (1) diff --git a/ports/windows/msvc/sources.props b/ports/windows/msvc/sources.props index de950c3ac9..24cdcd82da 100644 --- a/ports/windows/msvc/sources.props +++ b/ports/windows/msvc/sources.props @@ -8,18 +8,18 @@ - + - - - - - - - - - - + + + + + + + + + + diff --git a/ports/zephyr/CMakeLists.txt b/ports/zephyr/CMakeLists.txt index 39942bdc84..ddc613a2c0 100644 --- a/ports/zephyr/CMakeLists.txt +++ b/ports/zephyr/CMakeLists.txt @@ -43,7 +43,7 @@ set(MICROPY_SOURCE_PORT machine_uart.c modbluetooth_zephyr.c modmachine.c - modusocket.c + modsocket.c modzephyr.c modzsensor.c mphalport.c diff --git a/ports/zephyr/modusocket.c b/ports/zephyr/modsocket.c similarity index 100% rename from ports/zephyr/modusocket.c rename to ports/zephyr/modsocket.c diff --git a/ports/zephyr/modutime.c b/ports/zephyr/modtime.c similarity index 100% rename from ports/zephyr/modutime.c rename to ports/zephyr/modtime.c diff --git a/ports/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h index ec759bda77..df24e52002 100644 --- a/ports/zephyr/mpconfigport.h +++ b/ports/zephyr/mpconfigport.h @@ -87,7 +87,7 @@ #define MICROPY_PY_OS (1) #define MICROPY_PY_TIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) -#define MICROPY_PY_TIME_INCLUDEFILE "ports/zephyr/modutime.c" +#define MICROPY_PY_TIME_INCLUDEFILE "ports/zephyr/modtime.c" #define MICROPY_PY_ZEPHYR (1) #define MICROPY_PY_ZSENSOR (1) #define MICROPY_PY_SYS_MODULES (0) diff --git a/py/moduerrno.c b/py/moderrno.c similarity index 100% rename from py/moduerrno.c rename to py/moderrno.c diff --git a/py/py.cmake b/py/py.cmake index 07d1fe05ff..95a841b5f4 100644 --- a/py/py.cmake +++ b/py/py.cmake @@ -47,7 +47,7 @@ set(MICROPY_SOURCE_PY ${MICROPY_PY_DIR}/modstruct.c ${MICROPY_PY_DIR}/modsys.c ${MICROPY_PY_DIR}/modthread.c - ${MICROPY_PY_DIR}/moduerrno.c + ${MICROPY_PY_DIR}/moderrno.c ${MICROPY_PY_DIR}/mpprint.c ${MICROPY_PY_DIR}/mpstate.c ${MICROPY_PY_DIR}/mpz.c diff --git a/py/py.mk b/py/py.mk index 1dc0c8641f..ffb853c652 100644 --- a/py/py.mk +++ b/py/py.mk @@ -185,7 +185,7 @@ PY_CORE_O_BASENAME = $(addprefix py/,\ modmicropython.o \ modstruct.o \ modsys.o \ - moduerrno.o \ + moderrno.o \ modthread.o \ vm.o \ bc.o \ diff --git a/tools/codeformat.py b/tools/codeformat.py index 4a2cfb3367..517aced37a 100755 --- a/tools/codeformat.py +++ b/tools/codeformat.py @@ -69,8 +69,8 @@ EXCLUSIONS = [ "ports/nrf/modules/machine/*.[ch]", "ports/nrf/modules/music/*.[ch]", "ports/nrf/modules/ubluepy/*.[ch]", - "ports/nrf/modules/uos/*.[ch]", - "ports/nrf/modules/utime/*.[ch]", + "ports/nrf/modules/os/*.[ch]", + "ports/nrf/modules/time/*.[ch]", # STM32 USB dev/host code is mostly 3rd party. "ports/stm32/usbdev/**/*.[ch]", "ports/stm32/usbhost/**/*.[ch]", From 24c02c4eb5f11200f876bb57cd63a9d0bae91fd3 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 2 Jun 2023 12:28:07 +1000 Subject: [PATCH 170/565] py/makemoduledefs.py: Add a way to register extensible built-in modules. Signed-off-by: Jim Mussared --- py/builtinhelp.c | 1 + py/builtinimport.c | 22 ++++++++------------- py/makemoduledefs.py | 46 ++++++++++++++++++++++++++++++++++--------- py/makeqstrdefs.py | 4 ++-- py/obj.h | 3 +++ py/objmodule.c | 47 +++++++++++++++++++++++++++++++++++++++----- py/objmodule.h | 3 ++- py/repl.c | 4 ++-- 8 files changed, 97 insertions(+), 33 deletions(-) diff --git a/py/builtinhelp.c b/py/builtinhelp.c index 93d94a389d..c60ed44e9c 100644 --- a/py/builtinhelp.c +++ b/py/builtinhelp.c @@ -79,6 +79,7 @@ STATIC void mp_help_print_modules(void) { mp_obj_t list = mp_obj_new_list(0, NULL); mp_help_add_from_map(list, &mp_builtin_module_map); + mp_help_add_from_map(list, &mp_builtin_extensible_module_map); #if MICROPY_MODULE_FROZEN extern const char mp_frozen_names[]; diff --git a/py/builtinimport.c b/py/builtinimport.c index 299877de63..15521c77c4 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -384,28 +384,22 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, // An import of a non-extensible built-in will always bypass the // filesystem. e.g. `import micropython` or `import pyb`. - module_obj = mp_module_get_builtin(level_mod_name); + module_obj = mp_module_get_builtin(level_mod_name, false); if (module_obj != MP_OBJ_NULL) { return module_obj; } - #if MICROPY_PY_SYS - // Never allow sys to be overridden from the filesystem. If weak links - // are disabled, then this also provides a default weak link so that - // `import sys` is treated like `import usys` (and therefore bypasses - // the filesystem). - if (level_mod_name == MP_QSTR_sys) { - return MP_OBJ_FROM_PTR(&mp_module_sys); - } - #endif - // First module in the dotted-name; search for a directory or file // relative to all the locations in sys.path. stat = stat_top_level(level_mod_name, &path); // TODO: If stat failed, now try extensible built-in modules. - - // TODO: If importing `ufoo`, try `foo`. + if (stat == MP_IMPORT_STAT_NO_EXIST) { + module_obj = mp_module_get_builtin(level_mod_name, true); + if (module_obj != MP_OBJ_NULL) { + return module_obj; + } + } } else { DEBUG_printf("Searching for sub-module\n"); @@ -637,7 +631,7 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) { // Try the name directly as a built-in. qstr module_name_qstr = mp_obj_str_get_qstr(args[0]); - mp_obj_t module_obj = mp_module_get_builtin(module_name_qstr); + mp_obj_t module_obj = mp_module_get_builtin(module_name_qstr, false); if (module_obj != MP_OBJ_NULL) { return module_obj; } diff --git a/py/makemoduledefs.py b/py/makemoduledefs.py index 9061cd890b..2f787905a9 100644 --- a/py/makemoduledefs.py +++ b/py/makemoduledefs.py @@ -1,8 +1,17 @@ """ This pre-processor parses a single file containing a list of -MP_REGISTER_MODULE(module_name, obj_module) -These are used to generate a header with the required entries for -"mp_rom_map_elem_t mp_builtin_module_table[]" in py/objmodule.c +`MP_REGISTER_MODULE(MP_QSTR_module_name, obj_module)` or +`MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_module_name, obj_module)` +(i.e. the output of `py/makeqstrdefs.py cat module`). + +The output is a header (typically moduledefs.h) which is included by +py/objmodule.c that contains entries to be included in the definition of + - mp_rom_map_elem_t mp_builtin_module_table[] + - mp_rom_map_elem_t mp_builtin_extensible_module_table[] + +Extensible modules are modules that can be overridden from the filesystem, see +py/builtinimnport.c:process_import_at_level. Regular modules will always use +the built-in version. """ from __future__ import print_function @@ -13,7 +22,10 @@ import io import argparse -pattern = re.compile(r"\s*MP_REGISTER_MODULE\((.*?),\s*(.*?)\);", flags=re.DOTALL) +pattern = re.compile( + r"\s*(MP_REGISTER_MODULE|MP_REGISTER_EXTENSIBLE_MODULE)\(MP_QSTR_(.*?),\s*(.*?)\);", + flags=re.DOTALL, +) def find_module_registrations(filename): @@ -37,14 +49,23 @@ def generate_module_table_header(modules): # Print header file for all external modules. mod_defs = set() + extensible_mod_defs = set() print("// Automatically generated by makemoduledefs.py.\n") - for module_name, obj_module in modules: + for macro_name, module_name, obj_module in modules: mod_def = "MODULE_DEF_{}".format(module_name.upper()) - mod_defs.add(mod_def) + if macro_name == "MP_REGISTER_MODULE": + mod_defs.add(mod_def) + elif macro_name == "MP_REGISTER_EXTENSIBLE_MODULE": + extensible_mod_defs.add(mod_def) if "," in obj_module: print( - "ERROR: Call to MP_REGISTER_MODULE({}, {}) should be MP_REGISTER_MODULE({}, {})\n".format( - module_name, obj_module, module_name, obj_module.split(",")[0] + "ERROR: Call to {}({}, {}) should be {}({}, {})\n".format( + macro_name, + module_name, + obj_module, + macro_name, + module_name, + obj_module.split(",")[0], ), file=sys.stderr, ) @@ -53,7 +74,7 @@ def generate_module_table_header(modules): ( "extern const struct _mp_obj_module_t {obj_module};\n" "#undef {mod_def}\n" - "#define {mod_def} {{ MP_ROM_QSTR({module_name}), MP_ROM_PTR(&{obj_module}) }},\n" + "#define {mod_def} {{ MP_ROM_QSTR(MP_QSTR_{module_name}), MP_ROM_PTR(&{obj_module}) }},\n" ).format( module_name=module_name, obj_module=obj_module, @@ -68,6 +89,13 @@ def generate_module_table_header(modules): print("// MICROPY_REGISTERED_MODULES") + print("\n#define MICROPY_REGISTERED_EXTENSIBLE_MODULES \\") + + for mod_def in sorted(extensible_mod_defs): + print(" {mod_def} \\".format(mod_def=mod_def)) + + print("// MICROPY_REGISTERED_EXTENSIBLE_MODULES") + def main(): parser = argparse.ArgumentParser() diff --git a/py/makeqstrdefs.py b/py/makeqstrdefs.py index 13a8b54d67..dd96513351 100644 --- a/py/makeqstrdefs.py +++ b/py/makeqstrdefs.py @@ -21,7 +21,7 @@ _MODE_QSTR = "qstr" # Extract MP_COMPRESSED_ROM_TEXT("") macros. (Which come from MP_ERROR_TEXT) _MODE_COMPRESS = "compress" -# Extract MP_REGISTER_MODULE(...) macros. +# Extract MP_REGISTER_(EXTENSIBLE_)MODULE(...) macros. _MODE_MODULE = "module" # Extract MP_REGISTER_ROOT_POINTER(...) macros. @@ -93,7 +93,7 @@ def process_file(f): elif args.mode == _MODE_COMPRESS: re_match = re.compile(r'MP_COMPRESSED_ROM_TEXT\("([^"]*)"\)') elif args.mode == _MODE_MODULE: - re_match = re.compile(r"MP_REGISTER_MODULE\(.*?,\s*.*?\);") + re_match = re.compile(r"MP_REGISTER_(?:EXTENSIBLE_)?MODULE\(.*?,\s*.*?\);") elif args.mode == _MODE_ROOT_POINTER: re_match = re.compile(r"MP_REGISTER_ROOT_POINTER\(.*?\);") output = [] diff --git a/py/obj.h b/py/obj.h index 3735b72c22..005383e9f3 100644 --- a/py/obj.h +++ b/py/obj.h @@ -434,6 +434,9 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t; // param obj_module: mp_obj_module_t instance #define MP_REGISTER_MODULE(module_name, obj_module) +// As above, but allow this module to be extended from the filesystem. +#define MP_REGISTER_EXTENSIBLE_MODULE(module_name, obj_module) + // Declare a root pointer (to avoid garbage collection of a global static variable). // param variable_declaration: a valid C variable declaration #define MP_REGISTER_ROOT_POINTER(variable_declaration) diff --git a/py/objmodule.c b/py/objmodule.c index e63fb18a1e..bf38366266 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -166,17 +166,54 @@ mp_obj_t mp_obj_new_module(qstr module_name) { // Global module table and related functions STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { - // builtin modules declared with MP_REGISTER_MODULE() + // built-in modules declared with MP_REGISTER_MODULE() MICROPY_REGISTERED_MODULES }; MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table); -// Attempts to find (and initialise) a builtin, otherwise returns +STATIC const mp_rom_map_elem_t mp_builtin_extensible_module_table[] = { + // built-in modules declared with MP_REGISTER_EXTENSIBLE_MODULE() + MICROPY_REGISTERED_EXTENSIBLE_MODULES +}; +MP_DEFINE_CONST_MAP(mp_builtin_extensible_module_map, mp_builtin_extensible_module_table); + +// Attempts to find (and initialise) a built-in, otherwise returns // MP_OBJ_NULL. -mp_obj_t mp_module_get_builtin(qstr module_name) { - mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)&mp_builtin_module_map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); +mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) { + mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)(extensible ? &mp_builtin_extensible_module_map : &mp_builtin_module_map), MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); if (!elem) { - return MP_OBJ_NULL; + #if MICROPY_PY_SYS + // Special case for sys, which isn't extensible but can always be + // imported with the alias `usys`. + if (module_name == MP_QSTR_usys) { + return MP_OBJ_FROM_PTR(&mp_module_sys); + } + #endif + + if (extensible) { + // At this point we've already tried non-extensible built-ins, the + // filesystem, and now extensible built-ins. No match, so fail + // the import. + return MP_OBJ_NULL; + } + + // We're trying to match a non-extensible built-in (i.e. before trying + // the filesystem), but if the user is importing `ufoo`, _and_ `foo` + // is an extensible module, then allow it as a way of forcing the + // built-in. Essentially, this makes it as if all the extensible + // built-ins also had non-extensible aliases named `ufoo`. Newer code + // should be using sys.path to force the built-in, but this retains + // the old behaviour of the u-prefix being used to force a built-in + // import. + size_t module_name_len; + const char *module_name_str = (const char *)qstr_data(module_name, &module_name_len); + if (module_name_str[0] != 'u') { + return MP_OBJ_NULL; + } + elem = mp_map_lookup((mp_map_t *)&mp_builtin_extensible_module_map, MP_OBJ_NEW_QSTR(qstr_from_strn(module_name_str + 1, module_name_len - 1)), MP_MAP_LOOKUP); + if (!elem) { + return MP_OBJ_NULL; + } } #if MICROPY_MODULE_BUILTIN_INIT diff --git a/py/objmodule.h b/py/objmodule.h index 11bd7bb42f..63ae3c3bdf 100644 --- a/py/objmodule.h +++ b/py/objmodule.h @@ -32,8 +32,9 @@ #define MP_MODULE_ATTR_DELEGATION_ENTRY(ptr) { MP_ROM_QSTR(MP_QSTRnull), MP_ROM_PTR(ptr) } extern const mp_map_t mp_builtin_module_map; +extern const mp_map_t mp_builtin_extensible_module_map; -mp_obj_t mp_module_get_builtin(qstr module_name); +mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible); void mp_module_generic_attr(qstr attr, mp_obj_t *dest, const uint16_t *keys, mp_obj_t *values); diff --git a/py/repl.c b/py/repl.c index 0369b02195..cf69d3d899 100644 --- a/py/repl.c +++ b/py/repl.c @@ -162,8 +162,8 @@ STATIC bool test_qstr(mp_obj_t obj, qstr name) { return dest[0] != MP_OBJ_NULL; } else { // try builtin module - return mp_map_lookup((mp_map_t *)&mp_builtin_module_map, - MP_OBJ_NEW_QSTR(name), MP_MAP_LOOKUP); + return mp_map_lookup((mp_map_t *)&mp_builtin_module_map, MP_OBJ_NEW_QSTR(name), MP_MAP_LOOKUP) || + mp_map_lookup((mp_map_t *)&mp_builtin_extensible_module_map, MP_OBJ_NEW_QSTR(name), MP_MAP_LOOKUP); } } From 2eba98f1e0d292de0f7e48ce228221ef50c01967 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 2 Jun 2023 12:33:25 +1000 Subject: [PATCH 171/565] all: Use MP_REGISTER_EXTENSIBLE_MODULE for overrideable built-ins. Signed-off-by: Jim Mussared --- extmod/modbinascii.c | 2 +- extmod/modbluetooth.c | 6 +++++- extmod/modcryptolib.c | 6 +++++- extmod/modhashlib.c | 2 +- extmod/modheapq.c | 2 +- extmod/modjson.c | 2 +- extmod/modlwip.c | 2 +- extmod/modos.c | 2 +- extmod/modplatform.c | 2 +- extmod/modrandom.c | 2 +- extmod/modre.c | 2 +- extmod/modselect.c | 2 +- extmod/modsocket.c | 2 +- extmod/modssl_axtls.c | 2 +- extmod/modssl_mbedtls.c | 2 +- extmod/modtime.c | 2 +- extmod/modtimeq.c | 2 +- extmod/moductypes.c | 2 ++ extmod/modwebsocket.c | 6 +++++- extmod/modzlib.c | 2 +- ports/cc3200/mods/modmachine.c | 2 +- ports/cc3200/mods/modos.c | 2 +- ports/cc3200/mods/modsocket.c | 2 +- ports/cc3200/mods/modssl.c | 2 +- ports/esp32/modmachine.c | 2 +- ports/esp32/modsocket.c | 2 +- ports/esp8266/modmachine.c | 2 +- ports/mimxrt/modmachine.c | 2 +- ports/nrf/modules/machine/modmachine.c | 2 +- ports/nrf/modules/os/modos.c | 2 +- ports/qemu-arm/modmachine.c | 2 +- ports/renesas-ra/modmachine.c | 2 +- ports/rp2/modmachine.c | 2 +- ports/samd/modmachine.c | 2 +- ports/stm32/modmachine.c | 2 +- ports/unix/modmachine.c | 2 +- ports/unix/modselect.c | 2 +- ports/unix/modsocket.c | 2 +- ports/zephyr/modmachine.c | 2 +- ports/zephyr/modsocket.c | 2 +- py/builtinimport.c | 11 +++++++---- py/modarray.c | 2 +- py/modcollections.c | 2 +- py/moderrno.c | 2 +- py/modio.c | 2 +- py/modstruct.c | 2 +- py/modsys.c | 3 +++ 47 files changed, 68 insertions(+), 48 deletions(-) diff --git a/extmod/modbinascii.c b/extmod/modbinascii.c index af8eab79f0..46027d5fd5 100644 --- a/extmod/modbinascii.c +++ b/extmod/modbinascii.c @@ -203,6 +203,6 @@ const mp_obj_module_t mp_module_binascii = { .globals = (mp_obj_dict_t *)&mp_module_binascii_globals, }; -MP_REGISTER_MODULE(MP_QSTR_binascii, mp_module_binascii); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_binascii, mp_module_binascii); #endif // MICROPY_PY_BINASCII diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 628c643a58..7b13f9556c 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -1004,7 +1004,11 @@ const mp_obj_module_t mp_module_bluetooth = { .globals = (mp_obj_dict_t *)&mp_module_bluetooth_globals, }; -MP_REGISTER_MODULE(MP_QSTR_bluetooth, mp_module_bluetooth); +// This module should not be extensible (as it is not a CPython standard +// library nor is it necessary to override from the filesystem), however it +// has previously been known as `ubluetooth`, so by making it extensible the +// `ubluetooth` alias will continue to work. +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_bluetooth, mp_module_bluetooth); // Helpers diff --git a/extmod/modcryptolib.c b/extmod/modcryptolib.c index 2299477259..b33d8533fc 100644 --- a/extmod/modcryptolib.c +++ b/extmod/modcryptolib.c @@ -375,6 +375,10 @@ const mp_obj_module_t mp_module_cryptolib = { .globals = (mp_obj_dict_t *)&mp_module_cryptolib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_cryptolib, mp_module_cryptolib); +// This module should not be extensible (as it is not a CPython standard +// library nor is it necessary to override from the filesystem), however it +// has previously been known as `ucryptolib`, so by making it extensible the +// `ucryptolib` alias will continue to work. +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_cryptolib, mp_module_cryptolib); #endif // MICROPY_PY_CRYPTOLIB diff --git a/extmod/modhashlib.c b/extmod/modhashlib.c index 1b94cc01a0..3fafe6316d 100644 --- a/extmod/modhashlib.c +++ b/extmod/modhashlib.c @@ -374,6 +374,6 @@ const mp_obj_module_t mp_module_hashlib = { .globals = (mp_obj_dict_t *)&mp_module_hashlib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_hashlib, mp_module_hashlib); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_hashlib, mp_module_hashlib); #endif // MICROPY_PY_HASHLIB diff --git a/extmod/modheapq.c b/extmod/modheapq.c index 79a12c2b9c..db1e35bac2 100644 --- a/extmod/modheapq.c +++ b/extmod/modheapq.c @@ -118,7 +118,7 @@ const mp_obj_module_t mp_module_heapq = { .globals = (mp_obj_dict_t *)&mp_module_heapq_globals, }; -MP_REGISTER_MODULE(MP_QSTR_heapq, mp_module_heapq); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_heapq, mp_module_heapq); #endif #endif // MICROPY_PY_HEAPQ diff --git a/extmod/modjson.c b/extmod/modjson.c index 1b475543e1..1772b72998 100644 --- a/extmod/modjson.c +++ b/extmod/modjson.c @@ -381,6 +381,6 @@ const mp_obj_module_t mp_module_json = { .globals = (mp_obj_dict_t *)&mp_module_json_globals, }; -MP_REGISTER_MODULE(MP_QSTR_json, mp_module_json); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_json, mp_module_json); #endif // MICROPY_PY_JSON diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 24047b0a98..0d4c03c68a 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -1802,7 +1802,7 @@ const mp_obj_module_t mp_module_lwip = { MP_REGISTER_MODULE(MP_QSTR_lwip, mp_module_lwip); // On LWIP-ports, this is the socket module (replaces extmod/modsocket.c). -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_lwip); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_lwip); MP_REGISTER_ROOT_POINTER(mp_obj_t lwip_slip_stream); diff --git a/extmod/modos.c b/extmod/modos.c index e962a6c171..6df49d7f84 100644 --- a/extmod/modos.c +++ b/extmod/modos.c @@ -195,6 +195,6 @@ const mp_obj_module_t mp_module_os = { .globals = (mp_obj_dict_t *)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_os, mp_module_os); #endif // MICROPY_PY_OS diff --git a/extmod/modplatform.c b/extmod/modplatform.c index 4d10bdb4df..73846f946d 100644 --- a/extmod/modplatform.c +++ b/extmod/modplatform.c @@ -75,6 +75,6 @@ const mp_obj_module_t mp_module_platform = { .globals = (mp_obj_dict_t *)&modplatform_globals, }; -MP_REGISTER_MODULE(MP_QSTR_platform, mp_module_platform); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_platform, mp_module_platform); #endif // MICROPY_PY_PLATFORM diff --git a/extmod/modrandom.c b/extmod/modrandom.c index 1c697aec70..e65f31488b 100644 --- a/extmod/modrandom.c +++ b/extmod/modrandom.c @@ -255,7 +255,7 @@ const mp_obj_module_t mp_module_random = { .globals = (mp_obj_dict_t *)&mp_module_random_globals, }; -MP_REGISTER_MODULE(MP_QSTR_random, mp_module_random); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_random, mp_module_random); #endif #endif // MICROPY_PY_RANDOM diff --git a/extmod/modre.c b/extmod/modre.c index c8a019be89..7f00b1c23c 100644 --- a/extmod/modre.c +++ b/extmod/modre.c @@ -470,7 +470,7 @@ const mp_obj_module_t mp_module_re = { .globals = (mp_obj_dict_t *)&mp_module_re_globals, }; -MP_REGISTER_MODULE(MP_QSTR_re, mp_module_re); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_re, mp_module_re); #endif // Source files #include'd here to make sure they're compiled in diff --git a/extmod/modselect.c b/extmod/modselect.c index 011d5cb832..3d7ccbd995 100644 --- a/extmod/modselect.c +++ b/extmod/modselect.c @@ -373,6 +373,6 @@ const mp_obj_module_t mp_module_select = { .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; -MP_REGISTER_MODULE(MP_QSTR_select, mp_module_select); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_select, mp_module_select); #endif // MICROPY_PY_SELECT diff --git a/extmod/modsocket.c b/extmod/modsocket.c index 316a578ac2..488b6d1712 100644 --- a/extmod/modsocket.c +++ b/extmod/modsocket.c @@ -653,6 +653,6 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_NETWORK && MICROPY_PY_SOCKET && !MICROPY_PY_LWIP diff --git a/extmod/modssl_axtls.c b/extmod/modssl_axtls.c index 1c9caf76eb..de6e0ce5dd 100644 --- a/extmod/modssl_axtls.c +++ b/extmod/modssl_axtls.c @@ -357,6 +357,6 @@ const mp_obj_module_t mp_module_ssl = { .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_ssl, mp_module_ssl); #endif // MICROPY_PY_SSL && MICROPY_SSL_AXTLS diff --git a/extmod/modssl_mbedtls.c b/extmod/modssl_mbedtls.c index d724e0a08a..c230b1eaa2 100644 --- a/extmod/modssl_mbedtls.c +++ b/extmod/modssl_mbedtls.c @@ -507,6 +507,6 @@ const mp_obj_module_t mp_module_ssl = { .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_ssl, mp_module_ssl); #endif // MICROPY_PY_SSL && MICROPY_SSL_MBEDTLS diff --git a/extmod/modtime.c b/extmod/modtime.c index 163b874d5e..805c2621c0 100644 --- a/extmod/modtime.c +++ b/extmod/modtime.c @@ -231,6 +231,6 @@ const mp_obj_module_t mp_module_time = { .globals = (mp_obj_dict_t *)&mp_module_time_globals, }; -MP_REGISTER_MODULE(MP_QSTR_time, mp_module_time); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_time, mp_module_time); #endif // MICROPY_PY_TIME diff --git a/extmod/modtimeq.c b/extmod/modtimeq.c index 7c037ea0a9..4edb7dd3c8 100644 --- a/extmod/modtimeq.c +++ b/extmod/modtimeq.c @@ -230,6 +230,6 @@ const mp_obj_module_t mp_module_timeq = { .globals = (mp_obj_dict_t *)&mp_module_timeq_globals, }; -MP_REGISTER_MODULE(MP_QSTR_timeq, mp_module_timeq); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_timeq, mp_module_timeq); #endif // MICROPY_PY_TIMEQ diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 86d82f03ba..63be621fbc 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -718,6 +718,8 @@ const mp_obj_module_t mp_module_uctypes = { .globals = (mp_obj_dict_t *)&mp_module_uctypes_globals, }; +// uctypes is not a Python standard library module (hence "uctypes" +// not "ctypes") and therefore shouldn't be extensible. MP_REGISTER_MODULE(MP_QSTR_uctypes, mp_module_uctypes); #endif diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c index 3bf50cc58c..d2cb720396 100644 --- a/extmod/modwebsocket.c +++ b/extmod/modwebsocket.c @@ -311,6 +311,10 @@ const mp_obj_module_t mp_module_websocket = { .globals = (mp_obj_dict_t *)&websocket_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_websocket, mp_module_websocket); +// This module should not be extensible (as it is not a CPython standard +// library nor is it necessary to override from the filesystem), however it +// has previously been known as `uwebsocket`, so by making it extensible the +// `uwebsocket` alias will continue to work. +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_websocket, mp_module_websocket); #endif // MICROPY_PY_WEBSOCKET diff --git a/extmod/modzlib.c b/extmod/modzlib.c index a912f113ce..31096cfeb9 100644 --- a/extmod/modzlib.c +++ b/extmod/modzlib.c @@ -224,7 +224,7 @@ const mp_obj_module_t mp_module_zlib = { }; -MP_REGISTER_MODULE(MP_QSTR_zlib, mp_module_zlib); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_zlib, mp_module_zlib); #endif // Source files #include'd here to make sure they're compiled in diff --git a/ports/cc3200/mods/modmachine.c b/ports/cc3200/mods/modmachine.c index a695fdccae..bdf963c31a 100644 --- a/ports/cc3200/mods/modmachine.c +++ b/ports/cc3200/mods/modmachine.c @@ -214,5 +214,5 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t*)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); MP_REGISTER_ROOT_POINTER(mp_obj_t machine_config_main); diff --git a/ports/cc3200/mods/modos.c b/ports/cc3200/mods/modos.c index 7b1e8d79fd..1a854750f2 100644 --- a/ports/cc3200/mods/modos.c +++ b/ports/cc3200/mods/modos.c @@ -180,4 +180,4 @@ const mp_obj_module_t mp_module_os = { .globals = (mp_obj_dict_t*)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_os, mp_module_os); diff --git a/ports/cc3200/mods/modsocket.c b/ports/cc3200/mods/modsocket.c index fd09cd6a41..a107fa7120 100644 --- a/ports/cc3200/mods/modsocket.c +++ b/ports/cc3200/mods/modsocket.c @@ -818,4 +818,4 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t*)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); diff --git a/ports/cc3200/mods/modssl.c b/ports/cc3200/mods/modssl.c index eb3aea1f85..15c825fcf4 100644 --- a/ports/cc3200/mods/modssl.c +++ b/ports/cc3200/mods/modssl.c @@ -160,4 +160,4 @@ const mp_obj_module_t mp_module_ssl = { .globals = (mp_obj_dict_t*)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_ssl, mp_module_ssl); diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index a863f716c7..fc19618b73 100644 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -353,6 +353,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 0b2d40e333..731f69fbc2 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -872,4 +872,4 @@ const mp_obj_module_t mp_module_socket = { // Note: This port doesn't define MICROPY_PY_SOCKET or MICROPY_PY_LWIP so // this will not conflict with the common implementation provided by // extmod/mod{lwip,socket}.c. -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c index 383f46dda7..64346b4deb 100644 --- a/ports/esp8266/modmachine.c +++ b/ports/esp8266/modmachine.c @@ -456,6 +456,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/mimxrt/modmachine.c b/ports/mimxrt/modmachine.c index 098c3b949a..423a67d609 100644 --- a/ports/mimxrt/modmachine.c +++ b/ports/mimxrt/modmachine.c @@ -185,6 +185,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/nrf/modules/machine/modmachine.c b/ports/nrf/modules/machine/modmachine.c index b7cbdc7b2d..616757a96a 100644 --- a/ports/nrf/modules/machine/modmachine.c +++ b/ports/nrf/modules/machine/modmachine.c @@ -266,6 +266,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t*)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/nrf/modules/os/modos.c b/ports/nrf/modules/os/modos.c index 7c54f28ab4..7654ac119b 100644 --- a/ports/nrf/modules/os/modos.c +++ b/ports/nrf/modules/os/modos.c @@ -197,4 +197,4 @@ const mp_obj_module_t mp_module_os = { .globals = (mp_obj_dict_t*)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_os, mp_module_os); diff --git a/ports/qemu-arm/modmachine.c b/ports/qemu-arm/modmachine.c index 1f9151ff74..0d712f792e 100644 --- a/ports/qemu-arm/modmachine.c +++ b/ports/qemu-arm/modmachine.c @@ -48,6 +48,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/renesas-ra/modmachine.c b/ports/renesas-ra/modmachine.c index 07e6103aaa..47f7e8c805 100644 --- a/ports/renesas-ra/modmachine.c +++ b/ports/renesas-ra/modmachine.c @@ -307,6 +307,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c index 61b91bda0a..1efbb09312 100644 --- a/ports/rp2/modmachine.c +++ b/ports/rp2/modmachine.c @@ -278,6 +278,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index 9890e3b590..9d5b7c2e27 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -297,6 +297,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index e6eb73f9cb..25fc66eb9c 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -471,6 +471,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index 29ac532d2b..dd3cbf96c0 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -110,6 +110,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/unix/modselect.c b/ports/unix/modselect.c index 97c3602e4b..894820c63d 100644 --- a/ports/unix/modselect.c +++ b/ports/unix/modselect.c @@ -351,6 +351,6 @@ const mp_obj_module_t mp_module_select = { .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; -MP_REGISTER_MODULE(MP_QSTR_select, mp_module_select); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_select, mp_module_select); #endif // MICROPY_PY_SELECT_POSIX diff --git a/ports/unix/modsocket.c b/ports/unix/modsocket.c index 9854f3cbce..871be8dcf7 100644 --- a/ports/unix/modsocket.c +++ b/ports/unix/modsocket.c @@ -707,6 +707,6 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_SOCKET diff --git a/ports/zephyr/modmachine.c b/ports/zephyr/modmachine.c index 6f4bbbdab6..6334168054 100644 --- a/ports/zephyr/modmachine.c +++ b/ports/zephyr/modmachine.c @@ -89,6 +89,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/zephyr/modsocket.c b/ports/zephyr/modsocket.c index 8d4197410c..eacdb049da 100644 --- a/ports/zephyr/modsocket.c +++ b/ports/zephyr/modsocket.c @@ -473,6 +473,6 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_SOCKET diff --git a/py/builtinimport.c b/py/builtinimport.c index 15521c77c4..8a125fc538 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -380,20 +380,23 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t module_obj; if (outer_module_obj == MP_OBJ_NULL) { + // First module in the dotted-name path. DEBUG_printf("Searching for top-level module\n"); // An import of a non-extensible built-in will always bypass the - // filesystem. e.g. `import micropython` or `import pyb`. + // filesystem. e.g. `import micropython` or `import pyb`. So try and + // match a non-extensible built-ins first. module_obj = mp_module_get_builtin(level_mod_name, false); if (module_obj != MP_OBJ_NULL) { return module_obj; } - // First module in the dotted-name; search for a directory or file - // relative to all the locations in sys.path. + // Next try the filesystem. Search for a directory or file relative to + // all the locations in sys.path. stat = stat_top_level(level_mod_name, &path); - // TODO: If stat failed, now try extensible built-in modules. + // If filesystem failed, now try and see if it matches an extensible + // built-in module. if (stat == MP_IMPORT_STAT_NO_EXIST) { module_obj = mp_module_get_builtin(level_mod_name, true); if (module_obj != MP_OBJ_NULL) { diff --git a/py/modarray.c b/py/modarray.c index cfed0fbb59..ac2e56ed38 100644 --- a/py/modarray.c +++ b/py/modarray.c @@ -40,6 +40,6 @@ const mp_obj_module_t mp_module_array = { .globals = (mp_obj_dict_t *)&mp_module_array_globals, }; -MP_REGISTER_MODULE(MP_QSTR_array, mp_module_array); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_array, mp_module_array); #endif diff --git a/py/modcollections.c b/py/modcollections.c index a56fe069ea..30a5881bc2 100644 --- a/py/modcollections.c +++ b/py/modcollections.c @@ -46,6 +46,6 @@ const mp_obj_module_t mp_module_collections = { .globals = (mp_obj_dict_t *)&mp_module_collections_globals, }; -MP_REGISTER_MODULE(MP_QSTR_collections, mp_module_collections); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_collections, mp_module_collections); #endif // MICROPY_PY_COLLECTIONS diff --git a/py/moderrno.c b/py/moderrno.c index 99ca101bd6..4f0673a23a 100644 --- a/py/moderrno.c +++ b/py/moderrno.c @@ -99,7 +99,7 @@ const mp_obj_module_t mp_module_errno = { .globals = (mp_obj_dict_t *)&mp_module_errno_globals, }; -MP_REGISTER_MODULE(MP_QSTR_errno, mp_module_errno); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_errno, mp_module_errno); qstr mp_errno_to_str(mp_obj_t errno_val) { #if MICROPY_PY_ERRNO_ERRORCODE diff --git a/py/modio.c b/py/modio.c index 3462611d71..39317c52d5 100644 --- a/py/modio.c +++ b/py/modio.c @@ -226,6 +226,6 @@ const mp_obj_module_t mp_module_io = { .globals = (mp_obj_dict_t *)&mp_module_io_globals, }; -MP_REGISTER_MODULE(MP_QSTR_io, mp_module_io); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_io, mp_module_io); #endif diff --git a/py/modstruct.c b/py/modstruct.c index e908c73e1d..42f91b282c 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -266,6 +266,6 @@ const mp_obj_module_t mp_module_struct = { .globals = (mp_obj_dict_t *)&mp_module_struct_globals, }; -MP_REGISTER_MODULE(MP_QSTR_struct, mp_module_struct); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_struct, mp_module_struct); #endif diff --git a/py/modsys.c b/py/modsys.c index 1cfc09ecfb..ddc732e005 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -294,6 +294,9 @@ const mp_obj_module_t mp_module_sys = { .globals = (mp_obj_dict_t *)&mp_module_sys_globals, }; +// Unlike the other CPython-compatible modules, sys is not extensible from the +// filesystem. We rely on it to work so that things like sys.path are always +// available. MP_REGISTER_MODULE(MP_QSTR_sys, mp_module_sys); // If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is not enabled then these two lists From eb85f4d4c9c332c8e7bef9b20bb06e25f6f6c5d2 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 18 Aug 2022 21:40:53 +1000 Subject: [PATCH 172/565] examples/natmod: Rename umodule to module. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- examples/natmod/{uzlib => heapq}/Makefile | 6 +++--- examples/natmod/{uheapq/uheapq.c => heapq/heapq.c} | 0 examples/natmod/{uheapq => random}/Makefile | 6 +++--- examples/natmod/{urandom/urandom.c => random/random.c} | 0 examples/natmod/{ure => re}/Makefile | 6 +++--- examples/natmod/{ure/ure.c => re/re.c} | 0 examples/natmod/{urandom => zlib}/Makefile | 6 +++--- examples/natmod/{uzlib/uzlib.c => zlib/zlib.c} | 0 tools/ci.sh | 10 +++++----- 9 files changed, 17 insertions(+), 17 deletions(-) rename examples/natmod/{uzlib => heapq}/Makefile (68%) rename examples/natmod/{uheapq/uheapq.c => heapq/heapq.c} (100%) rename examples/natmod/{uheapq => random}/Makefile (67%) rename examples/natmod/{urandom/urandom.c => random/random.c} (100%) rename examples/natmod/{ure => re}/Makefile (69%) rename examples/natmod/{ure/ure.c => re/re.c} (100%) rename examples/natmod/{urandom => zlib}/Makefile (66%) rename examples/natmod/{uzlib/uzlib.c => zlib/zlib.c} (100%) diff --git a/examples/natmod/uzlib/Makefile b/examples/natmod/heapq/Makefile similarity index 68% rename from examples/natmod/uzlib/Makefile rename to examples/natmod/heapq/Makefile index 8761caf2dd..af45b472da 100644 --- a/examples/natmod/uzlib/Makefile +++ b/examples/natmod/heapq/Makefile @@ -1,11 +1,11 @@ # Location of top-level MicroPython directory MPY_DIR = ../../.. -# Name of module (different to built-in uzlib so it can coexist) -MOD = uzlib_$(ARCH) +# Name of module (different to built-in heapq so it can coexist) +MOD = heapq_$(ARCH) # Source files (.c or .py) -SRC = uzlib.c +SRC = heapq.c # Architecture to build for (x86, x64, armv7m, xtensa, xtensawin) ARCH = x64 diff --git a/examples/natmod/uheapq/uheapq.c b/examples/natmod/heapq/heapq.c similarity index 100% rename from examples/natmod/uheapq/uheapq.c rename to examples/natmod/heapq/heapq.c diff --git a/examples/natmod/uheapq/Makefile b/examples/natmod/random/Makefile similarity index 67% rename from examples/natmod/uheapq/Makefile rename to examples/natmod/random/Makefile index 55de3cc081..5c50227b15 100644 --- a/examples/natmod/uheapq/Makefile +++ b/examples/natmod/random/Makefile @@ -1,11 +1,11 @@ # Location of top-level MicroPython directory MPY_DIR = ../../.. -# Name of module (different to built-in uheapq so it can coexist) -MOD = uheapq_$(ARCH) +# Name of module (different to built-in random so it can coexist) +MOD = random_$(ARCH) # Source files (.c or .py) -SRC = uheapq.c +SRC = random.c # Architecture to build for (x86, x64, armv7m, xtensa, xtensawin) ARCH = x64 diff --git a/examples/natmod/urandom/urandom.c b/examples/natmod/random/random.c similarity index 100% rename from examples/natmod/urandom/urandom.c rename to examples/natmod/random/random.c diff --git a/examples/natmod/ure/Makefile b/examples/natmod/re/Makefile similarity index 69% rename from examples/natmod/ure/Makefile rename to examples/natmod/re/Makefile index f5254298fd..1ba5401106 100644 --- a/examples/natmod/ure/Makefile +++ b/examples/natmod/re/Makefile @@ -1,11 +1,11 @@ # Location of top-level MicroPython directory MPY_DIR = ../../.. -# Name of module (different to built-in ure so it can coexist) -MOD = ure_$(ARCH) +# Name of module (different to built-in re so it can coexist) +MOD = re_$(ARCH) # Source files (.c or .py) -SRC = ure.c +SRC = re.c # Architecture to build for (x86, x64, armv7m, xtensa, xtensawin) ARCH = x64 diff --git a/examples/natmod/ure/ure.c b/examples/natmod/re/re.c similarity index 100% rename from examples/natmod/ure/ure.c rename to examples/natmod/re/re.c diff --git a/examples/natmod/urandom/Makefile b/examples/natmod/zlib/Makefile similarity index 66% rename from examples/natmod/urandom/Makefile rename to examples/natmod/zlib/Makefile index 3f018baaf7..e4b4e0712e 100644 --- a/examples/natmod/urandom/Makefile +++ b/examples/natmod/zlib/Makefile @@ -1,11 +1,11 @@ # Location of top-level MicroPython directory MPY_DIR = ../../.. -# Name of module (different to built-in urandom so it can coexist) -MOD = urandom_$(ARCH) +# Name of module (different to built-in zlib so it can coexist) +MOD = zlib_$(ARCH) # Source files (.c or .py) -SRC = urandom.c +SRC = zlib.c # Architecture to build for (x86, x64, armv7m, xtensa, xtensawin) ARCH = x64 diff --git a/examples/natmod/uzlib/uzlib.c b/examples/natmod/zlib/zlib.c similarity index 100% rename from examples/natmod/uzlib/uzlib.c rename to examples/natmod/zlib/zlib.c diff --git a/tools/ci.sh b/tools/ci.sh index 8d361e2b39..21acc17535 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -454,10 +454,10 @@ function ci_native_mpy_modules_build { make -C examples/natmod/features3 ARCH=$arch make -C examples/natmod/btree ARCH=$arch make -C examples/natmod/framebuf ARCH=$arch - make -C examples/natmod/uheapq ARCH=$arch - make -C examples/natmod/urandom ARCH=$arch - make -C examples/natmod/ure ARCH=$arch - make -C examples/natmod/uzlib ARCH=$arch + make -C examples/natmod/heapq ARCH=$arch + make -C examples/natmod/random ARCH=$arch + make -C examples/natmod/re ARCH=$arch + make -C examples/natmod/zlib ARCH=$arch } function ci_native_mpy_modules_32bit_build { @@ -523,7 +523,7 @@ function ci_unix_coverage_run_mpy_merge_tests { function ci_unix_coverage_run_native_mpy_tests { MICROPYPATH=examples/natmod/features2 ./ports/unix/build-coverage/micropython -m features2 - (cd tests && ./run-natmodtests.py "$@" extmod/{btree*,framebuf*,uheapq*,urandom*,ure*,uzlib*}.py) + (cd tests && ./run-natmodtests.py "$@" extmod/{btree*,framebuf*,heapq*,random*,re*,zlib*}.py) } function ci_unix_32bit_setup { From 13c817e61cf2f00fc398e01840e5d8c20e575c8c Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Mon, 5 Jun 2023 15:52:57 +1000 Subject: [PATCH 173/565] py/objmodule: Add a table of built-in modules with delegation. This replaces the previous QSTR_null entry in the globals dict which could leak out to Python (e.g. via iteration of mod.__dict__) and could lead to crashes. It results in smaller code size at the expense of turning a lookup into a loop, but the list it is looping over likely only contains one or two elements. To allow a module to register its custom attr function it can use the new `MP_REGISTER_MODULE_DELEGATION` macro. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- py/builtin.h | 2 ++ py/builtinhelp.c | 7 +------ py/makemoduledefs.py | 27 +++++++++++++++++++++++---- py/makeqstrdefs.py | 4 +++- py/modsys.c | 8 ++------ py/mpconfig.h | 4 ++-- py/obj.h | 4 ++++ py/objmodule.c | 44 ++++++++++++++++++++++++++++++-------------- py/objmodule.h | 3 --- 9 files changed, 67 insertions(+), 36 deletions(-) diff --git a/py/builtin.h b/py/builtin.h index 81d0789802..57f275fb31 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -132,6 +132,8 @@ extern const mp_obj_module_t mp_module___main__; extern const mp_obj_module_t mp_module_builtins; extern const mp_obj_module_t mp_module_sys; +void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); + // Modules needed by the parser when MICROPY_COMP_MODULE_CONST is enabled. extern const mp_obj_module_t mp_module_errno; extern const mp_obj_module_t mp_module_uctypes; diff --git a/py/builtinhelp.c b/py/builtinhelp.c index c60ed44e9c..9bd56cca09 100644 --- a/py/builtinhelp.c +++ b/py/builtinhelp.c @@ -151,12 +151,7 @@ STATIC void mp_help_print_obj(const mp_obj_t obj) { if (map != NULL) { for (uint i = 0; i < map->alloc; i++) { mp_obj_t key = map->table[i].key; - if (key != MP_OBJ_NULL - #if MICROPY_MODULE_ATTR_DELEGATION - // MP_MODULE_ATTR_DELEGATION_ENTRY entries have MP_QSTRnull as qstr key. - && key != MP_OBJ_NEW_QSTR(MP_QSTRnull) - #endif - ) { + if (key != MP_OBJ_NULL) { mp_help_print_info_about_object(key, map->table[i].value); } } diff --git a/py/makemoduledefs.py b/py/makemoduledefs.py index 2f787905a9..5a1362a4c9 100644 --- a/py/makemoduledefs.py +++ b/py/makemoduledefs.py @@ -22,11 +22,16 @@ import io import argparse -pattern = re.compile( +register_pattern = re.compile( r"\s*(MP_REGISTER_MODULE|MP_REGISTER_EXTENSIBLE_MODULE)\(MP_QSTR_(.*?),\s*(.*?)\);", flags=re.DOTALL, ) +delegation_pattern = re.compile( + r"\s*(?:MP_REGISTER_MODULE_DELEGATION)\((.*?),\s*(.*?)\);", + flags=re.DOTALL, +) + def find_module_registrations(filename): """Find any MP_REGISTER_MODULE definitions in the provided file. @@ -37,7 +42,8 @@ def find_module_registrations(filename): global pattern with io.open(filename, encoding="utf-8") as c_file_obj: - return set(re.findall(pattern, c_file_obj.read())) + c = c_file_obj.read() + return set(re.findall(register_pattern, c)), set(re.findall(delegation_pattern, c)) def generate_module_table_header(modules): @@ -50,7 +56,6 @@ def generate_module_table_header(modules): # Print header file for all external modules. mod_defs = set() extensible_mod_defs = set() - print("// Automatically generated by makemoduledefs.py.\n") for macro_name, module_name, obj_module in modules: mod_def = "MODULE_DEF_{}".format(module_name.upper()) if macro_name == "MP_REGISTER_MODULE": @@ -97,13 +102,27 @@ def generate_module_table_header(modules): print("// MICROPY_REGISTERED_EXTENSIBLE_MODULES") +def generate_module_delegations(delegations): + print("\n#define MICROPY_MODULE_DELEGATIONS \\") + for obj_module, fun_name in delegations: + print( + " {{ MP_ROM_PTR(&{obj_module}), {fun_name} }},".format( + obj_module=obj_module, fun_name=fun_name + ) + ) + print("// MICROPY_MODULE_DELEGATIONS") + + def main(): parser = argparse.ArgumentParser() parser.add_argument("file", nargs=1, help="file with MP_REGISTER_MODULE definitions") args = parser.parse_args() - modules = find_module_registrations(args.file[0]) + print("// Automatically generated by makemoduledefs.py.\n") + + modules, delegations = find_module_registrations(args.file[0]) generate_module_table_header(sorted(modules)) + generate_module_delegations(sorted(delegations)) if __name__ == "__main__": diff --git a/py/makeqstrdefs.py b/py/makeqstrdefs.py index dd96513351..64249f76ce 100644 --- a/py/makeqstrdefs.py +++ b/py/makeqstrdefs.py @@ -93,7 +93,9 @@ def process_file(f): elif args.mode == _MODE_COMPRESS: re_match = re.compile(r'MP_COMPRESSED_ROM_TEXT\("([^"]*)"\)') elif args.mode == _MODE_MODULE: - re_match = re.compile(r"MP_REGISTER_(?:EXTENSIBLE_)?MODULE\(.*?,\s*.*?\);") + re_match = re.compile( + r"(?:MP_REGISTER_MODULE|MP_REGISTER_EXTENSIBLE_MODULE|MP_REGISTER_MODULE_DELEGATION)\(.*?,\s*.*?\);" + ) elif args.mode == _MODE_ROOT_POINTER: re_match = re.compile(r"MP_REGISTER_ROOT_POINTER\(.*?\);") output = [] diff --git a/py/modsys.c b/py/modsys.c index ddc732e005..a0ecb87b5f 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -207,7 +207,7 @@ STATIC const uint16_t sys_mutable_keys[] = { MP_QSTRnull, }; -STATIC void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { MP_STATIC_ASSERT(MP_ARRAY_SIZE(sys_mutable_keys) == MP_SYS_MUTABLE_NUM + 1); MP_STATIC_ASSERT(MP_ARRAY_SIZE(MP_STATE_VM(sys_mutable)) == MP_SYS_MUTABLE_NUM); mp_module_generic_attr(attr, dest, sys_mutable_keys, MP_STATE_VM(sys_mutable)); @@ -280,11 +280,6 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { #if MICROPY_PY_SYS_ATEXIT { MP_ROM_QSTR(MP_QSTR_atexit), MP_ROM_PTR(&mp_sys_atexit_obj) }, #endif - - #if MICROPY_PY_SYS_ATTR_DELEGATION - // Delegation of attr lookup. - MP_MODULE_ATTR_DELEGATION_ENTRY(&mp_module_sys_attr), - #endif }; STATIC MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table); @@ -317,6 +312,7 @@ MP_REGISTER_ROOT_POINTER(mp_obj_t sys_exitfunc); #if MICROPY_PY_SYS_ATTR_DELEGATION // Contains mutable sys attributes. MP_REGISTER_ROOT_POINTER(mp_obj_t sys_mutable[MP_SYS_MUTABLE_NUM]); +MP_REGISTER_MODULE_DELEGATION(mp_module_sys, &mp_module_sys_attr); #endif #endif // MICROPY_PY_SYS diff --git a/py/mpconfig.h b/py/mpconfig.h index a004f548ad..504ad64b01 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -839,8 +839,8 @@ typedef double mp_float_t; #define MICROPY_STREAMS_POSIX_API (0) #endif -// Whether modules can use MP_MODULE_ATTR_DELEGATION_ENTRY() to delegate failed -// attribute lookups. +// Whether modules can use MP_REGISTER_MODULE_DELEGATION() to delegate failed +// attribute lookups to a custom handler function. #ifndef MICROPY_MODULE_ATTR_DELEGATION #define MICROPY_MODULE_ATTR_DELEGATION (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif diff --git a/py/obj.h b/py/obj.h index 005383e9f3..de4c15b22c 100644 --- a/py/obj.h +++ b/py/obj.h @@ -437,6 +437,10 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t; // As above, but allow this module to be extended from the filesystem. #define MP_REGISTER_EXTENSIBLE_MODULE(module_name, obj_module) +// Add a custom handler for a builtin module that will be called to delegate +// failed attribute lookups. +#define MP_REGISTER_MODULE_DELEGATION(obj_module, fun_name) + // Declare a root pointer (to avoid garbage collection of a global static variable). // param variable_declaration: a valid C variable declaration #define MP_REGISTER_ROOT_POINTER(variable_declaration) diff --git a/py/objmodule.c b/py/objmodule.c index bf38366266..ad96a3be28 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -63,20 +63,7 @@ STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin mp_printf(print, "", module_name); } -STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { - #if MICROPY_MODULE_ATTR_DELEGATION - // Delegate lookup to a module's custom attr method (found in last lot of globals dict). - mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); - mp_map_t *map = &self->globals->map; - if (map->table[map->alloc - 1].key == MP_OBJ_NEW_QSTR(MP_QSTRnull)) { - ((mp_attr_fun_t)MP_OBJ_TO_PTR(map->table[map->alloc - 1].value))(self_in, attr, dest); - } - #else - (void)self_in; - (void)attr; - (void)dest; - #endif -} +STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest); STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); @@ -177,6 +164,18 @@ STATIC const mp_rom_map_elem_t mp_builtin_extensible_module_table[] = { }; MP_DEFINE_CONST_MAP(mp_builtin_extensible_module_map, mp_builtin_extensible_module_table); +#if MICROPY_MODULE_ATTR_DELEGATION && defined(MICROPY_MODULE_DELEGATIONS) +typedef struct _mp_module_delegation_entry_t { + mp_rom_obj_t mod; + mp_attr_fun_t fun; +} mp_module_delegation_entry_t; + +STATIC const mp_module_delegation_entry_t mp_builtin_module_delegation_table[] = { + // delegation entries declared with MP_REGISTER_MODULE_DELEGATION() + MICROPY_MODULE_DELEGATIONS +}; +#endif + // Attempts to find (and initialise) a built-in, otherwise returns // MP_OBJ_NULL. mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) { @@ -230,6 +229,23 @@ mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) { return elem->value; } +STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { + #if MICROPY_MODULE_ATTR_DELEGATION + // Delegate lookup to a module's custom attr method. + size_t n = MP_ARRAY_SIZE(mp_builtin_module_delegation_table); + for (size_t i = 0; i < n; ++i) { + if (*(mp_obj_t *)(&mp_builtin_module_delegation_table[i].mod) == self_in) { + mp_builtin_module_delegation_table[i].fun(self_in, attr, dest); + break; + } + } + #else + (void)self_in; + (void)attr; + (void)dest; + #endif +} + void mp_module_generic_attr(qstr attr, mp_obj_t *dest, const uint16_t *keys, mp_obj_t *values) { for (size_t i = 0; keys[i] != MP_QSTRnull; ++i) { if (attr == keys[i]) { diff --git a/py/objmodule.h b/py/objmodule.h index 63ae3c3bdf..9cc9a2f102 100644 --- a/py/objmodule.h +++ b/py/objmodule.h @@ -28,9 +28,6 @@ #include "py/obj.h" -// Place at the very end of a module's globals_table. -#define MP_MODULE_ATTR_DELEGATION_ENTRY(ptr) { MP_ROM_QSTR(MP_QSTRnull), MP_ROM_PTR(ptr) } - extern const mp_map_t mp_builtin_module_map; extern const mp_map_t mp_builtin_extensible_module_map; From e6926d60219d9b00da3eedb5eedecefe0d6c321c Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 6 Jun 2023 22:49:50 +1000 Subject: [PATCH 174/565] py/objmodule: Workaround for MSVC with no module delegation. When compiling mpy-cross, there is no `sys` module, and so there will be no entries in the `mp_builtin_module_delegation_table`. MSVC doesn't like this, so instead pretend as if the feature isn't enabled at all. Signed-off-by: Jim Mussared --- py/makemoduledefs.py | 3 +++ py/objmodule.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/py/makemoduledefs.py b/py/makemoduledefs.py index 5a1362a4c9..b1e118bf37 100644 --- a/py/makemoduledefs.py +++ b/py/makemoduledefs.py @@ -103,6 +103,9 @@ def generate_module_table_header(modules): def generate_module_delegations(delegations): + if not delegations: + return + print("\n#define MICROPY_MODULE_DELEGATIONS \\") for obj_module, fun_name in delegations: print( diff --git a/py/objmodule.c b/py/objmodule.c index ad96a3be28..8ffae139bc 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -230,7 +230,7 @@ mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) { } STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { - #if MICROPY_MODULE_ATTR_DELEGATION + #if MICROPY_MODULE_ATTR_DELEGATION && defined(MICROPY_MODULE_DELEGATIONS) // Delegate lookup to a module's custom attr method. size_t n = MP_ARRAY_SIZE(mp_builtin_module_delegation_table); for (size_t i = 0; i < n; ++i) { From 7d2ee8aed0cc5ba1a0041ac4cc7631898aaf252f Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Mon, 5 Jun 2023 22:38:36 +1000 Subject: [PATCH 175/565] py/mpconfig: Enable module delegation if sys needs it. Otherwise you can get into the confusing state where e.g. sys.ps1 is enabled in config (via `MICROPY_PY_SYS_PS1_PS2`) but still doesn't actually get enabled. Also verify that the required delegation options are enabled in modsys.c. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/esp8266/mpconfigport.h | 1 - py/modsys.c | 14 ++++++++++++++ py/mpconfig.h | 2 +- py/mpstate.h | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index 37a794f44b..18b2e47e29 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -19,7 +19,6 @@ #define MICROPY_OPT_MATH_FACTORIAL (0) #define MICROPY_REPL_EMACS_KEYS (0) #define MICROPY_PY_BUILTINS_COMPLEX (0) -#define MICROPY_MODULE_ATTR_DELEGATION (0) #define MICROPY_PY_FUNCTION_ATTRS (0) #define MICROPY_PY_DELATTR_SETATTR (0) #define MICROPY_PY_BUILTINS_STR_CENTER (0) diff --git a/py/modsys.c b/py/modsys.c index a0ecb87b5f..72817ce009 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -195,7 +195,21 @@ STATIC mp_obj_t mp_sys_settrace(mp_obj_t obj) { MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); #endif // MICROPY_PY_SYS_SETTRACE + +#if MICROPY_PY_SYS_PS1_PS2 && !MICROPY_PY_SYS_ATTR_DELEGATION +#error "MICROPY_PY_SYS_PS1_PS2 requires MICROPY_PY_SYS_ATTR_DELEGATION" +#endif + +#if MICROPY_PY_SYS_TRACEBACKLIMIT && !MICROPY_PY_SYS_ATTR_DELEGATION +#error "MICROPY_PY_SYS_TRACEBACKLIMIT requires MICROPY_PY_SYS_ATTR_DELEGATION" +#endif + +#if MICROPY_PY_SYS_ATTR_DELEGATION && !MICROPY_MODULE_ATTR_DELEGATION +#error "MICROPY_PY_SYS_ATTR_DELEGATION requires MICROPY_MODULE_ATTR_DELEGATION" +#endif + #if MICROPY_PY_SYS_ATTR_DELEGATION +// Must be kept in sync with the enum at the top of mpstate.h. STATIC const uint16_t sys_mutable_keys[] = { #if MICROPY_PY_SYS_PS1_PS2 MP_QSTR_ps1, diff --git a/py/mpconfig.h b/py/mpconfig.h index 504ad64b01..b6f8838662 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -842,7 +842,7 @@ typedef double mp_float_t; // Whether modules can use MP_REGISTER_MODULE_DELEGATION() to delegate failed // attribute lookups to a custom handler function. #ifndef MICROPY_MODULE_ATTR_DELEGATION -#define MICROPY_MODULE_ATTR_DELEGATION (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#define MICROPY_MODULE_ATTR_DELEGATION (MICROPY_PY_SYS_ATTR_DELEGATION || MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif // Whether to call __init__ when importing builtin modules for the first time. diff --git a/py/mpstate.h b/py/mpstate.h index 80b49cb6b6..3786131de6 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -40,6 +40,8 @@ // memory system, runtime and virtual machine. The state is a global // variable, but in the future it is hoped that the state can become local. +#if MICROPY_PY_SYS_ATTR_DELEGATION +// Must be kept in sync with sys_mutable_keys in modsys.c. enum { #if MICROPY_PY_SYS_PS1_PS2 MP_SYS_MUTABLE_PS1, @@ -50,6 +52,7 @@ enum { #endif MP_SYS_MUTABLE_NUM, }; +#endif // MICROPY_PY_SYS_ATTR_DELEGATION // This structure contains dynamic configuration for the compiler. #if MICROPY_DYNAMIC_COMPILER From 5e50975a6dd9466afafbcd012c00078093fe1f57 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Mon, 5 Jun 2023 16:52:29 +1000 Subject: [PATCH 176/565] py/modsys: Allow sys.path to be assigned to. Previously sys.path could be modified by append/pop or slice assignment. This allows `sys.path = [...]`, which can be simpler in many cases, but also improves CPython compatibility. It also allows sys.path to be set to a tuple which means that you can clear sys.path (e.g. temporarily) with no allocations. This also makes sys.path (and sys.argv for consistency) able to be disabled via mpconfig. The unix port (and upytesthelper) require them, so they explicitly verify that they're enabled. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/unix/main.c | 66 +++++++++++++++------------- ports/unix/mpconfigport.h | 2 +- py/builtinimport.c | 4 +- py/modsys.c | 18 ++++++-- py/mpconfig.h | 19 +++++++- py/mpstate.h | 3 ++ py/runtime.c | 6 ++- py/runtime.h | 7 ++- shared/upytesthelper/upytesthelper.c | 10 ++++- 9 files changed, 93 insertions(+), 42 deletions(-) diff --git a/ports/unix/main.c b/ports/unix/main.c index 16f663de19..b065706ba6 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -69,6 +69,14 @@ long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4); #define MICROPY_GC_SPLIT_HEAP_N_HEAPS (1) #endif +#if !MICROPY_PY_SYS_PATH +#error "The unix port requires MICROPY_PY_SYS_PATH=1" +#endif + +#if !MICROPY_PY_SYS_ARGV +#error "The unix port requires MICROPY_PY_SYS_ARGV=1" +#endif + STATIC void stderr_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t ret; @@ -538,44 +546,40 @@ MP_NOINLINE int main_(int argc, char **argv) { } #endif - char *home = getenv("HOME"); - char *path = getenv("MICROPYPATH"); - if (path == NULL) { - path = MICROPY_PY_SYS_PATH_DEFAULT; - } - size_t path_num = 1; // [0] is for current dir (or base dir of the script) - if (*path == PATHLIST_SEP_CHAR) { - path_num++; - } - for (char *p = path; p != NULL; p = strchr(p, PATHLIST_SEP_CHAR)) { - path_num++; - if (p != NULL) { - p++; - } - } - mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), path_num); - mp_obj_t *path_items; - mp_obj_list_get(mp_sys_path, &path_num, &path_items); - path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR_); { - char *p = path; - for (mp_uint_t i = 1; i < path_num; i++) { - char *p1 = strchr(p, PATHLIST_SEP_CHAR); - if (p1 == NULL) { - p1 = p + strlen(p); + // sys.path starts as [""] + mp_sys_path = mp_obj_new_list(0, NULL); + mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); + + // Add colon-separated entries from MICROPYPATH. + char *home = getenv("HOME"); + char *path = getenv("MICROPYPATH"); + if (path == NULL) { + path = MICROPY_PY_SYS_PATH_DEFAULT; + } + if (*path == PATHLIST_SEP_CHAR) { + // First entry is empty. We've already added an empty entry to sys.path, so skip it. + ++path; + } + bool path_remaining = *path; + while (path_remaining) { + char *path_entry_end = strchr(path, PATHLIST_SEP_CHAR); + if (path_entry_end == NULL) { + path_entry_end = path + strlen(path); + path_remaining = false; } - if (p[0] == '~' && p[1] == '/' && home != NULL) { + if (path[0] == '~' && path[1] == '/' && home != NULL) { // Expand standalone ~ to $HOME int home_l = strlen(home); vstr_t vstr; - vstr_init(&vstr, home_l + (p1 - p - 1) + 1); + vstr_init(&vstr, home_l + (path_entry_end - path - 1) + 1); vstr_add_strn(&vstr, home, home_l); - vstr_add_strn(&vstr, p + 1, p1 - p - 1); - path_items[i] = mp_obj_new_str_from_vstr(&vstr); + vstr_add_strn(&vstr, path + 1, path_entry_end - path - 1); + mp_obj_list_append(mp_sys_path, mp_obj_new_str_from_vstr(&vstr)); } else { - path_items[i] = mp_obj_new_str_via_qstr(p, p1 - p); + mp_obj_list_append(mp_sys_path, mp_obj_new_str_via_qstr(path, path_entry_end - path)); } - p = p1 + 1; + path = path_entry_end + 1; } } @@ -710,7 +714,7 @@ MP_NOINLINE int main_(int argc, char **argv) { // Set base dir of the script as first entry in sys.path. char *p = strrchr(basedir, '/'); - path_items[0] = mp_obj_new_str_via_qstr(basedir, p - basedir); + mp_obj_list_store(mp_sys_path, MP_OBJ_NEW_SMALL_INT(0), mp_obj_new_str_via_qstr(basedir, p - basedir)); free(pathbuf); set_sys_argv(argv, argc, a); diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 58aba9700b..c20aff1683 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -154,7 +154,7 @@ typedef long mp_off_t; // Ensure builtinimport.c works with -m. #define MICROPY_MODULE_OVERRIDE_MAIN_IMPORT (1) -// Don't default sys.argv because we do that in main. +// Don't default sys.argv and sys.path because we do that in main. #define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (0) // Enable sys.executable. diff --git a/py/builtinimport.c b/py/builtinimport.c index 8a125fc538..4fee04b8f3 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -118,7 +118,7 @@ STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { #if MICROPY_PY_SYS size_t path_num; mp_obj_t *path_items; - mp_obj_list_get(mp_sys_path, &path_num, &path_items); + mp_obj_get_array(mp_sys_path, &path_num, &path_items); // go through each sys.path entry, trying to import "/". for (size_t i = 0; i < path_num; i++) { @@ -365,7 +365,7 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, // which may have come from the filesystem. size_t path_num; mp_obj_t *path_items; - mp_obj_list_get(mp_sys_path, &path_num, &path_items); + mp_obj_get_array(mp_sys_path, &path_num, &path_items); if (path_num) #endif { diff --git a/py/modsys.c b/py/modsys.c index 72817ce009..9b3a2bc163 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -195,6 +195,9 @@ STATIC mp_obj_t mp_sys_settrace(mp_obj_t obj) { MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); #endif // MICROPY_PY_SYS_SETTRACE +#if MICROPY_PY_SYS_PATH && !MICROPY_PY_SYS_ATTR_DELEGATION +#error "MICROPY_PY_SYS_PATH requires MICROPY_PY_SYS_ATTR_DELEGATION" +#endif #if MICROPY_PY_SYS_PS1_PS2 && !MICROPY_PY_SYS_ATTR_DELEGATION #error "MICROPY_PY_SYS_PS1_PS2 requires MICROPY_PY_SYS_ATTR_DELEGATION" @@ -211,6 +214,11 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); #if MICROPY_PY_SYS_ATTR_DELEGATION // Must be kept in sync with the enum at the top of mpstate.h. STATIC const uint16_t sys_mutable_keys[] = { + #if MICROPY_PY_SYS_PATH + // Code should access this (as an mp_obj_t) for use with e.g. + // mp_obj_list_append by using the `mp_sys_path` macro defined in runtime.h. + MP_QSTR_path, + #endif #if MICROPY_PY_SYS_PS1_PS2 MP_QSTR_ps1, MP_QSTR_ps2, @@ -231,8 +239,9 @@ void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys) }, - { MP_ROM_QSTR(MP_QSTR_path), MP_ROM_PTR(&MP_STATE_VM(mp_sys_path_obj)) }, + #if MICROPY_PY_SYS_ARGV { MP_ROM_QSTR(MP_QSTR_argv), MP_ROM_PTR(&MP_STATE_VM(mp_sys_argv_obj)) }, + #endif { MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&mp_sys_version_obj) }, { MP_ROM_QSTR(MP_QSTR_version_info), MP_ROM_PTR(&mp_sys_version_info_obj) }, { MP_ROM_QSTR(MP_QSTR_implementation), MP_ROM_PTR(&mp_sys_implementation_obj) }, @@ -308,10 +317,11 @@ const mp_obj_module_t mp_module_sys = { // available. MP_REGISTER_MODULE(MP_QSTR_sys, mp_module_sys); -// If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is not enabled then these two lists -// must be initialised after the call to mp_init. -MP_REGISTER_ROOT_POINTER(mp_obj_list_t mp_sys_path_obj); +#if MICROPY_PY_SYS_ARGV +// Code should access this (as an mp_obj_t) for use with e.g. +// mp_obj_list_append by using the `mp_sys_argv` macro defined in runtime.h. MP_REGISTER_ROOT_POINTER(mp_obj_list_t mp_sys_argv_obj); +#endif #if MICROPY_PY_SYS_EXC_INFO // current exception being handled, for sys.exc_info() diff --git a/py/mpconfig.h b/py/mpconfig.h index b6f8838662..eb23c5965c 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1421,6 +1421,23 @@ typedef double mp_float_t; #define MICROPY_PY_SYS_ATEXIT (0) #endif +// Whether to provide the "sys.path" attribute (which forces module delegation +// and mutable sys attributes to be enabled). +// If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is enabled, this is initialised in +// mp_init to an empty list. Otherwise the port must initialise it using +// `mp_sys_path = mp_obj_new_list(...)`. +#ifndef MICROPY_PY_SYS_PATH +#define MICROPY_PY_SYS_PATH (1) +#endif + +// Whether to provide the "sys.argv" attribute. +// If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is enabled, this is initialised in +// mp_init to an empty list. Otherwise the port must initialise it using +// `mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), ...);` +#ifndef MICROPY_PY_SYS_ARGV +#define MICROPY_PY_SYS_ARGV (1) +#endif + // Whether to provide sys.{ps1,ps2} mutable attributes, to control REPL prompts #ifndef MICROPY_PY_SYS_PS1_PS2 #define MICROPY_PY_SYS_PS1_PS2 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) @@ -1455,7 +1472,7 @@ typedef double mp_float_t; // Whether the sys module supports attribute delegation // This is enabled automatically when needed by other features #ifndef MICROPY_PY_SYS_ATTR_DELEGATION -#define MICROPY_PY_SYS_ATTR_DELEGATION (MICROPY_PY_SYS_PS1_PS2 || MICROPY_PY_SYS_TRACEBACKLIMIT) +#define MICROPY_PY_SYS_ATTR_DELEGATION (MICROPY_PY_SYS_PATH || MICROPY_PY_SYS_PS1_PS2 || MICROPY_PY_SYS_TRACEBACKLIMIT) #endif // Whether to provide "errno" module diff --git a/py/mpstate.h b/py/mpstate.h index 3786131de6..080dc1380b 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -43,6 +43,9 @@ #if MICROPY_PY_SYS_ATTR_DELEGATION // Must be kept in sync with sys_mutable_keys in modsys.c. enum { + #if MICROPY_PY_SYS_PATH + MP_SYS_MUTABLE_PATH, + #endif #if MICROPY_PY_SYS_PS1_PS2 MP_SYS_MUTABLE_PS1, MP_SYS_MUTABLE_PS2, diff --git a/py/runtime.c b/py/runtime.c index 2326dfb3ca..f5d219728f 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -136,13 +136,17 @@ void mp_init(void) { #endif #if MICROPY_PY_SYS_PATH_ARGV_DEFAULTS - mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0); + #if MICROPY_PY_SYS_PATH + mp_sys_path = mp_obj_new_list(0, NULL); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script) #if MICROPY_MODULE_FROZEN mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen)); #endif + #endif + #if MICROPY_PY_SYS_ARGV mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0); #endif + #endif // MICROPY_PY_SYS_PATH_ARGV_DEFAULTS #if MICROPY_PY_SYS_ATEXIT MP_STATE_VM(sys_exitfunc) = mp_const_none; diff --git a/py/runtime.h b/py/runtime.h index 78194973d6..c033c77b40 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -227,8 +227,13 @@ int mp_native_type_from_qstr(qstr qst); mp_uint_t mp_native_from_obj(mp_obj_t obj, mp_uint_t type); mp_obj_t mp_native_to_obj(mp_uint_t val, mp_uint_t type); -#define mp_sys_path (MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_sys_path_obj))) +#if MICROPY_PY_SYS_PATH +#define mp_sys_path (MP_STATE_VM(sys_mutable[MP_SYS_MUTABLE_PATH])) +#endif + +#if MICROPY_PY_SYS_ARGV #define mp_sys_argv (MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_sys_argv_obj))) +#endif #if MICROPY_WARNINGS #ifndef mp_warning diff --git a/shared/upytesthelper/upytesthelper.c b/shared/upytesthelper/upytesthelper.c index 12fa8276b0..ba20037f7a 100644 --- a/shared/upytesthelper/upytesthelper.c +++ b/shared/upytesthelper/upytesthelper.c @@ -31,6 +31,14 @@ #include "py/compile.h" #include "upytesthelper.h" +#if !MICROPY_PY_SYS_PATH +#error "upytesthelper requires MICROPY_PY_SYS_PATH=1" +#endif + +#if !MICROPY_PY_SYS_ARGV +#error "upytesthelper requires MICROPY_PY_SYS_ARGV=1" +#endif + static const char *test_exp_output; static int test_exp_output_len, test_rem_output_len; static int test_failed; @@ -93,7 +101,7 @@ void upytest_execute_test(const char *src) { // reinitialized before running each. gc_init(heap_start, heap_end); mp_init(); - mp_obj_list_init(mp_sys_path, 0); + mp_sys_path = mp_obj_new_list(0, NULL); #if MICROPY_MODULE_FROZEN mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen)); #endif From 4216bc7d1351feb8199e4ebbff1a9598aa1c5b02 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 18 Aug 2022 16:57:45 +1000 Subject: [PATCH 177/565] tests: Replace umodule with module everywhere. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/unix/coverage.c | 14 +-- tests/basics/array1.py | 9 +- tests/basics/array_add.py | 9 +- tests/basics/array_construct.py | 9 +- tests/basics/array_construct2.py | 9 +- tests/basics/array_construct_endian.py | 9 +- tests/basics/array_intbig.py | 9 +- tests/basics/array_micropython.py | 9 +- tests/basics/async_await2.py | 5 +- tests/basics/async_for2.py | 5 +- tests/basics/async_with2.py | 5 +- tests/basics/attrtuple1.py | 5 +- tests/basics/builtin_callable.py | 5 +- tests/basics/builtin_dir.py | 5 +- tests/basics/bytearray_construct_array.py | 9 +- tests/basics/bytearray_construct_endian.py | 9 +- tests/basics/bytes_add_array.py | 9 +- tests/basics/bytes_add_endian.py | 9 +- tests/basics/bytes_compare_array.py | 9 +- tests/basics/bytes_construct_array.py | 9 +- tests/basics/bytes_construct_endian.py | 9 +- tests/basics/class_ordereddict.py | 9 +- tests/basics/class_store_class.py | 7 +- tests/basics/deque1.py | 5 +- tests/basics/deque2.py | 5 +- tests/basics/dict_fixed.py | 22 ++-- tests/basics/errno1.py | 14 +-- tests/basics/errno1.py.exp | 2 +- tests/basics/int_big1.py | 5 +- tests/basics/io_buffered_writer.py | 2 +- tests/basics/io_bytesio_cow.py | 6 +- tests/basics/io_bytesio_ext.py | 6 +- tests/basics/io_bytesio_ext2.py | 6 +- tests/basics/io_iobase.py | 6 +- tests/basics/io_stringio1.py | 6 +- tests/basics/io_stringio_base.py | 5 +- tests/basics/io_stringio_with.py | 6 +- tests/basics/io_write_ext.py | 6 +- tests/basics/memoryview1.py | 9 +- tests/basics/memoryview2.py | 9 +- tests/basics/memoryview_intbig.py | 9 +- tests/basics/memoryview_itemsize.py | 9 +- tests/basics/memoryview_slice_assign.py | 9 +- tests/basics/module2.py | 4 +- tests/basics/namedtuple1.py | 5 +- tests/basics/namedtuple_asdict.py | 5 +- tests/basics/ordereddict1.py | 7 +- tests/basics/ordereddict_eq.py | 7 +- tests/basics/python34.py | 6 +- tests/basics/string_compare.py | 5 +- tests/basics/struct1.py | 11 +- tests/basics/struct1_intbig.py | 11 +- tests/basics/struct2.py | 13 +-- tests/basics/struct_endian.py | 13 +-- tests/basics/struct_micropython.py | 11 +- tests/basics/subclass_native_call.py | 5 +- tests/basics/subclass_native_exc_new.py | 1 - tests/basics/sys1.py | 6 +- tests/basics/sys_exit.py | 6 +- tests/basics/sys_getsizeof.py | 7 +- tests/basics/sys_path.py | 6 +- tests/basics/sys_tracebacklimit.py | 8 +- tests/basics/sys_tracebacklimit.py.exp | 30 ++--- tests/cmdline/repl_micropyinspect | 4 +- tests/cmdline/repl_sys_ps1_ps2.py | 6 +- tests/cmdline/repl_sys_ps1_ps2.py.exp | 6 +- tests/esp32/partition_ota.py | 12 +- tests/esp32/resolve_on_connect.py | 5 +- ...i_a2b_base64.py => binascii_a2b_base64.py} | 5 +- ...i_b2a_base64.py => binascii_b2a_base64.py} | 5 +- .../{ubinascii_crc32.py => binascii_crc32.py} | 5 +- ...inascii_hexlify.py => binascii_hexlify.py} | 5 +- ...cii_unhexlify.py => binascii_unhexlify.py} | 5 +- tests/extmod/btree1.py | 8 +- tests/extmod/btree_error.py | 14 ++- tests/extmod/btree_gc.py | 4 +- ..._aes128_cbc.py => cryptolib_aes128_cbc.py} | 2 +- ...cbc.py.exp => cryptolib_aes128_cbc.py.exp} | 0 ..._aes128_ctr.py => cryptolib_aes128_ctr.py} | 2 +- ...ctr.py.exp => cryptolib_aes128_ctr.py.exp} | 0 ..._aes128_ecb.py => cryptolib_aes128_ecb.py} | 2 +- ...ecb.py.exp => cryptolib_aes128_ecb.py.exp} | 0 ...ecb_enc.py => cryptolib_aes128_ecb_enc.py} | 2 +- ...py.exp => cryptolib_aes128_ecb_enc.py.exp} | 0 ...b_inpl.py => cryptolib_aes128_ecb_inpl.py} | 2 +- ...y.exp => cryptolib_aes128_ecb_inpl.py.exp} | 0 ...b_into.py => cryptolib_aes128_ecb_into.py} | 2 +- ...y.exp => cryptolib_aes128_ecb_into.py.exp} | 0 ..._aes256_cbc.py => cryptolib_aes256_cbc.py} | 2 +- ...cbc.py.exp => cryptolib_aes256_cbc.py.exp} | 0 ..._aes256_ecb.py => cryptolib_aes256_ecb.py} | 2 +- ...ecb.py.exp => cryptolib_aes256_ecb.py.exp} | 0 tests/extmod/framebuf16.py | 4 +- tests/extmod/framebuf_palette.py | 2 +- tests/extmod/framebuf_subclass.py | 4 +- .../{uhashlib_final.py => hashlib_final.py} | 4 +- ...hlib_final.py.exp => hashlib_final.py.exp} | 0 tests/extmod/hashlib_md5.py | 18 +++ tests/extmod/hashlib_sha1.py | 18 +++ .../{uhashlib_sha256.py => hashlib_sha256.py} | 13 +-- tests/extmod/{uheapq1.py => heapq1.py} | 11 +- tests/extmod/{ujson_dump.py => json_dump.py} | 14 +-- ...son_dump_iobase.py => json_dump_iobase.py} | 12 +- ..._separators.py => json_dump_separators.py} | 14 +-- .../extmod/{ujson_dumps.py => json_dumps.py} | 9 +- tests/extmod/json_dumps_extra.py | 9 ++ ...s_extra.py.exp => json_dumps_extra.py.exp} | 0 tests/extmod/json_dumps_float.py | 8 ++ tests/extmod/json_dumps_ordereddict.py | 8 ++ ...separators.py => json_dumps_separators.py} | 9 +- tests/extmod/json_load.py | 11 ++ .../extmod/{ujson_loads.py => json_loads.py} | 9 +- ...son_loads_bytes.py => json_loads_bytes.py} | 9 +- ...s_bytes.py.exp => json_loads_bytes.py.exp} | 0 ...son_loads_float.py => json_loads_float.py} | 9 +- tests/extmod/machine1.py | 6 +- tests/extmod/machine_pinbase.py | 6 +- tests/extmod/machine_pulse.py | 6 +- tests/extmod/machine_signal.py | 6 +- tests/extmod/machine_timer.py | 6 +- .../{urandom_basic.py => random_basic.py} | 9 +- ...andom_basic.py.exp => random_basic.py.exp} | 0 .../{urandom_extra.py => random_extra.py} | 9 +- ...m_extra_float.py => random_extra_float.py} | 9 +- ...seed_default.py => random_seed_default.py} | 11 +- tests/extmod/{ure1.py => re1.py} | 9 +- tests/extmod/{ure_debug.py => re_debug.py} | 6 +- .../{ure_debug.py.exp => re_debug.py.exp} | 0 tests/extmod/{ure_error.py => re_error.py} | 9 +- tests/extmod/{ure_group.py => re_group.py} | 9 +- tests/extmod/{ure_groups.py => re_groups.py} | 9 +- tests/extmod/{ure_limit.py => re_limit.py} | 4 +- .../{ure_limit.py.exp => re_limit.py.exp} | 0 .../{ure_namedclass.py => re_namedclass.py} | 9 +- tests/extmod/{ure_span.py => re_span.py} | 9 +- tests/extmod/{ure_split.py => re_split.py} | 9 +- .../{ure_split_empty.py => re_split_empty.py} | 2 +- ...lit_empty.py.exp => re_split_empty.py.exp} | 0 ...e_split_notimpl.py => re_split_notimpl.py} | 2 +- ...notimpl.py.exp => re_split_notimpl.py.exp} | 0 tests/extmod/re_stack_overflow.py | 10 ++ ...erflow.py.exp => re_stack_overflow.py.exp} | 0 tests/extmod/{ure_sub.py => re_sub.py} | 9 +- ...e_sub_unmatched.py => re_sub_unmatched.py} | 9 +- ...matched.py.exp => re_sub_unmatched.py.exp} | 0 ...ect_poll_basic.py => select_poll_basic.py} | 13 +-- ...uselect_poll_udp.py => select_poll_udp.py} | 13 +-- ...ocket_tcp_basic.py => socket_tcp_basic.py} | 9 +- ...udp_nonblock.py => socket_udp_nonblock.py} | 9 +- tests/extmod/{ussl_basic.py => ssl_basic.py} | 4 +- .../{ussl_basic.py.exp => ssl_basic.py.exp} | 0 .../{ussl_keycert.py => ssl_keycert.py} | 6 +- ...ussl_keycert.py.exp => ssl_keycert.py.exp} | 0 tests/extmod/{ussl_poll.py => ssl_poll.py} | 14 +-- .../{ussl_poll.py.exp => ssl_poll.py.exp} | 0 tests/extmod/ticks_add.py | 2 +- tests/extmod/ticks_diff.py | 2 +- tests/extmod/time_ms_us.py | 26 ++--- tests/extmod/{utime_res.py => time_res.py} | 16 +-- .../{utime_res.py.exp => time_res.py.exp} | 0 .../{utime_time_ns.py => time_time_ns.py} | 14 +-- ...ime_time_ns.py.exp => time_time_ns.py.exp} | 0 tests/extmod/{utimeq1.py => timeq1.py} | 18 +-- .../extmod/{utimeq1.py.exp => timeq1.py.exp} | 0 .../{utimeq_stable.py => timeq_stable.py} | 4 +- ...imeq_stable.py.exp => timeq_stable.py.exp} | 0 tests/extmod/uasyncio_basic.py | 13 +-- tests/extmod/uasyncio_micropython.py | 8 +- tests/extmod/uasyncio_threadsafeflag.py | 2 +- tests/extmod/uasyncio_wait_task.py | 12 +- .../extmod/uctypes_array_assign_native_le.py | 4 +- .../uctypes_array_assign_native_le_intbig.py | 4 +- tests/extmod/uctypes_native_le.py | 4 +- tests/extmod/uctypes_ptr_le.py | 4 +- tests/extmod/uctypes_ptr_native_le.py | 4 +- tests/extmod/uctypes_sizeof_od.py | 2 +- tests/extmod/uhashlib_md5.py | 21 ---- tests/extmod/uhashlib_sha1.py | 21 ---- tests/extmod/ujson_dumps_extra.py | 9 -- tests/extmod/ujson_dumps_float.py | 11 -- tests/extmod/ujson_dumps_ordereddict.py | 12 -- tests/extmod/ujson_load.py | 15 --- tests/extmod/ure_stack_overflow.py | 13 --- tests/extmod/vfs_basic.py | 104 +++++++++--------- tests/extmod/vfs_blockdev.py | 12 +- tests/extmod/vfs_fat_fileio1.py | 24 ++-- tests/extmod/vfs_fat_fileio2.py | 26 ++--- tests/extmod/vfs_fat_finaliser.py | 12 +- tests/extmod/vfs_fat_ilistdir_del.py | 6 +- tests/extmod/vfs_fat_more.py | 92 ++++++++-------- tests/extmod/vfs_fat_mtime.py | 14 +-- tests/extmod/vfs_fat_oldproto.py | 12 +- tests/extmod/vfs_fat_ramdisk.py | 22 ++-- tests/extmod/vfs_fat_ramdisklarge.py | 12 +- tests/extmod/vfs_lfs.py | 10 +- tests/extmod/vfs_lfs_corrupt.py | 10 +- tests/extmod/vfs_lfs_error.py | 10 +- tests/extmod/vfs_lfs_file.py | 10 +- tests/extmod/vfs_lfs_ilistdir_del.py | 6 +- tests/extmod/vfs_lfs_mount.py | 42 +++---- tests/extmod/vfs_lfs_mtime.py | 16 +-- tests/extmod/vfs_lfs_superblock.py | 12 +- tests/extmod/vfs_posix.py | 48 ++++---- tests/extmod/vfs_userfs.py | 22 ++-- tests/extmod/websocket_basic.py | 22 ++-- .../{uzlib_decompio.py => zlib_decompio.py} | 4 +- ...b_decompio.py.exp => zlib_decompio.py.exp} | 0 ...lib_decompio_gz.py => zlib_decompio_gz.py} | 4 +- ...mpio_gz.py.exp => zlib_decompio_gz.py.exp} | 0 ...uzlib_decompress.py => zlib_decompress.py} | 7 +- tests/feature_check/byteorder.py | 5 +- .../{uio_module.py => io_module.py} | 4 +- .../{uio_module.py.exp => io_module.py.exp} | 0 tests/float/array_construct.py | 9 +- tests/float/bytearray_construct_endian.py | 9 +- tests/float/bytes_construct_endian.py | 9 +- tests/float/float2int_doubleprec_intbig.py | 8 +- tests/float/float2int_fp30_intbig.py | 8 +- tests/float/float2int_intbig.py | 8 +- tests/float/float_array.py | 9 +- tests/float/float_struct.py | 5 +- tests/import/builtin_ext.py | 4 + tests/import/builtin_ext.py.exp | 4 +- tests/import/ext/time.py | 6 +- tests/inlineasm/asmfpldrstr.py | 2 +- tests/inlineasm/asmsum.py | 2 +- tests/internal_bench/var-8-namedtuple-1st.py | 2 +- .../internal_bench/var-8.1-namedtuple-5th.py | 2 +- tests/io/argv.py | 5 +- tests/io/builtin_print_file.py | 5 +- tests/io/file_stdio.py | 5 +- tests/io/open_append.py | 5 +- tests/io/open_plus.py | 5 +- tests/micropython/builtin_execfile.py | 22 ++-- tests/micropython/emg_exc.py | 8 +- tests/micropython/heapalloc_bytesio.py | 4 +- tests/micropython/heapalloc_bytesio2.py | 4 +- tests/micropython/heapalloc_iter.py | 9 +- tests/micropython/heapalloc_traceback.py | 8 +- tests/micropython/import_mpy_invalid.py | 16 +-- tests/micropython/import_mpy_native.py | 20 ++-- tests/micropython/import_mpy_native_gc.py | 12 +- tests/micropython/opt_level_lineno.py | 2 +- tests/micropython/viper_misc_intbig.py | 4 +- tests/misc/non_compliant.py | 8 +- tests/misc/print_exception.py | 8 +- tests/misc/sys_atexit.py | 6 +- tests/misc/sys_exc_info.py | 5 +- tests/multi_net/ssl_cert_rsa.py | 2 +- tests/multi_net/ssl_data.py | 2 +- tests/multi_net/uasyncio_tcp_readinto.py | 9 +- tests/net_hosted/accept_nonblock.py | 5 +- tests/net_hosted/accept_timeout.py | 5 +- tests/net_hosted/connect_nonblock.py | 6 +- tests/net_hosted/connect_nonblock_xfer.py | 7 +- tests/net_hosted/connect_poll.py | 5 +- tests/net_hosted/ssl_getpeercert.py | 8 +- tests/net_inet/getaddrinfo.py | 5 +- tests/net_inet/ssl_cert.py | 6 +- tests/net_inet/ssl_errors.py | 7 +- tests/net_inet/test_tls_nonblock.py | 5 +- tests/net_inet/test_tls_sites.py | 17 +-- tests/net_inet/tls_num_errors.py | 6 +- tests/net_inet/tls_text_errors.py | 5 +- tests/perf_bench/benchrun.py | 6 +- tests/perf_bench/bm_hexiom.py | 5 +- tests/perf_bench/core_import_mpy_multi.py | 12 +- tests/perf_bench/core_import_mpy_single.py | 10 +- tests/renesas-ra/freq.py | 2 +- tests/run-natmodtests.py | 18 +-- tests/run-tests-exp.py | 4 +- tests/run-tests.py | 32 +++--- tests/stress/recursive_data.py | 2 +- tests/thread/stress_aes.py | 5 +- tests/thread/stress_create.py | 11 +- tests/thread/stress_heap.py | 5 +- tests/thread/stress_schedule.py | 8 +- tests/thread/thread_exc2.py | 4 +- tests/thread/thread_exit1.py | 5 +- tests/thread/thread_exit2.py | 5 +- tests/thread/thread_lock2.py | 5 +- tests/thread/thread_lock4.py | 5 +- tests/thread/thread_qstr1.py | 5 +- tests/thread/thread_sleep1.py | 10 +- tests/thread/thread_stacksize1.py | 6 +- tests/thread/thread_start1.py | 5 +- tests/thread/thread_start2.py | 5 +- tests/unicode/unicode_ure.py | 9 +- tests/unix/extra_coverage.py | 10 +- tests/unix/extra_coverage.py.exp | 24 ++-- tests/unix/ffi_types.py | 6 +- .../{time.py => time_mktime_localtime.py} | 5 +- tests/wipy/wlan/machine.py.exp | 2 +- tools/ci.sh | 4 +- tools/tinytest-codegen.py | 6 +- 295 files changed, 1006 insertions(+), 1428 deletions(-) rename tests/extmod/{ubinascii_a2b_base64.py => binascii_a2b_base64.py} (92%) rename tests/extmod/{ubinascii_b2a_base64.py => binascii_b2a_base64.py} (88%) rename tests/extmod/{ubinascii_crc32.py => binascii_crc32.py} (87%) rename tests/extmod/{ubinascii_hexlify.py => binascii_hexlify.py} (80%) rename tests/extmod/{ubinascii_unhexlify.py => binascii_unhexlify.py} (81%) rename tests/extmod/{ucryptolib_aes128_cbc.py => cryptolib_aes128_cbc.py} (90%) rename tests/extmod/{ucryptolib_aes128_cbc.py.exp => cryptolib_aes128_cbc.py.exp} (100%) rename tests/extmod/{ucryptolib_aes128_ctr.py => cryptolib_aes128_ctr.py} (94%) rename tests/extmod/{ucryptolib_aes128_ctr.py.exp => cryptolib_aes128_ctr.py.exp} (100%) rename tests/extmod/{ucryptolib_aes128_ecb.py => cryptolib_aes128_ecb.py} (89%) rename tests/extmod/{ucryptolib_aes128_ecb.py.exp => cryptolib_aes128_ecb.py.exp} (100%) rename tests/extmod/{ucryptolib_aes128_ecb_enc.py => cryptolib_aes128_ecb_enc.py} (91%) rename tests/extmod/{ucryptolib_aes128_ecb_enc.py.exp => cryptolib_aes128_ecb_enc.py.exp} (100%) rename tests/extmod/{ucryptolib_aes128_ecb_inpl.py => cryptolib_aes128_ecb_inpl.py} (90%) rename tests/extmod/{ucryptolib_aes128_ecb_inpl.py.exp => cryptolib_aes128_ecb_inpl.py.exp} (100%) rename tests/extmod/{ucryptolib_aes128_ecb_into.py => cryptolib_aes128_ecb_into.py} (90%) rename tests/extmod/{ucryptolib_aes128_ecb_into.py.exp => cryptolib_aes128_ecb_into.py.exp} (100%) rename tests/extmod/{ucryptolib_aes256_cbc.py => cryptolib_aes256_cbc.py} (90%) rename tests/extmod/{ucryptolib_aes256_cbc.py.exp => cryptolib_aes256_cbc.py.exp} (100%) rename tests/extmod/{ucryptolib_aes256_ecb.py => cryptolib_aes256_ecb.py} (89%) rename tests/extmod/{ucryptolib_aes256_ecb.py.exp => cryptolib_aes256_ecb.py.exp} (100%) rename tests/extmod/{uhashlib_final.py => hashlib_final.py} (92%) rename tests/extmod/{uhashlib_final.py.exp => hashlib_final.py.exp} (100%) create mode 100644 tests/extmod/hashlib_md5.py create mode 100644 tests/extmod/hashlib_sha1.py rename tests/extmod/{uhashlib_sha256.py => hashlib_sha256.py} (72%) rename tests/extmod/{uheapq1.py => heapq1.py} (78%) rename tests/extmod/{ujson_dump.py => json_dump.py} (69%) rename tests/extmod/{ujson_dump_iobase.py => json_dump_iobase.py} (71%) rename tests/extmod/{ujson_dump_separators.py => json_dump_separators.py} (86%) rename tests/extmod/{ujson_dumps.py => json_dumps.py} (83%) create mode 100644 tests/extmod/json_dumps_extra.py rename tests/extmod/{ujson_dumps_extra.py.exp => json_dumps_extra.py.exp} (100%) create mode 100644 tests/extmod/json_dumps_float.py create mode 100644 tests/extmod/json_dumps_ordereddict.py rename tests/extmod/{ujson_dumps_separators.py => json_dumps_separators.py} (93%) create mode 100644 tests/extmod/json_load.py rename tests/extmod/{ujson_loads.py => json_loads.py} (92%) rename tests/extmod/{ujson_loads_bytes.py => json_loads_bytes.py} (56%) rename tests/extmod/{ujson_loads_bytes.py.exp => json_loads_bytes.py.exp} (100%) rename tests/extmod/{ujson_loads_float.py => json_loads_float.py} (65%) rename tests/extmod/{urandom_basic.py => random_basic.py} (81%) rename tests/extmod/{urandom_basic.py.exp => random_basic.py.exp} (100%) rename tests/extmod/{urandom_extra.py => random_extra.py} (89%) rename tests/extmod/{urandom_extra_float.py => random_extra_float.py} (72%) rename tests/extmod/{urandom_seed_default.py => random_seed_default.py} (69%) rename tests/extmod/{ure1.py => re1.py} (95%) rename tests/extmod/{ure_debug.py => re_debug.py} (65%) rename tests/extmod/{ure_debug.py.exp => re_debug.py.exp} (100%) rename tests/extmod/{ure_error.py => re_error.py} (73%) rename tests/extmod/{ure_group.py => re_group.py} (81%) rename tests/extmod/{ure_groups.py => re_groups.py} (81%) rename tests/extmod/{ure_limit.py => re_limit.py} (88%) rename tests/extmod/{ure_limit.py.exp => re_limit.py.exp} (100%) rename tests/extmod/{ure_namedclass.py => re_namedclass.py} (85%) rename tests/extmod/{ure_span.py => re_span.py} (85%) rename tests/extmod/{ure_split.py => re_split.py} (82%) rename tests/extmod/{ure_split_empty.py => re_split_empty.py} (95%) rename tests/extmod/{ure_split_empty.py.exp => re_split_empty.py.exp} (100%) rename tests/extmod/{ure_split_notimpl.py => re_split_notimpl.py} (89%) rename tests/extmod/{ure_split_notimpl.py.exp => re_split_notimpl.py.exp} (100%) create mode 100644 tests/extmod/re_stack_overflow.py rename tests/extmod/{ure_stack_overflow.py.exp => re_stack_overflow.py.exp} (100%) rename tests/extmod/{ure_sub.py => re_sub.py} (93%) rename tests/extmod/{ure_sub_unmatched.py => re_sub_unmatched.py} (71%) rename tests/extmod/{ure_sub_unmatched.py.exp => re_sub_unmatched.py.exp} (100%) rename tests/extmod/{uselect_poll_basic.py => select_poll_basic.py} (69%) rename tests/extmod/{uselect_poll_udp.py => select_poll_udp.py} (66%) rename tests/extmod/{usocket_tcp_basic.py => socket_tcp_basic.py} (60%) rename tests/extmod/{usocket_udp_nonblock.py => socket_udp_nonblock.py} (63%) rename tests/extmod/{ussl_basic.py => ssl_basic.py} (96%) rename tests/extmod/{ussl_basic.py.exp => ssl_basic.py.exp} (100%) rename tests/extmod/{ussl_keycert.py => ssl_keycert.py} (94%) rename tests/extmod/{ussl_keycert.py.exp => ssl_keycert.py.exp} (100%) rename tests/extmod/{ussl_poll.py => ssl_poll.py} (94%) rename tests/extmod/{ussl_poll.py.exp => ssl_poll.py.exp} (100%) rename tests/extmod/{utime_res.py => time_res.py} (80%) rename tests/extmod/{utime_res.py.exp => time_res.py.exp} (100%) rename tests/extmod/{utime_time_ns.py => time_time_ns.py} (68%) rename tests/extmod/{utime_time_ns.py.exp => time_time_ns.py.exp} (100%) rename tests/extmod/{utimeq1.py => timeq1.py} (90%) rename tests/extmod/{utimeq1.py.exp => timeq1.py.exp} (100%) rename tests/extmod/{utimeq_stable.py => timeq_stable.py} (90%) rename tests/extmod/{utimeq_stable.py.exp => timeq_stable.py.exp} (100%) delete mode 100644 tests/extmod/uhashlib_md5.py delete mode 100644 tests/extmod/uhashlib_sha1.py delete mode 100644 tests/extmod/ujson_dumps_extra.py delete mode 100644 tests/extmod/ujson_dumps_float.py delete mode 100644 tests/extmod/ujson_dumps_ordereddict.py delete mode 100644 tests/extmod/ujson_load.py delete mode 100644 tests/extmod/ure_stack_overflow.py rename tests/extmod/{uzlib_decompio.py => zlib_decompio.py} (93%) rename tests/extmod/{uzlib_decompio.py.exp => zlib_decompio.py.exp} (100%) rename tests/extmod/{uzlib_decompio_gz.py => zlib_decompio_gz.py} (97%) rename tests/extmod/{uzlib_decompio_gz.py.exp => zlib_decompio_gz.py.exp} (100%) rename tests/extmod/{uzlib_decompress.py => zlib_decompress.py} (94%) rename tests/feature_check/{uio_module.py => io_module.py} (56%) rename tests/feature_check/{uio_module.py.exp => io_module.py.exp} (100%) rename tests/unix/{time.py => time_mktime_localtime.py} (96%) diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index ab06c0fb39..6022ff2bff 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -356,19 +356,19 @@ STATIC mp_obj_t extra_coverage(void) { mp_printf(&mp_plat_print, "# repl\n"); const char *str; - size_t len = mp_repl_autocomplete("__n", 3, &mp_plat_print, &str); + size_t len = mp_repl_autocomplete("__n", 3, &mp_plat_print, &str); // expect "ame__" mp_printf(&mp_plat_print, "%.*s\n", (int)len, str); - len = mp_repl_autocomplete("i", 1, &mp_plat_print, &str); + len = mp_repl_autocomplete("im", 2, &mp_plat_print, &str); // expect "port" mp_printf(&mp_plat_print, "%.*s\n", (int)len, str); - mp_repl_autocomplete("import ", 7, &mp_plat_print, &str); - len = mp_repl_autocomplete("import ut", 9, &mp_plat_print, &str); + mp_repl_autocomplete("import ", 7, &mp_plat_print, &str); // expect the list of builtins + len = mp_repl_autocomplete("import ti", 9, &mp_plat_print, &str); // expect "me" mp_printf(&mp_plat_print, "%.*s\n", (int)len, str); - mp_repl_autocomplete("import time", 12, &mp_plat_print, &str); + mp_repl_autocomplete("import time", 11, &mp_plat_print, &str); // expect "time timeq" mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0))); - mp_repl_autocomplete("sys.", 4, &mp_plat_print, &str); - len = mp_repl_autocomplete("sys.impl", 8, &mp_plat_print, &str); + mp_repl_autocomplete("sys.", 4, &mp_plat_print, &str); // expect dir(sys) + len = mp_repl_autocomplete("sys.impl", 8, &mp_plat_print, &str); // expect "ementation" mp_printf(&mp_plat_print, "%.*s\n", (int)len, str); } diff --git a/tests/basics/array1.py b/tests/basics/array1.py index f21ad4bd75..5c5d13a581 100644 --- a/tests/basics/array1.py +++ b/tests/basics/array1.py @@ -1,11 +1,8 @@ try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit a = array.array('B', [1, 2, 3]) print(a, len(a)) diff --git a/tests/basics/array_add.py b/tests/basics/array_add.py index 8335eb6b82..76ce59f761 100644 --- a/tests/basics/array_add.py +++ b/tests/basics/array_add.py @@ -1,12 +1,9 @@ # test array + array try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit a1 = array.array('I', [1]) a2 = array.array('I', [2]) diff --git a/tests/basics/array_construct.py b/tests/basics/array_construct.py index 4985244d13..2221de9906 100644 --- a/tests/basics/array_construct.py +++ b/tests/basics/array_construct.py @@ -1,13 +1,10 @@ # test construction of array.array from different objects try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # tuple, list print(array('b', (1, 2))) diff --git a/tests/basics/array_construct2.py b/tests/basics/array_construct2.py index d1b1e9d158..c305b7f011 100644 --- a/tests/basics/array_construct2.py +++ b/tests/basics/array_construct2.py @@ -1,11 +1,8 @@ try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # construct from something with unknown length (requires generators) print(array('i', (i for i in range(10)))) diff --git a/tests/basics/array_construct_endian.py b/tests/basics/array_construct_endian.py index 82a962fbe0..990d7b1ea0 100644 --- a/tests/basics/array_construct_endian.py +++ b/tests/basics/array_construct_endian.py @@ -1,13 +1,10 @@ # test construction of array.array from different objects try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # raw copy from bytes, bytearray print(array('h', b'12')) diff --git a/tests/basics/array_intbig.py b/tests/basics/array_intbig.py index ba7f9ef985..5702a8ae63 100644 --- a/tests/basics/array_intbig.py +++ b/tests/basics/array_intbig.py @@ -1,13 +1,10 @@ # test array types QqLl that require big-ints try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(array('L', [0, 2**32-1])) print(array('l', [-2**31, 0, 2**31-1])) diff --git a/tests/basics/array_micropython.py b/tests/basics/array_micropython.py index 44dc1d83d8..771a7d709c 100644 --- a/tests/basics/array_micropython.py +++ b/tests/basics/array_micropython.py @@ -1,12 +1,9 @@ # test MicroPython-specific features of array.array try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # arrays of objects a = array.array('O') diff --git a/tests/basics/async_await2.py b/tests/basics/async_await2.py index 56f77604ac..1e3164df93 100644 --- a/tests/basics/async_await2.py +++ b/tests/basics/async_await2.py @@ -1,9 +1,6 @@ # test await expression -try: - import usys as sys -except ImportError: - import sys +import sys if sys.implementation.name == 'micropython': # uPy allows normal generators to be awaitables coroutine = lambda f: f diff --git a/tests/basics/async_for2.py b/tests/basics/async_for2.py index 4af3be4c6d..aad23a3e5a 100644 --- a/tests/basics/async_for2.py +++ b/tests/basics/async_for2.py @@ -1,9 +1,6 @@ # test waiting within "async for" __anext__ function -try: - import usys as sys -except ImportError: - import sys +import sys if sys.implementation.name == 'micropython': # uPy allows normal generators to be awaitables coroutine = lambda f: f diff --git a/tests/basics/async_with2.py b/tests/basics/async_with2.py index 4dd1386240..44421ae917 100644 --- a/tests/basics/async_with2.py +++ b/tests/basics/async_with2.py @@ -1,9 +1,6 @@ # test waiting within async with enter/exit functions -try: - import usys as sys -except ImportError: - import sys +import sys if sys.implementation.name == 'micropython': # uPy allows normal generators to be awaitables coroutine = lambda f: f diff --git a/tests/basics/attrtuple1.py b/tests/basics/attrtuple1.py index 249c030bb4..78a0fbed1b 100644 --- a/tests/basics/attrtuple1.py +++ b/tests/basics/attrtuple1.py @@ -1,10 +1,7 @@ # test attrtuple # we can't test this type directly so we use sys.implementation object -try: - import usys as sys -except ImportError: - import sys +import sys t = sys.implementation # It can be just a normal tuple on small ports diff --git a/tests/basics/builtin_callable.py b/tests/basics/builtin_callable.py index c0a9d0c473..3ae49f004d 100644 --- a/tests/basics/builtin_callable.py +++ b/tests/basics/builtin_callable.py @@ -7,10 +7,7 @@ print(callable([])) print(callable("dfsd")) # modules should not be callabe -try: - import usys as sys -except ImportError: - import sys +import sys print(callable(sys)) # builtins should be callable diff --git a/tests/basics/builtin_dir.py b/tests/basics/builtin_dir.py index 1f2b498d77..1eecbd044b 100644 --- a/tests/basics/builtin_dir.py +++ b/tests/basics/builtin_dir.py @@ -4,10 +4,7 @@ print('__name__' in dir()) # dir of module -try: - import usys as sys -except ImportError: - import sys +import sys print('version' in dir(sys)) # dir of type diff --git a/tests/basics/bytearray_construct_array.py b/tests/basics/bytearray_construct_array.py index 52eaa7c6ef..bde5fa08bd 100644 --- a/tests/basics/bytearray_construct_array.py +++ b/tests/basics/bytearray_construct_array.py @@ -1,12 +1,9 @@ # test construction of bytearray from different objects try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # arrays print(bytearray(array('b', [1, 2]))) diff --git a/tests/basics/bytearray_construct_endian.py b/tests/basics/bytearray_construct_endian.py index 332b43e686..0002f19c5f 100644 --- a/tests/basics/bytearray_construct_endian.py +++ b/tests/basics/bytearray_construct_endian.py @@ -1,12 +1,9 @@ # test construction of bytearray from different objects try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # arrays print(bytearray(array('h', [1, 2]))) diff --git a/tests/basics/bytes_add_array.py b/tests/basics/bytes_add_array.py index c6382bed74..b17556d83c 100644 --- a/tests/basics/bytes_add_array.py +++ b/tests/basics/bytes_add_array.py @@ -1,12 +1,9 @@ # test bytes + other try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # should be byteorder-neutral print(b"123" + array.array('h', [0x1515])) diff --git a/tests/basics/bytes_add_endian.py b/tests/basics/bytes_add_endian.py index 40b3de7d61..8cfffa7b6a 100644 --- a/tests/basics/bytes_add_endian.py +++ b/tests/basics/bytes_add_endian.py @@ -1,11 +1,8 @@ # test bytes + other try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(b"123" + array.array('i', [1])) diff --git a/tests/basics/bytes_compare_array.py b/tests/basics/bytes_compare_array.py index 6bad50b55a..ad378de70c 100644 --- a/tests/basics/bytes_compare_array.py +++ b/tests/basics/bytes_compare_array.py @@ -1,11 +1,8 @@ try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(array.array('b', [1, 2]) in b'\x01\x02\x03') # CPython gives False here diff --git a/tests/basics/bytes_construct_array.py b/tests/basics/bytes_construct_array.py index 7bdd8f10df..453eb59010 100644 --- a/tests/basics/bytes_construct_array.py +++ b/tests/basics/bytes_construct_array.py @@ -1,12 +1,9 @@ # test construction of bytes from different objects try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # arrays print(bytes(array('b', [1, 2]))) diff --git a/tests/basics/bytes_construct_endian.py b/tests/basics/bytes_construct_endian.py index 294c5f23f5..cf1a9f408f 100644 --- a/tests/basics/bytes_construct_endian.py +++ b/tests/basics/bytes_construct_endian.py @@ -1,13 +1,10 @@ # test construction of bytes from different objects try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # arrays print(bytes(array('h', [1, 2]))) diff --git a/tests/basics/class_ordereddict.py b/tests/basics/class_ordereddict.py index 4dd25eb6e1..03a211ddad 100644 --- a/tests/basics/class_ordereddict.py +++ b/tests/basics/class_ordereddict.py @@ -1,13 +1,10 @@ # test using an OrderedDict as the locals to construct a class try: - from ucollections import OrderedDict + from collections import OrderedDict except ImportError: - try: - from collections import OrderedDict - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit if not hasattr(int, "__dict__"): print("SKIP") diff --git a/tests/basics/class_store_class.py b/tests/basics/class_store_class.py index 797f88f852..8ee2f8db11 100644 --- a/tests/basics/class_store_class.py +++ b/tests/basics/class_store_class.py @@ -5,11 +5,8 @@ try: from collections import namedtuple except ImportError: - try: - from ucollections import namedtuple - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit _DefragResultBase = namedtuple('DefragResult', [ 'foo', 'bar' ]) diff --git a/tests/basics/deque1.py b/tests/basics/deque1.py index 19966fcb07..8b7874e2b1 100644 --- a/tests/basics/deque1.py +++ b/tests/basics/deque1.py @@ -1,8 +1,5 @@ try: - try: - from ucollections import deque - except ImportError: - from collections import deque + from collections import deque except ImportError: print("SKIP") raise SystemExit diff --git a/tests/basics/deque2.py b/tests/basics/deque2.py index 22d370e943..80fcd66785 100644 --- a/tests/basics/deque2.py +++ b/tests/basics/deque2.py @@ -1,10 +1,7 @@ # Tests for deques with "check overflow" flag and other extensions # wrt to CPython. try: - try: - from ucollections import deque - except ImportError: - from collections import deque + from collections import deque except ImportError: print("SKIP") raise SystemExit diff --git a/tests/basics/dict_fixed.py b/tests/basics/dict_fixed.py index 4261a06557..cfd3b71f57 100644 --- a/tests/basics/dict_fixed.py +++ b/tests/basics/dict_fixed.py @@ -1,48 +1,48 @@ # test that fixed dictionaries cannot be modified try: - import uerrno + import errno except ImportError: print("SKIP") raise SystemExit -# Save a copy of uerrno.errorcode, so we can check later +# Save a copy of errno.errorcode, so we can check later # that it hasn't been modified. -errorcode_copy = uerrno.errorcode.copy() +errorcode_copy = errno.errorcode.copy() try: - uerrno.errorcode.popitem() + errno.errorcode.popitem() except TypeError: print("TypeError") try: - uerrno.errorcode.pop(0) + errno.errorcode.pop(0) except TypeError: print("TypeError") try: - uerrno.errorcode.setdefault(0, 0) + errno.errorcode.setdefault(0, 0) except TypeError: print("TypeError") try: - uerrno.errorcode.update([(1, 2)]) + errno.errorcode.update([(1, 2)]) except TypeError: print("TypeError") try: - del uerrno.errorcode[1] + del errno.errorcode[1] except TypeError: print("TypeError") try: - uerrno.errorcode[1] = 'foo' + errno.errorcode[1] = 'foo' except TypeError: print("TypeError") try: - uerrno.errorcode.clear() + errno.errorcode.clear() except TypeError: print("TypeError") -assert uerrno.errorcode == errorcode_copy +assert errno.errorcode == errorcode_copy diff --git a/tests/basics/errno1.py b/tests/basics/errno1.py index d9a895a972..0773c926fd 100644 --- a/tests/basics/errno1.py +++ b/tests/basics/errno1.py @@ -1,25 +1,25 @@ -# test errno's and uerrno module +# test errno's and errno module try: - import uerrno + import errno except ImportError: print("SKIP") raise SystemExit # check that constants exist and are integers -print(type(uerrno.EIO)) +print(type(errno.EIO)) # check that errors are rendered in a nice way -msg = str(OSError(uerrno.EIO)) +msg = str(OSError(errno.EIO)) print(msg[:7], msg[-5:]) -msg = str(OSError(uerrno.EIO, "details")) +msg = str(OSError(errno.EIO, "details")) print(msg[:7], msg[-14:]) -msg = str(OSError(uerrno.EIO, "details", "more details")) +msg = str(OSError(errno.EIO, "details", "more details")) print(msg[:1], msg[-28:]) # check that unknown errno is still rendered print(str(OSError(9999))) # this tests a failed constant lookup in errno -errno = uerrno +errno = errno print(errno.__name__) diff --git a/tests/basics/errno1.py.exp b/tests/basics/errno1.py.exp index 58605b4767..7a9ffea8f7 100644 --- a/tests/basics/errno1.py.exp +++ b/tests/basics/errno1.py.exp @@ -3,4 +3,4 @@ [Errno ] EIO: details ( , 'details', 'more details') 9999 -uerrno +errno diff --git a/tests/basics/int_big1.py b/tests/basics/int_big1.py index ea48372b28..de2ba9fc4f 100644 --- a/tests/basics/int_big1.py +++ b/tests/basics/int_big1.py @@ -105,10 +105,7 @@ x = 4611686018427387904 # big x = -4611686018427387904 # big # sys.maxsize is a constant mpz, so test it's compatible with dynamic ones -try: - import usys as sys -except ImportError: - import sys +import sys print(sys.maxsize + 1 - 1 == sys.maxsize) # test extraction of big int value via mp_obj_get_int_maybe diff --git a/tests/basics/io_buffered_writer.py b/tests/basics/io_buffered_writer.py index 0e943cb0a9..5c065f158a 100644 --- a/tests/basics/io_buffered_writer.py +++ b/tests/basics/io_buffered_writer.py @@ -1,4 +1,4 @@ -import uio as io +import io try: io.BytesIO diff --git a/tests/basics/io_bytesio_cow.py b/tests/basics/io_bytesio_cow.py index 92654a0003..2edb7136a9 100644 --- a/tests/basics/io_bytesio_cow.py +++ b/tests/basics/io_bytesio_cow.py @@ -1,10 +1,6 @@ # Make sure that write operations on io.BytesIO don't # change original object it was constructed from. -try: - import uio as io -except ImportError: - import io - +import io b = b"foobar" a = io.BytesIO(b) diff --git a/tests/basics/io_bytesio_ext.py b/tests/basics/io_bytesio_ext.py index e454b2fd9f..4d4c60c136 100644 --- a/tests/basics/io_bytesio_ext.py +++ b/tests/basics/io_bytesio_ext.py @@ -1,9 +1,5 @@ # Extended stream operations on io.BytesIO -try: - import uio as io -except ImportError: - import io - +import io a = io.BytesIO(b"foobar") a.seek(10) print(a.read(10)) diff --git a/tests/basics/io_bytesio_ext2.py b/tests/basics/io_bytesio_ext2.py index 8f624fd58c..414ac90a3b 100644 --- a/tests/basics/io_bytesio_ext2.py +++ b/tests/basics/io_bytesio_ext2.py @@ -1,8 +1,4 @@ -try: - import uio as io -except ImportError: - import io - +import io a = io.BytesIO(b"foobar") try: a.seek(-10) diff --git a/tests/basics/io_iobase.py b/tests/basics/io_iobase.py index 6f554b00f0..d3824c177f 100644 --- a/tests/basics/io_iobase.py +++ b/tests/basics/io_iobase.py @@ -1,8 +1,4 @@ -try: - import uio as io -except: - import io - +import io try: io.IOBase except AttributeError: diff --git a/tests/basics/io_stringio1.py b/tests/basics/io_stringio1.py index 41089f22d5..7d355930f5 100644 --- a/tests/basics/io_stringio1.py +++ b/tests/basics/io_stringio1.py @@ -1,8 +1,4 @@ -try: - import uio as io -except ImportError: - import io - +import io a = io.StringIO() print('io.StringIO' in repr(a)) print(a.getvalue()) diff --git a/tests/basics/io_stringio_base.py b/tests/basics/io_stringio_base.py index dffc879074..0f65fb3fab 100644 --- a/tests/basics/io_stringio_base.py +++ b/tests/basics/io_stringio_base.py @@ -1,10 +1,7 @@ # Checks that an instance type inheriting from a native base that uses # MP_TYPE_FLAG_ITER_IS_STREAM will still have a getiter. -try: - import uio as io -except ImportError: - import io +import io a = io.StringIO() a.write("hello\nworld\nmicro\npython\n") diff --git a/tests/basics/io_stringio_with.py b/tests/basics/io_stringio_with.py index c35975445d..a3aa6ec84e 100644 --- a/tests/basics/io_stringio_with.py +++ b/tests/basics/io_stringio_with.py @@ -1,8 +1,4 @@ -try: - import uio as io -except ImportError: - import io - +import io # test __enter__/__exit__ with io.StringIO() as b: b.write("foo") diff --git a/tests/basics/io_write_ext.py b/tests/basics/io_write_ext.py index 5a6eaa35cf..695abccef4 100644 --- a/tests/basics/io_write_ext.py +++ b/tests/basics/io_write_ext.py @@ -1,14 +1,14 @@ # This tests extended (MicroPython-specific) form of write: # write(buf, len) and write(buf, offset, len) -import uio +import io try: - uio.BytesIO + io.BytesIO except AttributeError: print('SKIP') raise SystemExit -buf = uio.BytesIO() +buf = io.BytesIO() buf.write(b"foo", 2) print(buf.getvalue()) diff --git a/tests/basics/memoryview1.py b/tests/basics/memoryview1.py index 4c20c91f49..1ebfbc53b9 100644 --- a/tests/basics/memoryview1.py +++ b/tests/basics/memoryview1.py @@ -5,13 +5,10 @@ except: print("SKIP") raise SystemExit try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # test reading from bytes b = b'1234' diff --git a/tests/basics/memoryview2.py b/tests/basics/memoryview2.py index eacc227c28..fa5514e072 100644 --- a/tests/basics/memoryview2.py +++ b/tests/basics/memoryview2.py @@ -5,13 +5,10 @@ except: print("SKIP") raise SystemExit try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(list(memoryview(b'\x7f\x80\x81\xff'))) print(list(memoryview(array('b', [0x7f, -0x80])))) diff --git a/tests/basics/memoryview_intbig.py b/tests/basics/memoryview_intbig.py index 4800a70cc2..72951d6eaa 100644 --- a/tests/basics/memoryview_intbig.py +++ b/tests/basics/memoryview_intbig.py @@ -5,13 +5,10 @@ except: print("SKIP") raise SystemExit try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(list(memoryview(array('i', [0x7f000000, -0x80000000])))) print(list(memoryview(array('I', [0x7f000000, 0x80000000, 0x81000000, 0xffffffff])))) diff --git a/tests/basics/memoryview_itemsize.py b/tests/basics/memoryview_itemsize.py index 64a8822b8b..5428a41785 100644 --- a/tests/basics/memoryview_itemsize.py +++ b/tests/basics/memoryview_itemsize.py @@ -4,13 +4,10 @@ except: print("SKIP") raise SystemExit try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit for code in ['b', 'h', 'i', 'q', 'f', 'd']: print(memoryview(array(code)).itemsize) diff --git a/tests/basics/memoryview_slice_assign.py b/tests/basics/memoryview_slice_assign.py index 74f6fae6f7..94f8073f0a 100644 --- a/tests/basics/memoryview_slice_assign.py +++ b/tests/basics/memoryview_slice_assign.py @@ -7,13 +7,10 @@ except (NameError, TypeError): raise SystemExit try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # test slice assignment between memoryviews b1 = bytearray(b'1234') diff --git a/tests/basics/module2.py b/tests/basics/module2.py index 5923a27e08..a135601579 100644 --- a/tests/basics/module2.py +++ b/tests/basics/module2.py @@ -1,6 +1,6 @@ # uPy behaviour only: builtin modules are read-only -import usys +import sys try: - usys.x = 1 + sys.x = 1 except AttributeError: print("AttributeError") diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index e8247e4d6e..362c60583e 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -1,8 +1,5 @@ try: - try: - from ucollections import namedtuple - except ImportError: - from collections import namedtuple + from collections import namedtuple except ImportError: print("SKIP") raise SystemExit diff --git a/tests/basics/namedtuple_asdict.py b/tests/basics/namedtuple_asdict.py index 34c4e6f713..e85281bb73 100644 --- a/tests/basics/namedtuple_asdict.py +++ b/tests/basics/namedtuple_asdict.py @@ -1,8 +1,5 @@ try: - try: - from ucollections import namedtuple - except ImportError: - from collections import namedtuple + from collections import namedtuple except ImportError: print("SKIP") raise SystemExit diff --git a/tests/basics/ordereddict1.py b/tests/basics/ordereddict1.py index 270deab384..a6f305ff78 100644 --- a/tests/basics/ordereddict1.py +++ b/tests/basics/ordereddict1.py @@ -1,11 +1,8 @@ try: from collections import OrderedDict except ImportError: - try: - from ucollections import OrderedDict - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit d = OrderedDict([(10, 20), ("b", 100), (1, 2)]) print(len(d)) diff --git a/tests/basics/ordereddict_eq.py b/tests/basics/ordereddict_eq.py index c69daf8802..e103c867e2 100644 --- a/tests/basics/ordereddict_eq.py +++ b/tests/basics/ordereddict_eq.py @@ -1,11 +1,8 @@ try: from collections import OrderedDict except ImportError: - try: - from ucollections import OrderedDict - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit x = OrderedDict() y = OrderedDict() diff --git a/tests/basics/python34.py b/tests/basics/python34.py index 36e25e20dd..922234d22d 100644 --- a/tests/basics/python34.py +++ b/tests/basics/python34.py @@ -29,9 +29,9 @@ test_syntax("del ()") # can't delete empty tuple (in 3.6 we can) # from basics/sys1.py # uPy prints version 3.4 -import usys -print(usys.version[:3]) -print(usys.version_info[0], usys.version_info[1]) +import sys +print(sys.version[:3]) +print(sys.version_info[0], sys.version_info[1]) # from basics/exception1.py # in 3.7 no comma is printed if there is only 1 arg (in 3.4-3.6 one is printed) diff --git a/tests/basics/string_compare.py b/tests/basics/string_compare.py index f34879df25..6515809b36 100644 --- a/tests/basics/string_compare.py +++ b/tests/basics/string_compare.py @@ -51,10 +51,7 @@ print("1/" <= "1") # this tests an internal string that doesn't have a hash with a string # that does have a hash, but the lengths of the two strings are different -try: - import usys as sys -except ImportError: - import sys +import sys print(sys.version == 'a long string that has a hash') # this special string would have a hash of 0 but is incremented to 1 diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index c4960d2f80..a18655517b 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -1,11 +1,8 @@ try: - import ustruct as struct -except: - try: - import struct - except ImportError: - print("SKIP") - raise SystemExit + import struct +except ImportError: + print("SKIP") + raise SystemExit print(struct.calcsize(" 0) # Only test deque if we have it try: - from ucollections import deque + from collections import deque assert sys.getsizeof(deque((), 1)) > 0 except ImportError: pass diff --git a/tests/basics/sys_path.py b/tests/basics/sys_path.py index 6456e24019..576bd66c94 100644 --- a/tests/basics/sys_path.py +++ b/tests/basics/sys_path.py @@ -1,10 +1,6 @@ # test sys.path -try: - import usys as sys -except ImportError: - import sys - +import sys # check that this script was executed from a file of the same name if "__file__" not in globals() or "sys_path.py" not in __file__: print("SKIP") diff --git a/tests/basics/sys_tracebacklimit.py b/tests/basics/sys_tracebacklimit.py index 1ee638967f..3ae372b8d5 100644 --- a/tests/basics/sys_tracebacklimit.py +++ b/tests/basics/sys_tracebacklimit.py @@ -1,12 +1,8 @@ # test sys.tracebacklimit try: - try: - import usys as sys - import uio as io - except ImportError: - import sys - import io + import sys + import io except ImportError: print("SKIP") raise SystemExit diff --git a/tests/basics/sys_tracebacklimit.py.exp b/tests/basics/sys_tracebacklimit.py.exp index 3647280584..39c54523a0 100644 --- a/tests/basics/sys_tracebacklimit.py.exp +++ b/tests/basics/sys_tracebacklimit.py.exp @@ -1,35 +1,35 @@ Traceback (most recent call last): - File , line 62, in ftop - File , line 57, in f3 - File , line 53, in f2 - File , line 49, in f1 - File , line 45, in f0 + File , line 58, in ftop + File , line 53, in f3 + File , line 49, in f2 + File , line 45, in f1 + File , line 41, in f0 ValueError: value limit 4 Traceback (most recent call last): - File , line 62, in ftop - File , line 57, in f3 - File , line 53, in f2 - File , line 49, in f1 + File , line 58, in ftop + File , line 53, in f3 + File , line 49, in f2 + File , line 45, in f1 ValueError: value limit 3 Traceback (most recent call last): - File , line 62, in ftop - File , line 57, in f3 - File , line 53, in f2 + File , line 58, in ftop + File , line 53, in f3 + File , line 49, in f2 ValueError: value limit 2 Traceback (most recent call last): - File , line 62, in ftop - File , line 57, in f3 + File , line 58, in ftop + File , line 53, in f3 ValueError: value limit 1 Traceback (most recent call last): - File , line 62, in ftop + File , line 58, in ftop ValueError: value limit 0 diff --git a/tests/cmdline/repl_micropyinspect b/tests/cmdline/repl_micropyinspect index 0710f1a75b..8dfa8810ea 100644 --- a/tests/cmdline/repl_micropyinspect +++ b/tests/cmdline/repl_micropyinspect @@ -1,3 +1,3 @@ -import uos +import os -uos.putenv('MICROPYINSPECT', '1') +os.putenv('MICROPYINSPECT', '1') diff --git a/tests/cmdline/repl_sys_ps1_ps2.py b/tests/cmdline/repl_sys_ps1_ps2.py index 4f96057c49..cfefe804bf 100644 --- a/tests/cmdline/repl_sys_ps1_ps2.py +++ b/tests/cmdline/repl_sys_ps1_ps2.py @@ -1,6 +1,6 @@ # test changing ps1/ps2 -import usys -usys.ps1 = "PS1" -usys.ps2 = "PS2" +import sys +sys.ps1 = "PS1" +sys.ps2 = "PS2" (1 + 2) diff --git a/tests/cmdline/repl_sys_ps1_ps2.py.exp b/tests/cmdline/repl_sys_ps1_ps2.py.exp index e4a802d34d..9e82db5e31 100644 --- a/tests/cmdline/repl_sys_ps1_ps2.py.exp +++ b/tests/cmdline/repl_sys_ps1_ps2.py.exp @@ -1,9 +1,9 @@ MicroPython \.\+ version Use \.\+ >>> # test changing ps1/ps2 ->>> import usys ->>> usys.ps1 = "PS1" -PS1usys.ps2 = "PS2" +>>> import sys +>>> sys.ps1 = "PS1" +PS1sys.ps2 = "PS2" PS1(1 + PS22) 3 diff --git a/tests/esp32/partition_ota.py b/tests/esp32/partition_ota.py index 212fcf0338..65e2742ebb 100644 --- a/tests/esp32/partition_ota.py +++ b/tests/esp32/partition_ota.py @@ -22,10 +22,10 @@ def log(*args): # replace boot.py with the test code that will run on each reboot -import uos +import os try: - uos.rename("boot.py", "boot-orig.py") + os.rename("boot.py", "boot-orig.py") except: pass with open("boot.py", "w") as f: @@ -74,10 +74,10 @@ elif STEP == 3: elif STEP == 4: log("Confirming boot ok and DONE!") Partition.mark_app_valid_cancel_rollback() - import uos - uos.remove("step.py") - uos.remove("boot.py") - uos.rename("boot-orig.py", "boot.py") + import os + os.remove("step.py") + os.remove("boot.py") + os.rename("boot-orig.py", "boot.py") print("\\nSUCCESS!\\n\\x04\\x04") """ diff --git a/tests/esp32/resolve_on_connect.py b/tests/esp32/resolve_on_connect.py index 068757ab2a..e604ce9ca0 100644 --- a/tests/esp32/resolve_on_connect.py +++ b/tests/esp32/resolve_on_connect.py @@ -5,10 +5,7 @@ if sys.implementation.name == "micropython" and sys.platform != "esp32": print("SKIP") raise SystemExit -try: - import usocket as socket, sys -except: - import socket, sys +import socket, sys def test_bind_resolves_0_0_0_0(): diff --git a/tests/extmod/ubinascii_a2b_base64.py b/tests/extmod/binascii_a2b_base64.py similarity index 92% rename from tests/extmod/ubinascii_a2b_base64.py rename to tests/extmod/binascii_a2b_base64.py index 2630965e6a..fd1ff75e1f 100644 --- a/tests/extmod/ubinascii_a2b_base64.py +++ b/tests/extmod/binascii_a2b_base64.py @@ -1,8 +1,5 @@ try: - try: - import ubinascii as binascii - except ImportError: - import binascii + import binascii except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ubinascii_b2a_base64.py b/tests/extmod/binascii_b2a_base64.py similarity index 88% rename from tests/extmod/ubinascii_b2a_base64.py rename to tests/extmod/binascii_b2a_base64.py index 3f92488969..306af94004 100644 --- a/tests/extmod/ubinascii_b2a_base64.py +++ b/tests/extmod/binascii_b2a_base64.py @@ -1,8 +1,5 @@ try: - try: - import ubinascii as binascii - except ImportError: - import binascii + import binascii except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ubinascii_crc32.py b/tests/extmod/binascii_crc32.py similarity index 87% rename from tests/extmod/ubinascii_crc32.py rename to tests/extmod/binascii_crc32.py index 8f5f4d9ba5..0e4a5b58f3 100644 --- a/tests/extmod/ubinascii_crc32.py +++ b/tests/extmod/binascii_crc32.py @@ -1,8 +1,5 @@ try: - try: - import ubinascii as binascii - except ImportError: - import binascii + import binascii except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ubinascii_hexlify.py b/tests/extmod/binascii_hexlify.py similarity index 80% rename from tests/extmod/ubinascii_hexlify.py rename to tests/extmod/binascii_hexlify.py index 3c266fb6cc..d06029aaba 100644 --- a/tests/extmod/ubinascii_hexlify.py +++ b/tests/extmod/binascii_hexlify.py @@ -1,8 +1,5 @@ try: - try: - import ubinascii as binascii - except ImportError: - import binascii + import binascii except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ubinascii_unhexlify.py b/tests/extmod/binascii_unhexlify.py similarity index 81% rename from tests/extmod/ubinascii_unhexlify.py rename to tests/extmod/binascii_unhexlify.py index 2c3598ab98..bb663bc5b0 100644 --- a/tests/extmod/ubinascii_unhexlify.py +++ b/tests/extmod/binascii_unhexlify.py @@ -1,8 +1,5 @@ try: - try: - import ubinascii as binascii - except ImportError: - import binascii + import binascii except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py index 876bce4f87..d142a370f4 100644 --- a/tests/extmod/btree1.py +++ b/tests/extmod/btree1.py @@ -1,13 +1,13 @@ try: import btree - import uio - import uerrno + import io + import errno except ImportError: print("SKIP") raise SystemExit # f = open("_test.db", "w+b") -f = uio.BytesIO() +f = io.BytesIO() db = btree.open(f, pagesize=512) mv = memoryview(b"bar1foo1") @@ -68,7 +68,7 @@ print(db.seq(1, b"qux")) try: db.seq(b"foo1") except OSError as e: - print(e.errno == uerrno.EINVAL) + print(e.errno == errno.EINVAL) print(list(db.keys())) print(list(db.values())) diff --git a/tests/extmod/btree_error.py b/tests/extmod/btree_error.py index b64769e884..2dd0d137a0 100644 --- a/tests/extmod/btree_error.py +++ b/tests/extmod/btree_error.py @@ -1,15 +1,15 @@ # Test that errno's propagate correctly through btree module. try: - import btree, uio, uerrno + import btree, io, errno - uio.IOBase + io.IOBase except (ImportError, AttributeError): print("SKIP") raise SystemExit -class Device(uio.IOBase): +class Device(io.IOBase): def __init__(self, read_ret=0, ioctl_ret=0): self.read_ret = read_ret self.ioctl_ret = ioctl_ret @@ -25,18 +25,24 @@ class Device(uio.IOBase): # Invalid pagesize; errno comes from btree library try: + import btree, io, errno + db = btree.open(Device(), pagesize=511) except OSError as er: - print("OSError", er.errno == uerrno.EINVAL) + print("OSError", er.errno == errno.EINVAL) # Valid pagesize, device returns error on read; errno comes from Device.readinto try: + import btree, io, errno + db = btree.open(Device(-1000), pagesize=512) except OSError as er: print(repr(er)) # Valid pagesize, device returns error on seek; errno comes from Device.ioctl try: + import btree, io, errno + db = btree.open(Device(0, -1001), pagesize=512) except OSError as er: print(repr(er)) diff --git a/tests/extmod/btree_gc.py b/tests/extmod/btree_gc.py index 1845aa0640..c5274eb489 100644 --- a/tests/extmod/btree_gc.py +++ b/tests/extmod/btree_gc.py @@ -1,7 +1,7 @@ # Test btree interaction with the garbage collector. try: - import btree, uio, gc + import btree, io, gc except ImportError: print("SKIP") raise SystemExit @@ -9,7 +9,7 @@ except ImportError: N = 80 # Create a BytesIO but don't keep a reference to it. -db = btree.open(uio.BytesIO(), pagesize=512) +db = btree.open(io.BytesIO(), pagesize=512) # Overwrite lots of the Python stack to make sure no reference to the BytesIO remains. x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] diff --git a/tests/extmod/ucryptolib_aes128_cbc.py b/tests/extmod/cryptolib_aes128_cbc.py similarity index 90% rename from tests/extmod/ucryptolib_aes128_cbc.py rename to tests/extmod/cryptolib_aes128_cbc.py index d861d2c6bf..ef6d453685 100644 --- a/tests/extmod/ucryptolib_aes128_cbc.py +++ b/tests/extmod/cryptolib_aes128_cbc.py @@ -4,7 +4,7 @@ try: aes = AES.new except ImportError: try: - from ucryptolib import aes + from cryptolib import aes except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ucryptolib_aes128_cbc.py.exp b/tests/extmod/cryptolib_aes128_cbc.py.exp similarity index 100% rename from tests/extmod/ucryptolib_aes128_cbc.py.exp rename to tests/extmod/cryptolib_aes128_cbc.py.exp diff --git a/tests/extmod/ucryptolib_aes128_ctr.py b/tests/extmod/cryptolib_aes128_ctr.py similarity index 94% rename from tests/extmod/ucryptolib_aes128_ctr.py rename to tests/extmod/cryptolib_aes128_ctr.py index 538d9606e9..b5066fb7b4 100644 --- a/tests/extmod/ucryptolib_aes128_ctr.py +++ b/tests/extmod/cryptolib_aes128_ctr.py @@ -1,5 +1,5 @@ try: - from ucryptolib import aes + from cryptolib import aes except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ucryptolib_aes128_ctr.py.exp b/tests/extmod/cryptolib_aes128_ctr.py.exp similarity index 100% rename from tests/extmod/ucryptolib_aes128_ctr.py.exp rename to tests/extmod/cryptolib_aes128_ctr.py.exp diff --git a/tests/extmod/ucryptolib_aes128_ecb.py b/tests/extmod/cryptolib_aes128_ecb.py similarity index 89% rename from tests/extmod/ucryptolib_aes128_ecb.py rename to tests/extmod/cryptolib_aes128_ecb.py index 5c0e179986..d1e77d326d 100644 --- a/tests/extmod/ucryptolib_aes128_ecb.py +++ b/tests/extmod/cryptolib_aes128_ecb.py @@ -4,7 +4,7 @@ try: aes = AES.new except ImportError: try: - from ucryptolib import aes + from cryptolib import aes except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ucryptolib_aes128_ecb.py.exp b/tests/extmod/cryptolib_aes128_ecb.py.exp similarity index 100% rename from tests/extmod/ucryptolib_aes128_ecb.py.exp rename to tests/extmod/cryptolib_aes128_ecb.py.exp diff --git a/tests/extmod/ucryptolib_aes128_ecb_enc.py b/tests/extmod/cryptolib_aes128_ecb_enc.py similarity index 91% rename from tests/extmod/ucryptolib_aes128_ecb_enc.py rename to tests/extmod/cryptolib_aes128_ecb_enc.py index 1d4484b0bc..1bc973e22d 100644 --- a/tests/extmod/ucryptolib_aes128_ecb_enc.py +++ b/tests/extmod/cryptolib_aes128_ecb_enc.py @@ -7,7 +7,7 @@ try: aes = AES.new except ImportError: try: - from ucryptolib import aes + from cryptolib import aes except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ucryptolib_aes128_ecb_enc.py.exp b/tests/extmod/cryptolib_aes128_ecb_enc.py.exp similarity index 100% rename from tests/extmod/ucryptolib_aes128_ecb_enc.py.exp rename to tests/extmod/cryptolib_aes128_ecb_enc.py.exp diff --git a/tests/extmod/ucryptolib_aes128_ecb_inpl.py b/tests/extmod/cryptolib_aes128_ecb_inpl.py similarity index 90% rename from tests/extmod/ucryptolib_aes128_ecb_inpl.py rename to tests/extmod/cryptolib_aes128_ecb_inpl.py index 88ccb02daf..826f95ced8 100644 --- a/tests/extmod/ucryptolib_aes128_ecb_inpl.py +++ b/tests/extmod/cryptolib_aes128_ecb_inpl.py @@ -1,6 +1,6 @@ # Inplace operations (input and output buffer is the same) try: - from ucryptolib import aes + from cryptolib import aes except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ucryptolib_aes128_ecb_inpl.py.exp b/tests/extmod/cryptolib_aes128_ecb_inpl.py.exp similarity index 100% rename from tests/extmod/ucryptolib_aes128_ecb_inpl.py.exp rename to tests/extmod/cryptolib_aes128_ecb_inpl.py.exp diff --git a/tests/extmod/ucryptolib_aes128_ecb_into.py b/tests/extmod/cryptolib_aes128_ecb_into.py similarity index 90% rename from tests/extmod/ucryptolib_aes128_ecb_into.py rename to tests/extmod/cryptolib_aes128_ecb_into.py index ff832d7ef3..f90dfcf272 100644 --- a/tests/extmod/ucryptolib_aes128_ecb_into.py +++ b/tests/extmod/cryptolib_aes128_ecb_into.py @@ -1,6 +1,6 @@ # Operations with pre-allocated output buffer try: - from ucryptolib import aes + from cryptolib import aes except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ucryptolib_aes128_ecb_into.py.exp b/tests/extmod/cryptolib_aes128_ecb_into.py.exp similarity index 100% rename from tests/extmod/ucryptolib_aes128_ecb_into.py.exp rename to tests/extmod/cryptolib_aes128_ecb_into.py.exp diff --git a/tests/extmod/ucryptolib_aes256_cbc.py b/tests/extmod/cryptolib_aes256_cbc.py similarity index 90% rename from tests/extmod/ucryptolib_aes256_cbc.py rename to tests/extmod/cryptolib_aes256_cbc.py index c01846f199..91a9cd7609 100644 --- a/tests/extmod/ucryptolib_aes256_cbc.py +++ b/tests/extmod/cryptolib_aes256_cbc.py @@ -4,7 +4,7 @@ try: aes = AES.new except ImportError: try: - from ucryptolib import aes + from cryptolib import aes except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ucryptolib_aes256_cbc.py.exp b/tests/extmod/cryptolib_aes256_cbc.py.exp similarity index 100% rename from tests/extmod/ucryptolib_aes256_cbc.py.exp rename to tests/extmod/cryptolib_aes256_cbc.py.exp diff --git a/tests/extmod/ucryptolib_aes256_ecb.py b/tests/extmod/cryptolib_aes256_ecb.py similarity index 89% rename from tests/extmod/ucryptolib_aes256_ecb.py rename to tests/extmod/cryptolib_aes256_ecb.py index 0760063c14..ed040bc15b 100644 --- a/tests/extmod/ucryptolib_aes256_ecb.py +++ b/tests/extmod/cryptolib_aes256_ecb.py @@ -4,7 +4,7 @@ try: aes = AES.new except ImportError: try: - from ucryptolib import aes + from cryptolib import aes except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ucryptolib_aes256_ecb.py.exp b/tests/extmod/cryptolib_aes256_ecb.py.exp similarity index 100% rename from tests/extmod/ucryptolib_aes256_ecb.py.exp rename to tests/extmod/cryptolib_aes256_ecb.py.exp diff --git a/tests/extmod/framebuf16.py b/tests/extmod/framebuf16.py index cd7f5ec015..9f373c331e 100644 --- a/tests/extmod/framebuf16.py +++ b/tests/extmod/framebuf16.py @@ -1,11 +1,11 @@ try: - import framebuf, usys + import framebuf, sys except ImportError: print("SKIP") raise SystemExit # This test and its .exp file is based on a little-endian architecture. -if usys.byteorder != "little": +if sys.byteorder != "little": print("SKIP") raise SystemExit diff --git a/tests/extmod/framebuf_palette.py b/tests/extmod/framebuf_palette.py index f5b15fda73..ad1af2cf4c 100644 --- a/tests/extmod/framebuf_palette.py +++ b/tests/extmod/framebuf_palette.py @@ -1,6 +1,6 @@ # Test blit between different color spaces try: - import framebuf, usys + import framebuf, sys except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/framebuf_subclass.py b/tests/extmod/framebuf_subclass.py index 4cd9ea4eb5..162839e8bf 100644 --- a/tests/extmod/framebuf_subclass.py +++ b/tests/extmod/framebuf_subclass.py @@ -1,13 +1,13 @@ # test subclassing framebuf.FrameBuffer try: - import framebuf, usys + import framebuf, sys except ImportError: print("SKIP") raise SystemExit # This test and its .exp file is based on a little-endian architecture. -if usys.byteorder != "little": +if sys.byteorder != "little": print("SKIP") raise SystemExit diff --git a/tests/extmod/uhashlib_final.py b/tests/extmod/hashlib_final.py similarity index 92% rename from tests/extmod/uhashlib_final.py rename to tests/extmod/hashlib_final.py index f562cc1780..c8fdac9234 100644 --- a/tests/extmod/uhashlib_final.py +++ b/tests/extmod/hashlib_final.py @@ -1,12 +1,12 @@ try: - import uhashlib + import hashlib except ImportError: print("SKIP") raise SystemExit for algo_name in ("md5", "sha1", "sha256"): - algo = getattr(uhashlib, algo_name, None) + algo = getattr(hashlib, algo_name, None) if not algo: continue diff --git a/tests/extmod/uhashlib_final.py.exp b/tests/extmod/hashlib_final.py.exp similarity index 100% rename from tests/extmod/uhashlib_final.py.exp rename to tests/extmod/hashlib_final.py.exp diff --git a/tests/extmod/hashlib_md5.py b/tests/extmod/hashlib_md5.py new file mode 100644 index 0000000000..5f925fc97d --- /dev/null +++ b/tests/extmod/hashlib_md5.py @@ -0,0 +1,18 @@ +try: + import hashlib +except ImportError: + # This is neither uPy, nor cPy, so must be uPy with + # hashlib module disabled. + print("SKIP") + raise SystemExit + +try: + hashlib.md5 +except AttributeError: + # MD5 is only available on some ports + print("SKIP") + raise SystemExit + +md5 = hashlib.md5(b"hello") +md5.update(b"world") +print(md5.digest()) diff --git a/tests/extmod/hashlib_sha1.py b/tests/extmod/hashlib_sha1.py new file mode 100644 index 0000000000..af23033a59 --- /dev/null +++ b/tests/extmod/hashlib_sha1.py @@ -0,0 +1,18 @@ +try: + import hashlib +except ImportError: + # This is neither uPy, nor cPy, so must be uPy with + # hashlib module disabled. + print("SKIP") + raise SystemExit + +try: + hashlib.sha1 +except AttributeError: + # SHA1 is only available on some ports + print("SKIP") + raise SystemExit + +sha1 = hashlib.sha1(b"hello") +sha1.update(b"world") +print(sha1.digest()) diff --git a/tests/extmod/uhashlib_sha256.py b/tests/extmod/hashlib_sha256.py similarity index 72% rename from tests/extmod/uhashlib_sha256.py rename to tests/extmod/hashlib_sha256.py index 2e6df7df13..f0d07e1482 100644 --- a/tests/extmod/uhashlib_sha256.py +++ b/tests/extmod/hashlib_sha256.py @@ -1,13 +1,10 @@ try: - import uhashlib as hashlib + import hashlib except ImportError: - try: - import hashlib - except ImportError: - # This is neither uPy, nor cPy, so must be uPy with - # uhashlib module disabled. - print("SKIP") - raise SystemExit + # This is neither uPy, nor cPy, so must be uPy with + # hashlib module disabled. + print("SKIP") + raise SystemExit h = hashlib.sha256() diff --git a/tests/extmod/uheapq1.py b/tests/extmod/heapq1.py similarity index 78% rename from tests/extmod/uheapq1.py rename to tests/extmod/heapq1.py index a470bb6f71..efe208dac3 100644 --- a/tests/extmod/uheapq1.py +++ b/tests/extmod/heapq1.py @@ -1,11 +1,8 @@ try: - import uheapq as heapq -except: - try: - import heapq - except ImportError: - print("SKIP") - raise SystemExit + import heapq +except ImportError: + print("SKIP") + raise SystemExit try: heapq.heappop([]) diff --git a/tests/extmod/ujson_dump.py b/tests/extmod/json_dump.py similarity index 69% rename from tests/extmod/ujson_dump.py rename to tests/extmod/json_dump.py index feda8a47dd..897d33cc81 100644 --- a/tests/extmod/ujson_dump.py +++ b/tests/extmod/json_dump.py @@ -1,13 +1,9 @@ try: - from uio import StringIO - import ujson as json -except: - try: - from io import StringIO - import json - except ImportError: - print("SKIP") - raise SystemExit + from io import StringIO + import json +except ImportError: + print("SKIP") + raise SystemExit s = StringIO() json.dump(False, s) diff --git a/tests/extmod/ujson_dump_iobase.py b/tests/extmod/json_dump_iobase.py similarity index 71% rename from tests/extmod/ujson_dump_iobase.py rename to tests/extmod/json_dump_iobase.py index 7ecf23afb6..94d317b879 100644 --- a/tests/extmod/ujson_dump_iobase.py +++ b/tests/extmod/json_dump_iobase.py @@ -1,14 +1,10 @@ -# test ujson.dump in combination with uio.IOBase +# test json.dump in combination with io.IOBase try: - import uio as io - import ujson as json + import io, json except ImportError: - try: - import io, json - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit if not hasattr(io, "IOBase"): print("SKIP") diff --git a/tests/extmod/ujson_dump_separators.py b/tests/extmod/json_dump_separators.py similarity index 86% rename from tests/extmod/ujson_dump_separators.py rename to tests/extmod/json_dump_separators.py index e19b99a26d..4f8e56dceb 100644 --- a/tests/extmod/ujson_dump_separators.py +++ b/tests/extmod/json_dump_separators.py @@ -1,13 +1,9 @@ try: - from uio import StringIO - import ujson as json -except: - try: - from io import StringIO - import json - except ImportError: - print("SKIP") - raise SystemExit + from io import StringIO + import json +except ImportError: + print("SKIP") + raise SystemExit for sep in [ None, diff --git a/tests/extmod/ujson_dumps.py b/tests/extmod/json_dumps.py similarity index 83% rename from tests/extmod/ujson_dumps.py rename to tests/extmod/json_dumps.py index 251b268755..16f144e44f 100644 --- a/tests/extmod/ujson_dumps.py +++ b/tests/extmod/json_dumps.py @@ -1,11 +1,8 @@ try: - import ujson as json + import json except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(json.dumps(False)) print(json.dumps(True)) diff --git a/tests/extmod/json_dumps_extra.py b/tests/extmod/json_dumps_extra.py new file mode 100644 index 0000000000..9074416a99 --- /dev/null +++ b/tests/extmod/json_dumps_extra.py @@ -0,0 +1,9 @@ +# test uPy json behaviour that's not valid in CPy + +try: + import json +except ImportError: + print("SKIP") + raise SystemExit + +print(json.dumps(b"1234")) diff --git a/tests/extmod/ujson_dumps_extra.py.exp b/tests/extmod/json_dumps_extra.py.exp similarity index 100% rename from tests/extmod/ujson_dumps_extra.py.exp rename to tests/extmod/json_dumps_extra.py.exp diff --git a/tests/extmod/json_dumps_float.py b/tests/extmod/json_dumps_float.py new file mode 100644 index 0000000000..25fbc5c512 --- /dev/null +++ b/tests/extmod/json_dumps_float.py @@ -0,0 +1,8 @@ +try: + import json +except ImportError: + print("SKIP") + raise SystemExit + +print(json.dumps(1.2)) +print(json.dumps({1.5: "hi"})) diff --git a/tests/extmod/json_dumps_ordereddict.py b/tests/extmod/json_dumps_ordereddict.py new file mode 100644 index 0000000000..e1fa2a659c --- /dev/null +++ b/tests/extmod/json_dumps_ordereddict.py @@ -0,0 +1,8 @@ +try: + import json + from collections import OrderedDict +except ImportError: + print("SKIP") + raise SystemExit + +print(json.dumps(OrderedDict(((1, 2), (3, 4))))) diff --git a/tests/extmod/ujson_dumps_separators.py b/tests/extmod/json_dumps_separators.py similarity index 93% rename from tests/extmod/ujson_dumps_separators.py rename to tests/extmod/json_dumps_separators.py index efb541fe8b..a3a9ec308f 100644 --- a/tests/extmod/ujson_dumps_separators.py +++ b/tests/extmod/json_dumps_separators.py @@ -1,11 +1,8 @@ try: - import ujson as json + import json except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit for sep in [ None, diff --git a/tests/extmod/json_load.py b/tests/extmod/json_load.py new file mode 100644 index 0000000000..b2c7733282 --- /dev/null +++ b/tests/extmod/json_load.py @@ -0,0 +1,11 @@ +try: + from io import StringIO + import json +except ImportError: + print("SKIP") + raise SystemExit + +print(json.load(StringIO("null"))) +print(json.load(StringIO('"abc\\u0064e"'))) +print(json.load(StringIO("[false, true, 1, -2]"))) +print(json.load(StringIO('{"a":true}'))) diff --git a/tests/extmod/ujson_loads.py b/tests/extmod/json_loads.py similarity index 92% rename from tests/extmod/ujson_loads.py rename to tests/extmod/json_loads.py index 2de9cdcbc1..f9073c121e 100644 --- a/tests/extmod/ujson_loads.py +++ b/tests/extmod/json_loads.py @@ -1,11 +1,8 @@ try: - import ujson as json + import json except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit def my_print(o): diff --git a/tests/extmod/ujson_loads_bytes.py b/tests/extmod/json_loads_bytes.py similarity index 56% rename from tests/extmod/ujson_loads_bytes.py rename to tests/extmod/json_loads_bytes.py index 3ee87bbcd5..45cd0a35c5 100644 --- a/tests/extmod/ujson_loads_bytes.py +++ b/tests/extmod/json_loads_bytes.py @@ -1,13 +1,10 @@ # test loading from bytes and bytearray (introduced in Python 3.6) try: - import ujson as json + import json except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(json.loads(b"[1,2]")) print(json.loads(bytearray(b"[null]"))) diff --git a/tests/extmod/ujson_loads_bytes.py.exp b/tests/extmod/json_loads_bytes.py.exp similarity index 100% rename from tests/extmod/ujson_loads_bytes.py.exp rename to tests/extmod/json_loads_bytes.py.exp diff --git a/tests/extmod/ujson_loads_float.py b/tests/extmod/json_loads_float.py similarity index 65% rename from tests/extmod/ujson_loads_float.py rename to tests/extmod/json_loads_float.py index 842718f37d..2a8402dc6a 100644 --- a/tests/extmod/ujson_loads_float.py +++ b/tests/extmod/json_loads_float.py @@ -1,11 +1,8 @@ try: - import ujson as json + import json except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit def my_print(o): diff --git a/tests/extmod/machine1.py b/tests/extmod/machine1.py index 0c7f8122f4..90e6d17174 100644 --- a/tests/extmod/machine1.py +++ b/tests/extmod/machine1.py @@ -1,10 +1,8 @@ # test machine module try: - try: - import umachine as machine - except ImportError: - import machine + import machine + machine.mem8 except: print("SKIP") diff --git a/tests/extmod/machine_pinbase.py b/tests/extmod/machine_pinbase.py index 8bddd4bb70..4c467c2d26 100644 --- a/tests/extmod/machine_pinbase.py +++ b/tests/extmod/machine_pinbase.py @@ -1,8 +1,6 @@ try: - try: - import umachine as machine - except ImportError: - import machine + import machine + machine.PinBase except: print("SKIP") diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py index 65d15fb351..c793134e19 100644 --- a/tests/extmod/machine_pulse.py +++ b/tests/extmod/machine_pulse.py @@ -1,8 +1,6 @@ try: - try: - import umachine as machine - except ImportError: - import machine + import machine + machine.PinBase machine.time_pulse_us except: diff --git a/tests/extmod/machine_signal.py b/tests/extmod/machine_signal.py index 1ffdb56436..2f6332748d 100644 --- a/tests/extmod/machine_signal.py +++ b/tests/extmod/machine_signal.py @@ -1,10 +1,8 @@ # test machine.Signal class try: - try: - import umachine as machine - except ImportError: - import machine + import machine + machine.PinBase machine.Signal except: diff --git a/tests/extmod/machine_timer.py b/tests/extmod/machine_timer.py index c9a47c4025..1be01d184d 100644 --- a/tests/extmod/machine_timer.py +++ b/tests/extmod/machine_timer.py @@ -1,7 +1,7 @@ # test machine.Timer try: - import utime, umachine as machine + import time, machine as machine machine.Timer except: @@ -29,10 +29,10 @@ t.deinit() # create one-shot timer with callback and wait for it to print (should be just once) t = machine.Timer(period=1, mode=machine.Timer.ONE_SHOT, callback=lambda t: print("one-shot")) -utime.sleep_ms(5) +time.sleep_ms(5) t.deinit() # create periodic timer with callback and wait for it to print t = machine.Timer(period=4, mode=machine.Timer.PERIODIC, callback=lambda t: print("periodic")) -utime.sleep_ms(14) +time.sleep_ms(14) t.deinit() diff --git a/tests/extmod/urandom_basic.py b/tests/extmod/random_basic.py similarity index 81% rename from tests/extmod/urandom_basic.py rename to tests/extmod/random_basic.py index f7f5a6d691..7cb992fede 100644 --- a/tests/extmod/urandom_basic.py +++ b/tests/extmod/random_basic.py @@ -1,11 +1,8 @@ try: - import urandom as random + import random except ImportError: - try: - import random - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # check getrandbits returns a value within the bit range for b in (1, 2, 3, 4, 16, 32): diff --git a/tests/extmod/urandom_basic.py.exp b/tests/extmod/random_basic.py.exp similarity index 100% rename from tests/extmod/urandom_basic.py.exp rename to tests/extmod/random_basic.py.exp diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/random_extra.py similarity index 89% rename from tests/extmod/urandom_extra.py rename to tests/extmod/random_extra.py index 78e17379dc..aa05053377 100644 --- a/tests/extmod/urandom_extra.py +++ b/tests/extmod/random_extra.py @@ -1,11 +1,8 @@ try: - import urandom as random + import random except ImportError: - try: - import random - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: random.randint diff --git a/tests/extmod/urandom_extra_float.py b/tests/extmod/random_extra_float.py similarity index 72% rename from tests/extmod/urandom_extra_float.py rename to tests/extmod/random_extra_float.py index 65918da136..3b37ed8dce 100644 --- a/tests/extmod/urandom_extra_float.py +++ b/tests/extmod/random_extra_float.py @@ -1,11 +1,8 @@ try: - import urandom as random + import random except ImportError: - try: - import random - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: random.randint diff --git a/tests/extmod/urandom_seed_default.py b/tests/extmod/random_seed_default.py similarity index 69% rename from tests/extmod/urandom_seed_default.py rename to tests/extmod/random_seed_default.py index a032b9362b..2fb16282ca 100644 --- a/tests/extmod/urandom_seed_default.py +++ b/tests/extmod/random_seed_default.py @@ -1,13 +1,10 @@ -# test urandom.seed() without any arguments +# test random.seed() without any arguments try: - import urandom as random + import random except ImportError: - try: - import random - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: random.seed() diff --git a/tests/extmod/ure1.py b/tests/extmod/re1.py similarity index 95% rename from tests/extmod/ure1.py rename to tests/extmod/re1.py index 2bdf2d0cfb..7e3839ae24 100644 --- a/tests/extmod/ure1.py +++ b/tests/extmod/re1.py @@ -1,11 +1,8 @@ try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit r = re.compile(".+") m = r.match("abc") diff --git a/tests/extmod/ure_debug.py b/tests/extmod/re_debug.py similarity index 65% rename from tests/extmod/ure_debug.py rename to tests/extmod/re_debug.py index 7a07ede2d4..0f4c95551f 100644 --- a/tests/extmod/ure_debug.py +++ b/tests/extmod/re_debug.py @@ -1,10 +1,10 @@ # test printing debugging info when compiling try: - import ure + import re - ure.DEBUG + re.DEBUG except (ImportError, AttributeError): print("SKIP") raise SystemExit -ure.compile("^a|b[0-9]\w$", ure.DEBUG) +re.compile("^a|b[0-9]\w$", re.DEBUG) diff --git a/tests/extmod/ure_debug.py.exp b/tests/extmod/re_debug.py.exp similarity index 100% rename from tests/extmod/ure_debug.py.exp rename to tests/extmod/re_debug.py.exp diff --git a/tests/extmod/ure_error.py b/tests/extmod/re_error.py similarity index 73% rename from tests/extmod/ure_error.py rename to tests/extmod/re_error.py index 52a96b7c03..f61d091328 100644 --- a/tests/extmod/ure_error.py +++ b/tests/extmod/re_error.py @@ -1,13 +1,10 @@ # test errors in regex try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit def test_re(r): diff --git a/tests/extmod/ure_group.py b/tests/extmod/re_group.py similarity index 81% rename from tests/extmod/ure_group.py rename to tests/extmod/re_group.py index 41425dd623..06c9ccfb2d 100644 --- a/tests/extmod/ure_group.py +++ b/tests/extmod/re_group.py @@ -1,13 +1,10 @@ # test groups, and nested groups try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit def print_groups(match): diff --git a/tests/extmod/ure_groups.py b/tests/extmod/re_groups.py similarity index 81% rename from tests/extmod/ure_groups.py rename to tests/extmod/re_groups.py index 7da072a920..840a4b1af1 100644 --- a/tests/extmod/ure_groups.py +++ b/tests/extmod/re_groups.py @@ -1,13 +1,10 @@ # test match.groups() try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: m = re.match(".", "a") diff --git a/tests/extmod/ure_limit.py b/tests/extmod/re_limit.py similarity index 88% rename from tests/extmod/ure_limit.py rename to tests/extmod/re_limit.py index 99c6a818e8..e0531afbdc 100644 --- a/tests/extmod/ure_limit.py +++ b/tests/extmod/re_limit.py @@ -1,7 +1,7 @@ -# Test overflow in ure.compile output code. +# Test overflow in re.compile output code. try: - import ure as re + import re except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ure_limit.py.exp b/tests/extmod/re_limit.py.exp similarity index 100% rename from tests/extmod/ure_limit.py.exp rename to tests/extmod/re_limit.py.exp diff --git a/tests/extmod/ure_namedclass.py b/tests/extmod/re_namedclass.py similarity index 85% rename from tests/extmod/ure_namedclass.py rename to tests/extmod/re_namedclass.py index 4afc09dc0a..442172f4ab 100644 --- a/tests/extmod/ure_namedclass.py +++ b/tests/extmod/re_namedclass.py @@ -1,13 +1,10 @@ # test named char classes try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit def print_groups(match): diff --git a/tests/extmod/ure_span.py b/tests/extmod/re_span.py similarity index 85% rename from tests/extmod/ure_span.py rename to tests/extmod/re_span.py index 03a3fef9f3..d00ef957a1 100644 --- a/tests/extmod/ure_span.py +++ b/tests/extmod/re_span.py @@ -1,13 +1,10 @@ # test match.span(), and nested spans try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: m = re.match(".", "a") diff --git a/tests/extmod/ure_split.py b/tests/extmod/re_split.py similarity index 82% rename from tests/extmod/ure_split.py rename to tests/extmod/re_split.py index 7e6ef3990f..7769e1a121 100644 --- a/tests/extmod/ure_split.py +++ b/tests/extmod/re_split.py @@ -1,11 +1,8 @@ try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit r = re.compile(" ") s = r.split("a b c foobar") diff --git a/tests/extmod/ure_split_empty.py b/tests/extmod/re_split_empty.py similarity index 95% rename from tests/extmod/ure_split_empty.py rename to tests/extmod/re_split_empty.py index 76ce97ea67..bc17aa8d78 100644 --- a/tests/extmod/ure_split_empty.py +++ b/tests/extmod/re_split_empty.py @@ -5,7 +5,7 @@ # splitting as soon as an empty match is found. try: - import ure as re + import re except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ure_split_empty.py.exp b/tests/extmod/re_split_empty.py.exp similarity index 100% rename from tests/extmod/ure_split_empty.py.exp rename to tests/extmod/re_split_empty.py.exp diff --git a/tests/extmod/ure_split_notimpl.py b/tests/extmod/re_split_notimpl.py similarity index 89% rename from tests/extmod/ure_split_notimpl.py rename to tests/extmod/re_split_notimpl.py index 51bad791ef..7ddec9fa03 100644 --- a/tests/extmod/ure_split_notimpl.py +++ b/tests/extmod/re_split_notimpl.py @@ -1,5 +1,5 @@ try: - import ure as re + import re except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ure_split_notimpl.py.exp b/tests/extmod/re_split_notimpl.py.exp similarity index 100% rename from tests/extmod/ure_split_notimpl.py.exp rename to tests/extmod/re_split_notimpl.py.exp diff --git a/tests/extmod/re_stack_overflow.py b/tests/extmod/re_stack_overflow.py new file mode 100644 index 0000000000..90fb8296b1 --- /dev/null +++ b/tests/extmod/re_stack_overflow.py @@ -0,0 +1,10 @@ +try: + import re +except ImportError: + print("SKIP") + raise SystemExit + +try: + re.match("(a*)*", "aaa") +except RuntimeError: + print("RuntimeError") diff --git a/tests/extmod/ure_stack_overflow.py.exp b/tests/extmod/re_stack_overflow.py.exp similarity index 100% rename from tests/extmod/ure_stack_overflow.py.exp rename to tests/extmod/re_stack_overflow.py.exp diff --git a/tests/extmod/ure_sub.py b/tests/extmod/re_sub.py similarity index 93% rename from tests/extmod/ure_sub.py rename to tests/extmod/re_sub.py index 806c389576..229c0e63ee 100644 --- a/tests/extmod/ure_sub.py +++ b/tests/extmod/re_sub.py @@ -1,11 +1,8 @@ try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: re.sub diff --git a/tests/extmod/ure_sub_unmatched.py b/tests/extmod/re_sub_unmatched.py similarity index 71% rename from tests/extmod/ure_sub_unmatched.py rename to tests/extmod/re_sub_unmatched.py index d6312bfc2c..c238a7ed64 100644 --- a/tests/extmod/ure_sub_unmatched.py +++ b/tests/extmod/re_sub_unmatched.py @@ -1,13 +1,10 @@ # test re.sub with unmatched groups, behaviour changed in CPython 3.5 try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: re.sub diff --git a/tests/extmod/ure_sub_unmatched.py.exp b/tests/extmod/re_sub_unmatched.py.exp similarity index 100% rename from tests/extmod/ure_sub_unmatched.py.exp rename to tests/extmod/re_sub_unmatched.py.exp diff --git a/tests/extmod/uselect_poll_basic.py b/tests/extmod/select_poll_basic.py similarity index 69% rename from tests/extmod/uselect_poll_basic.py rename to tests/extmod/select_poll_basic.py index 97fbd6fd15..b36e16f018 100644 --- a/tests/extmod/uselect_poll_basic.py +++ b/tests/extmod/select_poll_basic.py @@ -1,13 +1,10 @@ try: - import usocket as socket, uselect as select, uerrno as errno -except ImportError: - try: - import socket, select, errno + import socket, select, errno - select.poll # Raises AttributeError for CPython implementations without poll() - except (ImportError, AttributeError): - print("SKIP") - raise SystemExit + select.poll # Raises AttributeError for CPython implementations without poll() +except (ImportError, AttributeError): + print("SKIP") + raise SystemExit poller = select.poll() diff --git a/tests/extmod/uselect_poll_udp.py b/tests/extmod/select_poll_udp.py similarity index 66% rename from tests/extmod/uselect_poll_udp.py rename to tests/extmod/select_poll_udp.py index 2a56a122b5..336f987c12 100644 --- a/tests/extmod/uselect_poll_udp.py +++ b/tests/extmod/select_poll_udp.py @@ -1,15 +1,12 @@ # test select.poll on UDP sockets try: - import usocket as socket, uselect as select -except ImportError: - try: - import socket, select + import socket, select - select.poll # Raises AttributeError for CPython implementations without poll() - except (ImportError, AttributeError): - print("SKIP") - raise SystemExit + select.poll # Raises AttributeError for CPython implementations without poll() +except (ImportError, AttributeError): + print("SKIP") + raise SystemExit s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) diff --git a/tests/extmod/usocket_tcp_basic.py b/tests/extmod/socket_tcp_basic.py similarity index 60% rename from tests/extmod/usocket_tcp_basic.py rename to tests/extmod/socket_tcp_basic.py index c2fe8cd14c..ebd30f7862 100644 --- a/tests/extmod/usocket_tcp_basic.py +++ b/tests/extmod/socket_tcp_basic.py @@ -1,13 +1,10 @@ # Test basic, stand-alone TCP socket functionality try: - import usocket as socket, uerrno as errno + import socket, errno except ImportError: - try: - import socket, errno - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit # recv() on a fresh socket should raise ENOTCONN s = socket.socket() diff --git a/tests/extmod/usocket_udp_nonblock.py b/tests/extmod/socket_udp_nonblock.py similarity index 63% rename from tests/extmod/usocket_udp_nonblock.py rename to tests/extmod/socket_udp_nonblock.py index bc560de142..f7ce5f3444 100644 --- a/tests/extmod/usocket_udp_nonblock.py +++ b/tests/extmod/socket_udp_nonblock.py @@ -1,13 +1,10 @@ # test non-blocking UDP sockets try: - import usocket as socket, uerrno as errno + import socket, errno except ImportError: - try: - import socket, errno - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) diff --git a/tests/extmod/ussl_basic.py b/tests/extmod/ssl_basic.py similarity index 96% rename from tests/extmod/ussl_basic.py rename to tests/extmod/ssl_basic.py index dd3b6f0b91..d035798c98 100644 --- a/tests/extmod/ussl_basic.py +++ b/tests/extmod/ssl_basic.py @@ -1,8 +1,8 @@ # very basic test of ssl module, just to test the methods exist try: - import uio as io - import ussl as ssl + import io + import ssl except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ussl_basic.py.exp b/tests/extmod/ssl_basic.py.exp similarity index 100% rename from tests/extmod/ussl_basic.py.exp rename to tests/extmod/ssl_basic.py.exp diff --git a/tests/extmod/ussl_keycert.py b/tests/extmod/ssl_keycert.py similarity index 94% rename from tests/extmod/ussl_keycert.py rename to tests/extmod/ssl_keycert.py index 87a40a1e55..53f064fdaf 100644 --- a/tests/extmod/ussl_keycert.py +++ b/tests/extmod/ssl_keycert.py @@ -1,8 +1,8 @@ -# Test ussl with key/cert passed in +# Test ssl with key/cert passed in try: - import uio as io - import ussl as ssl + import io + import ssl except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ussl_keycert.py.exp b/tests/extmod/ssl_keycert.py.exp similarity index 100% rename from tests/extmod/ussl_keycert.py.exp rename to tests/extmod/ssl_keycert.py.exp diff --git a/tests/extmod/ussl_poll.py b/tests/extmod/ssl_poll.py similarity index 94% rename from tests/extmod/ussl_poll.py rename to tests/extmod/ssl_poll.py index 8080ec5112..347e5f7d37 100644 --- a/tests/extmod/ussl_poll.py +++ b/tests/extmod/ssl_poll.py @@ -1,8 +1,8 @@ try: - import uselect - import ussl + import select + import ssl import io - import ubinascii as binascii + import binascii except ImportError: print("SKIP") raise SystemExit @@ -121,9 +121,9 @@ client_io, server_io = _Pipe.new_pair() client_io.block_reads = True client_io.block_writes = True -client_sock = ussl.wrap_socket(client_io, do_handshake=False) +client_sock = ssl.wrap_socket(client_io, do_handshake=False) -server_sock = ussl.wrap_socket(server_io, key=key, cert=cert, server_side=True, do_handshake=False) +server_sock = ssl.wrap_socket(server_io, key=key, cert=cert, server_side=True, do_handshake=False) # Do a test read, at this point the TLS handshake wants to write, # so it returns None: @@ -175,7 +175,7 @@ assert server_sock.read(3) == b"bar" # Polling on a closed socket errors out: client_io, _ = _Pipe.new_pair() -client_sock = ussl.wrap_socket(client_io, do_handshake=False) +client_sock = ssl.wrap_socket(client_io, do_handshake=False) client_sock.close() assert_poll( client_sock, client_io, _MP_STREAM_POLL_RD, None, _MP_STREAM_POLL_NVAL @@ -184,7 +184,7 @@ assert_poll( # Errors propagates to poll: client_io, server_io = _Pipe.new_pair() -client_sock = ussl.wrap_socket(client_io, do_handshake=False) +client_sock = ssl.wrap_socket(client_io, do_handshake=False) # The server returns garbage: server_io.write(b"fooba") # Needs to be exactly 5 bytes diff --git a/tests/extmod/ussl_poll.py.exp b/tests/extmod/ssl_poll.py.exp similarity index 100% rename from tests/extmod/ussl_poll.py.exp rename to tests/extmod/ssl_poll.py.exp diff --git a/tests/extmod/ticks_add.py b/tests/extmod/ticks_add.py index 2f1ba6c810..4f465f3cfb 100644 --- a/tests/extmod/ticks_add.py +++ b/tests/extmod/ticks_add.py @@ -1,5 +1,5 @@ try: - from utime import ticks_diff, ticks_add + from time import ticks_diff, ticks_add except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/ticks_diff.py b/tests/extmod/ticks_diff.py index de45a557af..b2445f0d62 100644 --- a/tests/extmod/ticks_diff.py +++ b/tests/extmod/ticks_diff.py @@ -1,5 +1,5 @@ try: - from utime import ticks_diff, ticks_add + from time import ticks_diff, ticks_add except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/time_ms_us.py b/tests/extmod/time_ms_us.py index ac2ed8be27..e26c6e677a 100644 --- a/tests/extmod/time_ms_us.py +++ b/tests/extmod/time_ms_us.py @@ -1,23 +1,23 @@ try: - import utime + import time - utime.sleep_ms, utime.sleep_us, utime.ticks_diff, utime.ticks_ms, utime.ticks_us, utime.ticks_cpu + time.sleep_ms, time.sleep_us, time.ticks_diff, time.ticks_ms, time.ticks_us, time.ticks_cpu except (ImportError, AttributeError): print("SKIP") raise SystemExit -utime.sleep_ms(1) -utime.sleep_us(1) +time.sleep_ms(1) +time.sleep_us(1) -t0 = utime.ticks_ms() -t1 = utime.ticks_ms() -print(0 <= utime.ticks_diff(t1, t0) <= 1) +t0 = time.ticks_ms() +t1 = time.ticks_ms() +print(0 <= time.ticks_diff(t1, t0) <= 1) -t0 = utime.ticks_us() -t1 = utime.ticks_us() -print(0 <= utime.ticks_diff(t1, t0) <= 500) +t0 = time.ticks_us() +t1 = time.ticks_us() +print(0 <= time.ticks_diff(t1, t0) <= 500) # ticks_cpu may not be implemented, at least make sure it doesn't decrease -t0 = utime.ticks_cpu() -t1 = utime.ticks_cpu() -print(utime.ticks_diff(t1, t0) >= 0) +t0 = time.ticks_cpu() +t1 = time.ticks_cpu() +print(time.ticks_diff(t1, t0) >= 0) diff --git a/tests/extmod/utime_res.py b/tests/extmod/time_res.py similarity index 80% rename from tests/extmod/utime_res.py rename to tests/extmod/time_res.py index 4b62433483..548bef1f17 100644 --- a/tests/extmod/utime_res.py +++ b/tests/extmod/time_res.py @@ -1,18 +1,18 @@ -# test utime resolutions +# test time resolutions try: - import utime + import time except ImportError: print("SKIP") raise SystemExit def gmtime_time(): - return utime.gmtime(utime.time()) + return time.gmtime(time.time()) def localtime_time(): - return utime.localtime(utime.time()) + return time.localtime(time.time()) def test(): @@ -32,12 +32,12 @@ def test(): # call time functions results_map = {} - end_time = utime.ticks_ms() + TEST_TIME - while utime.ticks_diff(end_time, utime.ticks_ms()) > 0: - utime.sleep_ms(100) + end_time = time.ticks_ms() + TEST_TIME + while time.ticks_diff(end_time, time.ticks_ms()) > 0: + time.sleep_ms(100) for func_name, _ in EXPECTED_MAP: try: - time_func = getattr(utime, func_name, None) or globals()[func_name] + time_func = getattr(time, func_name, None) or globals()[func_name] now = time_func() # may raise AttributeError except (KeyError, AttributeError): continue diff --git a/tests/extmod/utime_res.py.exp b/tests/extmod/time_res.py.exp similarity index 100% rename from tests/extmod/utime_res.py.exp rename to tests/extmod/time_res.py.exp diff --git a/tests/extmod/utime_time_ns.py b/tests/extmod/time_time_ns.py similarity index 68% rename from tests/extmod/utime_time_ns.py rename to tests/extmod/time_time_ns.py index 0d13f839d4..3ef58e56a9 100644 --- a/tests/extmod/utime_time_ns.py +++ b/tests/extmod/time_time_ns.py @@ -1,18 +1,18 @@ -# test utime.time_ns() +# test time.time_ns() try: - import utime + import time - utime.sleep_us - utime.time_ns + time.sleep_us + time.time_ns except (ImportError, AttributeError): print("SKIP") raise SystemExit -t0 = utime.time_ns() -utime.sleep_us(5000) -t1 = utime.time_ns() +t0 = time.time_ns() +time.sleep_us(5000) +t1 = time.time_ns() # Check that time_ns increases. print(t0 < t1) diff --git a/tests/extmod/utime_time_ns.py.exp b/tests/extmod/time_time_ns.py.exp similarity index 100% rename from tests/extmod/utime_time_ns.py.exp rename to tests/extmod/time_time_ns.py.exp diff --git a/tests/extmod/utimeq1.py b/tests/extmod/timeq1.py similarity index 90% rename from tests/extmod/utimeq1.py rename to tests/extmod/timeq1.py index 688e5b834f..0778c87255 100644 --- a/tests/extmod/utimeq1.py +++ b/tests/extmod/timeq1.py @@ -1,8 +1,8 @@ -# Test for utimeq module which implements task queue with support for -# wraparound time (utime.ticks_ms() style). +# Test for timeq module which implements task queue with support for +# wraparound time (time.ticks_ms() style). try: - from utime import ticks_add, ticks_diff - from utimeq import utimeq + from time import ticks_add, ticks_diff + from timeq import timeq except ImportError: print("SKIP") raise SystemExit @@ -24,7 +24,7 @@ else: # Try not to crash on invalid data -h = utimeq(10) +h = timeq(10) try: h.push(1) assert False @@ -45,7 +45,7 @@ except TypeError: pass # pushing on full queue -h = utimeq(1) +h = timeq(1) h.push(1, 0, 0) try: h.push(2, 0, 0) @@ -68,7 +68,7 @@ assert h.peektime() == 1 # peektime with empty queue try: - utimeq(1).peektime() + timeq(1).peektime() assert False except IndexError: pass @@ -92,7 +92,7 @@ def add(h, v): dprint("-----") -h = utimeq(10) +h = timeq(10) add(h, 0) add(h, MAX) add(h, MAX - 1) @@ -107,7 +107,7 @@ for i in range(len(l) - 1): def edge_case(edge, offset): - h = utimeq(10) + h = timeq(10) add(h, ticks_add(0, offset)) add(h, ticks_add(edge, offset)) dprint(h) diff --git a/tests/extmod/utimeq1.py.exp b/tests/extmod/timeq1.py.exp similarity index 100% rename from tests/extmod/utimeq1.py.exp rename to tests/extmod/timeq1.py.exp diff --git a/tests/extmod/utimeq_stable.py b/tests/extmod/timeq_stable.py similarity index 90% rename from tests/extmod/utimeq_stable.py rename to tests/extmod/timeq_stable.py index 9fb522d514..b19ea1b3ad 100644 --- a/tests/extmod/utimeq_stable.py +++ b/tests/extmod/timeq_stable.py @@ -1,10 +1,10 @@ try: - from utimeq import utimeq + from timeq import timeq except ImportError: print("SKIP") raise SystemExit -h = utimeq(10) +h = timeq(10) # Check that for 2 same-key items, the queue is stable (pops items # in the same order they were pushed). Unfortunately, this no longer diff --git a/tests/extmod/utimeq_stable.py.exp b/tests/extmod/timeq_stable.py.exp similarity index 100% rename from tests/extmod/utimeq_stable.py.exp rename to tests/extmod/timeq_stable.py.exp diff --git a/tests/extmod/uasyncio_basic.py b/tests/extmod/uasyncio_basic.py index 20c0a82e47..3858e4fdd5 100644 --- a/tests/extmod/uasyncio_basic.py +++ b/tests/extmod/uasyncio_basic.py @@ -7,15 +7,12 @@ except ImportError: print("SKIP") raise SystemExit +import time -try: - import utime - - ticks = utime.ticks_ms - ticks_diff = utime.ticks_diff -except: - import time - +if hasattr(time, "ticks_ms"): + ticks = time.ticks_ms + ticks_diff = time.ticks_diff +else: ticks = lambda: int(time.time() * 1000) ticks_diff = lambda t1, t0: t1 - t0 diff --git a/tests/extmod/uasyncio_micropython.py b/tests/extmod/uasyncio_micropython.py index a6b65bb2a8..de1687ca8b 100644 --- a/tests/extmod/uasyncio_micropython.py +++ b/tests/extmod/uasyncio_micropython.py @@ -3,7 +3,7 @@ # - wait_for_ms try: - import utime, uasyncio + import time, uasyncio except ImportError: print("SKIP") raise SystemExit @@ -18,13 +18,13 @@ async def task(id, t): async def main(): # Simple sleep_ms - t0 = utime.ticks_ms() + t0 = time.ticks_ms() await uasyncio.sleep_ms(1) - print(utime.ticks_diff(utime.ticks_ms(), t0) < 100) + print(time.ticks_diff(time.ticks_ms(), t0) < 100) try: # Sleep 1ms beyond maximum allowed sleep value - await uasyncio.sleep_ms(utime.ticks_add(0, -1) // 2 + 1) + await uasyncio.sleep_ms(time.ticks_add(0, -1) // 2 + 1) except OverflowError: print("OverflowError") diff --git a/tests/extmod/uasyncio_threadsafeflag.py b/tests/extmod/uasyncio_threadsafeflag.py index a8a08d2e92..f97b138498 100644 --- a/tests/extmod/uasyncio_threadsafeflag.py +++ b/tests/extmod/uasyncio_threadsafeflag.py @@ -18,7 +18,7 @@ except AttributeError: try: # Unix port can't select/poll on user-defined types. - import uselect as select + import select poller = select.poll() poller.register(asyncio.ThreadSafeFlag()) diff --git a/tests/extmod/uasyncio_wait_task.py b/tests/extmod/uasyncio_wait_task.py index e19e29903c..1d70ddf720 100644 --- a/tests/extmod/uasyncio_wait_task.py +++ b/tests/extmod/uasyncio_wait_task.py @@ -10,14 +10,12 @@ except ImportError: raise SystemExit -try: - import utime - - ticks = utime.ticks_ms - ticks_diff = utime.ticks_diff -except: - import time +import time +if hasattr(time, "ticks_ms"): + ticks = time.ticks_ms + ticks_diff = time.ticks_diff +else: ticks = lambda: int(time.time() * 1000) ticks_diff = lambda t1, t0: t1 - t0 diff --git a/tests/extmod/uctypes_array_assign_native_le.py b/tests/extmod/uctypes_array_assign_native_le.py index 5bddfcdf2f..d4c27fc4b3 100644 --- a/tests/extmod/uctypes_array_assign_native_le.py +++ b/tests/extmod/uctypes_array_assign_native_le.py @@ -1,4 +1,4 @@ -import usys +import sys try: import uctypes @@ -6,7 +6,7 @@ except ImportError: print("SKIP") raise SystemExit -if usys.byteorder != "little": +if sys.byteorder != "little": print("SKIP") raise SystemExit diff --git a/tests/extmod/uctypes_array_assign_native_le_intbig.py b/tests/extmod/uctypes_array_assign_native_le_intbig.py index 42583b8afe..f33c63b4ef 100644 --- a/tests/extmod/uctypes_array_assign_native_le_intbig.py +++ b/tests/extmod/uctypes_array_assign_native_le_intbig.py @@ -1,4 +1,4 @@ -import usys +import sys try: import uctypes @@ -6,7 +6,7 @@ except ImportError: print("SKIP") raise SystemExit -if usys.byteorder != "little": +if sys.byteorder != "little": print("SKIP") raise SystemExit diff --git a/tests/extmod/uctypes_native_le.py b/tests/extmod/uctypes_native_le.py index 9889b98e9d..7958e5c22a 100644 --- a/tests/extmod/uctypes_native_le.py +++ b/tests/extmod/uctypes_native_le.py @@ -1,7 +1,7 @@ # This test is exactly like uctypes_le.py, but uses native structure layout. # Codepaths for packed vs native structures are different. This test only works # on little-endian machine (no matter if 32 or 64 bit). -import usys +import sys try: import uctypes @@ -9,7 +9,7 @@ except ImportError: print("SKIP") raise SystemExit -if usys.byteorder != "little": +if sys.byteorder != "little": print("SKIP") raise SystemExit diff --git a/tests/extmod/uctypes_ptr_le.py b/tests/extmod/uctypes_ptr_le.py index f475465ae8..5d8094ee48 100644 --- a/tests/extmod/uctypes_ptr_le.py +++ b/tests/extmod/uctypes_ptr_le.py @@ -1,4 +1,4 @@ -import usys +import sys try: import uctypes @@ -6,7 +6,7 @@ except ImportError: print("SKIP") raise SystemExit -if usys.byteorder != "little": +if sys.byteorder != "little": print("SKIP") raise SystemExit diff --git a/tests/extmod/uctypes_ptr_native_le.py b/tests/extmod/uctypes_ptr_native_le.py index ca2b316c54..8ca4d2c55c 100644 --- a/tests/extmod/uctypes_ptr_native_le.py +++ b/tests/extmod/uctypes_ptr_native_le.py @@ -1,4 +1,4 @@ -import usys +import sys try: import uctypes @@ -6,7 +6,7 @@ except ImportError: print("SKIP") raise SystemExit -if usys.byteorder != "little": +if sys.byteorder != "little": print("SKIP") raise SystemExit diff --git a/tests/extmod/uctypes_sizeof_od.py b/tests/extmod/uctypes_sizeof_od.py index 2f070095b5..375f05f5e2 100644 --- a/tests/extmod/uctypes_sizeof_od.py +++ b/tests/extmod/uctypes_sizeof_od.py @@ -1,5 +1,5 @@ try: - from ucollections import OrderedDict + from collections import OrderedDict import uctypes except ImportError: print("SKIP") diff --git a/tests/extmod/uhashlib_md5.py b/tests/extmod/uhashlib_md5.py deleted file mode 100644 index 07d5f31692..0000000000 --- a/tests/extmod/uhashlib_md5.py +++ /dev/null @@ -1,21 +0,0 @@ -try: - import uhashlib as hashlib -except ImportError: - try: - import hashlib - except ImportError: - # This is neither uPy, nor cPy, so must be uPy with - # uhashlib module disabled. - print("SKIP") - raise SystemExit - -try: - hashlib.md5 -except AttributeError: - # MD5 is only available on some ports - print("SKIP") - raise SystemExit - -md5 = hashlib.md5(b"hello") -md5.update(b"world") -print(md5.digest()) diff --git a/tests/extmod/uhashlib_sha1.py b/tests/extmod/uhashlib_sha1.py deleted file mode 100644 index a573121316..0000000000 --- a/tests/extmod/uhashlib_sha1.py +++ /dev/null @@ -1,21 +0,0 @@ -try: - import uhashlib as hashlib -except ImportError: - try: - import hashlib - except ImportError: - # This is neither uPy, nor cPy, so must be uPy with - # uhashlib module disabled. - print("SKIP") - raise SystemExit - -try: - hashlib.sha1 -except AttributeError: - # SHA1 is only available on some ports - print("SKIP") - raise SystemExit - -sha1 = hashlib.sha1(b"hello") -sha1.update(b"world") -print(sha1.digest()) diff --git a/tests/extmod/ujson_dumps_extra.py b/tests/extmod/ujson_dumps_extra.py deleted file mode 100644 index f2aa7f249f..0000000000 --- a/tests/extmod/ujson_dumps_extra.py +++ /dev/null @@ -1,9 +0,0 @@ -# test uPy ujson behaviour that's not valid in CPy - -try: - import ujson -except ImportError: - print("SKIP") - raise SystemExit - -print(ujson.dumps(b"1234")) diff --git a/tests/extmod/ujson_dumps_float.py b/tests/extmod/ujson_dumps_float.py deleted file mode 100644 index 25681d0c23..0000000000 --- a/tests/extmod/ujson_dumps_float.py +++ /dev/null @@ -1,11 +0,0 @@ -try: - import ujson as json -except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit - -print(json.dumps(1.2)) -print(json.dumps({1.5: "hi"})) diff --git a/tests/extmod/ujson_dumps_ordereddict.py b/tests/extmod/ujson_dumps_ordereddict.py deleted file mode 100644 index c6f4a8fcb7..0000000000 --- a/tests/extmod/ujson_dumps_ordereddict.py +++ /dev/null @@ -1,12 +0,0 @@ -try: - import ujson as json - from ucollections import OrderedDict -except ImportError: - try: - import json - from collections import OrderedDict - except ImportError: - print("SKIP") - raise SystemExit - -print(json.dumps(OrderedDict(((1, 2), (3, 4))))) diff --git a/tests/extmod/ujson_load.py b/tests/extmod/ujson_load.py deleted file mode 100644 index 7cec9246b8..0000000000 --- a/tests/extmod/ujson_load.py +++ /dev/null @@ -1,15 +0,0 @@ -try: - from uio import StringIO - import ujson as json -except: - try: - from io import StringIO - import json - except ImportError: - print("SKIP") - raise SystemExit - -print(json.load(StringIO("null"))) -print(json.load(StringIO('"abc\\u0064e"'))) -print(json.load(StringIO("[false, true, 1, -2]"))) -print(json.load(StringIO('{"a":true}'))) diff --git a/tests/extmod/ure_stack_overflow.py b/tests/extmod/ure_stack_overflow.py deleted file mode 100644 index d3ce0c5a7b..0000000000 --- a/tests/extmod/ure_stack_overflow.py +++ /dev/null @@ -1,13 +0,0 @@ -try: - import ure as re -except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit - -try: - re.match("(a*)*", "aaa") -except RuntimeError: - print("RuntimeError") diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index 9a9ef2ca61..028846406a 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -1,9 +1,9 @@ # test VFS functionality without any particular filesystem type try: - import uos + import os - uos.mount + os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -59,35 +59,35 @@ class Filesystem: # first we umount any existing mount points the target may have try: - uos.umount("/") + os.umount("/") except OSError: pass -for path in uos.listdir("/"): - uos.umount("/" + path) +for path in os.listdir("/"): + os.umount("/" + path) # stat root dir -print(uos.stat("/")) +print(os.stat("/")) # statvfs root dir; verify that f_namemax has a sensible size -print(uos.statvfs("/")[9] >= 32) +print(os.statvfs("/")[9] >= 32) # getcwd when in root dir -print(uos.getcwd()) +print(os.getcwd()) # test operations on the root directory with nothing mounted, they should all fail for func in ("chdir", "listdir", "mkdir", "remove", "rmdir", "stat"): for arg in ("x", "/x"): try: - getattr(uos, func)(arg) + getattr(os, func)(arg) except OSError: print(func, arg, "OSError") # basic mounting and listdir -uos.mount(Filesystem(1), "/test_mnt") -print(uos.listdir()) +os.mount(Filesystem(1), "/test_mnt") +print(os.listdir()) # ilistdir -i = uos.ilistdir() +i = os.ilistdir() print(next(i)) try: next(i) @@ -99,88 +99,88 @@ except StopIteration: print("StopIteration") # referencing the mount point in different ways -print(uos.listdir("test_mnt")) -print(uos.listdir("/test_mnt")) +print(os.listdir("test_mnt")) +print(os.listdir("/test_mnt")) # mounting another filesystem -uos.mount(Filesystem(2), "/test_mnt2", readonly=True) -print(uos.listdir()) -print(uos.listdir("/test_mnt2")) +os.mount(Filesystem(2), "/test_mnt2", readonly=True) +print(os.listdir()) +print(os.listdir("/test_mnt2")) # mounting over an existing mount point try: - uos.mount(Filesystem(3), "/test_mnt2") + os.mount(Filesystem(3), "/test_mnt2") except OSError: print("OSError") # mkdir of a mount point try: - uos.mkdir("/test_mnt") + os.mkdir("/test_mnt") except OSError: print("OSError") # rename across a filesystem try: - uos.rename("/test_mnt/a", "/test_mnt2/b") + os.rename("/test_mnt/a", "/test_mnt2/b") except OSError: print("OSError") # delegating to mounted filesystem -uos.chdir("test_mnt") -print(uos.listdir()) -print(uos.getcwd()) -uos.mkdir("test_dir") -uos.remove("test_file") -uos.rename("test_file", "test_file2") -uos.rmdir("test_dir") -print(uos.stat("test_file")) -print(uos.statvfs("/test_mnt")) +os.chdir("test_mnt") +print(os.listdir()) +print(os.getcwd()) +os.mkdir("test_dir") +os.remove("test_file") +os.rename("test_file", "test_file2") +os.rmdir("test_dir") +print(os.stat("test_file")) +print(os.statvfs("/test_mnt")) open("test_file") open("test_file", "wb") # umount -uos.umount("/test_mnt") -uos.umount("/test_mnt2") +os.umount("/test_mnt") +os.umount("/test_mnt2") # umount a non-existent mount point try: - uos.umount("/test_mnt") + os.umount("/test_mnt") except OSError: print("OSError") # root dir -uos.mount(Filesystem(3), "/") -print(uos.stat("/")) -print(uos.statvfs("/")) -print(uos.listdir()) +os.mount(Filesystem(3), "/") +print(os.stat("/")) +print(os.statvfs("/")) +print(os.listdir()) open("test") -uos.mount(Filesystem(4), "/mnt") -print(uos.listdir()) -print(uos.listdir("/mnt")) -uos.chdir("/mnt") -print(uos.listdir()) +os.mount(Filesystem(4), "/mnt") +print(os.listdir()) +print(os.listdir("/mnt")) +os.chdir("/mnt") +print(os.listdir()) # chdir to a subdir within root-mounted vfs, and then listdir -uos.chdir("/subdir") -print(uos.listdir()) -uos.chdir("/") +os.chdir("/subdir") +print(os.listdir()) +os.chdir("/") -uos.umount("/") -print(uos.listdir("/")) -uos.umount("/mnt") +os.umount("/") +print(os.listdir("/")) +os.umount("/mnt") # chdir to a non-existent mount point (current directory should remain unchanged) try: - uos.chdir("/foo") + os.chdir("/foo") except OSError: print("OSError") -print(uos.getcwd()) +print(os.getcwd()) # chdir to a non-existent subdirectory in a mounted filesystem -uos.mount(Filesystem(5, 1), "/mnt") +os.mount(Filesystem(5, 1), "/mnt") try: - uos.chdir("/mnt/subdir") + os.chdir("/mnt/subdir") except OSError: print("OSError") -print(uos.getcwd()) +print(os.getcwd()) diff --git a/tests/extmod/vfs_blockdev.py b/tests/extmod/vfs_blockdev.py index e24169ba93..f4c84ea921 100644 --- a/tests/extmod/vfs_blockdev.py +++ b/tests/extmod/vfs_blockdev.py @@ -1,10 +1,10 @@ # Test for behaviour of combined standard and extended block device try: - import uos + import os - uos.VfsFat - uos.VfsLfs2 + os.VfsFat + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -65,10 +65,12 @@ def test(bdev, vfs_class): try: + import os + bdev = RAMBlockDevice(50) except MemoryError: print("SKIP") raise SystemExit -test(bdev, uos.VfsFat) -test(bdev, uos.VfsLfs2) +test(bdev, os.VfsFat) +test(bdev, os.VfsLfs2) diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py index 55f399ff2e..f4db5ac8dd 100644 --- a/tests/extmod/vfs_fat_fileio1.py +++ b/tests/extmod/vfs_fat_fileio1.py @@ -1,12 +1,12 @@ try: - import uerrno - import uos + import errno + import os except ImportError: print("SKIP") raise SystemExit try: - uos.VfsFat + os.VfsFat except AttributeError: print("SKIP") raise SystemExit @@ -38,14 +38,14 @@ class RAMFS: try: bdev = RAMFS(50) - uos.VfsFat.mkfs(bdev) + os.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = uos.VfsFat(bdev) -uos.mount(vfs, "/ramdisk") -uos.chdir("/ramdisk") +vfs = os.VfsFat(bdev) +os.mount(vfs, "/ramdisk") +os.chdir("/ramdisk") # file IO f = open("foo_file.txt", "w") @@ -57,22 +57,22 @@ f.close() # allowed try: f.write("world!") except OSError as e: - print(e.errno == uerrno.EINVAL) + print(e.errno == errno.EINVAL) try: f.read() except OSError as e: - print(e.errno == uerrno.EINVAL) + print(e.errno == errno.EINVAL) try: f.flush() except OSError as e: - print(e.errno == uerrno.EINVAL) + print(e.errno == errno.EINVAL) try: open("foo_file.txt", "x") except OSError as e: - print(e.errno == uerrno.EEXIST) + print(e.errno == errno.EEXIST) with open("foo_file.txt", "a") as f: f.write("world!") @@ -104,7 +104,7 @@ vfs.mkdir("foo_dir") try: vfs.rmdir("foo_file.txt") except OSError as e: - print(e.errno == 20) # uerrno.ENOTDIR + print(e.errno == 20) # errno.ENOTDIR vfs.remove("foo_file.txt") print(list(vfs.ilistdir())) diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index 9429f115f6..353b997e5c 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -1,12 +1,12 @@ try: - import uerrno - import uos + import errno + import os except ImportError: print("SKIP") raise SystemExit try: - uos.VfsFat + os.VfsFat except AttributeError: print("SKIP") raise SystemExit @@ -38,34 +38,34 @@ class RAMFS: try: bdev = RAMFS(50) - uos.VfsFat.mkfs(bdev) + os.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = uos.VfsFat(bdev) -uos.mount(vfs, "/ramdisk") -uos.chdir("/ramdisk") +vfs = os.VfsFat(bdev) +os.mount(vfs, "/ramdisk") +os.chdir("/ramdisk") try: vfs.mkdir("foo_dir") except OSError as e: - print(e.errno == uerrno.EEXIST) + print(e.errno == errno.EEXIST) try: vfs.remove("foo_dir") except OSError as e: - print(e.errno == uerrno.EISDIR) + print(e.errno == errno.EISDIR) try: vfs.remove("no_file.txt") except OSError as e: - print(e.errno == uerrno.ENOENT) + print(e.errno == errno.ENOENT) try: vfs.rename("foo_dir", "/null/file") except OSError as e: - print(e.errno == uerrno.ENOENT) + print(e.errno == errno.ENOENT) # file in dir with open("foo_dir/file-in-dir.txt", "w+t") as f: @@ -81,7 +81,7 @@ with open("foo_dir/sub_file.txt", "w") as f: try: vfs.rmdir("foo_dir") except OSError as e: - print(e.errno == uerrno.EACCES) + print(e.errno == errno.EACCES) # trim full path vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") @@ -110,5 +110,5 @@ try: f = open("large_file.txt", "wb") f.write(bytearray(bsize * free)) except OSError as e: - print("ENOSPC:", e.errno == 28) # uerrno.ENOSPC + print("ENOSPC:", e.errno == 28) # errno.ENOSPC f.close() diff --git a/tests/extmod/vfs_fat_finaliser.py b/tests/extmod/vfs_fat_finaliser.py index b38e640c73..b6c7dffb82 100644 --- a/tests/extmod/vfs_fat_finaliser.py +++ b/tests/extmod/vfs_fat_finaliser.py @@ -1,9 +1,9 @@ # Test VfsFat class and its finaliser try: - import uerrno, uos + import errno, os - uos.VfsFat + os.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -31,14 +31,16 @@ class RAMBlockDevice: # Create block device, and skip test if not enough RAM try: + import errno, os + bdev = RAMBlockDevice(50) except MemoryError: print("SKIP") raise SystemExit # Format block device and create VFS object -uos.VfsFat.mkfs(bdev) -vfs = uos.VfsFat(bdev) +os.VfsFat.mkfs(bdev) +vfs = os.VfsFat(bdev) # Here we test that opening a file with the heap locked fails correctly. This # is a special case because file objects use a finaliser and allocating with a @@ -48,6 +50,8 @@ import micropython micropython.heap_lock() try: + import errno, os + vfs.open("x", "r") except MemoryError: print("MemoryError") diff --git a/tests/extmod/vfs_fat_ilistdir_del.py b/tests/extmod/vfs_fat_ilistdir_del.py index ccdacc57c2..055836ad71 100644 --- a/tests/extmod/vfs_fat_ilistdir_del.py +++ b/tests/extmod/vfs_fat_ilistdir_del.py @@ -2,9 +2,9 @@ import gc try: - import uos + import os - uos.VfsFat + os.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -77,4 +77,4 @@ except MemoryError: print("SKIP") raise SystemExit -test(bdev, uos.VfsFat) +test(bdev, os.VfsFat) diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py index 981c2524a6..7074221a32 100644 --- a/tests/extmod/vfs_fat_more.py +++ b/tests/extmod/vfs_fat_more.py @@ -1,11 +1,11 @@ try: - import uos + import os except ImportError: print("SKIP") raise SystemExit try: - uos.VfsFat + os.VfsFat except AttributeError: print("SKIP") raise SystemExit @@ -44,76 +44,76 @@ except MemoryError: # first we umount any existing mount points the target may have try: - uos.umount("/") + os.umount("/") except OSError: pass -for path in uos.listdir("/"): - uos.umount("/" + path) +for path in os.listdir("/"): + os.umount("/" + path) -uos.VfsFat.mkfs(bdev) -uos.mount(bdev, "/") +os.VfsFat.mkfs(bdev) +os.mount(bdev, "/") -print(uos.getcwd()) +print(os.getcwd()) f = open("test.txt", "w") f.write("hello") f.close() -print(uos.listdir()) -print(uos.listdir("/")) -print(uos.stat("")[:-3]) -print(uos.stat("/")[:-3]) -print(uos.stat("test.txt")[:-3]) -print(uos.stat("/test.txt")[:-3]) +print(os.listdir()) +print(os.listdir("/")) +print(os.stat("")[:-3]) +print(os.stat("/")[:-3]) +print(os.stat("test.txt")[:-3]) +print(os.stat("/test.txt")[:-3]) f = open("/test.txt") print(f.read()) f.close() -uos.rename("test.txt", "test2.txt") -print(uos.listdir()) -uos.rename("test2.txt", "/test3.txt") -print(uos.listdir()) -uos.rename("/test3.txt", "test4.txt") -print(uos.listdir()) -uos.rename("/test4.txt", "/test5.txt") -print(uos.listdir()) +os.rename("test.txt", "test2.txt") +print(os.listdir()) +os.rename("test2.txt", "/test3.txt") +print(os.listdir()) +os.rename("/test3.txt", "test4.txt") +print(os.listdir()) +os.rename("/test4.txt", "/test5.txt") +print(os.listdir()) -uos.mkdir("dir") -print(uos.listdir()) -uos.mkdir("/dir2") -print(uos.listdir()) -uos.mkdir("dir/subdir") -print(uos.listdir("dir")) +os.mkdir("dir") +print(os.listdir()) +os.mkdir("/dir2") +print(os.listdir()) +os.mkdir("dir/subdir") +print(os.listdir("dir")) for exist in ("", "/", "dir", "/dir", "dir/subdir"): try: - uos.mkdir(exist) + os.mkdir(exist) except OSError as er: print("mkdir OSError", er.errno == 17) # EEXIST -uos.chdir("/") -print(uos.stat("test5.txt")[:-3]) +os.chdir("/") +print(os.stat("test5.txt")[:-3]) -uos.VfsFat.mkfs(bdev2) -uos.mount(bdev2, "/sys") -print(uos.listdir()) -print(uos.listdir("sys")) -print(uos.listdir("/sys")) +os.VfsFat.mkfs(bdev2) +os.mount(bdev2, "/sys") +print(os.listdir()) +print(os.listdir("sys")) +print(os.listdir("/sys")) -uos.rmdir("dir2") -uos.remove("test5.txt") -print(uos.listdir()) +os.rmdir("dir2") +os.remove("test5.txt") +print(os.listdir()) -uos.umount("/") -print(uos.getcwd()) -print(uos.listdir()) -print(uos.listdir("sys")) +os.umount("/") +print(os.getcwd()) +print(os.listdir()) +print(os.listdir("sys")) # test importing a file from a mounted FS -import usys +import sys -usys.path.clear() -usys.path.append("/sys") +sys.path.clear() +sys.path.append("/sys") with open("sys/test_module.py", "w") as f: f.write('print("test_module!")') import test_module diff --git a/tests/extmod/vfs_fat_mtime.py b/tests/extmod/vfs_fat_mtime.py index d8fd66b75f..1ceb611364 100644 --- a/tests/extmod/vfs_fat_mtime.py +++ b/tests/extmod/vfs_fat_mtime.py @@ -1,11 +1,11 @@ # Test for VfsFat using a RAM device, mtime feature try: - import utime, uos + import time, os - utime.time - utime.sleep - uos.VfsFat + time.time + time.sleep + os.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -44,11 +44,11 @@ def test(bdev, vfs_class): vfs = vfs_class(bdev) # Create an empty file, should have a timestamp. - current_time = int(utime.time()) + current_time = int(time.time()) vfs.open("test1", "wt").close() # Wait 2 seconds so mtime will increase (FAT has 2 second resolution). - utime.sleep(2) + time.sleep(2) # Create another empty file, should have a timestamp. vfs.open("test2", "wt").close() @@ -71,4 +71,4 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(50) -test(bdev, uos.VfsFat) +test(bdev, os.VfsFat) diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index b1556ba2c0..f5336ba916 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,12 +1,12 @@ try: - import uerrno - import uos + import errno + import os except ImportError: print("SKIP") raise SystemExit try: - uos.VfsFat + os.VfsFat except AttributeError: print("SKIP") raise SystemExit @@ -41,9 +41,9 @@ except MemoryError: print("SKIP") raise SystemExit -uos.VfsFat.mkfs(bdev) -vfs = uos.VfsFat(bdev) -uos.mount(vfs, "/ramdisk") +os.VfsFat.mkfs(bdev) +vfs = os.VfsFat(bdev) +os.mount(vfs, "/ramdisk") # file io with vfs.open("file.txt", "w") as f: diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 01235bc266..1693359d49 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,12 +1,12 @@ try: - import uerrno - import uos + import errno + import os except ImportError: print("SKIP") raise SystemExit try: - uos.VfsFat + os.VfsFat except AttributeError: print("SKIP") raise SystemExit @@ -38,7 +38,7 @@ class RAMFS: try: bdev = RAMFS(50) - uos.VfsFat.mkfs(bdev) + os.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit @@ -46,8 +46,8 @@ except MemoryError: print(b"FOO_FILETXT" not in bdev.data) print(b"hello!" not in bdev.data) -vfs = uos.VfsFat(bdev) -uos.mount(vfs, "/ramdisk") +vfs = os.VfsFat(bdev) +os.mount(vfs, "/ramdisk") print("statvfs:", vfs.statvfs("/ramdisk")) print("getcwd:", vfs.getcwd()) @@ -55,7 +55,7 @@ print("getcwd:", vfs.getcwd()) try: vfs.stat("no_file.txt") except OSError as e: - print(e.errno == uerrno.ENOENT) + print(e.errno == errno.ENOENT) with vfs.open("foo_file.txt", "w") as f: f.write("hello!") @@ -78,18 +78,18 @@ with vfs.open("sub_file.txt", "w") as f: try: vfs.chdir("sub_file.txt") except OSError as e: - print(e.errno == uerrno.ENOENT) + print(e.errno == errno.ENOENT) vfs.chdir("..") print("getcwd:", vfs.getcwd()) -uos.umount(vfs) +os.umount(vfs) -vfs = uos.VfsFat(bdev) +vfs = os.VfsFat(bdev) print(list(vfs.ilistdir(b""))) # list a non-existent directory try: vfs.ilistdir(b"no_exist") except OSError as e: - print("ENOENT:", e.errno == uerrno.ENOENT) + print("ENOENT:", e.errno == errno.ENOENT) diff --git a/tests/extmod/vfs_fat_ramdisklarge.py b/tests/extmod/vfs_fat_ramdisklarge.py index 649a53db14..40cba9ee43 100644 --- a/tests/extmod/vfs_fat_ramdisklarge.py +++ b/tests/extmod/vfs_fat_ramdisklarge.py @@ -1,13 +1,13 @@ # test making a FAT filesystem on a very large block device try: - import uos + import os except ImportError: print("SKIP") raise SystemExit try: - uos.VfsFat + os.VfsFat except AttributeError: print("SKIP") raise SystemExit @@ -46,13 +46,13 @@ class RAMBDevSparse: try: bdev = RAMBDevSparse(4 * 1024 * 1024 * 1024 // RAMBDevSparse.SEC_SIZE) - uos.VfsFat.mkfs(bdev) + os.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = uos.VfsFat(bdev) -uos.mount(vfs, "/ramdisk") +vfs = os.VfsFat(bdev) +os.mount(vfs, "/ramdisk") print("statvfs:", vfs.statvfs("/ramdisk")) @@ -66,4 +66,4 @@ f = open("/ramdisk/test.txt") print(f.read()) f.close() -uos.umount(vfs) +os.umount(vfs) diff --git a/tests/extmod/vfs_lfs.py b/tests/extmod/vfs_lfs.py index 8e56400df3..83377653b2 100644 --- a/tests/extmod/vfs_lfs.py +++ b/tests/extmod/vfs_lfs.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device try: - import uos + import os - uos.VfsLfs1 - uos.VfsLfs2 + os.VfsLfs1 + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -150,5 +150,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, uos.VfsLfs1) -test(bdev, uos.VfsLfs2) +test(bdev, os.VfsLfs1) +test(bdev, os.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_corrupt.py b/tests/extmod/vfs_lfs_corrupt.py index 330458709a..c49dcad92b 100644 --- a/tests/extmod/vfs_lfs_corrupt.py +++ b/tests/extmod/vfs_lfs_corrupt.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, testing error handling from corrupt block device try: - import uos + import os - uos.VfsLfs1 - uos.VfsLfs2 + os.VfsLfs1 + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -108,5 +108,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, uos.VfsLfs1) -test(bdev, uos.VfsLfs2) +test(bdev, os.VfsLfs1) +test(bdev, os.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_error.py b/tests/extmod/vfs_lfs_error.py index 717284ea01..32b76b2821 100644 --- a/tests/extmod/vfs_lfs_error.py +++ b/tests/extmod/vfs_lfs_error.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, testing error handling try: - import uos + import os - uos.VfsLfs1 - uos.VfsLfs2 + os.VfsLfs1 + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -117,5 +117,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, uos.VfsLfs1) -test(bdev, uos.VfsLfs2) +test(bdev, os.VfsLfs1) +test(bdev, os.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_file.py b/tests/extmod/vfs_lfs_file.py index 774cca2964..b4a3e6b223 100644 --- a/tests/extmod/vfs_lfs_file.py +++ b/tests/extmod/vfs_lfs_file.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, file IO try: - import uos + import os - uos.VfsLfs1 - uos.VfsLfs2 + os.VfsLfs1 + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -117,5 +117,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, uos.VfsLfs1) -test(bdev, uos.VfsLfs2) +test(bdev, os.VfsLfs1) +test(bdev, os.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_ilistdir_del.py b/tests/extmod/vfs_lfs_ilistdir_del.py index 073576986d..ff66717147 100644 --- a/tests/extmod/vfs_lfs_ilistdir_del.py +++ b/tests/extmod/vfs_lfs_ilistdir_del.py @@ -2,9 +2,9 @@ import gc try: - import uos + import os - uos.VfsLfs2 + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -72,4 +72,4 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, uos.VfsLfs2) +test(bdev, os.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_mount.py b/tests/extmod/vfs_lfs_mount.py index bea8a2723a..4ebd9ac623 100644 --- a/tests/extmod/vfs_lfs_mount.py +++ b/tests/extmod/vfs_lfs_mount.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, with mount/umount try: - import uos + import os - uos.VfsLfs1 - uos.VfsLfs2 + os.VfsLfs1 + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -42,7 +42,7 @@ def test(vfs_class): # mount bdev unformatted try: - uos.mount(bdev, "/lfs") + os.mount(bdev, "/lfs") except Exception as er: print(repr(er)) @@ -53,7 +53,7 @@ def test(vfs_class): vfs = vfs_class(bdev) # mount - uos.mount(vfs, "/lfs") + os.mount(vfs, "/lfs") # import with open("/lfs/lfsmod.py", "w") as f: @@ -61,23 +61,23 @@ def test(vfs_class): import lfsmod # import package - uos.mkdir("/lfs/lfspkg") + os.mkdir("/lfs/lfspkg") with open("/lfs/lfspkg/__init__.py", "w") as f: f.write('print("package")\n') import lfspkg # chdir and import module from current directory (needs "" in sys.path) - uos.mkdir("/lfs/subdir") - uos.chdir("/lfs/subdir") - uos.rename("/lfs/lfsmod.py", "/lfs/subdir/lfsmod2.py") + os.mkdir("/lfs/subdir") + os.chdir("/lfs/subdir") + os.rename("/lfs/lfsmod.py", "/lfs/subdir/lfsmod2.py") import lfsmod2 # umount - uos.umount("/lfs") + os.umount("/lfs") # mount read-only vfs = vfs_class(bdev) - uos.mount(vfs, "/lfs", readonly=True) + os.mount(vfs, "/lfs", readonly=True) # test reading works with open("/lfs/subdir/lfsmod2.py") as f: @@ -90,25 +90,25 @@ def test(vfs_class): print(repr(er)) # umount - uos.umount("/lfs") + os.umount("/lfs") # mount bdev again - uos.mount(bdev, "/lfs") + os.mount(bdev, "/lfs") # umount - uos.umount("/lfs") + os.umount("/lfs") # clear imported modules - usys.modules.clear() + sys.modules.clear() # initialise path -import usys +import sys -usys.path.clear() -usys.path.append("/lfs") -usys.path.append("") +sys.path.clear() +sys.path.append("/lfs") +sys.path.append("") # run tests -test(uos.VfsLfs1) -test(uos.VfsLfs2) +test(os.VfsLfs1) +test(os.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_mtime.py b/tests/extmod/vfs_lfs_mtime.py index a67e48dd80..ade02fa144 100644 --- a/tests/extmod/vfs_lfs_mtime.py +++ b/tests/extmod/vfs_lfs_mtime.py @@ -1,11 +1,11 @@ # Test for VfsLfs using a RAM device, mtime feature try: - import utime, uos + import time, os - utime.time - utime.sleep - uos.VfsLfs2 + time.time + time.sleep + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -47,11 +47,11 @@ def test(bdev, vfs_class): vfs = vfs_class(bdev, mtime=True) # Create an empty file, should have a timestamp. - current_time = int(utime.time()) + current_time = int(time.time()) vfs.open("test1", "wt").close() # Wait 1 second so mtime will increase by at least 1. - utime.sleep(1) + time.sleep(1) # Create another empty file, should have a timestamp. vfs.open("test2", "wt").close() @@ -68,7 +68,7 @@ def test(bdev, vfs_class): print(stat1[8] < stat2[8]) # Wait 1 second so mtime will increase by at least 1. - utime.sleep(1) + time.sleep(1) # Open test1 for reading and ensure mtime did not change. vfs.open("test1", "rt").close() @@ -107,4 +107,4 @@ except MemoryError: print("SKIP") raise SystemExit -test(bdev, uos.VfsLfs2) +test(bdev, os.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_superblock.py b/tests/extmod/vfs_lfs_superblock.py index 1ac5675554..b8a8ec60b9 100644 --- a/tests/extmod/vfs_lfs_superblock.py +++ b/tests/extmod/vfs_lfs_superblock.py @@ -1,9 +1,9 @@ # Test for VfsLfs using a RAM device, when the first superblock does not exist try: - import uos + import os - uos.VfsLfs2 + os.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -36,12 +36,12 @@ lfs2_data = b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x bdev = RAMBlockDevice(64, lfs2_data) # Create the VFS explicitly, no auto-detection is needed for this. -vfs = uos.VfsLfs2(bdev) +vfs = os.VfsLfs2(bdev) print(list(vfs.ilistdir())) # Mount the block device directly; this relies on auto-detection. -uos.mount(bdev, "/userfs") -print(uos.listdir("/userfs")) +os.mount(bdev, "/userfs") +print(os.listdir("/userfs")) # Clean up. -uos.umount("/userfs") +os.umount("/userfs") diff --git a/tests/extmod/vfs_posix.py b/tests/extmod/vfs_posix.py index 3c23140065..05dc0f537e 100644 --- a/tests/extmod/vfs_posix.py +++ b/tests/extmod/vfs_posix.py @@ -2,9 +2,9 @@ try: import gc - import uos + import os - uos.VfsPosix + os.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -13,27 +13,29 @@ except (ImportError, AttributeError): # Skip the test if it does exist. temp_dir = "micropy_test_dir" try: - uos.stat(temp_dir) + import os + + os.stat(temp_dir) print("SKIP") raise SystemExit except OSError: pass # getcwd and chdir -curdir = uos.getcwd() -uos.chdir("/") -print(uos.getcwd()) -uos.chdir(curdir) -print(uos.getcwd() == curdir) +curdir = os.getcwd() +os.chdir("/") +print(os.getcwd()) +os.chdir(curdir) +print(os.getcwd() == curdir) # stat -print(type(uos.stat("/"))) +print(type(os.stat("/"))) # listdir and ilistdir -print(type(uos.listdir("/"))) +print(type(os.listdir("/"))) # mkdir -uos.mkdir(temp_dir) +os.mkdir(temp_dir) # file create f = open(temp_dir + "/test", "w") @@ -78,14 +80,14 @@ with open(nextfd, "w") as f: print("next_file_no <= base_file_no", next_file_no <= base_file_no) for n in names + [basefd, nextfd]: - uos.remove(n) + os.remove(n) # rename -uos.rename(temp_dir + "/test", temp_dir + "/test2") -print(uos.listdir(temp_dir)) +os.rename(temp_dir + "/test", temp_dir + "/test2") +print(os.listdir(temp_dir)) # construct new VfsPosix with path argument -vfs = uos.VfsPosix(temp_dir) +vfs = os.VfsPosix(temp_dir) print(list(i[0] for i in vfs.ilistdir("."))) # stat, statvfs (statvfs may not exist) @@ -98,21 +100,25 @@ print(type(list(vfs.ilistdir("."))[0][0])) print(type(list(vfs.ilistdir(b"."))[0][0])) # remove -uos.remove(temp_dir + "/test2") -print(uos.listdir(temp_dir)) +os.remove(temp_dir + "/test2") +print(os.listdir(temp_dir)) # remove with error try: - uos.remove(temp_dir + "/test2") + import os + + os.remove(temp_dir + "/test2") except OSError: print("remove OSError") # rmdir -uos.rmdir(temp_dir) -print(temp_dir in uos.listdir()) +os.rmdir(temp_dir) +print(temp_dir in os.listdir()) # rmdir with error try: - uos.rmdir(temp_dir) + import os + + os.rmdir(temp_dir) except OSError: print("rmdir OSError") diff --git a/tests/extmod/vfs_userfs.py b/tests/extmod/vfs_userfs.py index 570b833534..518373c70a 100644 --- a/tests/extmod/vfs_userfs.py +++ b/tests/extmod/vfs_userfs.py @@ -1,21 +1,21 @@ # test VFS functionality with a user-defined filesystem -# also tests parts of uio.IOBase implementation +# also tests parts of io.IOBase implementation -import usys +import sys try: - import uio + import io - uio.IOBase - import uos + io.IOBase + import os - uos.mount + os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit -class UserFile(uio.IOBase): +class UserFile(io.IOBase): def __init__(self, mode, data): assert isinstance(data, bytes) self.is_text = mode.find("b") == -1 @@ -69,16 +69,16 @@ user_files = { "/usermod1.py": b"print('in usermod1')\nimport usermod2", "/usermod2.py": b"print('in usermod2')", } -uos.mount(UserFS(user_files), "/userfs") +os.mount(UserFS(user_files), "/userfs") # open and read a file f = open("/userfs/data.txt") print(f.read()) # import files from the user filesystem -usys.path.append("/userfs") +sys.path.append("/userfs") import usermod1 # unmount and undo path addition -uos.umount("/userfs") -usys.path.pop() +os.umount("/userfs") +sys.path.pop() diff --git a/tests/extmod/websocket_basic.py b/tests/extmod/websocket_basic.py index dabdb76be1..133457784f 100644 --- a/tests/extmod/websocket_basic.py +++ b/tests/extmod/websocket_basic.py @@ -1,7 +1,7 @@ try: - import uio - import uerrno - import uwebsocket + import io + import errno + import websocket except ImportError: print("SKIP") raise SystemExit @@ -9,14 +9,14 @@ except ImportError: # put raw data in the stream and do a websocket read def ws_read(msg, sz): - ws = uwebsocket.websocket(uio.BytesIO(msg)) + ws = websocket.websocket(io.BytesIO(msg)) return ws.read(sz) # do a websocket write and then return the raw data from the stream def ws_write(msg, sz): - s = uio.BytesIO() - ws = uwebsocket.websocket(s) + s = io.BytesIO() + ws = websocket.websocket(s) ws.write(msg) s.seek(0) return s.read(sz) @@ -38,8 +38,8 @@ print(ws_write(b"pong" * 32, 132)) print(ws_read(b"\x81\x84maskmask", 4)) # close control frame -s = uio.BytesIO(b"\x88\x00") # FRAME_CLOSE -ws = uwebsocket.websocket(s) +s = io.BytesIO(b"\x88\x00") # FRAME_CLOSE +ws = websocket.websocket(s) print(ws.read(1)) s.seek(2) print(s.read(4)) @@ -49,15 +49,15 @@ print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG # close method -ws = uwebsocket.websocket(uio.BytesIO()) +ws = websocket.websocket(io.BytesIO()) ws.close() # ioctl -ws = uwebsocket.websocket(uio.BytesIO()) +ws = websocket.websocket(io.BytesIO()) print(ws.ioctl(8)) # GET_DATA_OPTS print(ws.ioctl(9, 2)) # SET_DATA_OPTS print(ws.ioctl(9)) try: ws.ioctl(-1) except OSError as e: - print("ioctl: EINVAL:", e.errno == uerrno.EINVAL) + print("ioctl: EINVAL:", e.errno == errno.EINVAL) diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/zlib_decompio.py similarity index 93% rename from tests/extmod/uzlib_decompio.py rename to tests/extmod/zlib_decompio.py index fae901aad0..9abbad43c6 100644 --- a/tests/extmod/uzlib_decompio.py +++ b/tests/extmod/zlib_decompio.py @@ -1,6 +1,6 @@ try: - import uzlib as zlib - import uio as io + import zlib + import io except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/uzlib_decompio.py.exp b/tests/extmod/zlib_decompio.py.exp similarity index 100% rename from tests/extmod/uzlib_decompio.py.exp rename to tests/extmod/zlib_decompio.py.exp diff --git a/tests/extmod/uzlib_decompio_gz.py b/tests/extmod/zlib_decompio_gz.py similarity index 97% rename from tests/extmod/uzlib_decompio_gz.py rename to tests/extmod/zlib_decompio_gz.py index 1bc8ba885b..1407459304 100644 --- a/tests/extmod/uzlib_decompio_gz.py +++ b/tests/extmod/zlib_decompio_gz.py @@ -1,6 +1,6 @@ try: - import uzlib as zlib - import uio as io + import zlib + import io except ImportError: print("SKIP") raise SystemExit diff --git a/tests/extmod/uzlib_decompio_gz.py.exp b/tests/extmod/zlib_decompio_gz.py.exp similarity index 100% rename from tests/extmod/uzlib_decompio_gz.py.exp rename to tests/extmod/zlib_decompio_gz.py.exp diff --git a/tests/extmod/uzlib_decompress.py b/tests/extmod/zlib_decompress.py similarity index 94% rename from tests/extmod/uzlib_decompress.py rename to tests/extmod/zlib_decompress.py index 8d4a9640b4..b72ee96ea8 100644 --- a/tests/extmod/uzlib_decompress.py +++ b/tests/extmod/zlib_decompress.py @@ -1,11 +1,8 @@ try: import zlib except ImportError: - try: - import uzlib as zlib - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit PATTERNS = [ # Packed results produced by CPy's zlib.compress() diff --git a/tests/feature_check/byteorder.py b/tests/feature_check/byteorder.py index 509bd8b1b5..c82a41a24b 100644 --- a/tests/feature_check/byteorder.py +++ b/tests/feature_check/byteorder.py @@ -1,6 +1,3 @@ -try: - import usys as sys -except ImportError: - import sys +import sys print(sys.byteorder) diff --git a/tests/feature_check/uio_module.py b/tests/feature_check/io_module.py similarity index 56% rename from tests/feature_check/uio_module.py rename to tests/feature_check/io_module.py index bad8d7c95b..9094e60531 100644 --- a/tests/feature_check/uio_module.py +++ b/tests/feature_check/io_module.py @@ -1,6 +1,6 @@ try: - import uio + import io - print("uio") + print("io") except ImportError: print("no") diff --git a/tests/feature_check/uio_module.py.exp b/tests/feature_check/io_module.py.exp similarity index 100% rename from tests/feature_check/uio_module.py.exp rename to tests/feature_check/io_module.py.exp diff --git a/tests/float/array_construct.py b/tests/float/array_construct.py index f6a3a9dc9d..6b5c996312 100644 --- a/tests/float/array_construct.py +++ b/tests/float/array_construct.py @@ -1,13 +1,10 @@ # test construction of array from array with float type try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(array("f", array("h", [1, 2]))) print(array("d", array("f", [1, 2]))) diff --git a/tests/float/bytearray_construct_endian.py b/tests/float/bytearray_construct_endian.py index 47f2b793c0..a971d706e2 100644 --- a/tests/float/bytearray_construct_endian.py +++ b/tests/float/bytearray_construct_endian.py @@ -1,12 +1,9 @@ # test construction of bytearray from array with float type try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(bytearray(array("f", [1, 2.5]))) diff --git a/tests/float/bytes_construct_endian.py b/tests/float/bytes_construct_endian.py index 4e15acc8bc..4dbcf390ea 100644 --- a/tests/float/bytes_construct_endian.py +++ b/tests/float/bytes_construct_endian.py @@ -1,12 +1,9 @@ # test construction of bytes from array with float type try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit print(bytes(array("f", [1, 2.5]))) diff --git a/tests/float/float2int_doubleprec_intbig.py b/tests/float/float2int_doubleprec_intbig.py index adc76d4aeb..402966cace 100644 --- a/tests/float/float2int_doubleprec_intbig.py +++ b/tests/float/float2int_doubleprec_intbig.py @@ -1,11 +1,7 @@ # check cases converting float to int, requiring double precision float -try: - import ustruct as struct - import usys as sys -except: - import struct - import sys +import struct +import sys maxsize_bits = 0 maxsize = sys.maxsize diff --git a/tests/float/float2int_fp30_intbig.py b/tests/float/float2int_fp30_intbig.py index 4e3c1fa217..1b22fe9646 100644 --- a/tests/float/float2int_fp30_intbig.py +++ b/tests/float/float2int_fp30_intbig.py @@ -1,11 +1,7 @@ # check cases converting float to int, relying only on single precision float -try: - import ustruct as struct - import usys as sys -except: - import struct - import sys +import struct +import sys maxsize_bits = 0 maxsize = sys.maxsize diff --git a/tests/float/float2int_intbig.py b/tests/float/float2int_intbig.py index 739f98f804..d047f247f2 100644 --- a/tests/float/float2int_intbig.py +++ b/tests/float/float2int_intbig.py @@ -1,11 +1,7 @@ # check cases converting float to int, relying only on single precision float -try: - import ustruct as struct - import usys as sys -except: - import struct - import sys +import struct +import sys maxsize_bits = 0 maxsize = sys.maxsize diff --git a/tests/float/float_array.py b/tests/float/float_array.py index 219b6b86ae..3d128da838 100644 --- a/tests/float/float_array.py +++ b/tests/float/float_array.py @@ -1,11 +1,8 @@ try: - from uarray import array + from array import array except ImportError: - try: - from array import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit def test(a): diff --git a/tests/float/float_struct.py b/tests/float/float_struct.py index 18893af0e0..47fe405018 100644 --- a/tests/float/float_struct.py +++ b/tests/float/float_struct.py @@ -1,9 +1,6 @@ # test struct package with floats try: - try: - import ustruct as struct - except: - import struct + import struct except ImportError: print("SKIP") raise SystemExit diff --git a/tests/import/builtin_ext.py b/tests/import/builtin_ext.py index dd8f95cbc1..87465f1d59 100644 --- a/tests/import/builtin_ext.py +++ b/tests/import/builtin_ext.py @@ -1,3 +1,4 @@ +# Verify that sys is a builtin. import sys print(sys, hasattr(sys, "__file__")) @@ -7,6 +8,8 @@ sys.path.append("ext") # All three should only get builtins, despite sys.py, usys.py, and # micropython.py being in the path. +# usys isn't extensible, but has a special-cased alias for backwards +# compatibility. import micropython print(micropython, hasattr(micropython, "__file__")) @@ -31,6 +34,7 @@ print(time, hasattr(time, "__file__"), time.sleep, time.extra) import uos print(uos, hasattr(uos, "__file__"), hasattr(uos, "extra")) + import utime print(utime, hasattr(utime, "__file__"), hasattr(utime, "extra")) diff --git a/tests/import/builtin_ext.py.exp b/tests/import/builtin_ext.py.exp index 08496e14b7..e09af2843a 100644 --- a/tests/import/builtin_ext.py.exp +++ b/tests/import/builtin_ext.py.exp @@ -6,5 +6,5 @@ os from filesystem True / 1 time from filesystem True 1 - False False - False False + False False + False False diff --git a/tests/import/ext/time.py b/tests/import/ext/time.py index 6f2d4a42c0..6b460b4235 100644 --- a/tests/import/ext/time.py +++ b/tests/import/ext/time.py @@ -4,11 +4,11 @@ print("time from filesystem") # import. import sys -_path = sys.path[:] -sys.path.clear() +_path = sys.path +sys.path = () from time import * -sys.path.extend(_path) +sys.path = _path del _path extra = 1 diff --git a/tests/inlineasm/asmfpldrstr.py b/tests/inlineasm/asmfpldrstr.py index 96cd0c23eb..c65f8a798b 100644 --- a/tests/inlineasm/asmfpldrstr.py +++ b/tests/inlineasm/asmfpldrstr.py @@ -1,4 +1,4 @@ -import uarray as array +import array @micropython.asm_thumb # test vldr, vstr diff --git a/tests/inlineasm/asmsum.py b/tests/inlineasm/asmsum.py index 208709a25f..51613ef6ac 100644 --- a/tests/inlineasm/asmsum.py +++ b/tests/inlineasm/asmsum.py @@ -46,7 +46,7 @@ def asm_sum_bytes(r0, r1): mov(r0, r2) -import uarray as array +import array b = array.array("l", (100, 200, 300, 400)) n = asm_sum_words(len(b), b) diff --git a/tests/internal_bench/var-8-namedtuple-1st.py b/tests/internal_bench/var-8-namedtuple-1st.py index 1a6daa6cdd..e3a2fa19cd 100644 --- a/tests/internal_bench/var-8-namedtuple-1st.py +++ b/tests/internal_bench/var-8-namedtuple-1st.py @@ -1,5 +1,5 @@ import bench -from ucollections import namedtuple +from collections import namedtuple T = namedtuple("Tup", ["num", "bar"]) diff --git a/tests/internal_bench/var-8.1-namedtuple-5th.py b/tests/internal_bench/var-8.1-namedtuple-5th.py index 568ece8067..3e52121746 100644 --- a/tests/internal_bench/var-8.1-namedtuple-5th.py +++ b/tests/internal_bench/var-8.1-namedtuple-5th.py @@ -1,5 +1,5 @@ import bench -from ucollections import namedtuple +from collections import namedtuple T = namedtuple("Tup", ["foo1", "foo2", "foo3", "foo4", "num"]) diff --git a/tests/io/argv.py b/tests/io/argv.py index 834292504d..53254da119 100644 --- a/tests/io/argv.py +++ b/tests/io/argv.py @@ -1,6 +1,3 @@ -try: - import usys as sys -except ImportError: - import sys +import sys print(sys.argv) diff --git a/tests/io/builtin_print_file.py b/tests/io/builtin_print_file.py index e5c20b64e4..822356a6cc 100644 --- a/tests/io/builtin_print_file.py +++ b/tests/io/builtin_print_file.py @@ -1,9 +1,6 @@ # test builtin print function, using file= argument -try: - import usys as sys -except ImportError: - import sys +import sys try: sys.stdout diff --git a/tests/io/file_stdio.py b/tests/io/file_stdio.py index 6c08f35d78..cbdb070163 100644 --- a/tests/io/file_stdio.py +++ b/tests/io/file_stdio.py @@ -1,7 +1,4 @@ -try: - import usys as sys -except ImportError: - import sys +import sys print(sys.stdin.fileno()) print(sys.stdout.fileno()) diff --git a/tests/io/open_append.py b/tests/io/open_append.py index 49cdd094b3..80a9422d81 100644 --- a/tests/io/open_append.py +++ b/tests/io/open_append.py @@ -1,7 +1,4 @@ -try: - import uos as os -except ImportError: - import os +import os if not hasattr(os, "remove"): print("SKIP") diff --git a/tests/io/open_plus.py b/tests/io/open_plus.py index 3cb2330eed..5199861a4e 100644 --- a/tests/io/open_plus.py +++ b/tests/io/open_plus.py @@ -1,7 +1,4 @@ -try: - import uos as os -except ImportError: - import os +import os if not hasattr(os, "remove"): print("SKIP") diff --git a/tests/micropython/builtin_execfile.py b/tests/micropython/builtin_execfile.py index 8a8ce79f78..5a26ccf0ad 100644 --- a/tests/micropython/builtin_execfile.py +++ b/tests/micropython/builtin_execfile.py @@ -1,17 +1,17 @@ # Test builtin execfile function using VFS. try: - import uio, uos + import io, os execfile - uio.IOBase - uos.mount + io.IOBase + os.mount except (ImportError, NameError, AttributeError): print("SKIP") raise SystemExit -class File(uio.IOBase): +class File(io.IOBase): def __init__(self, data): self.data = data self.off = 0 @@ -44,21 +44,25 @@ class Filesystem: # First umount any existing mount points the target may have. try: - uos.umount("/") + import io, os + + os.umount("/") except OSError: pass -for path in uos.listdir("/"): - uos.umount("/" + path) +for path in os.listdir("/"): + os.umount("/" + path) # Create and mount the VFS object. files = { "/test.py": "print(123)", } fs = Filesystem(files) -uos.mount(fs, "/test_mnt") +os.mount(fs, "/test_mnt") # Test execfile with a file that doesn't exist. try: + import io, os + execfile("/test_mnt/noexist.py") except OSError: print("OSError") @@ -67,4 +71,4 @@ except OSError: execfile("/test_mnt/test.py") # Unmount the VFS object. -uos.umount(fs) +os.umount(fs) diff --git a/tests/micropython/emg_exc.py b/tests/micropython/emg_exc.py index b8df94b071..9a09956c86 100644 --- a/tests/micropython/emg_exc.py +++ b/tests/micropython/emg_exc.py @@ -1,10 +1,10 @@ # test that emergency exceptions work import micropython -import usys +import sys try: - import uio + import io except ImportError: print("SKIP") raise SystemExit @@ -25,8 +25,8 @@ def f(): micropython.heap_unlock() # print the exception - buf = uio.StringIO() - usys.print_exception(exc, buf) + buf = io.StringIO() + sys.print_exception(exc, buf) for l in buf.getvalue().split("\n"): if l.startswith(" File "): print(l.split('"')[2]) diff --git a/tests/micropython/heapalloc_bytesio.py b/tests/micropython/heapalloc_bytesio.py index 4aae2abf06..0ac8c92555 100644 --- a/tests/micropython/heapalloc_bytesio.py +++ b/tests/micropython/heapalloc_bytesio.py @@ -1,5 +1,5 @@ try: - import uio + import io except ImportError: print("SKIP") raise SystemExit @@ -7,7 +7,7 @@ except ImportError: import micropython data = b"1234" * 16 -buf = uio.BytesIO(64) +buf = io.BytesIO(64) micropython.heap_lock() diff --git a/tests/micropython/heapalloc_bytesio2.py b/tests/micropython/heapalloc_bytesio2.py index 3b9f141270..05c384a516 100644 --- a/tests/micropython/heapalloc_bytesio2.py +++ b/tests/micropython/heapalloc_bytesio2.py @@ -1,7 +1,7 @@ # Creating BytesIO from immutable object should not immediately # copy its content. try: - import uio + import io import micropython micropython.mem_total @@ -14,7 +14,7 @@ data = b"1234" * 256 before = micropython.mem_total() -buf = uio.BytesIO(data) +buf = io.BytesIO(data) after = micropython.mem_total() diff --git a/tests/micropython/heapalloc_iter.py b/tests/micropython/heapalloc_iter.py index 18f5322ee1..bd1ba4db79 100644 --- a/tests/micropython/heapalloc_iter.py +++ b/tests/micropython/heapalloc_iter.py @@ -5,13 +5,10 @@ except NameError: print("SKIP") raise SystemExit try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: from micropython import heap_lock, heap_unlock diff --git a/tests/micropython/heapalloc_traceback.py b/tests/micropython/heapalloc_traceback.py index 09a2ad2c14..4c5f99afee 100644 --- a/tests/micropython/heapalloc_traceback.py +++ b/tests/micropython/heapalloc_traceback.py @@ -1,10 +1,10 @@ # test that we can generate a traceback without allocating import micropython -import usys +import sys try: - import uio + import io except ImportError: print("SKIP") raise SystemExit @@ -32,8 +32,8 @@ def test(): test() # print the exception that was raised -buf = uio.StringIO() -usys.print_exception(global_exc, buf) +buf = io.StringIO() +sys.print_exception(global_exc, buf) for l in buf.getvalue().split("\n"): # uPy on pyboard prints as file, so remove filename. if l.startswith(" File "): diff --git a/tests/micropython/import_mpy_invalid.py b/tests/micropython/import_mpy_invalid.py index b02312a7a8..36db102e9d 100644 --- a/tests/micropython/import_mpy_invalid.py +++ b/tests/micropython/import_mpy_invalid.py @@ -1,16 +1,16 @@ # test importing of invalid .mpy files try: - import usys, uio, uos + import sys, io, os - uio.IOBase - uos.mount + io.IOBase + os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit -class UserFile(uio.IOBase): +class UserFile(io.IOBase): def __init__(self, data): self.data = memoryview(data) self.pos = 0 @@ -52,8 +52,8 @@ user_files = { } # create and mount a user filesystem -uos.mount(UserFS(user_files), "/userfs") -usys.path.append("/userfs") +os.mount(UserFS(user_files), "/userfs") +sys.path.append("/userfs") # import .mpy files from the user filesystem for i in range(len(user_files)): @@ -64,5 +64,5 @@ for i in range(len(user_files)): print(mod, "ValueError", er) # unmount and undo path addition -uos.umount("/userfs") -usys.path.pop() +os.umount("/userfs") +sys.path.pop() diff --git a/tests/micropython/import_mpy_native.py b/tests/micropython/import_mpy_native.py index 73e20694cc..da20746b22 100644 --- a/tests/micropython/import_mpy_native.py +++ b/tests/micropython/import_mpy_native.py @@ -1,23 +1,23 @@ # test importing of .mpy files with native code try: - import usys, uio, uos + import sys, io, os - usys.implementation._mpy - uio.IOBase - uos.mount + sys.implementation._mpy + io.IOBase + os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit -mpy_arch = usys.implementation._mpy >> 8 +mpy_arch = sys.implementation._mpy >> 8 if mpy_arch >> 2 == 0: # This system does not support .mpy files containing native code print("SKIP") raise SystemExit -class UserFile(uio.IOBase): +class UserFile(io.IOBase): def __init__(self, data): self.data = memoryview(data) self.pos = 0 @@ -110,8 +110,8 @@ user_files = { # fmt: on # create and mount a user filesystem -uos.mount(UserFS(user_files), "/userfs") -usys.path.append("/userfs") +os.mount(UserFS(user_files), "/userfs") +sys.path.append("/userfs") # import .mpy files from the user filesystem for i in range(len(user_files)): @@ -123,5 +123,5 @@ for i in range(len(user_files)): print(mod, "ValueError", er) # unmount and undo path addition -uos.umount("/userfs") -usys.path.pop() +os.umount("/userfs") +sys.path.pop() diff --git a/tests/micropython/import_mpy_native_gc.py b/tests/micropython/import_mpy_native_gc.py index e18720fb31..5a3855dc7d 100644 --- a/tests/micropython/import_mpy_native_gc.py +++ b/tests/micropython/import_mpy_native_gc.py @@ -1,17 +1,17 @@ # Test that native code loaded from a .mpy file is retained after a GC. try: - import gc, sys, uio, uos + import gc, sys, io, os sys.implementation._mpy - uio.IOBase - uos.mount + io.IOBase + os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit -class UserFile(uio.IOBase): +class UserFile(io.IOBase): def __init__(self, data): self.data = memoryview(data) self.pos = 0 @@ -68,7 +68,7 @@ if sys_implementation_mpy not in features0_file_contents: user_files = {"/features0.mpy": features0_file_contents[sys_implementation_mpy]} # Create and mount a user filesystem. -uos.mount(UserFS(user_files), "/userfs") +os.mount(UserFS(user_files), "/userfs") sys.path.append("/userfs") # Import the native function. @@ -89,5 +89,5 @@ for i in range(1000): print(factorial(10)) # Unmount and undo path addition. -uos.umount("/userfs") +os.umount("/userfs") sys.path.pop() diff --git a/tests/micropython/opt_level_lineno.py b/tests/micropython/opt_level_lineno.py index 1cbf2fb1a8..d8253e54b4 100644 --- a/tests/micropython/opt_level_lineno.py +++ b/tests/micropython/opt_level_lineno.py @@ -3,4 +3,4 @@ import micropython as micropython # check that level 3 doesn't store line numbers # the expected output is that any line is printed as "line 1" micropython.opt_level(3) -exec("try:\n xyz\nexcept NameError as er:\n import usys\n usys.print_exception(er)") +exec("try:\n xyz\nexcept NameError as er:\n import sys\n sys.print_exception(er)") diff --git a/tests/micropython/viper_misc_intbig.py b/tests/micropython/viper_misc_intbig.py index ac09f57857..91673f2c10 100644 --- a/tests/micropython/viper_misc_intbig.py +++ b/tests/micropython/viper_misc_intbig.py @@ -7,6 +7,6 @@ def viper_uint() -> uint: return uint(-1) -import usys +import sys -print(viper_uint() == (usys.maxsize << 1 | 1)) +print(viper_uint() == (sys.maxsize << 1 | 1)) diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py index cc63185b5d..da90f90ac3 100644 --- a/tests/misc/non_compliant.py +++ b/tests/misc/non_compliant.py @@ -1,8 +1,8 @@ # tests for things that are not implemented, or have non-compliant behaviour try: - import uarray as array - import ustruct + import array + import struct except ImportError: print("SKIP") raise SystemExit @@ -106,10 +106,10 @@ except NotImplementedError: print("NotImplementedError") # struct pack with too many args, not checked by uPy -print(ustruct.pack("bb", 1, 2, 3)) +print(struct.pack("bb", 1, 2, 3)) # struct pack with too few args, not checked by uPy -print(ustruct.pack("bb", 1)) +print(struct.pack("bb", 1)) # array slice assignment with unsupported RHS try: diff --git a/tests/misc/print_exception.py b/tests/misc/print_exception.py index 06f4023349..1d196d6ab1 100644 --- a/tests/misc/print_exception.py +++ b/tests/misc/print_exception.py @@ -1,10 +1,6 @@ try: - try: - import uio as io - import usys as sys - except ImportError: - import io - import sys + import io + import sys except ImportError: print("SKIP") raise SystemExit diff --git a/tests/misc/sys_atexit.py b/tests/misc/sys_atexit.py index 141b24cc9f..e9c5693f97 100644 --- a/tests/misc/sys_atexit.py +++ b/tests/misc/sys_atexit.py @@ -1,9 +1,9 @@ # test sys.atexit() function -import usys +import sys try: - usys.atexit + sys.atexit except AttributeError: print("SKIP") raise SystemExit @@ -15,7 +15,7 @@ def do_at_exit(): print("done at exit:", some_var) -usys.atexit(do_at_exit) +sys.atexit(do_at_exit) some_var = "ok" print("done before exit") diff --git a/tests/misc/sys_exc_info.py b/tests/misc/sys_exc_info.py index 3a8c4a6c8d..d7e8a2d943 100644 --- a/tests/misc/sys_exc_info.py +++ b/tests/misc/sys_exc_info.py @@ -1,7 +1,4 @@ -try: - import usys as sys -except ImportError: - import sys +import sys try: sys.exc_info diff --git a/tests/multi_net/ssl_cert_rsa.py b/tests/multi_net/ssl_cert_rsa.py index 7c718ee40a..872855edba 100644 --- a/tests/multi_net/ssl_cert_rsa.py +++ b/tests/multi_net/ssl_cert_rsa.py @@ -2,7 +2,7 @@ # This test won't run under CPython because CPython doesn't have key/cert try: - import ubinascii as binascii, usocket as socket, ussl as ssl + import binascii, socket, ssl except ImportError: print("SKIP") raise SystemExit diff --git a/tests/multi_net/ssl_data.py b/tests/multi_net/ssl_data.py index aef85b83ab..a21c8c6589 100644 --- a/tests/multi_net/ssl_data.py +++ b/tests/multi_net/ssl_data.py @@ -2,7 +2,7 @@ # This test won't run under CPython because it requires key/cert try: - import ubinascii as binascii, usocket as socket, ussl as ssl + import binascii, socket, ssl except ImportError: print("SKIP") raise SystemExit diff --git a/tests/multi_net/uasyncio_tcp_readinto.py b/tests/multi_net/uasyncio_tcp_readinto.py index 631997652a..647c06b8aa 100644 --- a/tests/multi_net/uasyncio_tcp_readinto.py +++ b/tests/multi_net/uasyncio_tcp_readinto.py @@ -10,13 +10,10 @@ except ImportError: raise SystemExit try: - import uarray as array + import array except ImportError: - try: - import array - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit PORT = 8000 diff --git a/tests/net_hosted/accept_nonblock.py b/tests/net_hosted/accept_nonblock.py index d17e287498..30d2033e65 100644 --- a/tests/net_hosted/accept_nonblock.py +++ b/tests/net_hosted/accept_nonblock.py @@ -1,9 +1,6 @@ # test that socket.accept() on a non-blocking socket raises EAGAIN -try: - import usocket as socket -except: - import socket +import socket s = socket.socket() s.bind(socket.getaddrinfo("127.0.0.1", 8123)[0][-1]) diff --git a/tests/net_hosted/accept_timeout.py b/tests/net_hosted/accept_timeout.py index 734fe217ca..865d2aad26 100644 --- a/tests/net_hosted/accept_timeout.py +++ b/tests/net_hosted/accept_timeout.py @@ -1,9 +1,6 @@ # test that socket.accept() on a socket with timeout raises ETIMEDOUT -try: - import uerrno as errno, usocket as socket -except: - import errno, socket +import errno, socket try: socket.socket.settimeout diff --git a/tests/net_hosted/connect_nonblock.py b/tests/net_hosted/connect_nonblock.py index 4b8055c161..781f1a4ee2 100644 --- a/tests/net_hosted/connect_nonblock.py +++ b/tests/net_hosted/connect_nonblock.py @@ -1,10 +1,6 @@ # test that socket.connect() on a non-blocking socket raises EINPROGRESS -try: - import usocket as socket - import uerrno as errno -except: - import socket, errno +import socket, errno def test(peer_addr): diff --git a/tests/net_hosted/connect_nonblock_xfer.py b/tests/net_hosted/connect_nonblock_xfer.py index 1a0b242276..e669a5766c 100644 --- a/tests/net_hosted/connect_nonblock_xfer.py +++ b/tests/net_hosted/connect_nonblock_xfer.py @@ -1,11 +1,8 @@ # test that socket.connect() on a non-blocking socket raises EINPROGRESS # and that an immediate write/send/read/recv does the right thing -try: - import sys, time - import uerrno as errno, usocket as socket, ussl as ssl -except: - import socket, errno, ssl +import sys, time, socket, errno, ssl + isMP = sys.implementation.name == "micropython" diff --git a/tests/net_hosted/connect_poll.py b/tests/net_hosted/connect_poll.py index b2739e36e9..a3232bd334 100644 --- a/tests/net_hosted/connect_poll.py +++ b/tests/net_hosted/connect_poll.py @@ -1,9 +1,6 @@ # test that socket.connect() has correct polling behaviour before, during and after -try: - import usocket as socket, uselect as select -except: - import socket, select +import socket, select def test(peer_addr): diff --git a/tests/net_hosted/ssl_getpeercert.py b/tests/net_hosted/ssl_getpeercert.py index dee5fcfd89..0df895a654 100644 --- a/tests/net_hosted/ssl_getpeercert.py +++ b/tests/net_hosted/ssl_getpeercert.py @@ -1,11 +1,7 @@ # test ssl.getpeercert() method -try: - import usocket as socket - import ussl as ssl -except: - import socket - import ssl +import socket +import ssl def test(peer_addr): diff --git a/tests/net_inet/getaddrinfo.py b/tests/net_inet/getaddrinfo.py index 765723ae73..e26060ad21 100644 --- a/tests/net_inet/getaddrinfo.py +++ b/tests/net_inet/getaddrinfo.py @@ -1,7 +1,4 @@ -try: - import usocket as socket, sys -except: - import socket, sys +import socket, sys def test_non_existent(): diff --git a/tests/net_inet/ssl_cert.py b/tests/net_inet/ssl_cert.py index d2d437e381..d6e0aec889 100644 --- a/tests/net_inet/ssl_cert.py +++ b/tests/net_inet/ssl_cert.py @@ -1,6 +1,6 @@ -import ubinascii as binascii -import usocket as socket -import ussl as ssl +import binascii +import socket +import ssl # This certificate was obtained from micropython.org using openssl: diff --git a/tests/net_inet/ssl_errors.py b/tests/net_inet/ssl_errors.py index ece1f6e253..65f3637e9e 100644 --- a/tests/net_inet/ssl_errors.py +++ b/tests/net_inet/ssl_errors.py @@ -1,12 +1,7 @@ # test that socket.connect() on a non-blocking socket raises EINPROGRESS # and that an immediate write/send/read/recv does the right thing -import sys - -try: - import uerrno as errno, usocket as socket, ussl as ssl -except: - import errno, socket, ssl +import sys, errno, socket, ssl def test(addr, hostname, block=True): diff --git a/tests/net_inet/test_tls_nonblock.py b/tests/net_inet/test_tls_nonblock.py index b4f2ef4ed2..6378280a71 100644 --- a/tests/net_inet/test_tls_nonblock.py +++ b/tests/net_inet/test_tls_nonblock.py @@ -1,7 +1,4 @@ -try: - import usocket as socket, ussl as ssl, uerrno as errno, sys -except: - import socket, ssl, errno, sys, time, select +import socket, ssl, errno, sys, time, select def test_one(site, opts): diff --git a/tests/net_inet/test_tls_sites.py b/tests/net_inet/test_tls_sites.py index fabe4b43c9..f9a3dc86d2 100644 --- a/tests/net_inet/test_tls_sites.py +++ b/tests/net_inet/test_tls_sites.py @@ -1,21 +1,16 @@ -try: - import usocket as _socket -except: - import _socket -try: - import ussl as ssl -except: - import ssl +import socket +import ssl - # CPython only supports server_hostname with SSLContext +# CPython only supports server_hostname with SSLContext +if hasattr(ssl, "SSLContext"): ssl = ssl.SSLContext() def test_one(site, opts): - ai = _socket.getaddrinfo(site, 443) + ai = socket.getaddrinfo(site, 443) addr = ai[0][-1] - s = _socket.socket() + s = socket.socket() try: s.connect(addr) diff --git a/tests/net_inet/tls_num_errors.py b/tests/net_inet/tls_num_errors.py index dd7f714e6e..34aa2bb455 100644 --- a/tests/net_inet/tls_num_errors.py +++ b/tests/net_inet/tls_num_errors.py @@ -1,9 +1,7 @@ # test that modtls produces a numerical error message when out of heap -try: - import usocket as socket, ussl as ssl, sys -except: - import socket, ssl, sys +import socket, ssl, sys + try: from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock except: diff --git a/tests/net_inet/tls_text_errors.py b/tests/net_inet/tls_text_errors.py index 9e8ccfaf9e..498593bba2 100644 --- a/tests/net_inet/tls_text_errors.py +++ b/tests/net_inet/tls_text_errors.py @@ -1,9 +1,6 @@ # test that modtls produces a text error message -try: - import usocket as socket, ussl as ssl, sys -except: - import socket, ssl, sys +import socket, ssl, sys def test(addr): diff --git a/tests/perf_bench/benchrun.py b/tests/perf_bench/benchrun.py index ed43297d15..4029c8ac8a 100644 --- a/tests/perf_bench/benchrun.py +++ b/tests/perf_bench/benchrun.py @@ -1,10 +1,10 @@ def bm_run(N, M): try: - from utime import ticks_us, ticks_diff + from time import ticks_us, ticks_diff except ImportError: - import time + from time import perf_counter - ticks_us = lambda: int(time.perf_counter() * 1000000) + ticks_us = lambda: int(perf_counter() * 1000000) ticks_diff = lambda a, b: a - b # Pick sensible parameters given N, M diff --git a/tests/perf_bench/bm_hexiom.py b/tests/perf_bench/bm_hexiom.py index 84eda9a909..e36fc234cd 100644 --- a/tests/perf_bench/bm_hexiom.py +++ b/tests/perf_bench/bm_hexiom.py @@ -632,10 +632,7 @@ bm_params = { def bm_setup(params): - try: - import uio as io - except ImportError: - import io + import io loops, level, order, strategy = params diff --git a/tests/perf_bench/core_import_mpy_multi.py b/tests/perf_bench/core_import_mpy_multi.py index 99c4721d29..ce68306678 100644 --- a/tests/perf_bench/core_import_mpy_multi.py +++ b/tests/perf_bench/core_import_mpy_multi.py @@ -1,8 +1,8 @@ # Test performance of importing an .mpy file many times. -import usys, uio, uos +import sys, io, os -if not (hasattr(uio, "IOBase") and hasattr(uos, "mount")): +if not (hasattr(io, "IOBase") and hasattr(os, "mount")): print("SKIP") raise SystemExit @@ -26,7 +26,7 @@ result = 123 file_data = b'M\x06\x00\x1f\x14\x03\x0etest.py\x00\x0f\x02A\x00\x02f\x00\x0cresult\x00/-5#\x82I\x81{\x81w\x82/\x81\x05\x81\x17Iom\x82\x13\x06arg\x00\x05\x1cthis will be a string object\x00\x06\x1bthis will be a bytes object\x00\n\x07\x05\x0bconst tuple\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\x81\\\x10\n\x01\x89\x07d`T2\x00\x10\x024\x02\x16\x022\x01\x16\x03"\x80{\x16\x04Qc\x02\x81d\x00\x08\x02(DD\x11\x05\x16\x06\x10\x02\x16\x072\x00\x16\x082\x01\x16\t2\x02\x16\nQc\x03`\x1a\x08\x08\x12\x13@\xb1\xb0\x18\x13Qc@\t\x08\t\x12` Qc@\t\x08\n\x12``Qc\x82@ \x0e\x03\x80\x08+)##\x12\x0b\x12\x0c\x12\r\x12\x0e*\x04Y\x12\x0f\x12\x10\x12\x11*\x03Y#\x00\xc0#\x01\xc0#\x02\xc0Qc' -class File(uio.IOBase): +class File(io.IOBase): def __init__(self): self.off = 0 @@ -57,14 +57,14 @@ class FS: def mount(): - uos.mount(FS(), "/__remote") - uos.chdir("/__remote") + os.mount(FS(), "/__remote") + os.chdir("/__remote") def test(r): global result for _ in r: - usys.modules.clear() + sys.modules.clear() module = __import__("__injected") result = module.result diff --git a/tests/perf_bench/core_import_mpy_single.py b/tests/perf_bench/core_import_mpy_single.py index af3f4a29b2..1b411fc3fb 100644 --- a/tests/perf_bench/core_import_mpy_single.py +++ b/tests/perf_bench/core_import_mpy_single.py @@ -2,9 +2,9 @@ # The first import of a module will intern strings that don't already exist, and # this test should be representative of what happens in a real application. -import uio, uos +import io, os -if not (hasattr(uio, "IOBase") and hasattr(uos, "mount")): +if not (hasattr(io, "IOBase") and hasattr(os, "mount")): print("SKIP") raise SystemExit @@ -81,7 +81,7 @@ result = 123 file_data = b"M\x06\x00\x1f\x81=\x1e\x0etest.py\x00\x0f\x04A0\x00\x04A1\x00\x04f0\x00\x04f1\x00\x0cresult\x00/-5\x04a0\x00\x04a1\x00\x04a2\x00\x04a3\x00\x13\x15\x17\x19\x1b\x1d\x1f!#%')+1379;=?ACEGIKMOQSUWY[]_acegikmoqsuwy{}\x7f\x81\x01\x81\x03\x81\x05\x81\x07\x81\t\x81\x0b\x81\r\x81\x0f\x81\x11\x81\x13\x81\x15\x81\x17\x81\x19\x81\x1b\x81\x1d\x81\x1f\x81!\x81#\x81%\x81'\x81)\x81+\x81-\x81/\x811\x813\x815\x817\x819\x81;\x81=\x81?\x81A\x81C\x81E\x81G\x81I\x81K\x81M\x81O\x81Q\x81S\x81U\x81W\x81Y\x81[\x81]\x81_\x81a\x81c\x81e\x81g\x81i\x81k\x81m\x81o\x81q\x81s\x81u\x81w\x81y\x81{\x81}\x81\x7f\x82\x01\x82\x03\x82\x05\x82\x07\x82\t\x82\x0b\x82\r\x82\x0f\x82\x11\x82\x13\x82\x15\x82\x17\x82\x19\x82\x1b\x82\x1d\x82\x1f\x82!\x82#\x82%\x82'\x82)\x82+\x82-\x82/\x821\x823\x825\x827\x829\x82;\x82=\x82?\x82A\x82E\x82G\x82I\x82K\nname0\x00\nname1\x00\nname2\x00\nname3\x00\nname4\x00\nname5\x00\nname6\x00\nname7\x00\nname8\x00\nname9\x00$quite_a_long_name0\x00$quite_a_long_name1\x00$quite_a_long_name2\x00$quite_a_long_name3\x00$quite_a_long_name4\x00$quite_a_long_name5\x00$quite_a_long_name6\x00$quite_a_long_name7\x00$quite_a_long_name8\x00$quite_a_long_name9\x00&quite_a_long_name10\x00&quite_a_long_name11\x00\x05\x1ethis will be a string object 0\x00\x05\x1ethis will be a string object 1\x00\x05\x1ethis will be a string object 2\x00\x05\x1ethis will be a string object 3\x00\x05\x1ethis will be a string object 4\x00\x05\x1ethis will be a string object 5\x00\x05\x1ethis will be a string object 6\x00\x05\x1ethis will be a string object 7\x00\x05\x1ethis will be a string object 8\x00\x05\x1ethis will be a string object 9\x00\x06\x1dthis will be a bytes object 0\x00\x06\x1dthis will be a bytes object 1\x00\x06\x1dthis will be a bytes object 2\x00\x06\x1dthis will be a bytes object 3\x00\x06\x1dthis will be a bytes object 4\x00\x06\x1dthis will be a bytes object 5\x00\x06\x1dthis will be a bytes object 6\x00\x06\x1dthis will be a bytes object 7\x00\x06\x1dthis will be a bytes object 8\x00\x06\x1dthis will be a bytes object 9\x00\n\x07\x05\rconst tuple 0\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 1\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 2\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 3\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 4\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 5\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 6\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 7\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 8\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\n\x07\x05\rconst tuple 9\x00\x01\x02\x03\x07\x011\x07\x012\x07\x013\x82d\x10\x12\x01i@i@\x84\x18\x84\x1fT2\x00\x10\x024\x02\x16\x02T2\x01\x10\x034\x02\x16\x032\x02\x16\x042\x03\x16\x05\"\x80{\x16\x06Qc\x04\x82\x0c\x00\n\x02($$$\x11\x07\x16\x08\x10\x02\x16\t2\x00\x16\n2\x01\x16\x0b2\x02\x16\x0c2\x03\x16\rQc\x04@\t\x08\n\x81\x0b Qc@\t\x08\x0b\x81\x0b@Qc@\t\x08\x0c\x81\x0b`QcH\t\n\r\x81\x0b` Qc\x82\x14\x00\x0c\x03h`$$$\x11\x07\x16\x08\x10\x03\x16\t2\x00\x16\n2\x01\x16\x0b2\x02\x16\x0c2\x03\x16\rQc\x04H\t\n\n\x81\x0b``QcH\t\n\x0b\x81\x0b\x80\x07QcH\t\n\x0c\x81\x0b\x80\x08QcH\t\n\r\x81\x0b\x80\tQc\xa08P:\x04\x80\x0b13///---997799<\x1f%\x1f\"\x1f%)\x1f\"//\x12\x0e\x12\x0f\x12\x10\x12\x11\x12\x12\x12\x13\x12\x14*\x07Y\x12\x15\x12\x16\x12\x17\x12\x18\x12\x19\x12\x1a\x12\x08\x12\x07*\x08Y\x12\x1b\x12\x1c\x12\t\x12\x1d\x12\x1e\x12\x1f*\x06Y\x12 \x12!\x12\"\x12#\x12$\x12%*\x06Y\x12&\x12'\x12(\x12)\x12*\x12+*\x06Y\x12,\x12-\x12.\x12/\x120*\x05Y\x121\x122\x123\x124\x125*\x05Y\x126\x127\x128\x129\x12:*\x05Y\x12;\x12<\x12=\x12>\x12?\x12@\x12A\x12B\x12C\x12D\x12E*\x0bY\x12F\x12G\x12H\x12I\x12J\x12K\x12L\x12M\x12N\x12O\x12P*\x0bY\x12Q\x12R\x12S\x12T\x12U\x12V\x12W\x12X\x12Y\x12Z*\nY\x12[\x12\\\x12]\x12^\x12_\x12`\x12a\x12b\x12c\x12d*\nY\x12e\x12f\x12g\x12h\x12i\x12j\x12k\x12l\x12m\x12n\x12o*\x0bY\x12p\x12q\x12r\x12s\x12t\x12u\x12v\x12w\x12x\x12y\x12z*\x0bY\x12{\x12|\x12}\x12~\x12\x7f\x12\x81\x00\x12\x81\x01\x12\x81\x02\x12\x81\x03\x12\x81\x04*\nY\x12\x81\x05\x12\x81\x06\x12\x81\x07\x12\x81\x08\x12\x81\t\x12\x81\n\x12\x81\x0b\x12\x81\x0c\x12\x81\r\x12\x81\x0e\x12\x81\x0f*\x0bY\x12\x81\x10\x12\x81\x11\x12\x81\x12\x12\x81\x13\x12\x81\x14\x12\x81\x15\x12\x81\x16\x12\x81\x17\x12\x81\x18\x12\x81\x19*\nY\x12\x81\x1a\x12\x81\x1b\x12\x81\x1c\x12\x81\x1d\x12\x81\x1e\x12\x81\x1f\x12\x81 \x12\x81!\x12\x81\"\x12\x81#\x12\x81$*\x0bY\x12\x81%\x12\x81&*\x02Y\x12\x81'\x12\x81(\x12\x81)\x12\x81*\x12\x81+\x12\x81,\x12\x81-\x12\x81.\x12\x81/\x12\x810*\nY\x12\x811\x12\x812\x12\x813\x12\x814*\x04Y\x12\x815\x12\x816\x12\x817\x12\x818*\x04Y\x12\x819\x12\x81:\x12\x81;\x12\x81<*\x04YQc\x87p\x08@\x05\x80###############################\x00\xc0#\x01\xc0#\x02\xc0#\x03\xc0#\x04\xc0#\x05\xc0#\x06\xc0#\x07\xc0#\x08\xc0#\t\xc0#\n\xc0#\x0b\xc0#\x0c\xc0#\r\xc0#\x0e\xc0#\x0f\xc0#\x10\xc0#\x11\xc0#\x12\xc0#\x13\xc0#\x14\xc0#\x15\xc0#\x16\xc0#\x17\xc0#\x18\xc0#\x19\xc0#\x1a\xc0#\x1b\xc0#\x1c\xc0#\x1d\xc0Qc" -class File(uio.IOBase): +class File(io.IOBase): def __init__(self): self.off = 0 @@ -112,8 +112,8 @@ class FS: def mount(): - uos.mount(FS(), "/__remote") - uos.chdir("/__remote") + os.mount(FS(), "/__remote") + os.chdir("/__remote") def test(): diff --git a/tests/renesas-ra/freq.py b/tests/renesas-ra/freq.py index 6ce1871f8c..97fe946b72 100644 --- a/tests/renesas-ra/freq.py +++ b/tests/renesas-ra/freq.py @@ -20,7 +20,7 @@ import os try: import machine -except: +except ImportError: print("machine module is not found") raise SystemExit diff --git a/tests/run-natmodtests.py b/tests/run-natmodtests.py index 16bb469222..9fe970a6d0 100755 --- a/tests/run-natmodtests.py +++ b/tests/run-natmodtests.py @@ -22,16 +22,16 @@ NATMOD_EXAMPLE_DIR = "../examples/natmod/" TEST_MAPPINGS = { "btree": "btree/btree_$(ARCH).mpy", "framebuf": "framebuf/framebuf_$(ARCH).mpy", - "uheapq": "uheapq/uheapq_$(ARCH).mpy", - "urandom": "urandom/urandom_$(ARCH).mpy", - "ure": "ure/ure_$(ARCH).mpy", - "uzlib": "uzlib/uzlib_$(ARCH).mpy", + "heapq": "heapq/heapq_$(ARCH).mpy", + "random": "random/random_$(ARCH).mpy", + "re": "re/re_$(ARCH).mpy", + "zlib": "zlib/zlib_$(ARCH).mpy", } # Code to allow a target MicroPython to import an .mpy from RAM injected_import_hook_code = """\ -import usys, uos, uio -class __File(uio.IOBase): +import sys, os, io +class __File(io.IOBase): def __init__(self): self.off = 0 def ioctl(self, request, arg): @@ -52,9 +52,9 @@ class __FS: raise OSError(-2) # ENOENT def open(self, path, mode): return __File() -uos.mount(__FS(), '/__remote') -uos.chdir('/__remote') -usys.modules['{}'] = __import__('__injected') +os.mount(__FS(), '/__remote') +os.chdir('/__remote') +sys.modules['{}'] = __import__('__injected') """ diff --git a/tests/run-tests-exp.py b/tests/run-tests-exp.py index 21b6645336..bbb057f4ce 100644 --- a/tests/run-tests-exp.py +++ b/tests/run-tests-exp.py @@ -5,8 +5,8 @@ # This script is intended to be run by the same interpreter executable # which is to be tested, so should use minimal language functionality. # -import usys as sys -import uos as os +import sys +import os tests = ["basics", "micropython", "float", "import", "io", " misc", "unicode", "extmod", "unix"] diff --git a/tests/run-tests.py b/tests/run-tests.py index 498db8b404..4964ff49fd 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -56,8 +56,8 @@ os.environ["PYTHONIOENCODING"] = "utf-8" # Code to allow a target MicroPython to import an .mpy from RAM injected_import_hook_code = """\ -import usys, uos, uio -class __File(uio.IOBase): +import sys, os, io +class __File(io.IOBase): def __init__(self): self.off = 0 def ioctl(self, request, arg): @@ -80,8 +80,8 @@ class __FS: raise OSError(-2) # ENOENT def open(self, path, mode): return __File() -uos.mount(__FS(), '/__vfstest') -uos.chdir('/__vfstest') +os.mount(__FS(), '/__vfstest') +os.chdir('/__vfstest') __import__('__injected_test') """ @@ -455,9 +455,9 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if output == b"TypeError\n": skip_revops = True - # Check if uio module exists, and skip such tests if it doesn't - output = run_feature_check(pyb, args, base_path, "uio_module.py") - if output != b"uio\n": + # Check if io module exists, and skip such tests if it doesn't + output = run_feature_check(pyb, args, base_path, "io_module.py") + if output != b"io\n": skip_io_module = True # Check if fstring feature is enabled, and skip such tests if it doesn't @@ -512,9 +512,9 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add("extmod/uctypes_le_float.py") skip_tests.add("extmod/uctypes_native_float.py") skip_tests.add("extmod/uctypes_sizeof_float.py") - skip_tests.add("extmod/ujson_dumps_float.py") - skip_tests.add("extmod/ujson_loads_float.py") - skip_tests.add("extmod/urandom_extra_float.py") + skip_tests.add("extmod/json_dumps_float.py") + skip_tests.add("extmod/json_loads_float.py") + skip_tests.add("extmod/random_extra_float.py") skip_tests.add("misc/rge_sm.py") if upy_float_precision < 32: skip_tests.add( @@ -544,7 +544,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if not has_coverage: skip_tests.add("cmdline/cmd_parsetree.py") skip_tests.add("cmdline/repl_sys_ps1_ps2.py") - skip_tests.add("extmod/ussl_poll.py") + skip_tests.add("extmod/ssl_poll.py") # Some tests shouldn't be run on a PC if args.target == "unix": @@ -568,9 +568,9 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): } ) # requires uctypes skip_tests.add("extmod/zlibd_decompress.py") # requires zlib - skip_tests.add("extmod/uheapq1.py") # uheapq not supported by WiPy - skip_tests.add("extmod/urandom_basic.py") # requires urandom - skip_tests.add("extmod/urandom_extra.py") # requires urandom + skip_tests.add("extmod/heapq1.py") # heapq not supported by WiPy + skip_tests.add("extmod/random_basic.py") # requires random + skip_tests.add("extmod/random_extra.py") # requires random elif args.target == "esp8266": skip_tests.add("misc/rge_sm.py") # too large elif args.target == "minimal": @@ -582,7 +582,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add("micropython/opt_level.py") # don't assume line numbers are stored elif args.target == "nrf": skip_tests.add("basics/memoryview1.py") # no item assignment for memoryview - skip_tests.add("extmod/urandom_basic.py") # unimplemented: urandom.seed + skip_tests.add("extmod/random_basic.py") # unimplemented: random.seed skip_tests.add("micropython/opt_level.py") # no support for line numbers skip_tests.add("misc/non_compliant.py") # no item assignment for bytearray for t in tests: @@ -590,7 +590,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add(t) elif args.target == "renesas-ra": skip_tests.add( - "extmod/utime_time_ns.py" + "extmod/time_time_ns.py" ) # RA fsp rtc function doesn't support nano sec info elif args.target == "qemu-arm": skip_tests.add("misc/print_exception.py") # requires sys stdfiles diff --git a/tests/stress/recursive_data.py b/tests/stress/recursive_data.py index 3b7fa50952..6e01319ed3 100644 --- a/tests/stress/recursive_data.py +++ b/tests/stress/recursive_data.py @@ -1,6 +1,6 @@ # This tests that printing recursive data structure doesn't lead to segfault. try: - import uio as io + import io except ImportError: print("SKIP") raise SystemExit diff --git a/tests/thread/stress_aes.py b/tests/thread/stress_aes.py index aaf9f576dd..b25da855ae 100644 --- a/tests/thread/stress_aes.py +++ b/tests/thread/stress_aes.py @@ -216,10 +216,7 @@ class AES: ################################################################## # test code -try: - import utime as time -except ImportError: - import time +import time import _thread diff --git a/tests/thread/stress_create.py b/tests/thread/stress_create.py index 877424cdf5..98f272f5cd 100644 --- a/tests/thread/stress_create.py +++ b/tests/thread/stress_create.py @@ -1,13 +1,12 @@ # stress test for creating many threads -try: - import utime - - sleep_ms = utime.sleep_ms -except ImportError: - import time +import time +if hasattr(time, "sleep_ms"): + sleep_ms = time.sleep_ms +else: sleep_ms = lambda t: time.sleep(t / 1000) + import _thread diff --git a/tests/thread/stress_heap.py b/tests/thread/stress_heap.py index 2ad91ae147..dec65c7ce0 100644 --- a/tests/thread/stress_heap.py +++ b/tests/thread/stress_heap.py @@ -3,10 +3,7 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime as time -except ImportError: - import time +import time import _thread diff --git a/tests/thread/stress_schedule.py b/tests/thread/stress_schedule.py index 8be7f2d737..40191e6620 100644 --- a/tests/thread/stress_schedule.py +++ b/tests/thread/stress_schedule.py @@ -2,7 +2,7 @@ # while dealing with concurrent access from multiple threads. import _thread -import utime +import time import micropython import gc @@ -32,15 +32,15 @@ def thread(): micropython.schedule(task, None) except RuntimeError: # Queue full, back off. - utime.sleep_ms(10) + time.sleep_ms(10) for i in range(8): _thread.start_new_thread(thread, ()) # Wait up to 10 seconds for 10000 tasks to be scheduled. -t = utime.ticks_ms() -while n < _NUM_TASKS and utime.ticks_diff(utime.ticks_ms(), t) < _TIMEOUT_MS: +t = time.ticks_ms() +while n < _NUM_TASKS and time.ticks_diff(time.ticks_ms(), t) < _TIMEOUT_MS: pass if n < _NUM_TASKS: diff --git a/tests/thread/thread_exc2.py b/tests/thread/thread_exc2.py index 2863e1dec1..6f77bdbffa 100644 --- a/tests/thread/thread_exc2.py +++ b/tests/thread/thread_exc2.py @@ -1,5 +1,5 @@ # test raising exception within thread which is not caught -import utime +import time import _thread @@ -8,5 +8,5 @@ def thread_entry(): _thread.start_new_thread(thread_entry, ()) -utime.sleep(1) +time.sleep(1) print("done") diff --git a/tests/thread/thread_exit1.py b/tests/thread/thread_exit1.py index 186a9be340..e34ca827ca 100644 --- a/tests/thread/thread_exit1.py +++ b/tests/thread/thread_exit1.py @@ -2,10 +2,7 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime as time -except ImportError: - import time +import time import _thread diff --git a/tests/thread/thread_exit2.py b/tests/thread/thread_exit2.py index 5be7945db2..630b664758 100644 --- a/tests/thread/thread_exit2.py +++ b/tests/thread/thread_exit2.py @@ -2,10 +2,7 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime as time -except ImportError: - import time +import time import _thread diff --git a/tests/thread/thread_lock2.py b/tests/thread/thread_lock2.py index b842f69c93..96b3a6af80 100644 --- a/tests/thread/thread_lock2.py +++ b/tests/thread/thread_lock2.py @@ -2,10 +2,7 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime as time -except ImportError: - import time +import time import _thread lock = _thread.allocate_lock() diff --git a/tests/thread/thread_lock4.py b/tests/thread/thread_lock4.py index bbf9043996..97c3dc5380 100644 --- a/tests/thread/thread_lock4.py +++ b/tests/thread/thread_lock4.py @@ -2,10 +2,7 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime as time -except ImportError: - import time +import time import _thread diff --git a/tests/thread/thread_qstr1.py b/tests/thread/thread_qstr1.py index 14f5b6be66..f184d2a58e 100644 --- a/tests/thread/thread_qstr1.py +++ b/tests/thread/thread_qstr1.py @@ -2,10 +2,7 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime as time -except ImportError: - import time +import time import _thread diff --git a/tests/thread/thread_sleep1.py b/tests/thread/thread_sleep1.py index 18fa4e05a1..add9b02f15 100644 --- a/tests/thread/thread_sleep1.py +++ b/tests/thread/thread_sleep1.py @@ -2,13 +2,11 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime - - sleep_ms = utime.sleep_ms -except ImportError: - import time +import time +if hasattr(time, "sleep_ms"): + sleep_ms = time.sleep_ms +else: sleep_ms = lambda t: time.sleep(t / 1000) import _thread diff --git a/tests/thread/thread_stacksize1.py b/tests/thread/thread_stacksize1.py index cf46b73b77..140d165cb3 100644 --- a/tests/thread/thread_stacksize1.py +++ b/tests/thread/thread_stacksize1.py @@ -1,10 +1,8 @@ # test setting the thread stack size # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import usys as sys -except ImportError: - import sys + +import sys import _thread # different implementations have different minimum sizes diff --git a/tests/thread/thread_start1.py b/tests/thread/thread_start1.py index 7274633245..ea8c4f0002 100644 --- a/tests/thread/thread_start1.py +++ b/tests/thread/thread_start1.py @@ -2,10 +2,7 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime as time -except ImportError: - import time +import time import _thread diff --git a/tests/thread/thread_start2.py b/tests/thread/thread_start2.py index d68ea94329..f8239a779a 100644 --- a/tests/thread/thread_start2.py +++ b/tests/thread/thread_start2.py @@ -2,10 +2,7 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -try: - import utime as time -except ImportError: - import time +import time import _thread diff --git a/tests/unicode/unicode_ure.py b/tests/unicode/unicode_ure.py index 5a5dc60054..c268b9e6fe 100644 --- a/tests/unicode/unicode_ure.py +++ b/tests/unicode/unicode_ure.py @@ -1,13 +1,10 @@ # test match.span() for unicode strings try: - import ure as re + import re except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit try: m = re.match(".", "a") diff --git a/tests/unix/extra_coverage.py b/tests/unix/extra_coverage.py index 3c12b26923..0ea8f7886b 100644 --- a/tests/unix/extra_coverage.py +++ b/tests/unix/extra_coverage.py @@ -4,8 +4,8 @@ except NameError: print("SKIP") raise SystemExit -import uerrno -import uio +import errno +import io data = extra_coverage() @@ -18,7 +18,7 @@ print(hash(str(data[1], "utf8"))) # test streams stream = data[2] # has set_error and set_buf. Write always returns error -stream.set_error(uerrno.EAGAIN) # non-blocking error +stream.set_error(errno.EAGAIN) # non-blocking error print(stream.read()) # read all encounters non-blocking error print(stream.read(1)) # read 1 byte encounters non-blocking error print(stream.readline()) # readline encounters non-blocking error @@ -42,8 +42,8 @@ stream2 = data[3] # is textio print(stream2.read(1)) # read 1 byte encounters non-blocking error with textio stream # test BufferedWriter with stream errors -stream.set_error(uerrno.EAGAIN) -buf = uio.BufferedWriter(stream, 8) +stream.set_error(errno.EAGAIN) +buf = io.BufferedWriter(stream, 8) print(buf.write(bytearray(16))) # function defined in C++ code diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 7ea2599c91..6ec8eaaa04 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -48,21 +48,21 @@ RuntimeError: RuntimeError: # repl ame__ -mport +port builtins micropython _thread _uasyncio -btree cexample cmath cppexample -example_package ffi framebuf -gc math termios uarray -ubinascii ucollections ucryptolib uctypes -uerrno uhashlib uheapq uio -ujson umachine uos urandom -ure uselect usocket ussl -ustruct usys utime utimeq -uwebsocket uzlib -ime +array binascii btree cexample +cmath collections cppexample cryptolib +errno example_package ffi +framebuf gc hashlib heapq +io json machine math +os random re select +socket ssl struct sys +termios time timeq uctypes +websocket zlib +me -utime utimeq +time timeq argv atexit byteorder exc_info executable exit getsizeof implementation diff --git a/tests/unix/ffi_types.py b/tests/unix/ffi_types.py index fd94c509d0..06e9b89d3f 100644 --- a/tests/unix/ffi_types.py +++ b/tests/unix/ffi_types.py @@ -1,7 +1,7 @@ # test 8/16/32/64 bit signed/unsigned integer arguments and return types for ffi functions # requires ffi_lib.c to be compiled as: $(CC) -shared -o ffi_lib.so ffi_lib.c -import uos, usys +import os, sys try: import ffi @@ -9,9 +9,9 @@ except ImportError: print("SKIP") raise SystemExit -ffi_lib_filename = "./" + usys.argv[0].rsplit("/", 1)[0] + "/ffi_lib.so" +ffi_lib_filename = "./" + sys.argv[0].rsplit("/", 1)[0] + "/ffi_lib.so" try: - uos.stat(ffi_lib_filename) + os.stat(ffi_lib_filename) except OSError: print("SKIP") raise SystemExit diff --git a/tests/unix/time.py b/tests/unix/time_mktime_localtime.py similarity index 96% rename from tests/unix/time.py rename to tests/unix/time_mktime_localtime.py index 55a4b18aae..d1c03c103d 100644 --- a/tests/unix/time.py +++ b/tests/unix/time_mktime_localtime.py @@ -1,7 +1,4 @@ -try: - import utime as time -except ImportError: - import time +import time DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] diff --git a/tests/wipy/wlan/machine.py.exp b/tests/wipy/wlan/machine.py.exp index cc5b3f61da..303a0633a6 100644 --- a/tests/wipy/wlan/machine.py.exp +++ b/tests/wipy/wlan/machine.py.exp @@ -1,4 +1,4 @@ - + True True Active diff --git a/tools/ci.sh b/tools/ci.sh index 21acc17535..a010adcbce 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -630,8 +630,8 @@ function ci_unix_macos_build { function ci_unix_macos_run_tests { # Issues with macOS tests: # - import_pkg7 has a problem with relative imports - # - urandom_basic has a problem with getrandbits(0) - (cd tests && MICROPY_MICROPYTHON=../ports/unix/build-standard/micropython ./run-tests.py --exclude 'import_pkg7.py' --exclude 'urandom_basic.py') + # - random_basic has a problem with getrandbits(0) + (cd tests && MICROPY_MICROPYTHON=../ports/unix/build-standard/micropython ./run-tests.py --exclude 'import_pkg7.py' --exclude 'random_basic.py') } function ci_unix_qemu_mips_setup { diff --git a/tools/tinytest-codegen.py b/tools/tinytest-codegen.py index feda75f283..d6e87ac6ce 100755 --- a/tools/tinytest-codegen.py +++ b/tools/tinytest-codegen.py @@ -65,11 +65,11 @@ exclude_tests = ( "basics/bytes_compare3.py", "extmod/ticks_diff.py", "extmod/time_ms_us.py", - "extmod/uheapq_timeq.py", + "extmod/heapq_timeq.py", # unicode char issue - "extmod/ujson_loads.py", + "extmod/json_loads.py", # doesn't output to python stdout - "extmod/ure_debug.py", + "extmod/re_debug.py", "extmod/vfs_basic.py", "extmod/vfs_fat_ramdisk.py", "extmod/vfs_fat_fileio.py", From 109717457edbf49421af3848ea26e26fff567289 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 2 Jun 2023 15:23:23 +1000 Subject: [PATCH 178/565] tests/run-multitests.py: Don't allow imports from the cwd. Make tests run in an isolated environment (i.e. `import io` would otherwise get the `tests/io` directory). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/run-multitests.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/run-multitests.py b/tests/run-multitests.py index 81db31ea94..5ae8b8ea48 100755 --- a/tests/run-multitests.py +++ b/tests/run-multitests.py @@ -162,6 +162,14 @@ class PyInstanceSubProcess(PyInstance): def __str__(self): return self.argv[0].rsplit("/")[-1] + def prepare_script_from_file(self, filename, prepend, append): + # Make tests run in an isolated environment (i.e. `import io` would + # otherwise get the `tests/io` directory). + remove_cwd_from_sys_path = b"import sys\nsys.path.remove('')\n\n" + return remove_cwd_from_sys_path + super().prepare_script_from_file( + filename, prepend, append + ) + def run_script(self, script): output = b"" err = None @@ -582,7 +590,7 @@ def main(): cmd_args = cmd_parser.parse_args() # clear search path to make sure tests use only builtin modules and those in extmod - os.environ["MICROPYPATH"] = os.pathsep.join(("", ".frozen", "../extmod")) + os.environ["MICROPYPATH"] = os.pathsep.join((".frozen", "../extmod")) test_files = prepare_test_file_list(cmd_args.files) max_instances = max(t[1] for t in test_files) From 339f02a5947e79347014b4d34adbf8a120b184bc Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 2 Jun 2023 15:40:03 +1000 Subject: [PATCH 179/565] tests/run-perfbench.py: Don't allow imports from the cwd. Make tests run in an isolated environment (i.e. `import io` would otherwise get the `tests/io` directory). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/perf_bench/core_import_mpy_multi.py | 4 ++-- tests/perf_bench/core_import_mpy_single.py | 6 +++--- tests/run-perfbench.py | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/perf_bench/core_import_mpy_multi.py b/tests/perf_bench/core_import_mpy_multi.py index ce68306678..364c325042 100644 --- a/tests/perf_bench/core_import_mpy_multi.py +++ b/tests/perf_bench/core_import_mpy_multi.py @@ -47,7 +47,7 @@ class FS: pass def stat(self, path): - if path == "__injected.mpy": + if path == "/__injected.mpy": return tuple(0 for _ in range(10)) else: raise OSError(-2) # ENOENT @@ -58,7 +58,7 @@ class FS: def mount(): os.mount(FS(), "/__remote") - os.chdir("/__remote") + sys.path.insert(0, "/__remote") def test(r): diff --git a/tests/perf_bench/core_import_mpy_single.py b/tests/perf_bench/core_import_mpy_single.py index 1b411fc3fb..5757c3eaf1 100644 --- a/tests/perf_bench/core_import_mpy_single.py +++ b/tests/perf_bench/core_import_mpy_single.py @@ -2,7 +2,7 @@ # The first import of a module will intern strings that don't already exist, and # this test should be representative of what happens in a real application. -import io, os +import io, os, sys if not (hasattr(io, "IOBase") and hasattr(os, "mount")): print("SKIP") @@ -102,7 +102,7 @@ class FS: pass def stat(self, path): - if path == "__injected.mpy": + if path == "/__injected.mpy": return tuple(0 for _ in range(10)) else: raise OSError(-2) # ENOENT @@ -113,7 +113,7 @@ class FS: def mount(): os.mount(FS(), "/__remote") - os.chdir("/__remote") + sys.path.insert(0, "/__remote") def test(): diff --git a/tests/run-perfbench.py b/tests/run-perfbench.py index 578f975bb8..81d873c459 100755 --- a/tests/run-perfbench.py +++ b/tests/run-perfbench.py @@ -109,8 +109,9 @@ def run_benchmarks(args, target, param_n, param_m, n_average, test_list): continue # Create test script + test_script = b"import sys\nsys.path.remove('')\n\n" with open(test_file, "rb") as f: - test_script = f.read() + test_script += f.read() with open(BENCH_SCRIPT_DIR + "benchrun.py", "rb") as f: test_script += f.read() test_script += b"bm_run(%u, %u)\n" % (param_n, param_m) From 9d7eac07138b6e02f4c0775dc70f36fdd69432a2 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 2 Jun 2023 17:58:27 +1000 Subject: [PATCH 180/565] tests/run-natmodtests.py: Don't allow imports from the cwd. Make tests run in an isolated environment (i.e. `import io` would otherwise get the `tests/io` directory). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/run-natmodtests.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/run-natmodtests.py b/tests/run-natmodtests.py index 9fe970a6d0..16f8fde967 100755 --- a/tests/run-natmodtests.py +++ b/tests/run-natmodtests.py @@ -46,14 +46,14 @@ class __FS: def chdir(self, path): pass def stat(self, path): - if path == '__injected.mpy': + if path == '/__injected.mpy': return tuple(0 for _ in range(10)) else: raise OSError(-2) # ENOENT def open(self, path, mode): return __File() os.mount(__FS(), '/__remote') -os.chdir('/__remote') +sys.path.insert(0, '/__remote') sys.modules['{}'] = __import__('__injected') """ @@ -111,9 +111,10 @@ def run_tests(target_truth, target, args, stats): test_file_data = f.read() # Create full test with embedded .mpy + test_script = b"import sys\nsys.path.remove('')\n\n" try: with open(NATMOD_EXAMPLE_DIR + test_mpy, "rb") as f: - test_script = b"__buf=" + bytes(repr(f.read()), "ascii") + b"\n" + test_script += b"__buf=" + bytes(repr(f.read()), "ascii") + b"\n" except OSError: print("---- {} - mpy file not compiled".format(test_file)) continue From 5fd042e7d1610b4d42acfc523441468f2ac28c6f Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 19 Aug 2022 22:58:37 +1000 Subject: [PATCH 181/565] all: Replace all uses of umodule in Python code. Applies to drivers/examples/extmod/port-modules/tools. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- examples/hwapi/README.md | 6 +-- examples/hwapi/button_led.py | 4 +- examples/hwapi/button_reaction.py | 4 +- examples/hwapi/soft_pwm.py | 6 +-- examples/network/http_client.py | 5 +-- examples/network/http_client_ssl.py | 14 ++----- examples/network/http_server.py | 5 +-- examples/network/http_server_simplistic.py | 5 +-- .../http_server_simplistic_commented.py | 5 +-- examples/network/http_server_ssl.py | 10 ++--- examples/unix/machine_bios.py | 2 +- extmod/uasyncio/event.py | 4 +- extmod/uasyncio/stream.py | 6 +-- ports/esp32/modules/_boot.py | 4 +- ports/esp32/modules/inisetup.py | 8 ++-- ports/esp8266/boards/GENERIC/board.md | 2 +- ports/esp8266/boards/GENERIC_1M/board.md | 2 +- ports/esp8266/modules/_boot.py | 4 +- ports/esp8266/modules/espnow.py | 2 +- ports/esp8266/modules/inisetup.py | 18 ++++----- ports/nrf/modules/scripts/_mkfs.py | 14 +++---- ports/rp2/modules/rp2.py | 4 +- ports/samd/modules/_boot.py | 8 ++-- .../boards/NUCLEO_WB55/rfcore_firmware.py | 2 +- ports/stm32/mboot/fwupdate.py | 6 +-- tools/mpremote/mpremote/commands.py | 4 +- tools/mpremote/mpremote/main.py | 2 +- tools/mpremote/mpremote/transport_serial.py | 38 +++++++++---------- tools/pyboard.py | 26 ++++++------- 29 files changed, 99 insertions(+), 121 deletions(-) diff --git a/examples/hwapi/README.md b/examples/hwapi/README.md index f3de752f9c..a1b0c5642a 100644 --- a/examples/hwapi/README.md +++ b/examples/hwapi/README.md @@ -40,13 +40,13 @@ application of this idea would look like: `app.py`: from hwconfig import * - import utime + import time while True: LED.value(1) - utime.sleep_ms(500) + time.sleep_ms(500) LED.value(0) - utime.sleep_ms(500) + time.sleep_ms(500) To deploy this application to a particular board, a user will need: diff --git a/examples/hwapi/button_led.py b/examples/hwapi/button_led.py index bd6fe01729..c73bcfc89a 100644 --- a/examples/hwapi/button_led.py +++ b/examples/hwapi/button_led.py @@ -1,4 +1,4 @@ -import utime +import time from hwconfig import LED, BUTTON # Light LED when (and while) a BUTTON is pressed @@ -6,4 +6,4 @@ from hwconfig import LED, BUTTON while 1: LED.value(BUTTON.value()) # Don't burn CPU - utime.sleep_ms(10) + time.sleep_ms(10) diff --git a/examples/hwapi/button_reaction.py b/examples/hwapi/button_reaction.py index e5a139a575..52bdf79384 100644 --- a/examples/hwapi/button_reaction.py +++ b/examples/hwapi/button_reaction.py @@ -1,4 +1,4 @@ -import utime +import time import machine from hwconfig import LED, BUTTON @@ -18,4 +18,4 @@ while 1: print("Well, you're *really* slow") else: print("You are as slow as %d microseconds!" % delay) - utime.sleep_ms(10) + time.sleep_ms(10) diff --git a/examples/hwapi/soft_pwm.py b/examples/hwapi/soft_pwm.py index 72291b0ecd..466de08f09 100644 --- a/examples/hwapi/soft_pwm.py +++ b/examples/hwapi/soft_pwm.py @@ -1,4 +1,4 @@ -import utime +import time from hwconfig import LED @@ -15,10 +15,10 @@ def pwm_cycle(led, duty, cycles): for i in range(cycles): if duty: led.on() - utime.sleep_ms(duty) + time.sleep_ms(duty) if duty_off: led.off() - utime.sleep_ms(duty_off) + time.sleep_ms(duty_off) # At the duty setting of 1, an LED is still pretty bright, then diff --git a/examples/network/http_client.py b/examples/network/http_client.py index 0791c8066b..661c286b70 100644 --- a/examples/network/http_client.py +++ b/examples/network/http_client.py @@ -1,7 +1,4 @@ -try: - import usocket as socket -except: - import socket +import socket def main(use_stream=False): diff --git a/examples/network/http_client_ssl.py b/examples/network/http_client_ssl.py index 83f685fdf3..323971c0ee 100644 --- a/examples/network/http_client_ssl.py +++ b/examples/network/http_client_ssl.py @@ -1,17 +1,11 @@ -try: - import usocket as _socket -except: - import _socket -try: - import ussl as ssl -except: - import ssl +import socket +import ssl def main(use_stream=True): - s = _socket.socket() + s = socket.socket() - ai = _socket.getaddrinfo("google.com", 443) + ai = socket.getaddrinfo("google.com", 443) print("Address infos:", ai) addr = ai[0][-1] diff --git a/examples/network/http_server.py b/examples/network/http_server.py index 76be3ab817..a6ed53154a 100644 --- a/examples/network/http_server.py +++ b/examples/network/http_server.py @@ -1,7 +1,4 @@ -try: - import usocket as socket -except: - import socket +import socket CONTENT = b"""\ diff --git a/examples/network/http_server_simplistic.py b/examples/network/http_server_simplistic.py index a9831127ff..09936b9d91 100644 --- a/examples/network/http_server_simplistic.py +++ b/examples/network/http_server_simplistic.py @@ -1,9 +1,6 @@ # Do not use this code in real projects! Read # http_server_simplistic_commented.py for details. -try: - import usocket as socket -except: - import socket +import socket CONTENT = b"""\ diff --git a/examples/network/http_server_simplistic_commented.py b/examples/network/http_server_simplistic_commented.py index da042c6c8a..d4710ad61a 100644 --- a/examples/network/http_server_simplistic_commented.py +++ b/examples/network/http_server_simplistic_commented.py @@ -8,10 +8,7 @@ # details, and use this code only for quick hacks, preferring # http_server.py for "real thing". # -try: - import usocket as socket -except: - import socket +import socket CONTENT = b"""\ diff --git a/examples/network/http_server_ssl.py b/examples/network/http_server_ssl.py index 1116c71e99..7766fa7ea5 100644 --- a/examples/network/http_server_ssl.py +++ b/examples/network/http_server_ssl.py @@ -1,10 +1,6 @@ -import ubinascii as binascii - -try: - import usocket as socket -except: - import socket -import ussl as ssl +import binascii +import socket +import ssl # This self-signed key/cert pair is randomly generated and to be used for diff --git a/examples/unix/machine_bios.py b/examples/unix/machine_bios.py index 878f3fd8f3..40aae4ccef 100644 --- a/examples/unix/machine_bios.py +++ b/examples/unix/machine_bios.py @@ -4,6 +4,6 @@ # It is expected to print 0xaa55, which is a signature at the start of # Video BIOS. -import umachine as machine +import machine print(hex(machine.mem16[0xC0000])) diff --git a/extmod/uasyncio/event.py b/extmod/uasyncio/event.py index 43d47eb5f0..8a90534590 100644 --- a/extmod/uasyncio/event.py +++ b/extmod/uasyncio/event.py @@ -40,9 +40,9 @@ class Event: # that asyncio will poll until a flag is set. # Note: Unlike Event, this is self-clearing after a wait(). try: - import uio + import io - class ThreadSafeFlag(uio.IOBase): + class ThreadSafeFlag(io.IOBase): def __init__(self): self.state = 0 diff --git a/extmod/uasyncio/stream.py b/extmod/uasyncio/stream.py index 875353c940..ac297cce04 100644 --- a/extmod/uasyncio/stream.py +++ b/extmod/uasyncio/stream.py @@ -101,8 +101,8 @@ StreamWriter = Stream # # async def open_connection(host, port): - from uerrno import EINPROGRESS - import usocket as socket + from errno import EINPROGRESS + import socket ai = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0] # TODO this is blocking! s = socket.socket(ai[0], ai[1], ai[2]) @@ -154,7 +154,7 @@ class Server: # Helper function to start a TCP stream server, running as a new task # TODO could use an accept-callback on socket read activity instead of creating a task async def start_server(cb, host, port, backlog=5): - import usocket as socket + import socket # Create and bind server socket. host = socket.getaddrinfo(host, port)[0] # TODO this is blocking! diff --git a/ports/esp32/modules/_boot.py b/ports/esp32/modules/_boot.py index a7d9813090..651fc7b10c 100644 --- a/ports/esp32/modules/_boot.py +++ b/ports/esp32/modules/_boot.py @@ -1,10 +1,10 @@ import gc -import uos +import os from flashbdev import bdev try: if bdev: - uos.mount(bdev, "/") + os.mount(bdev, "/") except OSError: import inisetup diff --git a/ports/esp32/modules/inisetup.py b/ports/esp32/modules/inisetup.py index 426a47a6b4..35d1c6bc9a 100644 --- a/ports/esp32/modules/inisetup.py +++ b/ports/esp32/modules/inisetup.py @@ -1,4 +1,4 @@ -import uos +import os from flashbdev import bdev @@ -33,9 +33,9 @@ by firmware programming). def setup(): check_bootsec() print("Performing initial setup") - uos.VfsLfs2.mkfs(bdev) - vfs = uos.VfsLfs2(bdev) - uos.mount(vfs, "/") + os.VfsLfs2.mkfs(bdev) + vfs = os.VfsLfs2(bdev) + os.mount(vfs, "/") with open("boot.py", "w") as f: f.write( """\ diff --git a/ports/esp8266/boards/GENERIC/board.md b/ports/esp8266/boards/GENERIC/board.md index b93ca509f8..fa0cf410d6 100644 --- a/ports/esp8266/boards/GENERIC/board.md +++ b/ports/esp8266/boards/GENERIC/board.md @@ -6,7 +6,7 @@ Note: v1.12-334 and newer (including v1.13) require an ESP8266 module with 2MiB of flash or more, and use littlefs as the filesystem by default. When upgrading from older firmware please backup your files first, and either erase all flash before upgrading, or after upgrading execute -`uos.VfsLfs2.mkfs(bdev)`. +`os.VfsLfs2.mkfs(bdev)`. ### OTA builds Over-The-Air (OTA) builds of the ESP8266 firmware are also provided. diff --git a/ports/esp8266/boards/GENERIC_1M/board.md b/ports/esp8266/boards/GENERIC_1M/board.md index 4a0e677078..17cc6e3a6b 100644 --- a/ports/esp8266/boards/GENERIC_1M/board.md +++ b/ports/esp8266/boards/GENERIC_1M/board.md @@ -2,4 +2,4 @@ The following are daily builds of the ESP8266 firmware tailored for modules with only 1MiB of flash. This firmware uses littlefs as the filesystem. When upgrading from older firmware that uses a FAT filesystem please backup your files first, and either erase all flash before upgrading, or after upgrading execute -`uos.VfsLfs2.mkfs(bdev)`. +`os.VfsLfs2.mkfs(bdev)`. diff --git a/ports/esp8266/modules/_boot.py b/ports/esp8266/modules/_boot.py index 1f77d88024..06b372990a 100644 --- a/ports/esp8266/modules/_boot.py +++ b/ports/esp8266/modules/_boot.py @@ -1,12 +1,12 @@ import gc gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4) -import uos +import os from flashbdev import bdev if bdev: try: - uos.mount(bdev, "/") + os.mount(bdev, "/") except: import inisetup diff --git a/ports/esp8266/modules/espnow.py b/ports/esp8266/modules/espnow.py index 2f9c256c6b..1d2b946552 100644 --- a/ports/esp8266/modules/espnow.py +++ b/ports/esp8266/modules/espnow.py @@ -2,7 +2,7 @@ # MIT license; Copyright (c) 2022 Glenn Moloney @glenn20 from _espnow import * -from uselect import poll, POLLIN +from select import poll, POLLIN class ESPNow(ESPNowBase): diff --git a/ports/esp8266/modules/inisetup.py b/ports/esp8266/modules/inisetup.py index e5ce00138e..fa6a93fd83 100644 --- a/ports/esp8266/modules/inisetup.py +++ b/ports/esp8266/modules/inisetup.py @@ -1,13 +1,13 @@ -import uos +import os import network from flashbdev import bdev def wifi(): - import ubinascii + import binascii ap_if = network.WLAN(network.AP_IF) - ssid = b"MicroPython-%s" % ubinascii.hexlify(ap_if.config("mac")[-3:]) + ssid = b"MicroPython-%s" % binascii.hexlify(ap_if.config("mac")[-3:]) ap_if.config(ssid=ssid, security=network.AUTH_WPA_WPA2_PSK, key=b"micropythoN") @@ -32,7 +32,7 @@ def fs_corrupted(): """\ The filesystem starting at sector %d with size %d sectors looks corrupt. You may want to make a flash snapshot and try to recover it. Otherwise, -format it with uos.VfsLfs2.mkfs(bdev), or completely erase the flash and +format it with os.VfsLfs2.mkfs(bdev), or completely erase the flash and reprogram MicroPython. """ % (bdev.start_sec, bdev.blocks) @@ -44,17 +44,17 @@ def setup(): check_bootsec() print("Performing initial setup") wifi() - uos.VfsLfs2.mkfs(bdev) - vfs = uos.VfsLfs2(bdev) - uos.mount(vfs, "/") + os.VfsLfs2.mkfs(bdev) + vfs = os.VfsLfs2(bdev) + os.mount(vfs, "/") with open("boot.py", "w") as f: f.write( """\ # This file is executed on every boot (including wake-boot from deepsleep) #import esp #esp.osdebug(None) -import uos, machine -#uos.dupterm(None, 1) # disable REPL on UART(0) +import os, machine +#os.dupterm(None, 1) # disable REPL on UART(0) import gc #import webrepl #webrepl.start() diff --git a/ports/nrf/modules/scripts/_mkfs.py b/ports/nrf/modules/scripts/_mkfs.py index 00522ffbb9..02e8dabce2 100644 --- a/ports/nrf/modules/scripts/_mkfs.py +++ b/ports/nrf/modules/scripts/_mkfs.py @@ -1,19 +1,19 @@ -import uos, nrf +import os, nrf try: - from uos import VfsLfs1 + from os import VfsLfs1 - uos.VfsLfs1.mkfs(nrf.Flash()) + os.VfsLfs1.mkfs(nrf.Flash()) except ImportError: try: - from uos import VfsLfs2 + from os import VfsLfs2 - uos.VfsLfs2.mkfs(nrf.Flash()) + os.VfsLfs2.mkfs(nrf.Flash()) except ImportError: try: - from uos import VfsFat + from os import VfsFat - uos.VfsFat.mkfs(nrf.Flash()) + os.VfsFat.mkfs(nrf.Flash()) except ImportError: pass except OSError as e: diff --git a/ports/rp2/modules/rp2.py b/ports/rp2/modules/rp2.py index f145cbd607..a34e8e92a3 100644 --- a/ports/rp2/modules/rp2.py +++ b/ports/rp2/modules/rp2.py @@ -34,9 +34,9 @@ class PIOASMEmit: pull_thresh=32, fifo_join=0 ): - # uarray is a built-in module so importing it here won't require + # array is a built-in module so importing it here won't require # scanning the filesystem. - from uarray import array + from array import array self.labels = {} execctrl = 0 diff --git a/ports/samd/modules/_boot.py b/ports/samd/modules/_boot.py index 5fe2bc640c..1ff51de598 100644 --- a/ports/samd/modules/_boot.py +++ b/ports/samd/modules/_boot.py @@ -1,19 +1,19 @@ import gc -import uos +import os import samd bdev = samd.Flash() # Try to mount the filesystem, and format the flash if it doesn't exist. -fs_type = uos.VfsLfs2 if hasattr(uos, "VfsLfs2") else uos.VfsLfs1 +fs_type = os.VfsLfs2 if hasattr(os, "VfsLfs2") else os.VfsLfs1 try: vfs = fs_type(bdev, progsize=256) except: fs_type.mkfs(bdev, progsize=256) vfs = fs_type(bdev, progsize=256) -uos.mount(vfs, "/") +os.mount(vfs, "/") -del vfs, fs_type, bdev, uos, samd +del vfs, fs_type, bdev, os, samd gc.collect() del gc diff --git a/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py b/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py index fe34ce1228..3c741e575c 100644 --- a/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py +++ b/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py @@ -73,7 +73,7 @@ import struct, os try: import machine, stm - from ubinascii import crc32 + from binascii import crc32 from micropython import const except ImportError: # cpython diff --git a/ports/stm32/mboot/fwupdate.py b/ports/stm32/mboot/fwupdate.py index 4bf07f5a33..78a8d73658 100644 --- a/ports/stm32/mboot/fwupdate.py +++ b/ports/stm32/mboot/fwupdate.py @@ -3,7 +3,7 @@ from micropython import const import struct, time -import uzlib, machine, stm +import zlib, machine, stm # Constants to be used with update_mpy VFS_FAT = 1 @@ -36,7 +36,7 @@ def dfu_read(filename): if hdr == b"Dfu": pass elif hdr == b"\x1f\x8b\x08": - f = uzlib.DecompIO(f, 16 + 15) + f = zlib.DecompIO(f, 16 + 15) else: print("Invalid firmware", filename) return None @@ -231,7 +231,7 @@ def update_app_elements( # Check firmware is of .dfu or .dfu.gz type try: with open(filename, "rb") as f: - hdr = uzlib.DecompIO(f, 16 + 15).read(6) + hdr = zlib.DecompIO(f, 16 + 15).read(6) except Exception: with open(filename, "rb") as f: hdr = f.read(6) diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 45acb8da19..ef1a7643cb 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -137,14 +137,14 @@ def do_filesystem(state, args): raise CommandError("'cp -r' source files must be local") _list_recursive(src_files, path) known_dirs = {""} - state.transport.exec_("import uos") + state.transport.exec_("import os") for dir, file in src_files: dir_parts = dir.split("/") for i in range(len(dir_parts)): d = "/".join(dir_parts[: i + 1]) if d not in known_dirs: state.transport.exec_( - "try:\n uos.mkdir('%s')\nexcept OSError as e:\n print(e)" % d + "try:\n os.mkdir('%s')\nexcept OSError as e:\n print(e)" % d ) known_dirs.add(d) state.transport.filesystem_command( diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index 6689266098..eeb9cbd989 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -317,7 +317,7 @@ _BUILTIN_COMMAND_EXPANSIONS = { # Disk used/free. "df": [ "exec", - "import uos\nprint('mount \\tsize \\tused \\tavail \\tuse%')\nfor _m in [''] + uos.listdir('/'):\n _s = uos.stat('/' + _m)\n if not _s[0] & 1 << 14: continue\n _s = uos.statvfs(_m)\n if _s[0]:\n _size = _s[0] * _s[2]; _free = _s[0] * _s[3]; print(_m, _size, _size - _free, _free, int(100 * (_size - _free) / _size), sep='\\t')", + "import os\nprint('mount \\tsize \\tused \\tavail \\tuse%')\nfor _m in [''] + os.listdir('/'):\n _s = os.stat('/' + _m)\n if not _s[0] & 1 << 14: continue\n _s = os.statvfs(_m)\n if _s[0]:\n _size = _s[0] * _s[2]; _free = _s[0] * _s[3]; print(_m, _size, _size - _free, _free, int(100 * (_size - _free) / _size), sep='\\t')", ], # Other shortcuts. "reset": { diff --git a/tools/mpremote/mpremote/transport_serial.py b/tools/mpremote/mpremote/transport_serial.py index 84822fe69c..09025c3098 100644 --- a/tools/mpremote/mpremote/transport_serial.py +++ b/tools/mpremote/mpremote/transport_serial.py @@ -292,14 +292,14 @@ class SerialTransport(Transport): def fs_exists(self, src): try: - self.exec("import uos\nuos.stat(%s)" % (("'%s'" % src) if src else "")) + self.exec("import os\nos.stat(%s)" % (("'%s'" % src) if src else "")) return True except TransportError: return False def fs_ls(self, src): cmd = ( - "import uos\nfor f in uos.ilistdir(%s):\n" + "import os\nfor f in os.ilistdir(%s):\n" " print('{:12} {}{}'.format(f[3]if len(f)>3 else 0,f[0],'/'if f[1]&0x4000 else ''))" % (("'%s'" % src) if src else "") ) @@ -311,7 +311,7 @@ class SerialTransport(Transport): def repr_consumer(b): buf.extend(b.replace(b"\x04", b"")) - cmd = "import uos\nfor f in uos.ilistdir(%s):\n" " print(repr(f), end=',')" % ( + cmd = "import os\nfor f in os.ilistdir(%s):\n" " print(repr(f), end=',')" % ( ("'%s'" % src) if src else "" ) try: @@ -328,8 +328,8 @@ class SerialTransport(Transport): def fs_stat(self, src): try: - self.exec("import uos") - return os.stat_result(self.eval("uos.stat(%s)" % (("'%s'" % src)), parse=True)) + self.exec("import os") + return os.stat_result(self.eval("os.stat(%s)" % (("'%s'" % src)), parse=True)) except TransportError as e: reraise_filesystem_error(e, src) @@ -422,13 +422,13 @@ class SerialTransport(Transport): self.exec("f.close()") def fs_mkdir(self, dir): - self.exec("import uos\nuos.mkdir('%s')" % dir) + self.exec("import os\nos.mkdir('%s')" % dir) def fs_rmdir(self, dir): - self.exec("import uos\nuos.rmdir('%s')" % dir) + self.exec("import os\nos.rmdir('%s')" % dir) def fs_rm(self, src): - self.exec("import uos\nuos.remove('%s')" % src) + self.exec("import os\nos.remove('%s')" % src) def fs_touch(self, src): self.exec("f=open('%s','a')\nf.close()" % src) @@ -595,7 +595,7 @@ class SerialTransport(Transport): def umount_local(self): if self.mounted: - self.exec('uos.umount("/remote")') + self.exec('os.umount("/remote")') self.mounted = False self.serial = self.serial.orig_serial @@ -616,18 +616,18 @@ fs_hook_cmds = { } fs_hook_code = """\ -import uos, uio, ustruct, micropython +import os, io, struct, micropython SEEK_SET = 0 class RemoteCommand: def __init__(self): - import uselect, usys + import select, sys self.buf4 = bytearray(4) - self.fout = usys.stdout.buffer - self.fin = usys.stdin.buffer - self.poller = uselect.poll() - self.poller.register(self.fin, uselect.POLLIN) + self.fout = sys.stdout.buffer + self.fin = sys.stdin.buffer + self.poller = select.poll() + self.poller.register(self.fin, select.POLLIN) def poll_in(self): for _ in self.poller.ipoll(1000): @@ -710,7 +710,7 @@ class RemoteCommand: self.fout.write(self.buf4, 1) def wr_s32(self, i): - ustruct.pack_into('3 else 0,f[0],'/'if f[1]&0x4000 else ''))" % (("'%s'" % src) if src else "") ) @@ -528,7 +528,7 @@ class Pyboard: def repr_consumer(b): buf.extend(b.replace(b"\x04", b"")) - cmd = "import uos\nfor f in uos.ilistdir(%s):\n" " print(repr(f), end=',')" % ( + cmd = "import os\nfor f in os.ilistdir(%s):\n" " print(repr(f), end=',')" % ( ("'%s'" % src) if src else "" ) try: @@ -545,8 +545,8 @@ class Pyboard: def fs_stat(self, src): try: - self.exec_("import uos") - return os.stat_result(self.eval("uos.stat(%s)" % (("'%s'" % src)), parse=True)) + self.exec_("import os") + return os.stat_result(self.eval("os.stat(%s)" % (("'%s'" % src)), parse=True)) except PyboardError as e: raise e.convert(src) @@ -639,13 +639,13 @@ class Pyboard: self.exec_("f.close()") def fs_mkdir(self, dir): - self.exec_("import uos\nuos.mkdir('%s')" % dir) + self.exec_("import os\nos.mkdir('%s')" % dir) def fs_rmdir(self, dir): - self.exec_("import uos\nuos.rmdir('%s')" % dir) + self.exec_("import os\nos.rmdir('%s')" % dir) def fs_rm(self, src): - self.exec_("import uos\nuos.remove('%s')" % src) + self.exec_("import os\nos.remove('%s')" % src) def fs_touch(self, src): self.exec_("f=open('%s','a')\nf.close()" % src) @@ -737,9 +737,9 @@ def filesystem_command(pyb, args, progress_callback=None, verbose=False): _injected_import_hook_code = """\ -import uos, uio +import os, io class _FS: - class File(uio.IOBase): + class File(io.IOBase): def __init__(self): self.off = 0 def ioctl(self, request, arg): @@ -756,10 +756,10 @@ class _FS: raise OSError(-2) # ENOENT def open(self, path, mode): return self.File() -uos.mount(_FS(), '/_') -uos.chdir('/_') +os.mount(_FS(), '/_') +os.chdir('/_') from _injected import * -uos.umount('/_') +os.umount('/_') del _injected_buf, _FS """ From 8211d56712301d58970904892da5312b11b2ab7c Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 2 Jun 2023 23:33:42 +1000 Subject: [PATCH 182/565] docs/library/index: Update docs after umodule rename. - Update guide for extending built-in modules. - Remove any last trace of umodule in other docs. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- docs/esp32/tutorial/pwm.rst | 4 +- docs/library/index.rst | 66 +++++++++++-------- docs/library/zephyr.DiskAccess.rst | 2 +- docs/library/zephyr.FlashArea.rst | 2 +- docs/renesas-ra/tutorial/using_peripheral.rst | 5 +- docs/zephyr/quickref.rst | 2 +- 6 files changed, 46 insertions(+), 35 deletions(-) diff --git a/docs/esp32/tutorial/pwm.rst b/docs/esp32/tutorial/pwm.rst index 12d10a86b9..2650284d35 100644 --- a/docs/esp32/tutorial/pwm.rst +++ b/docs/esp32/tutorial/pwm.rst @@ -50,7 +50,7 @@ low all of the time. * Example of a smooth frequency change:: - from utime import sleep + from time import sleep from machine import Pin, PWM F_MIN = 500 @@ -75,7 +75,7 @@ low all of the time. * Example of a smooth duty change:: - from utime import sleep + from time import sleep from machine import Pin, PWM DUTY_MAX = 2**16 - 1 diff --git a/docs/library/index.rst b/docs/library/index.rst index 985a7ad770..e428f3a062 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -191,34 +191,27 @@ The following libraries are specific to the Zephyr port. Extending built-in libraries from Python ---------------------------------------- -Many built-in modules are actually named ``umodule`` rather than ``module``, but -MicroPython will alias any module prefixed with a ``u`` to the non-``u`` -version. This means that, for example, ``import time`` will first attempt to -resolve from the filesystem, and then failing that will fall back to the -built-in ``utime``. On the other hand, ``import utime`` will always go directly -to the built-in. +A subset of the built-in modules are able to be extended by Python code by +providing a module of the same name in the filesystem. This extensibility +applies to the following Python standard library modules which are built-in to +the firmware: ``array``, ``binascii``, ``collections``, ``errno``, ``hashlib``, +``heapq``, ``io``, ``json``, ``os``, ``platform``, ``random``, ``re``, +``select``, ``socket``, ``ssl``, ``struct``, ``time`` ``zlib``, as well as the +MicroPython-specific ``machine`` module. All other built-in modules cannot be +extended from the filesystem. This allows the user to provide an extended implementation of a built-in library (perhaps to provide additional CPython compatibility or missing functionality). -The user-provided module (in ``module.py``) can still use the built-in -functionality by importing ``umodule`` directly (e.g. typically an extension -module ``time.py`` will do ``from utime import *``). This is used extensively -in :term:`micropython-lib`. See :ref:`packages` for more information. +This is used extensively in :term:`micropython-lib`, see :ref:`packages` for +more information. The filesystem module will typically do a wildcard import of +the built-in module in order to inherit all the globals (classes, functions and +variables) from the built-in. -This extensibility applies to the following Python standard library modules -which are built-in to the firmware: ``array``, ``binascii``, ``collections``, -``errno``, ``hashlib``, ``heapq``, ``io``, ``json``, ``os``, ``platform``, -``random``, ``re``, ``select``, ``socket``, ``ssl``, ``struct``, ``sys``, -``time``, ``zlib``, as well as the MicroPython-specific libraries: ``bluepy``, -``bluetooth``, ``machine``, ``timeq``, ``websocket``. All other built-in -modules cannot be extended from the filesystem. - -*Other than when you specifically want to force the use of the built-in module, -we recommend always using* ``import module`` *rather than* ``import umodule``. - -**Note:** In MicroPython v1.21.0 and higher, it is now possible to force an -import of the built-in module by clearing ``sys.path`` during the import. For -example, in ``time.py``, you can write:: +In MicroPython v1.21.0 and higher, to prevent the filesystem module from +importing itself, it can force an import of the built-in module it by +temporarily clearing ``sys.path`` during the import. For example, to extend the +``time`` module from Python, a file named ``time.py`` on the filesystem would +do the following:: _path = sys.path sys.path = () @@ -228,6 +221,25 @@ example, in ``time.py``, you can write:: sys.path = _path del _path -This is now the preferred way (instead of ``from utime import *``), as the -``u``-prefix will be removed from the names of built-in modules in a future -version of MicroPython. + def extra_method(): + pass + +The result is that ``time.py`` contains all the globals of the built-in ``time`` +module, but adds ``extra_method``. + +In earlier versions of MicroPython, you can force an import of a built-in module +by appending a ``u`` to the start of its name. For example, ``import utime`` +instead of ``import time``. For example, ``time.py`` on the filesystem could +look like:: + + from utime import * + + def extra_method(): + pass + +This way is still supported, but the ``sys.path`` method described above is now +preferred as the ``u``-prefix will be removed from the names of built-in +modules in a future version of MicroPython. + +*Other than when it specifically needs to force the use of the built-in module, +code should always use* ``import module`` *rather than* ``import umodule``. diff --git a/docs/library/zephyr.DiskAccess.rst b/docs/library/zephyr.DiskAccess.rst index d19d81a962..3e5fa9a357 100644 --- a/docs/library/zephyr.DiskAccess.rst +++ b/docs/library/zephyr.DiskAccess.rst @@ -34,5 +34,5 @@ Methods These methods implement the simple and extended :ref:`block protocol ` defined by - :class:`uos.AbstractBlockDev`. + :class:`os.AbstractBlockDev`. diff --git a/docs/library/zephyr.FlashArea.rst b/docs/library/zephyr.FlashArea.rst index 306347d449..9cd4dd59d6 100644 --- a/docs/library/zephyr.FlashArea.rst +++ b/docs/library/zephyr.FlashArea.rst @@ -37,4 +37,4 @@ Methods These methods implement the simple and extended :ref:`block protocol ` defined by - :class:`uos.AbstractBlockDev`. + :class:`os.AbstractBlockDev`. diff --git a/docs/renesas-ra/tutorial/using_peripheral.rst b/docs/renesas-ra/tutorial/using_peripheral.rst index c50181b3d6..7296d8b330 100644 --- a/docs/renesas-ra/tutorial/using_peripheral.rst +++ b/docs/renesas-ra/tutorial/using_peripheral.rst @@ -12,9 +12,8 @@ To list supported modules, please enter:: help('modules') -Especially `machine` module and class :ref:`machine.Pin ` are very important for using -peripherals. Note that prefix 'u' is added to the module for MicroPython, -so you can see "umachine" in the list but you can use it like "import machine". +Especially `machine` module and class :ref:`machine.Pin ` are very +important for using peripherals. Using "from machine import Pin", Pin name is available corresponding to the RA MCU's pin name which are Pin.cpu.P000 and 'P000'. diff --git a/docs/zephyr/quickref.rst b/docs/zephyr/quickref.rst index 329a9c41c0..57262ffb5c 100644 --- a/docs/zephyr/quickref.rst +++ b/docs/zephyr/quickref.rst @@ -19,7 +19,7 @@ See the corresponding section of the tutorial: :ref:`intro`. Delay and timing ---------------- -Use the :mod:`time ` module:: +Use the :mod:`time