Hi!
Let's see. Your function works in my VS1010D board, which is, to be honest, a little bit surprising, because I thought that SPI flash file writing was forbidden by default, because there are severe memory limitations when you write to the SPI flash.
But let's see if we can find a common ground to agree upon. I converted your function into a small test program:
Code: Select all
#include <vo_stdio.h>
void WriteSPIbyte(u_int16 n){
FILE *f;
f = fopen("s:SetFile.txt", "wb");
if (f != NULL) {
fwrite(&n, 1, 1, f);
fclose(f);
}
}
ioresult main (char *params) {
WriteSPIbyte(0x4142);
}
This program works. It creates the file and writes its content:
- spifilewrite.png (32.83 KiB) Viewed 8077 times
I have two possible ideas of why it might be failing at your site:
1) Writing to SPI flash requires a large memory buffer for handling the read-erase-modfy-write cycle for the SPI flash. This buffer is allocated at a fixed address X:0x3000 in the VS1010 RAM. If this memory area is in use by your program, then it will write garbage. You can find out which memory areas are in use by calling RunLib("LIBLIST",NULL);. Also the MP3 decoder uses this memory.
2) The last block to be written to the SPI flash might not get committed to the SPI flash and might still only be in the RAM cache at x:0x3000. The way to force writing of this data to the SPI flash is to read some other area of the SPI flash.
Because of these two reasons, I thought that the kernel would immediately give an error when attempting to write to the SPI flash, and that you would need to enable writing separately to acknowledge that you know this issue. But it doesn't, it allows the write to occur, possiby failing if the memory is not free or the ram block is not committed.
3) The disk is already corrupted somehow before the write happens and writing makes this corruption worse. Try formatting your SPI flash and try again.
Does any of this give you an idea of what's going on at your site? Which VS1010 version you are using?
-Panu