This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RL-FlashFs in RTX Can't write data in file.

My project use RTX and RL-FlashFs,I can create,del,read file,but can't write anydata to file.
My CPU is LM3S8938,menory device is SD card.
Pls tell me how to solve it? Thanks!

Parents
  • Try to find out where your problem is:
    - try SD Card on PC and copy a file to it, and check if it is written correctly
    - use Keil SD_File demo for LM3S8962 board and over UART with terminal program try formatting the card

    format NAME
    

    after that try to create new file

    fill test.txt
    

    and then list directory

    dir
    

Reply
  • Try to find out where your problem is:
    - try SD Card on PC and copy a file to it, and check if it is written correctly
    - use Keil SD_File demo for LM3S8962 board and over UART with terminal program try formatting the card

    format NAME
    

    after that try to create new file

    fill test.txt
    

    and then list directory

    dir
    

Children
  • thank your reply.
    I had done your advices, it worked very well in Keil SD_File demo for LM3S8962 board and over UART with terminal program try formatting the card;but in my project,only write data into files can't work,I search ed a meaasge in this forum,it said that "Keil SD_File demo only work none-RTX,otherwise write operation result is a enmpy file",that is right?

  • SD_File demo is prepared without RTX but RTX can be used without problems.
    You obviously have done something wrong, I suggest you start with SD_File example for start of your application.

  • My application is baseed on keil's SD_File demo ,I created a task the code is:
    when I use this code it can write data into file :

    __task void SD_task (void) {
            U32 FreeSpace;
             FILEHANDLE f;
             char ch[5000];
             FINFO info;
            char returnVal = 0;
            if(finit() != 0)
              os_tsk_pass();           //SD/MMC Init Failed
            FreeSpace = ffree("");
            if(FreeSpace < 2000000)
              returnVal= fformat ("Fullsee /FAT32");
            if(returnVal != 0)
              os_tsk_pass();  //Formatting failed
            f = _sys_open("test.txt", OPEN_W);
            if (f == -1)
              os_tsk_pass();
            else {
                  _sys_write (f, ch, 5000, 1);
                  _sys_close (f);
                }
            info.fileID = 0;
            ffind ("test.txt",&info);
       while (1) {
        os_tsk_pass();
       }
    }
    

    .
    and if I use the fellow code,Result is enmty files

    __task void SD_task (void) {
            U32 FreeSpace;
             FILE *f1;
             char ch[5000];
             FINFO info;
            char returnVal = 0;
            if(finit() != 0)
              os_tsk_pass();           //SD/MMC Init Failed
            FreeSpace = ffree("");
            if(FreeSpace < 2000000)
              returnVal= fformat ("Fullsee /FAT32");
            if(returnVal != 0)
              os_tsk_pass();  //Formatting failed
            f1 = fopen ("test.txt", "w");
            if (f1 == NULL)
               os_tsk_pass();
            else
              {
                fwrite (ch, sizeof (char), 10, f1);
               fclose (f1);
              }
            info.fileID = 0;
            ffind ("test.txt",&info);
       while (1) {
        os_tsk_pass();
       }
    }
    

    .
    It very like that:
    o.keil.com/.../thread14166.asp

  • FINFO on the stack? It is quite large, better to do

    static FINFO info;
    

  • Well it seems that you have not done retargetting, take a look to Retarget.c file, have you included it into your project?

  • My Retarget.c is from keil's SD_File demo,and I had included it into my project.

    /*----------------------------------------------------------------------------
     *      R T L  -  F l a s h   F i l e   S y s t e m
     *----------------------------------------------------------------------------
     *      Name:    RETARGET.C
     *      Purpose: Retarget low level functions
     *      Rev.:    V3.20
     *----------------------------------------------------------------------------
     *      This code is part of the RealView Run-Time Library.
     *      Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
     *---------------------------------------------------------------------------*/
    
    #include <stdio.h>
    #include <string.h>
    #include <rt_misc.h>
    #include <rt_sys.h>
    #include <File_Config.h>
    
    #pragma import(__use_no_semihosting_swi)
    
    /* The following macro definitions may be used to translate this file:
    
      STDIO - use standard Input/Output device
              (default is NOT used)
     */
    
    /* Standard IO device handles. */
    #define STDIN   0x8001
    #define STDOUT  0x8002
    #define STDERR  0x8003
    
    /* Standard IO device name defines. */
    const char __stdin_name[]  = "STDIN";
    const char __stdout_name[] = "STDOUT";
    const char __stderr_name[] = "STDERR";
    
    struct __FILE { int handle; /* Add whatever you need here */ };
    
    #ifdef STDIO
     extern int sendchar (int ch);
     extern int getkey (void);
    #endif
    
    /*--------------------------- _ttywrch --------------------------------------*/
    
    void _ttywrch (int ch) {
    #ifdef STDIO
       sendchar(ch);
    #endif
    }
    
    /*--------------------------- _sys_open -------------------------------------*/
    
    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));
    }
    
    /*--------------------------- _sys_close ------------------------------------*/
    
    int _sys_close (FILEHANDLE fh) {
       if (fh > 0x8000) {
          return (0);
       }
       return (__fclose (fh));
    }
    
    /*--------------------------- _sys_write ------------------------------------*/
    
    int _sys_write (FILEHANDLE fh, const U8 *buf, U32 len, int mode) {
    #ifdef STDIO
       if (fh == STDOUT) {
          /* Standard Output device. */
          for (  ; len; len--) {
             sendchar (*buf++);
          }
          return (0);
       }
    #endif
       if (fh > 0x8000) {
          return (-1);
       }
       return (__write (fh, buf, len));
    }
    
    /*--------------------------- _sys_read -------------------------------------*/
    
    int _sys_read (FILEHANDLE fh, U8 *buf, U32 len, int mode) {
    #ifdef STDIO
       if (fh == STDIN) {
          /* Standard Input device. */
          for (  ; len; len--) {
             *buf++ = getkey ();
          }
          return (0);
       }
    #endif
       if (fh > 0x8000) {
          return (-1);
       }
       return (__read (fh, buf, len));
    }
    
    /*--------------------------- _sys_istty ------------------------------------*/
    
    int _sys_istty (FILEHANDLE fh) {
       if (fh > 0x8000) {
          return (1);
       }
       return (0);
    }
    
    /*--------------------------- _sys_seek -------------------------------------*/
    
    int _sys_seek (FILEHANDLE fh, long pos) {
       if (fh > 0x8000) {
          return (-1);
       }
       return (__setfpos (fh, pos));
    }
    
    /*--------------------------- _sys_ensure -----------------------------------*/
    
    int _sys_ensure (FILEHANDLE fh) {
       if (fh > 0x8000) {
          return (-1);
       }
       return (__flushbuf (fh));
    }
    
    /*--------------------------- _sys_flen -------------------------------------*/
    
    long _sys_flen (FILEHANDLE fh) {
       if (fh > 0x8000) {
          return (0);
       }
       return (__get_flen (fh));
    }
    
    /*--------------------------- _sys_tmpnam -----------------------------------*/
    
    int _sys_tmpnam (char *name, int sig, unsigned maxlen) {
       return (1);
    }
    
    /*--------------------------- _sys_command_string ---------------------------*/
    
    char *_sys_command_string (char *cmd, int len) {
       return (cmd);
    }
    
    /*--------------------------- _sys_exit -------------------------------------*/
    
    void _sys_exit (int return_code) {
       /* Endless loop. */
       while (1);
    }
    
    
    
    
    
    
    
    
    /*----------------------------------------------------------------------------
     * end of file
     *---------------------------------------------------------------------------*/