<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>I was able to compile my first hello world for esp32, however I
      had to patch a few files so that compiling works for 4.0 / 4.1
      Branch of esp-idf</p>
    <p>Florian, can you please have a look at the patches and apply them
      if they are OK?</p>
    <p><font size="-1"><tt>diff --git a/compiler/systems/t_freertos.pas
          b/compiler/systems/t_freertos.pas</tt><tt><br>
        </tt><tt>index 3698f28dc1..a0788751ec 100644</tt><tt><br>
        </tt><tt>--- a/compiler/systems/t_freertos.pas</tt><tt><br>
        </tt><tt>+++ b/compiler/systems/t_freertos.pas</tt><tt><br>
        </tt><tt>@@ -77,7 +77,7 @@ begin</tt><tt><br>
        </tt><tt>      if target_info.system=system_xtensa_freertos then</tt><tt><br>
        </tt><tt>        ExeCmd[1]:='ld -g '+platform_select+' $OPT
          $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES
          '+</tt><tt><br>
        </tt><tt>          '-u call_user_start_cpu0 -u
          ld_include_panic_highint_hdl -u esp_app_desc -u
          vfs_include_syscalls_impl -u pthread_include_pthread_impl -u
          pthread_include_pthread_cond_impl -u
          pthread_include_pthread_local_storage_impl -u
          newlib_include_locks_impl -u newlib_include_heap_impl -u
          newlib_include_syscalls_impl -u newlib_include_pthread_impl -u
          app_main -u uxTopUsedPriority '+</tt><tt><br>
        </tt><tt>-         '-L $IDF_PATH/components/esp_rom/esp32/ld -T
          esp32.rom.newlib-funcs-time.ld '+</tt><tt><br>
        </tt><tt>+         '-L $IDF_PATH/components/esp_rom/esp32/ld '+</tt><tt><br>
        </tt><tt>          '-T esp32.rom.ld -T esp32.rom.libgcc.ld -T
          esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T
          esp32.rom.newlib-funcs.ld '+</tt><tt><br>
        </tt><tt>          '-L . -T esp32_out.ld -T esp32.project.ld '+</tt><tt><br>
        </tt><tt>          '-L $IDF_PATH/components/esp32/ld -T
          esp32.peripherals.ld'</tt><tt><br>
        </tt><tt>@@ -1523,10 +1523,10 @@ begin</tt><tt><br>
        </tt><tt>       { generate linker maps for esp32 }</tt><tt><br>
        </tt><tt>       binstr:='$IDF_PATH/tools/ldgen/ldgen.py';</tt><tt><br>
        </tt><tt>       cmdstr:='--config sdkconfig --fragments
          $IDF_PATH/components/xtensa/linker.lf
          $IDF_PATH/components/soc/linker.lf
          $IDF_PATH/components/esp_event/linker.lf '+</tt><tt><br>
        </tt><tt>-        '$IDF_PATH/components/spi_flash/linker.lf
          $IDF_PATH/components/esp_wifi/linker.lf
          $IDF_PATH/components/lwip/linker.lf
          $IDF_PATH/components/log/linker.lf '+</tt><tt><br>
        </tt><tt>+        '$IDF_PATH/components/spi_flash/linker.lf
          $IDF_PATH/components/esp_wifi/linker.lf
          $IDF_PATH/components/lwip/linker.lf '+</tt><tt><br>
        </tt><tt>         '$IDF_PATH/components/heap/linker.lf
          $IDF_PATH/components/esp_ringbuf/linker.lf
          $IDF_PATH/components/espcoredump/linker.lf
          $IDF_PATH/components/esp32/linker.lf '+</tt><tt><br>
        </tt><tt>        
          '$IDF_PATH/components/esp32/ld/esp32_fragments.lf
          $IDF_PATH/components/freertos/linker.lf
          $IDF_PATH/components/newlib/newlib.lf '+</tt><tt><br>
        </tt><tt>-        '$IDF_PATH/components/app_trace/linker.lf
          $IDF_PATH/components/esp_gdbstub/linker.lf '+</tt><tt><br>
        </tt><tt>+        '$IDF_PATH/components/esp_gdbstub/linker.lf '+</tt><tt><br>
        </tt><tt>         '--input
          $IDF_PATH/components/esp32/ld/esp32.project.ld.in --output
          ./esp32.project.ld --kconfig $IDF_PATH/Kconfig --env-file
          config.env '+</tt><tt><br>
        </tt><tt>         '--libraries-file ldgen_libraries --objdump
          xtensa-esp32-elf-objdump';</tt><tt><br>
        </tt><tt>      
