2

I am programming a standard STM32F407 board under Linux. And I'm looking for a way to visualize the variables on a graph in an OpenSTM32 environment.

How do I visualize the variables in OpenSTM32. Is it like in Open STM Studio?

Enter image description here

mjh2007
  • 3,899
  • 24
  • 49
  • 2
    stackoverflow.com might be a better place to ask this question since you're asking about _how to program something_ verses something _hardware related_. –  Apr 24 '17 at 13:44
  • 3
    This http://www.openstm32.org/forumthread269 says that live variable update hasn't been implemented yet. One work-around, (or hack) is to write an app that does a telnet into OpenOcd to read (or write) a data structure at a fixed memory location. – JimFred Apr 24 '17 at 13:46

1 Answers1

1

I was working on the same thing. Here how I did it (not the GUI part).

You can use OpenOCD and gdb to debug/view variables.

Start an OpenOCD server:

sudo openocd -f /usr/local/share/openocd/scripts/board/st_nucleo_f4.cfg -c "init"

I assume you are working with a STM32F4DISCOVERY (STM32F407VG), so you should use stm32f4discovery.cfg config file.

Now start gdb in another terminal:

sudo gdb

Provide your object file (.elf/.axf) to gdb which contains debug info, symbols and etc. If you are using Keil uVision (MDK-ARM), you can find the .axf file under myProject/MDK-ARM/myProject/ folder. If you are using GNU Arm Embedded Toolchain, you should compile your program as a debug program, so compiler generates an .elf file under ../Build/ folder.

In gdb console:

file ~/myProject/Build/myProgram.axf

Now you can monitor your variables by name with gdb since you provided the object file.

Connect to OpenOCD server from gdb:

target remote localhost:3333

You can now see your variables from gdb with p myVar1, the type of the variable with ptype myVar1 and the address of the variable with info address myVar1 commands:

p myVar1

Here is a simple script which prints the desired variables every 1 second. You can run the script with gdb --batch --command=script.gdb:

shell sudo openocd -f /usr/local/share/openocd/scripts/board/st_nucleo_f4.cfg -c "init" &> /dev/null &

file b/BUILD/NUCLEO_F446RE/GCC_ARM/b.elf

target remote localhost:3333

#monitor reset run

display myVar1
display myVar2

while(1)
    display
    shell sleep 1s

Code on STM32:

uint32_t myVar1 = 0;
uint32_t myVar2 = 0;

int main(void){
    while(1){
        myVar1 +=1;
        myVar2 +=2;
    }
}
br.
  • 125
  • 1
  • 6
pmundt
  • 105
  • 8
  • 1
    Do not run openocd or gdb as root. Use a udev rule or whatever to grant access by your regular user to the debug adapter. Also you probably want the a target version of gdb, not the host one. – Chris Stratton Sep 11 '18 at 14:17