Can you please tell us exactly how you formatted your SD card? And with what OS did you do it?
~ Tectu
stm32f4 discovery fatfs problem
Moderator: RoccoMarco
Re: stm32f4 discovery fatfs problem
I told you what for information we need in order to help you. Please provide them.
~ Tectu
~ Tectu
Re: stm32f4 discovery fatfs problem
Thank u for the reply.
I formatted it in windows machine . It is fat32. it is 2 gb sandisk microsd. i partitioned it into two.
Sorry, I didn't see ur previous reply.
I formatted it in windows machine . It is fat32. it is 2 gb sandisk microsd. i partitioned it into two.
Sorry, I didn't see ur previous reply.
Re: stm32f4 discovery fatfs problem
Can you please try to format it again, but just creating one instead of two partitions? You may also try to do a full instead of a quick/fast formatting.
Otherwise make sure that you correctly handle the partitioning in your application code.
~ Tectu
Otherwise make sure that you correctly handle the partitioning in your application code.
~ Tectu
Re: stm32f4 discovery fatfs problem
I had the same problem before.
You can solve it by formatting the SD card as a primary partition (and not a logical, which is the default type). User for example the "MiniTool Partition Wizard Home Edition" which is free.
You can solve it by formatting the SD card as a primary partition (and not a logical, which is the default type). User for example the "MiniTool Partition Wizard Home Edition" which is free.
Re: stm32f4 discovery fatfs problem
I have the same issue. Was there a resolution?
I'm using an Olimex STM32-E407 board, and building everything on Ubuntu with GCC.
I started with the demo code ARMCM4-STM32F407-LWIP-FATFS-USB and have made only a few modifications, mostly in web.c.
I've added some debug code to main.c so that I get debug chprintf messages when I run the tree command, through the USB console interface.
Starting with a virgin 4GB Sandisk SD card I get the errors.
I reformatted the card using Disk Utility as FAT32 and put one file in the root (that I want to read to configure lwip).
ChibiOS/RT Shell
ch> tree
FS: f_getfree() failed 1
ch> tree
FS: 965347 free clusters, 8 sectors per cluster, 3954061312 bytes free
FS: f_readdir failed 1
ch> tree
FS: 965347 free clusters, 8 sectors per cluster, 3954061312 bytes free
/IFCONFIG.TXT
ch>
It eventually works, but seems to take a few tries. This is repeatable.
In f_getfree, chk_mounted returns FR_DISK_ERR, though the FS should be mounted in the insert routine - which does get called otherwise the fs_ready flag would be FALSE. The LED is also flashing fast, indicating the SD card was inserted and mounted already.
In chk_mounted, fs->fs_type is not true, which appears to mean the FS is not mounted.
I'm using ChibiOS 2.6.1, and that's about as far as I've got.
Needless to say, I want to add a function that, after inserting a card and seeing fs_ready, reads the ifconfig.txt file to get the MAC address, IP address, etc., and start a lwip thread using those opts. f_open calls chk_mounted and the system hangs for me.
James.
I'm using an Olimex STM32-E407 board, and building everything on Ubuntu with GCC.
I started with the demo code ARMCM4-STM32F407-LWIP-FATFS-USB and have made only a few modifications, mostly in web.c.
I've added some debug code to main.c so that I get debug chprintf messages when I run the tree command, through the USB console interface.
Starting with a virgin 4GB Sandisk SD card I get the errors.
I reformatted the card using Disk Utility as FAT32 and put one file in the root (that I want to read to configure lwip).
ChibiOS/RT Shell
ch> tree
FS: f_getfree() failed 1
ch> tree
FS: 965347 free clusters, 8 sectors per cluster, 3954061312 bytes free
FS: f_readdir failed 1
ch> tree
FS: 965347 free clusters, 8 sectors per cluster, 3954061312 bytes free
/IFCONFIG.TXT
ch>
It eventually works, but seems to take a few tries. This is repeatable.
In f_getfree, chk_mounted returns FR_DISK_ERR, though the FS should be mounted in the insert routine - which does get called otherwise the fs_ready flag would be FALSE. The LED is also flashing fast, indicating the SD card was inserted and mounted already.
In chk_mounted, fs->fs_type is not true, which appears to mean the FS is not mounted.
I'm using ChibiOS 2.6.1, and that's about as far as I've got.
Needless to say, I want to add a function that, after inserting a card and seeing fs_ready, reads the ifconfig.txt file to get the MAC address, IP address, etc., and start a lwip thread using those opts. f_open calls chk_mounted and the system hangs for me.
James.
Re: stm32f4 discovery fatfs problem
Comparing with another project ffconf.h of mine, where FatFs seems to work, I noticed only a few differences. One being;
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
In ChibiOS the default for this was set to 1. After setting to zero and rebuilding, the bug seems to be gone.
**UPDATE - the bug is not gone. I spoke too soon. It worked just once properly. Also, it may be necessary to remove all power (including the USB connection) before retesting. Somehow it seems to be something low level in talking to the card.
I'm not sure if there are other consequences, or just that it is now important that only one thread accesses the filesystem.
James.
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
In ChibiOS the default for this was set to 1. After setting to zero and rebuilding, the bug seems to be gone.
**UPDATE - the bug is not gone. I spoke too soon. It worked just once properly. Also, it may be necessary to remove all power (including the USB connection) before retesting. Somehow it seems to be something low level in talking to the card.
I'm not sure if there are other consequences, or just that it is now important that only one thread accesses the filesystem.
James.
Re: stm32f4 discovery fatfs problem
Stepping through sdc_lld_wait_transaction_end the first time it's called after typing "tree" at the console, I see..
Breakpoint 1, sdc_lld_wait_transaction_end (sdcp=0x20003680, n=1, resp=0x2000523c)
at ../os/hal/platforms/STM32/sdc_lld.c:161
161 chSysLock();
(gdb) n
162 if (SDIO->MASK != 0) {
(gdb)
170 if ((SDIO->STA & SDIO_STA_DATAEND) == 0) {
(gdb)
171 chSysUnlock();
(gdb)
172 return CH_FAILED;
Then...
sdc_lld_read_aligned (sdcp=0x20003680, startblk=0, buf=0x20004188 "", n=1)
at ../os/hal/platforms/STM32/sdc_lld.c:632
632 goto error;
disk_read returns RES_ERROR, and check_fs returns 3, and consequently chk_mounted returns FR_DISK_ERR.
But the second time I see:
Breakpoint 1, sdc_lld_wait_transaction_end (sdcp=0x20003680, n=1, resp=0x2000523c)
at ../os/hal/platforms/STM32/sdc_lld.c:161
161 chSysLock();
(gdb) n
162 if (SDIO->MASK != 0) {
(gdb) n
170 if ((SDIO->STA & SDIO_STA_DATAEND) == 0) {
(gdb)
177 while (sdcp->dma->stream->CR & STM32_DMA_CR_EN)
(gdb)
181 dmaStreamClearInterrupt(sdcp->dma);
(gdb)
183 SDIO->ICR = STM32_SDIO_ICR_ALL_FLAGS;
(gdb)
184 SDIO->DCTRL = 0;
(gdb)
185 chSysUnlock();
(gdb)
201 if (n > 1)
(gdb)
204 return CH_SUCCESS;
However f_readdir then fails.
James.
Breakpoint 1, sdc_lld_wait_transaction_end (sdcp=0x20003680, n=1, resp=0x2000523c)
at ../os/hal/platforms/STM32/sdc_lld.c:161
161 chSysLock();
(gdb) n
162 if (SDIO->MASK != 0) {
(gdb)
170 if ((SDIO->STA & SDIO_STA_DATAEND) == 0) {
(gdb)
171 chSysUnlock();
(gdb)
172 return CH_FAILED;
Then...
sdc_lld_read_aligned (sdcp=0x20003680, startblk=0, buf=0x20004188 "", n=1)
at ../os/hal/platforms/STM32/sdc_lld.c:632
632 goto error;
disk_read returns RES_ERROR, and check_fs returns 3, and consequently chk_mounted returns FR_DISK_ERR.
But the second time I see:
Breakpoint 1, sdc_lld_wait_transaction_end (sdcp=0x20003680, n=1, resp=0x2000523c)
at ../os/hal/platforms/STM32/sdc_lld.c:161
161 chSysLock();
(gdb) n
162 if (SDIO->MASK != 0) {
(gdb) n
170 if ((SDIO->STA & SDIO_STA_DATAEND) == 0) {
(gdb)
177 while (sdcp->dma->stream->CR & STM32_DMA_CR_EN)
(gdb)
181 dmaStreamClearInterrupt(sdcp->dma);
(gdb)
183 SDIO->ICR = STM32_SDIO_ICR_ALL_FLAGS;
(gdb)
184 SDIO->DCTRL = 0;
(gdb)
185 chSysUnlock();
(gdb)
201 if (n > 1)
(gdb)
204 return CH_SUCCESS;
However f_readdir then fails.
James.