Question

I am trying to write an application similar to stmicro STM-STUDIO, which reads variables from an embedded application running on a device (STM32Fx Discovery) via USB. How do I go about reading the output (variables) coming from the board, preferably an app using a C# application?

Was it helpful?

Solution

You should search around and see if there is an API or library of some sort you can use to talk to the SWD Debugger. Or maybe they have a command-line interface you can run from your program. You might try contacting the manufacturer (ST).

If they are not going to support you, then it's time to put on the reverse engineering hat. I would get a USB protocol analyzer. Total Phase sells good ones and I have used their $400 one to debug my USB devices for a long time. Your operating system might also have some built-in USB debugging capabilities. Then just run STM STUDIO and see what happens when you click various buttons. Hopefully you can figure it out.

You might need to get a solid understanding of the SWD protocol in order to figure out the USB traffic you are seeing on the analyzer.

OTHER TIPS

If you use OpenOCD (which you probably are if you're using OpenStm32 for development and debugging via an ST-Link connected by USB) then you can connect to OpenOCD via telnet on port 4444 and issue commands to read and write memory. You can try this with an interactive telnet session. In the telnet session, the OpenOCD command to read a 32-bit variable is mdw <hexAddress>. For example, to read a variable in RAM at address 0x20000024, use command mdw 0x20000024 and expect a response like 0x20000242: 89ABCDEF where 89ABCDEF represents a hex value. Converting the hex value in C# can be done with an expression like UInt32 myUInt32 = UInt32.Parse(myHexString, System.Globalization.NumberStyles.HexNumber);

There's a tutorial .pdf here describing how to connect to OpenOCD with telnet.

Then the question is... what memory addresses should be used? There are 2 ways to get the address: get it from the linker .map file (either programatically or manually) or use a library to parse & extract debug info from the .elf file.

I haven't yet found a self-contained DLL or dot.net wrapper that does all this in one package.

Another tool similar to STM-Studio is T.I.'s GUI Composer which works for T.I.'s ARM processors and communicates via JTAG or SWD. I haven't tried using GUI Composer with an STM processor but the concept is similar i.e., using the debug interface as a sort of communications co-processor for GUIs without modifying FW.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top