From aea93a88f82105699f44431b76ff3107fd7b5a45 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 14 Jun 2023 16:56:58 +0200 Subject: [PATCH] samd/mcu/samd21: Reorganize and enable more firmware features. This commit enables additional features for SAMD21 with external flash: - Viper and native code support. On a relatively slow devices, viper and native code can be helpful. - Freeze the asyncio scripts and add the select module. - Enable Framebuffer support. - Enable UART flow control. - Enable a few more features from the extra features set. Drop onewire and asyncio support from SAMD21 firmware without external flash, leaving a little bit more room for future extensions. Asyncio was anyhow incomplete. Signed-off-by: robert-hh --- ports/samd/Makefile | 3 +- ports/samd/mcu/samd21/manifest.py | 5 +++ ports/samd/mcu/samd21/mpconfigmcu.h | 52 +++++++++++++++++++++------- ports/samd/mcu/samd21/mpconfigmcu.mk | 4 +++ ports/samd/mcu/samd51/mpconfigmcu.h | 1 + ports/samd/mpconfigport.h | 3 -- 6 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 ports/samd/mcu/samd21/manifest.py diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 4f4c22c57..5a7cb9916 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -68,7 +68,8 @@ 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) +# Strip the letter 'K' from MICROPY_HW_CODESIZE for use by C code. +CFLAGS += -DMICROPY_HW_CODESIZE=$(strip $(subst K,' ', $(MICROPY_HW_CODESIZE))) LDFLAGS += -nostdlib $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref LDFLAGS += --defsym=_codesize=$(MICROPY_HW_CODESIZE) diff --git a/ports/samd/mcu/samd21/manifest.py b/ports/samd/mcu/samd21/manifest.py new file mode 100644 index 000000000..2a19a843f --- /dev/null +++ b/ports/samd/mcu/samd21/manifest.py @@ -0,0 +1,5 @@ +include("$(PORT_DIR)/boards/manifest.py") +include("$(MPY_DIR)/extmod/asyncio") +require("onewire") +require("ds18x20") +require("dht") diff --git a/ports/samd/mcu/samd21/mpconfigmcu.h b/ports/samd/mcu/samd21/mpconfigmcu.h index 1a3d95872..35e59a670 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.h +++ b/ports/samd/mcu/samd21/mpconfigmcu.h @@ -1,25 +1,28 @@ // Deinitions common to all SAMD21 boards #include "samd21.h" -#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES) +#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_BASIC_FEATURES) +#if MICROPY_HW_CODESIZE == 248 +#define SAMD21_EXTRA_FEATURES 1 +#else +#define SAMD21_EXTRA_FEATURES 0 +#endif // MicroPython emitters -#define MICROPY_EMIT_THUMB (0) -#define MICROPY_EMIT_INLINE_THUMB (0) +#define MICROPY_EMIT_THUMB (SAMD21_EXTRA_FEATURES) +#define MICROPY_EMIT_INLINE_THUMB (SAMD21_EXTRA_FEATURES) +#define MICROPY_EMIT_THUMB_ARMV7M (0) #define MICROPY_MODULE_BUILTIN_INIT (1) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) -#ifndef MICROPY_PY_BUILTINS_COMPLEX -#define MICROPY_PY_BUILTINS_COMPLEX (0) -#endif - -#ifndef MICROPY_PY_TIME -#define MICROPY_PY_TIME (1) -#endif - #ifndef MICROPY_PY_MATH #define MICROPY_PY_MATH (1) +#define MP_NEED_LOG2 (1) +#endif + +#ifndef MICROPY_PY_BUILTINS_COMPLEX +#define MICROPY_PY_BUILTINS_COMPLEX (0) #endif #ifndef MICROPY_PY_CMATH @@ -29,13 +32,36 @@ #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; - #ifndef MICROPY_HW_UART_TXBUF #define MICROPY_HW_UART_TXBUF (1) #endif +#ifndef MICROPY_HW_UART_RTSCTS +#define MICROPY_HW_UART_RTSCTS (SAMD21_EXTRA_FEATURES) +#endif +// selected extensions of the extra features set #define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (SAMD21_EXTRA_FEATURES) +#define MICROPY_COMP_RETURN_IF_EXPR (SAMD21_EXTRA_FEATURES) +#define MICROPY_OPT_MPZ_BITWISE (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_BUILTINS_STR_CENTER (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_BUILTINS_STR_PARTITION (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_BUILTINS_STR_SPLITLINES (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_BUILTINS_ROUND_INT (SAMD21_EXTRA_FEATURES) +#define MICROPY_CAN_OVERRIDE_BUILTINS (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_SYS_STDIO_BUFFER (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_FRAMEBUF (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_ASYNCIO (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_SELECT (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_ERRNO (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_DEFLATE (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_ONEWIRE (SAMD21_EXTRA_FEATURES) + +#ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU +#define MICROPY_PY_MACHINE_PIN_BOARD_CPU (1) +#endif + +#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages; #define CPU_FREQ (48000000) #define DFLL48M_FREQ (48000000) diff --git a/ports/samd/mcu/samd21/mpconfigmcu.mk b/ports/samd/mcu/samd21/mpconfigmcu.mk index b3092837c..89e63c3aa 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.mk +++ b/ports/samd/mcu/samd21/mpconfigmcu.mk @@ -6,6 +6,10 @@ MPY_CROSS_MCU_ARCH = armv6m MICROPY_HW_CODESIZE ?= 184K +ifeq ($(MICROPY_HW_CODESIZE), 248K) +FROZEN_MANIFEST ?= mcu/$(MCU_SERIES_LOWER)/manifest.py +endif + MICROPY_VFS_LFS1 ?= 1 SRC_S += shared/runtime/gchelper_thumb1.s diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index 7c95c341b..b8206558b 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -27,6 +27,7 @@ #define MICROPY_PY_OS_SYNC (1) #define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_PY_ONEWIRE (1) #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32()) unsigned long trng_random_u32(void); diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 466a4d775..a7a6e2662 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -107,8 +107,6 @@ #define MICROPY_PY_UCTYPES (1) #define MICROPY_PY_HEAPQ (1) #define MICROPY_PY_RANDOM (1) -#define MICROPY_PY_DEFLATE (1) -#define MICROPY_PY_ASYNCIO (1) #ifndef MICROPY_PY_MACHINE_ADC #define MICROPY_PY_MACHINE_ADC (1) #endif @@ -150,7 +148,6 @@ #define MICROPY_PY_MACHINE_WDT (1) #define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/samd/machine_wdt.c" #define MICROPY_PY_MACHINE_WDT_TIMEOUT_MS (1) -#define MICROPY_PY_ONEWIRE (1) #define MICROPY_PY_PLATFORM (1) #define MICROPY_PLATFORM_VERSION "ASF4"