Forum > Embedded - AVR
AVRPascal – free code editor for FPC for AVR
ccrause:
--- Quote from: mizar on October 22, 2024, 08:11:52 pm ---I compiled the blink example for ArduinoUNO board (AVR328P):
AVRpas (fpc): code 2816 byte, data 112 byte :-[
Arduino IDE: code 924 byte, data 9 byte :o
Is Arduino IDE cheating or what ? 8-)
I wish I could program avr using fpc, but we are on a platform where we can't afford to waste flash and /or ram that way...
--- End quote ---
In general the use of abstraction layers such as used by the Arduino libraries comes with overhead. For example hiding the pin/port low level detail and abstracting that with a pin number comes with the cost of a lookup table and some lookup code, and using a preconfigured timer for delays etc. also comes with code overhead. If one is really focused on minimizing executable code and data sizes get rid of abstraction layers. For example a blink using a timer interrupt compiled with FPC main:
--- Code: ---Verbose: Assembling blink
Verbose: 73 lines compiled, 0.2 sec, 264 bytes code, 3 bytes data
--- End code ---
Or a simple blink using busy delays compiled with FPC main:
--- Code: ---Verbose: Assembling delay
Verbose: Assembling blink
Verbose: 224 lines compiled, 0.2 sec, 218 bytes code, 0 bytes data
--- End code ---
AVRpas probably has room for size improvements compared to the Arduino c++ libraries, but the real trade-off to consider is smaller executable code/data size of bare bones programming vs the convenience of hiding a lot of the low level details from the programmer.
ackarwow:
--- Quote from: ccrause on October 23, 2024, 07:15:32 am ---For example a blink using a timer interrupt compiled with FPC main:
--- Code: ---Verbose: Assembling blink
Verbose: 73 lines compiled, 0.2 sec, 264 bytes code, 3 bytes data
--- End code ---
--- End quote ---
Which version of FPC was used for compile this blink code? I compiled the same with different result in AVRPascal:
--- Code: ---Target OS: Embedded
Compiling /home/andrzej/Programs/avr/avrpascal/examples/ccrause_blink.pas
ccrause_blink.pas(23,3) Hint: Local const "CS01msk" is not used
ccrause_blink.pas(39,11) Hint: Local proc "Timer0Overflow" is not used
Assembling blink
Linking /home/andrzej/Programs/avr/avrpascal/examples/ccrause_blink
75 lines compiled, 0.1 sec, 472 bytes code, 20 bytes data
2 hint(s) issued
--- End code ---
ccrause:
--- Quote from: ackarwow on October 23, 2024, 07:48:32 am ---Which version of FPC was used for compile this blink code? I compiled the same with different result in AVRPascal:
--- End quote ---
It was compiled with FPC main, probably a few weeks old. I will confirm later when ppcrossavr was compiled and which compiler settings I used (optimization setting can have a significant impact).
ackarwow:
--- Quote from: ccrause on October 23, 2024, 08:37:27 am ---optimization setting can have a significant impact.
--- End quote ---
Thank you for your answer. AVRPas uses internally -O3 parameter for compile RTL sources (system.pp and atmega328p.pp in this case), The same optimization level I used to compile your blink example. I have observed that FPC in version 3.2.2 produces significantly smaller code than FPC 3.3.1...
ccrause:
--- Quote from: ackarwow on October 23, 2024, 08:55:01 am ---
--- Quote from: ccrause on October 23, 2024, 08:37:27 am ---optimization setting can have a significant impact.
--- End quote ---
Thank you for your answer. AVRPas uses internally -O3 parameter for compile RTL sources (system.pp and atmega328p.pp in this case), The same optimization level I used to compile your blink example. I have observed that FPC in version 3.2.2 produces significantly smaller code than FPC 3.3.1...
--- End quote ---
I would expect 3.3.1 to produce smaller executable code compared to 3.2.2 in general (at least for simple procedural code). Please post example code which produces smaller code in 3.2.2 (in a separate discussion so that this discussion can focus on AVRPascal). I would like to investigate this further.
Back to the blink size:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program blink; uses intrinsics; const {$if defined(FPC_MCU_ATMEGA328P)} // Assume Uno layout LEDpin = 1 shl 5; {$elseif defined(FPC_MCU_ATMEGA32U4)} // Assume Pro Micro layout LEDpin = 1; {$elseif defined(FPC_MCU_ATMEGA2560)} // Assume Mega layout LEDpin = 1 shl 7; {$else} LEDpin = 1 shl 3; {$endif} CS00msk = 1 shl 0; CS01msk = 1 shl 1; CS02msk = 1 shl 2; TOIE0msk = {$ifdef FPC_MCU_ATTINY45} 1 shl 1; {$else} 1; {$endif} var countsPerSecond: byte; LEDport: byte absolute PORTB; LEDdir: byte absolute DDRB; i: byte = 1; procedure Timer0Overflow; alias: 'TIMER0_OVF_ISR'; interrupt;begin inc(i); if i > countsPerSecond then begin LEDport := LEDport xor LEDpin; i := 0; end;end; procedure init;begin LEDdir := LEDdir or LEDpin; // Set pin to output LEDport := LEDport or LEDpin; // Set LED highend; begin init; countsPerSecond := (((F_CPU div 1024) + 128) div 256 div 3) ; // ~1 Hz LEDdir := LEDdir or LEDpin; // Set pin to output LEDport := LEDport or LEDpin; // Set LED high TCNT0 := 0; TCCR0A := 0; TCCR0B := CS02msk or CS00msk; // clock prescaler = 1024 // enable timer1 overflow interrupt {$ifdef FPC_MCU_ATTINY45} TIMSK {$else} // defaults to atmega328p TIMSK0 {$endif} := TOIE0msk; avr_sei; while True do;end.
Compiled with current main (commit 2262d2050defed7a5df8aa6c70ad696603335d3d):
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---~/fpc/installs/lib/fpc/3.3.1/ppcrossavr -Wpatmega328p -Sm -dF_CPU:=16000000 -vwni -l -O3 blink.pp Free Pascal Compiler version 3.3.1 [2024/10/23] for avrCopyright (c) 1993-2024 by Florian Klaempfl and othersTarget OS: EmbeddedCompiling blink.ppAssembling blinkLinking blink73 lines compiled, 0.2 sec, 264 bytes code, 3 bytes data
Using 3.2.2:
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---~/fpc/installs/lib/fpc/3.2.2/ppcrossavr -Wpatmega328p -Sm -dF_CPU:=16000000 -vwni -l -O3 blink.pp Free Pascal Compiler version 3.2.2 [2022/06/26] for avrCopyright (c) 1993-2021 by Florian Klaempfl and othersTarget OS: EmbeddedCompiling blink.ppAssembling blinkLinking blink73 lines compiled, 0.1 sec, 272 bytes code, 3 bytes data
Here the main compiler version results in a smaller executable size compared to 3.2.2.
It is also odd that your output shows that 75 lines were compiled, is there extra code, or just extra empty lines in the source?
Navigation
[0] Message Index
[#] Next page
[*] Previous page