idf-eclipse-plugin icon indicating copy to clipboard operation
idf-eclipse-plugin copied to clipboard

'Run As'/Execute program with varargs (IEP-192)

Open rherrmannr opened this issue 5 years ago • 3 comments

Hey , is there a way to execute the program using varargs?

I've changed the app_main function to:

void app_main(int argc, char **argv) {
}

and hoped to use the varargs.

Adding arguments to the run config does not work.. varargs as the python script seems to expect files:

/home/rherrmann/.espressif/python_env/idf4.0_py2.7_env/bin/python: can't open file '192.168.0.1': [Errno 2] No such file or directory

I couldn't find anything in the sdkconfig file.

rherrmannr avatar May 27 '20 08:05 rherrmannr

@igrr @projectgus - Can we pass the arguments to the app_main(..)? Could you please help on this.

kolipakakondal avatar May 29 '20 05:05 kolipakakondal

Hi @rherrmannr, in ESP-IDF the app_main function is called without arguments, you can see the call here: https://github.com/espressif/esp-idf/blob/7d75213674b4572f90c68162ad6fe9b16dae65ad/components/esp32/cpu_start.c#L580

When the program runs on the ESP32, it is loaded and executed by the bootloader, the process is explained here. At this point, there is no communication between the ESP32 and the PC, other than that the ESP32 logs some of the events to the serial console.

Generally there can be two ways to pass arguments to the application (although not to app_main function, as its signature doesn't include any arguments):

  1. pass the arguments from the PC
  2. store the arguments in Flash and let the program read them

The first option can be implemented in a couple of ways:

  1. JTAG semihosting, where the application executes a semihosting call to the PC, requesting the argument list. We do support semihosting (example), but don't yet support the specific semihosting call used to fetch function arguments. I'll file that as a feature request in ESP-IDF.
  2. Reading the arguments from UART: on startup, the application can read the argument list from UART, and then split the line into arguments. This can be done using a console, or by reading the line manually and calling the esp_console_split_argv function.

The second option (storing the arguments in Flash) can be implemented using the NVS component. You can first use the NVS partition generator utility to generate a partition binary with the required key-value pairs inside, flash the partition binary into the device, and then read the values from your program at run time.

Unfortunately, all of these options are more involved than just adding launch arguments in Eclipse.

igrr avatar May 29 '20 06:05 igrr

Thanks for the detailed instructions. I‘ll try it!

rherrmannr avatar May 29 '20 06:05 rherrmannr