Code Monkey home page Code Monkey logo

msp430-test-g2231's Introduction

msp430-test-g2231

Just an example for msp430g2231, built on

msp430-quickstart

A template for building applications for TI MSP430 microcontrollers.

This project is developed and maintained by the MSP430 team.

TEST

Dependencies

  • Rust nightly-2022-01-24 or a newer toolchain. Only nightly compilers work for now.

    The rust-toolchain.toml file makes sure this step is done for you. This file tells rustup to download and use nightly compiler for this crate, as well as download the compiler source to build libcore.

    You can manually set up a nightly compiler as the default for all MSP430 projects by running:

    $ rustup default nightly
    $ rustup component add rust-src

    Alternatively, you can manually set up overrides on a project basis using:

    $ rustup override set --path /path/to/crate nightly-YYYY-MM-DD`.
    $ rustup component add --toolchain nightly-YYYY-MM-DD rust-src
  • The cargo generate subcommand (Installation instructions).

  • TI's MSP430 GCC Compiler, version 8.3.0 or greater. msp430-elf-gcc should be visible on the path.

The following dependencies are required in order to generate a peripheral access crate (see Using this template below)

  • svd2rust, version 0.20.0 or a newer commit.

  • msp430_svd, version 0.3.0 or a newer commit. Cloning the repo and following the directions in README.md is sufficient.

Using this template

  1. Before instantiating a project, you need to know some characteristics about your specific MSP430 device that will be used to fill in the template. In particular:

    • What is the exact part number of your device? Which MSP430 family does your part belong to?

    • Does your part have an already-existing peripheral access crate (PAC)?

    • How much flash memory, RAM, and how many interrupt vectors does your device have?

    • Where does flash memory, RAM, and interrupt vectors begin in the address space?

    msp430g2553 is used for the examples in this crate. Answering the first question above:

    The linked family manual and datasheet can be used to answer the remaining questions:

    • The msp430g2553 PAC exists already and can be found on crates.io.

    • msp430g2553 has 16kB of flash memory, 512 bytes of RAM, and 16 vectors.

    • Flash memory begins at address 0xC000. RAM begins at address 0x0200. The interrupt vectors begin at 0xFFE0.

  2. If your particular device does not have a PAC crate, you will need to generate one using svd2rust and possibly publish the crate to https://crates.io. To generate an SVD file, follow the directions in the msp430_svd README.md for your device.

    In some cases like msp430fr2355, TI's linker files are not consistent with datasheets on where interrupt vectors begin and how many interrupt vectors there are for a given device. In case of a conflict, examine the linker script to determine where to start the VECTORS section in memory.x. Copies of many linker scripts are kept in the msp430_svd repository.

  3. Instantiate the template and follow the prompts.

    $ cargo generate --git https://github.com/rust-embedded/msp430-quickstart
    Project Name: app
    Creating project called `app`...
    Done! New project created /tmp/app
    
    $ cd app
  4. If not targeting msp430g2553, replace the PAC entry for msp430g2553 in Cargo.toml with that of your device, e.g.:

    # [dependencies.msp430g2553]
    # version = "0.3.0"
    # features = ["rt"]
    [dependencies.msp430fr2355]
    version = "0.4.0"
    features = ["rt"]
  5. Populate the memory.x file with address space layout information of your device. Note: As mentioned above, in case of a conflict between the datasheet and linker script on where interrupt vectors begin, use the linker script!

    $ cat memory.x
    MEMORY
    {
      /* These values are correct for the msp430g2553 device. You will need to
         modify these values if using a different device. Room must be reserved
         for interrupt vectors plus reset vector and the end of the first 64kB
         of address space. */
      RAM : ORIGIN = 0x0200, LENGTH = 0x0200
      ROM : ORIGIN = 0xC000, LENGTH = 0x3FE0
      VECTORS : ORIGIN = 0xFFE0, LENGTH = 0x20
    }
  6. Build the template application or one of the examples. Some examples (such as timer or temp-hal) may not compile due to size constraints when building using the dev profile (the default). Pass the --release option to cargo build in these cases.

    $ cargo build
    $ cargo build --examples

    Note that due to .cargo/config and rust-toolchain.toml, the above is shorthand for:

    $ cargo +nightly build --target=msp430-none-elf -Zbuild-std=core
    $ cargo +nightly build --target=msp430-none-elf -Zbuild-std=core --examples

    You may wish to experiment with other commented options in .cargo/config.

  7. Once you have an ELF binary built, flash it to your microcontroller. Use mspdebug to launch a debug session and msp430-elf-gdb with the linked gdb script. For the msp430g2553 and the MSP-EXP430G2 launchpad board this looks like the following:

    In one terminal session

    $ mspdebug -C mspdebug.cfg rf2500

    In another terminal session

    $ msp430-elf-gdb -x mspdebug.gdb target/msp430-none-elf/debug/app

    This will flash your Rust code to the microcontroller and open a gdb debugging session to step through it.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

msp430-test-g2231's People

Contributors

tingox avatar

Watchers

 avatar

msp430-test-g2231's Issues

fails to link

build completes, but linking fails

[C:\Users\torfinn.ingolfsen\OneDrive - Inventas AS\Documents\Inventas\0_faglig\utvikling\rust\embedded\msp430-test-g2231] $ cargo build
   Compiling compiler_builtins v0.1.85
   Compiling core v0.0.0 (C:\Users\torfinn.ingolfsen\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core)
   Compiling proc-macro2 v1.0.50
   Compiling unicode-ident v1.0.6
   Compiling quote v1.0.23
   Compiling rand_core v0.6.4
   Compiling syn v1.0.107
   Compiling msp430-rt v0.4.0
   Compiling msp430g2231 v0.2.0 (https://github.com/tingox/msp430g2231#89bbcd07)
   Compiling rand v0.8.5
   Compiling rand_xoshiro v0.6.0
   Compiling msp430-rt-macros v0.4.0
   Compiling rustc-std-workspace-core v1.99.0 (C:\Users\torfinn.ingolfsen\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\rustc-std-workspace-core)
   Compiling critical-section v1.1.1
   Compiling vcell v0.1.3
   Compiling msp430 v0.4.1
   Compiling panic-msp430 v0.4.0
   Compiling msp430-test-g2231 v0.1.0 (C:\Users\torfinn.ingolfsen\OneDrive - Inventas AS\Documents\Inventas\0_faglig\utvikling\rust\embedded\msp430-test-g2231)
error: linking with `msp430-elf-gcc` failed: exit code: 1
  |
  = note: "msp430-elf-gcc" "C:\\Users\\TORFIN~1.ING\\AppData\\Local\\Temp\\rustc15mDp3\\symbols.o" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\msp430_test_g2231-61631bf75d8085f8.2k4jpbeaelp158da.rcgu.o" "-L" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps" "-L" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\debug\\deps" "-L" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\build\\msp430-rt-234a64ec35878595\\out" "-L" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\build\\msp430g2231-1482fcf1a53cd1f2\\out" "-L" "C:\\Users\\torfinn.ingolfsen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\msp430-none-elf\\lib" "-Wl,-Bstatic" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\libmsp430g2231-4e5510fabfa9328a.rlib" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\libvcell-75d629977897d950.rlib" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\libmsp430_rt-557135b41f274101.rlib" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\libpanic_msp430-05e6413d1ec79a2e.rlib" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\libmsp430-4b1e066d2184c51c.rlib" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\libcritical_section-96c96ff7585a30f8.rlib" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\librustc_std_workspace_core-d189d6ef5597a167.rlib" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\libcore-0d5e79c439c97b38.rlib" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\libcompiler_builtins-4b7734987d075df6.rlib" "-Wl,-Bdynamic" "-L" "C:\\Users\\torfinn.ingolfsen\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\msp430-none-elf\\lib" "-o" "C:\\Users\\torfinn.ingolfsen\\OneDrive - Inventas AS\\Documents\\Inventas\\0_faglig\\utvikling\\rust\\embedded\\msp430-test-g2231\\target\\msp430-none-elf\\debug\\deps\\msp430_test_g2231-61631bf75d8085f8" "-nodefaultlibs" "-Tlink.x" "-nostartfiles" "-mcpu=msp430" "-lmul_none" "-lgcc"
  = note: c:/ti/msp430-gcc/bin/../lib/gcc/msp430-elf/9.3.1/../../../../msp430-elf/bin/ld.exe:
          ERROR(msp430-rt): The VECTORS memory region must end at address 0x10000. Check memory.x
          c:/ti/msp430-gcc/bin/../lib/gcc/msp430-elf/9.3.1/../../../../msp430-elf/bin/ld.exe:
          ERROR(msp430-rt): .vector_table is shorter than expected.
          Possible solutions, from most likely to less likely:
          - Link to a svd2rust generated pac crate, if you are not
          - Fix _sinterrupts in memory.x; it doesn't match the number of interrupts provided by the
            pac crate
          - Disable the 'device' feature of msp430-rt to build a generic application; a dependency
          may be enabling it

          collect2.exe: error: ld returned 1 exit status


error: could not compile `msp430-test-g2231` due to previous error

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.