EmbDev.net

Forum: ARM programming with GCC/GNU tools Can read, can't write to ChaN's FATFs on AT91SAM7


Author: Travis Wiens (tkw954)
Posted on:

Rate this post
0 useful
not useful
Hi,
First off, a big thanks to ChaN for developing the FATFs and Martin 
Thomas for porting it to AT91.

I'm having some problems.  I can read files from a SD card, but not 
fully write.  It opens the file and creates it on the disk, but fails 
when I try to write with the error FR_NOT_READY.

I've attached a session dump below.

Does anyone have any ideas where to start?

I'm using Martin Thomas's port to a AT91SAM7S256 on a Olimex SAM7-P256 
Rev E board and a Canon 32M SD card (although another card I have does 
the same). I had to change the definition of SD_SOCKET_WP_PIN in board.h 
to AT91C_PIO_PA25 to match the newer Olimex circuit. Compiled using the 
latest gnuarm on linux.


Thanks in advance,
Travis

===

AT91SAM7S Demo Application by Martin Thomas
V1.0.3 5/2009
-- Compiled: May 12 2009 14:55:13 --
-- for Board SAM7-Pxxx

FatFs module test terminal
>di 0
rc=0
>ds
Power is ON
Drive size: 60800 sectors
Sector size: 512
Erase block size: 32 sectors
MMC/SDC type: 2
CSD:
00000000  00 5D 01 32 13 59 81 DA F6 D9 CF FF 16 40 00 7D 
.].2.Y.......@.}
CID:
00000000  01 50 41 53 30 33 32 42 45 F1 45 69 0B 00 7C 5F 
.PAS032BE.Ei..|_
OCR:
00000000  80 FF 80 00 ....
SD Status:
00000000  00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 
................
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
................
00000020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
................
00000030  00 00 00 55 50 00 00 55 00 20 07 00 75 01 07 1E ...UP..U. 
..u...
>fi 0
rc=0 FR_OK
>fs
FAT type = 2 (FAT16)
Bytes/Cluster = 2048
Number of FATs = 2
Root DIR entries = 512
Sectors/FAT = 47
Number of clusters = 12001
FAT start (lba) = 64
DIR start (lba,clustor) = 158
Data start (lba) = 190

2 files, 10444800 bytes.
0 folders.
24002 KB total disk space.
13798 KB available.
>fl
----A 2009/05/12 16:01  10240000  TESTDA~2.DAT  testdata2.dat
----A 2009/05/12 15:52    204800  TESTDA~1.DAT  testdata1.dat
   2 File(s),   10444800 bytes total
   0 Dir(s),    14129152 bytes free
>fo 1 testdata2.dat
rc=0 FR_OK
>fr 10240000
10240000 bytes read with 2012 kB/sec.
>fc
rc=0 FR_OK
>fo 10 testwrite.dat
rc=0 FR_OK
>fs
FAT type = 2 (FAT16)
Bytes/Cluster = 2048
Number of FATs = 2
Root DIR entries = 512
Sectors/FAT = 47
Number of clusters = 12001
FAT start (lba) = 64
DIR start (lba,clustor) = 158
Data start (lba) = 190

3 files, 10444800 bytes.
0 folders.
24002 KB total disk space.
13798 KB available.
>fw 2048 1
rc=1 FR_NOT_READY
0 bytes written with 0 kB/sec.
>fl
----A 2009/05/12 16:01  10240000  TESTDA~2.DAT  testdata2.dat
----A 2009/05/12 15:52    204800  TESTDA~1.DAT  testdata1.dat
----- 1980/00/00 00:00         0  TESTWR~1.DAT  testwrite.dat
   3 File(s),   10444800 bytes total
   0 Dir(s),    14129152 bytes free

Author: Martin Thomas (Guest)
Posted on:

Rate this post
0 useful
not useful
(1) Could you please try the write test without an "fs" between fo 10... 
und fw?:
- (remove card/insert card or power off/on, not just reset of the AT91)
- fi 0
- fo 10 test
- fw 2048 1
- fc
- fl
(2) try with a lower the SPI-bitrate (increase prescaler)
(3) format the disk using the PC+Card-Reader or fm in the test-terminal 
which calls ChaN's "makefs". Then retry with a "clean" system

Author: Travis Wiens (tkw954)
Posted on:

