Skip to content

Commit a8dddf1

Browse files
bors[bot]Jonathan Pallant (42 Technology)jonas-schievink
authored
Merge #321
321: Update 9160 HAL with latest memory map. r=jonas-schievink a=jonathanpallant Also adds a README to explain why we need SPM. Co-authored-by: Jonathan Pallant (42 Technology) <[email protected]> Co-authored-by: Jonas Schievink <[email protected]>
2 parents 39c0b8f + 1a67cfa commit a8dddf1

File tree

2 files changed

+117
-24
lines changed

2 files changed

+117
-24
lines changed

nrf9160-hal/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Hardware Abstration Layer for the Nordic nRF9160
2+
3+
This crate is a Hardware Abstraction Layer (HAL) for the Nordic nRF9160. It
4+
wraps the PAC (`nrf9160-pac`) and provides high level wrappers for the chip's
5+
peripherals.
6+
7+
This crate knows nothing about your PCB layout, or which pins you have assigned
8+
to which functions. The only exception are the examples, which are written to
9+
run on the official nRF9160-DK developer kit.
10+
11+
## Usage
12+
13+
You will require the `thumbv8m.main-none-eabihf` target installed.
14+
15+
```console
16+
$ rustup target add thumbv8m.main-none-eabihf
17+
```
18+
19+
## Secure vs Non-Secure
20+
21+
This HAL is designed to run in non-secure mode, as should most of your
22+
application code. You will therefore need a 'bootloader' which starts in secure
23+
mode, moves the required peripherals into 'non-secure' world, and then jumps to
24+
your application.
25+
26+
We have succesfully used Nordic's [Secure Partition Manager](https://github.com/nrfconnect/sdk-nrf/tree/v1.5.1/samples/spm)
27+
from nRF SDK v1.5.1. SPM v1.5.1 is configured to expect your application at address
28+
`0x0005_0000` and so that is what `memory.x` must specify as the start of Flash.
29+
30+
_Note:_ Other versions of SPM might expect a different start address -
31+
especially those compiled as a child image of another application (like
32+
`at_sample`)! You can see the start address on boot-up:
33+
34+
```
35+
SPM: NS image at 0x50000
36+
```
37+
38+
This tells you SPM is looking for a non-secure (NS) image at `0x0005_0000`.
39+
40+
To build SPM, run:
41+
42+
```console
43+
$ west init -m https://github.com/nrfconnect/sdk-nrf --mr v1.5.1 ncs
44+
$ cd ncs
45+
$ west update # This takes *ages*
46+
$ cd nrf/examples/spm
47+
$ west build --board=nrf9160dk_nrf9160
48+
$ west flash
49+
```
50+
51+
West is a Python tool supplied by Nordic for building the nRF Connect SDK. See
52+
[Nordic's website](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.1/nrf/gs_installing.html)
53+
for more details.
54+
55+
Your nRF9160-DK will now have SPM installed between `0x0000_0000` and
56+
`0x0004_FFFF`. Flashing your application at `0x0005_0000` should not affect SPM,
57+
provided you do not select *erase entire chip* or somesuch!
58+
59+
If you want to change the flash address, supply your own `memory.x` file in your
60+
application crate (or your Board Support Crate) and write a `build.rs` file that
61+
copies your `memory.x` over the top of this one.
62+
63+
## Licence
64+
65+
Licensed under either of
66+
67+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
68+
http://www.apache.org/licenses/LICENSE-2.0)
69+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
70+
71+
at your option.
72+
73+
## Contribution
74+
75+
Unless you explicitly state otherwise, any contribution intentionally
76+
submitted for inclusion in the work by you, as defined in the Apache-2.0
77+
license, shall be dual licensed as above, without any additional terms or
78+
conditions.

nrf9160-hal/memory.x

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
1-
/* Linker script for the nRF9160 in Non-secure mode */
1+
/* Linker script for the nRF9160 in Non-secure mode. It assumes you have the
2+
Nordic Secure Partition Manager installed at the bottom of flash and that
3+
the SPM is set to boot a non-secure application from the FLASH origin below. */
4+
25
MEMORY
36
{
4-
/* SECURE_FLASH : ORIGIN = 0x00000000, LENGTH = 256K */
5-
/* NONSECURE_FLASH : ORIGIN = 0x00040000, LENGTH = 768K */
6-
/* SECURE_RAM : ORIGIN = 0x20000000, LENGTH = 64K */
7-
/* LIBBSD_RAM : ORIGIN = 0x20010000, LENGTH = 64K */
8-
/* NONSECURE_RAM : ORIGIN = 0x20020000, LENGTH = 128K */
9-
10-
FLASH : ORIGIN = 0x00040000, LENGTH = 768K
11-
RAM : ORIGIN = 0x20020000, LENGTH = 128K
7+
/*
8+
* This is where the Bootloader, Secure Partition Manager or
9+
* Trusted-Firmware-M lives.
10+
*/
11+
SECURE_FLASH : ORIGIN = 0x00000000, LENGTH = 256K
12+
/*
13+
* This is where your non-secure Rust application lives. Note that SPM must agree this
14+
* is where your application lives, or it will jump to garbage and crash the CPU.
15+
*/
16+
FLASH : ORIGIN = 0x00050000, LENGTH = 768K
17+
/*
18+
* This RAM is reserved for the Secure-Mode code located in the `SECURE_FLASH` region.
19+
*/
20+
SECURE_RAM : ORIGIN = 0x20000000, LENGTH = 64K
21+
/*
22+
* This RAM is available to both the Cortex-M33 and the LTE core (well,
23+
technically anything between `0x2000_0000` and `0x2001_FFFF` is
24+
shareable, but we just gave the first 64 KiB to Secure Mode). Shared
25+
buffers must be placed here.
26+
*/
27+
SHARED_RAM : ORIGIN = 0x20010000, LENGTH = 64K
28+
/*
29+
* This RAM is available to your non-secure Rust application.
30+
*/
31+
RAM : ORIGIN = 0x20020000, LENGTH = 128K
1232
}
1333

14-
/* This is where the call stack will be allocated. */
15-
/* The stack is of the full descending type. */
16-
/* You may want to use this variable to locate the call stack and static
17-
variables in different memory regions. Below is shown the default value */
18-
/* _stack_start = ORIGIN(RAM) + LENGTH(RAM); */
19-
20-
/* You can use this symbol to customize the location of the .text section */
21-
/* If omitted the .text section will be placed right after the .vector_table
22-
section */
23-
/* This is required only on microcontrollers that store some configuration right
24-
after the vector table */
25-
/* _stext = ORIGIN(FLASH) + 0x400; */
26-
27-
/* Size of the heap (in bytes) */
28-
/* _heap_size = 1024; */
34+
SECTIONS
35+
{
36+
/* This section contains the buffers used by `libnrf_modem` to talk between the Cortex-M33 and the LTE core */
37+
.shared_ram (NOLOAD) : ALIGN(4)
38+
{
39+
. = ALIGN(4);
40+
*(.shared_ram .shared_ram.*);
41+
. = ALIGN(4);
42+
} > SHARED_RAM
43+
}

0 commit comments

Comments
 (0)