add nordic tutorial for developing environment installation

This commit is contained in:
Klagarge committed 2024-03-20 15:37:06 +01:00
1 parent 0f8fcb4fe6
commit 228da72eb1
4 files changed
+282

No files matched your search

+16
View File
@@ -118,6 +118,13 @@
formatUpdated: "{YYYY}-{MM}-{DD} {HH}:{mm}",
whereToPlace: "top",
},
tabs: {
persist: true, // default
sync: true, // default
theme: 'classic', // default
tabComments: true, // default
tabHeadings: true // default
},
};
</script>
@@ -184,6 +191,15 @@
<!----- Last time updated ----->
<script src="https://cdn.jsdelivr.net/npm/docsify-updated/src/time-updater.js"></script>
<!-- docsify-tabs (latest v1.x.x) -->
<script src="https://cdn.jsdelivr.net/npm/docsify-tabs@1"></script>
<style>
:root {
--docsifytabs-border-color: #ededed;
--docsifytabs-tab-highlight-color: purple;
}
</style>
</body>
</html>
+6
View File
@@ -0,0 +1,6 @@
<header><h1>
Nordic - nRF
</h1></header>
----------
Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

+260
View File
@@ -0,0 +1,260 @@
<header><h1>
nRF Development Environment
</h1></header>
----------
Here you'll find some information for setting up the nRF development environment.
We'll see more on detail how to set up the environment for Linux and program the nRF52 with Zephyr on CLion.
# 1. Installing the nRF Connect SDK & Toolchain
<!-- tabs:start -->
#### **Linux**
1. Install the `libfuse2` library
```bash
sudo apt install libfuse2
```
2. Download the [nRF Connect for Desktop](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-desktop)
3. Make the file executable
```bash
chmod a+x nrfconnect-*.appimage
```
4. Run the appimage (double-click on nrfconnect)
- If it asks for update, click "yes"
- If it asks is you want to help them improve the app, I recommend declining it.
- If it asks is you want to start the "Quick Start" app, click "Close"
5. Install necessary tools
- Toolchain Manager
- Programmer
6. Open the toolchain manager and install "nRF Connect SDK v2.6.0"
- Confirm the installation directory by clicking "Continue installation"
- Wait for the toolchain to download and install. (this may take a while)
- You can close the toolchain manager now
7. Download [nRF-udev](https://github.com/NordicSemiconductor/nrf-udev/releases/download/v1.0.1/nrf-udev_1.0.1-all.deb)
and install the nRF udev
```bash
sudo dpkg -i nrf-udev_1.0.1-all.deb
```
8. Install [JLink](https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb) and install it
```bash
sudo dpkg -i JLink_Linux_*_x86_64.deb
```
#### **Windows**
Use Linux or WSL
#### **WSL**
Cry
<!-- tabs:end -->
# Installing Zephyr [↗](https://builds.zephyrproject.io/zephyr/pr/60204/docs/develop/getting_started/index.html)
Zephyr is an open-source real-time operating system (RTOS) that is designed to be small, scalable, and secure for use
on resource-constrained systems.
It is a Linux Foundation project and is governed by a Technical Steering Committee (TSC).
## Install dependencies
| Tool | Min. Version |
|---------------------|--------------|
| CMake | 3.20.5 |
| Python | 3.8 |
| Devicetree compiler | 1.4.6 |
<!-- tabs:start -->
#### **Linux**
1. You'll probably need to update your package list
```bash
wget https://apt.kitware.com/kitware-archive.sh
sudo bash kitware-archive.sh
sudo apt update
```
2. Use apt to install the required dependencies:
```bash
sudo apt install --no-install-recommends git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
```
3. Verify the versions of the main dependencies installed on your system
```bash
cmake --version
python3 --version
dtc --version
```
#### **Windows**
Use Linux or WSL
#### **WSL**
Cry
<!-- tabs:end -->
## Get Zephyr and install Python dependencies
We'll see here only how to install within virtual environment because for CLion we'll need to use the virtual environment.
<!-- tabs:start -->
#### **Linux**
1. Install Python venv package
```bash
sudo apt install python3-venv
```
2. Create a new virtual environment
```bash
python3 -m venv ~/zephyrproject/.venv
```
3. Activate the virtual environment
```bash
source ~/zephyrproject/.venv/bin/activate
```
Once activated your shell will be prefixed with `(.venv)`. The virtual environment can be deactivated at any time by running `deactivate`.
4. Install west
```bash
pip install west
```
5. Get the Zephyr source code
```bash
west init ~/zephyrproject
cd ~/zephyrproject
west update
```
6. Export a [Zephyr CMake package](https://builds.zephyrproject.io/zephyr/pr/60204/docs/build/zephyr_cmake_package.html#cmake-pkg).
This allows CMake to automatically load boilerplate code required for building Zephyr applications.
```bash
west zephyr-export
```
7. Zephyr’s `scripts/requirements.txt` file declares additional Python dependencies.
```bash
pip install -r ~/zephyrproject/zephyr/scripts/requirements.txt
```
#### **Windows**
Use Linux or WSL
#### **WSL**
Cry
<!-- tabs:end -->
## Install the Zephyr SDK
<!-- tabs:start -->
#### **Linux**
1. Download and verify the [Zephyr SDK bundle](https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.5-1)
```bash
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.5-1/zephyr-sdk-0.16.5-1_linux-x86_64.tar.xz
wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.5-1/sha256.sum | shasum --check --ignore-missing
```
2. Extract the Zephyr SDK bundle archive:
```bash
tar xf zephyr-sdk-0.16.5-1_linux-x86_64.tar.xz
```
3. Run the Zephyr SDK bundle setup script
```bash
~/zephyr-sdk-0.16.5-1_linux-x86_64/install.sh
```
You only need to run the setup script once after extracting the Zephyr SDK bundle.
You must rerun the setup script if you relocate the Zephyr SDK bundle directory after the initial setup.
4. Install udev rules, which allow you to flash most Zephyr boards as a regular user.
```bash
sudo cp ~/zephyr-sdk-0.16.5-1/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
```
#### **Windows**
Use Linux or WSL
#### **WSL**
Cry
<!-- tabs:end -->
# Configure CLion for Zephyr [↗](https://builds.zephyrproject.io/zephyr/pr/60204/docs/develop/tools/clion.html#clion)
<!-- tabs:start -->
#### **Linux**
1. Create new Toolchain
1. Open CLion, go to `File` > `Settings` > `Build, Execution, Deployment` > `Toolchain`
2. Create a new `Zephyr` toolchain
3. `Add environment ‣ From file` and select `~/zephyrproject/.venv/bin/activate`.
2. Create a new project in `~/zephyrproject/zephyr/myApps/<my_project_name>`
3. On CMake profile setting dialog, set the following:
- `Name`: `Zephyr`
- `Toolchain`: `Zephyr`
- `CMake options`: `-DBOARD=nrf52840dk_nrf52840` (or other board you want to use)
4. Create the project configuration file (`prj.conf`):
```
CONFIG_PRINTK=y
CONFIG_GPIO=y
CONFIG_DEBUG_THREAD_INFO=y
CONFIG_THREAD_RUNTIME_STATS=y
CONFIG_DEBUG_OPTIMIZATIONS=y
```
5. Create a new `main.c` file in the `src` directory. For example:
```c
#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#define LED0_NODE DT_ALIAS(led0)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
int main(void){
int ret;
bool led_state = true;
if (!gpio_is_ready_dt(&led)) return 0;
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) return 0;
while (1) {
ret = gpio_pin_toggle_dt(&led);
if (ret < 0) return 0;
led_state = !led_state;
printf("LED state: %s\n", led_state ? "ON" : "OFF");
k_msleep(1000);
}
}
```
6. Create the `CMakeLists.txt` file in the root of the project
```cmake
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(my_project_name)
target_sources(app PRIVATE src/main.c)
```
7. Enable RTOS integration
1. Go to `Settings ‣ Build, Execution, Deployment ‣ Embedded Development ‣ RTOS Integration`.
2. Set the Enable RTOS Integration checkbox. You can leave the option set to `Auto`. CLion will detect Zephyr automatically.
8. Configure the debugger
1. Go to `Run ‣ New Embedded Configuration`.
2. Set the GDB settings:
![GDB settings](medias/GDB_settings.png)
3. Select your board and click `OK`.
9. Build and debug the project
#### **Windows**
Use Linux or WSL
#### **WSL**
Cry
<!-- tabs:end -->