diff --git a/docs/develop/natmod.rst b/docs/develop/natmod.rst index 8ffe49591c..6d15f867bc 100644 --- a/docs/develop/natmod.rst +++ b/docs/develop/natmod.rst @@ -34,6 +34,7 @@ options for the ``ARCH`` variable, see below): * ``x86`` (32 bit) * ``x64`` (64 bit x86) +* ``armv6m`` (ARM Thumb, eg Cortex-M0) * ``armv7m`` (ARM Thumb 2, eg Cortex-M3) * ``armv7emsp`` (ARM Thumb 2, single precision float, eg Cortex-M4F, Cortex-M7) * ``armv7emdp`` (ARM Thumb 2, double precision float, eg Cortex-M7) @@ -171,7 +172,7 @@ The file ``Makefile`` contains: # Source files (.c or .py) SRC = factorial.c - # Architecture to build for (x86, x64, armv7m, xtensa, xtensawin) + # Architecture to build for (x86, x64, armv6m, armv7m, xtensa, xtensawin) ARCH = x64 # Include to get the rules for compiling and linking the module diff --git a/py/dynruntime.mk b/py/dynruntime.mk index db06d41e73..09cbb2dd37 100644 --- a/py/dynruntime.mk +++ b/py/dynruntime.mk @@ -55,6 +55,13 @@ CROSS = CFLAGS += -fno-stack-protector MICROPY_FLOAT_IMPL ?= double +else ifeq ($(ARCH),armv6m) + +# thumb +CROSS = arm-none-eabi- +CFLAGS += -mthumb -mcpu=cortex-m0 +MICROPY_FLOAT_IMPL ?= none + else ifeq ($(ARCH),armv7m) # thumb diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py index 6189491518..b8652462d4 100755 --- a/tools/mpy_ld.py +++ b/tools/mpy_ld.py @@ -38,6 +38,7 @@ import makeqstrdata as qstrutil MPY_VERSION = 6 MP_NATIVE_ARCH_X86 = 1 MP_NATIVE_ARCH_X64 = 2 +MP_NATIVE_ARCH_ARMV6M = 4 MP_NATIVE_ARCH_ARMV7M = 5 MP_NATIVE_ARCH_ARMV7EMSP = 7 MP_NATIVE_ARCH_ARMV7EMDP = 8 @@ -82,7 +83,14 @@ def asm_jump_x86(entry): return struct.pack("> 11 == 0 or b_off >> 11 == -1, b_off + return struct.pack("> 1 & 0x07FF)) + + +def asm_jump_thumb2(entry): b_off = entry - 4 if b_off >> 11 == 0 or b_off >> 11 == -1: # Signed value fits in 12 bits @@ -129,13 +137,21 @@ ARCH_DATA = { (R_X86_64_GOTPCREL, R_X86_64_REX_GOTPCRELX), asm_jump_x86, ), + "armv6m": ArchData( + "EM_ARM", + MP_NATIVE_ARCH_ARMV6M << 2, + 2, + 4, + (R_ARM_GOT_BREL,), + asm_jump_thumb, + ), "armv7m": ArchData( "EM_ARM", MP_NATIVE_ARCH_ARMV7M << 2, 2, 4, (R_ARM_GOT_BREL,), - asm_jump_arm, + asm_jump_thumb2, ), "armv7emsp": ArchData( "EM_ARM", @@ -143,7 +159,7 @@ ARCH_DATA = { 2, 4, (R_ARM_GOT_BREL,), - asm_jump_arm, + asm_jump_thumb2, ), "armv7emdp": ArchData( "EM_ARM", @@ -151,7 +167,7 @@ ARCH_DATA = { 2, 4, (R_ARM_GOT_BREL,), - asm_jump_arm, + asm_jump_thumb2, ), "xtensa": ArchData( "EM_XTENSA",