Using Soft peripherals
Soft peripherals implement digital peripherals in firmware running on the Fast Lightweight Peripheral Processor (FLPR), a dedicated VPR CPU based on the RISC-V architecture in the fast domain. This guide describes what you need to add to an application developed with nRF Connect SDK Bare Metal option to use a Soft Peripheral, using sQSPI as an example. The Bare Metal subsystem also supports the sCAN and sEMMC soft peripherals, but this guide does not include integration examples for them. For the driver API, firmware versions, and the full porting guide of each Soft Peripheral, see Soft peripherals. For a sample implementation, see the Software QSPI sample.
Prerequisites
Before you integrate a Soft Peripheral, make sure of the following:
The Soft Peripheral firmware supports your SoC. See Soft peripherals for the list of supported SoCs and firmware versions.
The Fast Lightweight Peripheral Processor (FLPR) is not used by another component in your application.
The pins you want to use can be controlled by FLPR. See VPR pin mapping for the pins available on your SoC.
Project configuration
Enable the CONFIG_BM_SOFTPERIPHERAL Kconfig option to enable the Soft Peripheral subsystem in Bare Metal.
Enable one of the following Kconfig options to select the soft peripheral driver:
CONFIG_BM_SOFTPERIPHERAL_SCANSelects the sCAN driver for Controller Area NetworkCONFIG_BM_SOFTPERIPHERAL_SEMMC- Selects the sEMMC driver for embedded Multimedia CardCONFIG_BM_SOFTPERIPHERAL_SQSPI- Selects the sQSPI driver for Quad Serial Peripheral Interface
Memory reservation
The Soft Peripheral firmware runs from RAM. At startup, the driver copies the firmware into RAM and starts FLPR, which then executes it from there. The application core and FLPR also share a small RAM region, the virtual register interface, which the driver uses to control the Soft Peripheral.
You must reserve these RAM regions in the devicetree, so that the application, the SoftDevice, and other components do not use them. The following table shows the requirement for sQSPI on the nRF54L15 and nRF54LM20 SoCs:
Node label |
Content |
Size (sQSPI) |
|---|---|---|
|
Firmware |
|
|
Working memory of the firmware |
|
|
Virtual register interface |
|
The three regions must be placed directly after each other, in this order, which is 0x3D40 bytes in total.
For the required sizes of other Soft peripherals or firmware versions, see the porting guide of the selected Soft Peripheral in Soft peripherals.
Placing the regions in RAM
In the Bare Metal board targets, the softdevice_ram region starts at the beginning of SRAM, and the app_ram region uses the rest of SRAM up to the FLPR context-save area at the end.
The easiest place for the Soft Peripheral regions is directly after softdevice_ram, at the start of app_ram.
To make room for them, complete the following steps:
Delete the original
app_ramnode.Add the three Soft Peripheral regions, starting at the original
app_ramstart address.Add a new
app_ramnode directly after the Soft Peripheral regions. Move its start address up by0x3D40and reduce its size by0x3D40, so that its end address stays the same.
For example, for the bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice board target, where app_ram originally starts at 0x4380:
/delete-node/ &app_ram;
&cpuapp_sram {
flpr_firmware_ram: sram@4380 {
label = "flpr_firmware_ram";
reg = <0x4380 0x3740>;
};
flpr_execution_ram: sram@7ac0 {
label = "flpr_execution_ram";
reg = <0x7ac0 0x400>;
};
flpr_vri_ram: sram@7ec0 {
label = "flpr_vri_ram";
reg = <0x7ec0 0x200>;
};
app_ram: sram@80c0 {
label = "app_ram";
reg = <0x80c0 DT_SIZE_K(479)>;
};
};
Note
Do not let app_ram grow past its original end address.
FLPR uses the memory after it to save its context, so the application must not overwrite it.
You can add these nodes in one of the following ways:
As a devicetree overlay file in your application, for example
boards/<board_target>.overlay. This is how the Software QSPI sample does it, and it keeps the board files unchanged.Directly in the devicetree source of your own board. Use this approach if the Soft Peripheral is a permanent part of your design.
Using the regions in the application
The driver accesses the Soft Peripheral through the virtual register interface.
Use the address of the flpr_vri_ram node as the register address of the driver instance:
static nrf_sqspi_t qspi = {
.p_reg = (void *)DT_REG_ADDR(DT_NODELABEL(flpr_vri_ram)),
.drv_inst_idx = 0
};
Soft peripheral initialization
Before you initialize the driver, make sure of the following:
FLPR has access to the hardware peripherals that the firmware uses. For example, sQSPI needs access to MEMCONF, which you must allow in the SPU.
The pins are configured and their control is assigned to FLPR, either by the driver or by the application.
The FLPR interrupt is connected to the driver interrupt handler. Use
BM_IRQ_DIRECT_CONNECTwithSP_VPR_IRQn, and call the driver interrupt handler, for examplenrf_sqspi_irq_handler(), from it. Choose an interrupt priority that your SoftDevice configuration allows.
Then initialize the driver, configure the connected device, and activate the Soft Peripheral as described in the driver API.