ITM data via OCD mechanism

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

kb1gtt
Posts: 41
Joined: Sat Jul 09, 2016 11:29 am
Has thanked: 11 times
Been thanked: 2 times

ITM data via OCD mechanism

Postby kb1gtt » Tue Jun 01, 2021 8:27 pm

I'm looking for help getting ITM working via SWO signal on STM32 under ChibiStudio. I've got a FreeSTUDIO project to display stuff via the ITM / SWO mechanisms which proves the hardware is working. However I'm having trouble getting this to work with ChibiStudio. I can compile and step through code in ChibiStudio. However I cannot get messages to display via ITM / SWO mechanism in ChibiStudio.

I have a launcher which includes the below line. I believe that line should be enable OCD's ITM mechanisms. However I do not know how to display this data.

Code: Select all

monitor itm port 0 on

http://openocd.org/doc/html/Architectur ... x-itm-port

Does anyone have suggestions on how to view this ITM data via OCD mechanism?

Also I'm not specifically tied to OCD. I just see other references in the forum here which have guided me in that direction. I'm OK with using other mechanisms that can allow me to do printf statements which get debug data over the SWO signal on a STLink debugger.

I've made a demo project as an intermediate step in understanding how to get ITM working. I have a ChibiOS project which will ultimately use this on my own PCB. However this project has been simplified to just a blinking LED and it's using a demo board which other will hopefully have laying around.

The below project uses a STM32 discovery board, with NO modifications.
https://github.com/jharvey/ITM_Example

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ITM data via OCD mechanism

Postby Giovanni » Tue Jun 01, 2021 8:44 pm

Hi,

Never tried it personally.

If OpenOCD prints anything then you should see it in the console view, select the OpenOCD console if you don't see the right one, there is a drop down menu on the right side of the console bar.

Giovanni

kb1gtt
Posts: 41
Joined: Sat Jul 09, 2016 11:29 am
Has thanked: 11 times
Been thanked: 2 times

Re: ITM data via OCD mechanism

Postby kb1gtt » Tue Jun 08, 2021 8:32 pm

Are there any suggestions on how to send to OpenOCD the "tcl_trace on" command via ChibiStudio? A more detailed explanation is below.

I've made progress. I can get messages to display in a terminal. However I'm currently getting the below error message. I'm also trying to remove some annoying steps in this process.

Code: Select all

Error: tcl_trace: can only be called from the tcl server
tcl_trace [on|off]


I get beyond this error message by using Cygwin to launch the below python3 script.
https://github.com/z4yx/Cortex-SWO-Decoder

This script connects to tcl and sends the "tcl_trace on" command. Then I see the message printed to the terminal as shown in the attached picture.
SWO_Working.PNG


My OCD launcher contains the below commands.
Debugger_Settings.PNG

Here's a snippet of the commands. Take note the use of "monitor" to attempt to send the "tcl_trace on" command which produces the above error message.

Code: Select all

set remotetimeout 20
monitor reset init
monitor sleep 50
monitor init
monitor tpiu config internal - uart off 168000000 250000
monitor itm ports on
monitor tcl_trace on


Is there some way to send the "tcl_trace on" command via eclipse to OCD?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ITM data via OCD mechanism

Postby Giovanni » Tue Jun 08, 2021 9:17 pm

Hi,

You can use the terminal and connect to the command port of OpenOCD, 4444 if I remember well, you can give the command there.

Giovanni

kb1gtt
Posts: 41
Joined: Sat Jul 09, 2016 11:29 am
Has thanked: 11 times
Been thanked: 2 times

Re: ITM data via OCD mechanism

Postby kb1gtt » Wed Jun 09, 2021 4:17 pm

The telnet port is 4444, which is the port that is providing the error message and refusing to allow this particular tcl command. It appears the other tcl commands are OK over 4444, but this command is not being allowed over telnet. Instead I need to use the tcl port, which is 6666. From the python script, it appears the below is the important snippet.

Code: Select all

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as tcl_socket:
    tcl_socket.connect((HOST, PORT))
    # tcl_socket.settimeout(0)
    def send_tcl(tcl):
        tcl_socket.sendall(tcl.encode('ascii') + b'\n\x1a')
...
    send_tcl('itm ports on')
...

It appears this python script is simply opening localhost:6666 then sends "itm ports on\n\x1a"

I tried the below, and several variants of the below. It appears that eclipse is opening the port, and perhaps even sending the commands that I typed. However it appears I am not sending the correct set of characters. I have not yet gotten the telnet port to acknowledge that tcl trace has been activated. I suspect that I'm not sending the '\n\x1a correctly. I'm currently trying to figure out how to send \n\r, and even the standard line feed carriage return is being elusive right now. Perhaps I need a / or something like that to break it out. I'm not sure and I'm trying to hack my way through it.
ChibiStudio(6666).png

Suggestions on how to send \n\r or '\n\x1a are welcome :)

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ITM data via OCD mechanism

Postby Giovanni » Wed Jun 09, 2021 5:17 pm

Is it possible to enable this using the OCD command line? if so then you could just modify the launch arguments.

Giovanni

kb1gtt
Posts: 41
Joined: Sat Jul 09, 2016 11:29 am
Has thanked: 11 times
Been thanked: 2 times

Re: ITM data via OCD mechanism

Postby kb1gtt » Wed Jun 09, 2021 6:52 pm

It appears that I can only launch via tcl server. The attached picture was putty from localhost:4444 and after eclipse OCD was started.

OCD_tcl.PNG
OCD_tcl.PNG (7.17 KiB) Viewed 2502 times

It appears I need to connect to port 6666 and send the command. However it appears I need to also send the \n\x1a or tcl server does not process the request.


Return to “STM32 Support”

Who is online

Users browsing this forum: Google [Bot] and 21 guests