Antes de continuar con el siguiente demo por favor siga los pasos a seguir para instalar el Nordic nRF54L15-DK Zephyr Linux. El propósito de este demo es ilustrar como el módulo de modulación de ancho de pulso (PWM) usando Zephyr con el kit IoT de Nordic nRF54L15-DK usando el LED interno,
Crea el siguiente archivo de configuración Zephyr llamado proj.conf en el directorio de su preferencia,
#
# Copyright (c) 2024 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
# Logging
CONFIG_LOG=y
# Enable PWM
CONFIG_PWM=y
CONFIG_PWM_LOG_LEVEL_DBG=y
# Enable LED and LED PWM
CONFIG_LED=y
CONFIG_LED_PWM=y
Siguiendo el proceso standard de desarollo de Zephyr, incluya el siguiente archivo de CMakeLists.txt dentro del directorio del projecto de su preferencia,
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(spi)
target_sources(app PRIVATE src/main.c)
Tambien se incluye el siguiente archivo de overlay Zephyr llamado nrf54l15dk_nrf54l15.overlay,
/{
pwmleds {
compatible = "pwm-leds";
pwm_led0: pwm_led_0 {
pwms = <&pwm20 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
};
};
};
&pwm20 {
status = "okay";
pinctrl-0 = <&pwm20_custom>;
pinctrl-1 = <&pwm20_csleep>;
pinctrl-names = "default", "sleep";
};
&pinctrl {
pwm20_custom: pwm20_custom {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 1, 10)>;
nordic,invert;
};
};
pwm20_csleep: pwm20_csleep {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 1, 10)>;
low-power-enable;
};
};
};
Finalmente se crea un directorio llamado src donde el código main.c del demo reside,
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
/* Include the relevant headers for pwm*/
#include <zephyr/device.h>
#include <zephyr/drivers/pwm.h>
LOG_MODULE_REGISTER(DigiKey_Coffee_Cup, LOG_LEVEL_INF);
/* Define the desired PWM period and pulse */
#define PWM_PERIOD_NS 100000000
#define PWM_PULSE_WIDTH 1400000
/* Get the node identifier for [] through its alias */
#define PWM_LED0 DT_ALIAS(pwm_led0)
/* Initialize and populate struct pwm_dt_spec */
static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(PWM_LED0);
int main(void)
{
int err;
/* Check if the device is ready */
if (!pwm_is_ready_dt(&pwm_led0)) {
LOG_ERR("Error: PWM device %s is not ready", pwm_led0.dev->name);
return 0;
}
/* Control the LED with the control signal generated from the PWM */
err = pwm_set_dt(&pwm_led0, PWM_PERIOD_NS, PWM_PULSE_WIDTH);
if (err) {
LOG_ERR("Error in pwm_set_dt(), err: %d", err);
return 0;
}
return 0;
}
El directorio de Zephyr debe ser como se muestra a continuación,
|-- CMakeLists.txt
|-- nrf54l15dk_nrf54l15.overlay
|-- prj.conf
`-- src
|-- main.c
Ahora se procede a construir el projecto de Zephyr como sigue dentro del ambiente virtual de Python,
digikey_coffee_cup (venv) $ west build -p always -b nrf54l15dk/nrf54l15/cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=nrf54l15dk_nrf54l15.overlay
Finalmente se conecta el kit de Nordic nRF54L15-DK via la interfaz USB y se programa así,
digikey_coffee_cup (venv) $ west flash
El siguiente video muestra como el LED en el kit de Nordic nRF54L15-DK recibe la señal PWM,
El kit de Nordic nRF54L15-DKes una excelente plataforma IoT de desarrollo y está disponible en DigiKey. Que tenga un buen día.
Este artículo esta disponible en inglés aquí.
This article is available in english here.