Rate this post
0 useful
not useful
Thanks for the quick reply
>(1) Could you please try the write test without an "fs" between fo 10...
>und fw?:
Same result:
FatFs module test terminal
>fi 0
rc=0 FR_OK
>fo 10 test
rc=0 FR_OK
>fw 2048 1
rc=1 FR_NOT_READY
0 bytes written with 0 kB/sec.
>fc
rc=1 FR_NOT_READY
>fl
----A 2000/01/01 11:55         0  test  
   1 File(s),          0 bytes total
   0 Dir(s),    27836416 bytes free

>(2) try with a lower the SPI-bitrate (increase prescaler)

I changed
#define BOARD_PRESCALER         AT91C_PMC_PRES_CLK_2
in board_lowlevel.c to
#define BOARD_PRESCALER         AT91C_PMC_PRES_CLK_4
and
#define BOARD_MCK               48000000
in board.h to
#define BOARD_MCK               24000000
(I'm not sure if there are other changes to be made)
The result was exactly the same as before.

>(3) format the disk using the PC+Card-Reader or fm in the test-terminal
>which calls ChaN's "makefs". Then retry with a "clean" system

Reformatted with both Ubuntu's gparted and Panasonic's SD Formatter (on 
XP) with the same result as before.

fm doesn't seem to work:
FatFs module test terminal
>di 0
rc=0
>fi 0
rc=0 FR_OK
>fl
   0 File(s),          0 bytes total
   0 Dir(s),    31080448 bytes free
>fm 0 16384
The drive 0 will be formatted. Are you sure? (Y/n)=Y
rc=1 FR_NOT_READY
>fs
rc=13 FR_MKFS_ABORTED
>

powercycle

AT91SAM7S Demo Application by Martin Thomas
V1.0.3 5/2009
-- Compiled: May 12 2009 14:55:13 --
-- for Board SAM7-Pxxx

FatFs module test terminal
>di 0
rc=0
>fi 0
rc=0 FR_OK
>fs
rc=13 FR_MKFS_ABORTED
>
I then had to reformat the card to get it to work.

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Travis Wiens wrote:
>...
> rc=1 FR_NOT_READY

Could you please re-check that your modification for the 
"Write-Protect-Detection" works as expected? There is still some 
test-code in sd_spi_at91 -> disk_init() for this, just replace #if 0 
with #if 1. With this enabled the state of the socket-switches (CD and 
WP) will be shown on the terminal-interface with "di 0".

>>(2) try with a lower the SPI-bitrate (increase prescaler)
>
> I changed
> ...

Just increase the value defined for SPI_SCBR_MIN in sd_spi_at91.c, keep 
board.h as is.

>>(3) format the disk using the PC+Card-Reader or fm in the test-terminal
>>which calls ChaN's "makefs". Then retry with a "clean" system
>
> Reformatted with both Ubuntu's gparted and Panasonic's SD Formatter (on
> XP) with the same result as before.
>
> fm doesn't seem to work:
> [pre]
> FatFs module test terminal
>>di 0
> rc=0
>>fi 0
> rc=0 FR_OK
>>fl
>    0 File(s),          0 bytes total
>    0 Dir(s),    31080448 bytes free
>>fm 0 16384
> The drive 0 will be formatted. Are you sure? (Y/n)=Y
> rc=1 FR_NOT_READY
>...

I expect this and the "fw" problem have the same reason.

Do you have a scope? Could you try to monitor the supply voltage of the 
card during the different tests?

Author: Travis Wiens (tkw954)
Posted on:

Rate this post
0 useful
not useful
Martin Thomas wrote:
> Travis Wiens wrote:
>>...
>> rc=1 FR_NOT_READY
>
> Could you please re-check that your modification for the
> "Write-Protect-Detection" works as expected? There is still some
> test-code in sd_spi_at91 -> disk_init() for this, just replace #if 0
> with #if 1. With this enabled the state of the socket-switches (CD and
> WP) will be shown on the terminal-interface with "di 0".

It works as expected, identifying if a card is present or not, and also 
if the card is write protected or not.

>>>(2) try with a lower the SPI-bitrate (increase prescaler)
>>
>> I changed
>> ...
>
> Just increase the value defined for SPI_SCBR_MIN in sd_spi_at91.c, keep
> board.h as is.

Same result for SPI_SCBR_MIN ranging from 2 (default) to 8. (Doesn't 
work at all for SPI_SCBR_MIN = 1.)


> Do you have a scope? Could you try to monitor the supply voltage of the
> card during the different tests?

