Running PWMObjectInit sets channels to 0 and makes driver unusable. Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
haykodarb
Posts: 2
Joined: Sat Apr 01, 2023 1:01 am

Running PWMObjectInit sets channels to 0 and makes driver unusable.  Topic is solved

Postby haykodarb » Wed Jan 03, 2024 4:44 am

Very minor issue, not sure if it even qualifies as a bug, but for all drivers I usually run driverObjectInit() at the start of my program just in case.

For the PWM driver, in line hal_pwm.c:73 pwmp->channels is set to 0 and never set again after that.

If you try to run pwmEnableChannel it will fail at hal_pwm.c:188 when it checks "channel < pwmp->channels"

pwmp->channels is only set at the start of pwm_lld_init().

Removing line hal_pwm.c:73 or never running pwmObjectInit unnecessarily solves the issue.

User avatar
Giovanni
Site Admin
Posts: 14458
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Running PWMObjectInit sets channels to 0 and makes driver unusable.

Postby Giovanni » Wed Jan 03, 2024 7:14 am

Hi,

pwmObjectInit() is called internally by the LLD which also sets the channels field, the HLD has no knowledge about the number of channels.

In general, halInit() initializes everything, calling xxxObjectInit() functions undoes initialization already performed in the LLDs.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 6 guests