Recent

Author Topic: Setting up Xtensa-FreeRTOS for ESP8266  (Read 29822 times)

botster

  • New Member
  • *
  • Posts: 39
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #30 on: January 14, 2022, 07:45:00 pm »
While re-reading the instructions, I see the following line which I must have glossed over before thinking I had read that a version of FPC greater than 3 was required (which I probably read somewhere else).
Quote
A native FPC development branch ("main" in git; formerly "trunk" in svn) must be installed and working on the system and will be used to compile the xtensa cross compiler.

Is using a development branch version to compile ppcrossxtensa absolutely necessary? If so, how would I accomplish that?

Xtensa support is only available in the development branch (main).  It probably would be included in fpc 3.4, but that is still a long way away.

Yes, I understand that. That is not what I was asking.

That particular sentence could be read to mean that a working compiler from the development branch must be installed and working prior to following the instructions on the page. It is not clear that will be accomplished through following the instructions. But, what you stated later on in your reply ("If you start make from the root of the trunk source folder, it will start by building a native compiler using the starting stable compiler, then use the trunk native compiler to compile the cross compiler.") clarified that and answered my questions. I did not need to use fpcupdeluxe to install a trunk version of FPC and use that to follow along.


Quote
I'm starting to suspect your problem is not really a compiler problem, but perhaps something odd with the SDK libraries you are using.  I have tested your compiled blink, it doesn't appear to reach the main entry point of the FPC program.  Will try to perform some debugging, but that is very flaky on the esp8266...

I've set up the toolchain and SDK for the ESP32 also and tried with that. The 'hello world' example works, but the FPC 'hello' program does not. It seems unlikely there would be odd issues with both SDKs. But, I don't discount that possibility.

So, I re-installed the 8266 toolchain and SDK making sure to specify the SDK v3.4 branch as Andreas noted. After recompiling and flashing 'hello' and 'blink'; still no joy.


I used OpenOCD to debug your blink running on an esp8266.  It was clear that the boot process got stuck in an exception after loading the application from flash, but before reaching the Pascal main.
[snip]

Since the executions does not reach FPC code, the problem is most probably in the bootloader code linked in from the SDK libraries.  My guess is that the startup code does not properly initialize the CPU state.

Thank you for taking the time to do that.

There are a couple things I do not understand about this:
1. Why does the 'hello world' example work but a FPC program does not with the very same bootloader?
2. Since I did not share my bootloader image, you must have used your own. So, wouldn't that mean the issue is also present in yours as well? Or, am I missing something?
Lee

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #31 on: January 14, 2022, 10:39:14 pm »
I've set up the toolchain and SDK for the ESP32 also and tried with that. The 'hello world' example works, but the FPC 'hello' program does not. It seems unlikely there would be odd issues with both SDKs. But, I don't discount that possibility.

I agree, seems very unlikely...

Quote
So, I re-installed the 8266 toolchain and SDK making sure to specify the SDK v3.4 branch as Andreas noted. After recompiling and flashing 'hello' and 'blink'; still no joy.
That sucks, but must be fixable somehow...

Quote
I used OpenOCD to debug your blink running on an esp8266.  It was clear that the boot process got stuck in an exception after loading the application from flash, but before reaching the Pascal main.
[snip]

Since the executions does not reach FPC code, the problem is most probably in the bootloader code linked in from the SDK libraries.  My guess is that the startup code does not properly initialize the CPU state.

Thank you for taking the time to do that.

There are a couple things I do not understand about this:
1. Why does the 'hello world' example work but a FPC program does not with the very same bootloader?
2. Since I did not share my bootloader image, you must have used your own. So, wouldn't that mean the issue is also present in yours as well? Or, am I missing something?
My reference to the bootloader code is not quite accurate.  The problem occurs after the bootloader jumps into the application image, so it is the startup code of the application that generates the exception, not the bootloader itself.

If you can zip and share the SDK library folder with the .a, .ld and sdkconfig files you used to link your fpc example, I can compare that against my copies. Also relink an example against your libraries to see if the issue is repeatable on a different machine.

botster

  • New Member
  • *
  • Posts: 39
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #32 on: January 14, 2022, 11:29:32 pm »
If you can zip and share the SDK library folder with the .a, .ld and sdkconfig files you used to link your fpc example, I can compare that against my copies. Also relink an example against your libraries to see if the issue is repeatable on a different machine.

I am unsure what exactly you mean by, "SDK library folder." I would think you mean the 'xtensa-lx106-elf-libs' folder that I created according to the instructions, but that has no 'sdkconfig' file. I can certainly copy sdkconfig to that dir before I zip it.

