Skip to content

Simple blinking LED example that runs on the MSP430-FR4133

License

Notifications You must be signed in to change notification settings

stianeklund/rust_on_msp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust_on_msp

Simple blinking LED example that runs on MSP430.

This is a fork of the original rust_on_msp made for the MSP430FR4133

Compiling

This project can be compiled using nightly rust and xargo.

Tested using version rustc 1.16.0-nightly (4ecc85beb 2016-12-28)

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
  • Until issue #38824 is fixed, we need to use older version of nightly compiler. You can get it using this commands:
rustup default nightly-2016-12-29
rustup override set nightly-2016-12-29
rustup component add rust-src
  • 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:
#[no_mangle]
#[link_section = "__interrupt_vector_reset"]
pub static RESET_VECTOR: unsafe extern "C" fn() -> ! = main;

RESET_VECTOR is just a function pointer that gets placed inside a special section called __interrupt_vector_reset and is pointing to main function, so it will be called on reset. Other interrupts may be defined the same way for example __interrupt_vector_timer0_a0, but it is not possible to use interrupts yet (other than reset), because rust doesn't have a special calling convention for MSP430 interrupts. A workaround would be to use #[naked] functions. You can follow the discussion here: #38465

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).

The MSP430 package contents contains ldscripts, e.g on Ubuntu & Debian distro's this can be found under /usr/msp430/lib/ldscripts post install of the msp430mcu package.

  • 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 board with MSP430FR4133 MCU, but it is easy to port this code for any other board or MCU. board

About

Simple blinking LED example that runs on the MSP430-FR4133

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 98.9%
  • Other 1.1%