simple test EEPROM emulation (STM algorithm described in the application notes: AN4061, AN3969, AN2594, AN3390, AN4056) for STM32F091
main.cpp
00001 00002 #include "mbed.h" 00003 #include "eeprom.h" 00004 #include <ctype.h> 00005 00006 00007 00008 uint16_t n = 0; 00009 /* Virtual address defined by the user: 0xFFFF value is prohibited */ 00010 uint16_t VirtAddVarTab[NB_OF_VAR] = {0x5555, 0x6666, 0x7777}; 00011 uint16_t VarDataTab[] = {0, 0, 0}; 00012 00013 00014 00015 int main() 00016 { 00017 00018 /* Unlock the Flash Program Erase controller */ 00019 HAL_FLASH_Unlock(); 00020 00021 EE_Init(); 00022 00023 printf("EEPROM emulation test\n"); 00024 00025 printf("\n\rType one of the following commands and press space or enter"); 00026 printf("\n\r READ - read all variables\n\r WRITE1 <n> - write first variable\n\r WRITE2 <n> - write second variable\n\r WRITE3 <n> - write third variable"); 00027 printf("\n\rwhere <n> is uint16_t value (0-65535)"); 00028 printf("\n\r"); 00029 00030 00031 char command[20]; 00032 char arg[10]; 00033 int i; 00034 00035 while(1) { 00036 scanf("%s", command); 00037 i=0; 00038 while(command[i]) 00039 { 00040 command[i]=toupper(command[i]); 00041 i++; 00042 } 00043 00044 00045 if (strcmp("READ", command)==0) { 00046 for (i=0; i<3; i++) { 00047 EE_ReadVariable(VirtAddVarTab[i], &VarDataTab[i]); 00048 }; 00049 printf("\nvar1=%6u, var2=%6u, var3=%6u",VarDataTab[0],VarDataTab[1],VarDataTab[2]); 00050 } 00051 /////////////////////////////////////////////////////////////////////////////////////////////////////// 00052 else if (strcmp("WRITE1", command)==0) { 00053 scanf("%s", arg); 00054 printf("\nok"); 00055 n=atoi(arg); 00056 EE_WriteVariable(VirtAddVarTab[0], n); 00057 } 00058 //////////////////////////////////////////////////////////////////////////////////// 00059 else if (strcmp("WRITE2", command)==0) { 00060 scanf("%s", arg); 00061 printf("\nok"); 00062 n=atoi(arg); 00063 EE_WriteVariable(VirtAddVarTab[1], n); 00064 } 00065 //////////////////////////////////////////////////////////////////////////////////// 00066 else if (strcmp("WRITE3", command)==0) { 00067 scanf("%s", arg); 00068 printf("\nok"); 00069 n=atoi(arg); 00070 EE_WriteVariable(VirtAddVarTab[2], n); 00071 } 00072 //////////////////////////////////////////////////////////////////////////////////// 00073 else if (strcmp("T1", command)==0) { 00074 // multiple write test. After test var1 = 1000 00075 printf("\nok"); 00076 for (n=0;n<1001;n++) 00077 { 00078 EE_WriteVariable(VirtAddVarTab[0], n); 00079 }; 00080 } 00081 //////////////////////////////////////////////////////////////////////////////////// 00082 else if (strcmp("T2", command)==0) { 00083 // multiple write test. After test var2 = 1001 00084 printf("\nok"); 00085 for (n=0;n<1002;n++) 00086 { 00087 EE_WriteVariable(VirtAddVarTab[1], n); 00088 }; 00089 } 00090 //////////////////////////////////////////////////////////////////////////////////// 00091 else if (strcmp("T3", command)==0) { 00092 // multiple write test. After test var3 = 1002 00093 printf("\nok"); 00094 for (n=0;n<1003;n++) 00095 { 00096 EE_WriteVariable(VirtAddVarTab[2], n); 00097 }; 00098 } 00099 //////////////////////////////////////////////////////////////////////////////////// 00100 00101 else perror("\nThere is no command matching. Try again"); 00102 00103 command[0] = arg[0] = 0; 00104 printf("\n\r"); 00105 } 00106 00107 00108 }
Generated on Fri Jul 22 2022 14:32:51 by
1.7.2