Cellular: PDN
The PDN sample demonstrates how to create and configure a Packet Data Protocol (PDP) context, activate a Packet Data Network connection, and receive events on its state and connectivity using the PDN library.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Build target |
---|---|---|---|
nRF9161 DK |
|
|
|
PCA10090 |
|
When built for an _ns
build target, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
Overview
The sample first initializes the Modem library.
Next, the sample initializes the PDN library and registers a callback for events pertaining to the default PDP context.
This is done before changing the function mode to 1 (AT+CFUN=1
) to receive the activation event for the default PDP context.
The sample then creates a new PDP context and configures it to use the default APN, registers a callback for its events and activates the PDN connection.
Finally, the sample prints the PDP context IDs and PDN IDs of both the default PDP context and the new PDP context that it has created.
Note
The sample uses the LTE link control library to change the modem’s functional mode.
Hence, the PDN library can automatically register to the necessary packet domain events notifications using the AT+CGEREP=1
AT command, and notifications for unsolicited reporting of error codes sent by the network using the AT+CNEC=16
AT command.
See the AT+CGEREP set command and the AT+CNEC set command sections, respectively, in the nRF9160 AT Commands Reference Guide or the same sections in the nRF91x1 AT Commands Reference Guide depending on the SiP you are using.
If your application does not use the LTE link control library to change the modem’s functional mode, you have to subscribe to these notifications manually before the functional mode is changed.
Sending traces over UART on an nRF91 Series DK
To send modem traces over UART on an nRF91 Series DK, configuration must be added for the UART device in the devicetree and Kconfig. This is done by adding the modem trace UART snippet when building and programming.
Use the Cellular Monitor app for capturing and analyzing modem traces.
Building and running
This sample can be found under samples/cellular/pdn
in the nRF Connect SDK folder structure.
When built as firmware image for the _ns
build target, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE).
Because of this, it automatically includes the Trusted Firmware-M (TF-M).
To read more about CMSE, see Processing environments.
To build the sample with Visual Studio Code, follow the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation. See Building and programming an application for other building and programming scenarios and Testing and debugging an application for general information about testing and debugging in the nRF Connect SDK.
Testing
After programming the sample to your development kit, complete the following steps to test it:
Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.
Connect to the kit with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.
Power on or reset your nRF91 Series DK.
Observe that the sample starts, creates and configures a PDP context, and then activates a PDN connection.
Sample output
The sample shows the following output, which may vary based on the network provider:
PDN sample started
Event: PDP context 0 activated
Default APN is telenor.iot
Created new PDP context 1
PDP contEvent: PDP context 0 IPv6 up
ext 1 configured: APN telenor.iot, Family IPV4V6
Event: PDP context 1 activated
Event: PDP context 1 IPv6 up
PDP Context 0, PDN ID 0
PDP Context 1, PDN ID 0
Interface addresses:
l0: (AF_INET) 10.243.140.208
l0: (AF_INET6) fe80::63:b639:ab01
l0: (AF_INET6) 2a02:2121:20d:175d:0:63:b639:ab01
Event: PDP context 0 deactivated
Event: PDP context 1 deactivated
Event: PDP context 0 network detach
Event: PDP context 1 network detach
Bye
Dependencies
This sample uses the following nRF Connect SDK libraries:
It uses the following sdk-nrfxlib library:
In addition, it uses the following secure firmware component: