esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
411 stars 26 forks source link

Custom board file support #2370

Open olicooper opened 1 year ago

olicooper commented 1 year ago

Describe the problem you have/What new integration you would like

Sometimes the predefined board options are not suitable and some parameters need to be changed. Platformio allows the use of custom board files (see: https://docs.platformio.org/en/latest/platforms/creating_board.html). esphome does not support custom board files, but I have done some testing and I can get it working quite easily. esphome warns if the board is unknown with the message This board is unknown, please set the variant manually (see: components/esp32/init.py#L280)

My suggestion is to check if the board exists, and if it doesn't then check the variant is configured and that a custom board file can be found, then copy that file to the build directory...

I have written the following code for the esp32 platform which does everything required to get the board file to the build directory. This should be placed here: components/esp32/init.py#L526

board = CORE.data[KEY_ESP32][CONF_BOARD]
if CORE.data[KEY_ESP32][CONF_VARIANT] and board not in BOARDS:
    board_path = Path(f"boards/{board}.json")
    if board_path.is_file():
        _LOGGER.info(
            f"Loading custom board file: boards/{board}.json"
        )
        copy_file_if_changed(
            CORE.relative_config_path(f"boards/{board}.json"),
            CORE.relative_build_path(f"boards/{board}.json"),
        )
#    else:
#        raise cv.Invalid(
#            f"This board is unknown, please add a custom board file in the 'boards' folder: 'boards/{board}.json'",
#            path=[CONF_BOARD],
#        )

Please describe your use case for this integration and alternatives you've tried:

I would like to configure options like the maximum_ram_size but it is not possible with the current configuration options e.g.

platformio_options: 
    # like this..
    upload_flags: maximum_ram_size=532480
    # or this..
    upload_flags.maximum_ram_size: 532480

Additional context

nickolay commented 8 months ago

Using the esphome CLI I can set PLATFORMIO_BOARDS_DIR environment variable to the directory containing the custom board JSON.

For the home assistant add-on I think it would be better to support specifying URLs of the custom board JSON.