The King then read from his book: "Rule forty-two. _All persons more
than a mile high to leave the court_."
I have written a similar program in C for uC Cortex-M0. And my point is that in Pascal I haven't even achieved half of the functionality, and I'm already exceeding 5kB Flash more than the one written in C.
It worries me very much
I am slowly beginning to come to the conclusion that Pascal is not suitable for writing in microcontrollers.
I have big problems writing in this language ... I do the same thing as in C, and yet I encounter Hard Fault more often than I did in C.
Could PicPas example help this discussion?I have written a similar program in C for uC Cortex-M0. And my point is that in Pascal I haven't even achieved half of the functionality, and I'm already exceeding 5kB Flash more than the one written in C.With such constraints you indeed need to lay off the automated types. (though I would avoid textual I/O in microcontrollers in general)QuoteIt worries me very muchPascal and C are nearly equivalent in theoretical performance. The difference is more in the amount and quality of compilers and what their optimization targets are.
I am slowly beginning to come to the conclusion that Pascal is not suitable for writing in microcontrollers.
Free Pascal's Object Pascal is like C++. It is high level language, but the lowlevel (in C++ case: C) still lives there.
Just like that, rock bottom Pascal is like C without macros. (iow #define only for constants).
You will need to learn to adjust the levelQuoteI have big problems writing in this language ... I do the same thing as in C, and yet I encounter Hard Fault more often than I did in C.It could be a compiler bug, but 9 to 10 this is some mistake you made. If you are less proficient in embedded Pascal that can happen. Stay critical and try to isolate the problem. It could be as little as translating char buff[5] into array[0..5] of char; {1 char more!}
i get Hard Fault in line " buf^ := p^ "
Any attempt to write to 'buf ^' results in an error.
Older and simpler Pascal implementations prior to Free Pascal would be more appropriate to beat C results in this case?I have written a similar program in C for uC Cortex-M0. And my point is that in Pascal I haven't even achieved half of the functionality, and I'm already exceeding 5kB Flash more than the one written in C.With such constraints you indeed need to lay off the automated types. (though I would avoid textual I/O in microcontrollers in general)QuoteIt worries me very muchPascal and C are nearly equivalent in theoretical performance. The difference is more in the amount and quality of compilers and what their optimization targets are.
I am slowly beginning to come to the conclusion that Pascal is not suitable for writing in microcontrollers.
Free Pascal's Object Pascal is like C++. It is high level language, but the lowlevel (in C++ case: C) still lives there.
Just like that, rock bottom Pascal is like C without macros. (iow #define only for constants).
You will need to learn to adjust the levelQuoteI have big problems writing in this language ... I do the same thing as in C, and yet I encounter Hard Fault more often than I did in C.It could be a compiler bug, but 9 to 10 this is some mistake you made. If you are less proficient in embedded Pascal that can happen. Stay critical and try to isolate the problem. It could be as little as translating char buff[5] into array[0..5] of char; {1 char more!}
Older and simpler Pascal implementations prior to Free Pascal would be more appropriate to beat C results in this case?
Older and simpler Pascal implementations prior to Free Pascal would be more appropriate to beat C results in this case?
*sigh* again the myth of the large binaries. An empty program for avr25 results in
...
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data
The 38 bytes come from the interrupt handlers.
No myth at all: his complaint was about ARM. Somebody else made the point that perhaps comparing with AVR would be worthwhile.ARM embedded has similar sizes. But don't expect a Raspberry Pi with a full Debian as embedded. It will have the same overhead that comes with a full OS.
MarkMLl
I think it would be interesting, though, if there were some way of /completely/ disabling "Delphi-style" strings, and running FPC (with a subset of units/packages) with only "classical" Pascal strings (size predeclared, length in elementYou don't need some way to disable Delphi-style strings, because if you don't use them, then the compiler and linker won't include the corresponding functionality (this is especially true for the embedded target). Same for implicit exception frames: if you don't use managed types then the implicit frames won't be generated.
- , absolute limit of 256 8-bit characters) and possibly with no compiler support for finalisation blocks and exceptions. /If/ that could be done, then it would be possible to compare against say TP5 and against various Modula-2 compilers which as I understand it had well-regarded optimisation (because the user was giving the compiler a bit more information about what he was trying to do).
Take a look at the code again. buf is an input argument of type PChar and p is a pointer to the local array buff.i get Hard Fault in line " buf^ := p^ "
Any attempt to write to 'buf ^' results in an error.
The notation something^ applies only to a pointer: it's meant to dereference it. Your buf variable, though, is an array: you should access/set it by using an index into the array, as in:
buf[x] := p^
In C it's different because an "array" is almost exactly the same as a pointer.
*sigh* again the myth of the large binaries. An empty program for avr25 results inThe point you mentioned is empty program. But once users start to use more features that size obviously increases. So they need to monitor what they use so that they don't break any size constraints.
<fpc trunk for avr> -Wpattiny28 tavr.pp -O4
Free Pascal Compiler version 3.3.1 [2019/12/24] for avr
Copyright (c) 1993-2019 by Florian Klaempfl and others
Target OS: Embedded
Compiling tavr.pp
Assembling program
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data
The 38 bytes come from the interrupt handlers.
Take a look at the code again. buf is an input argument of type PChar and p is a pointer to the local array buff.i get Hard Fault in line " buf^ := p^ "
Any attempt to write to 'buf ^' results in an error.
The notation something^ applies only to a pointer: it's meant to dereference it. Your buf variable, though, is an array: you should access/set it by using an index into the array, as in:
buf[x] := p^
In C it's different because an "array" is almost exactly the same as a pointer.
*sigh* again the myth of the large binaries. An empty program for avr25 results inI think without real life project (working code) we can't make objective discussion.
<fpc trunk for avr> -Wpattiny28 tavr.pp -O4
Free Pascal Compiler version 3.3.1 [2019/12/24] for avr
Copyright (c) 1993-2019 by Florian Klaempfl and others
Target OS: Embedded
Compiling tavr.pp
Assembling program
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data
The 38 bytes come from the interrupt handlers.
Also for the embedded target one can explicitely decide which features should be enabled when compiling the RTL (take a look at $fpcdir/rtl/embedded/system.cfg), thus avoiding that it's used by accident.
Check trunkAlso for the embedded target one can explicitely decide which features should be enabled when compiling the RTL (take a look at $fpcdir/rtl/embedded/system.cfg), thus avoiding that it's used by accident.
In FPC 3.0.4 I did not find a system.cfg in this folder, but a rtl.cfg. Do you mean this?
It was my inexperience with this compiler that gave rise to this topic. I apologize in advance.
In 3.0.4 it's indeed the rtl.cfg. For trunk that was changed to system.cfg which is used to compile the System unit and rtl.cfg which is used for the remainder of the RTL (currently only used for i8086 to ensure that smartlinking is enabled) as the enabled features are now stored in the System unit.Also for the embedded target one can explicitely decide which features should be enabled when compiling the RTL (take a look at $fpcdir/rtl/embedded/system.cfg), thus avoiding that it's used by accident.
In FPC 3.0.4 I did not find a system.cfg in this folder, but a rtl.cfg. Do you mean this?
*sigh* again the myth of the large binaries. An empty program for avr25 results inThe point you mentioned is empty program.
<fpc trunk for avr> -Wpattiny28 tavr.pp -O4
Free Pascal Compiler version 3.3.1 [2019/12/24] for avr
Copyright (c) 1993-2019 by Florian Klaempfl and others
Target OS: Embedded
Compiling tavr.pp
Assembling program
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data
The 38 bytes come from the interrupt handlers.
OKEYMy first working FPC AVR target port (without strings, advanced records, heap, ...) http://elm-chan.org/fsw/ff/00index_p.html - hex image size is ~ 9k vs C ~ 2 - 4k.
From now on, I check 2x how the code I write affects the size of the output.
OKEYMy first working FPC AVR target port (without strings, advanced records, heap, ...) http://elm-chan.org/fsw/ff/00index_p.html - hex image size is ~ 9k vs C ~ 2 - 4k.
From now on, I check 2x how the code I write affects the size of the output.
Did you use trunk? The newest doesn't pull in exception handling for divisions/modulus by constants for example
2019/09/22 is not exactly new is it? Trunk is a moving target and if you want to use it, plz compile on a daily basis, not three monthly.After update -
Pascal is not C and some innocent looking code might pull in unwanted parts of the RTL. I hope you checked the map file for such problems?
Show the code that generates that muchhttps://github.com/JulStrat/pff/tree/devop/examples/arduino
Did you use trunk? The newest doesn't pull in exception handling for divisions/modulus by constants for example< snip >
Any reason for update?
*sigh* again the myth of the large binaries. An empty program for avr25 results in
<fpc trunk for avr> -Wpattiny28 tavr.pp -O4
Free Pascal Compiler version 3.3.1 [2019/12/24] for avr
Copyright (c) 1993-2019 by Florian Klaempfl and others
Target OS: Embedded
Compiling tavr.pp
Assembling program
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data
The 38 bytes come from the interrupt handlers.
Whether it is acceptable or not does not matter. div handling with all it's infrastructure needed in object pascal is that big. FPC generates an ldi, three moves and a call for the div.
8< ...
Whether it is acceptable or not does not matter. div handling with all it's infrastructure needed in object pascal is that big. FPC generates an ldi, three moves and a call for the div.
8< ...
I agree that the safety of using Pascal should not be sacrificed, but I would like to suggest that more compact error handling could be implemented for AVR, see e.g. the suggestion in issue 35754 (https://bugs.freepascal.org/view.php?id=35754). Basically, remove exception raising code, since exception handling support is not enabled anyway.
Whether it is acceptable or not does not matter. div handling with all it's infrastructure needed in object pascal is that big. FPC generates an ldi, three moves and a call for the div.
8< ...
I agree that the safety of using Pascal should not be sacrificed, but I would like to suggest that more compact error handling could be implemented for AVR, see e.g. the suggestion in issue 35754 (https://bugs.freepascal.org/view.php?id=35754). Basically, remove exception raising code, since exception handling support is not enabled anyway.
rtl/embedded/system.cfg -So exception handling enabled or disabled?
# does not require extra memory, neither code nor data # in programs not using e. g. writeln based I/O which is the common case for AVR #ifdef CPUAVR -SfOBJECTS -SfEXCEPTIONS -SfCLASSES -SfRTTI # AVR6 has normally more memory, so enable more functions #ifdef CPUAVR6 -SfANSISTRINGS -SfWIDESTRINGS -SfDYNARRAYS -SfTHREADING -SfVARIANTS -SfOBJECTS -SfCOMMANDARGS -SfRANDOM -SfRESOURCES #endif #endif
Strange output. I have disabled CLASSES, EXCEPTIONS -That is the list of features the compiler knows of. It does not mean that the system unit was compiled with those features enabled.
Recognized compiler and RTL features: HEAP,INITFINAL,RTTI,CLASSES,EXCEPTIONS,EXITCODE,ANSISTRINGS,WIDESTRINGS TEXTIO,CONSOLEIO,FILEIO,RANDOM,VARIANTS,OBJECTS,DYNARRAYS,THREADING COMMANDARGS,PROCESSES,STACKCHECK,DYNLIBS,SOFTFPU,OBJECTIVEC1,RESOURCES UNICODESTRINGS
OK. How read / output enabled compiler features ? Simple question. I need only enabled compiler features.Strange output. I have disabled CLASSES, EXCEPTIONS -That is the list of features the compiler knows of. It does not mean that the system unit was compiled with those features enabled.
Recognized compiler and RTL features: HEAP,INITFINAL,RTTI,CLASSES,EXCEPTIONS,EXITCODE,ANSISTRINGS,WIDESTRINGS TEXTIO,CONSOLEIO,FILEIO,RANDOM,VARIANTS,OBJECTS,DYNARRAYS,THREADING COMMANDARGS,PROCESSES,STACKCHECK,DYNLIBS,SOFTFPU,OBJECTIVEC1,RESOURCES UNICODESTRINGS