-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix pwm period calc #3795
Fix pwm period calc #3795
Conversation
As done for other families, let's define the PWM channel in the PWM pins table definition rather than driver.
The pwmout driver is very similar for each STM32 family. The only family specific part is defined in pwmout_device.h file. It mainly contains few specific information: - The mapping of PWM/TIMERS to APB1 or APB2 so that we can get the clock - The clock calculation uses the right APB clock, which was sometimes not the case before and could have lead to errors in case dividers were enabled on APB clock settings. This case is now covered. - Inactivation of inverted support on feaw families
targets/TARGET_STM/pwmout_api.c
Outdated
TimHandle.Init.Period = (us - 1); | ||
|
||
/* In case period or pre-scalers are out of range, loop-in to get valid values */ | ||
while ((TimHandle.Init.Period > 0xFFFF) || (TimHandle.Init.Period > 0xFFFF)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops - needs to be corrected
will do when I'm back in office
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any update for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LMESTM is off this week.
targets/TARGET_STM/pwmout_api.c
Outdated
/* In case period or pre-scalers are out of range, loop-in to get valid values */ | ||
while ((TimHandle.Init.Period > 0xFFFF) || (TimHandle.Init.Period > 0xFFFF)) { | ||
obj->prescaler = obj->prescaler * 2; | ||
if (APBxCLKDivider == RCC_HCLK_DIV1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you are touching this file, please fix formatting if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xc0170 I had a quick look but probably missed the point - what's wrong with current formatting ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
if (condition) {
do();
} else {
do_else();
}
{
and }
are missing there
PwmoutApb pwmoutApb; | ||
} pwm_apb_map_t; | ||
|
||
static const pwm_apb_map_t pwm_apb_map_table[] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there was earlier PR about 2 weeks ago that was defining some variables in the header file. I raised an issue there that this would be much better if it's done in a code file.
It works now as it is included in just one code file. however, this might become a silent bomb later if this HAL will include a new code file that would require some declarations from this file (it's possible and might be overlooked that this actually defines this map of pwm).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xc0170 yes you're right ! I will move the definition to a C file
Correct the while loop limit and add a safe guard to avoid infinite loop.
In order to avoid possible multiple definitions errors, move the table initialization to the C file instead of header file
Use the recommended style if (condition) { do(); } else { do_else(); }
@0xc0170 hey - I think the PR now takes into account your comments - let me know if anything missing |
/morph test |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputBuild failed! |
@LMESTM Please look at the failures Here's the output (XDOT platform fails for all 3 toolchains)
The link is above in the failure message to get this log |
Typo with misplaced closing parenthesis leads to compilation error, which is fixed with this patch
@0xc0170 - thanks - there was a typo in this XDOT file. Fixed now. |
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
Ports for Upcoming Targets Fixes and Changes 3716: fix for issue #3715: correction in startup files for ARM and IAR, alignment of system_stm32f429xx.c files ARMmbed/mbed-os#3716 3741: STM32 remove warning in hal_tick_32b.c file ARMmbed/mbed-os#3741 3780: STM32L4 : Fix GPIO G port compatibility ARMmbed/mbed-os#3780 3831: NCS36510: SPISLAVE enabled (Conflict resolved) ARMmbed/mbed-os#3831 3836: Allow to redefine nRF's PSTORAGE_NUM_OF_PAGES outside of the mbed-os ARMmbed/mbed-os#3836 3840: STM32: gpio SPEED - always set High Speed by default ARMmbed/mbed-os#3840 3844: STM32 GPIO: Typo correction. Update comment (GPIO_IP_WITHOUT_BRR) ARMmbed/mbed-os#3844 3850: STM32: change spi error to debug warning ARMmbed/mbed-os#3850 3860: Define GPIO_IP_WITHOUT_BRR for xDot platform ARMmbed/mbed-os#3860 3880: DISCO_F469NI: allow the use of CAN2 instance when CAN1 is not activated ARMmbed/mbed-os#3880 3795: Fix pwm period calc ARMmbed/mbed-os#3795 3828: STM32 CAN API: correct format and type ARMmbed/mbed-os#3828 3842: TARGET_NRF: corrected spi_init() to properly handle re-initialization ARMmbed/mbed-os#3842 3843: STM32L476xG: set APB2 clock to 80MHz (instead of 40MHz) ARMmbed/mbed-os#3843 3879: NUCLEO_F446ZE: Add missing AnalogIn pins on PF_3, PF_5 and PF_10. ARMmbed/mbed-os#3879 3902: Fix heap and stack size for NUCLEO_F746ZG ARMmbed/mbed-os#3902 3829: can_write(): return error code when no tx mailboxes are available ARMmbed/mbed-os#3829
Description
This pull request solves an issue that was encountered in specific cases where pwm HW frequency is high and the pwm period was about 100ms (encountered on F746). This was a limitation due to hard coded pre-scaler values of 1 or 500 only. The solution is to have more granularity.
In order to apply the fix to all families and not only F7, the code is also made common between all families which makes maintenance easier.
Status
READY
TESTS RESULTS
pwm_test_results.txt