Very bad performance if I compile the example for ESP32-CAM

Hi,

I am trying out an ESP32-CAM.

If I compile the example from:

Using the Arduino IDE performance is acceptable
Using Platformio performance is abismal

How can I check what is causing the difference?

Thanks!

  • Can you clarify how you measure the performance?
  • Can you post a screenshot of the Arduino IDE settings that you use during compilation?
  • What is the exact version of the Arduino-ESP32 core that you use in the Arduino IDE (in the board manager)?
  • What is the platformio.ini that you use?

Thanks for your reply.

When I compile the example in Arduino I get around 15 fps from the camera.
If I import it into Platformio I get 0.2 fps

Screenshots:

[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino
monitor_speed = 115200
board_build.partitions = huge_app.csv

I have also tried adding:
build_flags =
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue

and
lib_extra_dirs = ~/Documents/Arduino/libraries

And neither helped

Hm the only difference I see is that you’ve selected QIO mode and 80MHz flash frequency when the PlatformIO default for the board is DIO and 40 MHz… theoretically that’s a factor 4 in speed (double data lanes and double frequency), but it shouldn’t make a world’s difference if the application isn’t bottle-necked by flash reads. Still, per docs, let’s equalize it.

Add

board_build.flash_mode = qio
board_build.f_flash = 80000000L

to your platformio.ini.

Also the huge_app.csv is already the standard and not needed as an extra directive. The build_flags are also not needed since they are already contained.

Added both and it has the same behaviour. 0.3 fps with Platformio and 15 fps with Arduino :frowning_face:

Thanks for your help

Very interesting. I’m not sure what’s happening here. Different toolchains, different linkage, or different code? But your board manager definitely shows version 1.0.5 of the arduino core which is also what the latest Espressif32 platform is using (you did update the PlatformIO platforms by either using the PIO Home → Platforms GUI or a CLI with pio platform update, right?)

@valeros do you have any idea what might be going on here or can reproduce?

Sadly I don’t have the hardware to test but it might be worth getting.

Yes, I updated Platformio before compiling.

I am very interested in this also. Is there a Platformio Discord server or something similar? Maybe someone with the same hardware can test if they see the same difference?

I suppose there is, because I loaded an official Tasmota webcam firmware on the device, and it also had very bad fps. Tasmota is compiled with Platformio. So the behaviour was seen with code compiled by someone else.

It seems upon further investigation that for some reason my board is not using PS-RAM when compiled with Platformio, and the same code is using PS-RAM when compiled with Arduino.

Any Thoughts?

Maybe has something to do with the libraries that are linked in. But per

it should have the PSRAM activated.

Please file a bug in Issues · platformio/platform-espressif32 · GitHub.

I was comparing the board definitions from Platformio and Arduino and the only thing I can see is:

esp32cam.build.extra_libs=-lc-psram-workaround -lm-psram-workaround

Could these flags be the cause?
How do I use these in Platformio?

Ah indeed, a PR was made yesterday to address this issue in Add PSRAM-specific libs to PlatformIO build script by valeros · Pull Request #4911 · espressif/arduino-esp32 · GitHub

Can you add

platform_packages = 
  framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git

in the platformio.ini to test this latest version?

Success!

That was the problem. I can confirm that the PR fixes my issue

I notified the devs at Update framework-arduinoespressif32 package with hotfixes · Issue #508 · platformio/platform-espressif32 · GitHub regarding this – the 1.0.5 release seems really bumpy though.

Can I add only those two libs using platformio.ini?

Maybe. Try

build_flags = -lc-psram-workaround -lm-psram-workaround

or

build_flags = -Wl,-lc-psram-workaround -Wl,-lm-psram-workaround
1 Like

With both build_flags I get

/xtensa-esp32-elf/bin/ld.exe: cannot find -lc-psram-workaround
/xtensa-esp32-elf/bin/ld.exe: cannot find -lm-psram-workaround

Works for me.

[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino
build_flags = -lc-psram-workaround -lm-psram-workaround
RAM:   [          ]   4.3% (used 14172 bytes from 327680 bytes)
Flash: [=         ]   8.8% (used 275306 bytes from 3145728 bytes)
======================== [SUCCESS] Took 16.90 seconds ========================

And linker flags are

xtensa-esp32-elf-g++ -o .pio\build\esp32cam\firmware.elf -T esp32_out.ld -nostdlib -Wl,-static -u call_user_start_cpu0 -Wl,–undefined=uxTopUsedPriority -Wl,–gc-sections -Wl,-EL -T esp32.project.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.libgcc.ld -T esp32.rom.spiram_incompatible_fns.ld -u ld_include_panic_highint_hdl -u __cxa_guard_dummy -u __cxx_fatal_exception .pio\build\esp32cam\src\user_main.cpp.o -L.pio\build\esp32cam -LC:\Users\Max.platformio\packages\framework-arduinoespressif32\tools\sdk\lib -LC:\Users\Max.platformio\packages\framework-arduinoespressif32\tools\sdk\ld -Wl,–start-group .pio\build\esp32cam\libFrameworkArduinoVariant.a .pio\build\esp32cam\libFrameworkArduino.a -lc-psram-workaround -lm-psram-workaround -lgcc -lapp_trace -llibsodium -lbt -lesp-tls -lmdns -lconsole -ljsmn -lesp_ringbuf -lpthread -ldriver -ldetection -lsoc -lc -lmesh -lwpa2 -ljson -ldl -lwear_levelling -lmicro-ecc -lcoexist -lface_detection -lnvs_flash -lwifi_provisioning -lfr -lnghttp -lesp32 -lnet80211 -lesp_http_server -ltcp_transport -llog -lespnow -lhal -lmqtt -lesp_websocket_client -lesp_http_client -lvfs -lbtdm_app -lapp_update -lpe -lprotocomm -lwps -lsdmmc -lesp_adc_cal -lwpa -lefuse -lcoap -lsmartconfig -limage_util -lspiffs -lulp -lunity -lface_recognition -lesp_https_server -lethernet -lspi_flash -lpp -lexpat -lfatfs -ltcpip_adapter -llwip -lcxx -lfreertos -lesp32-camera -lmbedtls -ldetection_cat_face -lm -lc_nano -lesp_event -lnewlib -lcore -lopenssl -lsmartconfig_ack -lwpa_supplicant -lbootloader_support -lasio -lesp_https_ota -lod -lespcoredump -lheap -lrtc -lprotobuf-c -lfb_gfx -lfreemodbus -lfd -lphy -lxtensa-debug-module -lstdc++ -lc-psram-workaround -lm-psram-workaround -Wl,–end-group

At the end you can see the two flags being injected correctly.

Maybe try and open a CLI and do pio platform update espressif32.

Otherwise fix per platform_packages above.

Or as linked hopefully automatic soon with a package re-release.

Thanks for all your help!