Pablo
I just built your project with CW10.5 and had no problems - the LED always toggles with about 2.5us period - forever (irrespective of breakpoints etc.).
I recommend you build a FLASH target and flash it to your board to see whether it always behaves correctly (after power up and warm resets).
If this Flash version still causes problem, post a binary file (as created by CW10.6) so that it can be flashed to my board (it also has an old processor on it with the errate that can be successfully worked around !!). Ensure that the compiler version in CW10.6 is not optimising the workaround out of the code - CW10.5 compiler doesn't. [If thsi is happening and you have a PIT register view open it will be performing the workaround for you as it updates its view when stepping the IRQ code].
I have attached a binary file showing the TWR-K40 operating with PIT1 toggling the yellow LED every 500us - the red LED is toggled every 200ms by a SW timer so that you can verify that your board is OK (it does the workaround, otherwise the PIT wouldn't work correctly).
Regards
Mark
http://www.utasker.com/kinetis.html
P.S. In the code enabling NVIC interrupts I recommend using a define for the vector number rather than a fixed value.
| enable_irq(68); | | | | | | | | | | //Enable PIT IRQ in NVIC |
This will make the code portable across all K and KL device's PIT use - the number changes with certain type of chip (also within a family) and fixed values will cause code to break unnecessarily in case you choose to move to another device or want to reuse the code for a different project (with different Kinetis).