Hello DevZoners, I hope you are all doing great!
I'm struggling to understand how this works.
I've been following the NCS Tutorial part 2 to implement the PWM peripheral in 9160's chip (I have an nrf9160dk), and when I try to implement more than one channel pin using the same PWM instance, it does not work.
&pwm0 {
status = "okay";
ch0-pin = < 2 >;
ch1-pin = < 3 >;
};
#include <zephyr.h>
#include <sys/printk.h>
#include <drivers/pwm.h>
#define PWM_DEVICE_NAME DT_PROP(DT_NODELABEL(pwm0), label)
#define PWM_CH0_PIN DT_PROP(DT_NODELABEL(pwm0), ch0_pin)
#define PWM1_DEVICE_NAME DT_PROP(DT_NODELABEL(pwm0), label)
#define PWM1_CH0_PIN DT_PROP(DT_NODELABEL(pwm0), ch1_pin)
#define PWM_PERIOD 253
void main(void)
{
printk("PWM Application has started!\r\n");
uint8_t pulse = 0;
const struct device *pwm_dev = device_get_binding(PWM_DEVICE_NAME);
if (!pwm_dev) {
printk("Cannot find %s!\n", PWM_DEVICE_NAME);
return;
}
const struct device *pwm_dev1 = device_get_binding(PWM1_DEVICE_NAME);
if (!pwm_dev1) {
printk("Cannot find %s!\n", PWM1_DEVICE_NAME);
return;
}
while (1)
{
pulse = pulse +10;
if (pulse > PWM_PERIOD) {
pulse = 0;
}
if (pwm_pin_set_usec(pwm_dev, PWM_CH0_PIN, PWM_PERIOD, pulse, 0)) {
printk(".");
}
if (pwm_pin_set_usec(pwm_dev1, PWM1_CH0_PIN, PWM_PERIOD, pulse, 0)) {
printk(".");
}
k_sleep(K_MSEC(30));
}
}
For example, using the .overlay file and the code shown for the 9160DK and turn to the following error:
'DT_N_S_soc_S_peripheral_40000000_S_pwm_21000_P_ch1_pin' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_pwm_21000_P_ch0_pin'?
According to NCS tutorial, "The ch0-pin field is then transformed into the define DT_N_S_soc_S_peripheral_50000000_S_pwm_21000_P_ch0_pin inside <...>\light_controller\build\zephyr\include\generated\devicetree_unfixed.h and used by the driver pwm_nrfx.c through PWM_NRFX_OUTPUT_PIN()→PWM_NRFX_CH_PIN()."
Isn't supposed to make this automatically when I add more channels in the overlay file and the C code? Is this because the NCS version? I'm using the 1.6.1v and the 2.6.0v of Zephyr.
Obs: when I build this exact same code, but change the overlay file for the nrf52840DK it works.
