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

stm32: pwm capture with four channel support skips captures #84044

Open
gumulka opened this issue Jan 15, 2025 · 0 comments
Open

stm32: pwm capture with four channel support skips captures #84044

gumulka opened this issue Jan 15, 2025 · 0 comments
Assignees
Labels
area: PWM Pulse Width Modulation bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32

Comments

@gumulka
Copy link
Contributor

gumulka commented Jan 15, 2025

Describe the bug

When trying to implement tests for pwm pattern generation, I found that, when four-channel-capture support is enabled on a pwm channel, then every second capture is only passed on to the system, and every other capture is silently dropped.

If I disable four-channel-capture-support everything works fine.

See the code in https://github.com/gumulka/zephyr/tree/pwm_pattern_generation. To be precise: main...gumulka:zephyr:pwm_pattern_generation

To Reproduce

  • Check out my zephyr branch and execute the twister test for the nucleo board.
  • run the test west twister -T tests/drivers/pwm/pwm_loopback -v --inline-logs -p nucleo_h743zi --device-testing --device-serial /dev/serial/by-id/usb-STMicroelectronics_STLINK-V3_004C00243133510537363734-if02 -X pwm_loopback
  • remove the line about four-channel-capture-support in the overlay.
  • run again

Expected behavior

The description read, as if the results for four-channel-capture-support are less accurate, but not, that they are missing samples. I expected every sample to be there and captured by the system.

Impact

Annoyance

Logs and console output

I added the following patch to the code:

diff --git a/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c b/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c
index 588796c98a4..170b912954b 100644
--- a/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c
+++ b/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c
@@ -459,6 +459,15 @@ ZTEST(pwm_loopback, test_set_pattern)
        err = pwm_disable_capture(in.dev, in.pwm);
        zassert_equal(err, 0, "failed to disable pwm capture (err %d)", err);
 
+       printf("captured samples: %d\n", data_in.count);
+
+       for (i = 0; i < data_in.count; i++) {
+               uint64_t period, pulse;
+               pwm_cycles_to_usec(in.dev, in.pwm, periods_in[i], &period);
+               pwm_cycles_to_usec(in.dev, in.pwm, pulses_in[i], &pulse);
+               printf("%d: %lld/%lld\n", i, pulse, period);
+       }
+
        zassert_between_inclusive(data_in.count, NUM_SAMPLES / 2, NUM_SAMPLES,
                                  "Did not capture enough samples!");
 

The resulting log:

START - test_set_pattern
captured samples: 3
0: 1196/3596
1: 1996/5996
2: 2796/8396

    Assertion failed at WEST_TOPDIR/zephyr/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c:471: pwm_loopback_test_set_pattern: (data_in.count not between NUM_SAMPLES / 2 and NUM_SAMPLES inclusive)
Did not capture enough samples!

When the samples should have been something along the lines of:
0: 800/2400
1: 1200/3600
2: 1600/4800
3: 2000/6000
4: 2400/7200
5: 2800/8400
6: 3200/9600

Environment (please complete the following information):

  • OS: Linux
  • on my Zephyr fork the commit 2618a25, but the problem is also in zephyr main, just not visible because it is never tested.

I'm currently only testing on a nucleo_h753zi, but compiling it as a nucleo_h743zi, because for PWM it is equal enough. If I remove the line

https://github.com/gumulka/zephyr/blob/2618a257aaf8a1bb825507bbc445c567aa2a9bf4/tests/drivers/pwm/pwm_loopback/boards/nucleo_h743zi.overlay#L38

then everything works fine. I the line is there, then every second signal is not captured.

@gumulka gumulka added the bug The issue is a bug, or the PR is fixing a bug label Jan 15, 2025
@kartben kartben added the area: PWM Pulse Width Modulation label Jan 15, 2025
@henrikbrixandersen henrikbrixandersen added the platform: STM32 ST Micro STM32 label Jan 16, 2025
@henrikbrixandersen henrikbrixandersen assigned erwango and unassigned anangl Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: PWM Pulse Width Modulation bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32
Projects
None yet
Development

No branches or pull requests

5 participants