Problem with f_getlabel and SD card

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

Problem with f_getlabel and SD card

Postby sntnjrg » Tue Jul 30, 2019 1:10 pm

Hello, I'm learning ChibiOs. I'm trying to get information from an SD card. For this I use the MMCDriver driver.

After mounting the file system (I used f_mount() function) and calling the f_getlabel() function from ff.h header file(FatFs - Generic FAT Filesystem module R0.13 by ChanN), I see the following output on the serial terminal:

Code: Select all

Run demo program...
trigMCS vrSIdm rga..
                    etn ofgrto o P..
 pr:(sm2gi_ )((it2t04000U  x8000)+000U)niuain
                                       SI_IOIPT:
                                                 i  U
 P1MS(UPT:                                            ot (t3_pot*((un3_)x0000)+00000U  x00)
           i  U
 pn:1UTU)       ot (t3_pot*((un3_)x0000)+00000U  x00)
 DCR EETIPT:3_pot*((un3_)x0000)+00000U  xC0)
 pr:(sm2gi_ )((it2t04000U  x8000)+010U)
                                       P u ofgrto:
Tyt onc ihteisre ad.OKWrn scret                   Bs PD
Mdaif:t is posil opromra n rt prtoso netdcr
       lc iei ye:5


If I comment the invocation to the f_getlabel() function, the information is printed correctly. The code is:

Code: Select all

  char lbl[12];
  DWORD sn;
  memset(lbl,0,sizeof(lbl));
  FRESULT err = f_getlabel("", lbl, 0);
  if (err != FR_OK) {
    return;
  }


In Makefile, I add the following:

Code: Select all

include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk


I'm a bit lost. Why is this error occurring? How can I debug to find the bug?

Thank you.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Problem with f_getlabel and SD card

Postby Giovanni » Tue Jul 30, 2019 1:16 pm

You should try some other FatFS operation and confirm it is working.

Giovanni

sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

Re: Problem with f_getlabel and SD card

Postby sntnjrg » Tue Jul 30, 2019 1:30 pm

The f_getfree() function works for me. The output is:

Code: Select all

Setting configuration for SPI...OK
Checking for the presence of the card...OK (Wiring is correct)
Try to connect with the inserted card...OK
Now, it is possible to perform read and write operations on inserted card
Media info:
  Block size in bytes: 512
  Total number of blocks: 15138816
Try to mount device...OK!
Let's get information from the device mounted
LABEL:
  S/N: 0x0
FS: 234161 free clusters
    64 sectors per cluster
3378020352 B free
3298848 KB free
3221 MB free


The ffconf.h file is configured as follows::

Code: Select all

#define FF_FS_READONLY  0
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
/  Read-only configuration removes writing API functions, f_write(), f_sync(),
/  f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
/  and optional writing functions as well. */


#define FF_FS_MINIMIZE  0
/* This option defines minimization level to remove some basic API functions.
/
/   0: All basic functions are enabled.
/   1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
/      are removed.
/   2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
/   3: f_lseek() function is removed in addition to 2. */


#define FF_USE_STRFUNC  2
/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
/
/  0: Disable string functions.
/  1: Enable without LF-CRLF conversion.
/  2: Enable with LF-CRLF conversion. */


#define FF_USE_FIND     0
/* This option switches filtered directory read functions, f_findfirst() and
/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */


#define FF_USE_MKFS     0
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */


#define FF_USE_FASTSEEK 0
/* This option switches fast seek function. (0:Disable or 1:Enable) */


#define FF_USE_EXPAND   0
/* This option switches f_expand function. (0:Disable or 1:Enable) */


#define FF_USE_CHMOD    1
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
/  (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */


#define FF_USE_LABEL    1
/* This option switches volume label functions, f_getlabel() and f_setlabel().
/  (0:Disable or 1:Enable) */


#define FF_USE_FORWARD  0
/* This option switches f_forward() function. (0:Disable or 1:Enable) */



I'm using the card: STM32L4R5ZI-NUCLEO144.

Could it be a linker problem?

Thanks for the help.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Problem with f_getlabel and SD card

Postby Giovanni » Tue Jul 30, 2019 1:36 pm

It looks like it is overflowing the buffer, you need to debug and inspect the stack frame.

Giovanni

sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

Re: Problem with f_getlabel and SD card

Postby sntnjrg » Tue Jul 30, 2019 2:23 pm

I can't debug the code. After executing the haltInit() function, the program continues without stopping at the breakpoint. However, if I comment the invocation to the f_getlabel() function, the debugger stops at the breakpoint.

Am I missing something in the code? Does my program take up more space than the available memory?

Cheers

sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

Re: Problem with f_getlabel and SD card

Postby sntnjrg » Tue Jul 30, 2019 2:31 pm

I think it's a memory problem. My program requires more memory than is available.

Could you give me some orientation on which parts of Chibios I should study to control this problem?

Thanks for the help.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Problem with f_getlabel and SD card

Postby Giovanni » Tue Jul 30, 2019 3:32 pm

The ch.map and ch.dmp files.

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 35 guests