Ahh - just read the assembler page again, and the problem is that the STM32F1 in the original Espruino (what the Assembler page describes) and the STM32F4 in the Pico are different.
On the F1, the bit set and bit reset registers are 4 bytes apart, which is great because you can use the str data,[reg, #4] command. On the F4 they're 2 bytes apart, which means you have to shift the value left by 16 bits in the same register (since str has to be aligned to the nearest 4 bytes).
Try:
var on = E.asm("void()",
"ldr r2,gpiob_addr",
"movw r3,#4",
"str r3,[r2]",
"bx lr",
"nop",
"gpiob_addr:",
".word 0x40020418"
);
var off = E.asm("void()",
"ldr r2,gpiob_addr",
"movw r3,#4",
"lsl r3,r3,#16", // shift it left by 16
"str r3,[r2]",
"bx lr",
"gpiob_addr:",
".word 0x40020418"
);
var test = E.asm("void()",
"ldr r2,gpiob_addr",
"movw r0,#4",
"lsl r1,r0,#16", // shift r0 left by 16, put in r1
"loopStart:",
"str r0,[r2]", // on
"str r1,[r2]", // off
"b loopStart",
"bx lr",
"gpiob_addr:",
".word 0x40020418"
);
LED1.set();
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ahh - just read the assembler page again, and the problem is that the STM32F1 in the original Espruino (what the Assembler page describes) and the STM32F4 in the Pico are different.
On the F1, the bit set and bit reset registers are 4 bytes apart, which is great because you can use the
str data,[reg, #4]
command. On the F4 they're 2 bytes apart, which means you have to shift the value left by 16 bits in the same register (sincestr
has to be aligned to the nearest 4 bytes).Try:
I'll update the docs.