Recent

Author Topic: How to debug AVR firmware with Lazarus ( Windows )  (Read 2317 times)

Dimitrios Chr. Ioannidis

  • Full Member
  • ***
  • Posts: 167
    • Nephelae
How to debug AVR firmware with Lazarus ( Windows )
« on: February 16, 2021, 09:44:43 pm »
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:


  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,
« Last Edit: February 16, 2021, 11:05:02 pm by Dimitrios Chr. Ioannidis »
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

Dimitrios Chr. Ioannidis

  • Full Member
  • ***
  • Posts: 167
    • Nephelae
Re: How to debug AVR firmware with Lazarus ( Windows )
« Reply #1 on: February 17, 2021, 08:05:33 am »
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,
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

ccrause

  • Hero Member
  • *****
  • Posts: 592
Re: How to debug AVR firmware with Lazarus ( Windows )
« Reply #2 on: February 17, 2021, 09:11:45 am »
Thank you for the detailed instructions.

fliegermichl

  • New member
  • *
  • Posts: 7
Re: How to debug AVR firmware with Lazarus ( Windows )
« Reply #3 on: February 17, 2021, 12:09:19 pm »
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

  • Full Member
  • ***
  • Posts: 167
    • Nephelae
Re: How to debug AVR firmware with Lazarus ( Windows )
« Reply #4 on: February 17, 2021, 12:31:17 pm »
Hi,


< 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 >


 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,
« Last Edit: February 17, 2021, 12:42:53 pm by Dimitrios Chr. Ioannidis »
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

ccrause

  • Hero Member
  • *****
  • Posts: 592
Re: How to debug AVR firmware with Lazarus ( Windows )
« Reply #5 on: February 17, 2021, 12:49:18 pm »
Edit: Apologies, this reply didn't actually address any issue relevant to this discussion :-[
« Last Edit: February 17, 2021, 12:54:23 pm by ccrause »

fliegermichl

  • New member
  • *
  • Posts: 7
Re: How to debug AVR firmware with Lazarus ( Windows )
« Reply #6 on: February 17, 2021, 01:19:41 pm »
Thank you for the Hints.

heaptrc was not checked but "Display line numbers in run-time error backtraces" was. I removed it and now it compiles fine.
Now i will go further...

EDIT: I'm working on windows 10 64 Bit crosscompiling to embedded avr. If i have no success with simulavr then i try Microchip Studio..

Dimitrios Chr. Ioannidis

  • Full Member
  • ***
  • Posts: 167
    • Nephelae
Re: How to debug AVR firmware with Lazarus ( Windows )
« Reply #7 on: February 19, 2021, 11:55:41 am »
Hi,


< snip >

EDIT: I'm working on windows 10 64 Bit crosscompiling to embedded avr. If i have no success with simulavr then i try Microchip Studio..

  forgot to mention, the fpc team builded new avr-embedded binutils binaries for windows, approx. a week ago. The old binaries had some problems with fpc dwarf ( or the other way around ), see https://lists.freepascal.org/pipermail/fpc-devel/2021-February/043560.html.

  I don't know with which avr-embedded binutils version fpcupdeluxe comes with, but in case you experience debugging difficulties, you could try using the avr-embedded binutils binaries from https://svn.freepascal.org/svn/fpcbuild/binaries/i386-win32 .

regards,
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

 

TinyPortal © 2005-2018