Recent

Author Topic: Is there FreePascal for AVR or PIC microcontrollers for Linux?  (Read 14734 times)

xterro

  • New member
  • *
  • Posts: 9
Is there FreePascal for AVR or PIC microcontrollers for Linux?
« on: October 22, 2014, 10:37:58 am »
Hello, Is there a free pascal compiler for AVR, PIC, 8051 or at least ARM Cortex M3 microcontrollers?  All compilers that are available for these purposes are commercial, and for Windows only (I want for Linux)  :(   
If not, are there any plans to support these microcontrollers?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #1 on: October 22, 2014, 05:49:04 pm »
AFAIK we have support for AVR and ARM Cortex (not sure which one though), but probably only in trunk.

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #2 on: October 22, 2014, 06:01:08 pm »
Well there is pic micro pascal compiler which is free; but developed by only one person and on Window$.
http://www.pmpcomp.fr/index.php?lng=en

Another free alternative is sdcc (http://sdcc.sourceforge.net/).
Seems to be getting better/more complete every release; but alas, it's C.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Edson

  • Hero Member
  • *****
  • Posts: 1302
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #3 on: October 22, 2014, 06:22:26 pm »
PIC and AVR are very special architectures. Most of their devices are 8 bits based. FPC is not oriented to such "micros", Probably it could works with the most advanced series (32 bits), but FAIK it's not implemented yet.

I have started to develop a PIC compiler, with Lazarus, but I'm in a very basic level, so nothing functional by now.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #4 on: October 22, 2014, 06:36:14 pm »
PIC and AVR are very special architectures. Most of their devices are 8 bits based. FPC is not oriented to such "micros", Probably it could works with the most advanced series (32 bits), but FAIK it's not implemented yet.
I'd suggest you have a look at trunk... there's ongoing work there (don't know if it's 32 bit only)...

Edit: looks like there's recent work done on MIPS embedded
http://svn.freepascal.org/cgi-bin/viewvc.cgi/branches/mips_embedded/?sortby=date
... but I do recall some posts on the fpc-devel list about the AVR??!?!
« Last Edit: October 22, 2014, 06:53:43 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Edson

  • Hero Member
  • *****
  • Posts: 1302
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #5 on: October 22, 2014, 07:21:46 pm »
I have found nothing about PIC, but some references to AVR. It seems to be "experimental" on trunk.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #6 on: October 22, 2014, 08:10:41 pm »
There seem to be a lot of misunderstandings about PIC.

There are three very distinct PIC architectures, 8-bit PIC, 16-bit PIC (including dspic) and 32-bit PIC32.

  • the oldest form of PIC is 8-bit. Lower tiers in this range (up to PIC16) barely do C.  PIC18 and PIC16 with limitations are reasonably programmable in C. C programmability arrived fairly late in this line (say 2005), and there is a lot of misinformation about this. (based on pre 2005, pre PIC18 versions)
  • The 16-bit architecture (various ranges called PIC24, and DSPIC33, the latter with DSP instructions) are microcontrollers geared towards audio and other DSP solutions. C programmable, but has some quirks.
  • The 32-bit architecture is not own proprietary but MIPS32 M4K. Afaik this works with FPC to some degree

The FPC AVR port-still-in-progress is afaik mostly AVR32.

The 8051 is an 8-bitter with 128 bytes of memory in its original incarnation. There are numerous enhancements from varying vendors that are not always compatible to eachother.

Last but not least is Cortex M3. This is afaik not a device, but a family, and is supported somewhat by at least trunk (Phillips LPC among others)

Afaik none run Linux, since lacking MMU. Some of the heavier ones (PIC32, Cortex M3) might run some embedded variant like uclinux.

All of these require what you are doing, and I suggest getting a working knowledge with vendor's tools before moving onto FPC with it.
« Last Edit: October 22, 2014, 08:13:27 pm by marcov »

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #7 on: October 22, 2014, 09:00:27 pm »
All of these require what you are doing, and I suggest getting a working knowledge with vendor's tools before moving onto FPC with it.
Indeed.
The last thing you want for a hobby project is spending a lot of time finding bugs in the tools instead of your own project.
Especially with microcontrollers (which is why I use picbasic  :D).
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Laksen

  • Hero Member
  • *****
  • Posts: 742
    • J-Software
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #8 on: October 22, 2014, 10:48:13 pm »
fpc has supported ARM cortex m3/m4 for many years. The support is quite stable, so go right ahead and use it  :)

xterro

  • New member
  • *
  • Posts: 9
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #9 on: October 23, 2014, 05:58:12 am »
fpc has supported ARM cortex m3/m4 for many years. The support is quite stable, so go right ahead and use it  :)

Cool.  :)   So as I understand, the STM standard library is not supported, and I have to apply directly to the addresses of registers?  :o

Laksen

  • Hero Member
  • *****
  • Posts: 742
    • J-Software
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #10 on: October 23, 2014, 12:41:26 pm »
The STM library from a few years ago was partially ported in two versions(that I know of):
http://j-software.dk/stm32f103.php
https://github.com/alrieckert/stm32f1xx_spl

Not sure if that's generic enough to work for STM32F2xx or newer chips. But porting it will take at most a few days ;)

Otherwise, it's just a matter of writing to registers. Fun! :)

