ESP32-WROVER. Support for external RAM, strange build error!

My platformio.ini

src_dir = main
lib_dir = components
description = ESP32-Radiola

[env:esp-wrover-kit]
platform = https://github.com/platformio/platform-espressif32.git
board = esp-wrover-kit
framework = espidf
monitor_speed = 115200
monitor_flags = 
	--echo
	--raw
board_build.partitions = partitions.csv
build_flags = 
	-D FILENAME=ESP32Radiola
;	-mfix-esp32-psram-cache-issue
	-DCONFIG_SPIRAM_CACHE_WORKAROUND
	-Iinclude
	-Icomponents/audio_player/src
	-Icomponents/tda7313
	-Icomponents/fifo/src
	-Icomponents/ucglib/src
	-Icomponents/xpt2046
extra_scripts = pre:extra_script.py

If I add the -DCONFIG_SPIRAM_CACHE_WORKAROUND flag to support extended memory, I get this error:

  File "C:\users\alexander\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 167:
    env.SConscript(item, exports="env")
  File "C:\Users\Alexander\.platformio\packages\tool-scons\scons-local-4.0.1\SCons\Script\SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\Alexander\.platformio\packages\tool-scons\scons-local-4.0.1\SCons\Script\SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "D:\WORK\ESP-IDF\ESP32-Radiola\extra_script.py", line 4:
    defines =  { k:  v for (k,  v)  in my_flags.get("CPPDEFINES")}
  File "D:\WORK\ESP-IDF\ESP32-Radiola\extra_script.py", line 4:
    defines =  { k:  v for (k,  v)  in my_flags.get("CPPDEFINES")}

What am I doing wrong?
It is also very strange that ESP32-CAM has support for extended memory by default,

  "build": {
    "arduino":{
      "ldscript": "esp32_out.ld"
    },
    "core": "esp32",
    "extra_flags": "-DARDUINO_ESP32_DEV -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue",
    "f_cpu": "240000000L",
    "f_flash": "40000000L",
    "flash_mode": "dio",
    "mcu": "esp32",
    "partitions": "huge_app.csv",
    "variant": "esp32"
  },
  "connectivity": [
    "wifi",
    "bluetooth",
    "ethernet",
    "can"
  ],
  "debug": {
    "openocd_board": "esp-wroom-32.cfg"
  },
  "frameworks": [
    "arduino",
    "espidf"
  ],
  "name": "AI Thinker ESP32-CAM",
  "upload": {
    "flash_size": "4MB",
    "maximum_ram_size": 327680,
    "maximum_size": 4194304,
    "require_upload_port": true,
    "speed": 460800
  },
  "url": "https://wiki.ai-thinker.com/esp32-cam",
  "vendor": "AI Thinker"
}

while ESP32-WROWER still does not.

{
  "build": {
    "arduino":{
      "ldscript": "esp32_out.ld"
    },
    "core": "esp32",
    "extra_flags": "-DARDUINO_ESP32_DEV",
    "f_cpu": "240000000L",
    "f_flash": "40000000L",
    "flash_mode": "dio",
    "hwids": [
      [
        "0x0403",
        "0x6010"
      ]
    ],
    "mcu": "esp32",
    "variant": "esp32"
  },
  "connectivity": [
    "wifi",
    "bluetooth",
    "ethernet",
    "can"
  ],
  "debug": {
    "default_tool": "ftdi",
    "onboard_tools": [
      "ftdi"
    ],
    "openocd_board": "esp32-wrover.cfg"
  },
  "frameworks": [
    "arduino",
    "espidf"
  ],
  "name": "Espressif ESP-WROVER-KIT",
  "upload": {
    "flash_size": "4MB",
    "maximum_ram_size": 327680,
    "maximum_size": 4194304,
    "protocols": [
      "esptool",
      "espota",
      "ftdi"
    ],
    "require_upload_port": true,
    "speed": 460800
  },
  "url": "https://espressif.com/en/products/hardware/esp-wrover-kit/overview",
  "vendor": "Espressif"
}

This is nonsense.

Your script attempts to decode every entry in CPPDEFINES as a tuple of (k,v). For defines like -DMY_MACRO=VALUE it works, you get ("MY_MACRO", "VALUE") as a result. Since you have however added -DCONFIG_SPIRAM_CACHE_WORKAROUND it will result in just the string "CONFIG_SPIRAM_CACHE_WORKAROUND ", which python cannot decode in (k,v). Thus it fails, which is correct.

Correct the script you have placed in

by taking care that CPPDEFINES may not only contain tuples. See e.g. Change name of firmware file - #10 by maxgerhardt.

1 Like