Replace(binstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));</tt><tt><br>
        </tt><tt><br>
        </tt><tt>diff --git a/rtl/freertos/xtensa/esp32.pp
          b/rtl/freertos/xtensa/esp32.pp</tt><tt><br>
        </tt><tt>index 1bc9d3bcf9..e7070e082b 100644</tt><tt><br>
        </tt><tt>--- a/rtl/freertos/xtensa/esp32.pp</tt><tt><br>
        </tt><tt>+++ b/rtl/freertos/xtensa/esp32.pp</tt><tt><br>
        </tt><tt>@@ -22,10 +22,10 @@ unit esp32;</tt><tt><br>
        </tt><tt> {$linklib spi_flash,static}</tt><tt><br>
        </tt><tt> {$linklib app_update,static}</tt><tt><br>
        </tt><tt> {$linklib xtensa,static}</tt><tt><br>
        </tt><tt>-{$linklib esp_timer,static}</tt><tt><br>
        </tt><tt>+//{$linklib esp_timer,static}</tt><tt><br>
        </tt><tt> {$linklib bootloader_support,static}</tt><tt><br>
        </tt><tt> {$linklib pthread,static}</tt><tt><br>
        </tt><tt>-{$linklib soc_esp32,static}</tt><tt><br>
        </tt><tt>+//{$linklib soc_esp32,static}</tt><tt><br>
        </tt><tt> {$linklib hal,static}</tt><tt><br>
        </tt><tt> {$linklib c,static}</tt><tt><br>
        </tt><tt> {$linklib esp_event,static}</tt></font></p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">Am 05.04.20 um 14:50 schrieb Michael
      Ring via fpc-devel:<br>
    </div>
    <blockquote type="cite"
      cite="mid:f0350eec-7842-a98b-5fa7-a2c7fc5ea200@michael-ring.org">Just
      to be sure, from your Path settings it looks like you are using
      esp-idf from the release/v4.0 Branch, correct?
      <br>
      <br>
      Michael
      <br>
      <br>
      Am 04.04.20 um 19:44 schrieb Florian Klämpfl:
      <br>
      <blockquote type="cite">Am 04.04.20 um 16:06 schrieb Christo
        Crause via fpc-devel:
        <br>
        <blockquote type="cite">I'm keen to test the xtensa-freertos
          target, but it seems there are a couple of patches missing
          from trunk.
          <br>
          <br>
          It is possible to build an xtensa cross compiler, but the make
          files doesn't know the xtensa-freertos target. To get the make
          files in rtl  updated, one needs to rebuild fpcmake, edit
          rtl/MakeFile.fpc and add "dirs_freertos=freertos" to the
          target list, then run fpcmake. At this point the the following
          make command proceeds up to sysutils:
          <br>
          make rtl FPC=~/fpc/3.3.1/compiler/ppcrossxtensa
          CPU_TARGET=xtensa OS_TARGET=freertos
          BINUTILSPREFIX=xtensa-esp32-elf-
          <br>
          <br>
          where the following errors crop up:
          <br>
          syssbh.inc(43,41) Error: Identifier not found "Double"
          <br>
          syssbh.inc(49,41) Error: Identifier not found "Single" etc.
          <br>
          <br>
          I trust someone (Florian...) has a working build?
          <br>
          <br>
        </blockquote>
        <br>
        I sent Michael recently some instructions but I am not sure if
        they are still working. As Pierre got qemu-xtensa working I am
        pushing the linux port so we can test more easily the compiler.
        <br>
        <br>
        - install esp-idf and execute
        <br>
          source ~/eps/esp-idf/export.sh
        <br>
          to get the pathes and environment set (namely tools path and
        $IDF_PATH are needed)
        <br>
        - use the lazarus project fpc/compiler/ppcxtens.lpt to build an
        xtensa compiler
        <br>
        - build the rtl (breaks currently at sysutils, doesn't matter):
        <br>
        cd rtl/freertos
        <br>
        make FPC=../../compiler/xtensa/pp  OS_TARGET=freertos
        "OPT=-Cplx6 -Cawindowed -XPxtensa-esp32-elf-" clean all
        <br>
        - build the example hello world program from the esp-idf, copy
        all generated .a into e.g. ~/xtensa-esp32-elf-libs
        <br>
        - create somewhere a hello world program, compile it with
        <br>
        fpc/compiler/xtensa/pp -Fu../rtl/units/xtensa-freertos/
        -Tfreertos -Cawindowed -XPxtensa-esp32-elf- -al -O3 -Wpesp32
        -Fl~/xtensa-esp32-elf-libs
-Fl$HOME/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/lib/
        hello
        <br>
        - get partition-table.bin and bootloader.bin from the
        hello_world example compiled above and copy them into the same
        dir as the compiled hello.bin
        <br>
        - flash with
        <br>
        esptool.py -p /dev/ttyUSB0 -b 460800 --before default_reset
        --after hard_reset --chip esp32  write_flash --flash_mode dio
        --flash_size detect --flash_freq 40m 0x1000 bootloader.bin
        0x8000 partition-table.bin 0x10000 hello.bin
        <br>
        - monitor the output with:
        <br>
        idf_monitor.py  --port /dev/ttyUSB0 hello.elf
        <br>
        <br>
        _______________________________________________
        <br>
        fpc-devel maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
        <br>
        <a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
        <br>
      </blockquote>
      _______________________________________________
      <br>
      fpc-devel maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
      <br>
      <a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
      <br>
    </blockquote>
  </body>
</html>