AVRPascal - Frequently Asked Questions ====================================== Q: Is AVRPascal an Open-Source product? A: No, it is Freeware. However, the UnoLib library included with the package is Open-Source. Q: Can I use AVRPascal for my commercial products? A: Yes. You are free to sell devices and software created with AVRPascal. The licensing requirements depend on what you use in your project: 1) Generated Code: Uses the Free Pascal RTL (modified LGPL), which explicitly allows for commercial, closed-source applications without any need to release your source code. 2) UnoLib Library: If you choose to use it, it is licensed under MIT, which requires including a copyright notice in your documentation. 3) Pure Bare-Metal: If you write your own code without UnoLib, you only need to respect the FPC RTL terms. In all cases, the final binary belongs to you, and there are no royalties or fees for using AVRPascal. Q: Is AVRPascal a compiler? A: No. AVRPascal is an IDE and a ready-to-use development package. It integrates external tools such as the Free Pascal Compiler (FPC) for code generation and AVRdude for programming the microcontroller. Q: Is AVRPascal a complete package? A: Yes. AVRPascal includes everything needed to write, compile, and upload Pascal programs to AVR microcontrollers without installing any additional tools. Q: Do I need to define the MCU type in my source code? A: No. The FPC_MCU_XXX or simple XXX (MCU type) symbol is automatically defined by the IDE based on the microcontroller type selected in the Options window. Manual definitions are usually unnecessary and may cause conflicts. However, it is worth adding blocking directives that break compilation for the incorrect MCU type. Q: Where do MCU register and bit definitions come from? A: All register and bit definitions are provided by the Free Pascal Compiler (FPC), in separate definition files for each MCU located in rtl/avr folder. AVRPascal does not modify these definitions in order to remain fully compatible with the compiler. Q: Why is the generated code sometimes larger than in Microchip Studio? A: FPC includes startup, initialization, and finalization code, as well as the full interrupt vector table in its output. While Microchip Studio (GCC) generates only basic startup code, FPC provides a more robust runtime environment. This difference is expected and does not indicate lower code quality or inefficiency, but rather higher code safety and reliability. To minimize the binary size, ensure that the "Optimization" level is set to -O3 or -O4 in the Options window. Q: Why did my program suddenly use much more Flash or SRAM? A: Declaring hardware registers as normal variables allocates RAM and adds initialization code. MCU registers must be declared using the 'absolute' keyword to map them directly to hardware addresses. Q: Can I add my own MCU definitions? A: Yes. If needed, define missing registers locally in your program using the 'absolute' keyword instead of modifying FPC RTL files (for example var PORTB: byte absolute $25). Q: Can I use libraries written for Arduino? A: Not directly. C++ libraries must be ported to Pascal. However, AVRPascal comes with UnoLib, which provides familiar functions (DigitalWrite, Delay, etc.) for a smooth transition. Q: How can I perform floating-point calculations on 8-bit AVR? A: Standard Pascal Single or Double types are not supported by the Free Pascal Compiler for the AVR architecture. However, UnoLib 1.2+ introduces the TFloat32 type. It provides a functional implementation of 32-bit floating-point math, supporting standard operators (+, -, *, /) through operator overloading. This makes your math code both possible to compile and easy to read. Q: Why is my AVRPascal program using UnoLib sometimes larger than the same program in Arduino? A: This is normal and expected. There are two main reasons: 1) Startup and finalization code: Like GCC, FPC generates code to initialize and finalize memory sections and the runtime, ensuring correct program execution on the microcontroller. This adds to the total Flash size. 2) Limited preprocessor functionality in FPC: Unlike Arduino (GCC), FPC does not support text-based or function-like macros. Only conditional compilation directives (e.g., {$IFDEF}, {$IFNDEF}) and variable or symbol definitions via {$DEFINE} are available. To implement functionality that would normally use macros, UnoLib uses regular Pascal code and uses inlining where appropriate. This can increase code size, but ensures type safety, correctness, and maintainability. Overall, a larger program size in FPC/AVRPascal is expected and does not indicate inefficiency or errors in your code. Ensure you have "Optimization" level set to -O3 or -O4 in Project Options to minimize size. Q: Why doesn't FPC support function-like macros like Arduino/C? A: This is a deliberate design choice. FPC prioritizes type safety and code clarity. Instead of macros, use 'inline' procedures. They provide similar performance benefits while allowing the compiler to catch errors that macros would hide. Q: Are there any special requirements for Arduino Leonardo? A: Yes. Arduino Leonardo is a specific board that requires a serial port reset before programming. For full compatibility and stable operation, it is recommended to use the UnoLib library example in 'Extras' directory. Q: How can I debug communication errors with my programmer? A: You can enable the display of compiler and uploader command lines in the Options dialog. This allows you to verify the exact parameters being sent to avrdude. Q: Does AVRPascal support STM32 or ESP32? A: No. AVRPascal is specifically designed for the 8-bit AVR architecture. Supporting 32-bit cores like ARM (STM32) or Xtensa (ESP32) would require entirely different compilers and libraries. Q: Where can I find detailed documentation for Pascal on AVR? A: See the Free Pascal documentation and the wiki pages describing AVR support and low-level programming on https://wiki.freepascal.org/.