From 442835e8975d357e2fc93eaa6c6e4dce4bd1428b Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Thu, 21 Sep 2023 18:16:11 +0200 Subject: [PATCH 1/4] ports/psoc6: WIP Flash memory configuration per board. Signed-off-by: enriquezgarc --- ports/psoc6/.gitignore | 2 ++ ports/psoc6/modules/psoc6/psoc6_flash.c | 22 +++++++++++++++++++--- ports/psoc6/mpconfigport.h | 3 ++- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 ports/psoc6/.gitignore diff --git a/ports/psoc6/.gitignore b/ports/psoc6/.gitignore new file mode 100644 index 000000000000..7e5f7fa36a30 --- /dev/null +++ b/ports/psoc6/.gitignore @@ -0,0 +1,2 @@ +/mtb_shared +../../tools/psoc6/local-devs.yml \ No newline at end of file diff --git a/ports/psoc6/modules/psoc6/psoc6_flash.c b/ports/psoc6/modules/psoc6/psoc6_flash.c index 1bac10e5027b..d6af326daa77 100644 --- a/ports/psoc6/modules/psoc6/psoc6_flash.c +++ b/ports/psoc6/modules/psoc6/psoc6_flash.c @@ -38,10 +38,26 @@ // MTB includes #include "cyhal.h" -#define FLASH_BASE_TRUE (0x10000000) +#if defined(CY8C624ABZI_S2D44) +#define DEVICE_FLASH_SIZE (0x00200000) // 2MB +#define DEVICE_FLASH_BASE_ADDRESS (0x101A0000) // Where is this value coming from?? -#define FLASH_BASE (0x101A0000) -#define FLASH_SIZE (0x00200000 - (FLASH_BASE - FLASH_BASE_TRUE)) +#elif defined(CYBLE_416045_02_device) +#define DEVICE_FLASH_SIZE (0x00100000) // 1MB +#define DEVICE_FLASH_BASE_ADDRESS (0x100A0000) // Where is this value coming from?? + +#else +#error "MCU not supported." +#endif + + +#define FLASH_BASE_TRUE (0x10000000) + +// #define FLASH_BASE (0x101A0000) +// #define FLASH_SIZE (0x00200000 - (FLASH_BASE - FLASH_BASE_TRUE)) + +#define FLASH_BASE DEVICE_FLASH_BASE_ADDRESS +#define FLASH_SIZE (DEVICE_FLASH_SIZE - (FLASH_BASE - FLASH_BASE_TRUE)) #define FLASH_SECTOR_SIZE (0x200) #define BLOCK_SIZE_BYTES (FLASH_SECTOR_SIZE) diff --git a/ports/psoc6/mpconfigport.h b/ports/psoc6/mpconfigport.h index 28c74cf9388d..9dd61a796454 100644 --- a/ports/psoc6/mpconfigport.h +++ b/ports/psoc6/mpconfigport.h @@ -60,7 +60,8 @@ // #define MICROPY_GC_STACK_ENTRY_TYPE uint16_t #define MICROPY_GC_STACK_ENTRY_TYPE uint32_t #define MICROPY_ENABLE_GC (1) -#define MICROPY_GC_HEAP_SIZE (256 * 1024) +// #define MICROPY_GC_HEAP_SIZE (256 * 1024) //256 kb sectors -> 1 sector (0.25 of 2 MB flash) +#define MICROPY_GC_HEAP_SIZE (128 * 1024) // 32 kb #define MICROPY_MEM_STATS (1) #define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1) From 280ef6e22a170d8c0c222fc462bdae9d2080ab4e Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Mon, 25 Sep 2023 09:29:46 +0200 Subject: [PATCH 2/4] ports/psoc6: Adapting deps and config for multi bsp. Signed-off-by: enriquezgarc --- .../CY8CPROTO-062-4343W/mpconfigboard.h | 7 +++++++ .../boards/CY8CPROTO-063-BLE/mpconfigboard.h | 8 ++++++++ .../boards/CY8CPROTO-063-BLE/mpconfigboard.mk | 4 ++-- ports/psoc6/modules/psoc6/psoc6_flash.c | 5 +---- ports/psoc6/mpconfigport.h | 20 ++++++------------- ports/psoc6/mpconfigport.mk | 1 - ports/psoc6/mtb-libs/Makefile | 16 +++++++++++++-- .../cy-mbedtls-acceleration.mtb | 0 .../deps/{common => crypto}/mbedtls.mtb | 0 ports/psoc6/mtb-libs/makefile_mtb.mk | 6 +++++- 10 files changed, 43 insertions(+), 24 deletions(-) rename ports/psoc6/mtb-libs/deps/{common => crypto}/cy-mbedtls-acceleration.mtb (100%) rename ports/psoc6/mtb-libs/deps/{common => crypto}/mbedtls.mtb (100%) diff --git a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h index 68266f143618..92d32a558b24 100644 --- a/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h +++ b/ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h @@ -3,3 +3,10 @@ #define MICROPY_HW_BOARD_NAME "CY8CPROTO-062-4343W" #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "CY8C-062-4343W" + +#define MICROPY_GC_HEAP_SIZE (256 * 1024) // 256 KB + +#define MICROPY_PY_HASHLIB (1) +#define MICROPY_PY_HASHLIB_MD5 (1) +#define MICROPY_PY_HASHLIB_SHA1 (1) +#define MICROPY_PY_HASHLIB_SHA256 (1) diff --git a/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h b/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h index 19b19af85c4c..8960a5653645 100644 --- a/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h +++ b/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h @@ -3,3 +3,11 @@ #define MICROPY_HW_BOARD_NAME "CY8CPROTO-063-BLE" #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "CY8C-063-BLE" + +#define MICROPY_GC_HEAP_SIZE (64 * 1024) // 64 KB + +#define MICROPY_PY_HASHLIB (0) +#define MICROPY_PY_HASHLIB_MD5 (0) +#define MICROPY_PY_HASHLIB_SHA1 (0) +#define MICROPY_PY_HASHLIB_SHA256 (0) + diff --git a/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.mk b/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.mk index ffcbd6b72ba0..8f6ceb5829c8 100644 --- a/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.mk +++ b/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.mk @@ -1,4 +1,4 @@ FROZEN_MANIFEST ?= boards/manifest.py -MICROPY_PY_SSL = 1 -MICROPY_PSOC6_SSL_MBEDTLS = 1 +MICROPY_PY_SSL = 0 +MICROPY_PSOC6_SSL_MBEDTLS = 0 BOARD_VERSION=release-v4.2.0 diff --git a/ports/psoc6/modules/psoc6/psoc6_flash.c b/ports/psoc6/modules/psoc6/psoc6_flash.c index d6af326daa77..55635b53afdc 100644 --- a/ports/psoc6/modules/psoc6/psoc6_flash.c +++ b/ports/psoc6/modules/psoc6/psoc6_flash.c @@ -44,7 +44,7 @@ #elif defined(CYBLE_416045_02_device) #define DEVICE_FLASH_SIZE (0x00100000) // 1MB -#define DEVICE_FLASH_BASE_ADDRESS (0x100A0000) // Where is this value coming from?? +#define DEVICE_FLASH_BASE_ADDRESS (0x100E0000) // Where is this value coming from?? #else #error "MCU not supported." @@ -53,9 +53,6 @@ #define FLASH_BASE_TRUE (0x10000000) -// #define FLASH_BASE (0x101A0000) -// #define FLASH_SIZE (0x00200000 - (FLASH_BASE - FLASH_BASE_TRUE)) - #define FLASH_BASE DEVICE_FLASH_BASE_ADDRESS #define FLASH_SIZE (DEVICE_FLASH_SIZE - (FLASH_BASE - FLASH_BASE_TRUE)) diff --git a/ports/psoc6/mpconfigport.h b/ports/psoc6/mpconfigport.h index 9dd61a796454..64bf830b5c65 100644 --- a/ports/psoc6/mpconfigport.h +++ b/ports/psoc6/mpconfigport.h @@ -35,11 +35,6 @@ // Control over Python builtins #define MICROPY_PY_IO_BUFFEREDWRITER (1) #define MICROPY_PY_SELECT (1) -// TODO: Remove this -// This is defined per board, and by the mpconfigboard.mk -// #ifndef MICROPY_PY_SSL -// #define MICROPY_PY_SSL (1) -// #endif #define MICROPY_PY_IO (1) #define MICROPY_PY_IO_IOBASE (1) #define MICROPY_PY_BINASCII (1) @@ -60,8 +55,9 @@ // #define MICROPY_GC_STACK_ENTRY_TYPE uint16_t #define MICROPY_GC_STACK_ENTRY_TYPE uint32_t #define MICROPY_ENABLE_GC (1) -// #define MICROPY_GC_HEAP_SIZE (256 * 1024) //256 kb sectors -> 1 sector (0.25 of 2 MB flash) -#define MICROPY_GC_HEAP_SIZE (128 * 1024) // 32 kb +#define MICROPY_ENABLE_FINALISER (1) + + #define MICROPY_MEM_STATS (1) #define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1) @@ -135,14 +131,10 @@ #define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ #define MICROPY_FATFS_RPATH (2) -#define MICROPY_PY_CRYPTOLIB (1) -#define MICROPY_PY_CRYPTOLIB_CTR (1) -#define MICROPY_PY_CRYPTOLIB_CONSTS (1) +#define MICROPY_PY_CRYPTOLIB (MICROPY_PY_SSL) +#define MICROPY_PY_CRYPTOLIB_CTR (MICROPY_PY_SSL) +#define MICROPY_PY_CRYPTOLIB_CONSTS (MICROPY_PY_SSL) -#define MICROPY_PY_HASHLIB (1) -#define MICROPY_PY_HASHLIB_MD5 (1) -#define MICROPY_PY_HASHLIB_SHA1 (1) -#define MICROPY_PY_HASHLIB_SHA256 (1) #define MP_STATE_PORT MP_STATE_VM diff --git a/ports/psoc6/mpconfigport.mk b/ports/psoc6/mpconfigport.mk index 2faf92dc3ed9..5ae8f84b8f8c 100644 --- a/ports/psoc6/mpconfigport.mk +++ b/ports/psoc6/mpconfigport.mk @@ -1,3 +1,2 @@ MICROPY_VFS_LFS2=1 -MICROPY_PY_SSL=1 diff --git a/ports/psoc6/mtb-libs/Makefile b/ports/psoc6/mtb-libs/Makefile index 2117122950c8..219ad2517012 100755 --- a/ports/psoc6/mtb-libs/Makefile +++ b/ports/psoc6/mtb-libs/Makefile @@ -92,12 +92,16 @@ VERBOSE= # ... then code in directories named COMPONENT_foo and COMPONENT_bar will be # added to the build # -COMPONENTS+=FREERTOS MBEDTLS +COMPONENTS+=FREERTOS ifeq ($(MICROPY_PY_NETWORK),1) COMPONENTS+= LWIP endif +ifeq ($(MICROPY_PY_SSL),1) +COMPONENTS+=MBEDTLS +endif + # Like COMPONENTS, but disable optional code that was enabled by default. DISABLE_COMPONENTS= @@ -108,7 +112,7 @@ DISABLE_COMPONENTS= SOURCES= DEFINES=CY_RETARGET_IO_CONVERT_LF_TO_CRLF CY_RTOS_AWARE -DEFINES+=MBEDTLS_USER_CONFIG_FILE='"mbedtls_config.h"' + ifeq ($(MICROPY_PY_NETWORK),1) DEFINES+= CYBSP_WIFI_CAPABLE @@ -121,13 +125,21 @@ DEFINES+= CYBSP_WIFI_CAPABLE DEFINES+=CY_WIFI_HOST_WAKE_SW_FORCE=0 endif +ifeq ($(MICROPY_PY_SSL),1) +DEFINES+=MBEDTLS_USER_CONFIG_FILE='"mbedtls_config.h"' +endif + # Like SOURCES, but for include directories. Value should be paths to # directories (without a leading -I). + MPY_PSOC6_PORT_DIR = ../ MPY_TOP_DIR = $(MPY_PSOC6_PORT_DIR)/../.. + +ifeq ($(MICROPY_PY_SSL),1) MBEDTLS_CONF_DIR = $(MPY_PSOC6_PORT_DIR)/mbedtls MBEDTLS_MPY_CONF_DIR = $(MPY_TOP_DIR)/extmod/mbedtls INCLUDES+= $(MBEDTLS_CONF_DIR) $(MBEDTLS_MPY_CONF_DIR) +endif ifeq ($(MICROPY_PY_NETWORK),1) LWIP_OPTS_DIR = $(MPY_PSOC6_PORT_DIR)/lwip_inc diff --git a/ports/psoc6/mtb-libs/deps/common/cy-mbedtls-acceleration.mtb b/ports/psoc6/mtb-libs/deps/crypto/cy-mbedtls-acceleration.mtb similarity index 100% rename from ports/psoc6/mtb-libs/deps/common/cy-mbedtls-acceleration.mtb rename to ports/psoc6/mtb-libs/deps/crypto/cy-mbedtls-acceleration.mtb diff --git a/ports/psoc6/mtb-libs/deps/common/mbedtls.mtb b/ports/psoc6/mtb-libs/deps/crypto/mbedtls.mtb similarity index 100% rename from ports/psoc6/mtb-libs/deps/common/mbedtls.mtb rename to ports/psoc6/mtb-libs/deps/crypto/mbedtls.mtb diff --git a/ports/psoc6/mtb-libs/makefile_mtb.mk b/ports/psoc6/mtb-libs/makefile_mtb.mk index 7a13fee7d6af..b327a34ce52b 100644 --- a/ports/psoc6/mtb-libs/makefile_mtb.mk +++ b/ports/psoc6/mtb-libs/makefile_mtb.mk @@ -41,6 +41,10 @@ ifeq ($(MICROPY_PY_EXT_FLASH),1) MTB_DEPS_DIRS += ext_flash endif +ifeq ($(MICROPY_PY_SSL), 1) +MTB_DEPS_DIRS += crypto +endif + # The ModusToolbox expects all the .mtb files to be in the /deps folder. # The feature specific dependencies organized in folders are directly copied # to the deps/ root folder @@ -83,7 +87,7 @@ mtb_deinit: clean # Some of the configuration variables are passed to the ModusToolbox # Makefile to include/exclude certain middleware libraries and components -MPY_MTB_MAKE_VARS = MICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) +MPY_MTB_MAKE_VARS = MICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) MICROPY_PY_SSL=$(MICROPY_PY_SSL) # build MTB project mtb_build: From 49009dca79e835ba1497d6ea6291c619e39b44e4 Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Mon, 25 Sep 2023 10:04:02 +0200 Subject: [PATCH 3/4] .github/workflows/ports_psoc6.yml: Added 063-BLE to on-target-test. Signed-off-by: enriquezgarc --- .github/workflows/ports_psoc6.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ports_psoc6.yml b/.github/workflows/ports_psoc6.yml index d36e4203b7ae..96339f176730 100644 --- a/.github/workflows/ports_psoc6.yml +++ b/.github/workflows/ports_psoc6.yml @@ -52,6 +52,7 @@ jobs: matrix: board: - CY8CPROTO-062-4343W + - CY8CPROTO-063-BLE steps: - uses: actions/checkout@v3 - name: Download binaries From f4d46e78de99b1559dd2b2977f63b012902111e5 Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Tue, 26 Sep 2023 09:34:26 +0200 Subject: [PATCH 4/4] ports/psoc6: Removed 063-BLE default disabled config param. Signed-off-by: enriquezgarc --- ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h b/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h index 8960a5653645..0d750c8e15f9 100644 --- a/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h +++ b/ports/psoc6/boards/CY8CPROTO-063-BLE/mpconfigboard.h @@ -6,8 +6,4 @@ #define MICROPY_GC_HEAP_SIZE (64 * 1024) // 64 KB -#define MICROPY_PY_HASHLIB (0) -#define MICROPY_PY_HASHLIB_MD5 (0) -#define MICROPY_PY_HASHLIB_SHA1 (0) -#define MICROPY_PY_HASHLIB_SHA256 (0)