Need function for Flash read like flash_program in flash_demo project in kl25z

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

Need function for Flash read like flash_program in flash_demo project in kl25z

Jump to solution
1,152 Views
arthshah
Contributor II

hello kerryzhou

i am currently working on flash_demo project given in kinetis KSDK 1.3.0.

in this demo there are function for flash_program and flash_program_check i understand that function and apply in my project now i need a slimiler function for flah_read from any location of flash.

please suggest me some solution regarding flash_read.

Thanks And Best Regards,

Arth Shah

Labels (1)
0 Kudos
Reply
1 Solution
1,030 Views
mjbcswitzerland
Specialist V

Hi Arth

unsigned long flash_add = *(unsigned long *)0x00005420;

This is valid code and when I try to build with VisualStudio or with GCC there are no errors or warnings. Please check exactly how you have written it.

unsigned char ucBuffer[100];

memcpy(ucBuffer, (void *)0x00005420, sizeof(ucBuffer));

This will copy 100 bytes stating from the Flash address 0x5420 to the buffer.

Regards

Mark

View solution in original post

0 Kudos
Reply
5 Replies
1,030 Views
mjbcswitzerland
Specialist V

Arth

Flash is memory mapped so you can read with

TYPE value = *(TYPE *)flash_address; // where TYPE is unsigned char, unsigned long etc.

To read a block, just use memcpy().

eg.

unsigned char ucBuffer[100];

memcpy(ucBuffer, flash_address, 100);

Regards

Mark

0 Kudos
Reply
1,030 Views
arthshah
Contributor II

hello Mark,

Thanks for reply.

i want to read data from 0x00005420 memory location.

please give me example on that.

when i write unsigned long flash_add=*(unsigned long*)0x00005420

it give me error like 

"initializer element is not constant "

and other question is that when i give starting address of memory then we get 100 data from that to our ucBuffer?

thanks

0 Kudos
Reply
1,031 Views
mjbcswitzerland
Specialist V

Hi Arth

unsigned long flash_add = *(unsigned long *)0x00005420;

This is valid code and when I try to build with VisualStudio or with GCC there are no errors or warnings. Please check exactly how you have written it.

unsigned char ucBuffer[100];

memcpy(ucBuffer, (void *)0x00005420, sizeof(ucBuffer));

This will copy 100 bytes stating from the Flash address 0x5420 to the buffer.

Regards

Mark

0 Kudos
Reply
1,030 Views
arthshah
Contributor II

Hello Mark,

Thanks for help.. I don't know why this declaration is not work for my KDS.but i understand what you said .

Thanks for reply..!!

0 Kudos
Reply
1,030 Views
mjbcswitzerland
Specialist V

Arth

KDS uses GCC. In KDS I don't get any problems. Strange...

Regards

Mark

0 Kudos
Reply