Skip to content
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

Merged
merged 6 commits into from
Mar 9, 2017
Merged

Fix pwm period calc #3795

merged 6 commits into from
Mar 9, 2017

Conversation

LMESTM
Copy link
Contributor

@LMESTM LMESTM commented Feb 17, 2017

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

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
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same test

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Any update for this?

Copy link
Contributor

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.

/* 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)
Copy link
Contributor

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

Copy link
Contributor Author

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 ?

Copy link
Contributor

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[] =
Copy link
Contributor

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).

Copy link
Contributor Author

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();
}
@LMESTM
Copy link
Contributor Author

LMESTM commented Feb 27, 2017

@0xc0170 @bcostm branch updated as per your comments

@LMESTM
Copy link
Contributor Author

LMESTM commented Mar 6, 2017

@0xc0170 hey - I think the PR now takes into account your comments - let me know if anything missing

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 6, 2017

/morph test

@mbed-bot
Copy link

mbed-bot commented Mar 6, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1641

Build failed!

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 7, 2017

@LMESTM Please look at the failures

Here's the output (XDOT platform fails for all 3 toolchains)

13:29:01         [Error] PeripheralPins.c@88,0:  #54-D: too few arguments in invocation of macro "STM_PIN_DATA_EXT"
13:29:01         [Error] PeripheralPins.c@88,0:  #158: expression must be an lvalue or a function designator
13:29:01         [Error] PeripheralPins.c@88,0:  #158: expression must be an lvalue or a function designator
13:29:01         [Warning] PeripheralPins.c@88,0:  #1278-D: excess initializers are ignored

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
@LMESTM
Copy link
Contributor Author

LMESTM commented Mar 7, 2017

@0xc0170 - thanks - there was a typo in this XDOT file. Fixed now.

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 8, 2017

/morph test

@mbed-bot
Copy link

mbed-bot commented Mar 8, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1654

All builds and test passed!

aisair pushed a commit to aisair/mbed that referenced this pull request Apr 30, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants