mbed-ls


Namembed-ls JSON
Version 1.8.15 PyPI version JSON
download
home_pagehttps://github.com/ARMmbed/mbed-os-tools
Summarymbed-ls is a Python module that detects and lists mbed-enabled devices connected to the host computer
upload_time2023-01-25 11:49:34
maintainerGraham Hammond, Mark Edgeworth
docs_urlNone
authorGraham Hammond, Mark Edgeworth
requires_python>=2.7.10, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements PySerial requests intelhex future PrettyTable prettytable fasteners appdirs junit-xml lockfile six colorama beautifulsoup4 lxml
Travis-CI No Travis.
coveralls test coverage
            # Development moved

The development of Mbed LS has been moved into the [mbed-os-tools](../../src/mbed_os_tools) package. You can continue to use this module for legacy reasons, however all further development should be continued in the new package.

-------------

[![PyPI version](https://badge.fury.io/py/mbed-ls.svg)](https://badge.fury.io/py/mbed-ls)

# Mbed LS

Mbed LS is a Python (2 and 3) module that detects and lists Mbed Enabled devices connected to the host computer. The Mbed OS team publishes Mbed LS on PyPI. It works on all major operating systems (Windows, Linux and Mac OS X).

It provides the following information for all connected boards in a console (terminal) output:

- Mbed OS platform name.
- Mount point (MSD or disk).
- Serial port.

# Installation

## Installation from PyPI (Python Package Index)

To install Mbed LS from [PyPI](https://pypi.python.org/pypi/mbed-ls), run the following command:

```bash
$ pip install mbed-ls --upgrade
```

## Installation from Python sources

**Prerequisites:** You need to have [Python 2.7.x](https://www.python.org/download/releases/2.7/) or [Python 3.6.x](https://www.python.org/downloads/release/python-362/) installed on your system.

**Note:** If your OS is Windows, please follow the installation instructions [for the serial port driver](https://os.mbed.com/docs/latest/tutorials/windows-serial-driver.html).

Install Mbed LS from sources with the following commands:

```bash
$ git clone https://github.com/ARMmbed/mbed-os-tools.git
$ cd mbed-os-tools/packages/mbed-ls
$ python setup.py install
```

# Command-line

The command-line tool is available with the command `mbedls`.

**Note:** [Mbed CLI](https://github.com/armmbed/mbed-cli) has a similarly-named command `mbed ls`; however, the commands are different. Be sure to omit the space when using the Mbed LS command-line tool.

```bash
$ mbedls
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| platform_name | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| K64F          | K64F[0]              | D:          | COM18       | 0240000032044e4500257009997b00386781000097969900 | 0244            |
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
```

## Result formats

The Mbed LS command-line accepts a few arguments to change the format of the results. The default format is a table. You may pass `--simple` to simplify this table format, and `--json` to print the table as a json list of the rows.

### Simple (no table formatting)

```
$ mbedls --simple
 K64F  K64F[0]  D:  COM18  0240000032044e4500257009997b00386781000097969900  0244
```

### JSON

```bash
$ mbedls --json
[
    {
        "daplink_auto_reset": "0",
        "daplink_automation_allowed": "1",
        "daplink_bootloader_crc": "0xa65218eb",
        "daplink_bootloader_version": "0242",
        "daplink_daplink_mode": "Interface",
        "daplink_git_sha": "67f8727a030bcc585e982d899fb6382db56d673b",
        "daplink_hic_id": "97969900",
        "daplink_interface_crc": "0xe4422294",
        "daplink_interface_version": "0244",
        "daplink_local_mods": "0",
        "daplink_overflow_detection": "1",
        "daplink_remount_count": "0",
        "daplink_unique_id": "0240000032044e4500257009997b00386781000097969900",
        "daplink_usb_interfaces": "MSD, CDC, HID",
        "daplink_version": "0244",
        "mount_point": "D:",
        "platform_name": "K64F",
        "platform_name_unique": "K64F[0]",
        "product_id": "0204",
        "serial_port": "COM18",
        "target_id": "0240000032044e4500257009997b00386781000097969900",
        "target_id_mbed_htm": "0240000032044e4500257009997b00386781000097969900",
        "target_id_usb_id": "0240000032044e4500257009997b00386781000097969900",
        "vendor_id": "0d28"
    }
]
```

## Mocking (renaming) platforms

Override a platform's name using the `--mock` parameter:

```
$ mbedls --mock 0240:MY_NEW_PLATFORM
$ mbedls
+-----------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| platform_name   | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |
+-----------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| MY_NEW_PLATFORM | MY_NEW_PLATFORM[0]   | D:          | COM18       | 0240000032044e4500257009997b00386781000097969900 | 0244            |
+-----------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
```

The `--mock` parameter accepts a platform ID and a platform name, separated by the `:` character. The platform ID is the first 4 characters of the `target_id`. The platform name is the name you are temporarily assigning to this platform.

To remove a mocked platform, use the `--mock` parameter again. Continuing from the previous example, use `-<platform id>` as the value:

```
$ mbedls --mock -0240
$ mbedls
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| platform_name | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| K64F          | K64F[0]              | D:          | COM18       | 0240000032044e4500257009997b00386781000097969900 | 0244            |
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
```

You can also remove all mocked platforms by supplying `*` as the `target_id`:

```
$ mbedls --mock="-*"
```

**NOTE:** Due to a quirk in the parameter formatting, the command-line can interpret `-*` as another parameter instead of a value. It is necessary to use the complete `--mock="-*"` syntax, so the command-line interprets each part of the command correctly.

## Retargeting platforms

It is possible to change the returned results for certain platforms depending on the current directory. This is especially useful when developing new platforms.

The command-line tool and Python API check the current directory for a file named `mbedls.json`. When it is present, it overrides the returned values. The format of the `mbedls.json` file is:

```json
{
    "<target_id>": {
        "<key>": "<value>"
    }
}
```

For example, to change the `serial_port` of the K64F with a `target_id` of `0240000032044e4500257009997b00386781000097969900`, the `mbedls.json` file contains the following:

```json
{
    "0240000032044e4500257009997b00386781000097969900": {
        "serial_port": "COM99"
    }
}
```

This results in the following output from the command-line tool:

```bash
$ mbedls
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| platform_name | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| K64F          | K64F[0]              | D:          | COM99       | 0240000032044e4500257009997b00386781000097969900 | 0244            |
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
```

Note how the `serial_port` value changed from `COM18` to `COM99`. Deleting the `mbedls.json` or using the `--skip-retarget` parameter removes these changes.

# Python API

The Python API is available through the `mbed_lstools` module.

## `mbed_lstools.create(...)`

```python
>>> import mbed_lstools
>>> mbeds = mbed_lstools.create()
>>> mbeds
<mbed_lstools.lstools_win7.MbedLsToolsWin7 instance at 0x02F542B0>
```

This returns an instance that provides access to the rest of the API.

### Arguments

#### `skip_retarget`

**Default:** `False`

When set to `True`, this skips the retargetting step, and the results are unmodified. This enables the same behavior as the `--skip-retarget` command-line flag.

#### `list_unmounted`

**Default:** `False`

When set to `True`, this includes unmounted platforms in the results. This enables the same behavior as the `-u` command-line flag.

## `mbeds.list_mbeds(...)`

```python
>>> import mbed_lstools
>>> mbeds = mbed_lstools.create()
>>> mbeds.list_mbeds(fs_interaction=FSInteraction.BeforeFilter,
                                    filter_function=None,
                                    unique_names=False,
                                    read_details_txt=False)
[{'target_id_mbed_htm': u'0240000032044e4500257009997b00386781000097969900', 'mount_point': 'D:', 'target_id': u'0240000032044e4500257009997b00386781000097969900', 'serial_port': u'COM18', 'target_id_usb_id': u'0240000032044e4500257009997b00386781000097969900', 'platform_name': u'K64F'}]
```

### Arguments

#### `filter_function`

**Default:** `None`

This function allows you to filter results based on platform data. This can hasten the execution of the `list_mbeds` function.

As a normal function definition:

```python
def filter_func(mbed):
    return m['platform_name'] == 'K64F'

mbeds.list_mbeds(filter_function=filter_func)
```

As a lambda function:

```python
platforms = mbeds.list_mbeds(filter_function=lambda m: m['platform_name'] == 'K64F')
```

#### `fs_interaction`

**Default:** `FSInteraction.BeforeFilter`

This argument controls the accuracy and speed of this function. There are three choices (in ascending order of accuracy and decreasing order of speed):

- `FSInteraction.NEVER` - This is the fastest option but also potentially the least accurate. It never touches the file system of the devices. It uses only the information available through the USB descriptors. This is appropriate for use in a highly controlled environment (such as an automated Continuous Integration setup). **This has the potential to provide incorrect names and data. It may also lead to devices not being detected at all.**
- `FSInterfaction.AfterFilter` - This accesses the file system but only after application of the `filter_function`. This can lead to speed increases but at the risk of filtering on inaccurate information.
- `FSInteraction.BeforeFilter` - This accesses the file system before doing any filtering. It is the most accurate option and is recommended for most uses. This is the default behavior of the command-line tool and the API.

#### `unique_names`

**Default:** `False`.

Mbed LS assigns a unique name to each platform when this is set to `True`. The unique name takes the form of `K64F[0]`, where the number between the brackets is an incrementing value. This name is accessible through the dictionary member `platform_unique_name` in the returned platform data.

#### `read_details_txt`

**Default:** `False`

Mbed LS reads more data from the file system on each device when this is set to `True`. It can provide useful management data but also takes more time to execute.

## `mbeds.mock_manufacture_id(...)`

```python
>>> import mbed_lstools
>>> mbeds = mbed_lstools.create()
>>> mbeds.mock_manufacture_id('0240', 'CUSTOM_PLATFORM', oper='+')
>>> mbeds.list_mbeds()
[{'target_id': u'0240000032044e4500257009997b00386781000097969900', ... 'platform_name': u'CUSTOM_PLATFORM'}]
>>> mbeds.mock_manufacture_id('0240', '', oper='-')
>>> mbeds.list_mbeds()
[{'target_id': u'0240000032044e4500257009997b00386781000097969900', ... 'platform_name': u'K64F'}]
```

### Arguments

#### `mid`

**Required**

The first four characters of the `target_id` that you want to mock.

#### `platform_name`

**Required**

Overrides the `platform_name` for any platform with a `target_id` that starts with `mid`.

#### `oper`

**Default:** `'+'`

If set to `'+'`, the mocked platform is enabled. If `'-'`, the mocked platform is disabled.


## `mbeds.get_supported_platforms(...)`

```python
>>> import mbed_lstools
>>> mbeds = mbed_lstools.create()
>>> mbeds.get_supported_platforms(device_type='daplink')
{'0240': 'K64F', '0311': 'K66F'}
```

### Arguments

#### `device_type`

**Default:** `'daplink'`

Chooses which device type entries are retrieved from the platform database.

## Logging

Mbed LS uses the Python `logging` module for all of its logging needs. Mbed LS uses the logger `"mbedls"` as its root, and all other loggers start with `"mbedls."`. Configuring the Python root logger automatically redirects all of the Mbed LS logs to the configured endpoint. When using the Python API, configure logging, such as by calling `logging.basicConfig()`.

# Testing

The `/test` directory contains all tests. You can run the tests with the following command:

```
$ python setup.py test
```

## Code coverage

The `coverage` Python package measures code coverage. You can install it with following command:

```
$ pip install coverage --upgrade
```

To run the tests while measuring code coverage, use the following command:

```
$ coverage run setup.py test
```

You can then generate a report:

```
$ coverage report
Name                                Stmts   Miss  Cover
-------------------------------------------------------
mbed_lstools\__init__.py                2      0   100%
mbed_lstools\darwin.py                 85      7    92%
mbed_lstools\linux.py                  45      3    93%
mbed_lstools\lstools_base.py          299    124    59%
mbed_lstools\main.py                  134     44    67%
mbed_lstools\platform_database.py     114      4    96%
mbed_lstools\windows.py                98     21    79%
-------------------------------------------------------
TOTAL                                 777    203    74%
```

# OS-specific behavior

## Windows

The Mbed serial port works by default on Mac and Linux, but Windows needs a driver. Check [here](https://os.mbed.com/docs/latest/tutorials/windows-serial-driver.html) for more details.

## Linux

Mbed LS requires you to mount a platform before it shows up in the results. Many Linux systems do not automatically mount USB devices. We recommend you use an automounter to manage this for you.

There are many automounters available, and it is ultimately up to you to determine which is the best one for your use case. However, the `usbmount` package on Ubuntu makes it easy to start. If you need more control over your automounter, you can build and run an open source project called [ldm](https://github.com/LemonBoy/ldm).

# Mbed Enabled technical requirements overview

This tool relies on board interfaces conforming to certain standards, so it can detect platforms properly. The [Mbed Enabled](https://www.mbed.com/en/about-mbed/mbed-enabled/) program sets these standards. Please see the [Technical Requirements](https://www.mbed.com/en/about-mbed/mbed-enabled/mbed-enabled-program-requirements/) for more information.

## Device unique identifier

Each device must have a unique identifier. This identifier has two parts: a **platform ID** and a **platform unique string**.

The **platform ID** contains four ASCII characters containing only hexadecimal values (A-F and 0-9). This platform ID is the same for all platforms of the same type. For example, all `K64F` platforms have a platform ID of `0240`. `mbedls` uses this to identify the platform.

The **platform unique string** can be any length of characters (a-z, A-Z and 0-9) that you can use to uniquely identify platforms of the same type on the same machine. For example, two FRDM-K64F platforms attached to the same machine could have the following attributes:

```
$ mbedls
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| platform_name | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
| K64F          | K64F[0]              | D:          | COM18       | 0240000032044e4500257009997b00386781000097969900 | 0244            |
| K64F          | K64F[1]              | E:          | COM19       | 0240000032044e4500257009997b00386781000097840023 | 0244            |
+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+
```

Note how both platforms share the same platform ID (`0240`) but have a unique ending string.

# Adding platform support

If a platform meets the Mbed Enabled technical requirements (stated above), it can be added to Mbed LS.

## Adding a new platform with a supported debugger

Mbed LS currently supports the following types of debuggers:

- [DAPLink](https://github.com/ARMmbed/DAPLink)
   - As well as the related but legacy [CMSIS-DAP](https://github.com/mbedmicro/CMSIS-DAP) firmware
- ST-LINK
- J-Link

### Adding support for DAPLink-compatible platforms (DAPLink, ST-LINK, and CMSIS-DAP)

Add an entry to the `daplink` section of the [`DEFAULT_PLATFORM_DB`](../../src/mbed_os_tools/detect/platform_database.py).

If your platform's name is `NEW_PLATFORM` and it has platform ID of `9999`, the new entry should be:

```
DEFAULT_PLATFORM_DB = {
    u'daplink': {
        ...
        u'9999': u'NEW_PLATFORM',
        ...
    }
}
```

Please order the entries by the platform ID when adding new platforms.

### Adding support for J-Link platforms

J-Link detection works differently due to the information present on the platform's filesystem. All new entries should be added to the `jlink` section of the [`DEFAULT_PLATFORM_DB`](../../src/mbed_os_tools/detect/platform_database.py).

The following is an example `jlink` platform entry:

```
DEFAULT_PLATFORM_DB = {
    ...
    u'jlink': {
        u'X729475D28G': {
            u'platform_name': u'NRF51_DK',
            u'jlink_device_name': u'nRF51422_xxAC'
        },
        ...
    }
}
```

Instead of a platform ID, there is a target-unique string (`X729475D28G` in this case). This should correspond with the unique part of the link present in the `Board.html` or `User Guide.html`. This seems to vary among the platforms. In general, try following the links in each file. You want to use the url that links to a product page that references the platform. The J-Link logic in Mbed LS assumes that the url has the target-unique string on the end (after the last `/` character). In the above example, the expected url structure would be `http://www.nordicsemi.com/X729475D28G`.

If your J-Link platform does not follow this convention, please raise an issue with the following information:

- The name of the platform
- The file **names and contents** present on the platform's filesystem
- A link to the J-Link firmware binary if possible

## Adding a new type of debugger

The type of debugger present on the platform affects how it is detected. The USB Vendor ID is used to detect which type of debugger is present on the platform.

If a new type of debugger is being introduced to Mbed LS with the platform, you will need to add the Vendor ID to the [identification map](../../src/mbed_os_tools/detect/lstools_base.py). You will also need to assign the correct "update from the filesystem" logic [here](../../src/mbed_os_tools/detect/lstools_base.py). If the debugger is compatible with the files presented by DAPLink, you may reuse that implementation when updating the device information from the filesystem. If it is not, you may need to write your own update logic. If you need guidance on this, please ask for it when you submit an issue or a pull request.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ARMmbed/mbed-os-tools",
    "name": "mbed-ls",
    "maintainer": "Graham Hammond, Mark Edgeworth",
    "docs_url": null,
    "requires_python": ">=2.7.10, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4",
    "maintainer_email": "Graham.Hammond@arm.com, Mark.Edgeworth@arm.com",
    "keywords": "",
    "author": "Graham Hammond, Mark Edgeworth",
    "author_email": "Graham.Hammond@arm.com, Mark.Edgeworth@arm.com",
    "download_url": "",
    "platform": null,
    "description": "# Development moved\n\nThe development of Mbed LS has been moved into the [mbed-os-tools](../../src/mbed_os_tools) package. You can continue to use this module for legacy reasons, however all further development should be continued in the new package.\n\n-------------\n\n[![PyPI version](https://badge.fury.io/py/mbed-ls.svg)](https://badge.fury.io/py/mbed-ls)\n\n# Mbed LS\n\nMbed LS is a Python (2 and 3) module that detects and lists Mbed Enabled devices connected to the host computer. The Mbed OS team publishes Mbed LS on PyPI. It works on all major operating systems (Windows, Linux and Mac OS X).\n\nIt provides the following information for all connected boards in a console (terminal) output:\n\n- Mbed OS platform name.\n- Mount point (MSD or disk).\n- Serial port.\n\n# Installation\n\n## Installation from PyPI (Python Package Index)\n\nTo install Mbed LS from [PyPI](https://pypi.python.org/pypi/mbed-ls), run the following command:\n\n```bash\n$ pip install mbed-ls --upgrade\n```\n\n## Installation from Python sources\n\n**Prerequisites:** You need to have [Python 2.7.x](https://www.python.org/download/releases/2.7/) or [Python 3.6.x](https://www.python.org/downloads/release/python-362/) installed on your system.\n\n**Note:** If your OS is Windows, please follow the installation instructions [for the serial port driver](https://os.mbed.com/docs/latest/tutorials/windows-serial-driver.html).\n\nInstall Mbed LS from sources with the following commands:\n\n```bash\n$ git clone https://github.com/ARMmbed/mbed-os-tools.git\n$ cd mbed-os-tools/packages/mbed-ls\n$ python setup.py install\n```\n\n# Command-line\n\nThe command-line tool is available with the command `mbedls`.\n\n**Note:** [Mbed CLI](https://github.com/armmbed/mbed-cli) has a similarly-named command `mbed ls`; however, the commands are different. Be sure to omit the space when using the Mbed LS command-line tool.\n\n```bash\n$ mbedls\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| platform_name | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| K64F          | K64F[0]              | D:          | COM18       | 0240000032044e4500257009997b00386781000097969900 | 0244            |\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n```\n\n## Result formats\n\nThe Mbed LS command-line accepts a few arguments to change the format of the results. The default format is a table. You may pass `--simple` to simplify this table format, and `--json` to print the table as a json list of the rows.\n\n### Simple (no table formatting)\n\n```\n$ mbedls --simple\n K64F  K64F[0]  D:  COM18  0240000032044e4500257009997b00386781000097969900  0244\n```\n\n### JSON\n\n```bash\n$ mbedls --json\n[\n    {\n        \"daplink_auto_reset\": \"0\",\n        \"daplink_automation_allowed\": \"1\",\n        \"daplink_bootloader_crc\": \"0xa65218eb\",\n        \"daplink_bootloader_version\": \"0242\",\n        \"daplink_daplink_mode\": \"Interface\",\n        \"daplink_git_sha\": \"67f8727a030bcc585e982d899fb6382db56d673b\",\n        \"daplink_hic_id\": \"97969900\",\n        \"daplink_interface_crc\": \"0xe4422294\",\n        \"daplink_interface_version\": \"0244\",\n        \"daplink_local_mods\": \"0\",\n        \"daplink_overflow_detection\": \"1\",\n        \"daplink_remount_count\": \"0\",\n        \"daplink_unique_id\": \"0240000032044e4500257009997b00386781000097969900\",\n        \"daplink_usb_interfaces\": \"MSD, CDC, HID\",\n        \"daplink_version\": \"0244\",\n        \"mount_point\": \"D:\",\n        \"platform_name\": \"K64F\",\n        \"platform_name_unique\": \"K64F[0]\",\n        \"product_id\": \"0204\",\n        \"serial_port\": \"COM18\",\n        \"target_id\": \"0240000032044e4500257009997b00386781000097969900\",\n        \"target_id_mbed_htm\": \"0240000032044e4500257009997b00386781000097969900\",\n        \"target_id_usb_id\": \"0240000032044e4500257009997b00386781000097969900\",\n        \"vendor_id\": \"0d28\"\n    }\n]\n```\n\n## Mocking (renaming) platforms\n\nOverride a platform's name using the `--mock` parameter:\n\n```\n$ mbedls --mock 0240:MY_NEW_PLATFORM\n$ mbedls\n+-----------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| platform_name   | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |\n+-----------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| MY_NEW_PLATFORM | MY_NEW_PLATFORM[0]   | D:          | COM18       | 0240000032044e4500257009997b00386781000097969900 | 0244            |\n+-----------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n```\n\nThe `--mock` parameter accepts a platform ID and a platform name, separated by the `:` character. The platform ID is the first 4 characters of the `target_id`. The platform name is the name you are temporarily assigning to this platform.\n\nTo remove a mocked platform, use the `--mock` parameter again. Continuing from the previous example, use `-<platform id>` as the value:\n\n```\n$ mbedls --mock -0240\n$ mbedls\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| platform_name | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| K64F          | K64F[0]              | D:          | COM18       | 0240000032044e4500257009997b00386781000097969900 | 0244            |\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n```\n\nYou can also remove all mocked platforms by supplying `*` as the `target_id`:\n\n```\n$ mbedls --mock=\"-*\"\n```\n\n**NOTE:** Due to a quirk in the parameter formatting, the command-line can interpret `-*` as another parameter instead of a value. It is necessary to use the complete `--mock=\"-*\"` syntax, so the command-line interprets each part of the command correctly.\n\n## Retargeting platforms\n\nIt is possible to change the returned results for certain platforms depending on the current directory. This is especially useful when developing new platforms.\n\nThe command-line tool and Python API check the current directory for a file named `mbedls.json`. When it is present, it overrides the returned values. The format of the `mbedls.json` file is:\n\n```json\n{\n    \"<target_id>\": {\n        \"<key>\": \"<value>\"\n    }\n}\n```\n\nFor example, to change the `serial_port` of the K64F with a `target_id` of `0240000032044e4500257009997b00386781000097969900`, the `mbedls.json` file contains the following:\n\n```json\n{\n    \"0240000032044e4500257009997b00386781000097969900\": {\n        \"serial_port\": \"COM99\"\n    }\n}\n```\n\nThis results in the following output from the command-line tool:\n\n```bash\n$ mbedls\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| platform_name | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| K64F          | K64F[0]              | D:          | COM99       | 0240000032044e4500257009997b00386781000097969900 | 0244            |\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n```\n\nNote how the `serial_port` value changed from `COM18` to `COM99`. Deleting the `mbedls.json` or using the `--skip-retarget` parameter removes these changes.\n\n# Python API\n\nThe Python API is available through the `mbed_lstools` module.\n\n## `mbed_lstools.create(...)`\n\n```python\n>>> import mbed_lstools\n>>> mbeds = mbed_lstools.create()\n>>> mbeds\n<mbed_lstools.lstools_win7.MbedLsToolsWin7 instance at 0x02F542B0>\n```\n\nThis returns an instance that provides access to the rest of the API.\n\n### Arguments\n\n#### `skip_retarget`\n\n**Default:** `False`\n\nWhen set to `True`, this skips the retargetting step, and the results are unmodified. This enables the same behavior as the `--skip-retarget` command-line flag.\n\n#### `list_unmounted`\n\n**Default:** `False`\n\nWhen set to `True`, this includes unmounted platforms in the results. This enables the same behavior as the `-u` command-line flag.\n\n## `mbeds.list_mbeds(...)`\n\n```python\n>>> import mbed_lstools\n>>> mbeds = mbed_lstools.create()\n>>> mbeds.list_mbeds(fs_interaction=FSInteraction.BeforeFilter,\n                                    filter_function=None,\n                                    unique_names=False,\n                                    read_details_txt=False)\n[{'target_id_mbed_htm': u'0240000032044e4500257009997b00386781000097969900', 'mount_point': 'D:', 'target_id': u'0240000032044e4500257009997b00386781000097969900', 'serial_port': u'COM18', 'target_id_usb_id': u'0240000032044e4500257009997b00386781000097969900', 'platform_name': u'K64F'}]\n```\n\n### Arguments\n\n#### `filter_function`\n\n**Default:** `None`\n\nThis function allows you to filter results based on platform data. This can hasten the execution of the `list_mbeds` function.\n\nAs a normal function definition:\n\n```python\ndef filter_func(mbed):\n    return m['platform_name'] == 'K64F'\n\nmbeds.list_mbeds(filter_function=filter_func)\n```\n\nAs a lambda function:\n\n```python\nplatforms = mbeds.list_mbeds(filter_function=lambda m: m['platform_name'] == 'K64F')\n```\n\n#### `fs_interaction`\n\n**Default:** `FSInteraction.BeforeFilter`\n\nThis argument controls the accuracy and speed of this function. There are three choices (in ascending order of accuracy and decreasing order of speed):\n\n- `FSInteraction.NEVER` - This is the fastest option but also potentially the least accurate. It never touches the file system of the devices. It uses only the information available through the USB descriptors. This is appropriate for use in a highly controlled environment (such as an automated Continuous Integration setup). **This has the potential to provide incorrect names and data. It may also lead to devices not being detected at all.**\n- `FSInterfaction.AfterFilter` - This accesses the file system but only after application of the `filter_function`. This can lead to speed increases but at the risk of filtering on inaccurate information.\n- `FSInteraction.BeforeFilter` - This accesses the file system before doing any filtering. It is the most accurate option and is recommended for most uses. This is the default behavior of the command-line tool and the API.\n\n#### `unique_names`\n\n**Default:** `False`.\n\nMbed LS assigns a unique name to each platform when this is set to `True`. The unique name takes the form of `K64F[0]`, where the number between the brackets is an incrementing value. This name is accessible through the dictionary member `platform_unique_name` in the returned platform data.\n\n#### `read_details_txt`\n\n**Default:** `False`\n\nMbed LS reads more data from the file system on each device when this is set to `True`. It can provide useful management data but also takes more time to execute.\n\n## `mbeds.mock_manufacture_id(...)`\n\n```python\n>>> import mbed_lstools\n>>> mbeds = mbed_lstools.create()\n>>> mbeds.mock_manufacture_id('0240', 'CUSTOM_PLATFORM', oper='+')\n>>> mbeds.list_mbeds()\n[{'target_id': u'0240000032044e4500257009997b00386781000097969900', ... 'platform_name': u'CUSTOM_PLATFORM'}]\n>>> mbeds.mock_manufacture_id('0240', '', oper='-')\n>>> mbeds.list_mbeds()\n[{'target_id': u'0240000032044e4500257009997b00386781000097969900', ... 'platform_name': u'K64F'}]\n```\n\n### Arguments\n\n#### `mid`\n\n**Required**\n\nThe first four characters of the `target_id` that you want to mock.\n\n#### `platform_name`\n\n**Required**\n\nOverrides the `platform_name` for any platform with a `target_id` that starts with `mid`.\n\n#### `oper`\n\n**Default:** `'+'`\n\nIf set to `'+'`, the mocked platform is enabled. If `'-'`, the mocked platform is disabled.\n\n\n## `mbeds.get_supported_platforms(...)`\n\n```python\n>>> import mbed_lstools\n>>> mbeds = mbed_lstools.create()\n>>> mbeds.get_supported_platforms(device_type='daplink')\n{'0240': 'K64F', '0311': 'K66F'}\n```\n\n### Arguments\n\n#### `device_type`\n\n**Default:** `'daplink'`\n\nChooses which device type entries are retrieved from the platform database.\n\n## Logging\n\nMbed LS uses the Python `logging` module for all of its logging needs. Mbed LS uses the logger `\"mbedls\"` as its root, and all other loggers start with `\"mbedls.\"`. Configuring the Python root logger automatically redirects all of the Mbed LS logs to the configured endpoint. When using the Python API, configure logging, such as by calling `logging.basicConfig()`.\n\n# Testing\n\nThe `/test` directory contains all tests. You can run the tests with the following command:\n\n```\n$ python setup.py test\n```\n\n## Code coverage\n\nThe `coverage` Python package measures code coverage. You can install it with following command:\n\n```\n$ pip install coverage --upgrade\n```\n\nTo run the tests while measuring code coverage, use the following command:\n\n```\n$ coverage run setup.py test\n```\n\nYou can then generate a report:\n\n```\n$ coverage report\nName                                Stmts   Miss  Cover\n-------------------------------------------------------\nmbed_lstools\\__init__.py                2      0   100%\nmbed_lstools\\darwin.py                 85      7    92%\nmbed_lstools\\linux.py                  45      3    93%\nmbed_lstools\\lstools_base.py          299    124    59%\nmbed_lstools\\main.py                  134     44    67%\nmbed_lstools\\platform_database.py     114      4    96%\nmbed_lstools\\windows.py                98     21    79%\n-------------------------------------------------------\nTOTAL                                 777    203    74%\n```\n\n# OS-specific behavior\n\n## Windows\n\nThe Mbed serial port works by default on Mac and Linux, but Windows needs a driver. Check [here](https://os.mbed.com/docs/latest/tutorials/windows-serial-driver.html) for more details.\n\n## Linux\n\nMbed LS requires you to mount a platform before it shows up in the results. Many Linux systems do not automatically mount USB devices. We recommend you use an automounter to manage this for you.\n\nThere are many automounters available, and it is ultimately up to you to determine which is the best one for your use case. However, the `usbmount` package on Ubuntu makes it easy to start. If you need more control over your automounter, you can build and run an open source project called [ldm](https://github.com/LemonBoy/ldm).\n\n# Mbed Enabled technical requirements overview\n\nThis tool relies on board interfaces conforming to certain standards, so it can detect platforms properly. The [Mbed Enabled](https://www.mbed.com/en/about-mbed/mbed-enabled/) program sets these standards. Please see the [Technical Requirements](https://www.mbed.com/en/about-mbed/mbed-enabled/mbed-enabled-program-requirements/) for more information.\n\n## Device unique identifier\n\nEach device must have a unique identifier. This identifier has two parts: a **platform ID** and a **platform unique string**.\n\nThe **platform ID** contains four ASCII characters containing only hexadecimal values (A-F and 0-9). This platform ID is the same for all platforms of the same type. For example, all `K64F` platforms have a platform ID of `0240`. `mbedls` uses this to identify the platform.\n\nThe **platform unique string** can be any length of characters (a-z, A-Z and 0-9) that you can use to uniquely identify platforms of the same type on the same machine. For example, two FRDM-K64F platforms attached to the same machine could have the following attributes:\n\n```\n$ mbedls\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| platform_name | platform_name_unique | mount_point | serial_port | target_id                                        | daplink_version |\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n| K64F          | K64F[0]              | D:          | COM18       | 0240000032044e4500257009997b00386781000097969900 | 0244            |\n| K64F          | K64F[1]              | E:          | COM19       | 0240000032044e4500257009997b00386781000097840023 | 0244            |\n+---------------+----------------------+-------------+-------------+--------------------------------------------------+-----------------+\n```\n\nNote how both platforms share the same platform ID (`0240`) but have a unique ending string.\n\n# Adding platform support\n\nIf a platform meets the Mbed Enabled technical requirements (stated above), it can be added to Mbed LS.\n\n## Adding a new platform with a supported debugger\n\nMbed LS currently supports the following types of debuggers:\n\n- [DAPLink](https://github.com/ARMmbed/DAPLink)\n   - As well as the related but legacy [CMSIS-DAP](https://github.com/mbedmicro/CMSIS-DAP) firmware\n- ST-LINK\n- J-Link\n\n### Adding support for DAPLink-compatible platforms (DAPLink, ST-LINK, and CMSIS-DAP)\n\nAdd an entry to the `daplink` section of the [`DEFAULT_PLATFORM_DB`](../../src/mbed_os_tools/detect/platform_database.py).\n\nIf your platform's name is `NEW_PLATFORM` and it has platform ID of `9999`, the new entry should be:\n\n```\nDEFAULT_PLATFORM_DB = {\n    u'daplink': {\n        ...\n        u'9999': u'NEW_PLATFORM',\n        ...\n    }\n}\n```\n\nPlease order the entries by the platform ID when adding new platforms.\n\n### Adding support for J-Link platforms\n\nJ-Link detection works differently due to the information present on the platform's filesystem. All new entries should be added to the `jlink` section of the [`DEFAULT_PLATFORM_DB`](../../src/mbed_os_tools/detect/platform_database.py).\n\nThe following is an example `jlink` platform entry:\n\n```\nDEFAULT_PLATFORM_DB = {\n    ...\n    u'jlink': {\n        u'X729475D28G': {\n            u'platform_name': u'NRF51_DK',\n            u'jlink_device_name': u'nRF51422_xxAC'\n        },\n        ...\n    }\n}\n```\n\nInstead of a platform ID, there is a target-unique string (`X729475D28G` in this case). This should correspond with the unique part of the link present in the `Board.html` or `User Guide.html`. This seems to vary among the platforms. In general, try following the links in each file. You want to use the url that links to a product page that references the platform. The J-Link logic in Mbed LS assumes that the url has the target-unique string on the end (after the last `/` character). In the above example, the expected url structure would be `http://www.nordicsemi.com/X729475D28G`.\n\nIf your J-Link platform does not follow this convention, please raise an issue with the following information:\n\n- The name of the platform\n- The file **names and contents** present on the platform's filesystem\n- A link to the J-Link firmware binary if possible\n\n## Adding a new type of debugger\n\nThe type of debugger present on the platform affects how it is detected. The USB Vendor ID is used to detect which type of debugger is present on the platform.\n\nIf a new type of debugger is being introduced to Mbed LS with the platform, you will need to add the Vendor ID to the [identification map](../../src/mbed_os_tools/detect/lstools_base.py). You will also need to assign the correct \"update from the filesystem\" logic [here](../../src/mbed_os_tools/detect/lstools_base.py). If the debugger is compatible with the files presented by DAPLink, you may reuse that implementation when updating the device information from the filesystem. If it is not, you may need to write your own update logic. If you need guidance on this, please ask for it when you submit an issue or a pull request.\n\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "mbed-ls is a Python module that detects and lists mbed-enabled devices connected to the host computer",
    "version": "1.8.15",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "329d9a779e28d5b2097f750c5b1875d4578c0046453f3290012e194001f2328e",
                "md5": "8c236aa5b4b24e45df02505e058383b4",
                "sha256": "4670f02d0c30ce015c92ffcb7c4df67636060776bed903416b0c3d0dfd48fec2"
            },
            "downloads": -1,
            "filename": "mbed_ls-1.8.15-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8c236aa5b4b24e45df02505e058383b4",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=2.7.10, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4",
            "size": 37209,
            "upload_time": "2023-01-25T11:49:34",
            "upload_time_iso_8601": "2023-01-25T11:49:34.934811Z",
            "url": "https://files.pythonhosted.org/packages/32/9d/9a779e28d5b2097f750c5b1875d4578c0046453f3290012e194001f2328e/mbed_ls-1.8.15-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-25 11:49:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ARMmbed",
    "github_project": "mbed-os-tools",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "requirements": [
        {
            "name": "PySerial",
            "specs": [
                [
                    "<",
                    "4.0"
                ],
                [
                    ">=",
                    "3.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.0"
                ],
                [
                    "<",
                    "3.0"
                ]
            ]
        },
        {
            "name": "intelhex",
            "specs": [
                [
                    ">=",
                    "2.0"
                ],
                [
                    "<",
                    "3.0"
                ]
            ]
        },
        {
            "name": "future",
            "specs": []
        },
        {
            "name": "PrettyTable",
            "specs": [
                [
                    "<=",
                    "1.0.1"
                ]
            ]
        },
        {
            "name": "prettytable",
            "specs": [
                [
                    ">=",
                    "2.0"
                ],
                [
                    "<",
                    "3.0"
                ]
            ]
        },
        {
            "name": "fasteners",
            "specs": []
        },
        {
            "name": "appdirs",
            "specs": [
                [
                    "<",
                    "2.0"
                ],
                [
                    ">=",
                    "1.4"
                ]
            ]
        },
        {
            "name": "junit-xml",
            "specs": [
                [
                    "<",
                    "2.0"
                ],
                [
                    ">=",
                    "1.0"
                ]
            ]
        },
        {
            "name": "lockfile",
            "specs": []
        },
        {
            "name": "six",
            "specs": [
                [
                    "<",
                    "2.0"
                ],
                [
                    ">=",
                    "1.0"
                ]
            ]
        },
        {
            "name": "colorama",
            "specs": [
                [
                    "<",
                    "0.5"
                ],
                [
                    ">=",
                    "0.3"
                ]
            ]
        },
        {
            "name": "beautifulsoup4",
            "specs": []
        },
        {
            "name": "lxml",
            "specs": []
        }
    ],
    "test_requirements": [
        {
            "name": "coverage",
            "specs": [
                [
                    "<",
                    "5"
                ],
                [
                    ">=",
                    "4"
                ]
            ]
        },
        {
            "name": "coveralls",
            "specs": [
                [
                    "<",
                    "2"
                ],
                [
                    ">=",
                    "1"
                ]
            ]
        },
        {
            "name": "mock",
            "specs": [
                [
                    "<",
                    "4"
                ],
                [
                    ">=",
                    "2"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "<",
                    "5"
                ],
                [
                    ">=",
                    "3"
                ]
            ]
        },
        {
            "name": "wheel",
            "specs": [
                [
                    ">=",
                    "0.34"
                ]
            ]
        },
        {
            "name": "setuptools-scm",
            "specs": [
                [
                    ">=",
                    "4.1"
                ]
            ]
        }
    ],
    "lcname": "mbed-ls"
}
        
Elapsed time: 0.03487s