how to get program counter via updi (serial)

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there!

I'm building a gdb server which communicates with an attiny3217 over updi (on serial), aka I use pyupdi (or pymcuprog). There's a similar project (https://github.com/stemnic/pyAVRdbg) but it doesn't use a serial connection.

I can already communicate with the commands ld(), st(), ... to read some registers and memory and I can stop and start the mcu via commands. To get going I should now read the program counter via updi commands.
Unfortunately I haven't found, what the "raw" updi commands would be to read out the PC and on which address the PC is located.

Is anyone having a clue about it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

some useful links here: https://www.avrfreaks.net/commen... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

While it's talking about JTAG rather than UPDI I have a feeling the commands may be similar so by a complete fluke gchapman just posted this today:

 

https://www.avrfreaks.net/commen...

 

If you follow the top link in that post:

 

https://people.ece.cornell.edu/l...

 

you will find:

Also, we found an instruction undocumented in the AVR 8-bit instruction set for reading the current PC. This is run by giving an opcode of 0xFFFF0000. The PC is shifted out on TDO, which we then shift left by 1 to give a value that makes sense to the user.

Not sure if this is applicable to what you want to do but it's probably worth reading their work anyway! 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
by a complete fluke gchapman just posted this today

ha ha - my link in #2 is also to a gchapman "complete fluke" coincidence post!  laugh

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds promising. I'll give it a try. Thx for the links!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

2ni wrote:
Unfortunately I haven't found, what the "raw" updi commands would be to read out the PC and on which address the PC is located.

 

Yeah. The UPDI is a program and debug interface, however, only the program commands are documented, the other ones are proprietary.

 

You would need to get an official programmer, capable of debugging, and try to sniff the debug commands.

Now that I think about it, that would be an interesting project, a UPDI sniffer.

 

The only public information I have is from a preliminary datasheet, that I'll attach here. It has some little slips of "secret" info in the UPDI chapter that were scrubbed from current datasheets wink

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:
Now that I think about it, that would be an interesting project, a UPDI sniffer.
UPDI and PDI share instructions.

avr_pdi - sigrok

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

2ni wrote:
... and on which address the PC is located.
As an end run, can "breadcrumb" the PC then copy the PC list by the UPDI LD instruction; this is akin to AVR32 NanoTrace though by software instead of hardware.

 

P.S.

On all but tinyAVR, can copy the PC to a spare port to be captured by a logic analyzer.

 


Generating Unique Error Codes | The Embedded Muse 306 (GCC addr2line)

 

Troubleshooting real-time software issues using a logic analyzer - Embedded.com

AVR - Calibration & Daq toolchain? | AVR Freaks

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:
UPDI and PDI share instructions.

 

avr_pdi - sigrok

 

I'll check it out, although PDI differs from UPDI in that PDI is synchronous and has an extra clock line compared to UPDI. From a glance at the source code I think it can't decode debug information, just programming, as expected.

 

edit: I'd like to be able to write a UPDI decoder for sigrok but IDK how to do it... I guess I need to read this stuff  http://sigrok.org/wiki/Protocol_decoder_HOWTO

Last Edited: Fri. Feb 25, 2022 - 11:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would think the address for PC would be related to the CPU:      .equ CPU_base = 0x0030                   ; CPU ( this is for m4809 mcu)

Probably undocumented like El Tangas points out... But what do I know?

Good Question BTW!

 

Edit:

 I Misunderstood your question.  The only address I see is a Recieve :


# in "main.py"
HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
PORT = 12555        # Port to listen on (non-privileged ports are > 1023) 

 ## in "main.py"
  if len(command) > 1:
            if command[1:] == "22":
                # GDB defines PC register for AVR to be REG34(0x22)
                pc = dbg.readProgramCounter()
                print(pc)
                print(hex(pc))
                pc = pc << 1

 # in "debugger.py"
 # looks like this depends on many contingencies
from pyedbglib.hidtransport.hidtransportfactory import hid_transport
from pyedbglib.protocols import housekeepingprotocol
from pyedbglib.protocols import housekeepingprotocol
from pyedbglib.protocols import avr8protocol
from pyedbglib.protocols import avr8protocolerrors

The script looks as if it depends on other file(s) that are in other precompiled? packages, maybe? 

The proprietary debugging methods may not be shared on data/app notes.  

Seems OCD is not even mentioned in most of the Data sheets except for #6 above

You picked a stumper!

 

I reserve my right to assemble!
Brawndo's got what plants crave... It's got electrolytes!

Last Edited: Sat. Feb 26, 2022 - 11:58 PM