Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 26

Thread: Teensy with Freepascal

  1. #1

    Teensy with Freepascal

    Hi

    I am probably jumping the gun here, but I am eager to discover the possibilities.

    I have just ordered a Teensy 3.1 board that wil hopefully arrive tomorrow.

    I read several of the PRJC homepage entries that seems to suggest the supplied code and things are written and compiled in C.

    I would like to know if it will be possible for me to use my IDE and programming language of choice which is Lazarus IDE and Freepascal to code my own solutions, compile them, and run them on the teensy board? AFAIK, Freepascal does have an ARM compiler but I'm totally to new to this particular area so don't really know where to even start. So do I have to use to C and the C compiler? If I do, then I'll have to start learning but I hoped I could use what I have learnt these past few years with FPC and Lazarus.

    If that is possible, can anyone give me some direction as to the step required? Thanks

  2. #2
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    Arduino and Teensy use C++ and users may code in C or C++.
    The libraries of I/O and the standard C functions are for a C/C++ environment.

    There are several IDEs, including Arduino's, Microsoft Visual Studio 2013 (free) combined with free Visual Micro; VisualGDB, and for an IDE for Macs, and there's Eclipse. All these use GCC.

    Freepascal - I know nothing of it. But without a big effort on your part, it's C/C++ and the Arduino simplifying veneer over C++.

  3. #3
    Senior Member pictographer's Avatar
    Join Date
    May 2013
    Location
    San Jose, CA
    Posts
    681
    Yup. Definitely jumping the gun.

    Setting up a new tool chain run for a microprocessor is not an exercise for the faint of heart. You really need to be an expert at so many things: multiple programming languages, compiler options, make files, scripting, low-level debugging and waiting for errors that take hours to appear. If you scan through the forums here and find posts that are way over your head--that's exactly the sort of expertise needed to make something like Free Pascal run on a Teensy.

    Since you're just getting started, I would encourage you to start playing with your Teensy 3.1 by following the documentation and running simple examples the way other beginners do. Yes, it's definitely annoying to need to learn a new programming language, but I suggest you go ahead and bite the bullet. The Pascal programming language was a dead end back in the 80s. C++ is very popular and still improving.

    Not the answer you wanted, but there's a lot of fun and learning to be had here.

  4. #4
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    Best way to learn C (save C++ for later), is to do so on a PC where you have better testing tools and lots of internet info on the language. After first reading a primer.
    The C bible is Kernigan & Riche's small book - http://www.amazon.com/The-Programmin.../dp/0131103628

  5. #5
    Senior Member
    Join Date
    Jan 2015
    Location
    frisia
    Posts
    285
    Since pascal is part of gcc, you could theoretically generate your own pascal compiler (--enable-languages=pascal). But this will not be trivial.
    The big problem is with the arduino libraries, or more accurately with the header files, which contain c++ constructs like templates etc. There is tooling to access pure c header files, but hardly any (arduino) header file is pure C.

    So you could theoretically program in pascal, but without libraries. And it does not really make sense to program without libraries.
    Do not be too affraid of C. Pascal and C are not too dissimilar. Just replace every begin with '{' and every end with '}' end you solved 90% of the conversion. Futhermore, all of the examples willl be in C(++). With pascal you are all on your own.

    Finally, just to comment on this
    The Pascal programming language was a dead end back in the 80s
    Pascal had a bit of a revival in around 2000 with Borland Delphi.

  6. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,929
    Ummm, Free Pascal is not part of the official GCC release. I'm not sure what it uses for a backend, though there appears to be a project to switch and use the LLVM backend. According to goggle search, support for embedded ARM devices was only recently added to the trunk. There is Gnu Pascal, which does use the GCC backend.

  7. #7
    Senior Member
    Join Date
    Jan 2015
    Location
    frisia
    Posts
    285
    Sorry, I was not implying Free Pascal, just any pascal. As you mention gnu pascal is using the gcc backend, this seems to be the most viable solution. But building a crosscompiler with probably the pascal equivalent of libc, is definitely not a beginners project. I maintained a crosscompiler with uclibc for the sh4 for a while, this is pretty standard, but al sorts of (solvable) little problems kept popping up.

    I would suggest to learn C, as said if you know pascal, C is not a big hurdle. If you really insist, p2c (pascal to c-converter) is available on linux, don't know if there are winows equivalents. Only used it a couple of time in the early 90s when still at school, it still seems to be around. I remember it resulted in compilable c-code, not necessarily readible code.

  8. #8
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    I went from UCSD Pascal to C more decades ago than I care to admit.
    There was a day, when struggling with C and pointers and pointers to functions, when I realized that C is not a high level language like Pascal. C is a portable (machine independent) assembly language. Having spent years doing assembly for minicomputers, I warped my brain from Pascal mode to thinking how K&R's C was just that - a step up from assembly language. Then it all got easy. I just mentally set aside my Pascal thinking. Use a pointer wrong and you crash. Just like assembly.

    C++ is way too arcane for someone coming directly from Pascal. Start with C on a PC, and avoid a complex IDE for now as you'll divert too much thinking to the IDE and not learning C.
    Last edited by stevech; 05-03-2015 at 06:19 AM.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,446
    I'm pretty sure FreePascal's ARM support isn't going to be very useful. On their web page, it says:

    ARM architecture
    16 MB of RAM is required. Runs on any ARM Linux installation.
    With a tremendous amount of work, it might be possible to get some rudimentary system running on Teensy. Maybe. Probably a big first question is whether the FreePascal system can compile to lightweight bare metal programs? If it's got big (relative to Teensy 3.1's memory) support libraries that it always links into final executables, that's probably be a first huge roadblock.

    I agree completely with the comments above, that you can (in theory) link C and Pascal code. Maybe, if you have 2 toolchains that produce compatible object code formats and a linker that can combine them. Must of the Teensy 3.1 core library is pure C, at least for the basic USB functionality. Some of it is in .cpp files, but is basically just C code, so it could be brought over. But things like the Print class can't, so in a best case scenario, you'd be able to get your Pascal program to at least use the basic functionality of the hardware, like USB and hardware serial and analog & digital I/O.

    But even just that could be a long, uphill journey.

  10. #10
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,929
    In the status, FP listed embedded ARM as being in the trunk and not yet in a release. I would imagine you would use it in the same way you use the ARM GCC cross compilers we currently use. However, I suspect it is probably a WIP, and if you went down that path, you would have a lot of work to get it done.

  11. #11
    Interesting development regarding Free Pascal embedded! Note that Lazarus is a whole framework designed for creating desktop PC apps. For FP embedded, you would still need an IDE for Free Pascal, or use command line.

    My first job in embedded software many years ago was writing code for network controllers - most of it was written in Pascal, using an Intel Pascal compiler. About the only embedded Pascal I have seen recently is http://www.mikroe.com/mikropascal/arm/. There is an embedded Pascal for Z80/6502/AVR.

    The practicality of using Pascal means having to write every bit of code, it is hard to mix with C. That means rewriting libraries, and no "copy and paste" code samples off the web. I think I would only recommend Pascal for those die-hard guys, it will be a lot easier getting started in embedded with C/C++. Hopefully if FP embedded becomes a practical proposition that might change.

  12. #12
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    You can if you dare, go use MikroElectronica ARM boards (they're not Freescale), and their sorta-compilers for Pascal, C, Basic. Not at all like a big desktop run time, but there you got yer Pascal. I suppose the Pascal can target their mini-M4.

    I don't believe that real Pascal and embedded systems (small MCUs) are a fit.

  13. #13
    Thanks for the info guys. That was all the clarification I needed. I didn't want to miss something obvious and go down the route of new language learning unnecessarily. But seemingly it will be a big hill to climb to implement FPC with Teensy. I think we can consider the thread as solved. Thanks.

  14. #14
    I asked my friends at the Lazarus Freepascal project (http://forum.lazarus.freepascal.org/...8918#msg178918). Laksen and Michael Ring have kindly created the compiler for the Teensy processor which is committed to SVN trunk (http://svn.freepascal.org/svn/fpc/trunk/):

    The SVN trunk is at

    To build the compiler:
    make buildbase OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em CROSSINSTALL=1

    To install it:
    make installbase OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em CROSSINSTALL=1 PREFIX=C:/wherever you want to install

    To build a program:
    fpc -Parm -Tembedded -Cparmv7em -Wpmk20dx256xxx7 program.pas

  15. #15
    Junior Member
    Join Date
    Oct 2015
    Location
    Lawrence, Kansas, USA
    Posts
    8
    I just created this page: http://turbocontrol.com/simpleteensy.htm

  16. #16
    Senior Member pictographer's Avatar
    Join Date
    May 2013
    Location
    San Jose, CA
    Posts
    681
    How easy is it to do all the common hardware things from Freepascal? How much low-level setup is required use digital and analog I/O? Can you use the serial ports? Timers? Capacitive touch sensing? Can you even access the registers without porting a massive header file? Is it possible to link with existing C or C++ libraries?

  17. #17
    Junior Member
    Join Date
    Oct 2015
    Location
    Lawrence, Kansas, USA
    Posts
    8
    Thanks pictographer for your questions. Since it is the weekend it might be a day or two before I get back with some answers (from others).

    In the meantime, anyone who is not familiar with Delphi and Object Pascal can checkout the top section of this web page: http://turbocontrol.com/embeddedfreepascal.htm

  18. #18
    Junior Member
    Join Date
    Oct 2015
    Posts
    1
    Quote Originally Posted by pictographer View Post
    How easy is it to do all the common hardware things from Freepascal? How much low-level setup is required use digital and analog I/O? Can you use the serial ports? Timers? Capacitive touch sensing? Can you even access the registers without porting a massive header file? Is it possible to link with existing C or C++ libraries?
    Noone has to my knowledge ported the Freescale firmware library(if there is any?) to pascal, but it should be straight forward if anyone is up for the daunting task..

    The rest is just like how you would do it in C. The entire header has been ported and all registers are accessible. If you care the file showing the interfaces and startup code can be found in the freepascal SVN sources at rtl/embedded/arm/mk20d7.pp
    Lazarus(the editor) also has full integration so the registers and contents will show up in code completion, if set up right.

    It might be possible to link with C code or flattened C++ code, but I don't know if it's commonly done. I've heard someone does that for with Silabs SDK ARMv6M code. The ABI isn't standardized but as long as it's just simple functions without floating point stuff it should work (FPC doesn't support FPv4 that well yet).

  19. #19
    Junior Member
    Join Date
    Oct 2015
    Location
    Lawrence, Kansas, USA
    Posts
    8
    Quote Originally Posted by Laksen View Post
    If you care the file showing the interfaces and startup code can be found in the freepascal SVN sources at rtl/embedded/arm/mk20d7.pp
    Thanks Laksen for your reply. I just updated the zip and the new 11 MB zip now contains the rtl source code.

  20. #20
    Junior Member
    Join Date
    Oct 2015
    Location
    Lawrence, Kansas, USA
    Posts
    8
    Free Pascal for Teensy using Linux is close to release: http://wiki.freepascal.org/Small_Vir...irtual_machine

  21. #21
    Junior Member
    Join Date
    Oct 2015
    Location
    Lawrence, Kansas, USA
    Posts
    8
    There are many new things (including a powerful IDE released today) here:
    http://www.controlpascal.com/tutorial.htm
    Last edited by PaulBreneman; 12-24-2015 at 04:25 PM.

  22. #22
    Junior Member
    Join Date
    Oct 2015
    Location
    Lawrence, Kansas, USA
    Posts
    8
    A month ago a nice project www.Ultibo.org was released for the Raspberry Pi, and hopefully some of it can be ported and used on the Teensy!

  23. #23
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,446
    How many people still use Pascal?

    I personally haven't touched Pascal since 1989.

  24. #24
    Junior Member
    Join Date
    Oct 2015
    Location
    Lawrence, Kansas, USA
    Posts
    8
    Quote Originally Posted by PaulStoffregen View Post
    How many people still use Pascal?
    I have a few companies and schools listed at the top of this page:
    http://turbocontrol.com/embeddedfreepascal.htm

    I've been using Pascal (and lots of other languages) for 31 years. I know lots of other engineering companies that are using Pascal, but I'm not free to mention them publicly. Hang out on the forums and you'll discover a lot more!

  25. #25
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    Quote Originally Posted by PaulStoffregen View Post
    How many people still use Pascal?

    I personally haven't touched Pascal since 1989.
    Same here. Learning it was, back then, an invaluable tutorial on what a high level language can be, versus asm and C.
    It was widely used in Universities' comp sci courses, e.g., the infamous UCSD Pascal on Apple II's.
    https://en.wikipedia.org/wiki/UCSD_Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •