Recent

Author Topic: AVRPascal – free code editor for FPC for AVR  (Read 2101 times)

ackarwow

  • New Member
  • *
  • Posts: 17
AVRPascal – free code editor for FPC for AVR
« on: October 06, 2024, 06:47:12 pm »
Good evening, esteemed users of this forum!
I would like to introduce a Pascal code editor for AVR microcontrollers that I have created. I named it AVRPascal. AVRPascal uses the Free Pascal compiler to generate the output file and AVRdude to save the code in the microcontroller's memory using the USBasp programmer or an Arduino (AVRPascal supports several popular Arduino boards, including Uno and Nano).
Key features:
    • Syntax highlighting for improved code readability.
    • Error indication: Points to the line of code containing compilation errors.
    • Tooltips: Provide information about function and procedure parameters, record fields, and class methods.
    • Tabbed document interface for efficient code organization.
    • Microcontroller fuse-bit configuration capability.
    • Automatic detection of supported USB devices.

AVRPascal is absolutely free (freeware). I hope you will find it useful, and I would be grateful for any feedback, especially critical comments that can help me improve it. I am regularly release new versions of AVRPascal for Windows, Linux, and MacOS on my webpage http://akarwowski.pl/index.php?page=electronics&lang=en.
PS. AVRPascal is written in Free Pascal/Lazarus  :)
« Last Edit: October 06, 2024, 06:50:25 pm by ackarwow »

cb_1964

  • Newbie
  • Posts: 1
Re: AVRPascal – free code editor for FPC for AVR
« Reply #1 on: October 06, 2024, 09:12:10 pm »
Great Work

VisualLab

  • Hero Member
  • *****
  • Posts: 519
Re: AVRPascal – free code editor for FPC for AVR
« Reply #2 on: October 06, 2024, 09:42:43 pm »
I will certainly try it and will be happy to compare its capabilities with those of the Arduino IDE. If AVRPascal has even a fraction of the functionality of the Arduino IDE, I will use it (and try to popularize it). I must also admit that the screenshots shown are very encouraging. The program's GUI is not only aesthetically pleasing, but also seems well-thought-out and ergonomic.

P.S. This would be the second tool for microcontrollers written in Free Pascal. The previous one was PICPas, created by Edson.
« Last Edit: October 06, 2024, 09:46:37 pm by VisualLab »

ackarwow

  • New Member
  • *
  • Posts: 17
Re: AVRPascal – free code editor for FPC for AVR
« Reply #3 on: October 06, 2024, 09:55:48 pm »
I will certainly try it and will be happy to compare its capabilities with those of the Arduino IDE. If AVRPascal has even a fraction of the functionality of the Arduino IDE, I will use it (and try to popularize it). I must also admit that the screenshots shown are very encouraging. The program's GUI is not only aesthetically pleasing, but also seems well-thought-out and ergonomic.

P.S. This would be the second tool for microcontrollers written in Free Pascal. The previous one was PICPas, created by Edson.

Thanks for your comment. I didn't base my design on the Arduino IDE functionality, but I think AVRPascal can be similar to Arduino IDE in some ways (it also uses AVRDude :) ). There is a manual in pdf for AVRPascal on my website, I hope it will be useful regarding the possibilities and limitations of AVRPascal.

In my opinion GUI of AVRPascal is very simple, and slightly similar to old Pascal for Windows. Of course there may be better ideas for window layout or menu names. For example: for some people menu „Run” may be inadequate or misleading because the microcontroller is programmed (not run as exe application), but I mean run of e.g. compilation or uploading task...
« Last Edit: October 07, 2024, 12:06:17 am by ackarwow »

VisualLab

  • Hero Member
  • *****
  • Posts: 519
Re: AVRPascal – free code editor for FPC for AVR
« Reply #4 on: October 07, 2024, 12:08:50 am »
I will certainly try it and will be happy to compare its capabilities with those of the Arduino IDE. If AVRPascal has even a fraction of the functionality of the Arduino IDE, I will use it (and try to popularize it). I must also admit that the screenshots shown are very encouraging. The program's GUI is not only aesthetically pleasing, but also seems well-thought-out and ergonomic.

P.S. This would be the second tool for microcontrollers written in Free Pascal. The previous one was PICPas, created by Edson.

Thanks for your comment. I didn't base my design on the Arduino IDE functionality, but I think AVRPascal can be similar to Arduino IDE in some ways (it also uses AVRDude :) ). There is a manual in pdf for AVRPascal on my website, I hope it will be useful regarding the possibilities and limitations of AVRPascal.

In my opinion GUI of AVRPascal is very simple, and slightly similar to old Pascal for Windows. Of course there may be better ideas for window layout or menu names. For example: for some people menu „Run” may be inadequate or misleading because the microcontroller is programmed (not run as exe application), but I mean run of e.g. compilation or uploading task...

It doesn't have to be similar to Arduino at all. It just needs to be ergonomic. As for functionality, I meant more what it can do (operations).

ackarwow

  • New Member
  • *
  • Posts: 17
Re: AVRPascal – free code editor for FPC for AVR
« Reply #5 on: October 07, 2024, 12:18:56 am »
It just needs to be ergonomic. As for functionality, I meant more what it can do (operations).
Of course you are right.

ackarwow

  • New Member
  • *
  • Posts: 17
Re: AVRPascal – free code editor for FPC for AVR
« Reply #6 on: October 07, 2024, 07:42:12 am »

ackarwow

  • New Member
  • *
  • Posts: 17
Re: AVRPascal – free code editor for FPC for AVR
« Reply #7 on: October 21, 2024, 07:50:49 pm »
Today I published AVRPascal 2.6 on my website (http://akarwowski.pl/index.php?page=electronics&lang=en). The changes are mainly bug fixes.
Bug fixes:
- fixed small memory leaks
- fixed PID label name in USB device edit window
- fixed USBAsp connection notification (port: USB)
New features:
- storing height of Messages area
Other:
- new version of UnoLib (https://sourceforge.net/projects/unolib/) library; many thanks to Henk Heemstra for tests and TestBlinkWithoutDelay.pas code

mizar

  • New Member
  • *
  • Posts: 42
Re: AVRPascal – free code editor for FPC for AVR
« Reply #8 on: October 22, 2024, 08:11:52 pm »
I just tried AVRpas on linux64.
In my opinion, a better interface than Arduino IDE v. 2, great job! :)

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...

I hope I made some mistake or that with larger programs the differences will be reduced

ackarwow

  • New Member
  • *
  • Posts: 17
Re: AVRPascal – free code editor for FPC for AVR
« Reply #9 on: October 22, 2024, 09:24:30 pm »
I just tried AVRpas on linux64.
In my opinion, a better interface than Arduino IDE v. 2, great job! :)

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...

I hope I made some mistake or that with larger programs the differences will be reduced

Thank you for your comment and opinion, its nice for me  :)
I made some quick tests for ATMega328p with your options settings:
- program which do nothing (only begin..end): 398 bytes code, 18 bytes data
- and with directive {$mode objfpc}: 792 bytes code, 46 bytes data (+394 bytes code, +28 bytes data)
All code and data seem to be initialization code of FPC RTL.
More tests:
- with timer.pas, with its own initialization code: 1720 bytes code, 73 bytes data (+928 bytes code, +27 bytes data)
- TestBlink.pas (+used units defs.pas and digital.pas) with commented Delay(1000): 2424 bytes code, 133 bytes data (+704 bytes code, +60 bytes data)
My conclusions:
1) part of the code is initialization data of RTL, hard to reduce without changing RTL library
2) part of the code is initialization code of timer.pas which (I suppose) can be improved.
3) yes, its possible that with larger programs the differences will be reduced
4) AVRPascal uses FPC 3.3.1, which (as far I know) is not final version of the compiler and it is in working process.

ccrause

  • Hero Member
  • *****
  • Posts: 958
Re: AVRPascal – free code editor for FPC for AVR
« Reply #10 on: October 23, 2024, 07:15:32 am »
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...

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: [Select]
Verbose: Assembling blink
Verbose: 73 lines compiled, 0.2 sec, 264 bytes code, 3 bytes data

Or a simple blink using busy delays compiled with FPC main:
Code: [Select]
Verbose: Assembling delay
Verbose: Assembling blink
Verbose: 224 lines compiled, 0.2 sec, 218 bytes code, 0 bytes data

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

  • New Member
  • *
  • Posts: 17
Re: AVRPascal – free code editor for FPC for AVR
« Reply #11 on: October 23, 2024, 07:48:32 am »
For example a blink using a timer interrupt compiled with FPC main:
Code: [Select]
Verbose: Assembling blink
Verbose: 73 lines compiled, 0.2 sec, 264 bytes code, 3 bytes data
Which version of FPC was used for compile this blink code? I compiled the same with different result in AVRPascal:

Code: [Select]
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

ccrause

  • Hero Member
  • *****
  • Posts: 958
