Recent

Author Topic: Need help with FPC and ESP8266 (Cross compiler usage)  (Read 370 times)

rainer

  • Newbie
  • Posts: 5
Need help with FPC and ESP8266 (Cross compiler usage)
« on: December 02, 2025, 09:29:05 am »
Hello,
please let me introduce a bit before talking about my needs:

I am using MikroPascal PRO for PIC since many years and it works great. MikroPascal is designed to give perfect access to all internas of the target MCU, what is essential for writing firmware. I make really heavy use of embedded hardware modules (I2C, SPI, 1-wire, multiple serial, interrupts, PWM, ..., CRTOS). Here MikroPascal does a really good job even on 8-Bit controllers. Usually I use here the upper end of PIC18 with a lot of embedded hardware features (including Ethernet).   
Of course, I could also use PIC32 MCUs and use MikroPascal PRO for PIC32, but MikroElektronika stopped further development of Pascal compilers, so I decided to give FreePascal + ESP8266 a preference, because it features a real RTOS, no "Cooperative RTOS" (CRTOS), too.
As I will never ever touch this Arduino stuff and start with "C",  FreePascal appears to be an excellent alternative. It is free software and I know it from Linux, and it will be available and continually be developed.

So I bought 5 pcs ESP8266 to have some for first steps, and with some help of Christo I got fpcupdeluxe + freertos for ESP8266. installed and running, too.

My current status is:
I am able to write some code writing "Hello world" to the debug output (USB serial), so the compiler and all the tool chain really works.
But writing a "Hello World" definitely is not what I want to do. I want to write firmware for microcontroller controlled devices I build.

My problems:
I have massive problems with using GPIO, I2C, SPI, UART, 1-wire, .... on ESP8266.
In MikroPascal for PIC, accessing embedded hardware modules is extremely easy. Mark the related module(s) and use then the additional procedures/functions afterwards.
In FreePascal (for ESP8266) I am totally lost, because I cannot find any useful documentation on how to do anything. This starts at basic things like accessing GPIO (set directions, write/read levels, ...) and I also have absolutely no idea on how to use i.e. PWM, UART, I2C, 3-wire SPI, 1-wire, A/D converter (if existing at all).
I tried to follow the example on espressif web site showing a "Hello World" which also prints some hardware details), but even this I could not port, FreePascal does not know the type "esp_chip_info_t" (and this is the first line only.)..

I am very sure that I will have to include or import something to make things work, but without a series of running example programs and/or a useful documentation it is almost impossible to get started.

I wrote all of above to give you a picture of my current situation. Any real help is very welcome.

Thank you in advance.

nouzi

  • Sr. Member
  • ****
  • Posts: 323
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

dbannon

  • Hero Member
  • *****
  • Posts: 3647
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Need help with FPC and ESP8266 (Cross compiler usage)
« Reply #2 on: December 02, 2025, 10:34:01 am »
rainer, what you want, and I want, is not just the compiler and tool chain but also the equivalent of FPC RTL, run time library. Christo has done some amazing work getting that compiler going (and the GPIO) but we need more, as you say, I2C, One-Wire, SPI. Thats a very large task, one that would need a huge team to first build and then track as Xtensa updates their tool kit (as they do quite often).

I recognized thats not going happen and, eventually moved over to the dark side, C/C++. Now, there is (at least) two ways to do that, I have taken a softer approach, Arduino !  It seems that Xtensa very actively supports the Arduino port, the ESP chips are massively more powerful that the traditional Arduino ones and I made the transition easily. Its just this one project, I still enjoy programming in Pascal but I need this project !

Arduino provides a usable IDE, online help, excellent documentation and a large user group. Lots and lots of ready t use libraries. I use the ESP32-c3 and ESP32-s3, seems the ESP8266 is supported too.

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

rainer

  • Newbie
  • Posts: 5
Re: Need help with FPC and ESP8266 (Cross compiler usage)
« Reply #3 on: December 02, 2025, 10:38:20 am »
Hello, nouzi.
Thank you for your answer. I had a look into the links, this is not what I need.

My problem is not setting up this fpcupdeluxe toolchain and xtensa-freertos, my problems are at a lots deeper level.

Let me explain:
Usually firmware does some hardware initialization on startup first. Here it defines I/O directions, sets safe defaults, initializes further hardware components connected to the microcontroller and sets there safe defaults, too. 

My problem is:
  • How do I access ESP8266 GPIO ports and set them up? -> How to set their direction (input/output), how to set their leven (high/low) ?
  • Same with higher level things like PWM, I2C,SPI, ....
    How do I assign a PWM signal to a particulat I/O pin of ESP8266, how to I start it up? How do I set the PWM frequency and duty cycle?
    How to run a A/D converter on a particular I/O pin (if A/D is possible at all)?
    How do I include and run i.e. I2C or SPI ?

It is always the how, because I cannot find anything about that.


rainer

  • Newbie
  • Posts: 5
Re: Need help with FPC and ESP8266 (Cross compiler usage)
« Reply #4 on: December 02, 2025, 11:26:13 am »
Hi, Davo

So - hard said - there is currently no working RTL supporting the ESP8266 in FPC.
This is bad news.

Christo indeed did a wonderful job.   :D

But without ability to do all the rest ("control the controller", make it a Microcontroller with focus on controlling external things), this is academic, but not really useful.

Coding in C/C++ is a no-go for me. I don't change to the dark side.  Pascal is far away from C/C++ in both: coding language and RAD. With Pascal you can quickly write rugged code because you have lots harder syntax, while you can do weird things in "C" by accident (a simple typo can be enough). Even this is enough to not even think about using it.

My hope was that there is some kind of wrapper for everything, providing pascal functions and forwards them to the linked C libraries. And I also had the hope that this way I would be able to use the ESP8266 possibly not on its full power, but with almost 100% of its features right now. But this doesn't seem to happen soon.

You mentioned that the problem is with this permanently changing xtensa code and the required manpower to stay up to date...
Well, a simple approach would be to use a frozen copy of it and update it in bigger intervals.  I explicitly chose ESP8266 because I read somewhere that it is is not under further development. Xtensa focuses on ESP32, there are lots of changes, but ESP8266 is "frozen". Based on this, it would be an idea to take their ESP8266 libs (to have a frozen version) and build a RTL around that? For sure more promising than permanently trying to follow their changes.

So I am afraid that I will put this 5 pcs of ESP on ice until FPC reaches a level where it can be really used with them.

I will focus on  Microchip PIC32 MCUs instead. They are also very powerful, come with lots of internal hardware modules, and are also mostly pin-compatible to their 8-bit brothers.  Also I do have MikroPascal PRO for PIC32, it works absolutely identical to  MikroPascal PRO for PIC, so I can code in same way..
It is so sad that I have to go this way.
« Last Edit: December 02, 2025, 11:41:25 am by rainer »

 

TinyPortal © 2005-2018