STM32 live monitoring variables for mac

otw
Fri Apr 20, 2018 3:40 pm
Hello!

I am looking for an application which allows to live monitoring stm32 variables.
I believe STM-STUDIO-STM32 fully fits my requirements, but I cannot use it since I am mac user.
Can u recommend me an alternative?


RogerClark
Fri Apr 20, 2018 10:43 pm
I think you mean you want a debugger

Both Eclipse and VSCode are cross platform and support using a debugger, however as many people struggle to get them to work on Windows, I think it may be even harder to get them to work on a Mac


Rick Kimball
Sat Apr 21, 2018 12:21 am
Funny you should ask this question. The other day I was looking into enabling the SWO output of the BlackMagic Probe code. In that quest, I stumbled onto the fact that the SWO output is very low overhead and works quite effciently. The best part, you can use it without any debug hardware. You just need a low cost ebay USB->Serial dongle to get the output.

An overview on this technique can be found by reading this artlcle:

http://blog.japaric.io/itm/

Disregard that the author is talking about the Rust language instead of C++. The meat of this technique, which could help you on a Mac OS/X, can be found if you scroll about half way down. Find the heading “Standalone SWO”. Basically, you need a host program to decode the ITM output and you need to add some code to stm32f103 source that enables DWT and uses ITM_print statemetns.

On a linux host, I used an ITM decoder from black magic probe project called swolisten.

https://github.com/blacksphere/blackmag … wolisten.c

swolisten is written to work in two modes. The first mode reads the usb endpoint that black magic probe uses. The second mode swolisten opens the usb serial device (/dev/ttyUSB0 … on linux) and decodes each message and presents the output on a named pipe, one for each channel. The second mode reading the usb serial device is what we want. There is a readme in the blackmagic code titled something like “Using SWO Debug” if you poke around.

To run this on linux, use the following commands in two windows:

$ swolisten -p /dev/ttyUSB0 -v -b swo/ -s 4000000

and in the second window just run:

$ cat swo/chan00

Now that you have the host side setup, the final part of the puzzle is the code you need to add to your stm32f103 source. Sadly, I don’t have a readily avaliable example for Roger’s core. However, I did write code you can use as an example that uses the CubeMX CMSIS header that you can find here:

https://gist.github.com/RickKimball/55e … d52bbceadd

Basically you configure the DWT module to enable ITM output. When you want to output the value of some variable you call a CMSIS function called ITM_print(). In that example code I provided, it only takes 17 cycles to output the value. Of course, if you add fancy print formatting, you will slow it down considerably. An approach that would work better for what you want to do might be to output the raw values on individual channels and let the host side do the print formatting.

Sorry if this write-up leaves a lot of questions, however there are many articles about printing SWO output.

The thing that surprised me about using SWO was that you could use a low cost USB dongle like an FTDI, CP2102 or PL2303hx, and run them at 4Mbit without issue. Before I looked into SWO, I thought I needed a commercial professional debug probe that supported SWO with corresponding host software. Turns out it is actually simpler if you just use a standalone UART connected to the TDO pin. It is certainly less expensive.

Enjoy!


sheepdoll
Sat Apr 21, 2018 1:28 am
I think the OP is looking for real time code analysis. Where one can see the registers updating while the code is running.

The GDB debuggers which run on eclipse are step repeat debuggers, So they run one instruction then dump the registers through a read register command. Eclipse and other IDEs tend to do this transparently by looking back at the Debug stuff in the elf and dwarf files or is that the COFF files. This gives the illusion of watching the C variables.

Most of this code is built on the Visual Studio models, which is why there is limited *nix support for platforms like (Mac and Unix) The market has never been big enough for the serious developers to handle the Apple GUI callbacks, and Linux has so many flavors, it might be an ice cream shop. So we get Java things, like Eclipse that sort of to something or other than sort of gets through the worst of it.

Connecting to the SWO pin sounds quite promising, Yet there still seems to be the need to do all the source parsing and variable scope modeling that a full debugging interface provide. Some of these also provide waveform analysis too, at least in the trade show demos. The base requirement is that all these seem to require the M$ Visual or .Net infrastructure that seems to be the lowest common denominator, that companies hire interns to quickly code from library APIs rather than to bother to actually program it.

I did like Dilbert today where they want to 3D print the blockchain in HTML to create bitcoin. I am suspecting that there are a lot of users who want to do such nonsense now with proteus or protel, or what ever sim tool they teach in the diploma mill (that is designed to suck the (god-grand-)parents college savings fund dry) these days.


Rick Kimball
Sat Apr 21, 2018 1:55 am
[sheepdoll – Sat Apr 21, 2018 1:28 am] –
I think the OP is looking for real time code analysis. Where one can see the registers updating while the code is running.

I probably did not fully understand what they were asking. Actually, I thought the OP was talking about the ST eclipse based debugger. However, looking at it again, that software appears to be something that is using the ITM, ETM, and DWT features with graphing and logging. * which the ITM_Print is a subset feature *.

There are people using the opens source sigrok software with an ITM plugin and feeding that to open source graphing tools to get that kind of output.

