Code Monkey home page Code Monkey logo

stm32loader's Introduction

STM32Loader

PyPI package Build Status License Downloads

Python script to upload or download firmware to / from ST Microelectronics STM32 microcontrollers over UART.

Also supports ST BlueNRG devices, and the SweetPeas bootloader for Wiznet W7500.

Compatible with Python version 3.4 to 3.8.

Usage

./stm32loader [-hqVewvrsRB] [-l length] [-p port] [-b baud] [-P parity] [-a address] [-g address] [-f family] [file.bin]
    --version   Show version number and exit
    -e          Erase (note: this is required on previously written memory)
    -u          Readout unprotect
    -w          Write file content to flash
    -v          Verify flash content versus local file (recommended)
    -r          Read from flash and store in local file
    -l length   Length of read
    -p port     Serial port (default: /dev/tty.usbserial-ftCYPMYJ)
    -b baud     Baud speed (default: 115200)
    -a address  Target address (default: 0x08000000)
    -g address  Start executing from address (0x08000000, usually)
    -f family   Device family to read out device UID and flash size; e.g F1 for STM32F1xx

    -h          Print this help text
    -q          Quiet mode
    -V          Verbose mode

    -s          Swap RTS and DTR: use RTS for reset and DTR for boot0
    -R          Make reset active high
    -B          Make boot0 active low
    -u          Readout unprotect
    -n          No progress: don't show progress bar
    -P parity   Parity: "even" for STM32 (default), "none" for BlueNRG

Example

stm32loader -p /dev/tty.usbserial-ftCYPMYJ -e -w -v somefile.bin

This will pre-erase flash, write somefile.bin to the flash on the device, and then perform a verification after writing is finished.

You can skip the -p option by configuring environment variable STM32LOADER_SERIAL_PORT. Similarly, -f may be supplied through STM32LOADER_FAMILY.

To read out firmware and store it in a file:

stm32loader -r -p /dev/cu.usbserial-A5XK3RJT -f F1 -l 0x10000 -a 0x08000000 dump.bin 

Reference documents

  • ST AN2606: STM32 microcontroller system memory boot mode
  • ST AN3155: USART protocol used in the STM32 bootloader
  • ST AN4872: BlueNRG-1 and BlueNRG-2 UART bootloader protocol

Acknowledgement

Original Version by Ivan A-R (tuxotronic.org). Contributions by Domen Puncer, James Snyder, Floris Lambrechts, Atokulus, sam-bristow, NINI1988, Omer Kilic, Szymon Szantula, rdaforno, Mikolaj Stawiski, Tyler Coy, Alex Klimaj, Ondrej Mikle.

Inspiration for features from:

Electrically

The below assumes you are connecting an STM32F10x. For other chips, the serial pins and/or the BOOT0 / BOOT1 values may differ.

Make the following connections:

  • Serial adapter GND to MCU GND.
  • Serial adapter power to MCU power or vice versa (either 3.3 or 5 Volt).
  • Note if you're using 5 Volt signaling or 3V3 on the serial adapter.
  • Serial TX to MCU RX (PA10).
  • Serial RX to MCU TX (PA9).
  • Serial DTR to MCU RESET.
  • Serial RTS to MCU BOOT0 (or BOOT0 to 3.3V).
  • MCU BOOT1 to GND.

If either RTS or DTR are not available on your serial adapter, you'll have to manually push buttons or work with jumpers. When given a choice, set BOOT0 manually high and drive reset through the serial adepter (it needs to toggle, whereas BOOT0 does not).

Not currently supported

  • Command-line argument for readout protection
  • Command-line argument for write protection/unprotection
  • STM8 devices (ST UM0560)
  • Paged flash erase for devices with page size <> 1 KiB
  • Other bootloader protocols (e.g. I2C, HEX -> implemented in stm32flash)

Future work

  • Use proper logging instead of print statements
  • Try Azure pipelines for CI
  • Support PyPy, PyPy3
  • Drop Python2 support; start using intenum for commands and replies
  • Determine flash page size or make this configurable

stm32loader's People

Contributors

florisla avatar jsnyder avatar byq77 avatar omerk avatar atokulus avatar stawiski avatar hiviah avatar sam-bristow avatar float32 avatar alexklimaj avatar

Watchers

James Cloos avatar

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.