Advantages of using PASCAL to develop embedded programs lazarus / 68-Other OS ---------------------------------------------------------------------- gasensor · 2024-04-13 15:05 1. It's hard to get out of bounds when accessing arrays/string. 2. The compiler is free for commercial use. 3. It is effective to avoid the macro hell of the C language. 4. It can effectively avoid the trap of local variables in C language. 5. The program is highly readable, even if it lacks comments. 6. This kind of question does not appear: j=++j + ++j;  j= what? ---------------------------------------------------------------------- marcov · 2024-04-13 15:32 Tool selection is a multi facetted question, and general language is only one factor, e.g. licensing, as you saidThe usual language differences, like you said in most other optionsExtensions to the language for embedded, both general and target specific, how more embedded the target, the more important this islibrary support, including per target headerscross compilationIDE integrationDebugger support ---------------------------------------------------------------------- gasensor · 2024-04-13 18:33 I agree. For FPC installation and crossinstall issues, I'll write a separate topic. ---------------------------------------------------------------------- bobihot · 2024-04-13 22:56 I very need, but can`t for now - is not possibly practically. If possibly and visual programming like A visual programming environment https://www.mitov.com/products/visuino#overview ---------------------------------------------------------------------- gasensor · 2024-04-13 23:09 Quote from: bobihot on April 14, 2024, 12:56:45 amI very need, but can`t for now - is not possibly practically. If possibly and visual programming like A visual programming environment https://www.mitov.com/products/visuino#overview "A visual programming environment" = Labview This type of graphical programming language struggles to handle complex logical relationships. I've used Labview, and simple stuff is fine. Once the program is complicated, it's hell. ---------------------------------------------------------------------- ccrause · 2024-04-14 07:28 Quote from: gasensor on April 14, 2024, 01:09:48 amQuote from: bobihot on April 14, 2024, 12:56:45 amI very need, but can`t for now - is not possibly practically. If possibly and visual programming like A visual programming environment https://www.mitov.com/products/visuino#overview "A visual programming environment" = Labview This type of graphical programming language struggles to handle complex logical relationships. I've used Labview, and simple stuff is fine. Once the program is complicated, it's hell. Another example is Node-RED.  But this has nothing to do with Pascal (or any other traditional language), since the "language" is based on visual representation. ---------------------------------------------------------------------- ccrause · 2024-04-14 07:51 Quote from: marcov on April 13, 2024, 05:32:00 pm Tool selection is a multi facetted question, and general language is only one factor, e.g. licensing, as you saidThe usual language differences, like you said in most other optionsExtensions to the language for embedded, both general and target specific, how more embedded the target, the more important this islibrary support, including per target headerscross compilationIDE integrationDebugger support Marco, can you expand on examples where fpc/Lazarus falls short compared to other options? It may help in improving the situation eventually. For example fpc does not support handling of variables placed in sections for AVR target. I have proposed something to support this, but it isn't making progress.  On the other hand a patch to place code in various sections, and dropping RTL initialization, has been accepted (also AVR specific). There is a very long list of controller headers available in fpc, however it is not exhaustive.  Often these headers can be generated automatically, so adding them is mostly a matter of knowing what is missing. This is not coordinated AFAIK, so contributions trickle in when an interested party investigates a particular new target. A serious shortcoming I think is standard hardware support libraries for example I2C, USART, LCD etc. Pascal specific debugger support for embedded is slowly growing via fpdebug. At this point only AVR is reasonably tested, with ESP32 support at an experimental level. If we make the embedded specific needs better known, there is a chance of improving the status quo. ---------------------------------------------------------------------- ojz0r · 2024-04-14 08:26 Quote from: ccrause on April 14, 2024, 09:28:56 amQuote from: gasensor on April 14, 2024, 01:09:48 amQuote from: bobihot on April 14, 2024, 12:56:45 amI very need, but can`t for now - is not possibly practically. If possibly and visual programming like A visual programming environment https://www.mitov.com/products/visuino#overview "A visual programming environment" = Labview This type of graphical programming language struggles to handle complex logical relationships. I've used Labview, and simple stuff is fine. Once the program is complicated, it's hell. Another example is Node-RED.  But this has nothing to do with Pascal (or any other traditional language), since the "language" is based on visual representation. One could let the function blocks be created in pascal and provide a visual means to connect them. I've been tempted to create such an editor, but i lack the time and knowledge (again time). But its on my ever expanding todo list. ---------------------------------------------------------------------- ccrause · 2024-04-14 08:55 Quote from: ojz0r on April 14, 2024, 10:26:10 amQuote from: ccrause on April 14, 2024, 09:28:56 amQuote from: gasensor on April 14, 2024, 01:09:48 amQuote from: bobihot on April 14, 2024, 12:56:45 amI very need, but can`t for now - is not possibly practically. If possibly and visual programming like A visual programming environment https://www.mitov.com/products/visuino#overview "A visual programming environment" = Labview This type of graphical programming language struggles to handle complex logical relationships. I've used Labview, and simple stuff is fine. Once the program is complicated, it's hell. Another example is Node-RED.  But this has nothing to do with Pascal (or any other traditional language), since the "language" is based on visual representation. One could let the function blocks be created in pascal and provide a visual means to connect them. I've been tempted to create such an editor, but i lack the time and knowledge (again time). But its on my ever expanding todo list. Yes, that is true. But then the general question is still how good is fpc for embedded programming, since that will produce the final executable code. Compared to the Arduino framework (the engine below Visuino AFAIK) fpc lacks hardware support libraries and the range of targets supported.  On the positive side fpc is fast, so the compiling phase should be quick, particularly if most of the code sits in precompiled units. Thinking about this more, Node-RED is not relevant for this discussion of embedded microcontroller since it runs JavaScript. It is only relevant for application level platforms than can run the JavaScript engine. ---------------------------------------------------------------------- marcov · 2024-04-14 09:52 I was speaking in general. But specifically, I use dspic33E :-) ---------------------------------------------------------------------- ccrause · 2024-04-14 10:38 Quote from: marcov on April 14, 2024, 11:52:51 amI was speaking in general. But specifically, I use dspic33E :-) Unfortunately not even a whiff of PIC support in fpc... Edit: removed nonfunctional emoji ---------------------------------------------------------------------- VisualLab · 2024-04-14 12:33 Quote from: gasensor on April 13, 2024, 05:05:02 pm1. It's hard to get out of bounds when accessing arrays/string. 2. The compiler is free for commercial use. 3. It is effective to avoid the macro hell of the C language. 4. It can effectively avoid the trap of local variables in C language. 5. The program is highly readable, even if it lacks comments. 6. This kind of question does not appear: j=++j + ++j;  j= what? For myself I would add: 7. a system for building executable files that is much more convenient than those used in C and C++. An exception may be the building system used in Visual Studio (for C++), provided that someone makes the entire project only using this tool and only for Windows. The opposite of this is CMake - crap created probably just to annoy users (programmers) and increase the already considerable costs of developing software written in C or C++. But OK, ultimately you can understand it if it is a commercial solution, intended for a large number of users, which is supposed to run on several OSes (especially on servers). However, in other applications it is stupidity, masochism and malice all in one. Example: Raspberry Pi Pico SDK. Why the hell was there a need to use such a piece of crap (and a classic, shoddy and underdeveloped makeshift solution at that) like CMake for a project intended for only one microcontroller? And not even a family, just: 1 type of microcontroller. And the alternative is... Python! From one extreme idiocy to another extreme idiocy. And yet it could be done relatively cheaply and painlessly. This is shown by the example of Arduino (also the new one, Uno R4). ---------------------------------------------------------------------- VisualLab · 2024-04-14 12:40 Quote from: gasensor on April 14, 2024, 01:09:48 amQuote from: bobihot on April 14, 2024, 12:56:45 amI very need, but can`t for now - is not possibly practically. If possibly and visual programming like A visual programming environment https://www.mitov.com/products/visuino#overview "A visual programming environment" = Labview This type of graphical programming language struggles to handle complex logical relationships. I've used Labview, and simple stuff is fine. Once the program is complicated, it's hell. Maybe the problem is not very well refined modularity. In addition, the source code (a sequence of instructions) can be presented graphically in various ways. Maybe another way would be better. But now this can no longer be done due to the existing code base (as is the case with other programming languages). ---------------------------------------------------------------------- VisualLab · 2024-04-14 12:43 Quote from: ccrause on April 14, 2024, 12:38:23 pmQuote from: marcov on April 14, 2024, 11:52:51 amI was speaking in general. But specifically, I use dspic33E :-) Unfortunately not even a whiff of PIC support in fpc... Edit: removed nonfunctional emoji If someone really wants Pascal for microcontrollers from several different PIC families, all they have left is microPascal. ---------------------------------------------------------------------- marcov · 2024-04-14 13:11 Quote from: VisualLab on April 14, 2024, 02:43:07 pmIf someone really wants Pascal for microcontrollers from several different PIC families, all they have left is microPascal. Education, not production oriented.   Anyway, while I still curse at typical C gotchas and annoyances, for these relative small (2k-3k lines per project with 20000 lines own generic code compiling to 27kb) programs, it doesn't matter that much in the long run. ---------------------------------------------------------------------- 440bx · 2024-04-14 14:32 I wanted to add one thing to the list that isn't only related to embedded programming but still applicable and quite a plus in my mind, that is: compilation speed. Depending on how you write your programs, FPC can consistently deliver sub-second build cycles.  Once you get used to that and you go to programming in C/C++ using something like Visual Studio, very quickly you honestly wonder if you live on a planet of programming masochists (which forces you to ask yourself, why am I using this thing ???.) ---------------------------------------------------------------------- marcov · 2024-04-14 14:46 For me it doesn't matter. Simply because I have source files in the same magnitude as physical cores they are all built in one go, so instantaneously. ---------------------------------------------------------------------- 440bx · 2024-04-14 15:17 Quote from: marcov on April 14, 2024, 04:46:32 pmFor me it doesn't matter. Simply because I have source files in the same magnitude as physical cores they are all built in one go, so instantaneously. I'm not sure I am understanding you correctly.  Are you saying that your compiles in VS C/C++ happen instantaneously ?... if you get instantaneous builds in VS C/C++, I truly envy you. ---------------------------------------------------------------------- gasensor · 2024-04-14 15:33 Quote from: 440bx on April 14, 2024, 04:32:17 pmI wanted to add one thing to the list that isn't only related to embedded programming but still applicable and quite a plus in my mind, that is: compilation speed. Depending on how you write your programs, FPC can consistently deliver sub-second build cycles.  Once you get used to that and you go to programming in C/C++ using something like Visual Studio, very quickly you honestly wonder if you live on a planet of programming masochists (which forces you to ask yourself, why am I using this thing ???.) Programming languages with strong data types tend to compile quickly. When processing strings, you don't need to compare whether the current character is "0" character by character. In order to improve compilation speed, C/C++ often separates out the parts that need to be modified. That's why C/C++ projects have a lot of DLL files. I saw this method in an article written by a programmer at EA. Of course, there is another way, which is one file per function. In this way, you don't have to recompile all the programs if you modify a few places. But this results in thousands of source files. One of the projects I'm aware of that uses this style is Azure RTOS (formerly ThreadX) ---------------------------------------------------------------------- marcov · 2024-04-14 16:10 Quote from: 440bx on April 14, 2024, 05:17:08 pmQuote from: marcov on April 14, 2024, 04:46:32 pmFor me it doesn't matter. Simply because I have source files in the same magnitude as physical cores they are all built in one go, so instantaneously. I'm not sure I am understanding you correctly.  Are you saying that your compiles in VS C/C++ happen instantaneously ?... if you get instantaneous builds in VS C/C++, I truly envy you. This is about embedded 30kb programs (10-20kloc) in MP Lab X(a netbeans derivative) with gcc. ---------------------------------------------------------------------- AlanTheBeast · 2024-11-27 00:13 Quote from: gasensor on April 13, 2024, 05:05:02 pm1. It's hard to get out of bounds when accessing arrays/string. 2. The compiler is free for commercial use. 3. It is effective to avoid the macro hell of the C language. 4. It can effectively avoid the trap of local variables in C language. 5. The program is highly readable, even if it lacks comments. 6. This kind of question does not appear: j=++j + ++j;  j= what? I find it funny that people are bashing Pascal for "small" embedded programs. The new Arduino R4 (32b) at 48MHz, 32 KB of RAM and 256 KB of flash is a computer with nice I/O attached to it; In the 90s - such a setup would satisfy the flight management system for a B-747-400.  And, shocker, FMS' for airliners and military use were often written in ... wait for it, Pascal.  (Ada was warming up in the wings with a few projects implemented - A lot of the B-777 and almost all of the F-22 avionics for example). ---------------------------------------------------------------------- AlanTheBeast · 2024-11-27 15:30 Quote from: 440bx on April 14, 2024, 04:32:17 pmI wanted to add one thing to the list that isn't only related to embedded programming but still applicable and quite a plus in my mind, that is: compilation speed. Depending on how you write your programs, FPC can consistently deliver sub-second build cycles.  I use units a lot, so yes, most builds, post edit, are near instant.  Back in the 90's a moderately sized program could no longer be compiled in the Turbo-Pascal IDE, and with command line took a pretty even 60 s. to build on a 16MHz 386.  On a Celeron it took 1 or 2s.  The Ultibo version (Raspberry Pi target, no OS, runtime Lib) is not as quick though - but I think that is the Lazarus IDE more than the compiler). When I first worked for a large company, __ the assembler __ for a 65,000 line program took about 1 hour, or 4 hours if the chain printer was converting trees to paper during the assembly.  (I wonder why we never wrote a x-assembler for the 370). (make sure the whole thing assembles and links once before printing). This program was spread out over 9 files on the old HP-2100.  When we moved to the HP-1000, we broke it up into about 25 files.  The 2100 was a single user OS; the -1000 multi-user - we had about 10 stations for it.  I also wrote some data reduction s/w (Fortran-77) on there that I really should have moved to the VAX when it came in.  The HP-1000 OS failed Year 2000 (file system was date dependent on 2 digits) and we retired it.  A cross assembler was written for us by a contractor.  Good PC's could assemble that in a flash.  (Said contractor is now a mega millionaire). ---------------------------------------------------------------------- lainz · 2024-11-27 15:35 Quote from: marcov on April 14, 2024, 04:46:32 pmFor me it doesn't matter. Simply because I have source files in the same magnitude as physical cores they are all built in one go, so instantaneously. Can you explain what that means, I don't get it. ---------------------------------------------------------------------- marcov · 2024-11-27 16:57 Quote from: lainz on November 27, 2024, 04:35:44 pmQuote from: marcov on April 14, 2024, 04:46:32 pmFor me it doesn't matter. Simply because I have source files in the same magnitude as physical cores they are all built in one go, so instantaneously. Can you explain what that means, I don't get it. Simple. A typical project has 8 source (.c) files.   I have PCs with 8 cores, the IDE launches GCC 8 times.  So the whole project builds with the speed of the slowest .c file. ---------------------------------------------------------------------- lainz · 2024-11-27 18:10 Quote from: marcov on November 27, 2024, 05:57:09 pmQuote from: lainz on November 27, 2024, 04:35:44 pmQuote from: marcov on April 14, 2024, 04:46:32 pmFor me it doesn't matter. Simply because I have source files in the same magnitude as physical cores they are all built in one go, so instantaneously. Can you explain what that means, I don't get it. Simple. A typical project has 8 source (.c) files.   I have PCs with 8 cores, the IDE launches GCC 8 times.  So the whole project builds with the speed of the slowest .c file. Cool, thanks for the explanation.