Flash Writing in MKL15Z128CAD4R

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

Flash Writing in MKL15Z128CAD4R

Jump to solution
1,067 Views
shrejjjhh
Contributor III

Hi,

I am using MKL15Z128CAD4R MCU. I want to write some data to flash. How should I do this? please help. I tried to find online help but couldn't get any help.

1 Solution
857 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

I would recommend to check and download MCUXpresso SDK software package for KL15 chip.

You could find the [pflash] demo about Flash operation(sector erase/program) with below path:

..\MKL15Z64xxx4\boards\frdmkl25z\driver_examples\flash\pflash

Wish it helps.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

9 Replies
858 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

I would recommend to check and download MCUXpresso SDK software package for KL15 chip.

You could find the [pflash] demo about Flash operation(sector erase/program) with below path:

..\MKL15Z64xxx4\boards\frdmkl25z\driver_examples\flash\pflash

Wish it helps.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

857 Views
shrejjjhh
Contributor III

Thanks Mike for your help.

I have used the same code as you have mentioned above but could not write to flash.

Below Function does not write the data on flash address.

result = FLASH_Program(&s_flashDriver, destAdrss, s_buffer, sizeof(s_buffer));

My observations are, In this function there is variable to write the src buffer to flash register i.e kFCCOBx[].

Ideally it should get updated by src buffer as kFCCOBx[0] = *src++;

I am writing 'a' to the src buffer But it shows constant value as 536883200 instead of 'a'.

0 Kudos
857 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

I don't receive any bug report about MCUXpresso SDK flash driver.

Please check below table, the Flash address must be longword aligned (Flash address[1:0] = 00).

pastedImage_1.png

And what's the result value when you called the FLASH_Program() function?

result = FLASH_Program(&s_flashDriver, destAdrss, s_buffer, sizeof(s_buffer));


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

857 Views
shrejjjhh
Contributor III

Hi Mike,

It worked for me. But I have to modify the function as:

//---------------------------------------------------------------------------------------------------------------------

void BOARD_BootClockRUN(void)
{

1.  /* Set the system clock dividers in SIM to safe value. */
2.  CLOCK_SetSimSafeDivs();
3.  /* Initializes OSC0 according to board configuration. */
4.  //CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);                           
5.  CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
6.  /* Configure FLL external reference divider (FRDIV). */
7.  CLOCK_CONFIG_SetFllExtRefDiv(mcgConfig_BOARD_BootClockRUN.frdiv);
8.  /* Set MCG to PEE mode. */
9.  //CLOCK_BootToPeeMode(kMCG_OscselOsc,kMCG_PllClkSelPll0,&mcgConfig_BOARD_BootClockRUN.pll0Config);      

10. /* Configure the Internal Reference clock (MCGIRCLK). */
11. CLOCK_SetInternalRefClkConfig(mcgConfig_BOARD_BootClockRUN.irclkEnableMode,
12. mcgConfig_BOARD_BootClockRUN.ircs,
13. mcgConfig_BOARD_BootClockRUN.fcrdiv);
14. /* Set the clock configuration in SIM module. */
15. CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
16. /* Set SystemCoreClock variable. */
17. SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;

}

//--------------------------------------------------------------------------------------------------------------------

It works only if I remove line no 4 and 9.

Regards,

Shrek 

0 Kudos
857 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Shrek,

I think the below code with the issue to set Bus clock & Flash clock to 24MHz:

pastedImage_1.png

The correct clkdiv1 should be: 0x10030000U.

Could you try that setting with KL15 chip?


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
857 Views
shrejjjhh
Contributor III

Hi Mike,

I have tried above settings too but the code goes inti infinite loop at following function,

//---------------------------------------------------------------------------------------------------------------------

void CLOCK_InitOsc0(osc_config_t const *config)
{
 uint8_t range = CLOCK_GetOscRangeFromFreq(config->freq);

 OSC_SetCapLoad(OSC0, config->capLoad);
 OSC_SetExtRefClkConfig(OSC0, &config->oscerConfig);

 MCG->C2 = ((MCG->C2 & ~OSC_MODE_MASK) | MCG_C2_RANGE(range) | (uint8_t)config->workMode);

 if ((kOSC_ModeExt != config->workMode) && (OSC0->CR & OSC_CR_ERCLKEN_MASK))
 {
  /* Wait for stable. */
  while (!(MCG->S & MCG_S_OSCINIT0_MASK))      //goes to infinite loop here.
  {
  }
 }
}

//---------------------------------------------------------------------------------------------------------------

Regards,

Shrej

0 Kudos
857 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Shrej,

Could you share the KL15 board clock schematics for double check?

I don't meet any issue during test with FRDM-KL25Z board.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
857 Views
shrejjjhh
Contributor III

Hi Mike,

I have created a code from https://mcuxpresso.nxp.com/en/clock  and it worked for me. 

//-----------------------------------------------------------------------------------------------------------------

#include "clock_config.h"

