microchip-pic-avr-tools / pyedbglib

Low-level protocol library for communicating with Microchip CMSIS-DAP based debuggers
MIT License
11 stars 4 forks source link

not an issue but a question #3

Open mcsmark opened 2 years ago

mcsmark commented 2 years ago

i wonder what the best way is to ask a question? I do not have an issue but more some questions about API usage. i would like to use the debug functions from avr8protocol. like step,run, etc. but i have no idea how to setup a session so i can use these commands.

xedbg commented 2 years ago

Hi @mcsmark, An interesting and relevant question! First point is a matter of scope - this library contains a set of protocol definitions, and avr8protocol can be used for a set of AVR device/interfaces - so its a matter of knowing not only what functions to call to setup a session, but also what content must be sent to the debugger to configure a session for a given device. Since this library is the raw set of protocols, you have to start to look one layer up: pymcuprog.

However, pymcuprog is primarily targeted towards AVR UPDI devices, and the other device families are only partially supported for experimental/test purposes - are you planning to use an UPDI device?

If so - you can install the latest beta pymcuprog from the test.pypi.org, and use the newly-added debug functions, for example: (note - this does not program the flash)

from pyedbglib.hidtransport.hidtransportfactory import hid_transport
from pymcuprog.avrdebugger import AvrDebugger
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO)

transport = hid_transport()
transport.connect()

avr = AvrDebugger(transport)

avr.setup_session("ATmega4808")
avr.start_debugging()
pc = avr.program_counter_read()
avr.step()
pc = avr.program_counter_read()
avr.stop_debugging()
mcsmark commented 2 years ago

ha, that is great news. first of all, thank you for taking the time to reply. i first wanted to use pymcuprog but i see i need the beta. i do use updi interface and i understand it will only work for that. i just tried with the beta but there seems to be some problem. first of all i use avr128da28. here is the output from the info log :

INFO: Manufacturer: Microchip Technology Incorporated INFO: Product: MPLAB Snap ICD CMSIS-DAP INFO: Serial Number: BUR190972701 INFO: Setting up avr128da28 for debugging INFO: Looking for device avr128da28 INFO: UPDI baud rate: 900000bps INFO: Starting debug session INFO: UPDI-specific initialiser INFO: SIB: ' AVR P:2D:1-3M2 (A7.KV001.0)

so that works well. but the avr.start_debugging() hangs in this code : flush_events(self): the poll_events always returns this : bytearray(b'\x82\x00\x00\x08\x0e\x10\x00\x12\x84\x00\x17\x00\n\x00AVR P:2D:1-3M2 (A7.KV001.0)\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') and thus keeps looping for ever.

xedbg commented 2 years ago

Oh... I can try to replicate a similar session here - which Snap debugger FW version are you using? (reported easily by "pymcuprog ping")

mcsmark commented 2 years ago

Connecting to anything possible Connected to MPLAB Snap ICD CMSIS-DAP from Microchip Technology Incorpora serial number BUR190972701) Debugger firmware version 1.9.223 Debugger hardware revision 1 Pinging device... Ping response: 1E970A

it should be the latest since it was updated with firmware just few days ago using mplax-x

xedbg commented 2 years ago

OK, that should be fine. Two things to try next:

mcsmark commented 2 years ago

ok, thanks, i will try that.

mcsmark commented 2 years ago

ok, that fixed the problem. i see some errors when i use stop_debuggin

INFO: Stop debugging session Exception ignored in: <function HidTransportBase.del at 0x00000000037F1AF0> Traceback (most recent call last): File "pyedbglib\hidtransport\hidtransportbase.py", line 60, in del File "pyedbglib\hidtransport\hidtransportbase.py", line 161, in disconnect File "pyedbglib\hidtransport\cyhidapi.py", line 116, in hid_disconnect File "D:\Python38\lib\logging__init.py", line 1433, in debug File "D:\Python38\lib\logging\init__.py", line 1699, in isEnabledFor TypeError: 'NoneType' object is not callable

dont know if that is normal or not. but it works. i am really happy with this :+1: thanks for your help and support.

xedbg commented 2 years ago

Well, thanks for the feedback - we will take a look to see what might cause this. We hope to release this package update in the next sprint (2 weeks) - of course this module is 'alpha'.

mcsmark commented 2 years ago

ok, great. i will test all functions, if i find a problem i share it here.