Clock Dividers - Generic bug

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Clock Dividers - Generic bug

603 Views
brunoalbrecht
Contributor III

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:

  • 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.

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:

  • 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.

Cheers,

Bruno

Tags (3)
0 Kudos
1 Reply

406 Views
kerryzhou
NXP TechSupport
NXP TechSupport

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!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos