1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-15 15:20:27 +01:00

add pyocd upload

This commit is contained in:
Tomasz Duda 2024-02-19 22:05:44 +01:00
parent 348b090258
commit b9163b4f70
4 changed files with 6 additions and 110 deletions

View File

@ -48,7 +48,7 @@ from esphome.util import (
get_serial_ports,
)
from esphome.log import color, setup_log, Fore
from .zephyr_tools import smpmgr_upload, list_pyocd
from .zephyr_tools import smpmgr_upload
_LOGGER = logging.getLogger(__name__)
@ -97,17 +97,9 @@ def choose_upload_log_host(
# )
if default == "SERIAL":
return choose_prompt(options, purpose=purpose)
pyocd = list_pyocd()
if len(pyocd) > 0:
for probe in list_pyocd():
options.append(
(
f"pyOCD {probe['product_name']} ({probe['unique_id']})",
f"pyocd {probe['unique_id']}",
)
)
if default == "PYOCD":
return choose_prompt(options, purpose=purpose)
if default == "PYOCD":
options = [("pyocd", "PYOCD")]
return choose_prompt(options, purpose=purpose)
if (show_ota and "ota" in CORE.config) or (show_api and "api" in CORE.config):
options.append((f"Over The Air ({CORE.address})", CORE.address))
if default == "OTA":
@ -350,9 +342,8 @@ def upload_program(config, args, host):
raise EsphomeError(f"Unknown target platform: {CORE.target_platform}")
if host.startswith("pyocd"):
print(host.split(" ")[1])
raise EsphomeError("Not implemented")
if host == "PYOCD":
return upload_using_platformio(config, host, ["-t", "flash_pyocd"])
if host.startswith("mcumgr"):
firmware = os.path.abspath(

View File

@ -1,88 +0,0 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import (
CONF_ID,
)
from esphome.components.zephyr import zephyr_add_prj_conf, zephyr_add_overlay
fota_ns = cg.esphome_ns.namespace("fota")
FOTAComponent = fota_ns.class_("FOTAComponent", cg.Component)
CONFIG_SCHEMA = cv.All(
cv.Schema(
{
cv.GenerateID(): cv.declare_id(FOTAComponent),
}
).extend(cv.COMPONENT_SCHEMA),
cv.only_on_nrf52,
cv.only_with_zephyr,
)
bt = True
cdc = True
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
zephyr_add_prj_conf("NET_BUF", True)
zephyr_add_prj_conf("ZCBOR", True)
zephyr_add_prj_conf("MCUMGR", True)
zephyr_add_prj_conf("BOOTLOADER_MCUBOOT", True)
zephyr_add_prj_conf("IMG_MANAGER", True)
zephyr_add_prj_conf("STREAM_FLASH", True)
zephyr_add_prj_conf("FLASH_MAP", True)
zephyr_add_prj_conf("FLASH", True)
zephyr_add_prj_conf("MCUBOOT_SHELL", True)
zephyr_add_prj_conf("SHELL", True)
zephyr_add_prj_conf("SYSTEM_WORKQUEUE_STACK_SIZE", 2304)
zephyr_add_prj_conf("MAIN_STACK_SIZE", 2048)
zephyr_add_prj_conf("MCUMGR_GRP_IMG", True)
zephyr_add_prj_conf("MCUMGR_GRP_OS", True)
# echo
zephyr_add_prj_conf("MCUMGR_GRP_OS_ECHO", True)
# for Android-nRF-Connect-Device-Manager
zephyr_add_prj_conf("MCUMGR_GRP_OS_INFO", True)
zephyr_add_prj_conf("MCUMGR_GRP_OS_BOOTLOADER_INFO", True)
zephyr_add_prj_conf("MCUMGR_GRP_OS_MCUMGR_PARAMS", True)
# bt update fails without this
zephyr_add_prj_conf("MCUMGR_GRP_SHELL", True)
# make MTU bigger and other things
zephyr_add_prj_conf("NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUP", True)
# zephyr_add_prj_conf("MCUMGR_TRANSPORT_LOG_LEVEL_DBG", True)
if bt:
zephyr_add_prj_conf("BT", True)
zephyr_add_prj_conf("BT_PERIPHERAL", True)
zephyr_add_prj_conf("MCUMGR_TRANSPORT_BT", True)
# fix corrupted data during ble transport
zephyr_add_prj_conf("MCUMGR_TRANSPORT_BT_REASSEMBLY", True)
if cdc:
zephyr_add_prj_conf("MCUMGR_TRANSPORT_UART", True)
zephyr_add_prj_conf("USB_DEVICE_STACK", True)
zephyr_add_prj_conf("BASE64", True)
zephyr_add_prj_conf("CONSOLE", True)
# needed ?
zephyr_add_prj_conf("SERIAL", True)
zephyr_add_prj_conf("UART_LINE_CTRL", True)
zephyr_add_overlay(
"""
/ {
chosen {
zephyr,uart-mcumgr = &cdc_acm_uart0;
};
};
&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
"""
)
await cg.register_component(var, config)

View File

@ -11,7 +11,6 @@ from smpclient import SMPClient
from smpclient.mcuboot import IMAGE_TLV, ImageInfo, TLVNotFound
from smpclient.requests.image_management import ImageStatesRead, ImageStatesWrite
from smpclient.requests.os_management import ResetWrite
from pyocd.tools.lists import ListGenerator
from smpclient.generics import error, success
from esphome.espota2 import ProgressBar
@ -127,7 +126,3 @@ async def smpmgr_upload(config, host, firmware):
return 1
return 0
def list_pyocd():
return ListGenerator.list_probes()["boards"]

View File

@ -29,8 +29,6 @@ argcomplete>=2.0.0
# for mcumgr
git+https://github.com/tomaszduda23/smp/@f9b85266485062f6a466989e8f59b913cc83b08b
git+https://github.com/tomaszduda23/smpclient/@d25c8035ae2858fd41a106058297b619d58fbcb5
# move to framework?
git+https://github.com/tomaszduda23/pyOCD/@949193f7cbf09081f8e46d6b9d2e4a79e536997e
bleak==0.21.1
pydantic==2.16.2
cbor2==5.6.1