Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
flit committed Jul 11, 2021
2 parents fc2b7ef + 46a6c04 commit d9e84b0
Show file tree
Hide file tree
Showing 126 changed files with 284,653 additions and 38,184 deletions.
15 changes: 10 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ multiple ways to set these options.

- Many of the most commonly used session options have dedicated command line arguments.
- Options can be placed in a YAML config file.
- Arbitrary options can be set individually with the `-Ooption=value` command line argument.
- Arbitrary options can be set individually with the <tt>-O<i>option</i>=<i>value</i></tt> command line argument.
- If you are using the Python API, you may pass any option values directly
to the `ConnectHelper` methods or `Session` constructor as keyword arguments. You can also
pass a dictionary for the `options` parameter of these methods.
Expand All @@ -27,14 +27,18 @@ The priorities of the different session option sources, from highest to lowest:
## Project directory

To help pyOCD automatically find configuration files and other resources, it has the concept of
the project directory. By default this is simply the working directory where you ran the `pyocd`
tool. You can set the project directory explicitly with the `-j` or `--dir` command line
arguments. This can be helpful if you are running pyOCD from another tool or application.
the project directory.

When pyOCD looks for files such as the config file or a user script, it first expands '~'
references to the home directory. Then it checks whether the filename is absolute, and if so, it
uses the filename as-is. Otherwise, it looks for the file in the project directory.

By default, the project directory is simply the working directory where you ran the `pyocd` tool.
You can change the project directory to another location with the `-j`, `--project`, or `--dir` command line
arguments. This can be helpful if you are running pyOCD from another tool or application. The project
directory can also be set using the `PYOCD_PROJECT_DIR` environment variable. Command line arguments
have precedence over the environment variable.

## Config file

pyOCD supports a YAML configuration file that lets you set session options that either apply to
Expand All @@ -44,7 +48,8 @@ The easiest way to use a config file is to place a `pyocd.yaml` file in the proj
An alternate `.yml` extension and
optional dot prefix on the config file name are allowed. Alternatively, you can use the
`--config` command line option, for instance `--config=myconfig.yaml`. Finally, you can set the
`config_file` option.
`config_file` option. If there is a need to prevent reading a config file, use the `--no-config`
argument.

The top level of the YAML file is a dictionary. The keys in the top-level dictionary must be names
of session options, or the key `probes`. Session options are set to the value corresponding to the
Expand Down
7 changes: 7 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ working directory.
<td>'halt'</td>
<td>
Controls how pyOCD connects to the target. One of 'halt', 'pre-reset', 'under-reset', 'attach'.
<ul>
<li>'halt': immediately halt all accessible cores upon connect.</li>
<li>'pre-reset': perform a hardware reset prior to connect and halt.</li>
<li>'under-reset': assert hardware reset during the connect sequence, then deassert after the cores are halted.
This connect mode is often necessary to gain control of a target that is in a deep low power mode.</li>
<li>'attach': connect to a running target without halting cores.</li>
</ul>
</td></tr>

<tr><td>cpu.step.instruction.timeout</td>
Expand Down
4 changes: 2 additions & 2 deletions docs/target_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ DFPs. The part number patterns are matched case-insensitively and as a contains
For instance, if you know the specific part number of the device you are using, say STM32L073, you
can run this command to install support:

$ pyocd pack --install stm32l073
$ pyocd pack install stm32l073

This will download the index if required, then download the STM32L0xx_DFP pack. The

As another example, to find which pack(s) support the NXP MK26F family, you could run:

$ pyocd pack --find k26
$ pyocd pack find k26

This will print a table similar to:

Expand Down
8 changes: 6 additions & 2 deletions docs/terminology.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ Terminology

These are the key terms used by pyOCD and its documentation.