Re: AVRPascal – free code editor for FPC for AVR
« Reply #12 on: October 23, 2024, 08:37:27 am »
Which version of FPC was used for compile this blink code? I compiled the same with different result in AVRPascal:

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

  • New Member
  • *
  • Posts: 17
Re: AVRPascal – free code editor for FPC for AVR
« Reply #13 on: October 23, 2024, 08:55:01 am »
optimization setting can have a significant impact.
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

  • Hero Member
  • *****
  • Posts: 958
Re: AVRPascal – free code editor for FPC for AVR
« Reply #14 on: October 23, 2024, 06:03:39 pm »
optimization setting can have a significant impact.
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...

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  [Select][+][-]
  1. program blink;
  2.  
  3. uses
  4.   intrinsics;
  5.  
  6. const
  7.   {$if defined(FPC_MCU_ATMEGA328P)}
  8.   // Assume Uno layout
  9.   LEDpin = 1 shl 5;
  10.   {$elseif defined(FPC_MCU_ATMEGA32U4)}
  11.   // Assume Pro Micro layout
  12.   LEDpin = 1;
  13.   {$elseif defined(FPC_MCU_ATMEGA2560)}
  14.   // Assume Mega layout
  15.   LEDpin = 1 shl 7;
  16.   {$else}
  17.   LEDpin = 1 shl 3;
  18.   {$endif}
  19.  
  20.   CS00msk = 1 shl 0;
  21.   CS01msk = 1 shl 1;
  22.   CS02msk = 1 shl 2;
  23.  
  24.   TOIE0msk =
  25.   {$ifdef FPC_MCU_ATTINY45}
  26.    1 shl 1;
  27.   {$else}
  28.   1;
  29.   {$endif}
  30.  
  31. var
  32.   countsPerSecond: byte;
  33.   LEDport: byte absolute PORTB;
  34.   LEDdir: byte absolute DDRB;
  35.   i: byte = 1;
  36.  
  37. procedure Timer0Overflow; alias: 'TIMER0_OVF_ISR'; interrupt;
  38. begin
  39.   inc(i);
  40.   if i > countsPerSecond then
  41.   begin
  42.     LEDport := LEDport xor LEDpin;
  43.     i := 0;
  44.   end;
  45. end;
  46.  
  47. procedure init;
  48. begin
  49.   LEDdir := LEDdir or LEDpin;  // Set pin to output
  50.   LEDport := LEDport or LEDpin; // Set LED high
  51. end;
  52.  
  53. begin
  54.   init;
  55.   countsPerSecond := (((F_CPU div 1024) + 128) div 256 div 3) ;  // ~1 Hz
  56.   LEDdir := LEDdir or LEDpin;  // Set pin to output
  57.   LEDport := LEDport or LEDpin; // Set LED high
  58.  
  59.   TCNT0 := 0;
  60.   TCCR0A := 0;
  61.   TCCR0B := CS02msk or CS00msk;  // clock prescaler = 1024
  62.   // enable timer1 overflow interrupt
  63.   {$ifdef FPC_MCU_ATTINY45}
  64.   TIMSK
  65.   {$else} // defaults to atmega328p
  66.   TIMSK0
  67.   {$endif}
  68.   := TOIE0msk;
  69.  
  70.   avr_sei;
  71.   while True do;
  72. end.
  73.  

Compiled with current main (commit 2262d2050defed7a5df8aa6c70ad696603335d3d):
Code: Text  [Select][+][-]
  1. ~/fpc/installs/lib/fpc/3.3.1/ppcrossavr -Wpatmega328p -Sm -dF_CPU:=16000000 -vwni -l -O3 blink.pp
  2. Free Pascal Compiler version 3.3.1 [2024/10/23] for avr
  3. Copyright (c) 1993-2024 by Florian Klaempfl and others
  4. Target OS: Embedded
  5. Compiling blink.pp
  6. Assembling blink
  7. Linking blink
  8. 73 lines compiled, 0.2 sec, 264 bytes code, 3 bytes data

Using 3.2.2:
Code: Text  [Select][+][-]
  1. ~/fpc/installs/lib/fpc/3.2.2/ppcrossavr -Wpatmega328p -Sm -dF_CPU:=16000000 -vwni -l -O3 blink.pp
  2. Free Pascal Compiler version 3.2.2 [2022/06/26] for avr
  3. Copyright (c) 1993-2021 by Florian Klaempfl and others
  4. Target OS: Embedded
  5. Compiling blink.pp
  6. Assembling blink
  7. Linking blink
  8. 73 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?

 

TinyPortal © 2005-2018