Smallest/lightest FPC capable processor? lazarus / 77-Embedded ---------------------------------------------------------------------- AlanTheBeast · 2022-08-02 23:50 If I wanted to do a FPC project that had: - 2 temperature sensors (2 analog inputs) - 5 solid state to electromechanical relay controls - support for a simple display (Like a 2 line display) - text only - RTC desirable - serial i/o desirable (UART) - battery backed store or on board flash for parameters desirable. Processor speed not important - 5 MHz clock would be sufficient - anything higher, ok. Floating Point not needed What would be the slowest, cheapest processor that FPC can build code for? (On a cheap, Arduino-like, breakout kit) Thx. ---------------------------------------------------------------------- wildfire · 2022-08-03 04:08 The Raspberry Pi Pico would appear to fit your needs. ---------------------------------------------------------------------- ccrause · 2022-08-03 06:51 Quote from: AlanTheBeast on August 03, 2022, 01:50:48 am(On a cheap, Arduino-like, breakout kit) You mentioned it, any AVR based Arduino board: Uno, Nano. Perhaps one of the attiny based boards, but you may run out of IO pins. No build- in RTC though. FPC AVR on wiki: https://wiki.freepascal.org/AVR_Programming Next up would be esp8266 (only one ADC channel) and esp32: https://wiki.freepascal.org/Xtensa - only supported in fpc 3.3.1, and a bit of hassle to link to an SDK. But you get on-chip WiFi. Then there are plenty of ARM options, like the RP Pico. ---------------------------------------------------------------------- af0815 · 2022-08-03 07:03 Temperatur Sensors can have a serial interface too. Depending on the type. AVR Arduino board are state of the art and there are a lot of soloutions for external IO ,flash or flashcards. And it is cheap and you can get IO cards complete from stock. ---------------------------------------------------------------------- MarkMLl · 2022-08-03 09:32 Noted your comment about at least starting off with an Arduino-scale breakout board, but when you say "smallest/lightest" do you literally mean "small" as in some fraction of a mm2 and "light" as in mg? In any event, even if small etc. should be interpreted as "limited memory and cheap", you are likely to find that your scale is dominated by considerations of how tolerant the MCU chip (and attached peripherals) is to varying supply voltage, whether the chip/board can supply adequate power to supply the peripherals without an external regulator and so on. As a couple of observations that might or might not help, I've got a little RP2040 board from Waveshare programmed up as a Picoprobe. This is the size of a postage stamp, and its onboard regulator is sufficiently capable that it can drive a larger Pico breakout board with attached LEDs, SD-Card and so on. I've also got various AVR boards where I've upgraded the loader so that it retains the cause of the last reset, which can be read via a C++ variable. However I don't know whether FPC has the capability of declaring that a (global) variable should retain its value rather than being initialised at startup. A similar consideration applies to the RP2040: I've not yet seen anybody demonstrate how the chip's distinctive PIOs can be programmed from FPC. I think that what I'm building up to is that while both the RP2040 and sundry AVRs (plus lots of other chips) can undoubtedly be programmed using FPC, I've got reservations as to whether it's really the right tool for the job in view of the amount of effort that the wider community has devoted to getting them working well with C++. MarkMLl ---------------------------------------------------------------------- d.ioannidis · 2022-08-03 09:45 Hi,   an atmega avr could do the job easily.   You can have an RTC also if you can solder, and make the circuit in a zero/veroboard pcb, running at 4MHz. Of course you'll need a programmer but you can use an arduino uno / mini nano for that task or buy a USBasp or USBisp which are very cheap . regards, ---------------------------------------------------------------------- marcov · 2022-08-03 09:53 Quote from: MarkMLl on August 03, 2022, 11:32:56 amI've also got various AVR boards where I've upgraded the loader so that it retains the cause of the last reset, which can be read via a C++ variable. However I don't know whether FPC has the capability of declaring that a (global) variable should retain its value rather than being initialised at startup. (From similar functionality with dspics, I'd say that is a implementation specific attribute. FPC supports generic attributes, but what they do (placement in a block that isn't zeroed on startup) still will have to implemented) ---------------------------------------------------------------------- MarkMLl · 2022-08-03 10:16 Quote from: marcov on August 03, 2022, 11:53:17 amQuote from: MarkMLl on August 03, 2022, 11:32:56 amI've also got various AVR boards where I've upgraded the loader so that it retains the cause of the last reset, which can be read via a C++ variable. However I don't know whether FPC has the capability of declaring that a (global) variable should retain its value rather than being initialised at startup. (From similar functionality with dspics, I'd say that is a implementation specific attribute. FPC supports generic attributes, but what they do (placement in a block that isn't zeroed on startup) still will have to implemented) (Skipping the "TBD" bit): yes, agreed. Looking at my notes, the AVR format is Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /* * If possible, retrieve the reset reason. On an Arduino, Optiboot >=4.6 will save  * this into r2 and then clear MCUSR, other architectures might have something * similar. In all cases assume that interpretation of the value is target-specific, * but on an AVR are likely to be some combination of *  *      0x10  JTAG reset *      0x08  Watchdog reset *      0x04  Brownout reset *      0x02  External (button) reset *      0x01  Power-on reset */unsigned char _reset_reason __attribute__ ((section (".noinit"))); void getMCUSR(void) __attribute__((naked)) __attribute__((section(".init0"))); void getMCUSR(void){   __asm__ __volatile__ ( "mov %0, r2 \n" : "=r" (_reset_reason) : );}  /* This needs a runtime test that Optiboot is at at least version 4.6. If not * valid then as a side-effect the saved reason will be set to an "impossible" * value. */bool trustResetReason(void) {  if (pgm_read_word(0xfffe) >= 0x0406)    return true;  else {    _reset_reason = 0xff; // Not a valid combination    return false;  }  } ...       if (trustResetReason()) { // Needs runtime test against Optiboot version.        Serial.print(FF(" Reset: 0x"));        board_info_hex2(_reset_reason);      } However, I think the bigger point here is that the broader community has organised things such that this sort of thing can be done fairly painlessly on an AVR. They've also arranged things such that PIO programming can be done close to (if not interleaved with) the C++ on an RP2040, while my understanding is that the best that FPC can offer is "stick it into a resource and call the preprocessor using Lazarus" (which is also what we're told is an adequate alternative to embedding SQL blocks in Pascal). MarkMLl ---------------------------------------------------------------------- ccrause · 2022-08-03 11:22 Quote from: MarkMLl on August 03, 2022, 12:16:19 pmQuote from: marcov on August 03, 2022, 11:53:17 amQuote from: MarkMLl on August 03, 2022, 11:32:56 amI've also got various AVR boards where I've upgraded the loader so that it retains the cause of the last reset, which can be read via a C++ variable. However I don't know whether FPC has the capability of declaring that a (global) variable should retain its value rather than being initialised at startup. (From similar functionality with dspics, I'd say that is a implementation specific attribute. FPC supports generic attributes, but what they do (placement in a block that isn't zeroed on startup) still will have to implemented) (Skipping the "TBD" bit): yes, agreed. Looking at my notes, the AVR format is Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /* * If possible, retrieve the reset reason. On an Arduino, Optiboot >=4.6 will save  * this into r2 and then clear MCUSR, other architectures might have something * similar. In all cases assume that interpretation of the value is target-specific, * but on an AVR are likely to be some combination of *  *      0x10  JTAG reset *      0x08  Watchdog reset *      0x04  Brownout reset *      0x02  External (button) reset *      0x01  Power-on reset */unsigned char _reset_reason __attribute__ ((section (".noinit"))); void getMCUSR(void) __attribute__((naked)) __attribute__((section(".init0"))); void getMCUSR(void){   __asm__ __volatile__ ( "mov %0, r2 \n" : "=r" (_reset_reason) : );}  /* This needs a runtime test that Optiboot is at at least version 4.6. If not * valid then as a side-effect the saved reason will be set to an "impossible" * value. */bool trustResetReason(void) {  if (pgm_read_word(0xfffe) >= 0x0406)    return true;  else {    _reset_reason = 0xff; // Not a valid combination    return false;  }  } ...       if (trustResetReason()) { // Needs runtime test against Optiboot version.        Serial.print(FF(" Reset: 0x"));        board_info_hex2(_reset_reason);      } However, I think the bigger point here is that the broader community has organised things such that this sort of thing can be done fairly painlessly on an AVR. They've also arranged things such that PIO programming can be done close to (if not interleaved with) the C++ on an RP2040, while my understanding is that the best that FPC can offer is "stick it into a resource and call the preprocessor using Lazarus" (which is also what we're told is an adequate alternative to embedding SQL blocks in Pascal). MarkMLl I think this conversation is drifting away from the OP, but anyway, here is the FPC way (putting code in a section requires main version for now): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  resetReason: byte; section '.noinit'; procedure getMCUSR; assembler; noreturn; section '.init1';asm  sts resetReason, r2end; begin  Halt(resetReason);end. ---------------------------------------------------------------------- d.ioannidis · 2022-08-03 11:37 Hi, Quote from: ccrause on August 03, 2022, 01:22:15 pmI think this conversation is drifting away from the OP, but anyway, here is the FPC way (putting code in a section requires main version for now):  I remembered seeing this here https://github.com/ccrause/freepascal/wiki/Better-support-for-address- spaces-in-FPC#section-support-for-procedures  Maybe it should be in fpc avr wiki ? regards, ---------------------------------------------------------------------- MarkMLl · 2022-08-03 11:58 Quote from: Dimitrios Chr. Ioannidis on August 03, 2022, 01:37:12 pmI remembered seeing this here https://github.com/ccrause/freepascal/wiki/Better-support-for-address- spaces-in-FPC#section-support-for-procedures Maybe it should be in fpc avr wiki ? In any event, it should specify what versions of the compiler support it, i.e. "Requires a minimum of FPC 3.x.y targetting z and t". MarkMLl ---------------------------------------------------------------------- AlanTheBeast · 2022-08-03 14:25 Quote from: MarkMLl on August 03, 2022, 11:32:56 amNoted your comment about at least starting off with an Arduino-scale breakout board, but when you say "smallest/lightest" do you literally mean "small" as in some fraction of a mm2 and "light" as in mg? In any event, even if small etc. should be interpreted as "limited memory and cheap", you are likely to find that your scale is dominated by considerations of how tolerant the MCU chip (and attached peripherals) is to varying supply voltage, whether the chip/board can supply adequate power to supply the peripherals without an external regulator and so on. Language is fun. I meant "smallest/lightest" as in a little board that will do what I need it to do.  Arduino size would be fine.  Slightly larger or smaller would be fine. I'll throw (a) nice power suppl(ies)y at it. Thx. ---------------------------------------------------------------------- AlanTheBeast · 2022-08-03 14:29 Thanks everyone for all the replies.  I'll begin my research.  Key thing (which Dimitrios Chr. Ioannidis touched on) is programming it once the image is built... ---------------------------------------------------------------------- d.ioannidis · 2022-08-03 15:25 Hi, Quote from: AlanTheBeast on August 03, 2022, 04:29:00 pmKey thing (which Dimitrios Chr. Ioannidis touched on) is programming it once the image is built... All the suggestions above ( arduino uno / nano, esp32, rp pico, etc ), can be programmed "out-of-box", as they aleady have the supporting hardware and/or firmware. I was talking about the case, you maybe want to use an mcu with your own minimal homemade board i.e. From Arduino to a Microcontroller on a Breadboard. regards, ---------------------------------------------------------------------- MarkMLl · 2022-08-03 15:27 Quote from: AlanTheBeast on August 03, 2022, 04:25:56 pmI meant "smallest/lightest" as in a little board that will do what I need it to do.  Arduino size would be fine.  Slightly larger or smaller would be fine. Waveshare RP2040-Zero or equivalent, AVR-based Digispark clone, or depending on the precise number of inputs you need an Arduino Nano or larger. If you have two RP2040 boards you can use one as a Picoprobe, which can handle both loading and debugging. Otherwise there's a button that boots the RP2040 chip looking like a disc drive, and you just get your host OS to copy the firmware file onto it. Most Arduinos (except possibly the Nano) have a USB serial interface and preprogrammed loader firmware. However you have to jump through hoops to get a debugging interface. Beware of the "Blue Pill" which is normally shipped without a bootloader, so you need either an ST-Link adapter or something else that implements the SWD 3-wire bus (e.g. a Picoprobe, but I've not tried this combination). Also beware that even though it might appear to be good value, there's a vast number of elderly "Blue Pill" boards with a bad resistor in the USB circuit, meaning that you've got to start messing around with a soldering iron before you have any real chance of programming it over USB. For my money, the Pico+Picoprobe combination takes some beating. But I do have reservations about the RP2040 chip itself, since its USP (apart from price) is its PIO subsystems... which are great provided that you have a use for them (in the same way that the low-level processing hardware on a BeagleBone was great if you had a use for them) but for the vast majority of people will turn out to be a "solution looking for a problem" which they don't have. MarkMLl ---------------------------------------------------------------------- Edson · 2022-08-04 18:09 Not FPC, but my compiler https://github.com/t-edson/PicPas supports the more ridiculous minimalistic PIC microcontrollers like the PIC10F200. ---------------------------------------------------------------------- AlanTheBeast · 2022-08-04 18:46 Quote from: Edson on August 04, 2022, 08:09:39 pmNot FPC, but my compiler https://github.com/t-edson/PicPas supports the more ridiculous minimalistic PIC microcontrollers like the PIC10F200. At that level I'd probably just write it in assembler or the company C. I do like that device.  But probably too lean for the application and I'd have to add peripherals to that to do what I need to do. Thx! ---------------------------------------------------------------------- AlanTheBeast · 2022-08-04 18:54 Quote from: Dimitrios Chr. Ioannidis on August 03, 2022, 05:25:54 pmHi, Quote from: AlanTheBeast on August 03, 2022, 04:29:00 pmKey thing (which Dimitrios Chr. Ioannidis touched on) is programming it once the image is built... All the suggestions above ( arduino uno / nano, esp32, rp pico, etc ), can be programmed "out-of-box", as they aleady have the supporting hardware and/or firmware. I was talking about the case, you maybe want to use an mcu with your own minimal homemade board i.e. From Arduino to a Microcontroller on a Breadboard. Ah.  Got it. It would be cool to program the device and make a literal breadboard ... indeed that would fit in with the end goal of the project. I have a lot of green "bread" boards in 0.1" (2.54mm) pitch in various sizes as well. Thanks! ---------------------------------------------------------------------- MarkMLl · 2022-08-04 19:55 Quote from: AlanTheBeast on August 04, 2022, 08:54:43 pmIt would be cool to program the device and make a literal breadboard ... indeed that would fit in with the end goal of the project. You'd find the electrical characteristics of wood to be incompatible with modern electronics. The days are long gone when you could screw a couple of bits of tin can down, put a length of pencil between them, and call it a precision resistor... MarkMLl ---------------------------------------------------------------------- winni · 2022-08-04 20:30 Quote from: MarkMLl on August 04, 2022, 09:55:29 pmYou'd find the electrical characteristics of wood to be incompatible with modern electronics. Hi Not  a big trick. The main parameters are: * moisture content * type of wood (oak or balsa?) further * humidity * temperature That's all Coming soon: Eco resistors made from wood ... Winni ---------------------------------------------------------------------- funlw65 · 2022-09-21 07:01 Quote from: AlanTheBeast on August 04, 2022, 08:46:17 pmQuote from: Edson on August 04, 2022, 08:09:39 pmNot FPC, but my compiler https://github.com/t-edson/PicPas supports the more ridiculous minimalistic PIC microcontrollers like the PIC10F200. At that level I'd probably just write it in assembler or the company C. I do like that device.  But probably too lean for the application and I'd have to add peripherals to that to do what I need to do. Thx! Apart of the @Edson's  PicPas solution which is not FPC but is a Lazarus project and a Pascal language non the less, there is another free Pascal solution which programs from PIC12F to the fat-est PIC18F, named Pic Micro Pascal. Both of them program families of microcontrollers not supported by FPC. Both well optimized.  If your choice is AVR (ATmega, ATtiny) then the only free, non-limited Pascal compiler might be FreePascal but, if you can use BASIC instead, there is Great Cow Basic compiler that manages both PICs and AVRs with better results. Back to PICs, Jalv2 compiler (JAL language, similar to ADA?) and Great Cow Basic have always support for the latest (most recent) PIC microcontroller with a great library of functions for all the internal peripherals and a plethora of external devices, with tons of application examples. And great communities. If you want to try PIC24 and dsPIC33 families (which sometimes are a better choice than many ARM counterparts), then the best solution is Firewing Basic (similar to Visual Basic language) - free and non- limited (it converts BASIC to C language which is then compiled by a full featured C compiler, delivered in the package). You can have access to more PIC24 and dsPIC33 micros (otherwise I would have recommended other BASIC compilers) than are included in the package, but you have to develop your own libraries. Regardless, you have access to a free, fully optimized solution. Regarding FPC, I would recommend you to experiment with a cheap Nucleo STM32 board, even if overkill for your project. It has a programmer on board and enough FLASH memory for your programs. In my view, is a better solution than a Pico. Yeah, in my opinion, a Nucleo board is best suited for FPC. Support? I think the STM32 family is the best represented... ---------------------------------------------------------------------- marcov · 2022-09-21 07:37 Or just do C till FPC is ready.  As I have done with various pic18F and then later dspics (F,E,C) over the years. ---------------------------------------------------------------------- d.ioannidis · 2022-09-21 08:32 IMHO, the FPC for AVR compiler currently faces the classic problem. No users ( or no feedback ) -> no need/care for AVR development and no development -> no more users interested .... . It seems to me that the FPC embedded users are not a large group ( or not too loud ). Quote from: marcov on September 21, 2022, 09:37:11 amOr just do C till FPC is ready.  As I have done with various pic18F and then later dspics (F,E,C) over the years.  In git main the AVR part has progressed, IMO, and I'm expecting that the fpc 3.2 fixes release, it'll be a decent, stable, and capable AVR compiler. Also, AFAIU, the only person that pushes Free Pascal AVR development forward is ccrause. If one cares/wants to use Free Pascal for AVR it should at least report bugs, make tutorials, or post some projects made, to show that there is interest and help spread the word, that FPC for AVR is, for simple projects at least, a viable option. ---------------------------------------------------------------------- marcov · 2022-09-21 09:10 Florian has originally done the AVR port and is still regularly committing to it. But maybe more the compiler ---------------------------------------------------------------------- d.ioannidis · 2022-09-21 09:29 Quote from: marcov on September 21, 2022, 11:10:32 amFlorian has originally done the AVR port and is still regularly committing to it. But maybe more the compiler Quote from: Dimitrios Chr. Ioannidis on September 21, 2022, 10:32:42 amAlso, AFAIU, the only person that pushes Free Pascal AVR development forward is ccrause. I forgot to add the word, currently, in the above sentence ... Apologies !  AFAIU, Florian ( and Laksen ) fixes things as they are known to them . That's why I mentioned that bug reporting is very helpful,  in my previous post . ---------------------------------------------------------------------- Thaddy · 2022-09-21 09:54 Quote from: Dimitrios Chr. Ioannidis on September 21, 2022, 10:32:42 amIMHO, the FPC for AVR compiler currently faces the classic problem. No users ( or no feedback ) -> no need/care for AVR development and no development -> no I think it has more to do with the nature of AVR type projects which is often/mostly hardware control. In my case, if I get a project working (hard- and software), I will leave it alone. (mostly robotica and miniature railway control, I have a huge set of Jouef, the base dating from Christmas 1961 (1962 catalogue), when I was three years old.) In my case, I only do one or two projects a year. Maybe that goes for many programmers. The point is that even the users use the AVR compiler sporadically. So therefor feedback is also sporadically. Can that be the case? ---------------------------------------------------------------------- funlw65 · 2022-09-21 11:11 Quote from: marcov on September 21, 2022, 09:37:11 amOr just do C till FPC is ready. ... dspics (F,E,C) over the years. FPC for dsPICs ... that would be awesome. There is an open source assembler for PIC24 and dsPICs, with it's own particularities... If FPC could generate the required assembler file, FPC for dsPIC can become a reality much sooner than waiting for it to directly generate a proper .HEX file... I'm talking about naken_asm assembler/disassembler from here:  https://github.com/mikeakohn/naken_asm It supports a lot of micros... ---------------------------------------------------------------------- PascalDragon · 2022-09-21 11:48 Quote from: funlw65 on September 21, 2022, 01:11:27 pmFPC for dsPICs ... that would be awesome. There is an open source assembler for PIC24 and dsPICs, with it's own particularities... If FPC could generate the required assembler file, FPC for dsPIC can become a reality much sooner than waiting for it to directly generate a proper .HEX file... The assembler itself is usually not the problem and the assembler doesn't need to be open source to be usable. The main point of work is the code generator backend and that is always the biggest part. ---------------------------------------------------------------------- funlw65 · 2022-09-21 11:57 Not to clear in my mind, but the author has also a "java grinder", it writes the program in java then it has a tool (if I correctly understood) that produces assembler from the class bytecode? ---------------------------------------------------------------------- dseligo · 2022-09-21 22:02 Quote from: Thaddy on September 21, 2022, 11:54:45 amIn my case, I only do one or two projects a year. Maybe that goes for many programmers. The point is that even the users use the AVR compiler sporadically. So therefor feedback is also sporadically. Can that be the case? I agree, I have similar experience, although I'd like to work with AVR more, it's fun. ---------------------------------------------------------------------- MarkMLl · 2022-09-22 06:08 Quote from: Thaddy on September 21, 2022, 11:54:45 amI think it has more to do with the nature of AVR type projects which is often/mostly hardware control. In my case, if I get a project working (hard- and software), I will leave it alone. (mostly robotica and miniature railway control, I have a huge set of Jouef, the base dating from Christmas 1961 (1962 catalogue), when I was three years old.) In my case, I only do one or two projects a year. Maybe that goes for many programmers. The point is that even the users use the AVR compiler sporadically. So therefor feedback is also sporadically. Can that be the case? Or one-off industrial hacks and so on. MarkMLl ---------------------------------------------------------------------- avra · 2022-09-22 13:14 Quote from: funlw65 on September 21, 2022, 09:01:20 amIf your choice is AVR (ATmega, ATtiny) then the only free, non-limited Pascal compiler might be FreePascalNo. For quite some time E-Lab's AvrCo Multitasking Pascal is free and unlimited, and still a better option for AVR then FPC. https://www.e-lab.de/downloads/AVRco/rev4/index.html ---------------------------------------------------------------------- funlw65 · 2022-09-24 20:38 Thank you @avra, that means that the most recent version is free? ---------------------------------------------------------------------- avra · 2022-09-25 21:58 Quote from: funlw65 on September 24, 2022, 10:38:42 pmThank you @avra, that means that the most recent version is free?Yes, and development is not stopped. However, online debugging is available only with original debugger/programmer which just old users have - but you can flash hex file with any other AVR programmer.