Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSRAM stops working when importing arduino-esp32 into ESP-IDF. Flag CONFIG_SPIRAM becomes undefined when BOARD_HAS_PSRAM is not set. #10500

Open
1 task done
cjdell opened this issue Oct 22, 2024 · 8 comments
Assignees
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@cjdell
Copy link

cjdell commented Oct 22, 2024

Board

Xiao ESP32-S3 Sense

Device Description

Xiao ESP32-S3 Sense connected to PC with USB-C

Hardware Configuration

Just USB-C to PC

Version

latest master (checkout manually)

IDE Name

VSCode

Operating System

NixOS

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

460800

Description

Unfortunately my PSRAM stopped working as soon as I started using the arduino-esp32 component. This code literally undefines the CONFIG_SPIRAM and CONFIG_SPIRAM_SUPPORT flag out of existence:

https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-psram.h#L29

There is no way to override them back. I even tried defining BOARD_HAS_PSRAM as a build flag but it hasn't worked. I haven't found docs on how to set global builds flags nor is there any information on the BOARD_HAS_PSRAM flag and any explanation as to why it exists when we already have flags in sdkconfig for those.

Manually removing lines 24-31 in esp32-hal-psram.h will get PSRAM working again but this is an uncomfortable workaround.

Thanks

Sketch

#include <Arduino.h>

void setup()
{
  delay(2000);

  // DOES NOT WORK WITHOUT "BOARD_HAS_PSRAM" WHICH IS NOT DEFINED !!!
#if CONFIG_SPIRAM
  ESP_LOGI("main", "CONFIG_SPIRAM DEFINED");
#else
  ESP_LOGI("main", "CONFIG_SPIRAM ** NOT ** DEFINED");
#endif

  ESP_LOGI("main", "PSRAM Size: %i", (int)ESP.getPsramSize());
}

void loop()
{
}

Debug Message

No CONFIG_SPIRAM defined
PSRAM reports 0 bytes (incorrect)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@cjdell cjdell added the Status: Awaiting triage Issue is waiting for triage label Oct 22, 2024
@cjdell
Copy link
Author

cjdell commented Oct 22, 2024

Better workaround for now, add the following line to CMakeLists.txt in the root of your project:

add_compile_options(-DBOARD_HAS_PSRAM=1)

This may just be a documentation issue. It would be great to have the docs clarified when using arduino-esp32 directly via the ESP-IDF and not via the Arduino IDE.

@me-no-dev
Copy link
Member

You should not define BOARD_HAS_PSRAM yourself. All you need to do is control it through menuconfig and it will work

@me-no-dev
Copy link
Member

Ahh you are correct... need to do some tests

@me-no-dev
Copy link
Member

@cjdell fix is coming here. You will need to remove add_compile_options(-DBOARD_HAS_PSRAM=1) once it's applied

@me-no-dev
Copy link
Member

Unfortunately the proposed fix will break many libraries PlatformIO projects. I suspect that documenting the necessity to add add_compile_options(-DBOARD_HAS_PSRAM) to the project would be the only way to go.

@me-no-dev
Copy link
Member

BTW this code has been as-is for a very long time. You are the first to notice the issue

me-no-dev added a commit that referenced this issue Oct 22, 2024
me-no-dev added a commit that referenced this issue Oct 22, 2024
@cjdell
Copy link
Author

cjdell commented Oct 22, 2024

Thanks for the quick turnaround. I'm surprised using the ESP-IDF directly with the desire to use abundant Arduino libraries is not more common

Documentation seems the best way to go. Also on how to apply custom build flags in general as there is no info on that (that I can see).

@me-no-dev
Copy link
Member

I think I found a way that changes nothing in Arduino and does not delete the defines when using as component. Change is minimal and differentiates wether the prebuilt libs are used (Arduino IDE, PlatformIO) and if so it has the old behavior, else does not change anything. You can see it here if you want to try: 1833eeb

me-no-dev added a commit that referenced this issue Oct 22, 2024
* fix(psram): Do not disable PSRAM when used as component

Information: #10500

* IDF release/v5.3 59550599
me-no-dev added a commit that referenced this issue Oct 22, 2024
* fix(psram): Do not disable PSRAM when used as component

Information: #10500

* IDF release/v5.1 Update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants