Hi, I adopted FlashFS to use my NANDFlash (9F2G08U0A). finit() and fformat ("F:") are working fine and the flash gets erased. But if I call fopen, to create files, I get linker error:
.\at91sam9260-sdram\at91sam9260-sdram.axf: Error: L6915E: Library reports error: __use_no_semihosting_swi was requested, but _sys_open was referenced
I got a retarget.c which implements _sys_open and many other _sys-functions:
FILEHANDLE _sys_open (const char *name, int openmode) { /* Register standard Input Output devices. */ if (strcmp(name, "STDIN") == 0) { return (STDIN); } if (strcmp(name, "STDOUT") == 0) { return (STDOUT); } if (strcmp(name, "STDERR") == 0) { return (STDERR); } return (__fopen (name, openmode)); }
How can I compile my code without errors?
(I don't know much about this.)
The error msg means:
You declared
#pragma import(__use_no_semihosting_swi)
somewhere.
However, your _sys_open() needs some semihosting_swi support.
So maybe, you should re-write your _sys_open() or mark the "#pragma import(__use_no_semihosting_swi)".
I guess, STDIN/STDOUT/STDERR need some semihosting_swi support.
Hi, I found the problem concerning the _sys_open() linker error message. One has to implement all functions like _sys_open, _sys_close, _sys_write and so in, otherwise the sys_io library is beeing linked and code cannot be created.
But now I encounter new problems: I adopted the NANDFlash example project from the AT91SAM9260 software package to use FlashFS. I simply initialize the FS and try to open a file:
/* Initialize the FlashFS. */ result = finit(); printf("finit() = %i\n", result); /* Format a Flash Drive. */ if (fformat ("F:") != 0) { printf ("Flash File System format failed.\n"); } else { printf ("Flash File System initialized.\n"); } f1 = fopen ("F1.TXT","w"); fputs("hello world", f1); fclose(f1);
Its initialzing ok. Formating does also work, but fopen does not return - it's looping inside of fs_Find_File and executes code at 0x00000000 after some time.
Does someone have FlashFS running with a NANDFlash?
The following, I found out: When calling __fopen, the variable holding the variable name gets 0x00000000. When stepping it, it is valid, when the PC is at the first line. When I step in, it gets invalid.
FILEHANDLE _sys_open (const char *name, int openmode) { /* Register standard Input Output devices. */ if (strcmp(name, "STDIN") == 0) { return (STDIN); } if (strcmp(name, "STDOUT") == 0) { return (STDOUT); } if (strcmp(name, "STDERR") == 0) { return (STDERR); } return (__fopen (name, openmode)); } int __fopen (const char *fname, int openmode) { // until here everything is ok /* Low level file open function. */ U32 i,fid; int handle; IOB *fcb; /* Find unused _iob[] structure. */ if ((handle = fs_find_iob ()) == EOF) { // when stepping to here, fname gets 0x00000000 /* Cannot find any unused _iob[] structure */ return (-1); } ...
Do you get a stack overflow or a failed memory allocation somewhere?
Another think is that we only see that you are sending a pointer "name" in several steps but what does this pointer point at? A globally allocated memory block or a static text string stored in flash or?
I also though, that there would be a stack/heap problem, but I configured them to be 64kB each and its still failing.
Here is the main:
int main() { int result = 0; FILE *f1, *fin; signed char ch; char* fname = "F1.TXT"; char line[80]; // Configure the DBGU TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); printf("-- Basic NandFlash Project %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* Initialize the FlashFS. */ result = finit(); printf("finit() = %i\n", result); f1 = fopen (fname, "w"); fputs("hallo welt", f1); fclose(f1); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); fin = fopen (fname,"r"); if (fin == NULL) { printf ("File not found!\n"); } else { while (fgets (line, sizeof (line), fin) != NULL) { puts (line); } fclose (fin); } printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); return 0; }
I'm using an AT91SAM9260 and execute the code from external SD-RAM. I just took the NANDFlash example project for KEIL µVision out of the software package version 1.5 supplied by ATMEL. There are no problems, when I use the NANDFlash without the FlashFS. I'm able to read/write it.
Hello Stefan,
I plan to integrate a similar NAND flash into a my product (it incorporates Flash-FS, too). I saw in the manual that one is expected to provide the implementaiton of 'fs_Init', 'fs_EraseSector' and 'fs_ProgramPage' to customize the behavior, as decribed here: www.keil.com/.../rlarm_fs_cvrt_flashprg_c.htm But the read operation of the NAND flash involves more than addressing memory mapped I/O - how does this fit into Flash-FS?
Hi, you are right, memory mapped access to NAND flash does not work.
Concering FlashFS the problem is, that there is no bad block management implemented. Thus you have to care about it for your own.
To work around the memory mapped read access to NAND flash, you can cheat FlashFS and use the NAND flash as SPI flash. For Reading - fs_spi_ReadData For Writing - fs_spi_ProgramPage For Sector erasing - fs_spi_EraseSector For Initialization - fs_spi_Init
Thanks. I will try that.
View all questions in Keil forum