Hi everyone,
I am trying to configure TPM/PWM in MKL27 (MKL27Z256VFM4 , KSDK 1.2.0, KDS 3.0.0, MQX for KSDK), and MCU reboots when doing TPM_DRV_PwmStart().
My code is similar to the one in example tpm_example_frdmkl27z. I have found that the crash happens when writing to CSnC register in: TPM_WR_CnSC(tpmBase, channel, value)
(called in TPM_HAL_SetChnMsnbaElsnbaVal()).
I am using channel 0, and value=40 (so MSB:MSA=10 and ELSB:ELSA=10).
Could you give me any ideas?
Thank you very much
Solved! Go to Solution.
Hi xiangjun.rong,
We have finally found the reason of the reboots: it was a HW problem: a short in our custom board unity. Our HW team repaired it and now the TPM/PWM is working ok managing a driver vibrator. So everything wask ok with our software solution.
Thank you very much for your help.
Hi, Jose,
If it is convenient, can you attach the project so that we can have a review even have a test?
BR
XiangJun Rong
Hi xiangjun.rong,
We have finally found the reason of the reboots: it was a HW problem: a short in our custom board unity. Our HW team repaired it and now the TPM/PWM is working ok managing a driver vibrator. So everything wask ok with our software solution.
Thank you very much for your help.
Hi, Jose,
After the FTM start, you can not change the CSnC register. If you want to change the register, you have to stop the FTM by clearing the CMOD bits in TPMx_SC register, then change the FTM_CnSC registyer, then set the CMOD bits as you desired to start FTM.
Pls refer to section 23.4.4 Channel (n) Status and Control (TPMx_CnSC) in the user manual of Kl27, I copy it here:
"
23.4.4 Channel (n) Status and Control (TPMx_CnSC)
CnSC contains the channel-interrupt-status flag and control bits used to configure the
interrupt enable, channel configuration, and pin function. When switching from one
channel mode to a different channel mode, the channel must first be disabled and this
must be acknowledged in the TPM counter clock domain.
"
BR
Xiangjun Rong
Hi again,
I have found the cause of the reboots: it seems that the two pins used as TPM0_CH0 and TPM0_CH1 (PTC1 and PTC2 respectively) must be initially configured as outputs (and not only configured to use ALT4 config), so I added these pins to the outputPins in gpio_pins.c so that they are configured in GPIO_DRV_Init():
{ | ||||
.pinName = kGpioVIBRATOR1, | ||||
.config.outputLogic = 0, | ||||
.config.slewRate = kPortSlowSlewRate, | ||||
.config.driveStrength = kPortLowDriveStrength, | ||||
}, | ||||
{ | ||||
.pinName = kGpioVIBRATOR2, | ||||
.config.outputLogic = 0, | ||||
.config.slewRate = kPortSlowSlewRate, | ||||
.config.driveStrength = kPortLowDriveStrength, | ||||
}, |
With this change, the board does not restart, though I don't understand the reason causing this behaviour.
Thanks.
BR
José Antonio Martínez.
Hi,
I have revised code of function in TPM_HAL_EnablePwmMode() in file fsl_tpm_hal.c. This function disables (and then enables) the counter when calling TPM_HAL_SetCpwms(). However, it does NOT when calling TPM_HAL_SetChnMsnbaElsnbaVal() that is the call that causes my MKL27 to reboot. So, I have added the same protection to disable de counter before calling it, and enable it again after the call, but it does not fix the issue:
clkSrc = TPM_HAL_GetClockMode(tpmBase);
TPM_HAL_SetClockMode(tpmBase, kTpmClockSourceNoneClk);
TPM_HAL_SetChnMsnbaElsnbaVal(tpmBase, channel, val);
TPM_HAL_SetClockMode(tpmBase, clkSrc);
With this instructions I guess that I am following your upper indications (clear CMOD before changing FTM_CnSC and restore it later), so any idea about what is going wrong?
Thank you very much
BR
José Antonio Martínez.
Hi again,
Reading carefully your response I have also noted that the text you referenced appears in section 29.4.4 of document KL27P64M48SF6RM (Rev 4, September 2014), that is the one that I am using. However you pointed it as section 23.4.4: Is it another document? another revision? maybe a typo?...
Thanks a lot!
BR
José Antonio Martínez
Hi xiangjun.rong,
Thank you four your response. I am going to study deeply now, but at first sight I am a bit confused. In my program I am using the following secuence:
TPM_DRV_Init(TPM_INSTANCE_0, &tpmConfig);
TPM_DRV_SetClock(TPM_INSTANCE_0, kTpmClockSourceModuleHighFreq, kTpmDividedBy2);
TPM_DRV_PwmStart(TPM_INSTANCE_0, ¶m, TPM_CHANNEL_0);
and the fail happens inside this last function, because TPM_DRV_PwmStart() internally modifies TPMx_CnSC. So, what are then the correct steps to configure and start TPM/PWM using high level TPM driver (fsl_tpm_driver.h)?
Thank you very much.
Regards.
José Antonio Martínez