From f3191bcd48341ef0a8da0ad84c60b53a77e0635d Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Tue, 15 Aug 2023 22:03:07 +0200 Subject: [PATCH] mpy_ld.py: Support modules larger than 4KiB on armv6m Using the BL instruction in ARM Thumb All other architectures seems to support larger modules already Fixes exception such as: File "micropython/tools/mpy_ld.py", line 904, in build_mpy jump = env.arch.asm_jump(entry_offset) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "micropython/tools/mpy_ld.py", line 92, in asm_jump_thumb assert b_off >> 11 == 0 or b_off >> 11 == -1, b_off ^^^^^^^^^^^^^^^^^ AssertionError: 6153 Signed-off-by: Jon Nordby --- tools/mpy_ld.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py index 87e57869f6..4f37b0f71a 100755 --- a/tools/mpy_ld.py +++ b/tools/mpy_ld.py @@ -89,8 +89,17 @@ def asm_jump_x86(entry): def asm_jump_thumb(entry): # Only signed values that fit in 12 bits are supported b_off = entry - 4 - assert b_off >> 11 == 0 or b_off >> 11 == -1, b_off - return struct.pack("> 1 & 0x07FF)) + if b_off >> 11 == 0 or b_off >> 11 == -1: + return struct.pack("> 1 & 0x07FF)) + else: + # Use BL instruction + # Two 16-bit instructions in sequence + # each on form: 1111 HOOO OOOO OOOO + # first instruction has H=0, and has high 11 bits of the Offset + # second instruction has H=1, and has low 11 bits of the Offset + b0 = 0xF000 | (b_off >> 12 & 0x07FF) + b1 = 0xF800 | (b_off >> 1 & 0x7FF) + return struct.pack("