Hey guys, I'm reviewing the Clock Setting for the KBoot v2.0.0 and just found out that the clock dividers are not being correctly set.
The file to check is the specific clock_config_*.c for the platform you're using.
The function to check is the configure_clocks(), step 9 or 10, around there.
In this example, I'm studying MK64F12 freedom_bootloader project (NXP_Kinetis_Bootloader_2_0_0\targets\MK64F12\kds\freedom_bootloader) and the source file in question is NXP_Kinetis_Bootloader_2_0_0\targets\MK64F12\src\clock_config_MK64F12.c.
Line 163:
SIM->CLKDIV1 = SIM_CLKDIV1_OUTDIV1(div1 - 1) | SIM_CLKDIV1_OUTDIV1(div1 - 1) | SIM_CLKDIV1_OUTDIV2(div3 - 1) | SIM_CLKDIV1_OUTDIV4(div4 - 1); /* Update system prescalers */
Three problems there:
Next example, MK22F51212 freedom_booltoader project (NXP_Kinetis_Bootloader_2_0_0\targets\MK22F51212\kds\freedom_bootloader) and NXP_Kinetis_Bootloader_2_0_0\targets\MK22F51212\src\clock_config_K22F512.c source file. Same problem as before.
Next example, MK66F18 freedom_bootloader project (NXP_Kinetis_Bootloader_2_0_0\targets\MK66F18\kds\freedom_bootloader) and NXP_Kinetis_Bootloader_2_0_0\targets\MK66F18\src\clock_source_MK66F18.c source file.
Line 155:
SIM->CLKDIV1 = SIM_CLKDIV1_OUTDIV1(div1 - 1) |
SIM_CLKDIV1_OUTDIV2(div2 - 1) |
SIM_CLKDIV1_OUTDIV2(div3 - 1) |
SIM_CLKDIV1_OUTDIV4(div4 - 1); // Update system prescalers
One problem here:
Whoever is thinking on using the bootloader, please check carefully this file. This may lead to "weird" problems, like the bootloader only works after a power on.
Cheers,
Bruno
Hi Bruno Albercht,
Thank you for pointing out this code bug.
The correct code should be:
SIM->CLKDIV1 = SIM_CLKDIV1_OUTDIV1(div1 - 1) | SIM_CLKDIV1_OUTDIV2(div2 - 1) | SIM_CLKDIV1_OUTDIV3(div3 - 1) |
SIM_CLKDIV1_OUTDIV4(div4 - 1); /* Update system prescalers */
Please modify it on your side now.
This is the known issue, and the driver will be updated in the future .
Thanks again!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------