Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 5 months ago.
Not able to read data from Flash
Hi!!
I've encountered a problem in reading data from a flash sector where i wrote previously. The first program i've loaded on my K22F is the library example:
#include "mbed.h" #include "FreescaleIAP.h" int main() { int address = flash_size() - SECTOR_SIZE; //Write in last sector int *data = (int*)address; printf("Starting\r\n"); erase_sector(address); int numbers[10] = {0, 1, 10, 100, 1000, 10000, 1000000, 10000000, 100000000, 1000000000}; program_flash(address, (char*)&numbers, 40); //10 integers of 4 bytes each: 40 bytes length printf("Resulting flash: \r\n"); for (int i = 0; i<10; i++) printf("%d\r\n", data[i]); printf("Done\r\n\n"); while (true) { } }
Then i will write to an other sector and want to read from the previous sector:
#include "mbed.h" #include "FreescaleIAP.h" int main() { int sizeflash = flash_size(); printf(" Flash Size: %d\r\n",sizeflash); int sizesector = SECTOR_SIZE; printf("Sector Size: %d\r\n",sizesector); int address01 = flash_size() - (SECTOR_SIZE*2); int *data01 = (int*)address01; int address = flash_size()- SECTOR_SIZE; int *data = (int*)address; printf("Address01: %d\r\n",address01); printf(" \r\n"); printf("Address: %d\r\n",address); printf(" \r\n"); printf("Starting\r\n"); erase_sector(address01); int numbers[10] = {5,6,7,8,9,15,777,91,2,88}; program_flash(address01, (char*)&numbers, 40); printf("Resulting flash for address01\r\n"); for(int i=0;i<10;i++) printf("%d\r\n", data01[i]); printf("\r\n"); printf("Resulting flash for address\r\n"); for(int i=0;i<10;i++) printf("%d\r\n", data[i]); printf("Done\r\n\n"); while (true) { } }
I load these programs in sequency.
Where is the error?
Thank you!!
Question relating to:
1 Answer
9 years, 5 months ago.
Just checked it with just running the first program for a second time, but with the erase and program part commented out. That gave the same result. I am pretty sure this doesn't happen on the KL25 for example, not 100% sure though.
So it looks like the drag and drop loader performs a complete chip erase when programming.
The first printf works properly and returns "5,6,7,8,9,15,777,91,2,88". The second one returns me ten times "-1".
posted by giacomo amici 25 May 2015