EmbDev.net

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


von Travis W. (tkw954)


Rate this post
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

von Martin Thomas (Guest)


Rate this post
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

von Travis W. (tkw954)


Rate this post
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:
1
FatFs module test terminal
2
>fi 0
3
rc=0 FR_OK
4
>fo 10 test
5
rc=0 FR_OK
6
>fw 2048 1
7
rc=1 FR_NOT_READY
8
0 bytes written with 0 kB/sec.
9
>fc
10
rc=1 FR_NOT_READY
11
>fl
12
----A 2000/01/01 11:55         0  test  
13
   1 File(s),          0 bytes total
14
   0 Dir(s),    27836416 bytes free

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

I changed
1
#define BOARD_PRESCALER         AT91C_PMC_PRES_CLK_2
in board_lowlevel.c to
1
#define BOARD_PRESCALER         AT91C_PMC_PRES_CLK_4
and
1
#define BOARD_MCK               48000000
in board.h to
1
#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:
1
FatFs module test terminal
2
>di 0
3
rc=0
4
>fi 0
5
rc=0 FR_OK
6
>fl
7
   0 File(s),          0 bytes total
8
   0 Dir(s),    31080448 bytes free
9
>fm 0 16384
10
The drive 0 will be formatted. Are you sure? (Y/n)=Y
11
rc=1 FR_NOT_READY
12
>fs
13
rc=13 FR_MKFS_ABORTED
14
>
15
16
powercycle
17
18
AT91SAM7S Demo Application by Martin Thomas
19
V1.0.3 5/2009
20
-- Compiled: May 12 2009 14:55:13 --
21
-- for Board SAM7-Pxxx
22
23
FatFs module test terminal
24
>di 0
25
rc=0
26
>fi 0
27
rc=0 FR_OK
28
>fs
29
rc=13 FR_MKFS_ABORTED
30
>
I then had to reformat the card to get it to work.

von Martin T. (mthomas) (Moderator)


Rate this post
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?

von Travis W. (tkw954)


Rate this post
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.

von Travis W. (tkw954)


Rate this post
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.

von Martin T. (mthomas) (Moderator)


Rate this post
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.

von Travis W. (tkw954)


Rate this post
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.

von Alex (Guest)


Rate this post
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?

von Martin T. (mthomas) (Moderator)


Rate this post
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_projects/arm_memcards/index.html#chanfat_at91sam7
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

von Travis W. (tkw954)


Rate this post
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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.