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("