@@ -35,7 +35,6 @@ static int flash_init = 0;
3535#endif
3636
3737#ifdef __WOLFBOOT
38- #define CPU_CORE_CLOCK 120000000U
3938
4039static void CLOCK_CONFIG_SetFllExtRefDiv (uint8_t frdiv )
4140{
@@ -44,6 +43,13 @@ static void CLOCK_CONFIG_SetFllExtRefDiv(uint8_t frdiv)
4443
4544static void do_flash_init (void );
4645
46+ /* Assert hook needed by Kinetis SDK */
47+ void __assert_func (const char * a , int b , const char * c , const char * d )
48+ {
49+ while (1 )
50+ ;
51+ }
52+
4753/* This are the registers for the NV flash configuration area.
4854 * Access these field by setting the relative flags in NV_Flash_Config.
4955 */
@@ -68,20 +74,62 @@ const uint8_t __attribute__((section(".flash_config"))) NV_Flash_Config[NVTYPE_L
6874 0xFF
6975};
7076
71-
72- /* Assert hook needed by Kinetis SDK */
73- void __assert_func (const char * a , int b , const char * c , const char * d )
77+ #if defined(CPU_MK82FN256VLL15 )
78+ struct stage1_config
7479{
75- while (1 )
76- ;
77- }
80+ uint32_t tag ;
81+ uint32_t crcStartAddress ;
82+ uint32_t crcByteCount ;
83+ uint32_t crcExpectedValue ;
84+ uint8_t enabledPeripherals ;
85+ uint8_t i2cSlaveAddress ;
86+ uint16_t peripheralDetectionTimeoutMs ;
87+ uint16_t usbVid ;
88+ uint16_t usbPid ;
89+ uint32_t usbStringsPointer ;
90+ uint8_t clockFlags ;
91+ uint8_t clockDivider ;
92+ uint8_t bootFlags ;
93+ uint8_t RESERVED1 ;
94+ uint32_t mmcauConfigPointer ;
95+ uint32_t keyBlobPointer ;
96+ uint8_t RESERVED2 [8 ];
97+ uint32_t qspiConfigBlockPtr ;
98+ uint8_t RESERVED3 [12 ];
99+ };
100+
101+ const struct stage1_config __attribute__((section (".stage1_config" )))
102+ NV_Stage1_Config = {
103+ .tag = 0x6766636BU , /* Magic Number */
104+ .crcStartAddress = 0xFFFFFFFFU , /* Disable CRC check */
105+ .crcByteCount = 0xFFFFFFFFU , /* Disable CRC check */
106+ .crcExpectedValue = 0xFFFFFFFFU , /* Disable CRC check */
107+ .enabledPeripherals = 0x17 , /* Enable all peripherals */
108+ .i2cSlaveAddress = 0xFF , /* Use default I2C address */
109+ .peripheralDetectionTimeoutMs = 0x01F4U , /* Use default timeout */
110+ .usbVid = 0xFFFFU , /* Use default USB Vendor ID */
111+ .usbPid = 0xFFFFU , /* Use default USB Product ID */
112+ .usbStringsPointer = 0xFFFFFFFFU , /* Use default USB Strings */
113+ .clockFlags = 0x01 , /* Enable High speed mode */
114+ .clockDivider = 0xFF , /* Use clock divider 1 */
115+ .bootFlags = 0x01 , /* Enable communication with host */
116+ .mmcauConfigPointer = 0xFFFFFFFFU , /* No MMCAU configuration */
117+ .keyBlobPointer = 0x000001000 , /* keyblob data is at 0x1000 */
118+ .qspiConfigBlockPtr = 0xFFFFFFFFU /* No QSPI configuration */
119+ };
120+ #endif
121+
78122
79123#define MCG_PLL_DISABLE 0U /*!< MCGPLLCLK disabled */
80124#define OSC_CAP0P 0U /*!< Oscillator 0pF capacitor load */
81125#define OSC_ER_CLK_DISABLE 0U /*!< Disable external reference clock */
82126#define SIM_OSC32KSEL_RTC32KCLK_CLK 2U /*!< OSC32KSEL select: RTC32KCLK clock (32.768kHz) */
83127#define SIM_PLLFLLSEL_IRC48MCLK_CLK 3U /*!< PLLFLL select: IRC48MCLK clock */
84128#define SIM_PLLFLLSEL_MCGPLLCLK_CLK 1U /*!< PLLFLL select: MCGPLLCLK clock */
129+ #define SIM_CLKDIV1_RUN_MODE_MAX_CORE_DIV 1U /*!< SIM CLKDIV1 maximum run mode core/system divider configurations */
130+ #define SIM_CLKDIV1_RUN_MODE_MAX_BUS_DIV 3U /*!< SIM CLKDIV1 maximum run mode bus divider configurations */
131+ #define SIM_CLKDIV1_RUN_MODE_MAX_FLEXBUS_DIV 3U /*!< SIM CLKDIV1 maximum run mode flexbus divider configurations */
132+ #define SIM_CLKDIV1_RUN_MODE_MAX_FLASH_DIV 7U /*!< SIM CLKDIV1 maximum run mode flash divider configurations */
85133
86134static void CLOCK_CONFIG_FllStableDelay (void )
87135{
@@ -92,7 +140,6 @@ static void CLOCK_CONFIG_FllStableDelay(void)
92140 }
93141}
94142
95- /* Clock configuration for K64F */
96143const mcg_config_t mcgConfig_BOARD_BootClockRUN =
97144{
98145 .mcgMode = kMCG_ModePEE , /* PEE - PLL Engaged External */
@@ -103,19 +150,34 @@ const mcg_config_t mcgConfig_BOARD_BootClockRUN =
103150 .drs = kMCG_DrsLow , /* Low frequency range */
104151 .dmx32 = kMCG_Dmx32Default , /* DCO has a default range of 25% */
105152 .oscsel = kMCG_OscselOsc , /* Selects System Oscillator (OSCCLK) */
153+ #if defined(CPU_MK64FN1M0VLL12 )
106154 .pll0Config =
107155 {
108156 .enableMode = MCG_PLL_DISABLE , /* MCGPLLCLK disabled */
109157 .prdiv = 0x13U , /* PLL Reference divider: divided by 20 */
110158 .vdiv = 0x18U , /* VCO divider: multiplied by 48 */
111159 },
160+ #elif defined(CPU_MK82FN256VLL15 )
161+ .pll0Config =
162+ {
163+ .enableMode = MCG_PLL_DISABLE , /* MCGPLLCLK disabled */
164+ .prdiv = 0x0U , /* PLL Reference divider: divided by 1 */
165+ .vdiv = 0x9U , /* VCO divider: multiplied by 25 */
166+ },
167+ #else
168+ # error ("The selected Kinetis MPU does not have a clock line configuration. Please edit hal/kinetis.c")
169+ #endif
170+
112171};
172+
173+ #if defined(CPU_MK64FN1M0VLL12 )
113174const sim_clock_config_t simConfig_BOARD_BootClockRUN =
114175{
115176 .pllFllSel = SIM_PLLFLLSEL_MCGPLLCLK_CLK , /* PLLFLL select: MCGPLLCLK clock */
116177 .er32kSrc = SIM_OSC32KSEL_RTC32KCLK_CLK , /* OSC32KSEL select: RTC32KCLK clock (32.768kHz) */
117178 .clkdiv1 = 0x1240000U , /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV2: /2, OUTDIV3: /3, OUTDIV4: /5 */
118179};
180+
119181const osc_config_t oscConfig_BOARD_BootClockRUN =
120182{
121183 .freq = 50000000U , /* Oscillator frequency: 50000000Hz */
@@ -127,13 +189,41 @@ const osc_config_t oscConfig_BOARD_BootClockRUN =
127189 }
128190};
129191
192+ #elif defined(CPU_MK82FN256VLL15 )
193+
194+ const sim_clock_config_t simConfig_BOARD_BootClockRUN = {
195+ .pllFllSel = SIM_PLLFLLSEL_MCGPLLCLK_CLK , /* PLLFLL select: MCGPLLCLK clock */
196+ .pllFllDiv = 0 , /* PLLFLLSEL clock divider divisor: divided by 1 */
197+ .pllFllFrac = 0 , /* PLLFLLSEL clock divider fraction: multiplied by 1 */
198+ .er32kSrc = SIM_OSC32KSEL_RTC32KCLK_CLK , /* OSC32KSEL select: RTC32KCLK clock (32.768kHz) */
199+ .clkdiv1 = 0x1150000U , /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV2: /2, OUTDIV3: /2, OUTDIV4: /6 */
200+ };
201+
202+ const osc_config_t oscConfig_BOARD_BootClockRUN = {
203+ .freq = 12000000U , /* Oscillator frequency: 12000000Hz */
204+ .capLoad = (OSC_CAP0P ), /* Oscillator capacity load: 0pF */
205+ .workMode = kOSC_ModeOscLowPower , /* Oscillator low power */
206+ .oscerConfig = {
207+ .enableMode =
208+ kOSC_ErClkEnable , /* Enable external reference clock, disable external reference clock in STOP mode */
209+ .erclkDiv = 0 , /* Divider for OSCERCLK: divided by 1 */
210+ }
211+ };
212+ #endif
213+
214+
130215void hal_init (void )
131216{
132217 /* Disable MPU */
133218 SYSMPU_Enable (SYSMPU , false);
134219
135220 /* Set the system clock dividers in SIM to safe value. */
221+ #if defined(CPU_MK64FN1M0VLL12 )
136222 CLOCK_SetSimSafeDivs ();
223+ #elif defined(CPU_MK82FN256VLL15 )
224+ CLOCK_SetOutDiv (SIM_CLKDIV1_RUN_MODE_MAX_CORE_DIV , SIM_CLKDIV1_RUN_MODE_MAX_BUS_DIV ,
225+ SIM_CLKDIV1_RUN_MODE_MAX_FLEXBUS_DIV , SIM_CLKDIV1_RUN_MODE_MAX_FLASH_DIV );
226+ #endif
137227 /* Initializes OSC0 according to board configuration. */
138228 CLOCK_InitOsc0 (& oscConfig_BOARD_BootClockRUN );
139229 CLOCK_SetXtal0Freq (oscConfig_BOARD_BootClockRUN .freq );
@@ -151,6 +241,45 @@ void hal_init(void)
151241 CLOCK_SetSimConfig (& simConfig_BOARD_BootClockRUN );
152242 do_flash_init ();
153243}
244+ #if 0
245+ void BOARD_BootClockHSRUN (void )
246+ {
247+ /* In HSRUN mode, the maximum allowable change in frequency of the system/bus/core/flash is
248+ * restricted to x2, to follow this restriction, enter HSRUN mode should follow:
249+ * 1.set CLKDIV1 to safe divider value.
250+ * 2.set the PLL or FLL output target frequency for HSRUN mode.
251+ * 3.switch to HSRUN mode.
252+ * 4.switch to HSRUN mode target requency value.
253+ */
254+
255+ /* Set the system clock dividers in SIM to safe value. */
256+ CLOCK_SetOutDiv (SIM_CLKDIV1_RUN_MODE_MAX_CORE_DIV , SIM_CLKDIV1_RUN_MODE_MAX_BUS_DIV ,
257+ SIM_CLKDIV1_RUN_MODE_MAX_FLEXBUS_DIV , SIM_CLKDIV1_RUN_MODE_MAX_FLASH_DIV );
258+ /* Initializes OSC0 according to board configuration. */
259+ CLOCK_InitOsc0 (& oscConfig_BOARD_BootClockHSRUN );
260+ CLOCK_SetXtal0Freq (oscConfig_BOARD_BootClockHSRUN .freq );
261+ /* Configure the Internal Reference clock (MCGIRCLK). */
262+ CLOCK_SetInternalRefClkConfig (mcgConfig_BOARD_BootClockHSRUN .irclkEnableMode , mcgConfig_BOARD_BootClockHSRUN .ircs ,
263+ mcgConfig_BOARD_BootClockHSRUN .fcrdiv );
264+ /* Configure FLL external reference divider (FRDIV). */
265+ CLOCK_CONFIG_SetFllExtRefDiv (mcgConfig_BOARD_BootClockHSRUN .frdiv );
266+ /* Set MCG to PEE mode. */
267+ CLOCK_BootToPeeMode (mcgConfig_BOARD_BootClockHSRUN .oscsel , kMCG_PllClkSelPll0 ,
268+ & mcgConfig_BOARD_BootClockHSRUN .pll0Config );
269+
270+ /* Set HSRUN power mode */
271+ SMC_SetPowerModeProtection (SMC , kSMC_AllowPowerModeAll );
272+ SMC_SetPowerModeHsrun (SMC );
273+ while (SMC_GetPowerModeState (SMC ) != kSMC_PowerStateHsrun )
274+ {
275+ }
276+
277+ /* Set the clock configuration in SIM module. */
278+ CLOCK_SetSimConfig (& simConfig_BOARD_BootClockHSRUN );
279+ /* Set SystemCoreClock variable. */
280+ SystemCoreClock = BOARD_BOOTCLOCKHSRUN_CORE_CLOCK ;
281+ }
282+ #endif
154283
155284void hal_prepare_boot (void )
156285{
0 commit comments