From 357734d691daceb8eb6d77283ffd281198448edb Mon Sep 17 00:00:00 2001 From: Mattia Moffa Date: Thu, 25 Jun 2026 04:24:45 +0200 Subject: [PATCH] Fixes for old Maxim SDK --- arch.mk | 2 +- hal/max32666.c | 5 ++--- test-app/Makefile | 25 ++++++++++++++++++------- test-app/app_max32666.c | 7 +++---- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/arch.mk b/arch.mk index 6bb3b431..f19e28c4 100644 --- a/arch.mk +++ b/arch.mk @@ -253,6 +253,7 @@ ifeq ($(ARCH),ARM) NO_ARM_ASM=1 CFLAGS+=-DMAX3266X_SHA -DFAST_MEMCPY CFLAGS+=-ffunction-sections -fdata-sections + CFLAGS+=-DTARGET=MAX32665 -DTARGET_REV=0x4131 ifeq ($(MAX3266X_OLD),1) # Older Maxim SDK tree (flat MAX32665PeriphDriver layout) CFLAGS+=-DWOLFSSL_MAX3266X_OLD @@ -265,7 +266,6 @@ ifeq ($(ARCH),ARM) $(MSDK_DIR)/Libraries/MAX32665PeriphDriver/Source/mxc_delay.o else CFLAGS+=-DWOLFSSL_MAX3266X - CFLAGS+=-DTARGET=MAX32665 -DTARGET_REV=0x4131 MAX3266X_CFLAGS:= \ -I$(MSDK_DIR)/Libraries/PeriphDrivers/Include/MAX32665/ \ -I$(MSDK_DIR)/Libraries/CMSIS/Device/Maxim/MAX32665/Include/ \ diff --git a/hal/max32666.c b/hal/max32666.c index a2acf4c2..859ece30 100644 --- a/hal/max32666.c +++ b/hal/max32666.c @@ -44,9 +44,8 @@ #include "max32666.h" -/* CMSIS variable required by MSDK drivers (mxc_delay.c). - * Only define in bootloader; test-app provides its own. */ -#if defined(WOLFSSL_MAX3266X) && defined(__WOLFBOOT) +/* CMSIS variable required by MSDK drivers (mxc_delay.c). */ +#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD) uint32_t SystemCoreClock = 96000000; #endif diff --git a/test-app/Makefile b/test-app/Makefile index d6c7077a..4b79c4ec 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -696,13 +696,24 @@ endif ifeq ($(TARGET),max32666) LSCRIPT_TEMPLATE=ARM-max32666.ld ifeq ($(WOLFCRYPT_MAX32666_TEST),1) - APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TPU/tpu_me14.o - APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TPU/tpu_reva.o - APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TRNG/trng_reva.o - APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TRNG/trng_me14.o - APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TRNG/trng_revb.o - APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/SYS/sys_me14.o - APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/SYS/mxc_delay.o + ifeq ($(MAX3266X_OLD),1) + MAX3266X_SRC := $(MSDK_DIR)/Libraries/MAX32665PeriphDriver/Source + APP_OBJS += $(MAX3266X_SRC)/hash.o + APP_OBJS += $(MAX3266X_SRC)/cipher.o + APP_OBJS += $(MAX3266X_SRC)/maa.o + APP_OBJS += $(MAX3266X_SRC)/mem_utils.o + APP_OBJS += $(MAX3266X_SRC)/trng.o + APP_OBJS += $(MAX3266X_SRC)/mxc_sys.o + APP_OBJS += $(MAX3266X_SRC)/mxc_delay.o + else + APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TPU/tpu_me14.o + APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TPU/tpu_reva.o + APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TRNG/trng_reva.o + APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TRNG/trng_me14.o + APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/TRNG/trng_revb.o + APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/SYS/sys_me14.o + APP_OBJS += $(MSDK_DIR)/Libraries/PeriphDrivers/Source/SYS/mxc_delay.o + endif APP_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/maxim/max3266x.o endif endif diff --git a/test-app/app_max32666.c b/test-app/app_max32666.c index 10110b2b..1b13f173 100644 --- a/test-app/app_max32666.c +++ b/test-app/app_max32666.c @@ -19,10 +19,6 @@ #include "hal/max32666.h" #ifdef WOLFCRYPT_MAX32666_TEST -/* MSDK's mxc_delay.c references SystemCoreClock (CMSIS). - * wolfBoot configures HIRC96M = 96 MHz in hal_init(). */ -uint32_t SystemCoreClock = 96000000; - #include #include #include @@ -169,6 +165,9 @@ static int test_ecdhe_p256(void) /* Enable TRNG peripheral clock before wc_InitRng seeds from hardware */ GCR_PERCKCN1 &= ~GCR_PERCKCN1_TRNGD; + /* Wait for the entropy source to come up before wc_InitRng's health test */ + while ((MXC_TRNG->st & MXC_F_TRNG_ST_RND_RDY) == 0) {} + ret = wc_InitRng(&rng); if (ret != 0) { wolfBoot_printf("FAIL (InitRng: %d)\n", ret);