Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
storage.cpp
00001 #include "storage.h" 00002 00003 /* Function: writeByte 00004 * ------------------- 00005 * This function writes a byte of data to the EEPROM at the appropriate location. 00006 * This is called by my write. 00007 * Use this if you want to write a single byte. 00008 */ 00009 HAL_StatusTypeDef Storage::writeByte(uint8_t byte) 00010 { 00011 HAL_StatusTypeDef status; 00012 int address = offset + stadr; 00013 offset++; 00014 HAL_FLASHEx_DATAEEPROM_Unlock(); //Unprotect the EEPROM to allow writing 00015 status = HAL_FLASHEx_DATAEEPROM_Program(TYPEPROGRAMDATA_BYTE, address, byte); 00016 HAL_FLASHEx_DATAEEPROM_Lock(); // Reprotect the EEPROM 00017 return status; 00018 } 00019 00020 /* Function: write 00021 * --------------- 00022 * This function takes an array of bytes and its size and writes them to the EEPROM 00023 * Use this if you want to write a lot of bytes. 00024 */ 00025 void Storage::write(uint8_t* data, uint8_t size) 00026 { 00027 for(int i = 0; i < size; i++) 00028 { 00029 writeByte(data[i]); 00030 } 00031 } 00032 00033 /* Function: readByte 00034 * ------------------ 00035 * This function reads a byte of data from the EEPROM at the offset passed in. 00036 * This is called by my read function. 00037 */ 00038 uint8_t Storage::readByte(uint32_t off) { 00039 uint8_t tmp = 0; 00040 off = off + stadr; 00041 tmp = *(__IO uint32_t*)off; 00042 00043 return tmp; 00044 } 00045 00046 /* Function: read 00047 * --------------- 00048 * This takes an array of bytes an fills it with our entire EEPROM 00049 * Call this function when you want to send the data over GSM 00050 */ 00051 void Storage::read(uint8_t *ptr) 00052 { 00053 int nbytes = offset; 00054 printf("The number of bytes in the EEPROM is %d\n", nbytes); 00055 for(int i = 0; i < nbytes; i++) 00056 { 00057 ptr[i] = readByte(i); 00058 } 00059 return; 00060 }
Generated on Fri Jul 29 2022 23:23:18 by
1.7.2