Difference between revisions of "Nordic SoC"

From Organic Design wiki
(nrfutil install)
(Add modem init and network selection.)
Line 27: Line 27:
  
 
That wasn't the only long file, so I extracted everything but '''v3.1.0/modules/lib/matter/examples/chef/devices''' and then extracted file that wasn't too long in that. You will want it extracted to '''~/ncs/v3.1.0''' but you want to rename it to something else temporarily - click install in VS Code, select the SDK/Version and when it asks for the install path don't hit enter just yet, first rename the directory back to '''v3.1.0''' then hit enter in VS Code and it will detect that it is already installed and work fine. If you don't rename it first VS Code will complain that the directory already exists and if you don't have it named in the right place VS Code will attempt to install it normally and fail again.
 
That wasn't the only long file, so I extracted everything but '''v3.1.0/modules/lib/matter/examples/chef/devices''' and then extracted file that wasn't too long in that. You will want it extracted to '''~/ncs/v3.1.0''' but you want to rename it to something else temporarily - click install in VS Code, select the SDK/Version and when it asks for the install path don't hit enter just yet, first rename the directory back to '''v3.1.0''' then hit enter in VS Code and it will detect that it is already installed and work fine. If you don't rename it first VS Code will complain that the directory already exists and if you don't have it named in the right place VS Code will attempt to install it normally and fail again.
 +
 +
== Networking ==
 +
 +
=== Modem Init ===
 +
 +
<source lang="c">
 +
// CONFIG_NRF_MODEM_LIB=y
 +
#include <modem/nrf_modem_lib.h>
 +
 +
// Init modem manually (auto init is disabled)
 +
int err = nrf_modem_lib_init();
 +
 +
if (err < 0) {
 +
  printk("Modem init failed: %d\n", err);
 +
}
 +
</source>
 +
 +
=== RAT Selection ===
 +
Radio Access Technology (RAT). You can enable LTE-M, NB-IoT and GNSS or a combination of these RATs. If you have more than one selected you can configure what one is prefered.
 +
 +
 +
Option 1, force by config.
 +
<source lang="env">
 +
CONFIG_LTE_NETWORK_MODE_NBIOT=y
 +
</source>
 +
 +
Option 2, use lte link control.
 +
<source lang="c">
 +
// CONFIG_LTE_LINK_CONTROL=y ?
 +
#include <modem/lte_lc.h>
 +
 +
int err = lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_NBIOT, LTE_LC_SYSTEM_MODE_PREFER_NBIOT);
 +
 +
if (!err) {
 +
  printk("RAT Set: %d\n", err);
 +
} else {
 +
  printk("Failed to set RAT: %d\n", err);
 +
}
 +
</source>
 +
 +
Option 3, use [https://docs.nordicsemi.com/bundle/ref_at_commands_nrf91x1/page/REF/at_commands/mob_termination_ctrl_status/xsystemmode_set.html AT commands]:
 +
<source lang="c">
 +
char resp[64];
 +
 +
// AT%XSYSTEMMODE=<LTE-M 1/0>,<NB-IoT 1/0>,<GNSS 1/0>,<Preference 0=none,1=LTE-M,2=NB-IoT,3=SIM-preference-or-LTE-M,4=SIM-preference-or-NB-IoT>
 +
int err = nrf_modem_at_cmd(resp, sizeof(resp), "AT%%XSYSTEMMODE=0,1,0,2");
 +
if (!err) {
 +
  printk("SIM status: %s\n", resp);
 +
} else {
 +
  printk("Failed to check SIM status: %d\n", err);
 +
}
 +
</source>

Revision as of 02:29, 11 September 2025

VS Code is the only IDE that has extensions for Nordic Connect, so you will want to use that and download the Nordic Connect extensions.

Installing nrfutil

Download nrfutil, make it executable and move it somewhere where the path can pick it up, e.g.: ~/.local/bin/. You will also need to install the device module with it:

nrfutil search
nrfutil install device

Installing the SDK

I recommend installing version 3.0.2 because it just works whereas 3.1.0 runs into many issues.

3.0.2

Follow the walkthrough for VS Code: vscode:/nordic-semiconductor.nrf-connect-extension-pack/quickstart and select 3.0.2.

3.1.0

Note: I could not get my project to build with this version.

It's easiest to follow the walkthrough for VS Code: vscode:/nordic-semiconductor.nrf-connect-extension-pack/quickstart. I had an issue where installing the SDK would fail, checking the logs it threw on unpacking the SDK archive. I attempting to manually extract this and found that it failed beacause it contained some ridiculously long filenames in there, specifically:

v3.1.0/modules/lib/matter/examples/chef/devices/rootnode_contactsensor_lightsensor_occupancysensor_temperaturesensor_pressuresensor_flowsensor_humiditysensor_airqualitysensor_powersource_367e7cea91

That wasn't the only long file, so I extracted everything but v3.1.0/modules/lib/matter/examples/chef/devices and then extracted file that wasn't too long in that. You will want it extracted to ~/ncs/v3.1.0 but you want to rename it to something else temporarily - click install in VS Code, select the SDK/Version and when it asks for the install path don't hit enter just yet, first rename the directory back to v3.1.0 then hit enter in VS Code and it will detect that it is already installed and work fine. If you don't rename it first VS Code will complain that the directory already exists and if you don't have it named in the right place VS Code will attempt to install it normally and fail again.

Networking

Modem Init

// CONFIG_NRF_MODEM_LIB=y
#include <modem/nrf_modem_lib.h>

// Init modem manually (auto init is disabled)
int err = nrf_modem_lib_init();

if (err < 0) {
  printk("Modem init failed: %d\n", err);
}

RAT Selection

Radio Access Technology (RAT). You can enable LTE-M, NB-IoT and GNSS or a combination of these RATs. If you have more than one selected you can configure what one is prefered.


Option 1, force by config.

CONFIG_LTE_NETWORK_MODE_NBIOT=y

Option 2, use lte link control.

// CONFIG_LTE_LINK_CONTROL=y ?
#include <modem/lte_lc.h>

int err = lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_NBIOT, LTE_LC_SYSTEM_MODE_PREFER_NBIOT);

if (!err) {
  printk("RAT Set: %d\n", err);
} else {
  printk("Failed to set RAT: %d\n", err);
}

Option 3, use AT commands:

char resp[64];

// AT%XSYSTEMMODE=<LTE-M 1/0>,<NB-IoT 1/0>,<GNSS 1/0>,<Preference 0=none,1=LTE-M,2=NB-IoT,3=SIM-preference-or-LTE-M,4=SIM-preference-or-NB-IoT>
int err = nrf_modem_at_cmd(resp, sizeof(resp), "AT%%XSYSTEMMODE=0,1,0,2");
if (!err) {
  printk("SIM status: %s\n", resp);
} else {
  printk("Failed to check SIM status: %d\n", err);
}