I’m currently exploring peripheral support on the nRF54L15 and nRF54LM20A series controllers. I need to turn an LED on and off using the PWM component. The LED is connected to pin P2.0. Please help me with the overlay creation and a sample code snippet. I tried using the Zephyr PWM example, but the configuration is failing.
&pinctrl {
pwm21_default: pwm21_default {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 2, 0)>; // Use P2.0
};
};
};
&pwm21 {
compatible = "nordic,nrf-pwm";
status = "okay";
pinctrl-0 = <&pwm21_default>;
pinctrl-names = "default";
};
/* Include headers */
#include <zephyr/kernel.h>
#include <zephyr/drivers/pwm.h>
#define PWM_PERIOD 100
#define PWM_STEP 10
#define DIRECTION_FORWARD 0
#define DIRECTION_BACKWARD 1
const struct device *dev_pwm;
int cycle = 0;
int direction = DIRECTION_FORWARD;
int main(void)
{
int ret;
dev_pwm = DEVICE_DT_GET(DT_NODELABEL(pwm21));
while (true) {
pwm_pin_set_usec(dev_pwm, 31, PWM_PERIOD, cycle, 0);
if (direction == DIRECTION_FORWARD) {
if (cycle < PWM_PERIOD) {
cycle += PWM_STEP;
} else {
direction = DIRECTION_BACKWARD;
}
} else {
if (cycle > 0) {
cycle -= PWM_STEP;
} else {
direction = DIRECTION_FORWARD;
}
}
k_sleep(K_MSEC(PWM_PERIOD));
}
return 0;
}
