adoble / blink-cortex-m0

Blink program written in Rust for the Adafruit Feather M0 (Cortex-M0 processor)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

blink-cortex-m0

Simple blink program written in Rust for the Adafruit Feather M0 board.

This project has been generated using the cortex-mo-quickstart.

What follows is explicit for the Adafruit Feather M0 and this project.

Dependencies

To build embedded programs using this template you'll need:

  • Rust 1.31, 1.30-beta, nightly-2018-09-13 or a newer toolchain. e.g. rustup default beta

  • The cargo generate subcommand. Installation instructions.

  • rust-std components (pre-compiled core crate) for the ARM Cortex-M targets. Run:

$ rustup target add thumbv6m-none-eabi thumbv7m-none-eabi thumbv7em-none-eabi thumbv7em-none-eabihf

Using this template

NOTE: This is the very short version that only covers building programs. For the long version, which additionally covers flashing, running and debugging programs, check the embedded Rust book.

  1. Before we begin you need to identify some characteristics of the target device as these will be used to configure the project:
  • The ARM core. e.g. Cortex-M3.

  • Does the ARM core include an FPU? Cortex-M4F and Cortex-M7F cores do.

  • How much Flash memory and RAM does the target device has? e.g. 256 KiB of Flash and 32 KiB of RAM.

  • Where are Flash memory and RAM mapped in the address space? e.g. RAM is commonly located at address 0x2000_0000.

You can find this information in the data sheet or the reference manual of your device.

In this project we are using the Adafruit Feather M0 (and older version).

  1. Instantiate the template.
$ cargo generate --git https://github.com/rust-embedded/cortex-m-quickstart
 Project Name: blink-cortex-m0
 
$ cd app
  1. Set a default compilation target. There are four options as mentioned at the bottom of .cargo/config. For the Adafruit Feather M0, which has a Cortex-M0 core, we'll pick the thumbv6m-none-eabi target.
$ Edit .cargo/config
[build]
# Pick ONE of these compilation targets
target = "thumbv6m-none-eabi"    # CortexM0 and Cortex-M0+
# target = "thumbv7m-none-eabi"    # Cortex-M3
# target = "thumbv7em-none-eabi"   # Cortex-M4 and Cortex-M7 (no FPU)
# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
  1. Edit the dependencies in .\Cargo.toml
[dependencies]
cortex-m = "0.6.0"
cortex-m-rt = "0.6.10"
cortex-m-semihosting = "0.3.3"
panic-halt = "0.2.0"
feather_m0 = "0.10.1"

Orginally tried:

[dependencies]
panic-halt = "0.2.0"
feather_m0 = { git = "https://github.com/atsamd-rs/atsamd" }

This worked, but it seems some changes in the quickstart repo have caused a build error. Maybe this will work later.

  1. Enter the memory region information into the memory.x file. This information comes from another project.
MEMORY
{
  /* Leave 8k for the default bootloader on the Feather M0 */
  FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K
  RAM (xrw)  : ORIGIN = 0x20000000, LENGTH = 32K
}
_stack_start = ORIGIN(RAM) + LENGTH(RAM);
  1. Place the code in main.rs under ./src

  2. Build the appplication.

$ cargo build
  1. Copy the generated code over to a binary suitable for flashing.
$ objcopy -O binary .\target\thumbv6m-none-eabi\debug\blink-cortex-m0 .\target\thumbv6m-none-eabi\debug\blink-cortex-m0.bin

Also experimented with:

$  cargo objcopy -- -O binary  .\target\thumbv6m-none-eabi\debug\blink-context-m0.bin

Need to first install cargo-binutils.

But had little success!

  1. Flash the microcontroller. Note that the old version of the Feather M0 being used does not have the HF2 bootloader so have to use this the bossac command. Windows:
$ bossac -p COM7 -e -w -v -R  .\target\thumbv6m-none-eabi\debug\blink-cortex-m0.bin

Unix:

For version 1.9! Note the offset! Getting this wrong can brick the microcontroller.

$ bossac -p COM7 -e -w -v -R  --offset=0x2000 .\target\thumbv6m-none-eabi\debug\blink-cortex-m0.bin  
  1. The red led and any led connected to pin D7 should blink.

Debugging

Do not think that I can use OCD for debugging as the feather board does not have the corrresponding debugger chip. Problem as most of the examples in the cortex-m-quickstart use this to output something.

Note that openOSD is supplied with the Ardunino IDE. See this video.

Useful Links

About

Blink program written in Rust for the Adafruit Feather M0 (Cortex-M0 processor)


Languages

Language:Rust 73.9%Language:GDB 26.1%