/*******************************************************************************
* Definitions
******************************************************************************/
#define MCG_IRCLK_DISABLE 0U             /*!< MCGIRCLK disabled */
#define MCG_PLL_DISABLE 0U                 /*!< MCGPLLCLK disabled */
#define OSC_CAP0P 0U                             /*!< Oscillator 0pF capacitor load */
#define OSC_ER_CLK_DISABLE 0U        /*!< Disable external reference clock */
#define SIM_OSC32KSEL_OSC32KCLK_CLK 0U /*!< OSC32KSEL select: OSC32KCLK clock */
#define SIM_PLLFLLSEL_MCGFLLCLK_CLK 0U /*!< PLLFLL select: MCGFLLCLK clock */

#define BOARD_BOOTCLOCKRUN_CORE_CLOCK              48000000U  /*!< Core clock frequency: 48000000Hz */

/*******************************************************************************
* Variables
******************************************************************************/
/* System clock frequency. */
extern uint32_t SystemCoreClock;

/*******************************************************************************
* Code
******************************************************************************/
/*FUNCTION**********************************************************************
*
* Function Name : CLOCK_CONFIG_FllStableDelay
* Description : This function is used to delay for FLL stable.
*
*END**************************************************************************/
static void CLOCK_CONFIG_FllStableDelay(void)
{
uint32_t i = 30000U;
while (i--)
{
__NOP();
}
}

/*******************************************************************************
************************ BOARD_InitBootClocks function ************************
******************************************************************************/
void BOARD_InitBootClocks(void)
{
BOARD_BootClockRUN();
}

/*******************************************************************************
********************** Configuration BOARD_BootClockRUN ***********************
******************************************************************************/

/*******************************************************************************
* Variables for BOARD_BootClockRUN configuration
******************************************************************************/
const mcg_config_t mcgConfig_BOARD_BootClockRUN =
{
.mcgMode = kMCG_ModeFEI,                                           /* FEI - FLL Engaged Internal */
.irclkEnableMode = MCG_IRCLK_DISABLE,                   /* MCGIRCLK disabled */
.ircs = kMCG_IrcSlow,                                                       /* Slow internal reference clock selected */
.fcrdiv = 0x1U,                                                                    /* Fast IRC divider: divided by 2 */
.frdiv = 0x0U,                                                                      /* FLL reference clock divider: divided by 1 */
.drs = kMCG_DrsLow,                                                       /* Low frequency range */
.dmx32 = kMCG_Dmx32Default,                                      /* DCO has a default range of 25% */
.pll0Config =
{
.enableMode = MCG_PLL_DISABLE,                                /* MCGPLLCLK disabled */
.prdiv = 0x0U,                                                                      /* PLL Reference divider: divided by 1 */
.vdiv = 0x0U,                                                                       /* VCO divider: multiplied by 24 */
},
};
const sim_clock_config_t simConfig_BOARD_BootClockRUN =
{
.pllFllSel = SIM_PLLFLLSEL_MCGFLLCLK_CLK,           /* PLLFLL select: MCGFLLCLK clock */
.er32kSrc = SIM_OSC32KSEL_OSC32KCLK_CLK,       /* OSC32KSEL select: OSC32KCLK clock */
.clkdiv1 = 0x10000U,                                                          /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV4: /2 */
};
const osc_config_t oscConfig_BOARD_BootClockRUN =
{
.freq = 0U,                                                                           /* Oscillator frequency: 0Hz */
.capLoad = (OSC_CAP0P),                                               /* Oscillator capacity load: 0pF */
.workMode = kOSC_ModeExt,                                          /* Use external clock */
.oscerConfig =
{
.enableMode = OSC_ER_CLK_DISABLE,                      /* Disable external reference clock */
}
};

/*******************************************************************************
* Code for BOARD_BootClockRUN configuration
******************************************************************************/
void BOARD_BootClockRUN(void)
{
/* Set the system clock dividers in SIM to safe value. */
CLOCK_SetSimSafeDivs();
/* Set MCG to FEI mode. */
#if FSL_CLOCK_DRIVER_VERSION >= MAKE_VERSION(2, 2, 0)
CLOCK_BootToFeiMode(mcgConfig_BOARD_BootClockRUN.dmx32,
mcgConfig_BOARD_BootClockRUN.drs,
CLOCK_CONFIG_FllStableDelay);
#else
CLOCK_BootToFeiMode(mcgConfig_BOARD_BootClockRUN.drs,
CLOCK_CONFIG_FllStableDelay);
#endif
/* Configure the Internal Reference clock (MCGIRCLK). */
CLOCK_SetInternalRefClkConfig(mcgConfig_BOARD_BootClockRUN.irclkEnableMode,
mcgConfig_BOARD_BootClockRUN.ircs,
mcgConfig_BOARD_BootClockRUN.fcrdiv);
/* Set the clock configuration in SIM module. */
CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
}

//---------------------------------------------------------------------------------------------------------------------------------

Regards,

shrej

0 Kudos
857 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Thank you for the info, Shrej.

0 Kudos