Skip to content

Commit 31c8113

Browse files
authored
Merge pull request #3233 from brimston3/fix_k20_pwmclk
K20xx Calculate PWM clock relative to bus clock
2 parents c131a27 + 8482aaf commit 31c8113

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

targets/TARGET_Freescale/TARGET_K20XX/pwmout_api.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
2727
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
2828
MBED_ASSERT(pwm != (PWMName)NC);
2929

30+
uint32_t MGCOUTClock = SystemCoreClock * (1u + ((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV1_MASK) >> SIM_CLKDIV1_OUTDIV1_SHIFT));
31+
uint32_t BusClock = MGCOUTClock / (1u + ((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV2_MASK) >> SIM_CLKDIV1_OUTDIV2_SHIFT));
32+
3033
uint32_t clkdiv = 0;
31-
float clkval = SystemCoreClock / 1000000.0f;
34+
float clkval = BusClock / 1000000.0f;
3235

3336
while (clkval > 1) {
3437
clkdiv++;

0 commit comments

Comments
 (0)