Lazarus

Programming => Embedded => Operating Systems => Embedded - AVR => Topic started by: af0815 on June 23, 2019, 10:48:50 pm

Title: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: af0815 on June 23, 2019, 10:48:50 pm
The Arduino Projects have a lot of libraries for the diffents HATs or Sensors, is it possible to use compiled code from this libs ?

PS: This is no question about the license, only if it possible.

Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: lucamar on June 23, 2019, 11:15:36 pm
The Arduino Projects have a lot of libraries for the diffents HATs or Sensors, is it possible to use compiled code from this libs ?

PS: This is no question about the license, only if it possible.

Are they dynamic libraries with C bindings? If so, it should be possible to translate the bindings to Pascal and use them. For static libraries or object files ... I don't know, sorry.
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: PascalDragon on June 24, 2019, 09:06:47 am
The Arduino Projects have a lot of libraries for the diffents HATs or Sensors, is it possible to use compiled code from this libs ?
I did not test it, but you'd need to write units for the compiled libraries and then use {$L code.o} for each file you need (most files will probably require other files). Or you could try to move all .o files into a static library and link against that...
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: ccrause on June 24, 2019, 03:53:27 pm
I think it will be challenging since many (most?) of the libraries are written in C++.  One could write a C layer on top to flatten the code, but for that much effort I would rather stay with Arduino. Or better yet, rewrite library in Pascal.
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: Thaddy on June 24, 2019, 04:15:31 pm
I think it will be challenging since many (most?) of the libraries are written in C++.  One could write a C layer on top to flatten the code, but for that much effort I would rather stay with Arduino. Or better yet, rewrite library in Pascal.
@ccrause: you are an expert, but:
Arduino is almost all plain C, not C++. It is written C++ style., but it is usually plain C.
C++ is way too heavy to use at all. Free pascal works great on Arduino.
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: af0815 on June 24, 2019, 05:12:08 pm
Thaddy, have you a sample for me ? Please.
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: SymbolicFrank on June 24, 2019, 05:38:21 pm
How does free pascal work on Arduino?
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: Thaddy on June 24, 2019, 06:15:17 pm
How does free pascal work on Arduino?
Build a cross compiler for it.... Both AVR and ARM bare bone are supported as micro controllers.... Which one do you have?

Don't expect Lazarus component style programming to work, though.... But FPC does perfectly OK.
Just like the C cross-compilers
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: Thaddy on June 24, 2019, 06:45:08 pm
Thaddy, have you a sample for me ? Please.
There are (is) simple stuff in the wiki... Start here, but there is more: https://wiki.freepascal.org/Arduino
 And here https://wiki.freepascal.org/AVR_Programming
And here for the compiler: https://forum.lazarus.freepascal.org/index.php/topic,30960.msg200524.html#msg200524

The actual compiler compares very well on this platform!
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: ccrause on June 24, 2019, 07:04:30 pm
Arduino is almost all plain C, not C++. It is written C++ style., but it is usually plain C.
C++ is way too heavy to use at all.

The base wiring library is plain C, but most other libraries seem like C++ (except if class X : public Y is a valid C construct).  I'm no expert in C/C++, let alone the differences between the two, but I did spot use of inheritance and using-declaration (I had to search for that definition):
Code: C  [Select]
  1. class TwoWire : public Stream
  2. {
  3. ...
  4.     using Print::write;
  5. };

I only want to point out that the question to get access to available functionality in Arduino is reasonable, I just think it will be a lot more difficult that linking to a plain C library.
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: SymbolicFrank on June 24, 2019, 07:18:22 pm
How does free pascal work on Arduino?
Build a cross compiler for it.... Both AVR and ARM bare bone are supported as micro controllers.... Which one do you have?

Don't expect Lazarus component style programming to work, though.... But FPC does perfectly OK.
Just like the C cross-compilers

I have both, but I am trying to use ARM (STM32). But they work (almost) out of the box in the Arduino IDE, and while I do seem to be able to build an image for them with FPC, it is far from working.
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: jmpessoa on June 24, 2019, 07:36:36 pm
Quote
How does free pascal work on Arduino?

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

https://github.com/jmpessoa/lazarduinomodulewizard
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: Thaddy on June 24, 2019, 07:42:09 pm
Arduino is almost all plain C, not C++. It is written C++ style., but it is usually plain C.
C++ is way too heavy to use at all.

The base wiring library is plain C, but most other libraries seem like C++ (except if class X : public Y is a valid C construct).  I'm no expert in C/C++, let alone the differences between the two, but I did spot use of inheritance and using-declaration (I had to search for that definition):
Code: C  [Select]
  1. class TwoWire : public Stream
  2. {
  3. ...
  4.     using Print::write;
  5. };

I only want to point out that the question to get access to available functionality in Arduino is reasonable, I just think it will be a lot more difficult that linking to a plain C library.
That's actually more like a pascal record and is not a true "class" in that sense. You can only use it in record style.... (bitpacked, btw)
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: SymbolicFrank on June 24, 2019, 07:46:21 pm
A wizard to create Arduino loadable module (.hex) using Lazarus/Free Pascal:

https://github.com/jmpessoa/lazarduinomodulewizard

Yes, I got that part working. But the image generated by the Arduino IDE configures the controller, so that it actually works (ie. the clock sources and devices). Free Pascal only initializes it (ie. the vector table).
Title: Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
Post by: Dimitrios Chr. Ioannidis on June 24, 2019, 11:12:14 pm
Hi,

I have both, but I am trying to use ARM (STM32). But they work (almost) out of the box in the Arduino IDE, and while I do seem to be able to build an image for them with FPC, it is far from working.

you should try the Microcontroller Board Framework (https://github.com/michael-ring/mbf).

I test it with a samd21g18a and worked great. AFAIK, it has support for at least the NUCLEO-F303K8 an STM32 ARM based board so it's a good bet that it will work for you also.

regards,