From 2590c6a53b00f4a0f6341688b291de668896abf1 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Fri, 16 Feb 2024 14:13:45 +0530 Subject: [PATCH 01/11] ports/psoc6: Refactor internal flash code. Signed-off-by: NikhitaR-IFX --- .../CY8CPROTO-062-4343W/mpconfigboard.h | 2 +- .../CY8CPROTO-062-4343W/mpconfigboard.mk | 2 +- ports/psoc6/freeze/vfs_lfs2_qspi_flash.py | 2 +- ports/psoc6/psoc6_flash.c | 49 +++++++++++++------ ports/psoc6/psoc6_qspi_flash.c | 3 -- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h index aee15a934354..877b5d97dadb 100644 --- a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h +++ b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h @@ -12,7 +12,7 @@ #define MICROPY_PY_HASHLIB_SHA256 (1) // Flash type enablement for board -#define MICROPY_PY_EXT_FLASH (1) +#define MICROPY_PY_EXT_FLASH (0) #if (MICROPY_PY_EXT_FLASH) #define EXT_FLASH_BASE (0x00) /** 0x00 */ #define EXT_FLASH_SIZE (0x4000000) /** 64MB */ diff --git a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk index 90b328da6657..a79ac173581b 100644 --- a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk +++ b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk @@ -4,7 +4,7 @@ MICROPY_PY_NETWORK = 1 MICROPY_PSOC6_LWIP = 1 MICROPY_PY_SSL = 1 MICROPY_PSOC6_SSL_MBEDTLS = 1 -MICROPY_PY_EXT_FLASH = 1 +MICROPY_PY_EXT_FLASH = 0 BOARD_VERSION=release-v4.0.0 # Variables to support make-pins diff --git a/ports/psoc6/freeze/vfs_lfs2_qspi_flash.py b/ports/psoc6/freeze/vfs_lfs2_qspi_flash.py index e3dd0ae04124..ba352d863776 100644 --- a/ports/psoc6/freeze/vfs_lfs2_qspi_flash.py +++ b/ports/psoc6/freeze/vfs_lfs2_qspi_flash.py @@ -12,6 +12,6 @@ vfs = os.VfsLfs2(bdev, progsize=read_size, readsize=write_size) os.mount(vfs, "/flash") -print("LFS2 filesystem mounted at /flash\n") +print("External LFS2 filesystem mounted at /flash\n") del machine, os, psoc6, bdev, vfs, read_size, write_size diff --git a/ports/psoc6/psoc6_flash.c b/ports/psoc6/psoc6_flash.c index f2fba9b869b0..f95c457a8b06 100644 --- a/ports/psoc6/psoc6_flash.c +++ b/ports/psoc6/psoc6_flash.c @@ -33,6 +33,7 @@ #include "py/runtime.h" #include "extmod/vfs.h" #include "modpsoc6.h" +#include "mplogger.h" #include "mphalport.h" @@ -83,10 +84,29 @@ STATIC psoc6_flash_obj_t psoc6_flash_obj = { }; cyhal_flash_t cyhal_flash_obj; - +cyhal_flash_info_t flash_info; + +// Helper function to get external flash configurations +void get_flash_info(void) { + mplogger_print("\nRetrieving internal flash info...\n"); + cyhal_flash_get_info(&cyhal_flash_obj, &flash_info); + // mplogger_print("\nTotal flash size (MB): %d\n", cy_serial_flash_qspi_get_size() / (1024 * 1024)); + // mplogger_print("\nSize of erase sector (bytes): %d\n", cy_serial_flash_qspi_get_erase_size(0x00) / (1024)); + // mplogger_print("\nPage size (bytes): %d\n", cy_serial_flash_qspi_get_prog_size(0x00)); +} STATIC mp_obj_t psoc6_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - cyhal_flash_init(&cyhal_flash_obj); + mplogger_print("\nFlash constructor invoked\n"); + get_flash_info(); + + cy_rslt_t result = CY_RSLT_SUCCESS; + + result = cyhal_flash_init(&cyhal_flash_obj); + if (CY_RSLT_SUCCESS != result) { + mplogger_print("psoc6_flash_make_new() failed while initializing flash with error code : %u\n", CY_RSLT_GET_CODE(result)); + mp_raise_msg(&mp_type_Exception, MP_ERROR_TEXT("psoc6_flash_make_new() - QSPI flash init failed !\n")); + } + // Parse arguments enum { ARG_start, ARG_len }; @@ -128,6 +148,8 @@ STATIC mp_obj_t psoc6_flash_make_new(const mp_obj_type_t *type, size_t n_args, s } STATIC mp_obj_t psoc6_flash_readblocks(size_t n_args, const mp_obj_t *args) { + mplogger_print("\nFlash readblocks called\n"); + psoc6_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = mp_obj_get_int(args[1]) * BLOCK_SIZE_BYTES; mp_buffer_info_t bufinfo; @@ -138,9 +160,9 @@ STATIC mp_obj_t psoc6_flash_readblocks(size_t n_args, const mp_obj_t *args) { } cy_rslt_t result = cyhal_flash_read(&cyhal_flash_obj, self->flash_base + offset, bufinfo.buf, bufinfo.len); - if (CY_RSLT_SUCCESS != result) { - mp_raise_ValueError(MP_ERROR_TEXT("cyhal_rtc_read failed !")); + mplogger_print("psoc6_flash_readblocks() failed while reading the flash with error code: %u\n", CY_RSLT_GET_CODE(result)); + mp_raise_ValueError(MP_ERROR_TEXT("psoc6_flash_readblocks() - Flash Read failed !")); } // TODO: or simply do it like this ? @@ -151,28 +173,25 @@ STATIC mp_obj_t psoc6_flash_readblocks(size_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(psoc6_flash_readblocks_obj, 3, 4, psoc6_flash_readblocks); STATIC mp_obj_t psoc6_flash_writeblocks(size_t n_args, const mp_obj_t *args) { - + mplogger_print("\nFlash writeblocks called\n"); psoc6_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = mp_obj_get_int(args[1]) * BLOCK_SIZE_BYTES; mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); if (n_args == 3) { - // Flash erase/program must run in an atomic section. mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); - uint32_t numSectors = bufinfo.len / FLASH_SECTOR_SIZE; for (uint32_t i = 0; i <= numSectors; ++i) { cy_rslt_t result = cyhal_flash_erase(&cyhal_flash_obj, self->flash_base + offset + i * FLASH_SECTOR_SIZE); if (CY_RSLT_SUCCESS != result) { - mp_raise_ValueError(MP_ERROR_TEXT("cyhal_rtc_read failed !")); + mplogger_print("\npsoc6_flash_writeblocks() failed while erasing the flash with error code: %u\n", CY_RSLT_GET_CODE(result)); + mp_raise_ValueError(MP_ERROR_TEXT("psoc6_flash_writeblocks() - Flash Erase failed !")); } } - MICROPY_END_ATOMIC_SECTION(atomic_state); - // TODO: check return value } else { offset += mp_obj_get_int(args[3]); } @@ -182,22 +201,22 @@ STATIC mp_obj_t psoc6_flash_writeblocks(size_t n_args, const mp_obj_t *args) { mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); uint32_t numPages = bufinfo.len / FLASH_SECTOR_SIZE; // TODO: should be page size - for (uint32_t i = 0; i <= numPages; ++i) { cy_rslt_t result = cyhal_flash_program(&cyhal_flash_obj, self->flash_base + offset + i * FLASH_SECTOR_SIZE, bufinfo.buf + i * FLASH_SECTOR_SIZE); if (CY_RSLT_SUCCESS != result) { - mp_raise_ValueError(MP_ERROR_TEXT("cyhal_rtc_read failed !")); + mplogger_print("\npsoc6_flash_writeblocks() failed while writing with error code: %u\n", CY_RSLT_GET_CODE(result)); + mp_raise_ValueError(MP_ERROR_TEXT("\npsoc6_flash_writeblocks() - Flash Program failed!")); } } MICROPY_END_ATOMIC_SECTION(atomic_state); - // TODO: check return value return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(psoc6_flash_writeblocks_obj, 3, 4, psoc6_flash_writeblocks); STATIC mp_obj_t psoc6_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { + mplogger_print("QSPI flash ioctrl called\n"); psoc6_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); @@ -219,11 +238,11 @@ STATIC mp_obj_t psoc6_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t ar cy_rslt_t result = cyhal_flash_erase(&cyhal_flash_obj, self->flash_base + offset); if (CY_RSLT_SUCCESS != result) { - mp_raise_ValueError(MP_ERROR_TEXT("cyhal_rtc_read failed !")); + mplogger_print("psoc6_flash_ioctl() failed while erasing block with error code: %u\n", CY_RSLT_GET_CODE(result)); + mp_raise_ValueError(MP_ERROR_TEXT("psoc6_flash_ioctl() - Flash erase failed !")); } MICROPY_END_ATOMIC_SECTION(atomic_state); - // TODO: check return value return MP_OBJ_NEW_SMALL_INT(0); } default: diff --git a/ports/psoc6/psoc6_qspi_flash.c b/ports/psoc6/psoc6_qspi_flash.c index 2dfd69751bcb..1c7576cb3d3a 100644 --- a/ports/psoc6/psoc6_qspi_flash.c +++ b/ports/psoc6/psoc6_qspi_flash.c @@ -155,7 +155,6 @@ STATIC mp_obj_t psoc6_qspi_flash_readblocks(size_t n_args, const mp_obj_t *args) if (n_args == 4) { offset += mp_obj_get_int(args[3]); } - mplogger_print("Address in hex:%04X, Length:%u\n", self->flash_base + offset, bufinfo.len); mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); cy_rslt_t result = cy_serial_flash_qspi_read(self->flash_base + offset, bufinfo.len, bufinfo.buf); @@ -182,7 +181,6 @@ STATIC mp_obj_t psoc6_qspi_flash_writeblocks(size_t n_args, const mp_obj_t *args uint32_t numSectors = bufinfo.len / EXT_FLASH_SECTOR_SIZE; for (uint32_t i = 0; i <= numSectors; ++i) { - mplogger_print("Address in hex:%04X\n", self->flash_base + offset + i * EXT_FLASH_SECTOR_SIZE); cy_rslt_t result = cy_serial_flash_qspi_erase(self->flash_base + offset + i * EXT_FLASH_SECTOR_SIZE, cy_serial_flash_qspi_get_erase_size(self->flash_base + offset + i * EXT_FLASH_SECTOR_SIZE)); // the cy_serial_flash_qspi_get_erase_size() function call is necessary to keep the erase at sector boundary, else it throws errors. @@ -214,7 +212,6 @@ STATIC mp_obj_t psoc6_qspi_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj mplogger_print("QSPI flash ioctrl called\n"); psoc6_qspi_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); - mplogger_print("option:%u\n", cmd); switch (cmd) { case MP_BLOCKDEV_IOCTL_INIT: From 80a85ed72269e9294ed80755e78b71c3db7c7c0f Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Tue, 20 Feb 2024 15:24:50 +0530 Subject: [PATCH 02/11] ports/psoc6: Refactored internal flash code. Signed-off-by: NikhitaR-IFX --- ports/psoc6/freeze/vfs_lfs2.py | 2 +- ports/psoc6/psoc6_flash.c | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/ports/psoc6/freeze/vfs_lfs2.py b/ports/psoc6/freeze/vfs_lfs2.py index ca4ecf66b706..77eaa23e2bb6 100644 --- a/ports/psoc6/freeze/vfs_lfs2.py +++ b/ports/psoc6/freeze/vfs_lfs2.py @@ -24,6 +24,6 @@ vfs = os.VfsLfs2(bdev, progsize=write_size, readsize=read_size) os.mount(vfs, "/") -print("LFS2 filesystem mounted at /\n") +print("Internal LFS2 filesystem mounted at /\n") del machine, os, psoc6, bdev, vfs, read_size, write_size diff --git a/ports/psoc6/psoc6_flash.c b/ports/psoc6/psoc6_flash.c index f95c457a8b06..9488de821c7c 100644 --- a/ports/psoc6/psoc6_flash.c +++ b/ports/psoc6/psoc6_flash.c @@ -200,14 +200,10 @@ STATIC mp_obj_t psoc6_flash_writeblocks(size_t n_args, const mp_obj_t *args) { // Flash erase/program must run in an atomic section. mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); - uint32_t numPages = bufinfo.len / FLASH_SECTOR_SIZE; // TODO: should be page size - for (uint32_t i = 0; i <= numPages; ++i) { - cy_rslt_t result = cyhal_flash_program(&cyhal_flash_obj, self->flash_base + offset + i * FLASH_SECTOR_SIZE, bufinfo.buf + i * FLASH_SECTOR_SIZE); - - if (CY_RSLT_SUCCESS != result) { - mplogger_print("\npsoc6_flash_writeblocks() failed while writing with error code: %u\n", CY_RSLT_GET_CODE(result)); - mp_raise_ValueError(MP_ERROR_TEXT("\npsoc6_flash_writeblocks() - Flash Program failed!")); - } + cy_rslt_t result = cyhal_flash_write(&cyhal_flash_obj, self->flash_base + offset, bufinfo.buf); + if (CY_RSLT_SUCCESS != result) { + mplogger_print("psoc6_qspi_flash_writeblocks() failed while writing with error code: %u\n", CY_RSLT_GET_CODE(result)); + mp_raise_ValueError(MP_ERROR_TEXT("psoc6_qspi_flash_writeblocks() - QSPI Flash Write failed!")); } MICROPY_END_ATOMIC_SECTION(atomic_state); From 593cdad5a1f643f51ca637482cbf3274fca04e27 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Tue, 20 Feb 2024 16:12:15 +0530 Subject: [PATCH 03/11] .github/workflows: Enable flash tests for BLE board. Signed-off-by: NikhitaR-IFX --- .github/workflows/ports_psoc6.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ports_psoc6.yml b/.github/workflows/ports_psoc6.yml index 968436ba0ec9..e6458c1dddfc 100644 --- a/.github/workflows/ports_psoc6.yml +++ b/.github/workflows/ports_psoc6.yml @@ -67,7 +67,6 @@ jobs: cp mpy-psoc6_${{ matrix.board }}_${{ needs.server-build.outputs.commit_sha }}/firmware.hex . source tools/ci.sh && ci_psoc6_flash_multiple_devices ${{ matrix.board }} firmware.hex tools/psoc6/${{ runner.name }}-devs.yml - name: Run psoc6 filesystem test - if: matrix.board == 'CY8CPROTO-062-4343W' run: | devs=($(python tools/psoc6/get-devs.py port -b ${{ matrix.board }} -y tools/psoc6/${{ runner.name }}-devs.yml)) cd tests From ed1c93ba6666ffb8331460a171d510c2ab65e7cb Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Tue, 20 Feb 2024 16:27:19 +0530 Subject: [PATCH 04/11] tests/psoc6: Enable flash test for BLE board. Signed-off-by: NikhitaR-IFX --- tests/psoc6/flash.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/psoc6/flash.py b/tests/psoc6/flash.py index 7cde88f97ffc..6d60bdd31c6e 100644 --- a/tests/psoc6/flash.py +++ b/tests/psoc6/flash.py @@ -1,10 +1,6 @@ import os, psoc6 machine = os.uname().machine -if "CY8CPROTO-063-BLE" in machine: - # TODO: Not working for this board. Neither the timer timing is correct - print("SKIP") - raise SystemExit # Try to mount the filesystem, and format the flash if it doesn't exist. # create block device object based on whichever flash is active From ab77409d147d94de33f776e6fa61e4f0a6cbf1b5 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Wed, 21 Feb 2024 20:49:12 +0530 Subject: [PATCH 05/11] tests/psoc6: Final changes for fs tests. Signed-off-by: NikhitaR-IFX --- ports/psoc6/psoc6_flash.c | 28 +++++++-- ports/psoc6/psoc6_qspi_flash.c | 2 + tests/psoc6/run_psoc6_tests.sh | 37 ++--------- tests/psoc6/test_scripts/fs.py | 80 ++++++++++++++++++++++++ tests/psoc6/test_scripts/fs_adv.py.exp | 3 + tests/psoc6/test_scripts/fs_basic.py.exp | 1 + 6 files changed, 114 insertions(+), 37 deletions(-) create mode 100755 tests/psoc6/test_scripts/fs.py create mode 100644 tests/psoc6/test_scripts/fs_adv.py.exp create mode 100644 tests/psoc6/test_scripts/fs_basic.py.exp diff --git a/ports/psoc6/psoc6_flash.c b/ports/psoc6/psoc6_flash.c index 9488de821c7c..8a85e7c5bd47 100644 --- a/ports/psoc6/psoc6_flash.c +++ b/ports/psoc6/psoc6_flash.c @@ -86,18 +86,38 @@ STATIC psoc6_flash_obj_t psoc6_flash_obj = { cyhal_flash_t cyhal_flash_obj; cyhal_flash_info_t flash_info; -// Helper function to get external flash configurations +// Helper function to get internal flash configurations void get_flash_info(void) { mplogger_print("\nRetrieving internal flash info...\n"); cyhal_flash_get_info(&cyhal_flash_obj, &flash_info); - // mplogger_print("\nTotal flash size (MB): %d\n", cy_serial_flash_qspi_get_size() / (1024 * 1024)); - // mplogger_print("\nSize of erase sector (bytes): %d\n", cy_serial_flash_qspi_get_erase_size(0x00) / (1024)); - // mplogger_print("\nPage size (bytes): %d\n", cy_serial_flash_qspi_get_prog_size(0x00)); + /* Wait for 100ms for the flash write to complete */ + uint32_t timeout = 100; + /* Wait for the command to finish execution */ + while ((true != cyhal_flash_is_operation_complete(&cyhal_flash_obj)) && (0 < timeout)) { + timeout--; + cyhal_system_delay_ms(1); /* delay one millisecond each iteration */ + } + uint32_t total_flash_size = 0; + uint32_t page_size = 0; + if (0 != timeout) { + for (int index = 0; index < flash_info.block_count; index++) + { + const cyhal_flash_block_info_t *block_info = flash_info.blocks; + total_flash_size += block_info->size; + page_size = block_info->page_size; + } + } + + mplogger_print("\nTotal flash size (MB): %ld\n", total_flash_size / (1024 * 1024)); + mplogger_print("\nTotal no. of blocks: %d\n", flash_info.block_count); + mplogger_print("\nPage size (bytes): %ld\n", page_size); } STATIC mp_obj_t psoc6_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mplogger_print("\nFlash constructor invoked\n"); + #if MICROPY_LOGGER_DEBUG get_flash_info(); + #endif cy_rslt_t result = CY_RSLT_SUCCESS; diff --git a/ports/psoc6/psoc6_qspi_flash.c b/ports/psoc6/psoc6_qspi_flash.c index 1c7576cb3d3a..5c060c58afb2 100644 --- a/ports/psoc6/psoc6_qspi_flash.c +++ b/ports/psoc6/psoc6_qspi_flash.c @@ -89,7 +89,9 @@ void get_ext_flash_info(void) { STATIC mp_obj_t psoc6_qspi_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mplogger_print("\nQSPI flash constructor invoked\n"); + #if MICROPY_LOGGER_DEBUG get_ext_flash_info(); + #endif cy_rslt_t result = CY_RSLT_SUCCESS; diff --git a/tests/psoc6/run_psoc6_tests.sh b/tests/psoc6/run_psoc6_tests.sh index 72a3946b61ba..c7caaeb858dd 100755 --- a/tests/psoc6/run_psoc6_tests.sh +++ b/tests/psoc6/run_psoc6_tests.sh @@ -259,49 +259,20 @@ if [ ${fs} -eq 1 ]; then echo echo " done." echo + + chmod 777 ./psoc6/test_scripts/fs.py - echo " attempting to save different test files in flash " - echo - echo " saving test_fs_small_file.txt to FS - (size : 10KB) " - - command_output=$( ../tools/mpremote/mpremote.py connect ${device0} cp ./psoc6/test_inputs/test_fs_small_file.txt :/) - exp_output="cp ./psoc6/test_inputs/test_fs_small_file.txt :/" - if [ "$command_output" != "$exp_output" ]; then - echo "Error: Cannot save small file." - exit 1 - fi + python3 ./psoc6/test_scripts/fs.py ${device0} 0 # On device file saving tests for medium and large size takes considerable amount of time. Hence only when needed, this should be triggered. if [ ${afs} -eq 1 ]; then - - echo " saving test_fs_medium_file.txt to FS - (size : 500KB) " - command_output=$(../tools/mpremote/mpremote.py connect ${device0} cp ./psoc6/test_inputs/test_fs_medium_file.txt :/) - exp_output="cp ./psoc6/test_inputs/test_fs_medium_file.txt :/" - if [ "$command_output" != "$exp_output" ]; then - echo "Error: Cannot save medium file." - exit 1 - fi - - echo " saving test_fs_large_file.txt to FS - (size : 1MB) " - command_output=$(../tools/mpremote/mpremote.py connect ${device0} cp ./psoc6/test_inputs/test_fs_large_file.txt :/) - exp_output="cp ./psoc6/test_inputs/test_fs_large_file.txt :/" - if [ "$command_output" != "$exp_output" ]; then - echo "Error: Cannot save large file." - exit 1 - fi - + python3 ./psoc6/test_scripts/fs.py ${device0} 1 fi - echo - echo " done." - echo - fi - if [ ${implemented} -eq 1 ]; then - echo " running implemented tests ..." echo diff --git a/tests/psoc6/test_scripts/fs.py b/tests/psoc6/test_scripts/fs.py new file mode 100755 index 000000000000..36c05af95d80 --- /dev/null +++ b/tests/psoc6/test_scripts/fs.py @@ -0,0 +1,80 @@ +import subprocess +import sys + +device = sys.argv[1] +test_type = sys.argv[2] + +# local and remote(MPY device) paths +local_small_file_path = "./psoc6/test_inputs/test_fs_small_file.txt" +local_medium_file_path = "./psoc6/test_inputs/test_fs_medium_file.txt" +local_large_file_path = "./psoc6/test_inputs/test_fs_large_file.txt" +remote_directory_path = "/" + +# out and exp file paths +basic_test_op_fp = "./psoc6/test_scripts/results/fs_basic.py.out" +adv_test_op_fp = "./psoc6/test_scripts/results/fs_adv.py.out" +exp_basic_op_fp = "./psoc6/test_scripts/fs_basic.py.exp" +exp_adv_op_fp = "./psoc6/test_scripts/fs_adv.py.exp" + +# List of mpremote commands +mpr_connect = f"../tools/mpremote/mpremote.py connect {device}" +mpr_small_file_cp = f"{mpr_connect} cp {local_small_file_path} :{remote_directory_path}" +mpr_medium_file_cp = f"{mpr_connect} cp {local_medium_file_path} :{remote_directory_path}" +mpr_large_file_cp = f"{mpr_connect} cp {local_large_file_path} :{remote_directory_path}" +mpr_ls = f"{mpr_connect} fs ls /" +mpr_rm = f"{mpr_connect} fs rm " + + +def exec(cmd, op_file_path="null"): + if cmd == mpr_rm: + # Check if file is present already + output = subprocess.run(f"{mpr_ls} | grep {op_file_path}", shell=True, capture_output=True) + # If the file is present, remove it + if output.returncode == 0: + subprocess.run(f"{cmd} {op_file_path}", shell=True, capture_output=False) + else: + print(op_file_path) + with open(op_file_path, "a") as file: + subprocess.call(cmd, shell=True, stdout=file) + + +def validate_test(op, exp_op): + with open(op, "r") as output_file: + output = output_file.read() + + with open(exp_op, "r") as exp_output_file: + exp_output = exp_output_file.read() + + if output == exp_output: + print("Operation failed!") + sys.exit(1) + else: + print("Operation successful!") + + +def fs_basic_test(): + print("Running basic test") + print("Saving small file - 10KB") + exec(mpr_rm, "test_fs_small_file.txt") + exec(mpr_small_file_cp, basic_test_op_fp) + validate_test(basic_test_op_fp, exp_basic_op_fp) + + +def fs_adv_test(): + print("Running advance test") + print("Saving small files - 10KB") + exec(mpr_rm, "test_fs_small_file.txt") + exec(mpr_small_file_cp, adv_test_op_fp) + print("Saving medium files - 500KB") + exec(mpr_rm, "test_fs_medium_file.txt") + exec(mpr_medium_file_cp, adv_test_op_fp) + print("Saving large files - 1MB") + exec(mpr_rm, "test_fs_large_file.txt") + exec(mpr_large_file_cp, adv_test_op_fp) + validate_test(adv_test_op_fp, exp_adv_op_fp) + + +if test_type == "0": + fs_basic_test() +if test_type == "1": + fs_adv_test() diff --git a/tests/psoc6/test_scripts/fs_adv.py.exp b/tests/psoc6/test_scripts/fs_adv.py.exp new file mode 100644 index 000000000000..96ad71fa4bc0 --- /dev/null +++ b/tests/psoc6/test_scripts/fs_adv.py.exp @@ -0,0 +1,3 @@ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ +cp ./psoc6/test_inputs/test_fs_large_file.txt :/ diff --git a/tests/psoc6/test_scripts/fs_basic.py.exp b/tests/psoc6/test_scripts/fs_basic.py.exp new file mode 100644 index 000000000000..7c2dd0bc411e --- /dev/null +++ b/tests/psoc6/test_scripts/fs_basic.py.exp @@ -0,0 +1 @@ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ From 9db59b357fd41bef3cfaee3c22309c354898dcbf Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Wed, 21 Feb 2024 20:58:35 +0530 Subject: [PATCH 06/11] tests/psoc6: Adding exp files. Signed-off-by: NikhitaR-IFX --- tests/psoc6/test_scripts/results/fs_adv.py.out | 12 ++++++++++++ tests/psoc6/test_scripts/results/fs_basic.py.out | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/psoc6/test_scripts/results/fs_adv.py.out create mode 100644 tests/psoc6/test_scripts/results/fs_basic.py.out diff --git a/tests/psoc6/test_scripts/results/fs_adv.py.out b/tests/psoc6/test_scripts/results/fs_adv.py.out new file mode 100644 index 000000000000..17532666405a --- /dev/null +++ b/tests/psoc6/test_scripts/results/fs_adv.py.out @@ -0,0 +1,12 @@ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ +cp ./psoc6/test_inputs/test_fs_large_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ +cp ./psoc6/test_inputs/test_fs_large_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ +cp ./psoc6/test_inputs/test_fs_large_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ +cp ./psoc6/test_inputs/test_fs_large_file.txt :/ diff --git a/tests/psoc6/test_scripts/results/fs_basic.py.out b/tests/psoc6/test_scripts/results/fs_basic.py.out new file mode 100644 index 000000000000..8627ef6e405a --- /dev/null +++ b/tests/psoc6/test_scripts/results/fs_basic.py.out @@ -0,0 +1,7 @@ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ +cp ./psoc6/test_inputs/test_fs_small_file.txt :/ From 5cb58c379d3ff6a918fce03cfbe99db32678863a Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Wed, 21 Feb 2024 21:12:26 +0530 Subject: [PATCH 07/11] tests/psoc6: Fixing paths. Signed-off-by: NikhitaR-IFX --- tests/psoc6/test_scripts/fs.py | 8 +++++--- tests/psoc6/test_scripts/results/fs_adv.py.out | 12 ------------ tests/psoc6/test_scripts/results/fs_basic.py.out | 7 ------- 3 files changed, 5 insertions(+), 22 deletions(-) delete mode 100644 tests/psoc6/test_scripts/results/fs_adv.py.out delete mode 100644 tests/psoc6/test_scripts/results/fs_basic.py.out diff --git a/tests/psoc6/test_scripts/fs.py b/tests/psoc6/test_scripts/fs.py index 36c05af95d80..454d74baa0ed 100755 --- a/tests/psoc6/test_scripts/fs.py +++ b/tests/psoc6/test_scripts/fs.py @@ -1,5 +1,6 @@ import subprocess import sys +import os device = sys.argv[1] test_type = sys.argv[2] @@ -11,8 +12,8 @@ remote_directory_path = "/" # out and exp file paths -basic_test_op_fp = "./psoc6/test_scripts/results/fs_basic.py.out" -adv_test_op_fp = "./psoc6/test_scripts/results/fs_adv.py.out" +basic_test_op_fp = "./psoc6/test_scripts/fs_basic.py.out" +adv_test_op_fp = "./psoc6/test_scripts/fs_adv.py.out" exp_basic_op_fp = "./psoc6/test_scripts/fs_basic.py.exp" exp_adv_op_fp = "./psoc6/test_scripts/fs_adv.py.exp" @@ -33,7 +34,6 @@ def exec(cmd, op_file_path="null"): if output.returncode == 0: subprocess.run(f"{cmd} {op_file_path}", shell=True, capture_output=False) else: - print(op_file_path) with open(op_file_path, "a") as file: subprocess.call(cmd, shell=True, stdout=file) @@ -58,6 +58,7 @@ def fs_basic_test(): exec(mpr_rm, "test_fs_small_file.txt") exec(mpr_small_file_cp, basic_test_op_fp) validate_test(basic_test_op_fp, exp_basic_op_fp) + os.remove(basic_test_op_fp) def fs_adv_test(): @@ -72,6 +73,7 @@ def fs_adv_test(): exec(mpr_rm, "test_fs_large_file.txt") exec(mpr_large_file_cp, adv_test_op_fp) validate_test(adv_test_op_fp, exp_adv_op_fp) + os.remove(adv_test_op_fp_test_op_fp) if test_type == "0": diff --git a/tests/psoc6/test_scripts/results/fs_adv.py.out b/tests/psoc6/test_scripts/results/fs_adv.py.out deleted file mode 100644 index 17532666405a..000000000000 --- a/tests/psoc6/test_scripts/results/fs_adv.py.out +++ /dev/null @@ -1,12 +0,0 @@ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ -cp ./psoc6/test_inputs/test_fs_large_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ -cp ./psoc6/test_inputs/test_fs_large_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ -cp ./psoc6/test_inputs/test_fs_large_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_medium_file.txt :/ -cp ./psoc6/test_inputs/test_fs_large_file.txt :/ diff --git a/tests/psoc6/test_scripts/results/fs_basic.py.out b/tests/psoc6/test_scripts/results/fs_basic.py.out deleted file mode 100644 index 8627ef6e405a..000000000000 --- a/tests/psoc6/test_scripts/results/fs_basic.py.out +++ /dev/null @@ -1,7 +0,0 @@ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ -cp ./psoc6/test_inputs/test_fs_small_file.txt :/ From 7215290f1d2e636891188e19cf3f7fbe7503431e Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Wed, 21 Feb 2024 21:18:32 +0530 Subject: [PATCH 08/11] tests/psoc6: Test exit on failure. Signed-off-by: NikhitaR-IFX --- tests/psoc6/run_psoc6_tests.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/psoc6/run_psoc6_tests.sh b/tests/psoc6/run_psoc6_tests.sh index c7caaeb858dd..cd741eb293e5 100755 --- a/tests/psoc6/run_psoc6_tests.sh +++ b/tests/psoc6/run_psoc6_tests.sh @@ -263,10 +263,18 @@ if [ ${fs} -eq 1 ]; then chmod 777 ./psoc6/test_scripts/fs.py python3 ./psoc6/test_scripts/fs.py ${device0} 0 + if [ $? -ne 0 ]; then + echo "FS test failed" + exit 1 + fi # On device file saving tests for medium and large size takes considerable amount of time. Hence only when needed, this should be triggered. if [ ${afs} -eq 1 ]; then - python3 ./psoc6/test_scripts/fs.py ${device0} 1 + python3 ./psoc6/test_scripts/fs.py ${device0} 1 + if [ $? -ne 0 ]; then + echo "FS test failed" + exit 1 + fi fi fi From db07d24007b8701daf73ee41efb7a96d1853c8ad Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Wed, 21 Feb 2024 23:14:31 +0530 Subject: [PATCH 09/11] tests/psoc6: Fixed test failure. Signed-off-by: NikhitaR-IFX --- tests/psoc6/test_scripts/fs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/psoc6/test_scripts/fs.py b/tests/psoc6/test_scripts/fs.py index 454d74baa0ed..c3d04de992a8 100755 --- a/tests/psoc6/test_scripts/fs.py +++ b/tests/psoc6/test_scripts/fs.py @@ -35,17 +35,17 @@ def exec(cmd, op_file_path="null"): subprocess.run(f"{cmd} {op_file_path}", shell=True, capture_output=False) else: with open(op_file_path, "a") as file: - subprocess.call(cmd, shell=True, stdout=file) + subprocess.check_call(cmd, shell=True, stdout=file) def validate_test(op, exp_op): with open(op, "r") as output_file: - output = output_file.read() + output = [line.strip() for line in output_file] with open(exp_op, "r") as exp_output_file: - exp_output = exp_output_file.read() + exp_output = [line.strip() for line in exp_output_file] - if output == exp_output: + if output != exp_output: print("Operation failed!") sys.exit(1) else: @@ -73,7 +73,7 @@ def fs_adv_test(): exec(mpr_rm, "test_fs_large_file.txt") exec(mpr_large_file_cp, adv_test_op_fp) validate_test(adv_test_op_fp, exp_adv_op_fp) - os.remove(adv_test_op_fp_test_op_fp) + os.remove(adv_test_op_fp) if test_type == "0": From dc260e75157649f6d597692dd6fb825d615d65b4 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Wed, 21 Feb 2024 23:28:20 +0530 Subject: [PATCH 10/11] ports/psoc6: Finxinf typos. Signed-off-by: NikhitaR-IFX --- ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h | 2 +- ports/psoc6/psoc6_flash.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h index 877b5d97dadb..aee15a934354 100644 --- a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h +++ b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h @@ -12,7 +12,7 @@ #define MICROPY_PY_HASHLIB_SHA256 (1) // Flash type enablement for board -#define MICROPY_PY_EXT_FLASH (0) +#define MICROPY_PY_EXT_FLASH (1) #if (MICROPY_PY_EXT_FLASH) #define EXT_FLASH_BASE (0x00) /** 0x00 */ #define EXT_FLASH_SIZE (0x4000000) /** 64MB */ diff --git a/ports/psoc6/psoc6_flash.c b/ports/psoc6/psoc6_flash.c index 8a85e7c5bd47..8e1fa02af2d6 100644 --- a/ports/psoc6/psoc6_flash.c +++ b/ports/psoc6/psoc6_flash.c @@ -222,8 +222,8 @@ STATIC mp_obj_t psoc6_flash_writeblocks(size_t n_args, const mp_obj_t *args) { cy_rslt_t result = cyhal_flash_write(&cyhal_flash_obj, self->flash_base + offset, bufinfo.buf); if (CY_RSLT_SUCCESS != result) { - mplogger_print("psoc6_qspi_flash_writeblocks() failed while writing with error code: %u\n", CY_RSLT_GET_CODE(result)); - mp_raise_ValueError(MP_ERROR_TEXT("psoc6_qspi_flash_writeblocks() - QSPI Flash Write failed!")); + mplogger_print("psoc6_flash_writeblocks() failed while writing with error code: %u\n", CY_RSLT_GET_CODE(result)); + mp_raise_ValueError(MP_ERROR_TEXT("psoc6_flash_writeblocks() - Flash Write failed!")); } MICROPY_END_ATOMIC_SECTION(atomic_state); @@ -232,7 +232,7 @@ STATIC mp_obj_t psoc6_flash_writeblocks(size_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(psoc6_flash_writeblocks_obj, 3, 4, psoc6_flash_writeblocks); STATIC mp_obj_t psoc6_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { - mplogger_print("QSPI flash ioctrl called\n"); + mplogger_print("Flash ioctrl called\n"); psoc6_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); From 6c1b9fb25e57eabbe905b9f4fb3111982ee22a04 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Wed, 21 Feb 2024 23:37:06 +0530 Subject: [PATCH 11/11] ports/psoc6: Fixing typos. Signed-off-by: NikhitaR-IFX --- ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk index a79ac173581b..90b328da6657 100644 --- a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk +++ b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.mk @@ -4,7 +4,7 @@ MICROPY_PY_NETWORK = 1 MICROPY_PSOC6_LWIP = 1 MICROPY_PY_SSL = 1 MICROPY_PSOC6_SSL_MBEDTLS = 1 -MICROPY_PY_EXT_FLASH = 0 +MICROPY_PY_EXT_FLASH = 1 BOARD_VERSION=release-v4.0.0 # Variables to support make-pins