Page 1 of 1

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

Posted: Thu Jun 29, 2023 8:22 am
by ThomasESP32
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

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

Posted: Thu Jun 29, 2023 8:41 am
by a2800276
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

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

Posted: Tue Jul 04, 2023 2:40 pm
by ThomasESP32
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 ?

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

Posted: Wed Jul 05, 2023 11:43 pm
by ESP_igrr
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