Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ No changes since the latest nRF Connect SDK Bare Metal release.
Peripheral samples
------------------

No changes since the latest nRF Connect SDK Bare Metal release.
* Added the :ref:`pwm_sample` sample.

DFU samples
-----------
Expand Down
12 changes: 12 additions & 0 deletions samples/peripherals/pwm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2025 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(pwm)

target_sources(app PRIVATE src/main.c)
34 changes: 34 additions & 0 deletions samples/peripherals/pwm/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2025 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "PWM sample"

config PWM_IRQ_PRIO
int "PWM IRQ priority"
default 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this mirror other similar Kconfigs of other peripheral libraries? Taking into account SoftDevice and such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already mirrors how it is done for LPUARTE and UARTE.


config PWM_PLAYBACK_COUNT
int "PWM playback count"
default 1
help
Number of times the sequence will be replayed until the
NRFX_PWM_EVT_FINISHED event is raised.

config PWM_VALUE_REPEATS
int "PWM value repeats"
default 150
help
Number of times that each duty cycle is to be repeated (after being played once).


module=PWM_SAMPLE
module-dep=LOG
module-str=PWM Sample
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"

endmenu # "PWM sample"

source "Kconfig.zephyr"
96 changes: 96 additions & 0 deletions samples/peripherals/pwm/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.. _pwm_sample:

PWM
###

.. contents::
:local:
:depth: 2

The PWM sample demonstrates how to configure and use PWM with |BMlong|.

Requirements
************

The sample supports the following development kits:

.. tabs::

.. group-tab:: Simple board variants

The following board variants do **not** have DFU capabilities.

.. list-table::
:header-rows: 1

* - Hardware platform
- PCA
- SoftDevice
- Board target
* - `nRF54L15 DK`_
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
* - `nRF54L15 DK`_ (emulating nRF54L10)
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
* - `nRF54L15 DK`_ (emulating nRF54L05)
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice

.. group-tab:: MCUboot board variants

The following board variants have DFU capabilities.

.. list-table::
:header-rows: 1

* - Hardware platform
- PCA
- SoftDevice
- Board target
* - `nRF54L15 DK`_
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
* - `nRF54L15 DK`_ (emulating nRF54L10)
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
* - `nRF54L15 DK`_ (emulating nRF54L05)
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot

Overview
********

The sample initializes a PWM instance that blinks LED1 and LED3 on the device.

.. note::

The PWM signal can be exposed only on GPIO pins that belong to the same domain as the target pin.
For nRF54L-series there is only one domain which contains both PWM and GPIO: PWM20/21/22 and GPIO Port P1.
For the nRF54L Series only LEDs connected to P1 can work with PWM, for the nRF54L15DK this is LED1 and LED3.

Building and running
********************

This sample can be found under :file:`samples/peripherals/pwm/` in the |BMshort| folder structure.

.. include:: /includes/create_sample.txt

.. include:: /includes/configure_and_build_sample.txt

.. include:: /includes/program_sample.txt

Testing
=======

You can test this sample by performing the following steps:

1. Compile and program the application.
#. Observe that the ``PWM sample started`` message is printed.
#. Observe that LED1 and LED3 are blinking.
2 changes: 2 additions & 0 deletions samples/peripherals/pwm/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_LOG=y
CONFIG_LOG_BACKEND_BM_UARTE=y
21 changes: 21 additions & 0 deletions samples/peripherals/pwm/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
sample:
name: PWM Sample
tests:
sample.pwm:
sysbuild: true
build_only: true
integration_platforms:
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
platform_allow:
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
tags: ci_build
78 changes: 78 additions & 0 deletions samples/peripherals/pwm/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/logging/log.h>
#include <zephyr/logging/log_ctrl.h>
#include <nrfx_pwm.h>
#include <board-config.h>

LOG_MODULE_REGISTER(app, CONFIG_PWM_SAMPLE_LOG_LEVEL);

#define PWM_INST_IDX 20

nrf_pwm_values_common_t pwm_val[] = {
0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,
900, 800, 700, 600, 500, 400, 300, 200, 100, 0
};

static void pwm_handler(nrfx_pwm_evt_type_t event_type, void *ctx)
{
static uint32_t curr_loop = 1;

LOG_INF("Loops: %u ", curr_loop);
curr_loop++;
}

int main(void)
{
nrfx_err_t err;
nrfx_pwm_t pwm_instance = NRFX_PWM_INSTANCE(PWM_INST_IDX);
/*
* PWM signal can be exposed on GPIO pin only within same domain.
* For nRF54L-series there is only one domain which contains both PWM and GPIO:
* PWM20/21/22 and GPIO Port P1.
* Only LEDs connected to P1 can work with PWM, in this case LED1 and LED3.
*/
nrfx_pwm_config_t config = NRFX_PWM_DEFAULT_CONFIG(BOARD_PIN_LED_1, BOARD_PIN_LED_3,
NRF_PWM_PIN_NOT_CONNECTED,
NRF_PWM_PIN_NOT_CONNECTED);
nrf_pwm_sequence_t seq = {
.values = {pwm_val},
.length = NRFX_ARRAY_SIZE(pwm_val),
.repeats = CONFIG_PWM_VALUE_REPEATS,
.end_delay = 0
};

LOG_INF("PWM sample started");

IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_PWM_INST_GET(PWM_INST_IDX)),
CONFIG_PWM_IRQ_PRIO, NRFX_PWM_INST_HANDLER_GET(20), 0, 0);

err = nrfx_pwm_init(&pwm_instance, &config, pwm_handler, &pwm_instance);
if (err != NRFX_SUCCESS) {
LOG_ERR("Failed to initialize PWM, nrfx_error %#x", err);
goto idle;
}

nrfx_pwm_simple_playback(&pwm_instance, &seq, CONFIG_PWM_PLAYBACK_COUNT,
NRFX_PWM_FLAG_LOOP);

idle:
while (true) {
while (LOG_PROCESS()) {
}

/* Wait for an event. */
__WFE();

/* Clear Event Register */
__SEV();
__WFE();

}

return 0;
}