#arm #cortex-m #nrf52 #hal

no-std nrf52-hal-common

Common HAL for the nRF52 family of microcontrollers. More specific HAL crates also exist.

6 releases

0.8.1 Apr 28, 2019
0.8.0 Apr 21, 2019
0.7.0 Feb 22, 2019
0.6.1 Dec 29, 2018
0.6.0-beta.3 Nov 18, 2018

#701 in Embedded development

Download history 9/week @ 2021-09-28 14/week @ 2021-10-05 23/week @ 2021-10-12 12/week @ 2021-10-19 15/week @ 2021-10-26 32/week @ 2021-11-02 6/week @ 2021-11-09 12/week @ 2021-11-16 10/week @ 2021-11-23 31/week @ 2021-11-30 33/week @ 2021-12-07 21/week @ 2021-12-14 6/week @ 2021-12-21 18/week @ 2021-12-28 23/week @ 2022-01-04 28/week @ 2022-01-11

75 downloads per month




HAL for the nRF51, nRF52 and nRF91 families of microcontrollers


Please refer to the changelog to see what changed in the last releases.


Every nRF chip has its own crate, listed below:

Crate Docs crates.io target
nrf51-hal docs.rs crates.io thumbv6m-none-eabi
nrf52810-hal docs.rs crates.io thumbv7em-none-eabi
nrf52811-hal docs.rs crates.io thumbv7em-none-eabi
nrf52832-hal docs.rs crates.io thumbv7em-none-eabihf
nrf52833-hal docs.rs crates.io thumbv7em-none-eabihf
nrf52840-hal docs.rs crates.io thumbv7em-none-eabihf
nrf9160-hal docs.rs crates.io thumbv8m.main-none-eabihf

Device Reference Manuals from Nordic

Device Product Specification DK Reference Guide
nRF52810 v1.3 v1.3.1*
nRF52811 v1.0 v1.3.1*
nRF52832 v1.4 v1.3.1*
nRF52833 v1.3 v1.0.1
nRF52840 v1.1 v1.2
nRF9160 v2.0 v0.9.3

* These devices do not have a separate development kit and share the NRF52 DK


Be sure to copy and edit the Cargo.example.toml file to Cargo.toml. The file will require editing dependent on the target you wish to work with and contains some further instructions. Similarly, check out the .vscode/settings.json file when used in the context of Visual Studio Code. By default, all of these files are configured to work with the nRF52840 target.


Licensed under either of

at your option.


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.

Summary of the Examples

Here follows a brief description of each demo for quick reference. For a more in-depth explanation on how the peripherals work please refer to the device reference manuals linked above, the readme for each demo and the comments in the demo code itself.

Demo Category Description
blinky-button-demo Hello World Blinky button demo
ccm-demo Encryption Cipher block chaining - message authentication code (CCM) mode demo
comp-demo Analog Pins Voltage comparator peripheral demo
ecb-demo Encryption AES electronic codebook mode encryption demo
gpiote-demo Digital Pins General-Purpose Input Output Tasks and Events module demo
i2s-controller-demo Audio Inter-IC Sound interface "controller mode (aka master mode)" demo
i2s-peripheral-demo Audio Inter-IC Sound interface "peripheral mode (aka slave mode)" demo
lpcomp-demo Analog Pins Low power voltage comparator demo
ppi-demo Channels Programmable peripheral interconnect (PPI) demo
pwm-demo Digital Pins Pulse width modulation demo
qdec-demo Sensor Decoding Quadrature sensor decoder (QDEC) demo
rtic-demo Framework The Real-Time Interrupt-driven Concurrency framework demo
spi-demo Digital Pins Serial peripheral interface master (SPIM) with EasyDMA demo
spis-demo Digital Pins Serial peripheral interface slave (SPIS) demo
twi-ssd1306 Digital Pins I2C compatible Two-Wire Interface with the SSD1306 OLED Display demo
twim-demo Digital Pins I2C compatible Two-Wire Interface Master mode demo
twis-demo Digital Pins I2C compatible Two-Wire Interface Slave mode demo
wdt-demo Timer Watchdog timer demo

Running the Examples

Each demo readme should contain instructions on how to run it. However, the information below describes the technologies used and can be used to troubleshoot your system setup. Run the demos from within their respective project directories. E.g. to run ccm-demo, you must be in the nrf-hal/examples/ccm-demo/ directory.

Since the demos are stand-alone projects you would NOT typically run them with cargo run --example xyz-demo like some cargo projects are configured to do.

Once Off System Setup

Install the cross compilation toolchain to target your device. You would typically pass the target as a parameter to cargo or explicitly set it in your cargo config file. If you get compilation errors about eh_personality then you have not set the target correctly. Here is an example of the target for a nRF52840 chip:

$ rustup target add thumbv7em-none-eabihf

Install the tools to flash the device.

$ cargo install cargo-embed

For Every Project (optional)

Setup the Cargo.toml file to use the correct features. Features allow for conditional compilation which is essential for a library like this that supports multiple different devices. Under the [features] section add the following line default = ["52840"] for the nRF52840-DK device or whatever other feature is applicable for your device. This is optional but it will allow you to simply call cargo run and cargo build instead of cargo run --features 52840 and cargo build --features 52840 respectively. Note that some demo projects do not have features so this step may not be necessary. If you get a whole bunch of compilation errors or plugins like rust-analyzer are not working then check that you have set the chip features correctly.


~172K SLoC