A template for writing CMSIS-Pack flash algorithms in Rust

Overview

Flash Algorithm Template

This is a flash algorithm template for writing CMSIS-Pack flash algorithms in Rust. It can be used to generate new flash algoritms for usage with probe-rs.

Actions Status chat

Dependencies

Run the following requirements:

cargo install cargo-generate cargo-binutils target-gen
rustup component add llvm-tools-preview

Instantiating the template

Run

cargo generate gh:probe-rs/flash-algorithm-template

or

cargo generate gh:probe-rs/flash-algorithm-template  --name=algorithm \
-d target-arch=thumbv7em-none-eabi \
-d ram-start-address=0x20000000 \
-d ram-size=0x4000 \
-d flash-start-address=0x0 \
-d flash-size=0x40000

to generate a new project from the template.

Developing the algorithm

Building requires nightly Rust.

Just run cargo run. It spits out the flash algo in the probe-rs YAML format and downloads it onto a target and makes a test run. You will also be able to see RTT messages.

You can find the generated YAML in target/definition.yaml.

License

This thingy is licensed under either of

at your option.

You might also like...
Opendp - The core library of differential privacy algorithms powering the OpenDP Project.

OpenDP The OpenDP Library is a modular collection of statistical algorithms that adhere to the definition of differential privacy. It can be used to b

Symmetric key-wrapping algorithms

RustCrypto: Key Wrapping Functions Collection of symmetric Key Wrapping Functions (KW) written in pure Rust. About "Key Wrapping" describes symmetric

Chargo is a tool for file encryption/decryption. It's based on Argon2 and ChaCha20Poly1305 algorithms.

| Documentation Chargo is a tool for file encryption/decryption with password. It's based on Argon2 and ChaCha20Poly1305 algorithms. From arg2u with ♥

🧩Creating a blockchain wallet and integrating a couple of cryptographic algorithms to securely save the secrets.🧩

Rust Library For Cryptocurrency Wallet Folder Structure src : contains the source code of the library examples : contains some examples of the library

Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️
Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️

Solana BPF Boilerplate Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana This boilerplate provides the following. Si

A blazing fast, type-safe template engine for Rust.

markup.rs A blazing fast, type-safe template engine for Rust. markup.rs is a template engine for Rust powered by procedural macros which parses the te

This is a template to build secret contracts in Rust to run in Secret Network

Secret Contracts Starter Pack This is a template to build secret contracts in Rust to run in Secret Network. To understand the framework better, pleas

A template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

🖨 Template for Rust applications & smart contracts @okp4.

Rust Template Template for Rust projects @okp4. Purpose & Philosophy This repository holds the template for building Rust projects with a consistent s

