discovery icon indicating copy to clipboard operation
discovery copied to clipboard

Section 7: (mis)Optimization. Couldn't prevent LLVM from misoptimizing.

Open eavae opened this issue 5 years ago • 0 comments

I'm very new to rust and embedded things. I followed the instruction of the book and can not reproduce the section of the "volatile". If you have any idea, just let me know.

Here is my result from debug console.

Launching server: "openocd" "-c" "gdb_port 50000" "-s" "/Users/liyu/codespace/discovery/src/07-registers" "-f" "interface/stlink-v2-1.cfg" "-f" "target/stm32f3x.cfg"
Launching GDB: "arm-none-eabi-gdb" "-q" "--interpreter=mi2"
Reading symbols from /Users/liyu/codespace/discovery/src/07-registers/target/thumbv7em-none-eabihf/release/registers...
registers::__cortex_m_rt_main () at src/07-registers/src/main.rs:30
30	    loop {}
Not implemented stop reason (assuming exception): undefined
Unable to match requested speed 1000 kHz, using 950 kHz
Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000cd2 msp: 0x10002000
Unable to match requested speed 1000 kHz, using 950 kHz
Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000cd2 msp: 0x10002000
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, registers::__cortex_m_rt_main () at src/07-registers/src/main.rs:30
30	    loop {}
disassemble /m
Dump of assembler code for function registers::__cortex_m_rt_main:
10	fn main() -> ! {
   0x08000192 <+0>:	push	{r7, lr}
   0x08000194 <+2>:	mov	r7, sp

11	    aux7::init();
   0x08000196 <+4>:	bl	0x80001bc <aux7::init>
   0x0800019a <+8>:	movw	r0, #4120	; 0x1018
   0x0800019e <+12>:	mov.w	r1, #512	; 0x200
   0x080001a2 <+16>:	movt	r0, #18432	; 0x4800
12	
13	    unsafe {
14	        // A magic address!
15	        const GPIOE_BSRR: u32 = 0x48001018;
16	
17	        // Turn on the "North" LED (red)
18	        ptr::write_volatile(GPIOE_BSRR as *mut u32, 1 << 9);
19	
20	        // Turn on the "East" LED (green)
21	        ptr::write_volatile(GPIOE_BSRR as *mut u32, 1 << 11);
22	
23	        // Turn off the "North" LED
24	        ptr::write_volatile(GPIOE_BSRR as *mut u32, 1 << (9 + 16));
25	
26	        // Turn off the "East" LED
27	        ptr::write_volatile(GPIOE_BSRR as *mut u32, 1 << (11 + 16));
28	    }
29	
30	    loop {}
=> 0x080001ba <+40>:	b.n	0x80001ba <registers::__cortex_m_rt_main+40>

End of assembler dump.

Version informations:

System: Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64
Cargo: cargo 1.43.0 (3532cf738 2020-03-17)
Rust: rustc 1.43.0 (4fb7144ed 2020-04-20)

eavae avatar May 30 '20 11:05 eavae