Skip to content

ESP32-S3 board.json USB-CDC build variables ignored #258

@nomakewan

Description

@nomakewan

PROBLEM DESCRIPTION

A clear and concise description of what the problem is.

When defining options related to the USB Mode and CDC engine, the build flags appear to be ignored if I set them as build variables and are only heeded if they are set as explicit extra_flags instead.

If we look at the Arduino core from upstream we can see how these flags should work:

https://github.com/espressif/arduino-esp32/blob/f6b1910e8ba5a9aff99fa00b2133b10f34f85e4f/platform.txt#L80

However, this board definition does not work (instead, CDC defaults to 0):

{
  "build": {
    "arduino": {
      "partitions": "partitions/no_spiffs_16mb.csv",
      "memory_type": "qio_opi"
    },
    "core": "esp32",
    "extra_flags": [
      "-DARDUINO_ESP32S3_DEV",
      "-DARDUINO_RUNNING_CORE=1",
      "-DARDUINO_EVENT_RUNNING_CORE=1",
      "-DBOARD_HAS_PSRAM"
    ],
    "f_cpu": "240000000L",
    "f_flash": "80000000L",
    "flash_mode": "qio",
    "psram_type": "opi",
    "usb_mode": "1",
    "cdc_on_boot": "1",
    "msc_on_boot": "0",
    "dfu_on_boot": "0",
    "hwids": [
      ["0x303A", "0x1001"]
    ],
    "mcu": "esp32s3",
    "variant": "esp32s3"
  },
  "frameworks": ["arduino"],
  "name": "ESP32-S3 N16R8",
  "upload": {
    "flash_size": "16MB",
    "maximum_ram_size": 327680,
    "maximum_size": 16777216,
    "protocol": "esptool",
    "require_upload_port": true,
    "speed": 921600
  },
  "url": "https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf",
  "vendor": "Espressif"
}

This board definition which instead removes the build variables and replaces them with explicit extra_flags works:

{
  "build": {
    "arduino": {
      "partitions": "partitions/no_spiffs_16mb.csv",
      "memory_type": "qio_opi"
    },
    "core": "esp32",
    "extra_flags": [
      "-DARDUINO_ESP32S3_DEV",
      "-DARDUINO_RUNNING_CORE=1",
      "-DARDUINO_EVENT_RUNNING_CORE=1",
      "-DARDUINO_USB_MODE=1",
      "-DARDUINO_USB_CDC_ON_BOOT=1",
      "-DARDUINO_USB_MSC_ON_BOOT=0",
      "-DARDUINO_USB_DFU_ON_BOOT=0",
      "-DBOARD_HAS_PSRAM"
    ],
    "f_cpu": "240000000L",
    "f_flash": "80000000L",
    "flash_mode": "qio",
    "psram_type": "opi",
    "hwids": [
      ["0x303A", "0x1001"]
    ],
    "mcu": "esp32s3",
    "variant": "esp32s3"
  },
  "frameworks": ["arduino"],
  "name": "ESP32-S3 N16R8",
  "upload": {
    "flash_size": "16MB",
    "maximum_ram_size": 327680,
    "maximum_size": 16777216,
    "protocol": "esptool",
    "require_upload_port": true,
    "speed": 921600
  },
  "url": "https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf",
  "vendor": "Espressif"
}

TO REPRODUCE

Steps to reproduce the behavior:

1, Create a custom board definition json that attempts to set build variables such as usb_mode, cdc_on_boot, etc.
2. Build.
3. Upload to ESP32-S3.
4. Connect to terminal and inspect ROM messages, seeing that CDC engine is not set as configured.

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen.

USB-CDC build options should be set correctly at build time when defined as build variables.

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

platform.ini file
non-working board def
working board def

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions