Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with PWM device configuration and alias resolution in Zephyr #81754

Open
jayesh0711 opened this issue Nov 22, 2024 · 0 comments
Open

Issues with PWM device configuration and alias resolution in Zephyr #81754

jayesh0711 opened this issue Nov 22, 2024 · 0 comments
Labels
bug The issue is a bug, or the PR is fixing a bug

Comments

@jayesh0711
Copy link

jayesh0711 commented Nov 22, 2024

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");

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>;
};

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:

  1. error: 'DT_N_ALIAS_pwm_led0_P_pwms_IDX_0_VAL_period' undeclared here (not in a function)
  2. error: 'DT_N_ALIAS_pwm_led0_P_pwms_IDX_0_VAL_channel' undeclared here (not in a function)
  3. 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!
@jayesh0711 jayesh0711 added the bug The issue is a bug, or the PR is fixing a bug label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

1 participant