Hello, I'm trying to use the FlexPWM peripheral of the MCXA156 SoC in a FRDM_MCXA156 devboard using Zephyr but I can't get it to fully work.
Whatever I try, the pulse and period seen in the associated output pins do not correspond with the values I am assigning it.
I have found a way to reproduce the issue using the blinky_pwm example. Using the reproduction steps below I only get a small pulse of less than 1ms in pin P3_6 (where channel 0 of flexpwm0_pwm0 is linked) whenever the PWM is reconfigured, but nothing in between. AFAIK the example should be setting a 50% duty cycle signal and that is not what I am seeing.
It is not a regression; I've tried the same thing on a semi-recent commit 0d46a93 and commit 9f6fdae (Where PWM was implemented for the FRDM_MCXA156 board) and the issue still happens.
Steps to reproduce:
#include <zephyr/dt-bindings/pwm/pwm.h> / { pwmleds { compatible = "pwm-leds"; pwm_led_0: pwm_led_0 { pwms = <&flexpwm0_pwm0 0 PWM_MSEC(1) PWM_POLARITY_NORMAL>; label = "PWM LED 0"; }; }; aliases { pwm-led0 = &pwm_led_0; pwm-0 = &flexpwm0_pwm0; }; };
Logs don't show much:
[00:00:00.000,069] <dbg> pwm_mcux: pwm_mcux_init: Set prescaler 128, reload mode 2 *** Booting Zephyr OS build v4.2.0-2444-g0d46a934171a *** PWM-based blinky Calibrating for channel 0... [00:00:00.017,179] <err> pwm_mcux: Too long period (750000), adjust pwm prescaler! [00:00:00.025,412] <err> pwm_mcux: Too long period (375000), adjust pwm prescaler! [00:00:00.033,645] <err> pwm_mcux: Too long period (187500), adjust pwm prescaler! [00:00:00.041,879] <err> pwm_mcux: Too long period (93750), adjust pwm prescaler! Done calibrating; maximum/minimum periods 62500000/7812500 nsec Using period 62500000 Using period 31250000 Using period 15625000 Using period 7812500 Using period 15625000 Using period 31250000 ...
Attached is the (compressed) ELF final binary I got doing these steps.
I hope this is just a mistake on my side. Appreciate any feedback on this matter!
Thanks in advance
Hi @aperea-cc,
I imported the blinky_pwm example code from the Zephyr repository and added the overlay that you shared. Indeed, the P3_6 pin outputs small pulses instead of actual PWM signals.
After this test, I imported the normal pwm example (without Zephyr) and it worked properly with P3_6. This proves that the issue is not hardware, but rather software related. I will continue investigating whether the issue is on application level or on driver level on the Zephyr example. If you have any further developments, let me know.
BR,
Edwin.
Hello,
Thank you very much for your response and support. Yesterday I did the same thing (Comparing with the example from the official NXP SDK) and ended up noticing that the FlexPWM peripheral only works if the CPU is active. That would explain why in Zephyr doesn't work, since it sleeps for 4 seconds after every PWM configuration.
I don't think there's any elegant solution for this problem in Zephyr, since we'd need the CPU busy if we want the PWM to work, so I'm figuring out if the same behaviour I want can be reproduced using FlexIO instead.
From reading the reference manual it seems that FlexPWM is the only non-CPU-related peripheral that exhibits this behavior. It's in the same power management category as the watchdog, cache controller or CPU itself. Maybe this could be documented in the Zephyr driver somewhere; I think it'd save a lot of time to newcomers to the SoC.
Hi @aperea-cc,
Thanks for the suggestions of documenting this somewhere on the Zephyr driver. I will pass it on to the Zephyr team for their consideration.