Giter Site home page Giter Site logo

rust_on_msp's Introduction

rust_on_msp [deprecated]

Simple blinking LED example that runs on MSP430.

Deprecated

This project is deprecated in favor of msp430* crates on crates.io.

msp430 and msp430-rt crates are based on cortex-m* crates by @japaric. Device crates are generated using svd2rust. SVD files for msp430 microcontrollers can be generated by msp430_svd tool.

You can find code examples in msp430-quickstart repository.

There is also a real firmware that is using this framework: AT2XT.

Compiling

This project can be compiled using nightly rust and xargo.

Tested using version rustc 1.21.0-nightly (37c7d0ebb 2017-07-31)

Steps:

  • First, install msp430-elf-gcc compiler, and make sure it is in your $PATH. You can get it from here.

  • Install nightly rust: $ rustup default nightly

  • Install xargo: $ cargo install xargo

  • Build the project: $ make

  • or you can build it using xargo directly (if you don't like make)

    $ xargo build --release --target msp430

  • Flash the firmware using mspdebug: $ make prog

How it works

This project is does not use default startup code from gcc, so a reset handler should be defined like this:

#[used]
#[link_section = "__interrupt_vector_reset"]
static RESET_VECTOR: unsafe extern "msp430-interrupt" fn() = reset_handler;

RESET_VECTOR is just a function pointer that gets placed inside a special section called __interrupt_vector_reset and is pointing to reset_handler function, so it will be called on reset.

reset_handler function is defined in global_asm! block because it needs to set stack pointer as it's first instruction during startup. Handlers for other interrupts doesn't need this, so they can be written in rust. For example handler for timer_a0 interrupt can be defined like this:

#[used]
#[link_section = "__interrupt_vector_timer0_a0"]
static TIM0_VECTOR: unsafe extern "msp430-interrupt" fn() = timer0_handler;

unsafe extern "msp430-interrupt" fn timer0_handler() {
    // you can do something here
}

Porting to other boards and MCUs

To run this code on the other boards and MCUs, you need to change it in few places:

  • Get a linker script for your MCU from msp430-elf-gcc include directory, and place it inside ldscripts folder. (Don't forget to get *_symbols.ld one as well).
  • Modify .cargo/config file so it would point to your ld script from step 1 and change linker flags to match your MCU name.
  • Modify build.rs script so it would copy the right ld script from step 1.

Board

I am using TI LaunchPad G2 board with msp430g2553 MCU, but it should be easy to port this code for any other board or MCU.

board

rust_on_msp's People

Contributors

pftbest avatar vadzimdambrouski avatar rawrafox avatar japaric avatar

Stargazers

Jan Tobias Muehlberg avatar Roman Silberschneider avatar  avatar Christopher Woodall avatar DiGiTAL_CuRSe avatar Stian Eklund  avatar Matthew Iannucci avatar Emanuel Alasu avatar Cody Schafer avatar  avatar

Watchers

James Cloos avatar  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.