Hello,
I am in the process of following a series of tutorial videos on driving an LED with pwm, but I don't understand how to properly configure my .overlay file and my main.c file to generate pwm signals from a built-in pwm signal generator (e.g. pwm0) on a custom GPIO pin (e.g. P1.02).
my board is an Arduino Nano 33 BLE (Sense) with an nRF52840 ARM Cortex-M4F chip.
here are my current project files even though I know they're buggy (don't worry about preserving what I have though, I just want to know how to do this correctly):
arduino_nano_33_ble.overlay:
/ {
pwmleds {
compatible = "pwm-leds";
fading_led: fading_led {
pwms = <&pwm0 0 10000 PWM_POLARITY_NORMAL>;
};
};
};
&pinctrl {
pwm0_custom: pwm0_custom {
group1 {
psels = <NRF_PSEL(PWM_OUT3, 1, 2)>;
nordic,invert;
};
};
};
&pwm0 {
pinctrl-0 = <&pwm0_custom>;
/delete-property/ pinctrl-1;
pinctrl-names = "custom";
};
src/main.c:
#include <zephyr/device.h>
#include <zephyr/drivers/pwm.h>
#include <zephyr/kernel.h>
static const struct pwm_dt_spec green_fade_led = PWM_DT_SPEC_GET(DT_NODELABEL(fading_led));
void main(void) {
if (!device_is_ready(green_fade_led.dev)) {
return;
}
int ret;
while (1) {
ret = pwm_set_pulse_dt(&green_fade_led, 0);
k_sleep(K_SECONDS(1));
ret = pwm_set_pulse_dt(&green_fade_led, 10000);
k_sleep(K_SECONDS(1));
}
}
prj.conf:
CONFIG_CPP=y CONFIG_PWM=y CONFIG_LED=y CONFIG_LED_PWM=y
Thank you!
-spicysaberist