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.
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:
- OUTDIV1 is set twice
- OUTDIV2 is not set (div2 is ignored)
- div3 is set on OUTDIV2 instead of OUTDIV3
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.
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:
- div3 is set on OUTDIV2 instead of OUTDIV3.
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.