- **ADI**: Arm Debug Interface, an Arm architecture standard for how JTAG and SWD interface with CoreSight.
- **ADI**: Arm Debug Interface, an Arm architecture specification for how JTAG and SWD interface with CoreSight.
It defines the DAP structure and registers.
- **AP**: Access Port, part of the DAP, connected to the DP, that allows the debugger to perform operations
on the chip and cores. There are multiple types of AP that serve different purposes (see MEM-AP). Some MCU
vendors implement proprietary APs in their chips.
- **CoreSight**: A standard Arm architecture for debug subsystems. It defines a standardised way
- **Commander**: Refers to the `pyocd commander` subcommand that presents an interactive interface for exploring
the connected target.
- **CoreSight**: An Arm architecture specification for debug subsystems. It defines a standardised way
to discover the debug resources provided by a device.
- **DAP**: Debug Access Port, the debugging module that is accessed via the JTAG or SWD port. Composed of a
DP and one or more APs.
Expand All @@ -30,6 +32,8 @@ These are the key terms used by pyOCD and its documentation.
writes within the chip. Concrete MEM-APs have names that represent the kind of bus fabric with which they
interface, such as AHB-AP or AXI-AP.
- **probe server**: Server that shares a debug probe over TCP/IP.
- **REPL**: Read-Eval-Print-Loop. An interactive type of command interface used by pyOCD Commander, as well as
Python and other similar tools.
- **session**: Represents a connection to a debug probe and the runtime object graph.
- **session option**: A named setting that controls some feature of pyOCD. Options are associated with
a session, and each session can have different values for a given option.. They can be set from the
Expand Down
13 changes: 7 additions & 6 deletions pyocd/board/board.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2006-2013,2018 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,12 +15,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from ..core import exceptions
from ..target import TARGET
from ..target.pack import pack_target
from ..utility.graph import GraphNode
import logging
import six

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -60,11 +61,11 @@ def __init__(self, session, target=None):
try:
self.target = TARGET[self._target_type](session)
except KeyError as exc:
six.raise_from(exceptions.TargetSupportError(
"Target type '%s' not recognized. Use 'pyocd list --targets' to see currently "
raise exceptions.TargetSupportError(
f"Target type {self._target_type} not recognized. Use 'pyocd list --targets' to see currently "
"available target types. "
"See <https://github.com/pyocd/pyOCD/blob/master/docs/target_support.md> "
"for how to install additional target support." % self._target_type), exc)
"for how to install additional target support.") from exc

# Tell the user what target type is selected.
LOG.info("Target type is %s", self._target_type)
Expand Down Expand Up @@ -97,7 +98,7 @@ def uninit(self):
resume = self.session.options.get('resume_on_disconnect')
self.target.disconnect(resume)
self._inited = False
except:
except exceptions.Error:
LOG.error("link exception during target disconnect:", exc_info=self._session.log_tracebacks)

@property
Expand Down
2 changes: 2 additions & 0 deletions pyocd/board/board_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def __init__(self, name, target, binary):
"9014": BoardInfo( "Seeed 96Boards Nitrogen", "nrf52", "l1_nrf52-dk.bin", ),
"9900": BoardInfo( "micro:bit", "nrf51", "l1_microbit.bin", ),
"9901": BoardInfo( "micro:bit", "nrf51", "l1_microbit.bin", ),
"9903": BoardInfo( "micro:bit v2", "nrf52833", "microbitv2.bin", ),
"9904": BoardInfo( "micro:bit v2", "nrf52833", "microbitv2.bin", ),
"C004": BoardInfo( "tinyK20", "k20d50m", "l1_k20d50m.bin", ),
"C006": BoardInfo( "VBLUno51", "nrf51", "l1_nrf51.bin", ),
}
6 changes: 2 additions & 4 deletions pyocd/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import logging
import textwrap
import six

from ..core import exceptions
from ..utility import conversion
Expand Down Expand Up @@ -55,8 +54,7 @@ def __new__(mcs, name, bases, dict):
ALL_COMMANDS.setdefault(info['group'], set()).add(new_type)
return new_type

@six.add_metaclass(CommandMeta)
class CommandBase(object):
class CommandBase(metaclass=CommandMeta):
"""! @brief Base class for a command.
Each command class must have an `INFO` attribute with the following keys:
Expand Down Expand Up @@ -164,7 +162,7 @@ def _convert_value(self, arg):

return value
except ValueError as err:
raise six.raise_from(exceptions.CommandError("invalid argument '{}'".format(arg)), None)
raise exceptions.CommandError("invalid argument '{}'".format(arg)) from None

@classmethod
def format_help(cls, context, max_width=72):
Expand Down
2 changes: 1 addition & 1 deletion pyocd/commands/commander.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2015-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import logging
import os
import traceback
Expand Down
10 changes: 5 additions & 5 deletions pyocd/commands/execution_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def write(self, message='', **kwargs):
if self._output is None:
return
end = kwargs.pop('end', "\n")
if not isinstance(message, six.string_types):
if not isinstance(message, str):
message = str(message)
self._output.write(message + end)

Expand All @@ -175,7 +175,7 @@ def writei(self, fmt, *args, **kwargs):
@param self This object.
@param fmt Format string using printf-style "%" formatters.
"""
assert isinstance(fmt, six.string_types)
assert isinstance(fmt, str)
message = fmt % args
self.write(message, **kwargs)

