Skip to content

Conversation

ttmut
Copy link
Contributor

@ttmut ttmut commented Oct 16, 2025

Fixes a bug in the prescaler configuration formula. Prescaler enumerations are not consecutive numbers, so the existing formula does not work as expected. Add prescaler enums into a lookup table and set counter prescaler from this array using prescaler_index parameter.

This is the same fix introduced in #95409, but for the counter driver.

Comment on lines -249 to -254
if (prescaler_index == 0) {
tmr_cfg.pres = TMR_PRES_1; /* TMR_PRES_1 is 0 */
} else {
/* TMR_PRES_2 is 1<<X */
tmr_cfg.pres = TMR_PRES_2 + (prescaler_index - 1);
}
Copy link
Contributor

@ozersa ozersa Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i did not miss something, seems logic simply can be
tmr_cfg.pres = prescaler_index * TMR_PRES_2;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you propagate it to pwm_max32.c ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ttmut ttmut force-pushed the fix/counter_max32 branch 2 times, most recently from a2a8a80 to 2267dc4 Compare October 16, 2025 14:13
Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the commit message needs to be updated or removed:

Add prescaler enums into a lookup table and set
counter prescaler from this array using prescaler_index parameter.

Otherwise LGTM

@MaureenHelm MaureenHelm added this to the v4.3.0 milestone Oct 17, 2025
hfakkiz and others added 2 commits October 20, 2025 08:30
The existing formula assumed prescaler enumerations were consecutive,
which led to incorrect values being passed to HAL functions. Update
the code to calculate correct prescaler enumerations.

Signed-off-by: Furkan Akkiz <[email protected]>
Replace the look-up table used to obtain the prescaler enumeration with
a simple multiplication.

Signed-off-by: Tahsin Mutlugun <[email protected]>
@ttmut ttmut force-pushed the fix/counter_max32 branch from 2267dc4 to 5902b57 Compare October 20, 2025 06:07
@zephyrbot zephyrbot added the area: PWM Pulse Width Modulation label Oct 20, 2025
@ttmut
Copy link
Contributor Author

ttmut commented Oct 20, 2025

Commit message has been fixed and the change has been propagated to pwm_max32.c.

@sonarqubecloud
Copy link

@cfriedt cfriedt merged commit 36a3a4c into zephyrproject-rtos:main Oct 20, 2025
30 checks passed
@MaureenHelm MaureenHelm deleted the fix/counter_max32 branch October 21, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Counter area: PWM Pulse Width Modulation platform: ADI Analog Devices, Inc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants