Cross compiling installation for AVR lazarus / 78-Embedded - AVR ---------------------------------------------------------------------- process_1 · 2020-07-23 09:35 https://wiki.freepascal.org/AVR This guide is quite a bit obsolete now as the Atmel link which provides bintuils binaries is broken. I believe we all know that Atmel is sold to Microchip several years ago... - What would be exact steps to install cross-compiler for AVRs ? - Is it possible to precisely debug the code, regarding to shosen AVR model and crystal frequency in order to get precise cpu cycles count and variable values? ---------------------------------------------------------------------- trev · 2020-07-23 11:11 I replaced the Atmel links with Microchip links. ---------------------------------------------------------------------- d.ioannidis · 2020-07-23 11:46 Hi, Quote from: process_1 on July 23, 2020, 11:35:06 am< snip > - Is it possible to precisely debug the code, regarding to shosen AVR model and crystal frequency in order to get precise cpu cycles count and variable values?   Yes it is.   I'm able to debug physical AVR MCU's with Lazarus . I can set breakpoints, step in, step out,  see variables.   The only limitation currently, is that this is possible only with the use of Atmel Studio backend tools. No Linux or MacOS support ( for the tools ) until someone implement a gdb proxy for the mplab debugger which support Windows, Linux and MacOS. One workaround is to use a VM to host those tools and run Lazarus from MacOS and/or Linux which works.    As for debuggers, unfortunately the low price non HV programmer / debugger SNAP ( ~ 20€ ) is not supported yet in the Atmel Studio backend. AFAIK, it's  scheduled for addition at Q3 / Q4 this year . But you can use an xplained board ( look for those with an AVR mcu ), which have a debugger mcu on board specific for that board mcu.   Personal, I'm using a "custom" mEDBG debugger derived from the Xplained Yourself project. BTW, if you're only using mcu's with UPDI debug interface you could use a pro micro with some modifications as per the mcudude's microUPDI. PS: Maybe I should create a tutorial on how to setup such enviroment. regards, ---------------------------------------------------------------------- ccrause · 2020-07-23 12:11 Quote from: process_1 on July 23, 2020, 11:35:06 am- Is it possible to precisely debug the code, regarding to shosen AVR model and crystal frequency in order to get precise cpu cycles count and variable values? You can use avr-gdb and debug in Lazarus - for this you either need debugging hardware as per Dimitrios's post (for debugwire there are a couple of projects to easily hook up via a usb-serial dongle, search for debugwire on Github), or connect to a simulator/emulator (simavr, fp-avrsim, or qemu).  This will allow you to step through code, stop and inspect variables, memory, registers etc. The easy way to get cycle counts is to use either Atmel Studio or MPLAB X.  I've once tested an FPC compiled project in MPLAB X and it worked OK, but I stopped using it because it was frustratingly slow on my computer. The simulators listed above should also have cycle counters, but I haven't explored it myself. ---------------------------------------------------------------------- process_1 · 2020-07-23 12:50 First of all, thank you all. Hopefully, I have account on Microchip, thus had no issue to download required file avr8-gnu-toolchain-3.6.2.1759-linux.any.x86_64.tar.gz for toolchain. In ~/.bashrc I have added this line: export PATH=/usr/avr8-gnu-toolchain-linux_x86_64/bin:$PATH Then restarted the system and executed this script I have made previously: FPC_CrossLink_AVR Code: [Select]#!/bin/sh sudo cp avr8-gnu-toolchain-3.6.2.1759-linux.any.x86_64.tar.gz /usr cd /usr sudo tar zvxf avr8-gnu-toolchain-3.6.2.1759-linux.any.x86_64.tar.gz sudo rm  avr8-gnu-toolchain-3.6.2.1759-linux.any.x86_64.tar.gz sudo apt install avrdude cd /usr/share/fpcsrc/3.2.0 sudo make clean all OS_TARGET=embedded CPU_TARGET=avr sudo make crossinstall OS_TARGET=embedded CPU_TARGET=avr INSTALL_PREFIX=/usr SUBARCH=avr5 sudo ln -sf /usr/lib/fpc/3.2.0/ppcrossavr /usr/bin/ppcrossavr All passed well, but at end this error is shown: system.pp(325) Error: Assembler avr-embedded-as not found, switching to external assembling Indeed there is no avr-embedded-as inside /usr/avr8-gnu-toolchain- linux_x86_64/bin, just avr-as which is required file or not? If it is, then symbolic link will do the rest, I believe... ---------------------------------------------------------------------- d.ioannidis · 2020-07-23 12:57 Hi, Quote from: process_1 on July 23, 2020, 02:50:59 pm < snip > sudo make crossinstall OS_TARGET=embedded CPU_TARGET=avr INSTALL_PREFIX=/usr SUBARCH=avr5 < snip > Indeed there is no avr-embedded-as inside /usr/avr8-gnu-toolchain- linux_x86_64 fpc is searching for the fpc binutils starting with avr-embedded-* which AFAIU is only for windows . As you're using the official binutils binaries from Microhip, you should change the binutilsprefix from the avr-embedded- to avr-. Meaning you should add the BINUTILSPREFIX=avr- to the command line : Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sudo make crossinstall OS_TARGET=embedded CPU_TARGET=avr INSTALL_PREFIX=/usr SUBARCH=avr5 BINUTILSPREFIX=avr- regards, ---------------------------------------------------------------------- d.ioannidis · 2020-07-23 13:04 Hi,   FYI, an avr-embedded free pascal cross linux archive exists at ftp://ftp.hu.freepascal.org/pub/fpc/dist/3.2.0/avr-embedded/ . regards, ---------------------------------------------------------------------- process_1 · 2020-07-23 15:09 With suggestion regardin BINUTILSPREFIX it makes cross-compiler fine (attached script). Attached Blinky sample found somewhere at this forum is also compiled fine from commandline by: Code: [Select]ppcrossavr -Tembedded -Pavr -WpATMEGA328P -XPavr- Blinky.lpr However when tried to compile from IDE, it returns error regarding avr-embedded-as: Code: [Select]Project checks, Hints: 1 Note: passing compiler option -Cp twice with different values Compile Project, OS: embedded, CPU: avr, Target: Blinky: Exit code 1, Errors: 1 Blinky.lpr(7,1) Error: Assembler avr-embedded-as not found, switching to external assembling This is strange... Also "-Cp twice with different values". I have specifically set AVR5 group in project settings, but it is already set by defailt. Obvious conflict in parameters, or a bug. Another problem I can see is that ATmega2560 (which I'm using regularly) is in AVR6 group, while this compiler compiles only code for models from AVR5 group. Would this compiler can be configured to compile code for any AVR MCUs group, or it is currently limited only to AVR5 group? ---------------------------------------------------------------------- ccrause · 2020-07-23 15:52 Quote from: process_1 on July 23, 2020, 05:09:30 pm Code: [Select]ppcrossavr -Tembedded -Pavr -WpATMEGA328P -XPavr- Blinky.lpr Howere, when tried to compile from IDE, it returns error regarding avr-embedded-as: Code: [Select]Project checks, Hints: 1 Note: passing compiler option -Cp twice with different values Compile Project, OS: embedded, CPU: avr, Target: Blinky: Exit code 1, Errors: 1 Blinky.lpr(7,1) Error: Assembler avr-embedded-as not found, switching to external assembling In Lazarus you need to add the -XPavr- option to the project custom options (Project | Project Options | Custom Options). QuoteAnother problem I can see is that ATmega2560 (which I'm using regularly) is in avr6 group, while this co,piler compiles only models from avr5 group. Is this compiler can be configured to compile code for any AVR MCUs group, or it is currently limited only to avr6 group? The problem is that the compiler generates different units depending on the subarchitecture specified.  Unfortunately these units are all stored in a folder with the generic name avr-embedded by default.  This means that you can recompile the RTL and specify a different subarch, which will then overwrite the previous units.  To work around this, one has to build the RTL for a single subarch, then copy/move/install this into a differently named folder with a unique name, say avr-embedded-avr5 (some people prefer a subfolder with the subarch name e.g. avr-embedded/avr6).  The next step is to update the fpc.cfg file for the AVR target and set the unit paths for AVR according to this structure.  Somewhere in fpc.cfg look for a -Fu entry that points to the RTL and packages units and change them more or less as follows: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i # searchpath for units and other system dependent things#ifdef cpuavr  -Fu~/fpc/$fpcversion/rtl/units/$fpctarget-$fpcsubarch  -Fu~/fpc/$fpcversion/packages/*/units/$fpctarget-$fpcsubarch/*#else  -Fu~/fpc/$fpcversion/rtl/units/$fpctarget  -Fu~/fpc/$fpcversion/packages/*/units/$fpctarget#endif Obviously you have to adapt the folder template above to reflect your setup. If you are using make install then you can specify the destination folder using the following option: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i INSTALL_UNITDIR=/usr/local/lib/fpc/3.3.1/units/avr-embedded-avr5Again adapt to your specific path requirements (I don't install FPC so I'm not familiar with the typical paths used). ---------------------------------------------------------------------- d.ioannidis · 2020-07-23 16:15 Hi, Quote from: process_1 on July 23, 2020, 05:09:30 pm < snip > Also "-Cp twice with different values". I have specifically set AVR5 group in project settings, but it is already set by defailt. Obvious conflict in parameters, or a bug. < snip > It's not a bug. In Lazarus change the Target processor ( Project | Project Options | Compiler Options | Config and Target | Target processor ) to (default) and use the -Cp option in ( Project | Project Options | Compiler Options | Custom Options ) i.e. -CpAVR6 or -CpAVR25. Don't forget to enable the macro ( -Sm ) for the mcu frequency . For example this is what my custom options looks like from a avr project : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i -a-al-Xe- Xm-Sm-CpAVR25-WpATTINY2313A-XPavr--FD"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu- toolchain\bin"-godwarfsets-dF_CPU:=8000000 You can see what those options do if you click at the "All options.." button in the project custom options window. EDIT: Because the "All Options" window has a lot of options, you can check the "Show only modified" checkbox to filter out those that are not enabled. regards, ---------------------------------------------------------------------- process_1 · 2020-07-23 17:36 Quote from: ccrause on July 23, 2020, 05:52:25 pmThe problem is that the compiler generates different units depending on the subarchitecture specified.  Unfortunately these units are all stored in a folder with the generic name avr-embedded by default. ... For now, it is fine for me to recompile all whenever is necessary to change of MCU from another group, as recompilation is much faster now on new hardware. Anyway, the whole process definitely require to be suggested to be fixed "officially" for some next realease of FPC. ---------------------------------------------------------------------- process_1 · 2020-07-23 17:51 Dimitrios, Thank you once again for all info, it worked now as should be. One thing only require to be clarified: Quote from: process_1 on July 23, 2020, 05:09:30 pm It's not a bug. In Lazarus change the Target processor ( Project | Project Options | Compiler Options | Config and Target | Target processor ) to (default) and use the -Cp option in ( Project | Project Options | Compiler Options | Custom Options ) i.e. -CpAVR6 or -CpAVR25. If Target processor is chaged, thus -Cp in Custom Options have to be changed accordingly, I suppose. With MCUs, additional combobox with filtered MCU list is as well desired to be shown instead to manually change -CP. As well additional edit field for frequency in -dF_CPU is welcome. Similar as used in MPLABX and many other compilers in order to simplify and clear all. Perhaps also posibility to use some compiler directives in the main file for some settings, as F_CPU and specific MCU. BTW, is it F_CPU allowed to be used in the code, for delays, USART or similar code modifications in order to calculate some constants without need to change it whenever change frequency or MCU? ---------------------------------------------------------------------- ccrause · 2020-07-23 18:13 Quote from: process_1 on July 23, 2020, 07:36:45 pm Anyway, the whole process definitely require to be suggested to be fixed "officially" for some next realease of FPC. This issue has been around for quite a while (e.g. this discussion) but no fix has been included in trunk yet. It also affects other targets such as ARM and xtensa. ---------------------------------------------------------------------- d.ioannidis · 2020-07-23 18:30 Hi, Quote from: process_1 on July 23, 2020, 07:51:25 pm < snip > One thing only require to be clarified: Quote from: process_1 on July 23, 2020, 05:09:30 pm It's not a bug. In Lazarus change the Target processor ( Project | Project Options | Compiler Options | Config and Target | Target processor ) to (default) and use the -Cp option in ( Project | Project Options | Compiler Options | Custom Options ) i.e. -CpAVR6 or -CpAVR25. If Target processor is chaged, thus -Cp in Custom Options have to be changed accordingly, I suppose. < snip >  Those are mutually exclusive. If you set the Target processor then the IDE sets the -Cp option. Thats why I thought that you had the error. You had set the Target processor to AVR5 and also in custom options you added a -CpAVR5 option.   You can always check the fpc command line call with the "Show Options" button in the Project Option window. Quote from: process_1 on July 23, 2020, 07:51:25 pm < snip > With MCUs, additional combobox with filtered MCU list is as well deisered to be shown instead to manually change -CP. As well additional edit field for frequency in -dF_CPU is welcome. Similar as used in MPLABX and many other compilers in order to simplify and clear all. Perhaos also posibility to use compiler directives in the main file for some settings, as F_CPU and specific MCU. < snip >   A package which do what you suggest exist ( didn't test it my self ) already. Look at AVR / Arduino GUI Package for Lazarus. Quote from: process_1 on July 23, 2020, 07:51:25 pm < snip > BTW, is it F_CPU allowed to be used in the code, for delays, USART or similar code modifications in order to calculate some constants without need to change it whenever change frequency or MCU?   Yes this is exactly the purpose.  You can read about macro's and embedded targets here. regards, ---------------------------------------------------------------------- process_1 · 2020-07-23 18:47 Quote from: Dimitrios Chr. Ioannidis on July 23, 2020, 08:30:13 pmYou had set the Target processor to AVR5 and also in custom options you added a -CpAVR5 option. I didn't change a thing in "Custom options" memo. The -CpAVR5 where by default, even I didn't set it in IDE. When I choose AVR5 in IDE, this warning was shown. As well, -Wpatmega328p is there by default. All that makes me to believe this is a bug. ---------------------------------------------------------------------- d.ioannidis · 2020-07-23 19:13 Hi, Quote from: process_1 on July 23, 2020, 08:47:49 pm < snip > All that makes me to believe this is a bug. I didn't notice such behavior. But if you can reproduce it, you should report it to the bug tracker. regards, ---------------------------------------------------------------------- process_1 · 2020-07-29 01:54 Quote from: Dimitrios Chr. Ioannidis on July 23, 2020, 09:13:44 pmI didn't notice such behavior. But if you can reproduce it, you should report it to the bug tracker. regards, Well, that is how it behaves with the attached blinky example, where actually existed some parameters in "Custom options". With absolutely new project, the "Custom options" memo is emply. But here "Generate info for the debugger" need to be disabled, otherwise this error is shown: Code: [Select]Compile Project, OS: embedded, CPU: avr, Target: Test: Exit code 1, Errors: 1 Fatal: Cannot find lnfodwrf used by Test. ---------------------------------------------------------------------- ccrause · 2020-07-29 07:12 Quote from: process_1 on July 29, 2020, 03:54:52 am... With absolutely new project, the "Custom options" memo is emply. But here "Generate info for the debugger" need to be disabled, otherwise this error is shown: Code: [Select]Compile Project, OS: embedded, CPU: avr, Target: Test: Exit code 1, Errors: 1 Fatal: Cannot find lnfodwrf used by Test. Yes I agree, please log a bug report for this.  The lnfodwrf unit is not available for the AVR target. ---------------------------------------------------------------------- ccrause · 2020-07-29 09:28 Quote from: ccrause on July 23, 2020, 08:13:38 pmQuote from: process_1 on July 23, 2020, 07:36:45 pm Anyway, the whole process definitely require to be suggested to be fixed "officially" for some next realease of FPC. This issue has been around for quite a while (e.g. this discussion) but no fix has been included in trunk yet. It also affects other targets such as ARM and xtensa. For reference note that an issue requesting inclusion of subarch in the unit folder name has been created in 2016 already: https://bugs.freepascal.org/view.php?id=30294 ---------------------------------------------------------------------- process_1 · 2020-07-29 09:37 Huh, created 2016 and last change in 2018 for such trivial issue! Quote from: ccrause on July 29, 2020, 09:12:01 amYes I agree, please log a bug report for this.  The lnfodwrf unit is not available for the AVR target. Be my guest, I have no account in bugtrucker. ---------------------------------------------------------------------- PascalDragon · 2020-07-29 11:40 Quote from: process_1 on July 29, 2020, 11:37:19 amHuh, created 2016 and last change in 2018 for such trivial issue! It might seem easy to you, but this is not necessarily the case. See the mailing list discussion that is referenced from the issue report. ---------------------------------------------------------------------- process_1 · 2020-07-29 14:11 Quote from: PascalDragon on July 29, 2020, 01:40:07 pmIt might seem easy to you, but this is not necessarily the case. See the mailing list discussion that is referenced from the issue report. I really have no luck when I opened the mailing list link: Code: [Select]Secure Connection Failed An error occurred during a connection to www.mail-archive.com. SSL received a record with an incorrect Message Authentication Code. Error code: SSL_ERROR_BAD_MAC_READ What happening here? ---------------------------------------------------------------------- PascalDragon · 2020-07-29 14:23 Don't know, mail-archive is not controlled by us. Here is the same thread on our own archive (it's continued in August here). ---------------------------------------------------------------------- process_1 · 2020-07-29 14:25 Thanks, that can be opened fine. ---------------------------------------------------------------------- process_1 · 2020-07-29 14:38 https://lists.freepascal.org/pipermail/fpc-devel/2018-July/039489.html Well, according to this, fpmkunit is a problem. What is so dificult to fix it to support subarch? Indeed, simply adding subarch and changing in few places in make scripts and FPC/Lazarus sources sounds fairly easy to me. But, I can't judge, since I have not looking inside the sources, nor I have working solution for that. ---------------------------------------------------------------------- PascalDragon · 2020-07-29 21:00 Did you also read the followup from August I linked to? ---------------------------------------------------------------------- process_1 · 2020-07-30 14:45 Yes, I did. There is several ways to do this, if I understand correctly. But simply just pick one, whatever, and fix this. Waiting several years for this issue is just too much. ---------------------------------------------------------------------- pascalbythree · 2022-09-11 14:15 While installing FPC for AVR i got this error, plenty of times Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Fatal: Can't find unit system used by delay Does anybody have system.pp for AVR ? To place in the directory and help me compile it again. Greetz W ---------------------------------------------------------------------- d.ioannidis · 2022-09-11 14:28 Quote from: pascalbythree on September 11, 2022, 04:15:13 pmWhile installing FPC for AVR i got this error, plenty of times Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Fatal: Can't find unit system used by delay Can you please post more info so we can understand the problem ? Which OS ? Which compiler version used for bootstrap ? Which compiler sources version used ? Commands used for building the cross compiler ? regards, ---------------------------------------------------------------------- Mathias · 2022-09-20 12:08 I always use fpcupdeluxe, which usually allows you to build a cross- compiler for most embedded systems straight away. AVR should work right away if you use the stable from FPC and Lazarus. https://wiki.freepascal.org/AVR_Embedded_Tutorial_- _Entry_Lazarus_and_Arduino ---------------------------------------------------------------------- dalfy · 2023-01-06 20:12 Why do I not have a menu with commands after clicking Ctrl+space? ---------------------------------------------------------------------- BlueIcaro · 2023-02-06 16:08 Try to rescan FPC Source Directory in tools menu /BlueIcaro