f_read doesn't respond in large files



  • Hi All,

    I am tying to read a large file ( ~300kb) from sd card , I am using FreeRTOS sdk, but it doesn't respond properly . I have tried to read in 1000 bytes blocks but after couple of readings it's halted. I should mention that I've tested the same code in Kendryte_standalone_sdk and it works fine ( I was able to read 65535 bytes in each reading while in FreeRtos it doean't work even with 5000 bytes) . After some readings f_read it's halted (stays in f_read).



  • @hukai The test code is what I have attached before, However I've attached here.
    I should mention that I tried to write 10K file, the file is created but either it's empty or file format is unreadable ( I've attached the error once I try to open the file in my computer). I wasn't able to attached the written file here, if you give me an email I can email it to you.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <devices.h>
    #include <filesystem.h>
    #include <storage/sdcard.h>
    #include "project_cfg.h"
    
    handle_t install_sdcard()
    {
        handle_t spi, gpio;
        configASSERT(spi = io_open("/dev/spi0"));
        configASSERT(gpio = io_open("/dev/gpio0"));
        handle_t sd0 = spi_sdcard_driver_install(spi, gpio, 7);
        io_close(spi);
        io_close(gpio);
        return sd0;
    }
    
    //char buffer[size];
    
    int main()
    {
        printf("Hello sd\n");
        int size = 10000;
    
        char *msg = NULL ;//="k233333333333333333";
        msg = (char *) malloc(size);
        if (!msg) printf("errorrrrr\n");
        else {
          memset(msg,'A',size);
          *(msg+size-1) = NULL;
        //
    
          handle_t sd0 = install_sdcard();
          configASSERT(sd0);
          configASSERT(filesystem_mount("/fs/0/", sd0) == 0);
          io_close(sd0);
    
      /************************* test syscalls ************************************/
          FILE *stream;
    
          if((stream=fopen("/fs/0/testlagefile.txt","wb"))==NULL)
          {
              fprintf(stderr,"Can not open file.\n");
              exit(-1);
          }
      printf("fwrite\n");
          uint16_t ret= fwrite(msg, 1, size, stream);
      
          fclose(stream);
      printf("done %d\n",ret);
        }
    
        while (1)
            ;
    }
    
    

    Error message in opening file:
    0_1557952097044_95c65bc5-1073-4306-bebe-b92ff85b32b5-image.png


  • Global Moderator |  Mod

    Hi Nancy,
    Could you please attach your test code? I've test sdcard and everything is OK.



  • Hi @hukai
    I updated my toolchain and FreeRtosSdk, now I can run the code without error. I tested with 1000bytes and it was written on sd card successfully then tested with 2000bytes , file was created but it was empty and nothing was written in file.

    OS : Ubuntu18.04
    SDK: https://github.com/kendryte/kendryte-freertos-sdk (develop branch)
    Toolchain: v8.2.0-20190409-4-g37b9dd4
    Board : K210_test_v0.2



  • @hukai Sorry for the late reply, I was away for 3 weeks. My test environment is ubuntu too.

    Once I did this test, my tool-chain version was v8.2.0-20190213.I was using the latest FreeRtos SDK in develop branch and since then it has some changes in cmake folder only (19 days ago), I'll try to download it and do the test again.
    I was using the latest kendryte-freertos-demo . However, I'll update this too and see if still have the same problem.


  • Global Moderator |  Mod

    Hi,
    I can't reproduce this issue. Would you please download the lastest kendryte-freertos-sdk, kendryte-freertos-demo and toolchain and try again. My test environment is ubuntu(not windows), I want to know your test environment.

    Thanks.


  • Global Moderator |  Mod

    This post is deleted!


  • @hukai Thanks for testing but it doesn't work for me, here is the code. I am getting "runtime_error" , I've attached the screenshot of the error.

    int main()
    {
    printf("Hello sd\n");
    int size = 65535;

    char *msg = NULL ;//="k233333333333333333";
    msg = (char *) malloc(size);
    if (!msg) printf("errorrrrr\n");
    else {
      memset(msg,'A',size);
      *(msg+size-1) = NULL;
    

    ![alt text](![image url](![image url](image url)))
    handle_t sd0 = install_sdcard();
    configASSERT(sd0);
    configASSERT(filesystem_mount("/fs/0/", sd0) == 0);
    io_close(sd0);

    /************************* test syscalls ************************************/
    FILE *stream;

      if((stream=fopen("/fs/0/test_syscalls.txt","wb"))==NULL)
      {
          fprintf(stderr,"Can not open file.\n");
          exit(-1);
      }
    

    printf("fwrite\n");
    fwrite(msg, 1, size, stream);
    fclose(stream);
    printf("done\n");
    }
    0_1555007619106_440db1fd-c0a9-4ddd-a723-72487c798fff-image.png


  • Global Moderator |  Mod

    Hi,

    1. I have download kendryte-freertos-sdk and kendryte-freertos-demo;

    2. copied kendryte-freertos-demo/sdcard_filesystem to kendryte-freertos-sdk/src;

    3. changed sdcard_filesystem/main.c
      ++char msg[65536];
      ++char buffer[65536];
      int main()
      {
      printf("Hello sd\n");
      ++memset(msg,'A',65535);
      ++memset(buffer,'A',65535);
      --//char msg[]="k233333333333333333";
      --//char buffer[32];

    4. I tested this case and everything is OK.



  • Hi @hukai
    When did you test it? If you have tested with the latest FreeRTOS existing is develop branch, it's ok now. I've seen this issue with the previous one but it's been almost two weeks the branch has been updated and problem is resolved , however, writing in sd_card still has problem and for big files you have to break down it in smaller blocks( 512bytes).
    I should mention that I wan't able to use fwrite even with breaking down to small blocks , However f_write can store the large files if it's broken down to 512bytes block.


  • Global Moderator |  Mod

    Hi , I have use FreeRTOS and tested sdcard, but it's OK. Could you please provide your test code? Thanks.