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.
6 years, 2 months ago.
EEProm Emulation on STM32L432KC
Hello, my question is a bit stupid, but i have spent one week to check the forum and trying different methods how to solve it and without sucess :( I am using the Nucleo STM32L432KC and I need to save only 5 bytes into the EEPROM as a configuration data. Because this MCU don't have EEPROM it is necessary to save it into Flash. I have found few examples and I have tested it - but without success.
One, which is here in forum was to use the back-up registers from RTC, but there is necessary to have backup battery - i dont have it in my application :(
Second was to use Flash HAL API. I did a short test below, but EEdata_read on the end are 0, not 55.
uint32_t EEaddress = 0x8020000; start on 128kB
uint8_t EEdata_write = 55;
uint8_t EEdata_read;
uint32_t EEsize = 1;
int32_t flash_init (flash_t *obj);
int32_t flash_program_page(flash_t *obj, uint32_t EEaddress, const uint8_t *EEdata_write, uint32_t EEsize);
int32_t flash_read(flash_t *obj, uint32_t EEadress, uint8_t *EEdata_read, uint32_t EEsize);
The third what I tested was recommendation from this page http://micromouseusa.com/?p=606 but also without success :(
And I can continue - I really tested lot of different examples during this week, but with the same result - it is not working :(
Is here somebody who can recommend me simple and working solution how to save 5 bytes? I am realy desperate, because I am bit new in programing of ARM and I am not able to make some working solution myself :(
Thank you very much, I will be very grateful for your help.
Lucas
1 Answer
6 years, 2 months ago.
Hello Lukas,
That must be very frustrating :( I haven't tried it yet but the Flash IAP might help solve the issue.
Have a look also at https://os.mbed.com/questions/82407/How-do-I-use-a-txt-file-in-an-embedded-d.
Hello, thank you very much for your fast answer. I have also tried this library, but also without success :(
address 0x8020000 means: from 128 kB
uint32_t EEaddress = 0x8020000; uint8_t EEdata_write = 55; uint8_t EEdata_read; uint32_t EEdata_size = 1; uint32_t EEsizeSector = 2048;
in program
FlashIAP(); int init();
int erase(uint32_t EEadress, uint32_t EEsizeSector); int program(const void *EEdata_write, uint32_t EEadress, uint32_t EEdata_size);
int read(void *EEdata_read, uint32_t EEadress, uint32_t EEdata_size);
t_max=EEdata_read;
And after this t_max=0 not 55 :( And I am really not sure regarding size of sectors (but in datasheet is info that this MCU has 256kB of flash in 128 x 2kbyte) and also regarding address 0x8020000..... (My program is now 59kB HEX file)
My flustration is growing :)
posted by 11 Oct 2018You made me curious about the Flash IAP. Unfortunately I have no access to a NUCLEO-L432KC. So below is a program which worked for me on a NUCLEO-F446RE.
#include "mbed.h" FlashIAP flash; int main() { flash.init(); const uint32_t flash_start = flash.get_flash_start(); const uint32_t flash_size = flash.get_flash_size(); const uint32_t flash_end = flash_start + flash_size; const uint32_t page_size = flash.get_page_size(); uint32_t sector_size = flash.get_sector_size(flash_end - 1); uint8_t* page_buffer = new uint8_t[page_size]; uint32_t addr = flash_end - sector_size; uint8_t EEdata_write = 55; uint8_t EEdata_read = 0; printf("flash_start = 0x%.8x\r\n", flash_start); printf("flash_size = 0x%.8x\r\n", flash_size); printf("flash_end = 0x%.8x\r\n", flash_end); printf("page_size = 0x%.8x\r\n", page_size); printf("sector_size = 0x%.8x\r\n", sector_size); printf("addr = 0x%.8x\r\n", addr); printf("EEdata_write = %d\r\n", EEdata_write); printf("EEdata_read = %d\r\n", EEdata_read); page_buffer[0] = EEdata_write; flash.erase(addr, sector_size); flash.program(page_buffer, addr, page_size); page_buffer[0] = 0; flash.read(page_buffer, addr, page_size); EEdata_read = page_buffer[0]; delete[] page_buffer; flash.deinit(); printf("EEdata_read = %d\r\n", EEdata_read); }
ADVISE: To have a more readable code published here (on mbed pages) try to mark it up as below (with <<code>> and <</code>>
tags, each on separate line at the begin and end of your code)
<<code>> text of your code <</code>>posted by 11 Oct 2018