memoire flash

Committer:
nikobirolini
Date:
Mon Dec 07 09:06:35 2020 +0000
Revision:
0:e32119dfd2fe
memoire morte

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nikobirolini 0:e32119dfd2fe 1 #include "mbed.h"
nikobirolini 0:e32119dfd2fe 2
nikobirolini 0:e32119dfd2fe 3 FlashIAP flash;
nikobirolini 0:e32119dfd2fe 4
nikobirolini 0:e32119dfd2fe 5 int main() {
nikobirolini 0:e32119dfd2fe 6 flash.init();
nikobirolini 0:e32119dfd2fe 7
nikobirolini 0:e32119dfd2fe 8 const uint32_t flash_start = flash.get_flash_start();
nikobirolini 0:e32119dfd2fe 9 const uint32_t flash_size = flash.get_flash_size();
nikobirolini 0:e32119dfd2fe 10 const uint32_t flash_end = flash_start + flash_size;
nikobirolini 0:e32119dfd2fe 11 const uint32_t page_size = flash.get_page_size();
nikobirolini 0:e32119dfd2fe 12 uint32_t sector_size = flash.get_sector_size(flash_end - 1);
nikobirolini 0:e32119dfd2fe 13 uint8_t* page_buffer = new uint8_t[page_size];
nikobirolini 0:e32119dfd2fe 14 uint32_t addr = flash_end - sector_size;
nikobirolini 0:e32119dfd2fe 15 uint8_t EEdata_write; //= 55;
nikobirolini 0:e32119dfd2fe 16 uint8_t EEdata_read = 0;
nikobirolini 0:e32119dfd2fe 17
nikobirolini 0:e32119dfd2fe 18 printf("flash_start = 0x%.8x\r\n", flash_start);
nikobirolini 0:e32119dfd2fe 19 printf("flash_size = 0x%.8x\r\n", flash_size);
nikobirolini 0:e32119dfd2fe 20 printf("flash_end = 0x%.8x\r\n", flash_end);
nikobirolini 0:e32119dfd2fe 21 printf("page_size = 0x%.8x\r\n", page_size);
nikobirolini 0:e32119dfd2fe 22 printf("sector_size = 0x%.8x\r\n", sector_size);
nikobirolini 0:e32119dfd2fe 23 printf("addr = 0x%.8x\r\n", addr);
nikobirolini 0:e32119dfd2fe 24 printf("EEdata_write = %d\r\n", EEdata_write);
nikobirolini 0:e32119dfd2fe 25 printf("EEdata_read = %d\r\n", page_buffer[0]);
nikobirolini 0:e32119dfd2fe 26 //page_buffer[0] = 55;//EEdata_write;
nikobirolini 0:e32119dfd2fe 27 //flash.erase(addr, sector_size);
nikobirolini 0:e32119dfd2fe 28 //flash.program(page_buffer, addr, page_size);
nikobirolini 0:e32119dfd2fe 29 //page_buffer[0] = 0;
nikobirolini 0:e32119dfd2fe 30 //flash.read(page_buffer, addr, page_size);
nikobirolini 0:e32119dfd2fe 31 //EEdata_read = page_buffer[0];
nikobirolini 0:e32119dfd2fe 32 //page_buffer[0]++;
nikobirolini 0:e32119dfd2fe 33 //flash.erase(addr, sector_size);
nikobirolini 0:e32119dfd2fe 34
nikobirolini 0:e32119dfd2fe 35 //flash.program(page_buffer, addr, page_size);
nikobirolini 0:e32119dfd2fe 36 flash.read(page_buffer, addr, page_size);
nikobirolini 0:e32119dfd2fe 37 printf("EEdata_read PB = %d\r\n", page_buffer[0]);
nikobirolini 0:e32119dfd2fe 38
nikobirolini 0:e32119dfd2fe 39 page_buffer[0] = page_buffer[0]+1;
nikobirolini 0:e32119dfd2fe 40 printf("EEdata_read PB = %d\r\n", page_buffer[0]);
nikobirolini 0:e32119dfd2fe 41 //temp = page_buffer[0];
nikobirolini 0:e32119dfd2fe 42 flash.erase(addr, sector_size);
nikobirolini 0:e32119dfd2fe 43 flash.program(page_buffer, addr, page_size);
nikobirolini 0:e32119dfd2fe 44 //flash.program(page_buffer, addr, page_size);
nikobirolini 0:e32119dfd2fe 45 //flash.read(page_buffer, addr, page_size);
nikobirolini 0:e32119dfd2fe 46 //delete[] page_buffer;
nikobirolini 0:e32119dfd2fe 47 //flash.deinit();
nikobirolini 0:e32119dfd2fe 48 flash.read(page_buffer, addr, page_size);
nikobirolini 0:e32119dfd2fe 49 printf("EEdata_read PB = %d\r\n", page_buffer[0]);
nikobirolini 0:e32119dfd2fe 50 }