Skip to main content
M. Jeong
Associate III
December 18, 2017
Question

reading I/O register values with command line GDB

  • December 18, 2017
  • 7 replies
  • 4672 views
Posted on December 18, 2017 at 16:54

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?

    This topic has been closed for replies.

    7 replies

    waclawek.jan
    Super User
    December 18, 2017
    Posted on December 18, 2017 at 17:02

    Use -g3 when compiling, the compiler then adds macros into debug info.

    Then in gdb simply type p /x *GPIOB

    Enjoy! ;)

    JW

    M. Jeong
    M. JeongAuthor
    Associate III
    December 18, 2017
    Posted on December 18, 2017 at 17:13

    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

    waclawek.jan
    Super User
    December 18, 2017
    Posted on December 18, 2017 at 17:23

    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