Hi I am having a problem writing to onboard Flash on MK22FN256 chips.

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

Hi I am having a problem writing to onboard Flash on MK22FN256 chips.

1,005 Views
davestarkey
Contributor II

I am using the fsl_flash Peripheral Driver from SDK 1.2.0 on KDS 3.0.  Because this part does not have flex Ram

it only has 1 bank of flash.. Therefore when writing to the flash code must make a detour to RAM. The Driver

provides "RelocateFunction()" to move code to RAM. This works, although it does seem to have a bug (more on that later).

My problem is that the code jumps to the Ram Based function, the chip hangs up immediately.

 

 

#define LAUNCH_CMD_SIZE  0x100;

uint8_t command_sequence[LAUNCH_CMD_SIZE];

pFLASHCOMMANDSEQUENCE pFlashCommandSequence;

 

  uint32_t  pflash   = 0x00038400;

 

 

  pFlashCommandSequence = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)command_sequence , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence);

  FlashEraseSector(&flash1_InitConfig0, pflash, FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE, pFlashCommandSequence);  

 

At the bottom of FlashEraseSector:

        ret = pFlashCommandSequence(pSSDConfig);

This is where it crashes.

 

I have tried writing very simple functions to execute in RAM. I cant get that to work.

I tried using the demo aps: Flash_demo_twrk22f120m it worked once and then stopped.

There must be a compiler, linker or debugger setting causing my problem.

 

Thanks


Dave Starkey

 

 

dave@pianoarc.com

dstarkey@midi9.com

Labels (1)
0 Kudos
6 Replies

636 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Dave,

1) Check the memory to be sure the copy to ram succeed.

2) Please change the erase address 0x38400 to 0x3800 to have a  try .

If still can not work , you can sen your project to me , i will debug it on my side to check the problem.

Hope it helps

Alice

0 Kudos

636 Views
davestarkey
Contributor II

1) Copy to RAM was successful. Although I did need to modify RelocateFunction() to make it work.

2)I used the Address 0x38400 is a typo.. Actually the code uses 0x3f800 which is on the correct border.

Where and how do i send you my project?

0 Kudos

636 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello DAVID,

I have received your project from email.

- In the project , relocate the fucntion "how_many_calls" to 0x20004000,  i only changed one place, then it can work well.

i changed

   call_counter = ram_calls(call_counter);         to

  call_counter = ram_calls(call_counter,call_counter);

pastedImage_0.png

then i build and debug , this funciton can work well , please see the screenshot when i debug , pay attention the variable of " call_counter" .pastedImage_1.png

pastedImage_2.png

pastedImage_3.png

- In the project you send to me , i have not fund the use the function about "FlashCommandSequence" after you relocate it .

Hope it helps

Alice

0 Kudos

636 Views
davestarkey
Contributor II

While you certainly found an error in my code. When i fixed it my problem remains.

I have cleaned up the code now. So there is no confusion between the flash code and just

executing out of RAM which is the real problem.

Here is a the code now. I will attach a zip of the project.  I am pretty sure the problem

is in my setting up KDS rather than actually the code itself.

#if TEST_RAM_EXECUTION

uint32_t how_many_calls(uint32_t calls,uint32_t incr);

uint32_t how_many_calls(uint32_t calls,uint32_t incr)

{

  calls++;

  calls += incr;

  return calls;

}

void test_ram_execution(ps3_context * ps3)

{

  uint32_t (* ram_calls)(uint32_t,uint32_t);

  uint32_t call_counter;

  ram_calls = RelocateFunction((uint32_t)0x20004000 , LAUNCH_CMD_SIZE ,(uint32_t)how_many_calls);

  call_counter = ps3->serial_number;

  call_counter = how_many_calls(call_counter, call_counter);

  ps3->serial_number       =  call_counter;

  INT_SYS_DisableIRQGlobal();

  call_counter = ram_calls(call_counter, call_counter);

  INT_SYS_EnableIRQGlobal();

  ps3->serial_number       =  call_counter;

}

#endif

void InitFlashandPS3Now(char init_mode, ps3_context * ps3)

{

  unsigned short sensor;

  uint32_t * pflash = (uint32_t *)PARAMETER_FLASH_ADDRESS;

  unsigned char outbyte[1] = {ACTIVE_SENSE};

#if TEST_RAM_EXECUTION

  test_ram_execution(ps3);

#endif

0 Kudos

636 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello David,

Since you have be sure the problem is not the code , it is the configuration of KDS,

please provide how to configure the KDS debugger when you debug , for example the debug method , the configure view.

And also please test on simple project on your board to have a try , check whether it can work well.

BR

Alice

0 Kudos

636 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello David,

Please send your project as this :

pastedImage_0.png

pastedImage_0.png

BR

Alice

0 Kudos