I don't have a scope, but I've got a 225 KHz daq system. If I can, I'll 
take some measurements this afternoon.

Author: Travis Wiens (tkw954)
Posted on:

Rate this post
0 useful
not useful
>
>> Do you have a scope? Could you try to monitor the supply voltage of the
>> card during the different tests?
>
> I don't have a scope, but I've got a 225 KHz daq system. If I can, I'll
> take some measurements this afternoon.

I've uploaded plots of Vcc during "fo" and "fw" commands to
http://picasaweb.google.com/tkw954/SAM7#
I've uploaded the raw data in Matlab format to
http://homepage.usask.ca/~tkw954/save_data3.mat
which includes 225 KHz data for Vcc DI DO and CLK for 'fl', 'fo', 'fw', 
and 'di' commands.

The supply voltage does go below 2.5 V momentarily and seems to 
oscillate between 2.7 and 3.8 V, especially at the end of the 'fo' 
command.

If it would help, I can probably borrow a 'scope next week.

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Travis Wiens wrote:
>>
>>> Do you have a scope? Could you try to monitor the supply voltage of the
>>> card during the different tests?
>>
>> I don't have a scope, but I've got a 225 KHz daq system. If I can, I'll
>> take some measurements this afternoon.
>
> I've uploaded plots of Vcc during "fo" and "fw" commands to
> http://picasaweb.google.com/tkw954/SAM7#
> I've uploaded the raw data in Matlab format to
> http://homepage.usask.ca/~tkw954/save_data3.mat
> which includes 225 KHz data for Vcc DI DO and CLK for 'fl', 'fo', 'fw',
> and 'di' commands.
>
> The supply voltage does go below 2.5 V momentarily and seems to
> oscillate between 2.7 and 3.8 V, especially at the end of the 'fo'
> command.

Hmm, this reather wide span does not look "healthy" to me. What kind of 
power-supply to you use? Maybe it's a little weak. Can you try with 
another one?

> If it would help, I can probably borrow a 'scope next week.
I guess addtional measurements will not help that much. Test with a 
"stronger" power-supply first.

There might be a software-issue but the few tests I made did not show a 
problem (some outputs shown in the readme-file of the package). I will 
do some more testing when I'm back at my "workbench" and will also scope 
the card's vcc line.

Author: Travis Wiens (tkw954)
Posted on:

Rate this post
0 useful
not useful
>Hmm, this reather wide span does not look "healthy" to me. What kind of
>power-supply to you use? Maybe it's a little weak. Can you try with
>another one?

I was using the USB powersupply, but get the same errors using a "wall 
wart" rated for 2.1 A.

Author: Alex (Guest)
Posted on:

Rate this post
0 useful
not useful
Author: Martin Thomas (Guest)
Posted on: 2009-05-13 00:33

------------------------------------------------------------------------ 
---

(1) Could you please try the write test without an "fs" between fo 10...
und fw?:
- (remove card/insert card or power off/on, not just reset of the AT91)
- fi 0
- fo 10 test
- fw 2048 1
- fc
- fl
(2) try with a lower the SPI-bitrate (increase prescaler)
(3) format the disk using the PC+Card-Reader or fm in the test-terminal
which calls ChaN's "makefs". Then retry with a "clean" system

------------------------------------------------------------------------ 
------------------------------------------------------------------------ 
------------------------------------------------------------------------ 
---------
Ive had similar problems with card initialisation...if i remove and 
re-insert the card it works fine.
It has to do with the card init..its not done correctly..did you find a 
way to fix this problem?

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
A new package of the AT91SAM7/ChaN FatFS demo-application is available 
from my page: 
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm...
This - hopefully - includes a fix for the mentioned write problems. At 
least all tests I have run with a SanDisk ultra II SDHC 4GB and 
extrememory performance SD-Card 1GB worked as expected. If there are 
still problems please disable DMA/PDC by a define in the 
low-level-driver and try again. Feedback welcome.
Martin Thomas

Author: Travis Wiens (tkw954)
Posted on:

Rate this post
0 useful
not useful
>A new package of the AT91SAM7/ChaN FatFS demo-application is available
>from my page:
>http://www.siwawi.arubi.uni-kl.de/avr_projects/arm...
>This - hopefully - includes a fix for the mentioned write problems.

Yes, this solves my problems. Seems to work perfectly.

Thanks a lot,
Travis

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.