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.
reading from flash memory of K64f
Hi all, Finally I managed to write the data into flash memory of K64f. Thanks to the following link: https://developer.mbed.org/users/Sissors/code/FreescaleIAP/
The issue is I am struggling to read the code from the memory. If I write and read from the memory int the same program, every things work fine. But when I tries to write the data from one program and try to read it from different program, it gives me the null value. for example if I run the following code
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");
It gives me the correct output. But when I just try to read the values from different program it dont display the output/
// code for reading int address = flash_size() - SECTOR_SIZE; //Write in last sector int *data = (int*)address; printf("Starting\r\n"); // erase_sector(address); do not erase the previous content // int numbers[10] = {0, 1, 10, 100, 1000, 10000, 1000000, 10000000, 100000000, 1000000000}; // program_flash(address, (char*)&numbers, 40); //dont overwrite the previous data printf("Resulting flash: \r\n"); for (int i = 0; i<10; i++) printf("%d\r\n", data[i]); //display the non volatile data printf("Done\r\n\n");
The read code doesnt show any output rather it gives me -1 means it doesnt have any thing to display.
1 Answer
9 years, 5 months ago.
I am pretty sure this happens because the interface chip most likely issues a full chip erase before programming, removing the programmed values again. So either you need to program it with a different method (maybe CMSIS-DAP programmer does not do it), or stick to using it to store data between resets/no power situations.
Yes you are right... we need to develop a algorithm that it has to read and write in a single program
int address = flash_size() - SECTOR_SIZE; //Write in last sector char *data = (char*)address; for (int i = 0; i<11; i++) printf(" %c ", data[i]); // it will not run for the initial setup, but it will print data // for the subsequent bootups //if (data) // call function to print stored data printf(" \n Starting\r\n"); erase_sector(address); char *store="192.168.0.2"; program_flash(address, store, 12); //10 integers of 4 bytes each: 40 bytes length printf("Resulting flash: \r\n"); printf("stored data %s\r\n", data); printf("Done\r\n\n"); printf("stored data %s\r\n", data);