pyOCD-一个基于python的开源Cortex-M单片机调试工具

news/2024/7/10 21:45:30 标签: python, 开源, 单片机, stm32, ci/cd

pyOCD 是一个基于 Python 的工具和 API,用于调试、编程和探索 Arm Cortex 微控制器。它支持通过命令行或 IDE(如 VSCode Cortex-Debug 插件和 Eclipse Embedded CDT)使用 gdb 进行调试,支持将固件和数据镜像编程到内部或外部闪存中,也可以将镜像加载到 RAM 中。它还提供了一个简单的 API,非常适合用于 CI、定制测试和调试工具、安全研究等。此外,pyOCD 还支持 Semihosting 和 SWV,具有完整的半主机实现,包括控制台和文件 I/O。它内置了对超过 70 种流行 MCU 的支持,并且通过使用 CMSIS 设备族包,几乎市面上所有的 Cortex-M 设备都能得到支持。

pyOCD

特性

  • gdbserver
    • 支持在命令行或IDE中使用gdb进行调试,可以在VSCode Cortex-Debug 插件和Eclipse Embedded CDT中使用。
  • flash programming
    • 将固件和数据映像烧写到内部或外部flash,也可以载入到ram中。
  • python API
    • 通过简单的 API 完全控制目标设备,高度 适用于 CI、定制测试和调试工具、安全研究等。
  • semihosting and SWV
    • 具有控制台和文件 I/O 的完整半托管实现。 SWV 基本 printf 输出, 通过TCP/IP流式传输原始SWO数据,在Python中构建SWO事件处理数据流图。
  • CMSIS-Packs
    • 访问 CMSIS 设备系列包支持的全套 Arm Cortex-M 设备。包装罐 由 pyOCD 管理并按部件号安装,或自行下载包。
  • built-in devices
    • 内置了对 70 多种常见 Arm Cortex-M 设备的支持。

命令行工具

pyocd命令行工具通过以下子命令提供了对目标设备的完全控制:

  • gdbserver: GDB remote server allows you to debug using gdb via either the console or
    several GUI debugger options.
  • load: Program files of various formats into flash or RAM.
  • erase: Erase part or all of an MCU’s flash memory.
  • pack: Manage CMSIS Device Family Packs
    that provide additional target device support.
  • commander: Interactive REPL control and inspection of the MCU.
  • server: Share a debug probe with a TCP/IP server.
  • reset: Hardware or software reset of a device.
  • rtt: Stream Segger RTT IO with any debug probe.
  • list: Show connected devices.

API

python API提供了以下特性:

  • halt, step, resume control
  • read/write memory
  • read/write core registers
  • set/remove hardware and software breakpoints
  • set/remove watchpoints
  • write to flash memory
  • load binary, hex, or ELF files into flash
  • reset control
  • access CoreSight DP and APs
  • SWO and SWV
  • and more!

可以通过配置文件和用户脚本来实现更多个性化功能。

Requirements

  • Python 3.6.0 or later.
  • macOS, Linux, Windows 7 or newer, or FreeBSD
  • A recent version of libusb. See libusb installation for details.
  • Microcontroller with an Arm Cortex-M CPU
  • Supported debug probe
    • CMSIS-DAP v1 (HID) or v2 (WinUSB), including:
      • Atmel EDBG/nEDBG
      • Atmel-ICE
      • Cypress KitProg3 or MiniProg4
      • DAPLink based debug probe, either on-board or standalone
      • Keil ULINKplus
      • NXP LPC-LinkII
      • NXP MCU-Link
    • PE Micro Cyclone and Multilink
    • Raspberry Pi Picoprobe
    • SEGGER J-Link
    • STLinkV2 or STLinkV3, either on-board or the standalone versions

Version 0.29 is the last version to support Python 2.

安装

最简单的方式就是通过pip安装:

pip install -U pyocd

使用python建立工作环境时,始终在虚拟环境中进行操作是个好习惯,强烈建议用condapython自带虚拟环境工具建立工作环境。

更全面的安装说明请参阅 documentation.

为树莓派等非 x-86 平台系统安装请参阅relevant documentation。

