STM32L031K6: Why can't I access registers r0 through r3 with a simplest-possible assembly program using gcc/gdb?
- April 7, 2021
- 3 replies
- 1042 views
I'm brand new to STM32 development, but have many years of programming experience in higher level languages. I'm trying to get a very basic assembly program to run on an STM32L031K6 Nucleo board, as a kind of hello world example. I've attached a small tarfile with the files I'm using to produce the problem I describe here.
My process is to run "build.sh", then plug in my Nucleo board and start "st-util". Then I fire up "arm-non-eabi-gdb minimal.elf", setting gdb to use the port 4242 remote port via "target extended-remote :4242", load, continue, and ctrl-c to break into the program. Then, inspecting registers in gdb, I see this:
(gdb) i r
r0 0x30 48
r1 0x30 48
r2 0x16575448 374821960
r3 0x7fff 32767
r4 0x33333333 858993459
r5 0x44444444 1145324612
r6 0x55555555 1431655765
r7 0x66666666 1717986918
r8 0x77777777 2004318071
r9 0xffffffff 4294967295
r10 0xffffffff 4294967295
r11 0xffffffff 4294967295
r12 0xffffffff 4294967295
sp 0xffffffff 0xffffffff
lr 0x20002000 536879104
pc 0xffffffff 0xffffffff
cpsr 0xf1000000 4043309056What I should be seeing is each of r0 through r7 set to their respective 0x11111111 style numbers. Yet r0 through r3 are completely wrong, and r4 through r8 are offset by one. I don't understand what I'm doing that may be causing this problem.
I've also tested this code with an STM32F042K6 Nucleo board, modifying things to use "cortex-m0" as the cpu, and setting the RAM size and start location to 6k, and it produces a very similar result. This leads me to believe that either something is wrong with my toolchain (currently using the gcc-arm-none-eabi-10-2020-q4-major package, downloaded from developer.arm.com, and running on an Ubuntu derivative), or my understanding of the assembly I'm writing is flawed.
If anyone can help me sort out what I'm doing wrong, I would appreciate the help. I figure there's no point continuing past this point until I can figure out why this very basic example isn't working correctly.