Regarding relinking an example, would you like the .bin, .o, and .elf (w/ or without debug info?) files? And, shall I do hello.pas since it is simpler?
Lee

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #33 on: January 15, 2022, 08:00:05 am »
If you can zip and share the SDK library folder with the .a, .ld and sdkconfig files you used to link your fpc example, I can compare that against my copies. Also relink an example against your libraries to see if the issue is repeatable on a different machine.

I am unsure what exactly you mean by, "SDK library folder." I would think you mean the 'xtensa-lx106-elf-libs' folder that I created according to the instructions, but that has no 'sdkconfig' file. I can certainly copy sdkconfig to that dir before I zip it.

Regarding relinking an example, would you like the .bin, .o, and .elf (w/ or without debug info?) files? And, shall I do hello.pas since it is simpler?

Yes, I meant 'xtensa-lx106-elf-libs' folder.  The sdkconfig file is in the root of the SDK example, produced during the Preparations step of the wiki instructions. It is not required for linking, but shows all the options configured when the "hello world" example was build.

I was thinking of just compiling my own FPC example, but for completeness you can also add your FPC hello.pp and compiled hello.o and hello.elf files.  Set debug info to Dwarf3, this helps when disassembling.  Note that adding debug info only affects the produced .elf size - the debug info is not carried over to the .bin image that is flashed to the controller.

Another test is if you download the SDK files I use: https://github.com/ccrause/fpc-esp-freertos/blob/master/snapshot/fpc-esp8266-idf-3.4-20220107.zip
Extract this zip file for example to "~/eDevel/Embedded/esp/fpc-esp8266-idf-3.4" and recompile your FPC example:
Code: Text  [Select][+][-]
  1. ~/eDevel/Embedded/esp/8266/fpc/compiler/ppcrossxtensa -Fu~/eDevel/Embedded/esp/8266/fpc/rtl/units/xtensa-freertos/ -Tfreertos -XPxtensa-lx106-elf- -O3 -Wpesp8266 -WP3.4 -Fl~/eDevel/Embedded/fpc-esp8266-idf-3.4/libs -Fl~/eDevel/Embedded/esp/xtensa-lx106-elf/xtensa-lx106-elf/lib blink -gw3 -Ff~/eDevel/Embedded/fpc-esp8266-idf-3.4 blink

Checking compiler and tools versions. Mine:
Code: [Select]
~/fpc/gitlab-cc/compiler/ppcrossxtensa -iWD
3.3.1 2022/01/10

~/xtensa/xtensa-lx106-elf/bin/xtensa-lx106-elf-ld -v
GNU ld (crosstool-NG esp-2020r3-49-gd5524c1) 2.31.1

Hopefully after this it will be clear where the problem is, or at least produce a working example on your side.

botster

  • New Member
  • *
  • Posts: 39
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #34 on: January 15, 2022, 09:09:07 pm »
Okay. The following is what is included in the Zip file.

- My 'xtensa-lx106-elf-libs' folder including sdkconfig copied from the hello_world example
- A 'hello' project folder built with Espressif's SDK (including, FWIW, the bootloader and partition images)
- A 'hello2' project folder built with your SDK (which, unfortunately, hangs at the very same spot after loading the app image)

Since, when you previously requested an ELF file with debug info, you specified optimization level 1, I changed your code-quoted compiler command from "-O3" to "-O1" figuring it was merely an oversight.

Notes on changes to sdkconfig from default:
Bootloader config -> Bootloader log verbosity (Verbose)
Serial flasher config -> Flash size (4 MB)

I left the flash and monitor baud rates at default (115200 & 74880, respectively).

hello build:
Code: [Select]
#hello> ~/eDevel/Embedded/esp/8266/fpc/compiler/ppcrossxtensa -Fu~/eDevel/Embedded/esp/8266/fpc/rtl/units/xtensa-freertos/ -Tfreertos -XPxtensa-lx106-elf- -O1 -gw3 -Wpesp8266 -WP3.4 -Fl~/eDevel/Embedded/esp/xtensa-lx106-elf-libs -Fl$IDF_PATH/components/esp8266/lib -Fl~/eDevel/Embedded/esp/xtensa-lx106-elf/xtensa-lx106-elf/lib hello
Free Pascal Compiler version 3.3.1 [2022/01/13] for xtensa
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: FreeRTOS
Compiling hello.pas
Assembling hello
Linking hello
esptool.py v2.4.0
5 lines compiled, 2.7 sec, 105266 bytes code, 68 bytes data

hello2 build:
Code: [Select]
#hello2> ~/eDevel/Embedded/esp/8266/fpc/compiler/ppcrossxtensa -Fu~/eDevel/Embedded/esp/8266/fpc/rtl/units/xtensa-freertos/ -Tfreertos -XPxtensa-lx106-elf- -O1 -Wpesp8266 -WP3.4 -Fl~/eDevel/Embedded/esp/fpc-esp8266-idf-3.4/libs -Fl~/eDevel/Embedded/esp/xtensa-lx106-elf/xtensa-lx106-elf/lib -gw3 hello
Free Pascal Compiler version 3.3.1 [2022/01/13] for xtensa
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: FreeRTOS
Compiling hello.pas
Assembling hello
Linking hello
esptool.py v2.4.0
5 lines compiled, 2.0 sec, 111562 bytes code, 68 bytes data
(I had to remove the framework option to get it to link; otherwise it complained about not finding linker script file esp8266.peripherals.ld)

My compiler and tools versions:
Code: [Select]
#> 8266/fpc/compiler/ppcrossxtensa -iWD
3.3.1 2022/01/13
#> xtensa-lx106-elf/bin/xtensa-lx106-elf-ld -v
GNU ld (crosstool-NG esp-2020r3-49-gd5524c1) 2.31.1

Edit: I forgot to mention that my sdkconfig has the USB path set to ttyUSB1.
« Last Edit: January 15, 2022, 09:26:48 pm by botster »
Lee

botster

  • New Member
  • *
  • Posts: 39
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #35 on: January 17, 2022, 12:43:46 am »
Well ... I found something that works*. Use Debian (or probably any Debian-based distro).

* At least I think it worked. Is it expected to see "_haltproc called, exit code: 0" on the monitor after "Hello world" is written?

I tried a "live" Debian ISO image after trying a "live" Fedora image with no success.

Now the question is:
Why does it work on Debian 11.2.0 but won't work on Fedora 35 or openSUSE Leap 15.3?
Lee

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #36 on: January 17, 2022, 10:01:25 pm »
Well ... I found something that works*. Use Debian (or probably any Debian-based distro).
I'm using a Debian derivative (Linux Mint)...

Quote
* At least I think it worked. Is it expected to see "_haltproc called, exit code: 0" on the monitor after "Hello world" is written?
Yes, that is correct.  Your simple hello program calls writeln, then exits. The default RTL action when your Pascal program exits main is to write the exit code (0 = no error). I am glad you finally got some output!

Quote
I tried a "live" Debian ISO image after trying a "live" Fedora image with no success.

Now the question is:
Why does it work on Debian 11.2.0 but won't work on Fedora 35 or openSUSE Leap 15.3?
No idea.  Just as I am none the wiser after trying to debug your executables.

botster

  • New Member
  • *
  • Posts: 39
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #37 on: January 18, 2022, 01:52:38 am »
Yes, I did get some output, finally! Unfortunately for me, it's not worth switching to Debian or any of its flavors.

There is a difference in the ELF files (the Debian-generated/working and the openSUSE-generated/non-working) that I find interesting. The deb/working ELF has only 3 program segments/sections. The other has 4. That section is listed as a NOTE and has the very same offset and address as section 01 (the iram section).

Code: [Select]
user@linux-desktop:~/deb/esp/hello> readelf -l hello.elf

Elf file type is EXEC (Executable file)
Entry point 0x40212c5c
There are 3 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0x3ffe8000 0x3ffe8000 0x00634 0x01dc0 RW  0x1000
  LOAD           0x002000 0x40100000 0x40100000 0x04783 0x04990 RWE 0x1000
  LOAD           0x007010 0x40210010 0x40210010 0x1f388 0x1f388 RWE 0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .data .dram0.data .dram0.bss
   01     .iram0.vectors .iram0.text .iram0.bss
   02     .flash.text .flash.rodata

Code: [Select]
user@linux-desktop:~/eDevel/Embedded/esp/hello> readelf -l hello.elf

Elf file type is EXEC (Executable file)
Entry point 0x40212fa4
There are 4 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0x3ffe8000 0x3ffe8000 0x00634 0x01dc0 RW  0x1000
  LOAD           0x002000 0x40100000 0x40100000 0x047a3 0x049b0 RWE 0x1000
  LOAD           0x007010 0x40210010 0x40210010 0x1f22c 0x1f22c RWE 0x1000
  NOTE           0x002000 0x40100000 0x40100000 0x00024 0x00024 R   0x4

 Section to Segment mapping:
  Segment Sections...
   00     .data .dram0.data .dram0.bss
   01     .note.gnu.build-id .iram0.vectors .iram0.text .iram0.bss
   02     .flash.text .flash.rodata
   03     .note.gnu.build-id

I don't understand enough about what I'm looking at there to know if that means anything. So, I'll have to leave it there.