xterro

  • New member
  • *
  • Posts: 9
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #11 on: October 23, 2014, 01:25:18 pm »
Thank you   ;)

microphil

  • Newbie
  • Posts: 3
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #12 on: October 23, 2014, 10:29:18 pm »
It's fine to read that there is a demand on Pascal on microcontrollers. If you are using uCs, you might be interested on a compiler for the 16bit-uC family of Microchip.

Most compilers for microcontrollers don't consider the limited resources of the hardware. If the operating system is adapted to the compiler and uC hardware (but not the inverse), amazing performance is feasible with 16bit-microncontrollerrs. Since I needed double precision FP-math and perfect single-cycle accuracy of program-generated timings as well, I developed a new Pascal compiler EmbPas for the PIC24/dsPIC33 microcontroller family from the scratch. But why 64bit floating point? Many advanced data processing algorithms (f.ex. LMSq, SVD) demand high numerical precision while computation. The input/output can/will be less accurate.

Using the Whetstone benchmark, EmbPas code on the PIC24F (32 MHz) is 69% faster than Borland Pascal 7.0 with real math (6 bytes, 40bit mantissa) on an i486 processor with 33 MHz clock. To fit better on the 16bit architecture, the numerical format of EmbPas uses a 48bit mantissa but 53bit as of IEEE double precision. Compiled math functions of EmbPas (sqrt, ln, exp, sin, tan, arctan...) are, in average, 5 times faster than the same in C compiled by the latest XC16 compiler of Microchip. Note: Microchip was not interested on the much faster math assembler code since “the Microchip compiler still generates faster code than the competition”. OK, that's business.

Niklaus Wirth designed his Pascal compilers in a way that interpretation of intermediate code (see his P-compiler series) is easy. Interpretation enables modules (similar to units) which are running quasi-parallel. Modules can be loaded/disposed dynamically as required - an important feature if there is only 4 kbyte RAM. A loader/scheduler controls the interpreted modules by using preemptive multitasking. Concurrent modules can use floating point math - a feature which is hardly possible with C. The overhead for interpretation is 15 cycles per instruction of the intermediate code, so that the Whetstone code is slowed down by only 40% when using interpretation. Library modules can be compiled to machine code. Such modules must rely on cooperative multitasking. Interpretation absorbs CPU power, but allows to overcome the limitations of the Harvard architecture: you can load new program code without reprogramming the flash microcontroller.

As you see, Pascal programs can be run on microcontrollers with even <<1mW power dissipation -  but not FreePascal using Linux or Windows. There are some similarities between EmbPas and Java, while Java is (by orders of magnitude) too complex for a microcontroller. EmbPas is applied for numerical processing and user interface in commercial measurement devices. However, the compiler is not commonly available since there is no time to support it, i.e. tests, bug fixes, manuals, GUI(s), operating system etc.

jabu

  • New Member
  • *
  • Posts: 14
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #13 on: October 24, 2014, 09:11:44 am »
To microphil,

hello, I'm a fan of PIC24/dsPIC33, for AVR I used a long (commercial) AVRco with great success, is possible to try EmbPas?

jabu


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Is there FreePascal for AVR or PIC microcontrollers for Linux?
« Reply #14 on: October 24, 2014, 09:45:19 am »
Since I needed double precision FP-math and perfect single-cycle accuracy of program-generated timings as well, I developed a new Pascal compiler EmbPas for the PIC24/dsPIC33 microcontroller family from the scratch.

The PIC24/dsPIC33 is not perfect single-cycle timing accurate. It has a instruction prefetch (hence a penalty cycle on branching), and a stall (penalty cycle) on use of a register in the instruction after a register write.

The -E family in addition also has a read-write-modify penalty cycle, and variable interrupt latency (though you can fixate that to the worst count). The branch penalty is also increased to 4 if not branching to the next instruction.

Quote

Compiled math functions of EmbPas (sqrt, ln, exp, sin, tan, arctan...) are, in average, 5 times faster than the same in C compiled by the latest XC16 compiler of Microchip. Note: Microchip was not interested on the much faster math assembler code since “the Microchip compiler still generates faster code than the competition”. OK, that's business.

I'm not particularly impressed by XC16. The code quality is similar to C30, but it seems buggier, specially on the segmented dspic33e.  I haven't tested the latest version though (early october iirc)

Same with the IDE. Looks sharp, but they didn't manage to get the assembler view working in 2 years.

Quote
The overhead for interpretation is 15 cycles per instruction of the intermediate code, so that the Whetstone code is slowed down by only 40% when using interpretation.

Do you have a number for integer operation?  15 cycles per instruction sounds bad, but dspic is not the most concise architecture, and I assume your bytecodes are denser than dspic assembler.

Quote
As you see, Pascal programs can be run on microcontrollers with even <<1mW power dissipation -  but not FreePascal using Linux or Windows.

Well, there was already Mikropascal :-) http://www.mikroe.com/mikropascal/pic/

Quote
There are some similarities between EmbPas and Java, while Java is (by orders of magnitude) too complex for a microcontroller. EmbPas is applied for numerical processing and user interface in commercial measurement devices. However, the compiler is not commonly available since there is no time to support it, i.e. tests, bug fixes, manuals, GUI(s), operating system etc.

May I ask why you chose the dspic? It seems your usecases might be helped by a bit beefier hardware.


 

TinyPortal © 2005-2018