8 years, 10 months ago.

flash_size is int or bytes?

Hi Erik!

Thank you for your job, i really appreciate it!

1) I would ask you what flash_size() returns...i've seen in your library cpp. that flash_size() should return an "int" number and actually for my K22F is 24288, SECTOR_SIZE instead is 2048.

What do these numbers mean?

2) Is it correct to say that Flash Memory is composed by Sectors, and each of them has an address? So there will be few addresses in each Flash Memory, so if we write on an address we are writing on the last free part of this Sector?

Thanks you so much and good job!!

Question relating to:

IAP code for Freescale platforms

Because flash_size() returns 24288, but my platform has a 512KB FlashMemory, how is it possibile?

posted by giacomo amici 21 May 2015

Just making sure you get an email i commented.

posted by Erik - 21 May 2015

1 Answer

8 years, 10 months ago.

1. It returns the size on bytes. Can you post the code you use to print it? For example I know someone else made the mistake of printing &flash_size, which prints the address of the flash_size function (which could very well be 24288).

2. The memory indeed consists of different sectors, with size SECTOR_SIZE. However these sectors themselves dont have addresses, the storage inside a sector does have an address. You can write wherever you want in a sector, with as requirements:

It needs to be 32-bit alligned (so lower two LSBs need to be zero: you can write for example at 0x04, 0x08, etc. But not at 0x03). You need to write multiples of 4 (otherwise it will append it with garbage data to get to a multiple of 4). And the bytes you are writing need to be erased.

And that last part is the irritating part regarding flash: You can only erase per sector. For erasing a sector you can give any 32-bit alligned address within the sector, it does not matter which one. So if you tell it to erase 0x00, or 0xF0, it will in both cases erase sector 0.

Accepted Answer

Hi again!

Thank you for responsing me soon. There is the code i use to print:

int sizeflash = flash_size(); printf("%d\r\n",sizeflash);

int sizesector = SECTOR_SIZE; printf("%d",sizesector);

How should i print these?

posted by giacomo amici 21 May 2015

That seems correct, I'll have a look at it soonish.

posted by Erik - 21 May 2015

Ahahahahhaa. I found the problem. There is a bit of a bug in the Freescale Serial (either code or silicon, I thought I solved it some time ago in a very ugly way, but apparantly not), where for some reason the first character is not properly printed. So the issue is really simple here: The '5' in front of it fell away. Print something else first and it will show up.

So then we end up at 5 24288, which is exactly 512kB :)

posted by Erik - 21 May 2015

Ahahah i got it! Thank you Erik! Good job!

posted by giacomo amici 22 May 2015