mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Prefer Black Magic GDB for uploading // Issue #4023
This commit is contained in:
@ -116,6 +116,7 @@ def AutodetectUploadPort(*args, **kwargs):
|
||||
initial_port=initial_port,
|
||||
board_config=env.BoardConfig() if "BOARD" in env else None,
|
||||
upload_protocol=upload_protocol,
|
||||
prefer_gdb_port="blackmagic" in upload_protocol,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -18,7 +18,7 @@ import os
|
||||
from platformio import fs, proc, util
|
||||
from platformio.compat import string_types
|
||||
from platformio.debug.exception import DebugInvalidOptionsError
|
||||
from platformio.device.finder import find_debug_port
|
||||
from platformio.device.finder import find_serial_port, is_pattern_port
|
||||
from platformio.project.config import ProjectConfig
|
||||
from platformio.project.helpers import load_build_metadata
|
||||
from platformio.project.options import ProjectOptions
|
||||
@ -123,10 +123,13 @@ class DebugConfigBase: # pylint: disable=too-many-instance-attributes
|
||||
self.env_options.get("debug_port", self.tool_settings.get("port"))
|
||||
or self._port
|
||||
)
|
||||
port = find_debug_port(
|
||||
if initial_port and not is_pattern_port(initial_port):
|
||||
return initial_port
|
||||
port = find_serial_port(
|
||||
initial_port,
|
||||
self.tool_name,
|
||||
self.tool_settings,
|
||||
board_config=self.board_config,
|
||||
upload_protocol=self.tool_name,
|
||||
prefer_gdb_port=True,
|
||||
)
|
||||
if port:
|
||||
return port
|
||||
|
@ -67,8 +67,13 @@ def is_serial_port_ready(port, timeout=1):
|
||||
return False
|
||||
|
||||
|
||||
def find_serial_port(
|
||||
initial_port, board_config=None, upload_protocol=None, ensure_ready=False, timeout=3
|
||||
def find_serial_port( # pylint: disable=too-many-arguments
|
||||
initial_port,
|
||||
board_config=None,
|
||||
upload_protocol=None,
|
||||
ensure_ready=False,
|
||||
prefer_gdb_port=False,
|
||||
timeout=3,
|
||||
):
|
||||
if initial_port:
|
||||
if not is_pattern_port(initial_port):
|
||||
@ -76,7 +81,7 @@ def find_serial_port(
|
||||
return match_serial_port(initial_port)
|
||||
|
||||
if upload_protocol and upload_protocol.startswith("blackmagic"):
|
||||
return find_blackmagic_serial_port(timeout)
|
||||
return find_blackmagic_serial_port(prefer_gdb_port, timeout)
|
||||
if board_config and board_config.get("build.hwids", []):
|
||||
return find_board_serial_port(board_config, timeout)
|
||||
port = find_known_uart_port(ensure_ready, timeout)
|
||||
@ -94,7 +99,7 @@ def find_serial_port(
|
||||
return best_port or port
|
||||
|
||||
|
||||
def find_blackmagic_serial_port(timeout=0, only_gdb_port=False):
|
||||
def find_blackmagic_serial_port(prefer_gdb_port=False, timeout=0):
|
||||
try:
|
||||
|
||||
@retry(timeout=timeout)
|
||||
@ -118,18 +123,18 @@ def find_blackmagic_serial_port(timeout=0, only_gdb_port=False):
|
||||
raise retry.RetryNextException()
|
||||
|
||||
for item in candidates:
|
||||
if ("GDB" if only_gdb_port else "UART") in item["description"]:
|
||||
if ("GDB" if prefer_gdb_port else "UART") in item["description"]:
|
||||
return item["port"]
|
||||
if IS_MACOS:
|
||||
# 1 - GDB, 3 - UART
|
||||
for item in candidates:
|
||||
if item["port"].endswith("1" if only_gdb_port else "3"):
|
||||
if item["port"].endswith("1" if prefer_gdb_port else "3"):
|
||||
return item["port"]
|
||||
|
||||
candidates = sorted(candidates, key=lambda item: item["port"])
|
||||
return (
|
||||
candidates[0] # first port is GDB?
|
||||
if len(candidates) == 1 or only_gdb_port
|
||||
if len(candidates) == 1 or prefer_gdb_port
|
||||
else candidates[1]
|
||||
)["port"]
|
||||
|
||||
@ -222,15 +227,3 @@ def find_mbed_disk(initial_port):
|
||||
if item["name"] and any(l in item["name"].lower() for l in msdlabels):
|
||||
return item["path"]
|
||||
return None
|
||||
|
||||
|
||||
def find_debug_port(initial_port, tool_name, tool_settings):
|
||||
if initial_port:
|
||||
if not is_pattern_port(initial_port):
|
||||
return initial_port
|
||||
return match_serial_port(initial_port)
|
||||
if not tool_settings.get("require_debug_port"):
|
||||
return None
|
||||
if tool_name.startswith("blackmagic"):
|
||||
return find_blackmagic_serial_port(timeout=0, only_gdb_port=True)
|
||||
return None
|
||||
|
Reference in New Issue
Block a user