I am trying to write a bootloader for STM32 in Rust, and I cannot figure out how to properly populate the stack pointer. Next, as I can say, the code should be:
asm!("MOV SP, $0" :: "0"(stack_pointer));
but the compiler does not agree:
error: invalid operand in inline asm: 'MOV SP, $0' --> src/main.rs:38:5 | 38 | asm!("MOV SP, $0" :: "0"(stack_pointer)); // set the stack pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: <inline asm>:1:11: error: unexpected token in operand MOV SP, ^ --> src/main.rs:38:5 | 38 | asm!("MOV SP, $0" :: "0"(stack_pointer)); // set the stack pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What am I doing wrong? He seems to be complaining about the dollar sign, but I got it directly from the documentation .
In the conversation in the comments, I tried two things, both of which compile (!), But none of them work (but this may be for some one billionth reason that is still working on it):
Version A:
asm!("MOV R0, #0x0800"); asm!("LSL R0, R0, #16"); asm!("MOV R1, #0x8000"); asm!("ORR R2, R1, R0"); asm!("LDRT R0, [R2]"); asm!("MOV SP, R0"); entry_point()
Version B:
#[inline(never)] unsafe fn go(_addr: u32, entry_point: fn()->()) { asm!("MOV SP, R0"); entry_point() }