Thank you, ccrause, for your help and patience.  :)
Lee

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #38 on: August 17, 2022, 04:49:05 am »
hello friend, i did on windows using latest fpcupdeluxe, open blink sample from ccrause github, i got following wrong ppu error, how to eliminate this problem?

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #39 on: August 17, 2022, 07:57:18 am »
hello friend, i did on windows using latest fpcupdeluxe, open blink sample from ccrause github, i got following wrong ppu error, how to eliminate this problem?

As a quick test add -Cfhard to your project's Custom Options tab and check if the compiler loads the system unit.

The second line of the output you showed indicates that the RTL system unit was compiled with an FPU setting different from your project build settings. To fix this error requires that the initial build mode used by fpcupdeluxe to build the compiler and RTL and the build mode used by your project should match (specifically the FPU mode set by the command line option -Cf). Can you show the build settings in Lazarus (Project > Project Options > Show Options) and also the fpc.cfg file generated by fpcupdeluxe?

Also, can you re-install the xtensa cross compiler and copy the build log - this will show the FPU mode specified for the RTL.

This will be a lot of information, you can attach it as files to a reply to this thread.

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #40 on: August 18, 2022, 01:14:12 am »
Thank you ccrause, this one is my following fpc setting
« Last Edit: August 18, 2022, 01:18:24 am by Mongkey »

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #41 on: August 18, 2022, 08:02:49 am »
I suspect there is a subtle bug in fpcupdeluxe. By default fpcupdeluxe installs both the lx6 and lx106 sub architectures (esp32 & esp8266 respectively), but does not add the -Cfhard compiler option when compiling the lx6 RTL:
/home/christo/fpcupdeluxe/working/fpc/bin/x86_64-linux/ppcrossxtensa -Cplx6 -Ur -Tfreertos -Pxtensa -XPxtensa-esp32-elf- -Ur -Xs -O2 -n -Fi../inc -Fi../xtensa -FD/home/christo/fpcupdeluxe/working/cross/bin/xtensa-freertos/bin -FE. -FU/home/christo/fpcupdeluxe/working/fpcsrc/rtl/units/xtensa-freertos -vw-n-h-l-d-u-t-p-c- -dxtensa -dRELEASE -WP4.3.2 -XPxtensa-esp32-elf- -Xd -Fl/home/christo/fpcupdeluxe/working/cross/lib/xtensa-freertos/lx6  -Us -Sg system.pp @system.cfg

To fix this, reinstall the xtensa cross compiler, but click on Setup+, click on the Subarch tab, select lx6 and add -Cfhard to Cross Build Options Override, click OK and click on Install cross-compiler.  See attached picture.
 
After building the cross compiler, scroll up in the output view and verify that -Cfhard was added to the compiler command when building the cross RTL:
/home/christo/fpcupdeluxe/working/fpc/bin/x86_64-linux/ppcrossxtensa -Cplx6 -Ur -Tfreertos -Pxtensa -XPxtensa-esp32-elf- -Ur -Xs -O2 -n -Fi../inc -Fi../xtensa -FD/home/christo/fpcupdeluxe/working/cross/bin/xtensa-freertos/bin -FE. -FU/home/christo/fpcupdeluxe/working/fpcsrc/rtl/units/xtensa-freertos -vw-n-h-l-d-u-t-p-c- -dxtensa -dRELEASE -Cfhard -WP4.3.2 -XPxtensa-esp32-elf- -Xd -Fl/home/christo/fpcupdeluxe/working/cross/lib/xtensa-freertos/lx6  -Us -Sg system.pp @system.cfg

If this fixes your problem, this should be reported so that fpcupdeluxe can be improved.
« Last Edit: August 18, 2022, 08:09:37 am by ccrause »

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #42 on: August 18, 2022, 11:11:41 am »
thanks ccrause for your help, but it still got error result. i try open another sample.
« Last Edit: August 18, 2022, 11:31:44 am by Mongkey »

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #43 on: August 18, 2022, 02:07:56 pm »
thanks ccrause for your help, but it still got error result. i try open another sample.
At least you have progressed to a new error :).

From the compiler output it is clear that linking failed because some files could not be located (a linker script and some esp-idf libraries).  Can you search for the following files in your fpcupdeluxe folder and show the full paths (these are the Linux names, hopefully it is the same in Windows):
  • libesp_hw_support.a
  • esp32.ld
  • esp32.project.ld

The problem may simply be that the fpc.cfg file is pointing to the wrong folders - if so it is easy to fix.

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: Setting up Xtensa-FreeRTOS for ESP8266
« Reply #44 on: August 19, 2022, 02:02:27 am »
at which folder of this fpc.cfg must be change? i already to include that containing folder via project option but no luck  :)
« Last Edit: August 19, 2022, 03:40:41 am by Mongkey »

 

TinyPortal © 2005-2018