Comments
  • Panic -

    Panic - "Not all sectors were erased" while the flash has been wiped?

    Hi all,

    Firstly thanks for this great work! I've finally found something much more organized than CMSIS-Pack's flashing algorithm! I'm trying to implement a flash algorithm for STM32WLJC. Here's the implementation: https://github.com/huming2207/stm32wle5-flash-algo/blob/master/src/main.rs

    Then I tried running RUST_BACKTRACE=1 cargo run, here's what I've got:

    Test: Erasing sectorwise and writing two pages ...
    Message: Init
    Message: Erase sector addr:0x8000000
    Message: Erase sector addr:0x8000800
    thread 'main' panicked at 'Not all sectors were erased', /home/hu/.cargo/registry/src/github.com-1ecc6299db9ec823/target-gen-0.16.0/src/commands/test.rs:99:5
    stack backtrace:
       0: rust_begin_unwind
                 at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/panicking.rs:575:5
       1: core::panicking::panic_fmt
                 at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/panicking.rs:65:14
       2: target_gen::commands::test::cmd_test
       3: target_gen::main
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    

    However, if I use pyocd cmd and run rw 0x08000000 128, here's what I've got:

    pyocd> rw 0x08000000 4096
    08000000:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000010:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000020:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000030:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000040:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000050:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000060:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000070:  ffffffff ffffffff ffffffff ffffffff    |................|
    ...
    08000e40:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000e50:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000e60:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000e70:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000e80:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000e90:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000ea0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000eb0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000ec0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000ed0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000ee0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000ef0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f00:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f10:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f20:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f30:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f40:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f50:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f60:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f70:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f80:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000f90:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000fa0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000fb0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000fc0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000fd0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000fe0:  ffffffff ffffffff ffffffff ffffffff    |................|
    08000ff0:  ffffffff ffffffff ffffffff ffffffff    |................|
    

    As you see, the flash has been emptied.

    I've also checked the target-gen 's code and here's something that made me a bit confused: https://github.com/probe-rs/probe-rs/blob/dc5eb11ba23a5abfd1dd734385b93c7edd60f490/target-gen/src/commands/test.rs#L98

    I'm not sure why it's hardcoded to 0x0? I think it probably should be to whichever the microcontroller's flash base address is. For my STM32WLE5JC, it should be 0x08000000. May I ask, am I right? Have I misinterpreted something?

    Regards, Jackson

    opened by huming2207 5
  • Feature suggestion: read chip UID and self testing functions?

    Feature suggestion: read chip UID and self testing functions?

    Hi,

    I'm wondering if you guys would like to have some sort of self-testing or reading chip UID functions. I can implement something like that but I'm not sure if that might be out of scope for this project or not. But I believe it may be quite useful for mass production purposes.

    For example, I implement some functions (in C symbol, not Rust, that exposes to some customized offline programming probe or host-side debug program like probe-rs's YAML configs) like:

    • ReadChipUID(): read out the chip's unique ID (for STM32 it's 96-bit + some STM32s have an additional 64-bit unique MAC)
    • SelfTest(): do a simple, custom self-test, e.g. check if the UART/I2C/SPI communications with other external peripherals on the boards are working or not; return a zero result if successful, otherwise returns some non-zero values to indicate what has gone wrong.

    For ReadChipUID(), it can be done by asking the probe to read out the memory address directly (like STM32WL that's 0x1fff7590) but it's more for some sort of unification. Different chips have different UID addresses, and the host-side debug/mass production programs only need to call the same ReadChipUID() to retrieve the UID number without knowing where the address is.

    Regards, Jackson

    opened by huming2207 4
  • No RTT messages

    No RTT messages

    When running with cargo run, RTT messages are not printed.

    Actual behavior:

    Generating the YAML file in `"target/definition.yaml"`
    Test: Erasing sectorwise and writing two pages ...
    thread 'main' panicked at 'Not all sectors were erased'
    

    Expected:

    Generating the YAML file in `"target/definition.yaml"`
    Test: Erasing sectorwise and writing two pages ...
    Message: Init
    Message: Erase sector addr:0
    Message: Erase sector addr:8192
    thread 'main' panicked at 'Not all sectors were erased'
    

    This happens because target-gen disables the default rtt feature of probe-rs when installed according to the README.

    cargo install target-gen
    

    Installing target-gen with the feature enabled gives the expected behavior.

    cargo install target-gen --features probe-rs/rtt
    

    The README could be updated to suggest this, but I'm not sure if it makes more sense to change the default features of target-gen instead.

    opened by vccnfitingh 2
Owner
probe.rs
embedded tooling in rust
probe.rs
Port path module (and tests) of nodejs to rust using the same algorithms.

rusty_nodejs_path Port path module (and tests) of nodejs to rust using the same algorithms. crates.io Documents Progress posix path.basename(path[, ex

Yunfei He 10 Sep 25, 2022
Collection of block cipher algorithms written in pure Rust

RustCrypto: block ciphers Collection of block ciphers and block modes written in pure Rust. Warnings Currently only the aes crate provides constant-ti

Rust Crypto 506 Jan 3, 2023
A Rust Library of China's Standards of Encryption Algorithms (SM2/3/4)

Libsm Libsm is an open source pure rust library of China Cryptographic Algorithm Standards. It is completed by a collaborative effort between the Cryp

CITAHub 149 Dec 23, 2022
A Rust Implementation of China's Standards of Encryption Algorithms(SM2/SM3/SM4)

gm-rs A Pure Rust High-Performance Implementation of China's Standards of Encryption Algorithms(SM2/SM3/SM4) Usage Add this to your Cargo.toml: [depen

null 2 Oct 27, 2022
A general solution for commonly used crypt in rust, collection of cryptography-related traits and algorithms.

Crypto-rs A general solution for commonly used crypt in rust, collection of cryptography-related traits and algorithms. This is a Rust implementation

houseme 4 Nov 28, 2022
R1cs-tutorial - Tutorial for writing constraints in the `arkworks` framework

Introduction to SNARK Development with `arkworks` In this tutorial, we will learn how to write applications for use with state-of-the-art zkSNARKs usi

arkworks 113 Dec 29, 2022
Cryptographic signature algorithms: ECDSA, Ed25519

RustCrypto: signatures Support for digital signatures, which provide authentication of data using public-key cryptography. All algorithms reside in th

Rust Crypto 300 Jan 8, 2023
Collection of stream cipher algorithms

RustCrypto: stream ciphers Collection of stream cipher algorithms written in pure Rust. ⚠️ Security Warning: Hazmat! Crates in this repository do not

Rust Crypto 186 Dec 14, 2022
Authenticated Encryption with Associated Data Algorithms: high-level encryption ciphers

RustCrypto: Authenticated Encryption with Associated Data (AEAD) Algorithms Collection of Authenticated Encryption with Associated Data (AEAD) algorit

Rust Crypto 457 Jan 4, 2023
A collection of algorithms that can do join between two parties while preserving the privacy of keys on which the join happens

Private-ID Private-ID is a collection of algorithms to match records between two parties, while preserving the privacy of these records. We present tw

Meta Research 169 Dec 5, 2022