Classic ESP32: GPIO17 is not needed to be reserved for chips with in-package PSRAM#5338
Classic ESP32: GPIO17 is not needed to be reserved for chips with in-package PSRAM#5338wled-install wants to merge 2 commits intowled:mainfrom
Conversation
WalkthroughRefined ESP32 pin validation in the pin manager: GPIO16 now uses a direct PSRAM absence check; GPIO17 gains a chip-model branch permitting it on ESP32-D0WDR2-V3 while other variants follow PSRAM-based rules. Other pin behaviors remain unchanged. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Failure to add the new IP will result in interrupted reviews. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I think we need more testing with classic esp32 that have psram, to confirm that pin17 is only allowed when the board supports it. The test can be quite simple
I have a wrover-b and a lilygo-t7 with psram in my collection, but I'll need a few days before I can test. If anybody else has another classic esp32 with PSRAM, please feel invited to test. Edit:
|
|
@softhack007 Actually in my tests only WLED 0.16.x works reliable with PSRAM, 0.15.x (if not esp-idf4 used) crashes whatever I do. |
@wled-install yes for all the 3 boards in my collection the change is safe.
same here - I never got any PSRAM boards working with the old "AC" framework. It seems that PSRAM boards always need a V4 build. |
|
I have one classic WROVER, not sure which model. will check. |
@DedeHai side-discussion: My understanding is:
-> psramFound() == false might also indicate that support is available (BOARD_HAS_PSRAM), but PSRAM is not working -> For PIN allocation, relying on psramFound() might be dangerous in one case: a broken PSRAM chip does not mean you can use PSRAM pins freely bool ARDUINO_ISR_ATTR psramFound(){
return spiramDetected;
}
void ARDUINO_ISR_ATTR *ps_malloc(size_t size){
if(!spiramDetected){
return NULL;
}
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
}
void initArduino()
{
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
psramInit();
#endifstatic volatile bool spiramDetected = false;
bool psramInit(){
if (spiramDetected) {
return true;
}
#ifndef CONFIG_SPIRAM_BOOT_INIT
if (spiramFailed) {
return false;
}
#if CONFIG_IDF_TARGET_ESP32
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
uint32_t pkg_ver = chip_ver & 0x7;
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) {
spiramFailed = true; // <-- HERE check failed
log_w("PSRAM not supported!");
return false;
}
#elif CONFIG_IDF_TARGET_ESP32S2
extern void esp_config_data_cache_mode(void);
esp_config_data_cache_mode();
Cache_Enable_DCache(0);
#endif
if (esp_spiram_init() != ESP_OK) {
spiramFailed = true; // <-- HERE check failed
log_w("PSRAM init failed!");
#if CONFIG_IDF_TARGET_ESP32
if (pkg_ver != EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) {
pinMatrixOutDetach(16, false, false);
pinMatrixOutDetach(17, false, false);
}
#endif
return false;
}
esp_spiram_init_cache();
//testSPIRAM() allows user to bypass SPI RAM test routine
if (!testSPIRAM()) {
spiramFailed = true; // <-- HERE check failed
log_e("PSRAM test failed!");
return false;
}
if (esp_spiram_add_to_heapalloc() != ESP_OK) {
spiramFailed = true; // <-- HERE check failed
log_e("PSRAM could not be added to the heap!");
return false;
}
#if CONFIG_SPIRAM_USE_MALLOC && !CONFIG_ARDUINO_ISR_IRAM
heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL);
#endif
#endif /* CONFIG_SPIRAM_BOOT_INIT */
log_i("PSRAM enabled");
spiramDetected = true; // <-- HERE all checks passed
return true;
}
|
|
my info may be outdated, at the time (few months ago), I think it was discussed several times but no conclusion reached: if PSRAM is enabled on ESP32, it also requires that compile fix to support the chips with that silicon bug. I am not sure on the best way to solve it in general (not this PR). Ideally we would have one single build for all ESP32 classic variants, no matter if it has PSRAM or not, I am not aware of all pitfalls for that though. |
Fix for #5334
Edit (softhack007): The change relies on the framework knowing about the "ESP32-D0WDR2-V3" chip model - available since arduino-esp32 v2.0.7. It means that only "V4" builds will allow using GPIO17. WLED 0.15.3 is still using the older framework, only WLED 0.16 will be able to detect the "ESP32-D0WDR2-V3" chip properly.
Summary by CodeRabbit