Skip to content

STM32 PWM driver generates signal with wrong frequency on STM32G4 #30705

@martinjaeger

Description

@martinjaeger

Describe the bug

The following code snipped should generate a 5 kHz PWM signal with 50% duty cycle.

#define PWM_CONTROLLER "PWM_8"
#define PWM_PERIOD 200000 /* 200 us period = 5 kHz */
#define PWM_CHANNEL 1

void start_pwm()
{
    const struct device *pwm_dev = device_get_binding(PWM_CONTROLLER);
    pwm_pin_set_nsec(pwm_dev, PWM_CHANNEL, PWM_PERIOD, PWM_PERIOD / 2, 0);
}

The actual signal generated is 7.5 kHz (duty cycle of 50% is correct).

Tested MCUs: STM32G431 and STM32G474.

Environment:

  • OS: Linux
  • Zephyr master, SHA: 1b680c8

@gmarull I'm trying to find a fix for the issue myself, but if you already have an idea what could be wrong, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: PWMPulse Width ModulationbugThe issue is a bug, or the PR is fixing a bugplatform: STM32ST Micro STM32

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions