Nvs encryption in ESP32 using arduino IDE

Hi all,
I want to use encrypted NVS region in the esp32.
The program works fine in ESP-IDF, but when I translate it to arduino IDE I find these LOCs give error :

    err = nvs_flash_read_security_cfg(partition, &cfg);
    if (err != ESP_OK) {
        ESP_LOGE(nvs_tag, "Failed to read nvs keys (rc=0x%x)", err);
        err = ESP_ERR_NVS_CORRUPT_KEY_PART;
        return err;
    }

    // 3. initialize nvs partition
    err = nvs_flash_secure_init(&cfg);
    if (err != ESP_OK ) {
        ESP_LOGE(nvs_tag, "failed to initialize nvs partition (err=0x%x). Aborting.", err);
        return err;
    };

nvs_flash_secure_init && nvs_flash_read_security_cfg give error.
On further inspection I found that the arduino-esp32 core doesn’t has these functions compiled within the libnvs_flash.a library.
Is there a way out to use these functions there?
Or can we compile and link all the libraries separately and put them under tools/lib folder in ArduinoData folder?
Thanks

Technically one can recompile the ESP-IDF base libs for Arduino-ESP32 using GitHub - espressif/esp32-arduino-lib-builder with whatever options you like enabled.

But remember PlatformIO is still only at 2.0.1 with the latest version, and not 2.0.2. Have you tried it in the Arduino IDE first?

When we compile any project in IDF, it also generates the static libs, under the build/esp-idf folder.
I tried using that with the arduino IDE, but it gave several errors. All of them are related to dependencies.
the libnvs_flash.a from IDF needed some functions which are not present in the existing arduino setup.

Btw what is https://github.com/espressif/esp32-arduino-lib-builder it used for?
I couldn’t make much from the doc. Does it maps the dependencies and then creates the binary?

Did you use the exact ESP-IDF version as indicated in the commit history History for tools/sdk/esp32/lib - espressif/arduino-esp32 · GitHub?

hey, I got the libs working with arduino as an ESP-iDF component.
But now another error creeped up
I can’t use the default BLE library of the arduino. I tried to compile the default example but it gave error :

/home/ubuntu/hello/main/BLE.cpp:312:24: error: 'pCharacteristicName' was not declared in this scope
     BLECharacteristic *pCharacteristicName = pService->createCharacteristic(
                        ^~~~~~~~~~~~~~~~~~~
esp-idf/main/CMakeFiles/__idf_main.dir/build.make:75: recipe for target 'esp-idf/main/CMakeFiles/__idf_main.dir/hello.cpp.obj' failed
make[2]: *** [esp-idf/main/CMakeFiles/__idf_main.dir/hello.cpp.obj] Error 1
make[2]: *** Waiting for unfinished jobs....
/home/ubuntu/hello/main/BLE.cpp:314:11: error: 'BLECharacteristic' is not a class, namespace, or enumeration
           BLECharacteristic::PROPERTY_READ
           ^~~~~~~~~~~~~~~~~
/home/ubuntu/hello/main/BLE.cpp:317:24: error: 'pCharacteristicType' was not declared in this scope
     BLECharacteristic *pCharacteristicType = pService->createCharacteristic(
                        ^~~~~~~~~~~~~~~~~~~
/home/ubuntu/hello/main/BLE.cpp:319:11: error: 'BLECharacteristic' is not a class, namespace, or enumeration
           BLECharacteristic::PROPERTY_READ
           ^~~~~~~~~~~~~~~~~
/home/ubuntu/hello/main/BLE.cpp:322:5: error: 'pCharacteristic

only a part has been pasted here.
Do we need to do something else to get the default libs working?

If you’re using ESP-IDF now instead of PIO + ESP-IDF/Arduino, the people at espressif should be able to help you – I have no further clues about that error except “something” in the BLE menuconfig might be wrong → GitHub - espressif/esp-idf: Espressif IoT Development Framework. Official development framework for Espressif SoCs.

Thanks for the guide!