Skip to content

Latest commit

 

History

History
284 lines (181 loc) · 9.33 KB

nrf52-tools.md

File metadata and controls

284 lines (181 loc) · 9.33 KB

nRF52 Tools

Follow the entire section for the operating system that you're using, then go to Setup check.

Linux

Install VS Code

Follow the instructions for your distribution on https://code.visualstudio.com/docs/setup/linux.

Install dependencies

Some of our tools depend on pkg-config and libudev.pc.

Ensure you have the proper packages installed. On Debian based distributions you can use:

sudo apt-get install libudev-dev libusb-1.0-0-dev

Configure USB Device access for non-root users

Connect the dongle and check its permissions with these commands:

$ lsusb -d 1915:521f
Bus 001 Device 016: ID 1915:521f Nordic Semiconductor ASA USB Billboard
$ #   ^         ^^

$ # take note of the bus and device numbers that appear for you when run the next command
$ ls -l /dev/bus/usb/001/016
crw-rw-r-- 1 root root 189, 15 May 20 12:00 /dev/bus/usb/001/016

The root root part in crw-rw-r-- 1 root root indicates the device can only be accessed by the root user.

To access the USB devices as a non-root user, follow these steps:

  1. As root, create /etc/udev/rules.d/50-ferrous-training.rules with the following contents:

    # udev rules to allow access to USB devices as a non-root user
    
    # nRF52840 Dongle in bootloader mode
    ATTRS{idVendor}=="1915", ATTRS{idProduct}=="521f", TAG+="uaccess"
    
    # nRF52840 Dongle applications
    ATTRS{idVendor}=="1209", TAG+="uaccess"
    
    # nRF52840 Development Kit
    ATTRS{idVendor}=="1366", ENV{ID_MM_DEVICE_IGNORE}="1", TAG+="uaccess"
  2. Run the following command to put the new udev rules into effect

    sudo udevadm control --reload-rules

To check the permissions again, first disconnect and reconnect the dongle. Then run lsusb.

$ lsusb
Bus 001 Device 017: ID 1915:521f Nordic Semiconductor ASA 4-Port USB 2.0 Hub

$ ls -l /dev/bus/usb/001/017
crw-rw-r--+ 1 root root 189, 16 May 20 12:11 /dev/bus/usb/001/017

The + part in crw-rw-r--+ indicates the device can be accessed without root permissions. If you have permission to access them dongle, then the nRF52-DK should also work because both were listed in the udev rules file.

Install base rust tooling

Go to https://rustup.rs and follow the instructions.

Install rust analyzer

Open VS Code, find Rust Analyzer in the marketplace (bottom icon in the left panel), then install it.

Configure Rust Cross compilation support

Run this command in a terminal:

rustup +stable target add thumbv7em-none-eabihf

Install ELF analysis tools

Run these commands in a terminal:

cargo install cargo-binutils
rustup +stable component add llvm-tools

Third-party tools written in Rust

Install the flip-link, nrf-dfu and cyme tools from source using the following Cargo commands:

cargo install flip-link
cargo install nrfdfu
cargo install cyme

Install probe-rs 0.24 pre-compiled binaries on Linux with:

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-installer.sh | sh

Windows

Install VS Code

Go to https://code.visualstudio.com and run the installer.

Associate the device with the WinUSB drivers

On Windows you'll need to associate the nRF52840 Development Kit's USB device to the WinUSB driver.

To do that connect the nRF52840 DK to your PC using micro-USB port J2, then download and run the Zadig tool.

In Zadig's graphical user interface,

  1. Select the 'List all devices' option from the Options menu at the top.

  2. From the device (top) drop down menu select "BULK interface (Interface nnn)"

  3. Once that device is selected, 1366 1051 should be displayed in the USB ID field. That's the Vendor ID - Product ID pair.

  4. Select 'WinUSB' as the target driver (right side)

  5. Click "Install Driver". The process may take a few minutes to complete and might not appear to do anything right away. Click it once and wait.

