2017-12-18 07:54 AM
Recently I found that STM32CubeMX support Makefile as well as SW4STM32. So far I worked with only the SW4STM32, but now I'm happy to move to the command line development with GCC, GNU make , stlink, and GDB. After spending time fixing minor bugs I could compile a blinky code and flashed my STM32L476 without problem. The blinky program is working as expected.
Now I'm trying to debug the program with GDB. I ran st-util and arm-none-eabi-gdb using my .elf file. Then setting breakpoints and reading the values of variables were successful. But I wonder how to read I/O register values. On the System Workbench for STM32 it's very easy to check the state of the I/O registers. Would it be possible for one to do the same thing on the command line? For example, how can you read the values of GPIOB_MODER, GPIOB_OTYPER, and GPIOB_ODR registers at once?
2017-12-18 08:02 AM
Use -g3 when compiling, the compiler then adds macros into debug info.
Then in gdb simply type p /x *GPIOB
Enjoy! ;)
JW
2017-12-18 09:13 AM
Hi JW,
thank you for the quick answer! The flag '-g3' worked. This is awesome.. I feel like I don't need the heavy IDE anymore.
I have two questions. Is there a command which displays the register values in binary format? Would it be bad that one uses the -g3 option to compile a release version(for flashing)?
thanks
2017-12-18 09:23 AM
Is there a command which displays the register values in binary format?
Use /t modifier instead of /x in p (print) command. The result is IMO less readable than hexadecimal.
Compare
(gdb) p /t TIM3->CCMR1
$39 = 1111000111110001
(gdb) p /x TIM3->CCMR1
$40 = 0xf1f1
Would it be bad that one uses the -g3 option to compile a release version(for flashing)?
Shouldn't matter, as -g3 should influence only the debug information, which does not go to the binary for FLASH.
JW
2017-12-21 12:42 AM
Hi JW,
with the -g3 flag I could debug my program for STM32L476-discovery board. But strangely I cannot read I/O registers of STM32F407 using the flag. When the source code is compiled by SW4STM32, then command line gdb shows the I/O register values. However, when it's compiled using
https://github.com/nownuri/STM32F407_command_line_development/blob/master/STM32F407_make/Makefile
, the gdb says 'no symbol 'RCC' in current context'. The Makefile is almost same as the one worked well for my STM32L4. I tried various flags (-O0/-Og/-O and -g/-ggdb/-g3), but I couldn't solve the problem.Could you please have a look at my Makefile linked above, or could you please post your one?
Thank you,
2017-12-21 01:35 AM
Reading makefiles is no fun. Look at the command line the makefile produces. Can't there be multiple conflicting -g in it?
JW
2018-01-22 09:50 AM
Unfortunately I still couldn't success with STM32F4Discovery. The following is the Makefile setting which is relevant to the debugging. To me this looks just fine, but it doesn't allow gdb to read register values. Symbols like GPIOD are not found in gdb.
♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯
♯ building variables ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯ ♯ debug build? DEBUG = 1 ♯ optimization OPT = -Og♯ compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sectionsCFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g3 -gdwarf-2 endif2018-01-22 11:57 AM
As I've said above,
Reading makefiles is no fun. Look at the command line the makefile produces
You also can check if the .elf contains the macros, using arm-none-eabi-objdump --dwarf=macro xxxx.elf >xxxx.dwarf
JW