Lazarus

Programming => Embedded => Operating Systems => Embedded - AVR => Topic started by: ykot on January 02, 2016, 09:27:06 pm

Title: FPC/Lazarus Arduino Tutorial
Post by: ykot on January 02, 2016, 09:27:06 pm
As it has been asked in another thread (http://forum.lazarus.freepascal.org/index.php/topic,29852.msg197126.html), I'm writing this as a quick/short tutorial for people who want to try programming their Arduino Uno (https://www.arduino.cc/en/Main/ArduinoBoardUno) using FreePascal and Lazarus. The steps should work on Windows and Linux.

1. Make sure you are running up-to-date Trunk versions of both FreePascal and Lazarus. There are several posts on this forum as well as Internet blogs about it, so make sure to check those. You should be having a fully working environment before proceeding and be comfortable configuring and rebuilding the trunk yourself.

2. On Windows, instead of AVR Toolchain (http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx), you may want to just use FPCBuild Binaries (http://svn2.freepascal.org/svn/fpcbuild/binaries/i386-win32), which include AVR-related tools with prefix "avr-embedded-" (e.g. "avr-embedded-as.exe"). Make sure you have all these tools in some folder that you can easily remember.

On Linux, there is official AVR Toolchain (http://www.atmel.com/tools/atmelavrtoolchainforlinux.aspx). If you happen to use Debian-based distribution, just use:
Code: [Select]
sudo apt-get install binutils-avr

3. Make sure to use latest version of avrdude. On Windows, you can download it from here (http://download.savannah.gnu.org/releases/avrdude/avrdude-6.1-svn-20131205-mingw32.zip). For Linux, you can pick the appropriate version from this list (http://download.savannah.gnu.org/releases/avrdude/). On Debian-based distribution, use:
Code: [Select]
sudo apt-get install avrdude

4. Compile trunk FreePascal for AVR target. On Windows, this is a sample batch script, which you may want to fine-tune yourself:
Code: [Select]
SET FPC_PATH=%CD%\3.0.0\bin\i386-win32
SET PPCBIN=%FPC_PATH%\fpc.exe
SET INSTALL_PATH=%CD%\Win32
SET PATH=%FPC_PATH%;%NDK_BIN%;%PATH%
make clean crossall crossinstall FPC=%PPCBIN% OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=%INSTALL_PATH% CROSSBINDIR=%GNU_BIN_PATH% BINUTILSPREFIX=avr-embedded- CROSSOPT="-O3 -XX -CX"
In above code, adjust the paths as needed. Pay special attention to "GNU_BIN_PATH", which should point to the path, where you downloaded FPCBuild binaries for AVR.

On Linux, you can use the following script (assumes FPC is installed in "/usr/local"):
Code: [Select]
#!/bin/sh
set -e
make clean crossall OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 BINUTILSPREFIX=avr- CROSSOPT="-O3 -XX -CX"
sudo make crossinstall OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5
sudo ln -s -f /usr/local/lib/fpc/3.1.1/ppcrossavr /usr/local/bin/ppcrossavr

In above scripts, notice "avr5" subarch flag. This may be different for other Atmel chips, in FreePascal sources open to "/rtl/embedded/Makefile" to see what chip corresponds to each subarch. For Arduino Uno and ATMega328P, this is "avr5".

5. Edit "fpc.cfg" and on Windows add the following:
Code: [Select]
#ifdef embedded
-FD$GNU_BIN_PATH$
-OoFastMath
#-XX
-CX
-Oonostackframe
#ifdef avr
-XPavr-embedded-
#endif
#endif
Note that "GNU_BIN_PATH" should be set as a global environment variable pointing to AVR tools that you've installed in step 2.

On Linux, add something like this:
Code: [Select]
#IFDEF embedded
-OoFastMath
-XX
-CX
-OoNoStackFrame
#IFDEF cpuavr
-XPavr-
#ENDIF
#ENDIF

6. Open the attached example "Blinky" and try compiling it. If you have configured toolchains and built FreePascal for AVR target correctly, it should succeed. You should obtain files such as "Blinky.elf", "Blinky.hex" and "Blinky.bin". Either one of these files can be used for uploading to Arduino.

7. Upload the resulting executable to Arduino using its own bootloader and avrdude. The command would be something like:
Code: [Select]
sudo avrdude -v -patmega328p -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:Blinky.hex:i
In above command, on Linux, "/dev/ttyACM0" is the path to mapped serial port after connecting Arduino, make sure to adjust it as needed. On Windows, it would probably be something like:
Code: [Select]
avrdude -v -patmega328p -carduino -P\\.\COM3 -b115200 -D -Uflash:w:Blinky.hex:i

If the operation is successful, the application should execute immediately and you should see internal LED blinking. If you have any problems with this, feel free to ask here.

Note that attached example accesses port bits directly, similar to C/C++ AVR samples. Currently, there is no higher-level framework, but PXL (http://www.afterwarp.net/products/pxl) on GitHub (https://github.com/yunkot/pxl) is being ported. Meanwhile, you can just use code similar to AVR C tutorials (http://www.avr-tutorials.com/).

The following are some limitations on AVR target:
To figure out what Arduino pin corresponds to what port, you can use pinout diagram from this post (http://forum.arduino.cc/index.php?topic=146315.0). Internal LED appears to be connected to pin 13 (PB5).
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: Edson on January 03, 2016, 07:15:50 pm
Interesting.

I will check when I get some time.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 30, 2016, 10:26:45 pm
Has anyone been able to get this working for windows 7 or 8? I have just spent 4 hours and I am getting no closer.

The instructions on this page are are not complete or ambiguous at best.

I can see the OP, ykot, has been active up to yesterday so I am hoping he/she can shed some light as I am getting nowhere.

I am at the point with the Arduino stuff, where I need to spend a month or so to learn C/C++ OR try and get something that will compile and upload to to the Arduino.

I have been programming in Pascal for 35+ years and the mental move to C/C++ is too much for this tired old brain. :)

Thanks
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: Laksen on January 30, 2016, 11:41:10 pm
Maybe if you told where you were stuck it would be easier to help :)
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 31, 2016, 12:28:49 am
Maybe if you told where you were stuck it would be easier to help :)

OK, good point. I downloaded the latest Lazarus and did a clean install to D:\Lazarus on a win8.1 i5 8MB that had never seen Lazarus before.
I downloaded six "avr-embedded...exe files and put them in a Folder within Lazarus "d:\Lazarus\AVREmbedded"
Saved the .bat file as "install01.bat" and here is the contents of it.
Code: [Select]
SET FPC_PATH=d:\lazarus\fpc
SET PPCBIN=%FPC_PATH%\fpc.exe
SET INSTALL_PATH=%CD%\Win32
SET PATH=%FPC_PATH%;%NDK_BIN%;%PATH%
make clean crossall crossinstall FPC=%PPCBIN% OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=%INSTALL_PATH% CROSSBINDIR=d:\lazarus\AVREmbedded BINUTILSPREFIX=avr-embedded- CROSSOPT="-O3 -XX -CX"

When I ran that it complained about "no make" so I found an earlier version of Arduino that had make.exe and copied it to the Lazarus folder.

I opened an elevated command prompt and navigated to d:\Lazarus and ran the .bat file.

...and got this...
Code: [Select]
D:\Lazarus>install01

D:\Lazarus>SET FPC_PATH=d:\lazarus\fpc

D:\Lazarus>SET PPCBIN=d:\lazarus\fpc\fpc.exe

D:\Lazarus>SET INSTALL_PATH=D:\Lazarus\Win32

D:\Lazarus>SET PATH=d:\lazarus\fpc;;d:\lazarus\fpc;;d:\lazarus\fpc  d:\lazarus\f
pc;;d:\lazarus\fpc;;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\W
indows\System32\WindowsPowerShell\v1.0\

D:\Lazarus>make clean crossall crossinstall FPC=d:\lazarus\fpc\fpc.exe OS_TARGET
=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=D:\Lazarus\Win32 CROSSBINDI
R=d:\lazarus\AVREmbedded BINUTILSPREFIX=avr-embedded- CROSSOPT="-O3 -XX -CX"
makefile:29: *** You need the GNU utils package to use this Makefile.  Stop.

It seems the instructions for the .bat file are incorrect, incomplete and/or ambiguous.

It would make more sense if the instructions were in two separate parts. One for windows and one for linux instead of being interleaved.

The .bat file needs to use actual install folders using the default Lazarus installation. I changed only the drive letter during the default  installation.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: molly on January 31, 2016, 12:39:43 am
Hi HatForCat,

my FPC binaries are inside: Q:\WinDev\Lazarus\FPC\2.6.4\bin\i386-win32 and that seems a bit different when comparing that with yours.

That would probably cause the batch file to not be able to find the required executables.

you can check by opening a command shell and typing fpc and see what that returns.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 31, 2016, 12:49:08 am
Thanks Molly,

OK, changed to that and got some more errors so copied the six avr files to the Lazarus folder and then it did a lot of stuff.

I loaded the Blinky file and got
d:\lazarus\FPC\2.6.4\bin\i386-win32\fpc.exe does not support target avr-embedded.

Compile Project, OS: embedded, CPU: avr, Target: Blinky: Exit code 1, Errors: 1
Error: Illegal processor type "avr"

Shutting down for the night, "duty" calls. :)

Thanks so far, I feel we are getting closer...
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 31, 2016, 01:55:05 pm
OK, so I have uninstalled everything and did another clean full install of Lazarus.

I think the problems are coming from the use of Path-tokens in the Batch file as I don't have these predefined

%CD%
%NDK_BIN%
%INSTALL_PATH%\Win32  <-- what is that ?Install for what?

Could someone please just give me a copy of that batch file with all their actual things defined and I can figure it out from there.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: molly on January 31, 2016, 02:37:49 pm
HiHatForCat,

I can't help you with the actual values (as they are specific for your setup), but i can attempt to tell you what they do:

%CD% is representing teh current directory (automatically filled by dos shell -> do a echo %CD% in a shell to see for yourself)

%NDK_BIN% should be the path to your SDK. use SET NDK_BIN=Path_to_your_NDK_Directory

%INSTALL_PATH% is used for the INSTALL_PREFIX option and is used as a location where to store the final results

"Error: Illegal processor type "avr"" seems to indicate that your compiler does not support this cpu, hence why you need to create one that does (read: create cross-compiler).

PS: Sometimes, the makefiles get confused by residue that was left behind by a previous attempt. in that case do a "make clean" before you start the batch again.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 31, 2016, 04:30:16 pm
Hi Molly,

Thank you so much for taking the time to explain this. VERY much appreciated.

%NDK_BIN% should be the path to your SDK. use SET NDK_BIN=Path_to_your_NDK_Directory

Thanks, but what SDK? A Software Developers Kit for what? Do I have to download something else? What? Where?

PS: Sometimes, the makefiles get confused by residue that was left behind.

Thanks, I am already doing that. I use Revo to uninstall Lazarus, then roll back with a System Restore. Been caught too many times in the past dealing with hidden remnants. :)
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: molly on January 31, 2016, 04:45:08 pm
Thanks, but what SDK? A Software Developers Kit for what? Do I have to download something else? What? Where?
I am unfamiliar with this particular target, so you would need to ask the person that wrote the instructions  :D

Generally speaking, some targets require extra files to be able to compile working executables for the target with FPC or requires extra utilities to aid development cycle.

I can only assume that the person writing the instructions meant the avrdude utils. (but please note that there might be more to it).

Well, at least i figured out that you can't create a cross-compiler from 3.0.0 release source files:
Quote
Clean of package fpc-all completed
MAKE[3]: Leaving directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0/packages'
MAKE[2]: Leaving directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0'
MAKE rtl_all FPC=D:/Temp/Build-FPC-from-source/fpc-3.0.0/compiler/ppcrossavr.exe FPCFPMAKE=D:/Temp/Build-FPC-from-source/fpc-3.0.0/compiler/ppc.exe RELEASE=1 'OPT='
MAKE[2]: Entering directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0'
MAKE -C rtl all
MAKE[3]: Entering directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0/rtl'
MAKE -C embedded all
MAKE[4]: Entering directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0/rtl/embedded'
D:/Temp/Build-FPC-from-source/fpc-3.0.0/compiler/ppcrossavr.exe @rtl.cfg -Ur -Tembedded -Pavr -XPavr- -Xr -Ur -Xs -O2 -n -Fi../inc -Fi../avr -FDD:\WinDev\BinUtils -FE. -FUD:/Temp/Build-FPC-from-source/fpc-3.0.0/rtl/units/avr-embedded -davr -dRELEASE -Us -Sg system.pp
sstrings.inc(1004,1) Fatal: Internal error 200309041
Fatal: Compilation aborted
MAKE[4]: Leaving directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0/rtl/embedded'
MAKE[3]: Leaving directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0/rtl'
MAKE[2]: Leaving directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0'
MAKE[1]: Leaving directory `D:/Temp/Build-FPC-from-source/fpc-3.0.0'
 
Log stopped zo 31-01-2016, 16:36:42,50

So afaik that means you would have to install 3.0.0, and attempt to build the cross-compiler from trunk sources (but user ykot did wrote that)
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 31, 2016, 05:39:01 pm
OK, thanks Molly. I quit.

The OP's instructions are too vague and as you have found out, just plain wrong in some places. There is great skill required in writing effective instructions and these were not it.

It is far better to have no instructions rather than poor ones that only frustrate after wasting many hours. :)

BUT, thank you very much for trying to help. I have been programming in Pascal for 35+ years and the learning curve for C/C++ for the Arduino was too great a stretch so I was hoping for this to work. Ahhh well, uninstall Lazarus (I used Delphi) and back to the C/C++ tutorials.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: molly on January 31, 2016, 07:30:26 pm
@HatForCat
Quitter  :P  ;)

ykot's instructions do mention needing to create the cross-compiler from FPC trunk sources, it could be that you missed that part ?

I can't judge ykot's instructions fully, as i didn't created the cross-compiler from trunk but from fpc 3.0 source-tree (i had that sitting on my disk, so that was easy to test).

Basically, these instructions from ykot seems correct to me (although it does leave room for interpretation, especially if not understanding fully what each and every parameter/option does).

For my situation, things worked as advertised (except for the error i ran into creating the FPC RTL)

The only thing that doesn't make sense to me is having lazarus compiled from trunk (afaik there is no need for that).

Please realize that afaik, the compiler for avr is a work in progress (and therefor experimental -> bad things might happen). The target seems not suited for end-users (yet).

In that regards, i disagree a little with your opinion to have no instructions at all. Every error you run into will help improve things, as developers do read these kind of things (might be that a bug-report needs to be created though -> i haven't looked yet if it was already reported or perhaps already fixed in trunk).

edit:
... and a little search led me to this (http://forum.lazarus.freepascal.org/index.php/topic,27737.msg171850.html) thread (which reports the same error as i ran into).

Looking at the commits, then i can see a related commit here (http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=32441)
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 31, 2016, 08:09:37 pm
Quitter

:) It does not happen often, but I look at it as a positive thing making me go learn C++. I have been putting it off for years. But, given that I am 76 and retired there seemed no real point. Now that I am messing with Arduino, the point has become obvious.

Unless I can find out what the %NDK_BIN% means it is pointless.

I saw the mention of "trunks" and did some google searching and could not find anything so assumed it just meant the latest version of Lazarus so that's what I downloaded.

I stand by the "no instructions" as it is useless trying to do something if a large chunk of the instructions assumes I am an expert on Lazarus and the things needed to create a cross-compiler with it. By definition a Tutorial should be for the lowest common denominator. Many years back, I wrote quite a few award winning (by peers) technical manuals and they all covered things taking into consideration the barest novice to the trained expert. They all had sidebars on every page indicating the level of prior knowledge needed to read or skip.

Now, I am not by any stretch expecting that degree of detail on a free website, but I do expect tutorials to be just that. If a "trunk" version is need then a link to that download is mandatory.

Quitting rather than massive esophageal reflux after many hours of frustration guessing what the tutorial meant, was/is the better option. I would have been happy to write a complete tutorial on the subject for this site, but if I can't get it working what could I write. <-- Yes, rhetorical.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: engkin on January 31, 2016, 08:10:54 pm
For Windows:

1-Install latest Lazarus ( I installed Lazarus 1.6 RC2 mentioned here (http://forum.lazarus.freepascal.org/index.php/topic,31095.0.html) ) later on I'll assume that  you installed it in c:\Laz1.6RC2 folder.
2-Get FPC trunk ( you can get the archived version from ftp://ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip )
3-Decompress that archive somewhere (if you did that in c:\avrtest then you should have a file named Makefile in c:\avrtest\fpc\ folder )
4-Get the avr toolchain (avr-embedded-* from here (http://svn2.freepascal.org/svn/fpcbuild/binaries/i386-win32) )
5-I put the avr-embedded-* files in c:\avrtest folder
6-Make a batch file in c:\avrtest\fpc\ , where the Makefile file located, and name the batch file avrbuild.bat that contains:

Code: Text  [Select][+][-]
  1. REM if you installed Lazarus 1.6 RC2 in c:\Laz1.6RC2 it comes with FPC.exe in c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32 folder
  2. REM That is the folder we need to add here.
  3. SET FPC_PATH=c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32
  4.  
  5. REM The compiler itself ( Which its location is saved in FPC_PATH )
  6. SET PPCBIN=%FPC_PATH%\fpc.exe
  7.  
  8. REM A folder where the generated cross compiler and run-time libraries are going to be saved
  9. SET INSTALL_PATH=c:\avrtest\Win32
  10.  
  11. REM We need the path to avr-embedded-* files
  12. SET NDK_BIN=c:\avrtest\
  13.  
  14. REM Make all the binary files that we need accessible
  15. SET PATH=%FPC_PATH%;%NDK_BIN%;%PATH%
  16.  
  17. REM Use the correct SUBARCH here
  18. REM for Uno (ATMega328P) use avr5
  19. REM for Mega (ATMega2560) use avr6
  20. REM To find the correct SUBARCH value check http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/embedded/Makefile?view=co
  21. REM Start the process
  22. make clean crossall crossinstall FPC=%PPCBIN% OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=%INSTALL_PATH% CROSSBINDIR=%GNU_BIN_PATH% BINUTILSPREFIX=avr-embedded- CROSSOPT="-O3 -XX -CX"

Make sure to use the correct SUBARCH, for Uno (ATMega328P) use avr5, for Mega (ATMega2560) use avr6. Check /rtl/embedded/Makefile (http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/embedded/Makefile?view=co) to find the correct one.

7-Start a command window ( Run - Type cmd  )
8-Move to the directory where you saved the previous batch file ( CD c:\avrtest\fpc )
9-Run the batch file ( type avrbuild.bat and hit Enter )
10-Wait and be patient ( patience is a virtue! )

If it succeeded then you should have:
1-a cross compiler named ppcrossavr.exe in c:\avrtest\win32\bin\i386-win32
2-compiled rtl units in c:\avrtest\units\avr-embedded\

How to use them is a different story (http://forum.lazarus.freepascal.org/index.php/topic,30960.msg200624.html#msg200624).

Corrections:
1-Thanks to jmpessoa, the folder name I chose is avrtest, not armtest.
2-Thanks to HatForCat: corrected the link to FPC trunk archive.
3-Thanks to HatForCat: corrected the name of the Makefile (not make).
4-Thanks to HatForCat: corrected the path for fpc binaries.
5-Thanks to HatForCat: avr5 for Uno, avr6 for Mega.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: molly on January 31, 2016, 09:06:35 pm
.. it off for years. But, given that I am 76 and retired there seemed no real point. Now that I am messing with Arduino, the point has become obvious.
We can't have you switch to c(++), really there is no point especially at such respectable age :-)

Quote
I saw the mention of "trunks" ...
Every FPC/Lazarus you can download from official link and install is a release (whether it is a beta, a release candidate or otherwise).

with trunk is meant, the very up to date sources that are stored on the svn/git server. Every time a developer makes a change/improvement/otherwise to the FPC sources, the developer 'uploads' his local stored changes to the svn/git server. Git/svn is version control, consisting of tools that allows multiple developers to work at same source-tree and doing so at the same time (such as in FPC's/Lazarus' case).

Quote
...if a large chunk of the instructions assumes I am an expert on Lazarus and the things needed to create a cross-compiler with it. By definition a Tutorial should be for the lowest common denominator.
Although i understand that from end-user perspective, it is assumed that when using trunk that you know what you are doing.

A 'tutorial' on how to build the experimental compiler from trunk for avr, was/is actually written here (http://wiki.freepascal.org/AVR).

Quote
Now, I am not by any stretch expecting that degree of detail on a free website, but I do expect tutorials to be just that. If a "trunk" version is need then a link to that download is mandatory.
I think that was/is a small oversight in that the person writing the tutorial assumed that you understand where to 'fetch' trunk sources.

It was not my intention to grieve you in any way with my quitter remark... actually i was trying to encourage you to try again and report further 'errors' or 'incomprehensible' instructions -> that is the only way able to let things improve.


Thanks to engkin, he wrote very detailed instructions that should work for you. (i was actually starting to write something similar, based on your return answer).

@engkin:
thank you very much.

edit: typo's
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: jmpessoa on January 31, 2016, 09:22:53 pm

Hint:

 "arduino-using-lazarus-free-pascal"

https://bigdanzblog.wordpress.com/full-list-of-posts/







Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 31, 2016, 11:00:57 pm
Thanks Molly, I understood the light heart-ed "quitter," it's all good.

I basically understood what  trunk meant but could not find it anywhere. Even searching with google returned no links to trunk downloads and that's why I reverted to the current stable. When you know where to look it is simple.

it is assumed that when using trunk that you know what you are doing.

haaa, ha. :) If I couldn't find a trunk how would I know what to do?

Thanks to engkin, he wrote very detailed instructions that should work for you. (i was actually starting to write something similar, based on your return answer).

I appreciate the efforts of both of you. There is a typo in the link to the FPC
http://ftp//ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip

should be...
ftp://ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip

I knew enough to figure that out. Stuff downloading as I type.

I had seen the wiki page but the opening sentence
Quote
The FPC-AVR port is currently experimental and non working.
Was too ominous to bother with trying.

p.s.
I had also found big Dan's site but I am already happy with the Delphi code I have written that uses the Serial ports to communicate both ways with the Arduino boards. I went looking for this Lazarus/AVR solution as my skills with the Arduino C/C++ were hitting a technical wall. I  was fine with the basic programming, but am now running out of skill for the more advanced stuff I need the Arduino to do.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: engkin on January 31, 2016, 11:21:19 pm
Hint:

 "arduino-using-lazarus-free-pascal"

https://bigdanzblog.wordpress.com/full-list-of-posts/

Nice link, thank you!

@engkin:
thank you very much.

You are welcome, although I did nothing. It is ykot, you & HatForCat that motivated the effort to write that post.

There is a typo in the link to the FPC
http://ftp//ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip

should be...
ftp://ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip

Thanks for pointing that out. I just corrected it. It seems that "Insert Hyperlink" button does not like ftp protocol.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on January 31, 2016, 11:37:01 pm
For Windows:
3-Decompress that archive somewhere (if you did that in c:\avrtest then you should have a file named make in c:\avrtest\fpc\ folder )

Thanks, I appreciate the help, but hit a snag, no Make, but I have 7 Folders and
Code: [Select]
avrbuild.bat <<- saved as per instructions. used all recommended Folders/Paths
fpmake.pp
fpmake_add1.inc
fpmake_proc1.inc
Makefile
makefile.fpc
readme.rev

Running avrbuild.bat
Code: [Select]
C:\avrtest\fpc>avrbuild

C:\avrtest\fpc>REM if you installed Lazarus 1.6 RC2 in c:\Laz1.6RC2 it comes wit
h FPC.exe in c:\Laz1.6RC2\3.0.0\bin\i386-win32 folder

C:\avrtest\fpc>REM That is the folder we need to add here.

C:\avrtest\fpc>SET FPC_PATH=c:\Laz1.6RC2\3.0.0\bin\i386-win32

C:\avrtest\fpc>REM The compiler itself ( Which its location is saved in FPC_PATH
 )

C:\avrtest\fpc>SET PPCBIN=c:\Laz1.6RC2\3.0.0\bin\i386-win32\fpc.exe

C:\avrtest\fpc>REM A folder where the generated cross compiler and run-time libr
aries are going to be saved

C:\avrtest\fpc>SET INSTALL_PATH=c:\avrtest\Win32

C:\avrtest\fpc>REM We need the path to avr-embedded-* files

C:\avrtest\fpc>SET NDK_BIN=c:\avrtest\

C:\avrtest\fpc>REM Make all the binary files that we need accessible

C:\avrtest\fpc>SET PATH=c:\Laz1.6RC2\3.0.0\bin\i386-win32;c:\avrtest\;C:\Windows
\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerSh
ell\v1.0\;

C:\avrtest\fpc>REM Start the process

C:\avrtest\fpc>make clean crossall crossinstall FPC=c:\Laz1.6RC2\3.0.0\bin\i386-
win32\fpc.exe OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=c:\a
vrtest\Win32 CROSSBINDIR= BINUTILSPREFIX=avr-embedded- CROSSOPT="-O3 -XX -CX"
'make' is not recognized as an internal or external command,
operable program or batch file.

C:\avrtest\fpc>
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: engkin on February 01, 2016, 12:07:36 am
For Windows:
3-Decompress that archive somewhere (if you did that in c:\avrtest then you should have a file named make in c:\avrtest\fpc\ folder )

Thanks, I appreciate the help, but hit a snag, no Make, but I have 7 Folders and

You are right, it is called Makefile. Corrected the post, thanks!

Quote
C:\avrtest\fpc>make clean crossall crossinstall FPC=c:\Laz1.6RC2\3.0.0\bin\i386-
win32\fpc.exe OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=c:\a
vrtest\Win32 CROSSBINDIR= BINUTILSPREFIX=avr-embedded- CROSSOPT="-O3 -XX -CX"
'make' is not recognized as an internal or external command,
operable program or batch file.

I assume you did install Lazarus 1.6 RC2, check in your Lazarus folder c:\Laz1.6RC2\3.0.0\bin\i386-win32\ do you see a file named make.exe? If not something went wrong with your installation. I installed that version of Lazarus and I have that file there.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 01, 2016, 12:22:38 am
I assume you did install Lazarus 1.6 RC2, check in your Lazarus folder c:\Laz1.6RC2\3.0.0\bin\i386-win32\ do you see a file named make.exe?

Thanks for the follow up. That path is not what I have, but make.exe is here...
c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32\

I changed the batch file and it is doing stuff? It skipped all but two of the avr-embedded... files. Is that good?

"Duty" calls again and must close down for the night. I will report back in the morning.

Thanks again for the help.



Title: Re: FPC/Lazarus Arduino Tutorial
Post by: engkin on February 01, 2016, 12:41:42 am
I assume you did install Lazarus 1.6 RC2, check in your Lazarus folder c:\Laz1.6RC2\3.0.0\bin\i386-win32\ do you see a file named make.exe?

Thanks for the follow up. That path is not what I have, but make.exe is here...
c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32\

I have to admit, I cheated, I'm working on a different computer than this one. You have the correct path. I just modified the post above to reflect this correction. Thank you.

I changed the batch file and it is doing stuff? It skipped all but two of the avr-embedded... files. Is that good?

We both will know the answer when you check the c:\avrtest\Win32 folder.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: herux on February 01, 2016, 02:52:47 am
I love this thread, will try it later. I will buy arduino first of course  :D
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 01, 2016, 04:56:16 pm
I love this thread, will try it later. I will buy arduino first of course

:D Don't be too hasty, I have not found out how to use it yet.

I opened the IDE and went through every option, operational-function, plug-in and anything thing else. Nothing mentions compiling for Arduino. I may be ruing the moment and now heeding that ominous warning from engkin, "How to use them is a different story."

@engkin:
Quote from: engkin
If it succeeded then you should have:
1-a cross compiler named ppcrossavr.exe in c:\avrtest\win32\bin\i386-win32
2-compiled rtl units in c:\avrtest\units\avr-embedded\

I do indeed have
ppcrossavr.exe
C:\avrtest\Win32\bin\i386-win32
and
173 items in
C:\avrtest\Win32\units\avr-embedded\rtl

Am I correct in now assuming that there are no further instructions? :) I had assumed that after all of this, upon launching the IDE, I would simply select a Platform to compile to. Once done, I then use the AVRDude instructions from the OP. But, it seems we are still a long way from integrated at this point.

Shaking and shuddering, I see C/C++ looming on my horizons. I am grateful for the help getting thus far, but as you warned, "How to use them is a different story."

It seems ironic that now that I have achieved that ppcrossavr.exe status, I am now left to my own devices. I shall charge ahead as nothing ventured, nothing gained. What's the worst that could happen? I have full daily image backups, I, well, my laptop is invincible. {gasp!!}
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: Leledumbo on February 01, 2016, 05:27:49 pm
For anyone interested, here is the Help page from the cross compiler { SHOCK HORROR }
That's just the generic -h output, fpc -i should show architecture specific information.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: engkin on February 01, 2016, 05:43:35 pm
I love this thread, will try it later. I will buy arduino first of course

:D Don't be too hasty, I have not found out how to use it yet.

I opened the IDE and went through every option, operational-function, plug-in and anything thing else. Nothing mentions compiling for Arduino. I may be ruing the moment and now heeding that ominous warning from engkin, "How to use them is a different story."

1-Copy (I actually moved it) avr-embedded folder (located in c:\avrtest\win32\units\) to:
c:\Laz1.6RC2\fpc\3.0.0\units\ folder
( In this folder there is already a folder named i386-win32 )

2-Copy ppcrossavr.exe to its normal location among FPC binaries, that is to:
c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32\

3-While you are still in c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32\ folder, there is a file named fpc.cfg.

a-Open the fpc.cfg with your preferred editor ( I dropped it on Lazarus )

b-Go to the end of the file.

c-Add the following ten lines to it ( to guide FPC where/how to find avr-embedded-* files, and a few more options ):
Code: Pascal  [Select][+][-]
  1. #ifdef embedded
  2. -FDc:\avrtest\
  3. -OoFastMath
  4. #-XX
  5. -CX
  6. -Oonostackframe
  7. #ifdef avr
  8. -XPavr-embedded-
  9. #endif
  10. #endif

d-Save it and close it.

If you did all of that then download the sample app attached (http://forum.lazarus.freepascal.org/index.php?action=dlattach;topic=30960.0;attach=14031) to ykoy's first post.

Unpack it (I did that in c:\avrtest folder and I ended up with the sample project inside c:\avrtest\Blinky folder).
Open the project, and compile.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 02, 2016, 12:32:31 am
Open the project, and compile.

You are more than aptly named "Hero Member," we just got back from shopping, but "duty" again calls so I will tackle this in the morning.

Thank you so much for all the time and effort. Greatly appreciated.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: herux on February 02, 2016, 03:47:21 am
Quote
:D Don't be too hasty, I have not found out how to use it yet.

Not reckless, too, we can try and maybe could help development.  ;)
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 02, 2016, 07:08:47 pm
Open the project, and compile.

Excellent. It created the blinky.hex

Next issue is avrdude. With the OPs instruction I got some errors and here's what I have done so far. The green bits are where I have installed the Arduino stuff, so, others will need to swap in their own for their installation. Most likely "c:\program Files\Arduino" at a guess.

The Path to avrdude within the Arduino installation folders needs to be added to the Windows Path.
D:\_Programs\_ArduinoIDE\hardware\tools\avr\bin

Also, the configuration file for avrdude needs to be included in the OP's instructions and some extra items added to the command. Please note that command line switchs for avrdude ARE case-sensitive.
D:\_Programs\_ArduinoIDE\hardware\tools\avr\etc\avrdude.conf

Here is the contents of a batch file, but so far it only uploads to a Uno and not a Nano or Mega. With the Nano/Mega avrdude hangs and then fails after 10 tries with a ten of these errors.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x53

I saved the batch file as "test.bat" in the same folder as blinky.hex and launched within a Command Prompt with "test com5 blinky.hex" (without quotes) and it has the Uno blinking on com port 5.
Code: [Select]
avrdude -CD:\_Programs\_ArduinoIDE\hardware\tools\avr\etc\avrdude.conf -v -patmega328p -carduino -P\\.\%1 -b115200 -D -Uflash:w:%2:i

Good news is the failed Nano/Mega uploads did no damage to the boot-loader in the Nano or Mega as they still upload OK from the Arduino IDE.

I also tried to create an External Tool within the Lazarus IDE to launch that batch file, but cannot seem to make it work.
Things still to fix.
1: Assign the various boards for avrdude to work with Nano, Mega etc.
2: Create a working External  Tool with in the Lazarus IDE to launch the batch file.

It's getting closer. :)

Thanks for everyone's help so far.

p.s.
I have blocked C/C++ tutorial sites from my browser. ;)

Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 02, 2016, 08:46:36 pm
Hitting a bit of a wall here. Using Arduino's blink sketch and with Verbose mode on the Arduino IDE it shows this line for launching avrdude with the blink in the Mega.

Code: [Select]
D:\_Programs\_ArduinoIDE\hardware\tools\avr/bin/avrdude -CD:\_Programs\_ArduinoIDE\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM5 -b115200 -D -Uflash:w:C:\Users\admin\AppData\Local\Temp\build5676851336824123120.tmp/Blink.cpp.hex:i

Using that line manually in a Command Prompt, it uploads and gives the same results output as when the IDE did it. BUT, nothing happens. No blink and no clearing of blink uploaded by the IDE. So, it seems there is a command switch that the Arduino is supplying that I am not.

very weird.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: jmpessoa on February 02, 2016, 09:40:10 pm
I found this:

https://typeunsafe.wordpress.com/2011/07/22/programming-arduino-with-avrdude/

[maybe can help you ...]
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 02, 2016, 10:33:14 pm
https://typeunsafe.wordpress.com/2011/07/22/programming-arduino-with-avrdude/

Thanks, but where he gets to "Magic Words" is where I got to this morning. That command line will program the Uno fine, but not the Nano or Mega.

The other thing is he is addressing the USBPort directly instead of the COM port as he is using a Linux-like system (dmesg is Linux) and with windows the com ports change when they are identified.

Thanks for trying though. I have not yet given up it is sooooo close. That fact that it works with a Uno (and a $5 clone at that) means we are close.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 02, 2016, 11:44:07 pm
I am beginning to think it is the .hex file. I have managed to use avrdude and the ArduinioIDE "blink.cpp.hex" to upload to the Mega just fine via the Command Line.

D:\Blinky>avrdude -CD:\_Programs\_ArduinoIDE\hardware\tools\avr/etc/avrdude.conf
 -v -patmega2560 -cwiring -P\\.\COM5 -b115200 -D -Uflash:w:D:\Blinky\Blink.cpp.h
ex:i

If I use "Blinky.hex" in place of "Blink.cpp.hex" it doesn't work. No combinations of names work with the Lazarus file.

BUT having said that "Blinky.hex" does upload OK to a Uno and makes it blink. Still the Nano and Mega causing the problems.

Enough for today. I am beginning to feel like Einstein's interpretation of lunacy.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: engkin on February 03, 2016, 12:46:48 am
I am beginning to think it is the .hex file.

I believe you are right. The process was to show that FPC is able to compile for AVR, and it was specific for Arduino Uno (ATMega328P) as the main post explains:
Quote
In above scripts, notice "avr5" subarch flag. This may be different for other Atmel chips, in FreePascal sources open to "/rtl/embedded/Makefile (http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/embedded/Makefile?view=co)" to see what chip corresponds to each subarch. For Arduino Uno and ATMega328P, this is "avr5".

For Arduino Mega (atmega2560) you need another compiler using avr6 for SUBARCH flag:
Quote
ifeq ($(SUBARCH),avr6)
CPU_UNITS=atmega2561 atmega2560
CPU_UNITS_DEFINED=1
endif

I just edited my post to reflect this detail.

So, it seems there is a command switch that the Arduino is supplying that I am not.

In this case, I don't think there is any hidden switch (http://www.nongnu.org/avrdude/user-manual/avrdude_4.html). In general, whenever I get a similar feeling I resort to using a fake program -replacing the original one- to show me the command line parameters:
Code: Pascal  [Select][+][-]
  1. uses
  2.     Windows;
  3. ...
  4.  
  5. procedure TMainForm.FormCreate(Sender: TObject);
  6. var
  7.   I: Integer;
  8.  
  9. begin
  10.   LogMemo.Lines.Add(Format('Program: %s', [ParamStr(0)]));
  11.   for I := 1 to ParamCount do
  12.     LogMemo.Lines.Add(Format('Param %d : %s', [I, ParamStr(I)]));
  13.  
  14.   LogMemo.Lines.Add(GetCommandLine);
  15. end;

Edit:
As for Arduino Nano (https://www.arduino.cc/en/Products/Compare) (ATmega168/ATmega328P) it seems to me that it should work with avr5.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 03, 2016, 04:01:27 pm
I believe you are right. The process was to show that FPC is able to compile for AVR, and it was specific for Arduino Uno (ATMega328P) as the main post explains:
Quote

The avrdude will display all of it's parameters when run with no parameters and I mentioned they are case-sensitive so I'd like to retract that prior thought. :)

What I do, (being an old DOS guy) us

avrdude > out.txt

Which pipes it's output to the text file.

I agree that the Nano has the same Atmel chip, but it has a different serial bootloader. But I saw a youtube video of Julian Lett (I think) programming a Nano with the the Uno bootloader thus turning it into a Uno-like thing. I will try that as I have an ISP prorammer here somewhere. The Nano cost 5-bucks and if it never loads again I will not be crying.

If that fakes avrdude into thinking it is a Nano then I have won as the Uno bootloader is smaller and more efficient than the stock one on the Nano.

Moor to come soon.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 03, 2016, 04:23:23 pm
I'm not actually sure why you bother with this...

Clearly you haven't read the entire thread.
1: I have been programming in Pascal for almost 40-years.
2: I am retired so I have plenty of time on my hands.
3: I like free stuff and helping to make it work to thwart stupidly high software prices.
4: As Julius Summner Miller used to quote, "There is no crime in not knowing, it is not wanting to know that is the crime."

The C/C++ offered by Arduino software is much more easier to learn than configure FPC/Lazarus properly in order to make workable .hex file from this experimental attempt to support AVRs. 

Obviously you have already managed this with Lazarus otherwise how would you know how long it takes to achieve success?
Please share your experiences and save us all this fun.
Besides, the Lazarus part is now working at least for the Uno which is a mile ahead of where it was when this process started.
Dare I suggest a conflict of interests in getting a FREE working Pascal version of the Arduiono compiler? :o

Experimentation is how things are done in the real world.
If everyone adhered to only what was available you would still be clubbing a buffalo to death for meat.


board (actually ATmega2560 itself) can be blocked refusing further communication with avrdude

And, I will cry myself to sleep each night for a week over that $5 loss.

If you want to use Pascal anyway, you may start with  Mikroelektronika's AVR Pascal compiler.

Hmmm, let me think about that one. Lazarus cost $0.00, your software cost $250.00. :o :o :o 

At least we know it can be done and there is no greater impetus for experimenters than an existing example of an expensive something to replicate.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: cpicanco on February 03, 2016, 04:52:26 pm
Hey, it means almost R$ 20,00 + importation fees + some weeks to me... so I would cry a little bit in your position. Just keep doing your stuff dude, you are awesome!

Quote
And, I will cry myself to sleep each night for a week over that $5 loss.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: HatForCat on February 04, 2016, 04:50:33 pm
Great success.  :D :D :D

Using a USBasp programmer and the instructions from Julian's video,
https://www.youtube.com/watch?v=bpXUvRr2ywA

It turned the Nano into a Uno and now the Blinky.hex uploads and runs like a champ. I could not get the programming to work with the USBtiny that Julian used as I got an error "The ID code is invalid, use -F to override." I was using 1.6.7 Arduino IDE (Julian showed 1.6.5) so maybe they have changed something but using the USBasp it just hammered past it and did my bidding.

I am OK with that and will cycle all of my Nano through with the USBasp and make them all Uno. :)

It seems that Blinky.hex needs to be tweaked to suit the boot-loader of the device. By over-writing the Nano boot-loader with the Uno boot-loader, it was happy. A little later on, I will see what I can do with the Mega, but for now I am back in business with Lazarus and uploading to both Nano and Uno.

One thing I will note is that, as the OP mentions within the Blinky.lpr file, the delay is "some kind" as the LED flashes a little faster than the standard "Blink" program. That 400000 probably needs to be 500000. I may play with that, but it is close to what a second looks like compare to the "Blink" sketch. Probably close enough.

Code: [Select]
// This function simulates some kind of delay by looping.
procedure SomeDelay;
var
  I: LongInt;
begin
  for I := 0 to 400000 do
    Dec(DelayVar);
end;
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: jmpessoa on February 12, 2016, 07:58:30 pm
Hello All!

I want to make available in two or three days a new wizard of the "Lamw's" family: a  little brother "Lamwino: Lazarus Arduino Module Wizard" .

key features:

1.Builder for FPC avr/arduino cross compiler
2.New Project option:  "Arduino [avr] Module"

My request. Please, someone could create a new "Arduino" Operating Systems child board?

Thanks to All!

Edited: DONE!

Lamwino: Lazarus Arduino Module Wizard:
   Version 0.1      

   "A wizard to create Arduino loadable module (.hex) using Lazarus/Free Pascal"

         ref.
      https://github.com/jmpessoa/lazarduinomodulewizard

      http://forum.lazarus.freepascal.org/index.php?topic=31513.msg201993
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: herux on March 24, 2016, 08:41:49 am
Hello all, I am going to write a tutorial build fpc for avr embedded in OSX. Completing the tutorial in this thread that only for windows and linux. here is the step i did:
Code: Bash  [Select][+][-]
  1. brew tap osx-cross/avr
Install updated version, type:
Code: Bash  [Select][+][-]
  1. brew install avr-libc
avr binutil will be installed in the folder /usr/local/Cellar/avr-binutils

Code: Bash  [Select][+][-]
  1. make clean crossall  OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=/usr/local CROSSBINDIR=/usr/local/Cellar/avr-binutils/2.25/bin/ BINUTILSPREFIX=avr- CROSSOPT="-O3 -XX -CX"
  2.  

Code: Bash  [Select][+][-]
  1. sudo make crossinstall OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5
if successful install, terminal output will appear similar to this
Code: Bash  [Select][+][-]
  1. ....
  2. Skipped package regexpr which has been disabled for target avr-embedded
  3. Skipped package rexx which has been disabled for target avr-embedded
  4. Skipped package rtl-console which has been disabled for target avr-embedded
  5. Skipped package rtl-extra which has been disabled for target avr-embedded
  6. Skipped package rtl-objpas which has been disabled for target avr-embedded
  7. Skipped package rtl-unicode which has been disabled for target avr-embedded
  8. Skipped package sdl which has been disabled for target avr-embedded
  9. Skipped package sqlite which has been disabled for target avr-embedded
  10. Skipped package svgalib which has been disabled for target avr-embedded
  11. Skipped package symbolic which has been disabled for target avr-embedded
  12. Skipped package syslog which has been disabled for target avr-embedded
  13. Skipped package tcl which has been disabled for target avr-embedded
  14. Skipped package univint which has been disabled for target avr-embedded
  15. Skipped package unixutil which has been disabled for target avr-embedded
  16. Skipped package unzip which has been disabled for target avr-embedded
  17. Skipped package users which has been disabled for target avr-embedded
  18. Skipped package utmp which has been disabled for target avr-embedded
  19. Skipped package uuid which has been disabled for target avr-embedded
  20. Skipped package winceunits which has been disabled for target avr-embedded
  21. Skipped package winunits-base which has been disabled for target avr-embedded
  22. Skipped package winunits-jedi which has been disabled for target avr-embedded
  23. Skipped package x11 which has been disabled for target avr-embedded
  24. Skipped package xforms which has been disabled for target avr-embedded
  25. Skipped package zlib which has been disabled for target avr-embedded
  26. Skipped package libenet which has been disabled for target avr-embedded
  27. Skipped package zorba which has been disabled for target avr-embedded
  28. Skipped package googleapi which has been disabled for target avr-embedded
  29. Skipped package fcl-pdf which has been disabled for target avr-embedded
  30. Installing package fpc-all

Code: Bash  [Select][+][-]
  1. sudo ln -s -f /usr/local/lib/fpc/3.1.1/ppcrossavr /usr/local/bin/ppcavr

Code: Bash  [Select][+][-]
  1. sudo nano /etc/fpc.cfg

and add something like this
Code: Bash  [Select][+][-]
  1. #IFDEF embedded
  2. -OoFastMath
  3. -XX
  4. -CX
  5. -OoNoStackFrame
  6. #IFDEF cpuavr
  7. -XPavr-
  8. #ENDIF
  9. #ENDIF


Code: Bash  [Select][+][-]
  1. fpc Blinky.lpr  -Tembedded -Pavr -MDelphi -Scghi -CX -O3 -Xs -XX -l -vewnhibq -Filib/avr-embedded -Fu. -FUlib/avr-embedded -Cpavr5 -Wpatmega328p -a


Code: Bash  [Select][+][-]
  1. sudo avrdude -v -patmega328p -carduino -P/dev/cu.wchusbserial1420 -b115200 -D -Uflash:w:Blinky.hex:i
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: Thaddy on March 24, 2016, 09:04:27 am
@Herux:
Good enough for the wiki. Note linux need some little changes (e.g. apt-get) in the first two steps.
Windows is only slightly different. I use winavr https://sourceforge.net/projects/winavr/files/latest/download that contains a windows version of avrdude.
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: herux on March 24, 2016, 10:43:52 am
please do, i have not account to write down in the wiki
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: diego bertotti on January 05, 2019, 03:00:35 pm
a little contribution

tool config to transfer the .hex file to arduino uno using a previously installed avrdude(arduino ide).

ovbiously, fine tune the paths to your case!

Tools -- Configure external tools -- Add

Title:
Arduino Upload with avrdude

Program File name:
F:\Progra~1\arduino\arduino_1_8_8\hardware\tools\avr\bin\avrdude.exe

Parameters:
-CF:\progra~1\arduino\arduino_1_8_8\hardware\tools\avr\etc\avrdude.conf
-v -patmega328p -carduino -P\\.\COM13 -b115200 -D -Uflash:w:$OutputFile().hex:i
Title: Re: FPC/Lazarus Arduino Tutorial
Post by: af0815 on January 05, 2019, 03:48:25 pm
Maybe some information is in the freepascal wiki too : http://wiki.freepascal.org/AVR_Embedded_Tutorial/de im German :-) but with google translate it is possible to read.

The info of the tutorial was collected by mathias in the thread https://www.lazarusforum.de/viewtopic.php?f=9&t=11127&hilit=avr (german).

Title: Re: FPC/Lazarus Arduino Tutorial
Post by: diego bertotti on January 07, 2019, 12:36:13 pm
another one

for upload to nano atmega328pu maybe this work for you (it work for me)

different baudrate and another way to find the hex file

Tools -- Configure external tools -- Add

Title:
Arduino nano upload with avrdude (old bootloader)

Program File name:
F:\Program Files\arduino\arduino_1_8_8\hardware\tools\avr\bin\avrdude.exe

Parameters:
-CF:\progra~1\arduino\arduino_1_8_8\hardware\tools\avr\etc\avrdude.conf
-v -patmega328p -carduino -P\\.\COM13 -b57600 -D -Uflash:w:$ProjPath()\$NameOnly($ProjFile()).hex:i
TinyPortal © 2005-2018