You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello Zephyr Community,
I'm encountering errors when trying to build my Zephyr application for controlling an LED using PWM i am using mec1521 ASSY 6883 development board . Below are the details of my configuration:
Code Overview:
In the main.c file, I’m trying to control an LED using PWM, and here is the relevant code:
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/device.h>
#include <zephyr/drivers/pwm.h>
/* Define PWM specifications for the LED */
static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
void main(void) {
printk("PWM LED Control Example\n");
if (!pwm_is_ready_dt(&pwm_led0)) {
printk("Error: PWM device is not ready\n");
return;
}
uint32_t period = MAX_PERIOD;
uint8_t dir = 0; /* Direction of change: 0 = decrease, 1 = increase */
while (1) {
/* Set PWM for the LED */
pwm_set_dt(&pwm_led0, period, period / 2);
printk("PWM Period: %u\n", period);
/* Adjust period */
if (dir) {
period *= 2;
if (period > MAX_PERIOD) {
period = MAX_PERIOD / 2;
dir = 0;
}
} else {
period /= 2;
if (period < MIN_PERIOD) {
period = MIN_PERIOD * 2;
dir = 1;
}
}
k_sleep(K_MSEC(500)); /* Adjust delay as needed */
}
}
Device Tree Configuration:
Here is the relevant section from my .dts overlay:
& pwm-0 {
status = "okay";
channel-gpios = <&gpio_040_076 0xb GPIO_ACTIVE_HIGH>;
};
Errors Encountered:
When trying to build the project, I am receiving the following errors:
error: 'DT_N_ALIAS_pwm_led0_P_pwms_IDX_0_VAL_period' undeclared here (not in a function)
error: 'DT_N_ALIAS_pwm_led0_P_pwms_IDX_0_VAL_channel' undeclared here (not in a function)
error: '__device_dts_ord_DT_N_ALIAS_pwm_led0_P_pwms_IDX_0_PH_ORD' undeclared here (not in a function)
The error seems to be related to how the PWM alias and associated properties are being handled.
What I’ve Tried:
• Verified the device tree overlay configuration.
• Ensured that the aliases are correctly defined.
• Checked if the PWM driver is correctly registered.
Question:
Could anyone help me understand why these undeclared errors are happening? Is there an issue with how I have defined the alias for the PWM LED, or am I missing something in the device tree setup? Any guidance on fixing these errors would be appreciated.
Thanks in advance!
The text was updated successfully, but these errors were encountered:
Hello Zephyr Community,
I'm encountering errors when trying to build my Zephyr application for controlling an LED using PWM i am using mec1521 ASSY 6883 development board . Below are the details of my configuration:
Code Overview:
In the main.c file, I’m trying to control an LED using PWM, and here is the relevant code:
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/device.h>
#include <zephyr/drivers/pwm.h>
/* Define PWM specifications for the LED */
static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
#define MIN_PERIOD PWM_MSEC(1)
#define MAX_PERIOD PWM_SEC(1U)
void main(void) {
printk("PWM LED Control Example\n");
}
Device Tree Configuration:
Here is the relevant section from my .dts overlay:
& pwm-0 {
status = "okay";
channel-gpios = <&gpio_040_076 0xb GPIO_ACTIVE_HIGH>;
};
pwmleds {
compatible = "pwm-leds";
pwm_led0: pwm_led_0 {
pwms = <&pwm-0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>; /* Channel 0, Period 20ms /
label = "PWM_LED0";
};
};
/ Define PWM channel for LED2 /
& pwm_led0 {
pwms = <&pwm-0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>; / Channel 0 */
label = "PWM_LED2";
};
Errors Encountered:
When trying to build the project, I am receiving the following errors:
The error seems to be related to how the PWM alias and associated properties are being handled.
What I’ve Tried:
• Verified the device tree overlay configuration.
• Ensured that the aliases are correctly defined.
• Checked if the PWM driver is correctly registered.
Question:
Could anyone help me understand why these undeclared errors are happening? Is there an issue with how I have defined the alias for the PWM LED, or am I missing something in the device tree setup? Any guidance on fixing these errors would be appreciated.
Thanks in advance!
The text was updated successfully, but these errors were encountered: