Ada for xtensa esp32 (LX6/LX7) [DRAFT!]

I have built a cross-compiler for xtensa-esp32-elf. Several members of the telegram channel expressed interest in supporting Ada on this platform. I spent some time and built a toolchain using Alire’s scripts. Fabian then accepted my changes and this compiler is now available in the community index. Porting bareboard runtimes is still to come. If you are interested, join the telegram channel or leave your comments on the forum here.

  • If you want install the toolchain, run alr toolchain --select gnat_xtensa_esp32_elf

  • Beside toolchain you need a xtensa-dynconfig plugin:

git clone https://github.com/jcmvbkbc/xtensa-dynconfig
git -C xtensa-dynconfig clone https://github.com/espressif/xtensa-overlays config
make -C xtensa-dynconfig
export XTENSA_GNU_CONFIG=$PWD/xtensa-dynconfig/xtensa_esp32s3.so
  • I’ve made a patch to bb-runtimes to make it simpler somebody to start working on the run time. If you want to try:
git clone -b esp32 https://github.com/reznikmm/bb-runtimes/
cd bb-runtimes
./build_rts.py --output=$HOME/.local/share/alire/toolchains/gnat_xtensa_esp32_elf_14.2.1_f8471bd4/xtensa-esp32-elf/lib/gnat --build esp32 --rts-src-descriptor ./gnat_rts_sources/lib/gnat/rts-sources.json

# Optionaly rebuild rts with debug info:

gprbuild -P $HOME/.local/share/alire/toolchains/gnat_xtensa_esp32_elf_14.2.1_f8471bd4/xtensa-esp32-elf/lib/gnat/light-esp32/runtime_build.gpr -XBUILD=Debug
  • Now you can try to build hello world and get linker errors, because some/many files are missing:
gprbuild --target=xtensa-esp32-elf --RTS=light-esp32 -P examples/hello-light/hello.gpr

Links:

3 Likes

Will this work with an ESP32-WROOM-32? I just saw it on sale at AZ-Delivery :hugs:

ESPRESSIF does not recommend it for new projects https://www.espressif.com/sites/default/files/documentation/esp32-wroom-32_datasheet_en.pdf It is a rather old CPU by now. However, it has an Xtensa CPU, so it should work with the toolchain :slight_smile: It is probably under discount in order to get rid of extra inventory.

Newer CPUs/Boards include the ESP32-C6, C3, S3, etc :slight_smile:

1 Like

It should work in theory, but right now nobody ports Ada runtime for esp32. We have only compiler.

1 Like

Please excuse my ignorance (I’m trying to learn :upside_down_face: )…

What does not having an available runtime mean and does it apply to all ESP32 boards?

Does it mean you can’t use any Ada library code and you need to do programming on pure bare metal?

What is required to port an Ada runtime for ESP32? Just wondering if it’s something I could take on, for didactic reasons, or if it’s totally over my head for now :sweat_smile:

Thanks a lot and best regards,

Alexis.

It mean that our toolchain for ESP32 is incomplete. We have only compiler, but not runtime (for any board). So with the compiler one could starting porting Ada runtime and build it: get libgnat.a and a bunch of *.ali file from runtime source files. Yje having compiler and runtime anyone could build and link an Ada application.

Without runtime you can’t compile any user’s compilation unit (package/subprogram), because it depends on Standard package that is part of runtime. During compilation the compiler reads System package to find target properties. In turn, runtime comes in several types. light runtime is most thin and most easy to port. It provides only basic support, you won’t be able to use tasks, protected object, but you can build an application. light-tasking runtime has support of tasks/protected object with some restrictions (See Ravenscar profile). To get full Ada you need full Ada runtime, that is very big and probably requires real OS underneath.

Porting runtime could be an interesting and you could find out mush about how it works. From my point of view it is not hard, at least for light runtime. You will need to find out

  • compiler flags for your particular chip
  • flash layout to create a linker script
  • number and names of interrupts to write interrupt vector (in assembly)
  • create a starter assembly chunk to initialize stack, clean bss memory section

Some links:

Don’t hesitate to ask questions! :+1:

1 Like

Adding info to what Maxim just linked, the AdaCore blog has quite a few posts about this topic:

2 Likes