{"id":1727,"date":"2023-04-30T06:39:43","date_gmt":"2023-04-30T06:39:43","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1727"},"modified":"2023-04-30T06:39:46","modified_gmt":"2023-04-30T06:39:46","slug":"eeprom-emulation-using-flash-on-stm32f4xx","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1727","title":{"rendered":"EEPROM Emulation using Flash on STM32F4xx"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-1024x768.jpeg\" alt=\"\" class=\"wp-image-1728\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-1024x768.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-300x225.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-768x576.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-1536x1152.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-2048x1536.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-1150x863.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-750x563.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-400x300.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/AdobeStock_90169450-250x188.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Since most STM32Fxxx doesn&#8217;t feature internal EEPROM. Hence, this guide we shall use the internal flash to emulate EEPROM.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What is EEPROM.<\/li><li>Develop the driver.<\/li><li>Code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is EEPROM:<\/h2>\n\n\n\n<p>EEPROMs (electrically erasable programmable read-only memories) are used for non- volatile storage of updatable application data, or to retain small amounts of data in the event of power failure in complex systems. To reduce cost, an external EEPROM can be replaced by on-chip Flash memory, provided that a specific software algorithm is used.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Difference between emulated EEPROM and real EEPROM:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"615\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-1024x615.png\" alt=\"\" class=\"wp-image-1729\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-1024x615.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-300x180.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-768x461.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-1536x922.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-2048x1229.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-1150x690.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-750x450.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-400x240.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-8.39.54-AM-250x150.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As you can see, the endurance is way less compared to EEPROM. Hence, the usage of emulated EEPROM should be considered as last resort and dealt with it carefully.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Developing the Driver:<\/h2>\n\n\n\n<p>Since we need to read and write from\/to flash, the basic driver to read\/flash from\/to flash can be found here:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Read from flash (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=1708\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1708\" target=\"_blank\">here<\/a>).<\/li><li>Write to flash (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=1716\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1716\" target=\"_blank\">here<\/a>).<\/li><\/ul>\n\n\n\n<p>We start by creating new header and source file with name of eeprom.h and eeprom.c respectively.<\/p>\n\n\n\n<p>Within the eeprom.h, set the guard as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef EEPROM_H_\n#define EEPROM_H_\n\n\n\n#endif \/* EEPROM_H_ *\/<\/pre><\/div>\n\n\n\n<p>Within the guard, declare the following enum:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">typedef enum\n{\n\tEEPROM_OK=0,\n\tEEPROM_ERROR=1\n}EEPROMTypedefStatus;<\/pre><\/div>\n\n\n\n<p>This for error handling in your firmware.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The initializing function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void eeprom_init(uint32_t st_add, uint16_t size);\n<\/pre><\/div>\n\n\n\n<p>Get the size function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint32_t get_eeprom_size();<\/pre><\/div>\n\n\n\n<p>Read and write from\/to EEPROM:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">EEPROMTypedefStatus eeprom_read(uint16_t add, uint32_t *pData );\n\nEEPROMTypedefStatus eeprom_write(uint16_t add, uint32_t pData);<\/pre><\/div>\n\n\n\n<p>Hence, the entire eeprom.h as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef EEPROM_H_\n#define EEPROM_H_\n\n\ntypedef enum\n{\n\tEEPROM_OK=0,\n\tEEPROM_ERROR=1\n}EEPROMTypedefStatus;\n\nvoid eeprom_init(uint32_t st_add, uint16_t size);\n\nuint32_t get_eeprom_size();\n\nEEPROMTypedefStatus eeprom_read(uint16_t add, uint32_t *pData );\n\nEEPROMTypedefStatus eeprom_write(uint16_t add, uint32_t pData);\n\n\n#endif \/* EEPROM_H_ *\/<\/pre><\/div>\n\n\n\n<p>Now, within the source file, include the header file for eeprom and flash as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;flash.h&quot;\n#include &quot;eeprom.h&quot;<\/pre><\/div>\n\n\n\n<p>Some required variables:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint16_t e_size;\n\nuint32_t start_address, end_add;<\/pre><\/div>\n\n\n\n<p>The initializing function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void eeprom_init(uint32_t st_add, uint16_t size)\n{\n\t\/*Evaluate the end address*\/\n\tend_add=st_add+(uint32_t)((size*4));\n\t\n\t\/*Get the starting address*\/\n\tstart_address=st_add;\n\t\n\t\/*Store the size*\/\n\te_size=size;\n\n}<\/pre><\/div>\n\n\n\n<p>The function takes two argument:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Starting address within flash region.<\/li><li>Number of EEPROM block (multiple of 4byte).<\/li><\/ul>\n\n\n\n<p>Within the function: <\/p>\n\n\n\n<p>Calculate the end address by adding the base address to the number of blocks by 4 (since the memory increment of Flash is 4byte).<\/p>\n\n\n\n<p>Store the passed starting address to start_addres variable.<\/p>\n\n\n\n<p>Store the passed size to e_size.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Get the size function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint32_t get_eeprom_size()\n{\n\/*Return the size of EEPROM*\/\t\n  return e_size;\n}<\/pre><\/div>\n\n\n\n<p>Simply, it will return the e_size.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Read EEPROM function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\n\nEEPROMTypedefStatus eeprom_read(uint16_t add, uint32_t *pData )\n{\n\t\/*Get the EEPROM address*\/\n\tuint32_t address= ((add)*4)+start_address;\n\t\/*Check if the address within the limit*\/\n\tif(address &gt; end_add) {return EEPROM_ERROR;}\n\t\n\t\/*Read the content of the address*\/\n\telse\n\t{\n\t\tflash_read32(address,pData,1);\n\t}\n\t\n\t\/*Return OK*\/\n\treturn EEPROM_OK;\n}\n<\/pre><\/div>\n\n\n\n<p>The function takes two argument:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>EEPROM block address.<\/li><li>Pointer to variable to store the read data from flash.<\/li><\/ul>\n\n\n\n<p>Within the function:<\/p>\n\n\n\n<p>First check if the address within the valid range, if it is not, return error.<\/p>\n\n\n\n<p>Else, read the specific memory location in flash.<\/p>\n\n\n\n<p>Return ok for success.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Write EEPROM function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">EEPROMTypedefStatus eeprom_write(uint16_t add, uint32_t pData)\n{\n\t\/*Variable to hold the read data*\/\n\tuint32_t data;\n\n\t\/*Get the EEPROM address*\/\n\tuint32_t address= ((add)*4)+start_address;\n\n\t\/*Check if the address within the limit*\/\n\tif(address &gt; end_add) {return EEPROM_ERROR;}\n\n\n\n\t\/*Check if data is the same*\/\n\teeprom_read(add,&amp;data);\n\n\t\/*Same data, don't write new data*\/\n\tif(data==pData)\n\t{\n\t\treturn EEPROM_OK;\n\t}\n\t\/*If it is not the same data, write the new data*\/\n\n\tflash_unlock();\n\tflash_write32(address,&amp;pData,1);\n\tflash_lock();\n\n\t\/*Return ok*\/\n\treturn EEPROM_OK;\n}\n<\/pre><\/div>\n\n\n\n<p>The function takes two arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Address of eeprom block.<\/li><li>Data to be written.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>Within the function:<\/p>\n\n\n\n<p>Declare a variable to store the read data.<\/p>\n\n\n\n<p>Get the address.<\/p>\n\n\n\n<p>Check if the address is valid.<\/p>\n\n\n\n<p>Read the address.<\/p>\n\n\n\n<p>If the data is the same one as the one to be store, return from function.<\/p>\n\n\n\n<p>Else, write the new data.<\/p>\n\n\n\n<p>Return ok after writing the new data.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In main.c:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stdio.h&quot;\n#include &quot;delay.h&quot;\n#include &quot;uart.h&quot;\n#include &quot;eeprom.h&quot;\n\n\nuint32_t eeprom_data;\n\nint main(void)\n{\n\tuart2_tx_init(115200,16000000);\n\n\tsystick_init_ms(16000000);\n\n\teeprom_init(0x08010000, 10);\n\n\tprintf(&quot;EEPROM size = %d\\r\\n&quot;,get_eeprom_size());\n\teeprom_write(0, 0x11223344);\n\teeprom_write(1, 0xbabababa);\n\teeprom_write(2, 0xdeadbeef);\n\teeprom_write(3, 0xFAFAFAFA);\n\n\teeprom_read(0,&amp;eeprom_data);\n\tprintf(&quot;EEPROM data at address 0 is 0x%x\\r\\n&quot;,eeprom_data);\n\n\n\teeprom_read(1,&amp;eeprom_data);\n\tprintf(&quot;EEPROM data at address 1 is 0x%x\\r\\n&quot;,eeprom_data);\n\n\n\teeprom_read(2,&amp;eeprom_data);\n\tprintf(&quot;EEPROM data at address 2 is 0x%x\\r\\n&quot;,eeprom_data);\n\n\n\teeprom_read(3,&amp;eeprom_data);\n\tprintf(&quot;EEPROM data at address 3 is 0x%x\\r\\n&quot;,eeprom_data);\n\n\n\n\twhile(1)\n\t{\n\n\n\n\t}\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Code:<\/h2>\n\n\n\n<p>You may download the entire project from here:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/EEPROM_Emulation.zip\">EEPROM_Emulation<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/EEPROM_Emulation.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"733\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM-1024x733.png\" alt=\"\" class=\"wp-image-1731\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM-1024x733.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM-300x215.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM-768x550.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM-1150x823.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM-750x537.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM-400x286.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM-250x179.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/04\/Screenshot-2023-04-30-at-9.38.54-AM.png 1168w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Successfully wrote and read the data.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since most STM32Fxxx doesn&#8217;t feature internal EEPROM. Hence, this guide we shall use the internal flash to emulate EEPROM. In this guide, we shall cover the following: What is EEPROM. Develop the driver. Code. Results. 1. What is EEPROM: EEPROMs (electrically erasable programmable read-only memories) are used for non- volatile storage of updatable application data, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-1727","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1727"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1727"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1727\/revisions"}],"predecessor-version":[{"id":1732,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1727\/revisions\/1732"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}