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.
Post Reply
haykodarb
Posts: 2
Joined: Sat Apr 01, 2023 1:01 am

Running PWMObjectInit sets channels to 0 and makes driver unusable.

Post by haykodarb »

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: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

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

Post by Giovanni »

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
Post Reply