News:

Attention: For security reasons,please choose a user name *different* from your login name.
Also make sure to choose a secure password and change it regularly.

Main Menu

f_getcwd command for SD1 in Zynq ultrascale+ returns failure

Started by sandeep, February 11, 2019, 09:42:32 AM

Previous topic - Next topic

sandeep

Hello,

I'm trying to obtain the current working directory on SD1 of the Zynq Ultrascale+ device (TE0820) for FTP application. however, the command f_getcwd is returning failure. It works fine for SD0. Below is the example code:

#include "xparameters.h" /* SDK generated parameters */
#include "xsdps.h" /* SD device driver */
#include "xil_printf.h"
#include "ff.h"
#include "xil_cache.h"
#include "xplatform_info.h"

static FIL fil; /* File object */
static FATFS fatfs;
static char FileName[32] = "1:/Test.bin";
static char *SD_File;

u8 DestinationAddress[10*1024*1024] __attribute__ ((aligned(32)));
u8 SourceAddress[10*1024*1024] __attribute__ ((aligned(32)));


#define TEST 7

int main(void)

{
   int Status;
   
   xil_printf("SD Polled File System Example Test \r\n");
   
   FRESULT Res;
   UINT NumBytesRead;
   UINT NumBytesWritten;
   u32 BuffCnt;
   BYTE work[FF_MAX_SS];
   u32 FileSize = (8*1024*1024);
   
   TCHAR *Path = "1:/";
   
   for(BuffCnt = 0; BuffCnt < FileSize; BuffCnt++){
   SourceAddress[BuffCnt] = TEST + BuffCnt;
   }
   
   Res = f_mount(&fatfs, Path, 0);
   
   if (Res != FR_OK) {
      print ("mount failed\n");
   return XST_FAILURE;
   
   }
   
   Res = f_mkfs(Path, FM_FAT32, 0, work, sizeof work);
   if (Res != FR_OK) {
      print ("mkfs failed\n");
   return XST_FAILURE;
   }

   #define SZ_STR 255
   TCHAR str[SZ_STR];

    /* Get current directory path */
    Res = f_getcwd(str, SZ_STR);
    if (Res != FR_OK) {
       xil_printf ("Current working directory return failed cwd\n",);
            return XST_FAILURE;
        }
    xil_printf ("Current working directory success cwd= %s\n", str);

}

I'm using TE0720 SOM and Vivado version is 2018.3. And below is the BSP settings of generic fat file system library . Any idea where I am going wrong?
Thank you.

Kind regards,
Sandeep

JH

Hello,
can you tell me the error message?

And which module did you use, your wrote:
QuoteZynq Ultrascale+ device (TE0820)
and
QuoteI'm using TE0720 SOM and Vivado version is 2018.3.

Is the second one a typo?

SD0 is eMMC and SD1 is the SD Card on TE0820.
Does our Linux example design boot from SD?
If yes, than it seems to be more Xilinx  barmetal driver specific, maybe you should also write a post to Xilinx forum.

br
John


sandeep

Hello John,

Sorry about the confusion. I'm using TE0820 on TE0703 carrier board. The booting from SD card works fine.

The error I'm getting is "FR_NOT_ENABLED".

And I've posted the issue in Xilinx forum too, but no luck there (https://forums.xilinx.com/t5/Embedded-Processor-System-Design/The-f-getcwd-command-for-SD1-in-Zynq-ultrascale-returns-failure/m-p/937078#M43965). I was hoping someone in here would have come across this issue for this particular device.

Kind regards,
Sandeep

JH

Hi,
http://irtos.sourceforge.net/FAT32_ChaN/doc/en/rc.html
QuoteFR_NOT_ENABLED
    Work area for the logical drive has not been registered by f_mount function.
so your f_mount returns no error? Your SD has only one partition?
br
John



sandeep

Hi John,

The f_mount() function does not return any error and yes, SD has only one partition and is been formatted as FAT32. The f_getcwd () works fine with eMMC (SD0) returns the correct CWD,  but fails for SD card.

Kind regards,
Sandeep

JH

Hi,
you should start SDK debugger and jump into this function to find out what's exactly failed.

I thing either something is not configured correctly or it's bug if the driver. But I can't help much more in this case.

Here are also notes and links from Xilinx:


br
John

sandeep

Hi John,

When f_getcwd() function calls the get_ldnumber(), instead of returning '1', it returns '0'. Because of this, the function fails. I'm debugging why this is happening.

I want to go for editing the BSP as my last option, but thanks for the quick response John!

Kind regards,
Sandeep

JH

Hi,
get_ldnumber() seems to be xilffs. You must check, why he think it's one and not zero. But it can also happens that Zero is from eMMC mounting and one is from SD...?
If I see it correctly only -1 is invalid:
https://github.com/Xilinx/embeddedsw/blob/master/lib/sw_services/xilffs/src/ff.c

Enable debugging of Xilinx BSP Libs:
https://forums.xilinx.com/t5/Embedded-Development-Tools/Xilinx-SDK-IDE-Enable-Debug-With-BSP-Sources/td-p/751507
br
John

sandeep

Hi John,

Yes, working on it. I'll update here if I figure out the issue.

Kind regards,
Sandeep

sandeep

Hi John,

To resolve this error, The f_chdrive() function should be called before f_getcwd(), then it returns the correct CWD.

Kind regards,
Sandeep


JH

Hi,
thanks for this notes it's good to hear that it works now.
br
John