Expand All @@ -188,7 +188,7 @@ def writef(self, fmt, *args, **kwargs):
@param self This object.
@param fmt Format string using the format() mini-language.
"""
assert isinstance(fmt, six.string_types)
assert isinstance(fmt, str)
message = fmt.format(*args, **kwargs)
self.write(message, **kwargs)

Expand Down Expand Up @@ -394,7 +394,7 @@ def handle_python(self, invocation):

result = eval(invocation.cmd, globals(), self._python_namespace)
if result is not None:
if isinstance(result, six.integer_types):
if isinstance(result, str):
self.writei("0x%08x (%d)", result, result)
else:
w, h = get_terminal_size()
Expand All @@ -411,4 +411,4 @@ def handle_system(self, invocation):
output = subprocess.check_output(invocation.cmd, stderr=subprocess.STDOUT, shell=True)
self.write(six.ensure_str(output), end='')
except subprocess.CalledProcessError as err:
six.raise_from(exceptions.CommandError(str(err)), err)
raise exceptions.CommandError(str(err)) from err
5 changes: 2 additions & 3 deletions pyocd/commands/repl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2015-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,10 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import logging
import os
import six
import traceback
import atexit

Expand Down Expand Up @@ -75,7 +74,7 @@ def run(self):
try:
while True:
try:
line = six.moves.input(self.PROMPT)
line = input(self.PROMPT)
self.run_one_command(line)
except KeyboardInterrupt:
print()
Expand Down
3 changes: 2 additions & 1 deletion pyocd/commands/values.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2015-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -178,7 +179,7 @@ def display(self, args):
DFSR = 0xe000ed30
MMFAR = 0xe000ed34
BFAR = 0xe000ed38
AFSR = 0xe000ed3c
# AFSR = 0xe000ed3c

MMFSR_fields = [
('IACCVIOL', 0),
Expand Down
6 changes: 3 additions & 3 deletions pyocd/core/core_registers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2019-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,7 +16,6 @@
# limitations under the License.

import logging
import six
from copy import copy

from ..utility import conversion
Expand Down Expand Up @@ -59,13 +59,13 @@ def get(cls, reg):
@exception KeyError
"""
try:
if isinstance(reg, six.string_types):
if isinstance(reg, str):
reg = reg.lower()
return cls._NAME_MAP[reg]
else:
return cls._INDEX_MAP[reg]
except KeyError as err:
six.raise_from(KeyError('unknown core register %s' % reg), err)
raise KeyError('unknown core register %s' % reg) from err

def __init__(self, name, index, bitsize, reg_type, reg_group, reg_num=None, feature=None):
"""! @brief Constructor."""
Expand Down
10 changes: 5 additions & 5 deletions pyocd/core/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2018-2019 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,14 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
from .session import Session
from ..probe.aggregator import DebugProbeAggregator
from time import sleep
import colorama
import six
import prettytable

from .session import Session
from ..probe.aggregator import DebugProbeAggregator

# Init colorama here since this is currently the only module that uses it.
colorama.init()

Expand Down Expand Up @@ -168,7 +168,7 @@ def choose_probe(blocking=True, return_first=False, unique_id=None):
while True:
print(colorama.Style.RESET_ALL)
print("Enter the number of the debug probe or 'q' to quit", end='')
line = six.moves.input("> ")
line = input("> ")
valid = False
if line.strip().lower() == 'q':
return None
Expand Down
7 changes: 2 additions & 5 deletions pyocd/core/options_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2019-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,9 +16,6 @@
# limitations under the License.

import logging
import six
import yaml
import os
from functools import partial
from collections import namedtuple

Expand Down Expand Up @@ -130,8 +128,7 @@ def get(self, key):
for layer in self._layers:
if key in layer:
return layer[key]
else:
return self.get_default(key)
return self.get_default(key)

def set(self, key, value):
"""! @brief Set an option in the current highest priority layer."""
Expand Down
Loading

0 comments on commit d9e84b0

Please sign in to comment.