You do not need to do anything for the nRF52840 Dongle device.

Install base rust tooling

Go to https://rustup.rs and follow the instructions.

You will need a C compiler to use Rust on Windows. The rustup installer will suggest you install either Visual Studio, or the Build Tools for Visual Studio - either is fine. When that is installing, be sure to select the optional "Desktop development with C++" part of the C++ build tools package. The installation may take up to 5.7 GB of disk space. Please also be aware of the license conditions attached to these products, especially in an enterprise environment.

Install rust analyzer

Open VS Code, find Rust Analyzer in the marketplace (bottom icon in the left panel), then install it.

If you get a message about git not being installed, ignore it!

Configure Rust Cross compilation support

Run this command in a terminal:

rustup +stable target add thumbv7em-none-eabihf

Install ELF analysis tools

Run these commands in a terminal:

cargo install cargo-binutils
rustup +stable component add llvm-tools

Third-party tools written in Rust

Install the flip-link, nrf-dfu and cyme tools from source using the following Cargo commands:

cargo install flip-link
cargo install nrfdfu
cargo install cyme

Install probe-rs 0.24 pre-compiled binaries on Windows with:

powershell -c "irm https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-installer.ps1 | iex"

macOS

Install VS Code

Go to https://code.visualstudio.com and click on "Download for Mac".

Install base rust tooling

Go to https://rustup.rs and follow the instructions.

Install rust analyzer

Open VS Code, find Rust Analyzer in the marketplace (bottom icon in the left panel), then install it.

Configure Rust Cross compilation support

Run this command in a terminal:

rustup +stable target add thumbv7em-none-eabihf

Install ELF analysis tools

Run these commands in a terminal:

cargo install cargo-binutils
rustup +stable component add llvm-tools

Third-party tools written in Rust

Install the flip-link, nrf-dfu and cyme tools from source using the following Cargo commands:

cargo install flip-link
cargo install nrfdfu
cargo install cyme

Install probe-rs 0.24 pre-compiled binaries on macOS with:

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-installer.sh | sh

Setup check

✅ Let's check that you have installed all the tools listed in the previous section.

$ cargo size --version
cargo-size 0.3.6

✅ Connect the nRF52840-DK with your computer by plugging the usb-cable into the J2 connector on the DK (the usb connector on the short side of the board).

✅ Use cyme to list the USB devices on your computer.

$ cyme
(..)
  2  15  0x1366 0x1051 J-Link                   001050255503      12.0 Mb/s
(..)

Your nRF52840-DK should appear as "J-Link" with USB Vendor ID (VID) of 0x1366 and a USB Product ID (PID) 0x1051.

🔎 If cyme doesn't work for any reason, you can use cargo xtask usb-list, which does the same thing but is much more basic. Run it from the root of the extracted tarball / git checkout:

$ cargo xtask usb-list
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running `xtask/target/debug/xtask usb-list`
Bus 002 Device 015: ID 1366:1051 <- J-Link on the nRF52840 Development Kit
(...) random other USB devices will be listed

✅ In the terminal run cargo run --bin hello from the nrf52-code/radio-app folder, to build and run a simple program on the DK to test the set-up.

cargo run --bin hello
    Finished `dev` profile [optimized + debuginfo] target(s) in 0.06s
     Running `probe-rs run --chip nRF52840_xxAA target/thumbv7em-none-eabihf/debug/hello --allow-erase-all`
      Erasing ✔ [00:00:00] [################################################] 8.00 KiB/8.00 KiB @ 31.22 KiB/s (eta 0s )
  Programming ✔ [00:00:00] [################################################] 8.00 KiB/8.00 KiB @ 36.25 KiB/s (eta 0s )    Finished in 0.496s
<lvl> Hello, world!
└─ hello::__cortex_m_rt_main @ src/bin/hello.rs:21
<lvl> `dk::exit()` called; exiting ...
└─ dk::exit @ /home/samuel/src/ferrous/rust-exercises/nrf52-code/boards/dk/src/lib.rs:415