Forum > Embedded - AVR

How to debug AVR firmware with Lazarus ( Windows )

(1/2) > >>

Dimitrios Chr. Ioannidis:
Hi,

( I wanted to make a tutorial, for quite some time, on how to debug a AVR firmware on Windows. At least how I do it for my hobbyist projects. )

 Assuming that you have a workable avr embedded free pascal cross compiler, you'll need ( at the time of writing ) Lazarus trunk and to download also:


* Microchip Studio 7

* MiR's patched avr-gdb-8.3

  After installing MS7,  open Lazarus->Options, select from the left options tree the Debugger->Debugger backend, add a new configuration and select "GNU remote debugger (gdbserver)" for debugger type and put the avr-gdb-8.3 full path ( press the ... button to open the Choose debugger executable ).


  Lazarus and MS7's backend agent ( atbackend.exe ) simulator setup :


* Uncheck the Debugger_Remote_DownloadExe.


* In Debugger_Remote_Port put the same port number that you'll use in the MS7's backend agent /avr8-gdb-ports parameter ( see below ).

  i.e. 2345


* Drop down the EventProperties and


* in AfterConnect ( press the ... button to open the editor ) add the following :

monitor tool simulator
monitor device [avr device] ( i.e.  monitor device atmega328p )
load
break pascalmain
monitor reset
delete breakpoint 1


* in AfterInit you'll need the full path of your project elf file with forward slash dir separator:

i.e. file "G:/Programming/dimitris/Projects/uIP_FP/apps/hello-world/bin/avr-embedded/Debug/hello_world.elf"


* Select ieRunCloseOnStop for InitExec_Mode.


* In InitExec_RemoteTarget put the full path of the MS7's backend agent ( atbackend.exe ) with the parameter /avr8-gdb-ports matching the Debugger_Remote_Port.

  i.e. "C:\Program Files (x86)\Atmel\Studio\7.0\atbackend\atbackend.exe" /avr8-gdb-ports=2345
  Make sure that the  Debugger_Remote_Port also have the same port number.


* Drop down the InternalExceptionBreakPoints


* uncheck the ieRaiseBreakPoint


* uncheck the ieRunErrorBreakPoint.


* Select gdsbMain for InternalStartBreak.


* In RemoteTimeout put something like ~30 - 50.

  You'll end up with something like in LazarusATBackend_Simulator image.



  Lazarus and MS7's backend agent ( atbackend.exe ) and physical mcu's / boards setup :


* In Debugger_Remote_Port put the same port number that you'll use in the MS7's backend agent /avr8-gdb-ports parameter ( see below ).

  i.e. 2345


* Drop down the EventProperties and


* in AfterConnect ( press the ... button to open the editor ) add the following :

monitor tool [avr debugger] [serial] (if needed) ( i.e. for MPLAB SNAP, monitor snap BURXXXXXX )
monitor device [avr device] [debug interface] ( i.e.  monitor device atmega328p debugwire)


* Select ieRunCloseOnStop for InitExec_Mode.


* In InitExec_RemoteTarget put the full path of the MS7's backend agent ( atbackend.exe ) with the parameter /avr8-gdb-ports matching the Debugger_Remote_Port.

  i.e. "C:\Program Files (x86)\Atmel\Studio\7.0\atbackend\atbackend.exe" /avr8-gdb-ports=2345
  Make sure that the  Debugger_Remote_Port also have the same port number.


* Drop down the InternalExceptionBreakPoints


* uncheck the ieRaiseBreakPoint


* uncheck the ieRunErrorBreakPoint.


* Select gdsbMain for InternalStartBreak.


* In RemoteTimeout put something like ~30 - 50.

  You'll end up with something like in LazarusATBackend_Physical image. ( in the image I'm using a custom mEDBG debugger )



  Also, for AVR debugging is better to use dwarf 3 and not dwarf 2. But either is working fine, at least for me .

  Happy debugging !

PS: You can see a screenshot ( LazarusAVRDebugSession image )  from an actual Lazarus debugging session using MS7's backend agent ( atbackend.exe ).

regards,

Dimitrios Chr. Ioannidis:
Hi,

  if you're on linux or mac, you could still be able to use the above .

  AFAIU, MS7's backend agent is ( among other things ) a gdbproxy for their tools.

  You can have a separate windows box (or a windows VM) with the above setup and in the  Debugger_Remote_Port you just add the ip:port of that windows box. i.e. 192.168.1.5:2345.

  In this case, of course, the debugger tools and / or the boards to be debugged, are connected to the windows box and not on the development linux / mac box.

regards,

ccrause:
Thank you for the detailed instructions.

fliegermichl:
Thank you very much for the tutorial,

i have installed FPC and Lazarus trunk using fpcupdeluxe and created crosscompiler for embedded-AVR.
Then i have set up a virtual linux mint with "simulavr -d atmega328 -g -p 2345" acting as gdbserver.

My problem now is if i compile my avr project with debuggerinfo "dwarf" then i get the errormessage "can't find unit Infodwrf" if i try to compile with stabs the errormessage changes to can't find unit lineinfo.

if i compile without debuggerinfos there are no errors but i think then debugging is impossible?

Dimitrios Chr. Ioannidis:
Hi,


--- Quote from: fliegermichl on February 17, 2021, 12:09:19 pm ---
< snip >

My problem now is if i compile my avr project with debuggerinfo "dwarf" then i get the errormessage "can't find unit Infodwrf" if i try to compile with stabs the errormessage changes to can't find unit lineinfo.

< snip >


--- End quote ---

 Looking at https://forum.lazarus.freepascal.org/index.php/topic,30705.msg195525.html#msg195525, I think that you enable heaptrc . If so, then please uncheck the Use heaptrc unit option in project debugging page and try again.

Also, bear in mind, that this a tutorial for windows and atbackend not for simulavr and linux.

EDIT: Although, with the appropriate changes, there is no reason it shouldn't work.

regards,

Navigation

[0] Message Index

[#] Next page

Go to full version