I'm using the SDK for MKW41Z512 and have found a probable error in the SDK related to the LPTMR. In fsl_lptmr.h there is a function for setting the compare register. For some reason (which does not make sense if the timer is free running) you are not allowed to set the compare to 0. The Reference Manual also states that:
When the LPTMR is enabled and the CNR equals the value in the CMR and increments, TCF is set
hence the compare value needs to be -1 to what is wanted. This results in the following code in the SDK:
static inline void LPTMR_SetTimerPeriod(LPTMR_Type *base, uint32_t ticks)
{
assert(ticks > 0);
base->CMR = ticks - 1;
}
However, if ticks = 1, assert is OK but 0 will be written to the register, which is not allowed (for normal behaviour)!
In the Reference Manual Rev. No. 3, there is a related error in the documentation. In Chapter 35.3.3 one can read:
If the LPTMR is enabled, the CMR must be altered only when TCF is set.
TCF is the Timer Compare Flag and it does not make sense that you can only alter the compare if a compare match has already happened. I believe that it should be TFC, Timer Free-Running Counter, i.e. you can only alter the compare when the LPTMR is running and is free running, which make sense!
Hi Samuel Vestlin
If you are using free running timer then there is no need to use the LPTMR_SetTimerPeriod API, CNR will be reset until it overflows and the interruption will be triggered when this happened
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Can we get a confirmation that the SDK is wrong there?
What about the datasheet saying TCF instead of TFC, is that correct?
Hi Jorge
I know that the free running timer will reset at 0 after overflow and continue to run, that's why I use it in free running mode.
However, I need to set compare values, e.g. CMR = CNR +10, and if my wanted compare happens to be 1, the provided SDK function will fail (since 0 will be written to the CMR). Hence, I have implemented my own setter to solve this, but the SDK is still not correct.
The error in the Reference Manual is also annoying.