Hello,
I have a problem with RL-FlashFS for SPI Flash memory(AT45DB161). As you know, currently there is no 'update' option for NOR flash memory in the library. I can easly manage fopen, fclose,fdelete functions without problem. But when i try to update a file, i am using this; - Read a file (fopen), - Update some parameters in MCU-memory, - Write them to the spi-flash back.
Sometimes, this sequence is not working perfectly. Especially, after 100bytes-file size, i faced many problems. 'fopen' function stores the stream in MCU-Memory perfectly and i can see the stream while debugging. But when i try to read (fread, fgetc or fgets), the file memory in MCU is gone. If you help me, i will be appreciated... I added the code below;
U8 SDCardSetParam(char *fileName, char *param, char *value) { FILE *fx; char name[100], fxBuf[1000]; int i=0, index=0; PCHAR line[100]; if(fileName == NULL) //No file name requesting... return 0; fx = fopen(fileName, "r"); //Open the file for updating. if(fx == NULL) return 0; fread(fxBuf, sizeof(fxBuf), 500, fx); /*MCU memory is going bad here if the file is bigger than 100bytes. */ fclose(fx); line[index++] = &fxBuf[0]; while(fxBuf[i] != '\0') { if(fxBuf[i++] == '\n') line[index++] = &fxBuf[i]; } for(i=0; i<(index-1); i++) { if(sscanf(line[i], "%s\n", name) != EOF) if(strcmp(name, param) == 0) //Finding parameter line in the buffer. break; } sprintf(line[i], "%s = %02X.%02X.%02X.%02X\n", param, *value, *(value+1), *(value+2), *(value+3)); fx = fopen(fileName, "w"); //Open the file for writing back. if(fx == NULL) return 0; fprintf(fx, fxBuf); fflush(fx); fclose(fx); return 1; }