Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nrf52 layout #98

Merged
merged 5 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@
# libtock-rs
Rust userland library for Tock (WIP)

Tested with tock a3b36d5872315ff05ef5ad34ed9453b0789218ce.
Tested with tock [Release 1.4.1](https://github.com/tock/tock/commit/7e37bf67761d83fd585cace4fb201e2864d300b1).

The library works in principle on most boards, but there is currently the [showstopper
bug #28](https://github.com/tock/libtock-rs/issues/28) that prevents
the generation of relocatable code. This means that all applications
must be installed at the flash address they are compiled with, which
usually means that they must be compiled especially for your board
and that there can only be one application written in rust at a time
and it must be installed as the first application on the board, unless
you want to play games with linker scripts.
There are some `*_layout.ld` files provided that allow to run the
examples on common boards.
Due to MPU region alignment issues they may not work for applications
that use a lot of RAM, in that case you may have to change the SRAM
start address to fit your application.

## Getting Started

Expand Down Expand Up @@ -36,15 +50,18 @@ to use:
./run_example.sh blink
```

This should work if you are using the nRF52-DK platform. For other platforms,
you will end up with a TAB file in `target/tab` that you can program onto your
Tock board (e.g. with `tockloader install target/tab/blink.tab`).
Due to bug #28 this will currently only work if you are using the nRF52-DK platform.

If you have a nRF52840-DK you must change `link-arg=-Tnrf52_layout.ld` in
`.cargo/config` to `link-arg=-Tnrf52840_layout.ld`

If you have a hail board you can flash your device as follows:
- set the environment variable `hail` to `1`
- set `link-arg=-Tnrf52_layout.ld` in `.cargo/config` to `link-arg=-Thail_layout.ld`
- change `link-arg=-Tnrf52_layout.ld` in `.cargo/config` to `link-arg=-Thail_layout.ld`
- run `run_example.sh` as above.

For other platforms, you may have to create your own memory layout definition.

## Using libtock-rs

The easiest way to start using libtock-rs is adding an example to the examples folder.
Expand Down
17 changes: 17 additions & 0 deletions nrf52840_layout.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Layout for the nRF52840-DK, usable by the examples in this repository. */

MEMORY {
/* The application region is 64 bytes (0x40) */
FLASH (rx) : ORIGIN = 0x00030040, LENGTH = 0x000CFFC0
SRAM (rwx) : ORIGIN = 0x20004000, LENGTH = 62K
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the SRAM length is correct. Isn't there more memory than that on the nRF52840-DK?

}

/*
* Any change to STACK_SIZE should be accompanied by a corresponding change to
* `elf2tab`'s `--stack` option
*/
STACK_SIZE = 2048;

MPU_MIN_ALIGN = 8K;

INCLUDE layout.ld
2 changes: 1 addition & 1 deletion nrf52_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MEMORY {
/* The application region is 64 bytes (0x40) */
FLASH (rx) : ORIGIN = 0x00020040, LENGTH = 0x0005FFC0
FLASH (rx) : ORIGIN = 0x00030040, LENGTH = 0x0005FFC0
SRAM (rwx) : ORIGIN = 0x20002000, LENGTH = 62K
}

Expand Down
2 changes: 1 addition & 1 deletion run_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ elf_file_name="target/tab/$1/cortex-m4.elf"
tab_file_name="target/tab/$1.tab"

# Default value for nRF52-DK
tockloader_flags="--jlink --arch cortex-m4 --board nrf52dk --jtag-device nrf52 --app-address 0x20000"
tockloader_flags="--jlink --arch cortex-m4 --board nrf52dk --jtag-device nrf52"

hail_defined=${hail:-}
if [ -n "$hail_defined" ]
Expand Down
2 changes: 1 addition & 1 deletion run_hardware_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

set -eux

yes 0|tockloader uninstall --jlink --arch cortex-m4 --board nrf52dk --jtag-device nrf52 --app-address 0x20000 || true
yes 0|tockloader uninstall --jlink --arch cortex-m4 --board nrf52dk --jtag-device nrf52 || true

./run_example.sh hardware_test --dont-clear-apps