Custom board JSON file that adds more entries to platformio.ini

Hi I am trying to create a custom board JSON file for the ESP32-C3-DevKitC-02 which uses the WROOM module. I want to use the C3 module on a custom PCB with different pin assignments.

I have successfully done so but after project creation the generated platformio.ini file contains only a few lines, as follows.

[env:esp32-c3-custom-pcb]
platform = espressif32
board = esp32-c3-custom-pcb
framework = arduino

I had some trouble previously which was solved by a very helpful post by maxgerhardt about a toolchain mismatch.. The solution meant I had to paste in some lines into platformio.ini for the project to compile. It looks like this:

[env:esp32-c3-custom-pcb]
platform = espressif32
platform_packages = 
	toolchain-riscv-esp
	framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#master
	platformio/tool-esptoolpy @ ~1.30100
framework = arduino
board = esp32-c3-custom-pcb
board_build.mcu = esp32c3
board_build.partitions = huge_app.csv
board_build.variant = esp32c3wroom_custom
board_build.f_cpu = 160000000L
board_build.f_flash = 80000000L
board_build.flash_mode = qio
board_build.arduino.ldscript = esp32c3_out.ld
build_unflags = 
	-DARDUINO_ESP32_DEV
	-DARDUINO_VARIANT="esp32"
build_flags = 
	-DARDUINO_ESP32C3_DEV
	-DARDUINO_VARIANT="esp32c3wroom_custom"

I was hoping to find out how I can modify the .JSON file so that it automatically adds the additional lines to the platformio.ini file when I create a project based on that board JSON, so I dont have to remember to paste in the code manually.

Specifically the section “platform_packages” and the following 3 package lines.

Also I wonder why when the JSON file contains sections like

  "build": {
    "arduino":{
      "ldscript": "esp32c3_out.ld"
    },
    "core": "esp32",
    "f_cpu": "160000000L",
    "f_flash": "80000000L",
    "flash_mode": "qio",
    "mcu": "esp32c3",
    "variant": "esp32c3wroom_custom"
  }

they are not added to the generated ini file. My full JSON file is as follows:

{
  "_comment": "Based on https://github.com/platformio/platform-espressif32/blob/develop/boards/esp32-c3-devkitm-1.json Goes into /users/[USERNAME]/.platformio/platforms/espressif32/boards/",
  "build": {
    "arduino":{
      "ldscript": "esp32c3_out.ld"
    },
    "core": "esp32",
    "f_cpu": "160000000L",
    "f_flash": "80000000L",
    "flash_mode": "qio",
    "mcu": "esp32c3",
    "variant": "esp32c3wroom_custom"
  },
  "connectivity": [
    "wifi",
    "bluetooth"
  ],
  "debug": {
    "openocd_target": "esp32c3.cfg"
  },
  "frameworks": [
    "arduino",
    "espidf"
  ],
  "name": "Esp32 Custom PCB",
  "upload": {
    "flash_size": "4MB",
    "maximum_ram_size": 327680,
    "maximum_size": 4194304,
    "require_upload_port": true,
    "speed": 460800
  },
  "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitc-02.html",
  "vendor": "Espressif"
}

Thanks for any advice.

Can’t help much with JSON file details, but generally they specify defaults, so if the JSON is properly defined and found, then these defaults don’t need to be repeated in your platformio.ini file.

Is your JSON file placed at boards/esp32-c3-custom-pcb.json in your project directory? I’m not sure about whether dashes are allowed in the name, btw.

PS. See Custom Embedded Boards — PlatformIO latest documentation

1 Like