https://www.sigrok.org/blog/new-protoco … -itm-etmv3


RogerClark
Sat Apr 21, 2018 3:53 am
I don’t know if the OP has phrased the question correctly.

I don’t think its worth wasting any more time on until the requirement has been clarified.


otw
Sat Apr 21, 2018 9:09 am
Roger, I am not looking for a debugger, since I have got one already working.
I have got also logic analyzer.
What I am looking for is an application which allows visualizing and displaying variables from the MCU without interrupting program execution.
Below I dropped a link how mentioned STM-STUDIO-STM32 works.

https://www.youtube.com/watch?v=wrmQYfYPyOI

Currently I am using a simple gdb script to see how some variables changes. It’s very useful but not much handy and I have no idea how it affects MCU program execution.

shell openocd -f /usr/local/Cellar/open-ocd/0.10.0/share/openocd/scripts/board/stm32f4discovery.cfg -c "init" &> /dev/null &

file /Users/grzes/Documents/AC6/AC6Hello/Debug/AC6Hello.elf

target remote localhost:3333

#monitor reset run

display outX
display outY
display outZ

set $loop = 0
while(1)
set $loop = $loop + 1
display
shell sleep 1
echo \n
if $loop == 20
echo "exit"\n
shell killall openocd
quit
end
end


sheepdoll
Sat Apr 21, 2018 6:42 pm
What I am looking for is an application which allows visualizing and displaying variables from the MCU without interrupting program execution.
Below I dropped a link how mentioned STM-STUDIO-STM32 works.

https://www.youtube.com/watch?v=wrmQYfYPyOI

I followed that link to the download page. It looks from the PDF getting started file that this program requires java. So it might be like Cube and can run on the Mac using the java engine via the JAR file embedded in the *.exe The old version of the Cube tool would work this way.

I have not tried this yet as I have a WinXP machine to test it with first and see what gets installed where.

If the code is written in Java, then one could use a Jar dumper to see the code and modify it to run under different versions of java.

It looks like STM-STUDIO-STM32 is an older tool and has not been updated for a few years. There might be something that supersedes it.

Here are some scripts that installed and ran the 2015 era cube, this type of script might install and run SSTMStudio_setup.exe software as well. ST replaced the need for the java wrapper with a pre built Mac executable.

# run the installer
$ sudo /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -jar ~/Downloads/SetupSTM32CubeMX-4.8.0.exe
# this install the STM32CubeMX.exe in Applications. The exe is really a jar. I ran it from the terminal


otw
Sun Apr 22, 2018 11:33 am
sheepdoll, that’s very interesting what u wrote I gave it a shot but unfortunately I received following output:

rMacBookProGrzes:~ grzes$ sudo /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -jar ~/Documents/STM32/STM\ Studio/STMStudio_setup.exe
Password:
Error: Invalid or corrupt jarfile /Users/grzes/Documents/STM32/STM Studio/STMStudio_setup.exe


sheepdoll
Wed May 02, 2018 11:03 pm
So I finally got a chance to install STMStudo on a WinXP machine and copy the *.jar file to the mac.

When I attempt to run the jar from the command line using the settings in the windows shortcut I get
$ java -Xms512m -Xmx512m -jar STMStudio.jar
Native library not available for the current platform (mac os x x86_64)


otw
Sat May 05, 2018 4:14 pm
I have started to develop native mac os application to monitor variables.
Im basing on this question from stackoveflow:
https://stackoverflow.com/questions/197 … ut-via-usb

I am using OpenOCD to read value form specified memory address.
It works.
Now Im working on how to get global variables from executable.

I also browsed STM-STUDIO folder and found there GDB and ST Link plugins.
I suppose it uses ST Link driver for communication with MCU and GDB for extracting variables from executable.
Basing on that I assume there is no possibility to successfully run STM-STUDIO on mac os x.


sheepdoll
Sat May 05, 2018 6:19 pm
[otw – Sat May 05, 2018 4:14 pm] –
I have started to develop native mac os application to monitor variables.
Im basing on this question from stackoveflow:
https://stackoverflow.com/questions/197 … ut-via-usb

I am using OpenOCD to read value form specified memory address.
It works.
Now Im working on how to get global variables from executable.

I also browsed STM-STUDIO folder and found there GDB and ST Link plugins.
I suppose it uses ST Link driver for communication with MCU and GDB for extracting variables from executable.
Basing on that I assume there is no possibility to successfully run STM-STUDIO on mac os x.

Should be able to run STMStudio on the mac with a re-build of the JAR file. If you look at the program it already has detections for Mac OS and SUNOS. These currently echo in the unsupported message when the jar file is run. The coms seem to be through STDIO (STDIN,STDOUT, and STDError.) The Java provides the GUI.
Tricky part would be setting up the bridge code that runs in the Native space.
I am thinking of having a go at this myself, as STMStudio could be a useful tool. I am also thinking java might make for a front end to the pipe organ stuff. (Well it is already through jOrgan via MIDI.) This interface looks to provide more direct monitoring of the internal states.


Leave a Reply

Your email address will not be published. Required fields are marked *