Esp32S3 : How to place environment variables in a ESP-IDF project ?

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Esp32S3 : How to place environment variables in a ESP-IDF project ?

Postby ThomasESP32 » Thu Jun 29, 2023 8:22 am

Good morning,

I am using ESP-IDF in order to program an Esp32S3 chip.
I would like to place environment variables in my project so that I can use them in my firmware.

For example, I would like to define a "PROJECT_VERSION = 10" environment variable
and use it in the program.

Could you please help me to do it ?
Best regards,

Thomas TRUILHE

a2800276
Posts: 78
Joined: Sat Jan 23, 2016 1:59 pm

Re: Esp32S3 : How to place environment variables in a ESP-IDF project ?

Postby a2800276 » Thu Jun 29, 2023 8:41 am

You can add custom 'menuconfig' pages containing options/macro definitions you can access from code. Is that what you are looking for?

https://docs.espressif.com/projects/esp ... figuration

Or are you looking to include Unix shell environment variables a'la `-D$(ENV_VAR)` ? I assume you'd just need to pass those in as compiler flags:

https://docs.espressif.com/projects/esp ... ompilation

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Re: Esp32S3 : How to place environment variables in a ESP-IDF project ?

Postby ThomasESP32 » Tue Jul 04, 2023 2:40 pm

No sorry this is not what I want.

I can see that in Eclipse, in the Run, Run Configuration Menu, and in Environment tab,
I can device some environment variables with their values.

Here is can define for example : SOFTWARE_VERSION = 1.0.0.0.1

However, I do not know, how to access to them into my firmware.
Do you have any idea ?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Esp32S3 : How to place environment variables in a ESP-IDF project ?

Postby ESP_igrr » Wed Jul 05, 2023 11:43 pm

There's likely a better solution than environment variables for storing the software version (for example: IDF can automatically determine project version from Git tags). However if you have decided to use environment variables, you can pass their values to the compiler as described in this thread: viewtopic.php?f=13&t=30196

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], MicroController and 76 guests