注意,在不同平台上安装时可能会遇到权限问题,可以参考以下方法解决:

  1. Under Linux, run with sudo -H to install pyOCD and dependencies globally.
  2. On macOS, installing with sudo should never be required, although sometimes permissions can become modified such that installing without using sudo fails.
  3. Specify the --user option to install local to your user account.
  4. Run the command in a virtualenv local to a specific project working set.

验证下安装:

❯ pyocd -h
usage: pyocd [-h] [-V] [--help-options]  ...

PyOCD debug tools for Arm Cortex devices

optional arguments:
  -h, --help       show this help message and exit
  -V, --version    show program version number and exit
  --help-options   Display available session options.

subcommands:

    commander (cmd)
                   Interactive command console.
    erase          Erase entire device flash or specified sectors.
    load (flash)   Load one or more images into target device memory.
    gdbserver (gdb)
                   Run the gdb remote server(s).
    json           Output information as JSON.
    list           List information about probes, targets, or boards.
    pack           Manage CMSIS-Packs for target support.
    reset          Reset a target device.
    server         Run debug probe server.
    rtt            SEGGER RTT Viewer.

❯ pyocd -V
0.34.3

http://www.niftyadmin.cn/n/220568.html

相关文章

MongoDB 聚合管道中使用数组表达式运算符($slice截取数组)

数组表达式运算符主要用于文档中数组的操作&#xff0c;本篇我们主要介绍数组表达式运算符中用于截取数组的操作&#xff0c;下面我们进行详细介绍&#xff1a; 一、语法 { $slice: [ <array>, <n> ] } 或者 { $slice: [ <array>, <position>, <…

实验手册 - 第7周Spark DataFrame

目录标题DataFrame实验内容实验1实验2实验3DataFrame 官方解释&#xff1a; DataFrame RDD[Person] - 泛型 Schema SQL操作 优化官方原文&#xff1a;A DataFrame is a DataSet organized into named columns.中文翻译&#xff1a;以列&#xff08;列名&#xff0c;列类型…

1.Antlr4-简介入门

1.简介: ANTLR v4是一款功能强大的语法分析器生成器&#xff0c;可以用来读取、处理、执行和转换结构化文本或二进制文件。它被广泛应用于学术界和工业界构建各种语言、工具和框架。 2 关键字&#xff1a; import, fragment, lexer, parser, grammar, returns, locals, throw…

助力工业物联网,工业大数据之ODS层构建:需求分析【八】

文章目录01&#xff1a;ODS层构建&#xff1a;需求分析02&#xff1a;ODS层构建&#xff1a;创建项目环境03&#xff1a;ODS层构建&#xff1a;代码导入01&#xff1a;ODS层构建&#xff1a;需求分析 目标&#xff1a;掌握ODS层构建的实现需求 路径 step1&#xff1a;目标step…

NumPy 数组学习手册:1~5

原文&#xff1a;Learning NumPy Array 协议&#xff1a;CC BY-NC-SA 4.0 译者&#xff1a;飞龙 一、NumPy 入门 让我们开始吧。 我们将在不同的操作系统上安装 NumPy 和相关软件&#xff0c;并查看一些使用 NumPy 的简单代码。 正如“序言”所述&#xff0c;SciPy 与 NumPy 密…

HTML5 表单属性

文章目录HTML5 表单属性HTML5 新的表单属性\<form> / \<input> autocomplete 属性\<form> novalidate 属性\<input> autofocus 属性\<input> form 属性\<input> formaction 属性\<input> formenctype 属性\<input> formmethod…

洛谷题单 Part 8.1 图的存储与遍历

这周末程设期末小米杯&#xff0c;多复习复习找找手感&#xff0c;从图论开始吧&#xff0c;正好现在大晚上不想做太多题&#xff0c;这个专题第一个部分就俩题哈哈哈&#xff0c;懒死我得了 P2661 [NOIP2015 提高组] 信息传递 题面 Solution:Solution:Solution:利用并查集&a…

如何获取系统下目录的文件系统类型

最近看到一个问题&#xff0c;如何获取当前系统的文件类型&#xff1f; 这个时候就要介绍下/proc/mounts文件&#xff1a;这个文件以/etc/mtab文件的格式给出当前系统所安装的文件系统信息。同时也能反映出任何手工安装从而在/etc/mtab文件中没有包含的文件系统。 我们可以通…