Giter Club home page Giter Club logo

psdb's Introduction

psdb

This package provides Python access to various ARM-compatible debug probes.

All tools support the --help option. It is required to use python3. The easiest way to install psdb is using pip:

pip3 install psdb

Note that you may wish to use sudo to install psdb for all users on your system:

sudo pip3 install psdb

You may also install the package from the source using:

make install

which will require super-user privileges. Alternatively, you can run all commands from the root of the repository without installing anything.

If you are on a Linux machine, it is also recommended to install the udev rules file that will allow non-sudo access to the debug probes (otherwise you must run the psdb tools using sudo) to anybody that is a member of the 'usb' group:

sudo addgroup usb
sudo adduser YOUR_USER_NAME usb
sudo cp -r etc/* /etc/

This command is not necessary on macOS since USB devices are accessible without super-user privileges. If your debug probe is connected when you install the udev rules, you may need to hot-plug it in order for the new rules to take effect. Also, if you just added yourself to the usb group then you will need to start a new shell session for that permission to take effect.

psdb_flash_tool

The flash_tool script allows you to burn ELF images into flash, retrieve the contents of flash and reset a target board. On STM32, it is highly recommended to use the --connect-under-reset option. This will reset the target MCU and halt in the reset handler before any code has a chance to execute and potentially interfere with the flashing operation. This is especially important on the STM32WB series where the flash is shared by the wireless coprocessor. Non-STM32 MCUs may not support connecting to the target while it is under reset (for instance, the MSP432 does not support this).

To dump the full flash contents to a file, generating a raw binary image (useful for making a backup of the original flash contents on a board):

psdb_flash_tool --connect-under-reset --read path/to/file.bin

To write a raw binary image into flash:

psdb_flash_tool --connect-under-reset --write--raw-binary path/to/file.bin

Flashing of ELF and Intel HEX files is also supported. In these cases, all address ranges that overlap with the flash will be burnt in, and other address ranges will be ignored. Note that the target sectors (and only the target sectors) are fully erased first, so any sectors that are under-specified in the ELF or HEX files will contain 0xFF in the unused regions. To flash an ELF or HEX file:

psdb_flash_tool --connect-under-reset --flash path/to/image.elf
psdb_flash_tool --connect-under-reset --flash path/to/image.hex

Finally, erasing the flash is also supported. All writeable sectors will be erased to the value 0xFF:

psdb_flash_tool --connect-under-reset --erase

The flash_tool script can also be used to view and modify the STM32 option bytes stored in the MCU's flash. The --get-options flag allows one to dump the contents of all option bytes:

psdb_flash_tool --connect-under-reset --get-options

While the --option argument (which takes two parameters - a case-insensitive option name and an option value) can be specified multiple times to change options:

psdb_flash_tool --connect-under-reset --option nboot1 0 --option nboot0 1

psdb_core_tool

The core_tool script can be used to capture the contents of flash and SRAM in the form of an ELF core file. This core file, in conjunction with the original ELF executable, can be opened under gdb for offline diagnosis. Unfortunately, the standard arm-none-eabi-gdb tool cannot open core files; however, gdb-multiarch is able to open these without any trouble. On Linux, this is as simple as installing gdb-multiarch with your package manager. On other systems, installing in a Docker container may be a viable alternative.

The --peripheral-capture option allows the capture of all registers from devices listed in the target's dev array.

The captured core file is independent of the build system used to generate the executable or the actual code installed on the microcontroller. To debug the core file:

gdb-multiarch path/to/executable.elf
target core path/to/core.elf

psdb_gdb_tool

The gdb_tool script starts a simple gdb server that attaches to the target device. It can be connected to with a remote gdb client.

psdb_inspect_tool

The inspect_tool script starts an interactive curses-based tool that can be used to view the current CPU registers, select target peripheral registers and select regions of target RAM or flash. The inspect_tool script requires the tgcurses library to be installed (available on github/tgree). pip will install tgcurses automatically.

psdb_fus_tool

The fus_tool script is for interacting with the ST Firmare Upgrade Services (FUS) on the STM32WB55 wireless MCU. The STM32WB55 co-processor has a secure region of flash that includes the FUS binary itself and the wireless stack currently installed on the MCU. Different wireless stacks can be installed and FUS itself can also be upgraded. The binaries can be found in ST's STM32CubeWB.git repository under the path:

Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x

Sample invocations for manipulating wireless firmware:

psdb_fus_tool --fw-upgrade Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_BLE_Stack_full_fw.bin
psdb_fus_tool --fw-delete

Or, a compound command to remove the old WS firmware, install new WS firmware and then start the application back up:

psdb_fus_tool \
    --fw-delete \
    --fw-upgrade Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_BLE_Stack_full_fw.bin \
    --set-flash-boot

Note that an invocation with --set-flash-boot is required when you are done; in order to properly communicate with FUS, we need to prevent any user firmware from starting CPU2 or trying to use the IPC channels - we do that by switching the system to boot from SRAM1 until we are done with it.

When using this to upgrade FUS itself, you use the --fus-upgrade option along with the --bin-dir option. The code will find the next valid FUS binary in the upgrade path for your target. For instance, a brand new Nucleo STM32WB55 board has an ancient 0.5.3 version of FUS. This cannot be directly upgraded to the latest 1.1.0 version of FUS but must instead stop at 1.0.2 first. You can then reinvoke fus_tool again if you wish to then upgrade from 1.0.2 to 1.1.0. Note that it is not possible to downgrade FUS, so this behavior allows you to stop at any desired version. When upgrading FUS, it is required to first delete the current wireless stack with the --fw-delete option.

Sample invocation for updating FUS:

psdb_fus_tool --bin-dir Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x --fus-upgrade

Note that when upgrading FUS, the target board will reboot at least 4 times.

It is recommended to upgrade to FUS 1.1.0.

STLINK Protocol

We also attempt to document the STLINK protocol inside the stlink package. You can view it most easily from within the python interpreter:

>>> import psdb.probes.stlink
>>> help(psdb.probes.stlink.cdb)

psdb's People

Contributors

tgree avatar tgreeniaus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mfkiwl jtagnexus

psdb's Issues

Maintaining binaries.py for STM32WB

Hi, thanks for this, really helps me get up the learning curve for this part. I believe what's happening is binaries.py has not been updated with the ST releases. eg. stm32wb5x_BLE_LLD_fw.bin is not there.
I can follow the pattern and add more entries, cite the docs and submit a PR.
Can you advise?

error erasing/writing, Mac M1, stlink-v3 mini

I'm getting this error:

'''
erwincoumans@Erwins-MBP build % psdb_flash_tool --connect-under-reset --erase
Probing with SWD frequency at 1.000 MHz
Set SWD frequency to 24.000 MHz
Erasing entire flash...
Traceback (most recent call last):
File "/opt/homebrew/bin/psdb_flash_tool", line 8, in
sys.exit(_main())
File "/opt/homebrew/lib/python3.10/site-packages/psdb/flash_tool.py", line 173, in _main
main(rv)
File "/opt/homebrew/lib/python3.10/site-packages/psdb/flash_tool.py", line 86, in main
target.flash.erase_all()
File "/opt/homebrew/lib/python3.10/site-packages/psdb/devices/stm32h7/flash.py", line 219, in erase_all
with self._flash_bank_unlocked(self.banks[1]):
IndexError: list index out of range
'''

Since nbanks=1, I removed access to bank[1] and now it succeeds, but another error:

'''
Unexpected error 0x11 at 0x08000020
'''

Any idea?

Can't reach you by mail

Hi Terry,

I wrote you back but the email can't be delivered.

Error:

Message delivery to '[email protected]' delayed SMTP module(domain phasesensors.com) reports:
connection with smtp.secureserver.net is broken

-Gerard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.