Im using a microblaze soft processor on a Basys3 dev board. I am able to write a text file to an SD card but I am trying to write to the end of the file. Currently it overwrites anything that's in the file. Im using the DFATFS functions to do the writing. The Basys3 has a PMOD uSD reader attached.
I've tried using the fslseek function in DFATFS to move the file pointer to the end of file but it still writes to the beginning.
//the subroutine to print to the SD card
void SD(int32_t rando, int addr, int bit, int pc) {
DXSPISDVOL disk(XPAR_PMODSD_0_AXI_LITE_SPI_BASEADDR,
XPAR_PMODSD_0_AXI_LITE_SDCS_BASEADDR);
DFILE file;
int eof;
char printline[128];
sprintf(printline, "\nLFSR: %d ", rando);
// The drive to mount the SD volume to.
// Options are: "0:", "1:", "2:", "3:", "4:"
static const char szDriveNbr[] = "0:";
// Mount the disk
DFATFS::fsmount(disk, szDriveNbr, 1);
xil_printf("Disk mounted\r\n");
fr = file.fsopen("output.txt", FA_WRITE | FA_OPEN_ALWAYS);
if (fr == FR_OK) {
file.fslseek(0);
file.fswrite(printline, 12, &bytesWritten);
fr = file.fsclose();
} else {
xil_printf("Failed to open file to write to\r\n");
}
}
I expect the code to move the file pointer to the end of the file and print a new line after the previous one. When stepping through the program (multiple times through the print subroutine) but it always overwrites.