Woyten | fbf1ffc | 2018-03-19 23:10:33 +0100 | [diff] [blame] | 1 | [](https://travis-ci.org/tock/libtock-rs) |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 2 | |
Amit Levy | bf8fec8 | 2017-05-10 14:43:48 -0400 | [diff] [blame] | 3 | # libtock-rs |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 4 | |
Amit Levy | bf8fec8 | 2017-05-10 14:43:48 -0400 | [diff] [blame] | 5 | Rust userland library for Tock (WIP) |
Pat Pannuto | 287a8ae | 2017-05-10 18:19:21 -0400 | [diff] [blame] | 6 | |
torfmaster | 2740ae4 | 2019-11-22 16:09:16 +0100 | [diff] [blame] | 7 | Tested with tock [Release 1.4.1](https://github.com/tock/tock/commit/7e37bf67761d83fd585cace4fb201e2864d300b1). |
Florian Hars | 5cf866b | 2019-10-14 02:32:51 +0200 | [diff] [blame] | 8 | |
Florian Hars | 70791a3 | 2019-10-14 18:32:56 +0200 | [diff] [blame] | 9 | The library works in principle on most boards, but there is currently the [showstopper |
Florian Hars | 5cf866b | 2019-10-14 02:32:51 +0200 | [diff] [blame] | 10 | bug #28](https://github.com/tock/libtock-rs/issues/28) that prevents |
| 11 | the generation of relocatable code. This means that all applications |
| 12 | must be installed at the flash address they are compiled with, which |
Florian Hars | 70791a3 | 2019-10-14 18:32:56 +0200 | [diff] [blame] | 13 | usually means that they must be compiled especially for your board |
| 14 | and that there can only be one application written in rust at a time |
Florian Hars | 5cf866b | 2019-10-14 02:32:51 +0200 | [diff] [blame] | 15 | and it must be installed as the first application on the board, unless |
| 16 | you want to play games with linker scripts. |
Alistair Francis | b3e3a9a | 2020-03-09 16:36:44 -0700 | [diff] [blame] | 17 | There are some `boards/layout_*.ld` files provided that allow to run the |
Florian Hars | 7d9d856 | 2019-10-16 11:56:54 +0200 | [diff] [blame] | 18 | examples on common boards. |
| 19 | Due to MPU region alignment issues they may not work for applications |
| 20 | that use a lot of RAM, in that case you may have to change the SRAM |
| 21 | start address to fit your application. |
Philipp Vollmer | 090398c | 2018-06-29 15:14:54 +0200 | [diff] [blame] | 22 | |
Pat Pannuto | 287a8ae | 2017-05-10 18:19:21 -0400 | [diff] [blame] | 23 | ## Getting Started |
| 24 | |
| 25 | This project is nascent and still under heavy development, but first steps: |
| 26 | |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 27 | 1. Ensure you have [rustup](https://www.rustup.rs/) installed. |
Pat Pannuto | 00bb198 | 2017-08-17 00:02:37 -0700 | [diff] [blame] | 28 | |
JOE1994 | 51168c9 | 2020-04-27 17:05:34 -0400 | [diff] [blame^] | 29 | 2. Clone the repository: |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 30 | |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 31 | ```shell |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 32 | git clone https://github.com/tock/libtock-rs |
Woyten | 97b27b0 | 2018-06-19 20:44:59 +0200 | [diff] [blame] | 33 | cd libtock-rs |
| 34 | ``` |
| 35 | |
JOE1994 | 51168c9 | 2020-04-27 17:05:34 -0400 | [diff] [blame^] | 36 | 3. Install the dependencies: |
Woyten | 97b27b0 | 2018-06-19 20:44:59 +0200 | [diff] [blame] | 37 | |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 38 | ```shell |
| 39 | make setup |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 40 | ``` |
| 41 | |
JOE1994 | 51168c9 | 2020-04-27 17:05:34 -0400 | [diff] [blame^] | 42 | 4. Use `make` to build examples |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 43 | |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 44 | ```shell |
| 45 | make nrf52 # Builds all examples for the nrf52 platform |
Teddy Katz | bc37685 | 2018-04-02 16:39:46 -0400 | [diff] [blame] | 46 | ``` |
| 47 | |
torfmaster | 02f000a | 2020-01-05 02:16:00 +0100 | [diff] [blame] | 48 | ```bash |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 49 | make opentitan # Builds all examples for the OpenTitan platform |
Woyten | 860e0bc | 2020-01-29 21:17:14 +0100 | [diff] [blame] | 50 | ``` |
torfmaster | cf1018c | 2019-02-11 19:35:24 +0100 | [diff] [blame] | 51 | |
Alistair Francis | 55e3d6b | 2020-03-10 14:04:22 -0700 | [diff] [blame] | 52 | ```bash |
| 53 | make opentitan FEATURES=alloc # Builds all examples for the OpenTitan platform, with alloc feature enabled |
| 54 | ``` |
| 55 | |
JOE1994 | 51168c9 | 2020-04-27 17:05:34 -0400 | [diff] [blame^] | 56 | ```bash |
| 57 | make flash-hail EXAMPLE=blink # Flash the example 'blink' program to the hail platform |
| 58 | ``` |
| 59 | |
Alistair Francis | cb3d5b8 | 2020-03-10 13:43:48 -0700 | [diff] [blame] | 60 | For an unknown platform, you may have to create your own memory layout definition. Place the layout definition file at `boards/layout_<platform>.ld` and do not forget to enhance the `tockloader_flags` dispatching section in `tools/flash.sh`. You are welcome to create a PR, s.t. the number of supported platforms grows. |
Florian Hars | 5dbdd50 | 2019-10-15 20:10:56 +0200 | [diff] [blame] | 61 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 62 | ## Using libtock-rs |
| 63 | |
| 64 | The easiest way to start using libtock-rs is adding an example to the examples folder. |
| 65 | The boiler plate code you would write is |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 66 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 67 | ```rust |
| 68 | #![no_std] |
| 69 | |
Woyten | 82633c1 | 2019-11-27 18:29:17 +0100 | [diff] [blame] | 70 | use libtock::result::TockResult; |
| 71 | |
torfmaster | ac39e92 | 2019-12-17 09:37:38 +0100 | [diff] [blame] | 72 | #[libtock::main] |
Woyten | 82633c1 | 2019-11-27 18:29:17 +0100 | [diff] [blame] | 73 | async fn main() -> TockResult<()> { |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 74 | // Your code |
| 75 | } |
| 76 | ``` |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 77 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 78 | If you want to use heap based allocation you will have to add |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 79 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 80 | ```rust |
torfmaster | 9ca48f0 | 2019-11-15 08:49:36 +0100 | [diff] [blame] | 81 | extern crate alloc; |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 82 | ``` |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 83 | |
Woyten | f0b3e08 | 2020-02-18 23:11:19 +0100 | [diff] [blame] | 84 | to the preamble and store your example in the `examples-alloc` folder. |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 85 | |
JOE1994 | 51168c9 | 2020-04-27 17:05:34 -0400 | [diff] [blame^] | 86 | To build the examples for your board you can use |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 87 | |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 88 | ```shell |
| 89 | make <platform> [FEATURES=alloc] |
| 90 | ``` |
| 91 | |
JOE1994 | 51168c9 | 2020-04-27 17:05:34 -0400 | [diff] [blame^] | 92 | A program can be flashed to your board after the build process by running: |
Alistair Francis | 0c1cb58 | 2020-03-10 13:49:40 -0700 | [diff] [blame] | 93 | |
| 94 | ```shell |
| 95 | make flash-<platform> EXAMPLE=<example> |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 96 | ``` |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 97 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 98 | This script does the following steps for you: |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 99 | |
| 100 | - cross-compile your program |
| 101 | - create a TAB (tock application bundle) |
Woyten | 860e0bc | 2020-01-29 21:17:14 +0100 | [diff] [blame] | 102 | - if you have a J-Link compatible board connected: flash this TAB to your board (using tockloader) |
| 103 | |
Philipp Vollmer | 209e318 | 2018-03-27 09:05:49 +0200 | [diff] [blame] | 104 | |
Pat Pannuto | 0dc3e13 | 2017-05-11 16:22:12 -0400 | [diff] [blame] | 105 | ## License |
| 106 | |
| 107 | Licensed under either of |
| 108 | |
torfmaster | 92f8131 | 2019-12-30 00:09:03 +0100 | [diff] [blame] | 109 | - Apache License, Version 2.0 |
| 110 | ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 111 | - MIT license |
| 112 | ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
Pat Pannuto | 0dc3e13 | 2017-05-11 16:22:12 -0400 | [diff] [blame] | 113 | |
| 114 | at your option. |
| 115 | |
| 116 | ### Contribution |
| 117 | |
| 118 | Unless you explicitly state otherwise, any contribution intentionally submitted |
| 119 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be |
| 120 | dual licensed as above, without any additional terms or conditions. |
torfmaster | f310ac0 | 2019-12-30 00:12:17 +0100 | [diff] [blame] | 121 | |
| 122 | The contribution guidelines can be found here: [contribution guidelines](CONTRIBUTING.md) |