The design concept of application code is support USB CDC and CAN bus.
So we create a project code support CDC and the clock configuration is source from IRC48M.
After leave KBOOT and jump to application, sometime the CDC device will not show up at device manager.
So we place several GPIO to toggle LEDs to trace the critical issue and found the system is stuck in "CLOCK_SetPbeMode" while loop to check external reference clock.
But I also try that CDC function without KBOOT, always can found CDC device in device manager.
Please help check this issue and clarify the workaround steps.
Thanks.
Original Attachment has been moved to: bm.7z.zip
Original Attachment has been moved to: Kyle_MKS22FN256xxx12.mex.zip
Solved! Go to Solution.
I found another helpful link and solved this problem.
This is the link:
kinetis bootloader and application startup
Hello,
I have checked the clock configuration and the generated code and it seems correct. But I am not sure what the KBOOT modify on the MCU. The generated BOARD_BootClockRUN() function suppose the after reset state of all devices. When the BOARD_BootClockRUN() function is used in different context (e.g. MCG device was already initialized by the KBOOT and the MCG mode was changed) the function BOARD_BootClockRUN() may not work properly.
Best Regards,
Marek Neuzil
Hi Marek Neuzil,
I did not modify the KBOOT for KS22, the default setting should be PEE mode and clock source from IRC48M.
So as you said, if the clock configuration of KBOOT had already set to PEE mode.
If I try to setup clock mode in PEE again, the function may not work properly, right?
Hi Kyle,
The problem is that the BOARD_BootClockRUN() suppose the after-reset state of the MCG (FEI mode). If you use this method in the PEE MCG mode the behavior can be undefined.
It is caused by design of the MCG device that must be driven according to the following state diagram:
I.e. the BOARD_BootClockRUN() function provides transition from the FEI to the FBE, PBE and PEE modes of the MCG. But when the MCG device is in the PEE mode and the BOARD_BootClockRUN() function is executed the behavior of the MCG device is undefined.
In your use case, you can for example use directly the CLOCK_SetPbeMode() function (fsl_clock.c driver) that support transition from PEE to PBE mode and reconfiguration of the PLL device and then you can set the PEE mode by using the CLOCK_SetPeeMode() function.
Best Regards,
Marek Neuzil
Hi Marek Neuzil,
Yes, I know this clock transition flow and need to follow it when change the clock mode.
But according to the description in "CLOCK_SetPbeMode" API as attached snap shot.
This API can directly transition to PBE from any mode except PEI/PBI.
Hi Kyle,
You are right, you can directly use the CLOCK_SetPbeMode() function (I have already recommended it). But the BOARD_BootClockRUN() function contains a call of the CLOCK_BootToPeeMode() that also writes into the OSCSEL bitfield of the MCG_C7 register. It can cause the issue (even though it select the same clock source).
Best Regards,
Marek Neuzil
Hi Marek Neuzil,
OK... Is there any other way can change MCG mode from FEI to PEE and not stuck in the while loop.
This issue only occur in the case that leave KBOOT and jump to application.
When only application code available in flash without KBOOT, the issue will not duplicate anymore.
Hey Kyle ,
I am also facing the same issue. Only when it jumps from KBOOT to application i am getting stuck in the while loop you mentioned.
Were you able to solve it?
Please let me know it will be great help.
Thanks in advance.
Regards,
Abhi
Hi Abhishek,
Actually, no...
But I enabled a watchdog module to assure system won't keep hold by the while loop.
I am not sure this solution is accept for you, but you can try it.
I found another helpful link and solved this problem.
This is the link:
kinetis bootloader and application startup
Hi Kyle,
I am sorry I am not sure what is your issue. If you need to support both use cases (application with KBOOT and without KBOOT) you need to update the generated code of the BOARD_BootClockRUN() function. The function supports the startup initialization from the reset state only. When the MCG is in a different state the BOARD_BootClockRUN() may not work. You must update this generated function to detect the MCG mode and properly do the initialization in both use cases, e.g. if you detect the MCG PEE mode just call the CLOCK_SetPbeMode() and CLOCK_SetPeeMode() functions instead of the call CLOCK_BootToPeeMode().
Best Regards,
Marek Neuzil