diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index e19bea6259..b25e0b0299 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -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 ----------- diff --git a/samples/peripherals/pwm/CMakeLists.txt b/samples/peripherals/pwm/CMakeLists.txt new file mode 100644 index 0000000000..36404b3c90 --- /dev/null +++ b/samples/peripherals/pwm/CMakeLists.txt @@ -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) diff --git a/samples/peripherals/pwm/Kconfig b/samples/peripherals/pwm/Kconfig new file mode 100644 index 0000000000..e4c972371e --- /dev/null +++ b/samples/peripherals/pwm/Kconfig @@ -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 + +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" diff --git a/samples/peripherals/pwm/README.rst b/samples/peripherals/pwm/README.rst new file mode 100644 index 0000000000..81ca98da07 --- /dev/null +++ b/samples/peripherals/pwm/README.rst @@ -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. diff --git a/samples/peripherals/pwm/prj.conf b/samples/peripherals/pwm/prj.conf new file mode 100644 index 0000000000..8e1424b0db --- /dev/null +++ b/samples/peripherals/pwm/prj.conf @@ -0,0 +1,2 @@ +CONFIG_LOG=y +CONFIG_LOG_BACKEND_BM_UARTE=y diff --git a/samples/peripherals/pwm/sample.yaml b/samples/peripherals/pwm/sample.yaml new file mode 100644 index 0000000000..49d9c9ae02 --- /dev/null +++ b/samples/peripherals/pwm/sample.yaml @@ -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 diff --git a/samples/peripherals/pwm/src/main.c b/samples/peripherals/pwm/src/main.c new file mode 100644 index 0000000000..927227ec3d --- /dev/null +++ b/samples/peripherals/pwm/src/main.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include +#include + +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; +}