Set up a Pancake Motor with a nRF5340 and getting an error on device_is_ready

I am trying to get a pancake motor working with a nRF5340 using Zephyr in VSC. I have an intermediary board.

I keep getting this error:

 <wrn> vibration_manager: Vibration motor control not supported

I have these settings in the overlay:

    vib_pwr: vib-pwr-ctrl {
        compatible = "regulator-fixed";
        regulator-name = "vib-pwr-ctrl";
        enable-gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>;
    };

    pwmleds {
        compatible = "pwm-leds";
        vibrator_pwm: pwm_led_0 {
            pwms = <&pwm0 0 PWM_MSEC(20) 0>;
        };
    };

And have these two lines in the program:

static const struct pwm_dt_spec vib_motor = PWM_DT_SPEC_GET_OR(DT_ALIAS(vibrator_pwm), {});
static const struct gpio_dt_spec enable_gpio = GPIO_DT_SPEC_GET_OR(DT_NODELABEL(vib_pwr), enable_gpios, {});

Here is the init code:

void vibration_manager_init(void)
{
    LOG_DBG("Initializing vibration manager");

    int rc;
    
    if (!device_is_ready(enable_gpio.port)) {
        LOG_WRN("Vibration motor enable/disable not supported");
        return -ENODEV;
    }


    if (!device_is_ready(vib_motor.dev)) {
        LOG_WRN("Vibration motor control not supported");
        return -ENODEV;
    }



    rc = gpio_pin_configure_dt(&enable_gpio, GPIO_OUTPUT_LOW);
    if (rc != 0) {
        printk("Failed init vibration motor enable pin\n");
    }

    vibration_motor_set_on(false);

    vib_motor_enabled = true;

    return 0;
}

I have this in the prj.conf

# vibration motor and pwm
CONFIG_PWM=y

I read this post but it didn't help. I also read Haptics — Zephyr Project Documentation but don't know if it is implemented in the Nordic version yet.

Parents
  • I changed things around to make it simpler. Here are the overlay entries:

    &pinctrl {
    
        pwm0_default: pwm0_default {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 10)>;
    		};
    	};
    
    	pwm0_sleep: pwm0_sleep {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 10)>;
    			low-power-enable;
    		};
    	};
    	
    	...
    };
    
    
    &pwm0 {
        status = "okay";
        pinctrl-0 = <&pwm0_default>;
        pinctrl-1 = <&pwm0_sleep>;
        pinctrl-names = "default", "sleep";
    };
    
    
    / {
        ...
        
        pwmleds {
            compatible = "pwm-leds";
            pwm_led0: pwm_led_0 {
                //pwms = <&pwm0 0 PWM_MSEC(20) 0>;
                //pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
                pwms = <&pwm0 0 20000 PWM_POLARITY_NORMAL>;
                label = "FIT0774 Motor";
            };
        };
    };

    and the code:

    static const struct pwm_dt_spec vib_motor = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
    
    
    static bool vib_motor_enabled;
    static bool vib_motor_busy;
    
    void vibration_manager_init(void)
    {
        LOG_DBG("Initializing vibration manager");
    
        uint32_t pulse_width = vib_motor.period / 2; // 50% duty cycle
    
        int rc;
    
        if (!device_is_ready(vib_motor.dev)) {
            LOG_WRN("Vibration motor control not supported");
            return -ENODEV;
        }
    
        // Generate a short vibration
        pwm_set_pulse_dt(&vib_motor, vib_motor.period);
        k_sleep(K_MSEC(1000)); // Vibration duration: 100 milliseconds
        pwm_set_pulse_dt(&vib_motor, 0); // Stop the PWM signal
    
        LOG_DBG("Single short vibration test completed.");
    
    
        vib_motor_enabled = true;
    
        return 0;
    }

    The error is gone but no vibration.

Reply
  • I changed things around to make it simpler. Here are the overlay entries:

    &pinctrl {
    
        pwm0_default: pwm0_default {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 10)>;
    		};
    	};
    
    	pwm0_sleep: pwm0_sleep {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 10)>;
    			low-power-enable;
    		};
    	};
    	
    	...
    };
    
    
    &pwm0 {
        status = "okay";
        pinctrl-0 = <&pwm0_default>;
        pinctrl-1 = <&pwm0_sleep>;
        pinctrl-names = "default", "sleep";
    };
    
    
    / {
        ...
        
        pwmleds {
            compatible = "pwm-leds";
            pwm_led0: pwm_led_0 {
                //pwms = <&pwm0 0 PWM_MSEC(20) 0>;
                //pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
                pwms = <&pwm0 0 20000 PWM_POLARITY_NORMAL>;
                label = "FIT0774 Motor";
            };
        };
    };

    and the code:

    static const struct pwm_dt_spec vib_motor = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
    
    
    static bool vib_motor_enabled;
    static bool vib_motor_busy;
    
    void vibration_manager_init(void)
    {
        LOG_DBG("Initializing vibration manager");
    
        uint32_t pulse_width = vib_motor.period / 2; // 50% duty cycle
    
        int rc;
    
        if (!device_is_ready(vib_motor.dev)) {
            LOG_WRN("Vibration motor control not supported");
            return -ENODEV;
        }
    
        // Generate a short vibration
        pwm_set_pulse_dt(&vib_motor, vib_motor.period);
        k_sleep(K_MSEC(1000)); // Vibration duration: 100 milliseconds
        pwm_set_pulse_dt(&vib_motor, 0); // Stop the PWM signal
    
        LOG_DBG("Single short vibration test completed.");
    
    
        vib_motor_enabled = true;
    
        return 0;
    }

    The error is gone but no vibration.

Children
Related