MMC/SD drive newbie - need help

Page 6/13
1 | 2 | 3 | 4 | 5 | | 7 | 8 | 9 | 10 | 11

By Erikie

Champion (324)

Erikie's picture

27-02-2009, 14:43

flash is only needed to support flashing the rom and to write files to flash rom memory as there is a flash disk on it. So if you don't use atmel chip then you don't have to solder the whole flash component of the circuit

By jpgrobler

Master (154)

jpgrobler's picture

27-02-2009, 14:49

Where is the bios routines for accessing the sd/mmc located?

Does the flash routines check for the atmel chip via chip id?
soldering the flash rom is a small part on the whole, sourcing the chip loccaly is more of a challenge for me.. .

By Erikie

Champion (324)

Erikie's picture

27-02-2009, 16:05

at least the atload program checks for atmel chip. I have the code available if you want.
I am still in the process of finding out exactly how the hardware works. I am busy with cpld implementation and have some timing issues on it. Hence I want to find out how the whole thing works.
The atmel chip can be purchased from futurlec. I have bought many of them already. Allthough it is not necessary to use this chip for the sd interface to work

By cax

Prophet (3740)

cax's picture

27-02-2009, 21:09

Does the flash routines check for the atmel chip via chip id?

At least the ATLOAD.COM utility finds atmel chip in the specified slot by running chip id retrieval sequence.
Also sharksym's readme file says

Atmel AT29C040A (4MBits) only
Anyway, you can use any 4MBits Flashrom as BIOS ROM.
But FlashROM works as readonly disk in this case.

By cax

Prophet (3740)

cax's picture

10-03-2009, 06:32

Well, Erikie, it's time to ask other MRC members to help us. I will describe the problem:

We are trying to extract flashing routine from ATLOAD.COM tool (self-extractable: can be extracted with, used to flash SD/MMC drive (here is the flash chip datasheet).

We've found the flashing code (at least we think so), but for some reason my routine doesn't work (endless loop).
Here is the code I have:

	ld	a,(SLOT_NUMBER)  	
	ld	h,$40		
	call	$0024		

	ld	a,(SLOT_NUMBER)  
	ld	h,$80		
	call	$0024		

	ld	a,(BLOCK_NUM)  
	ld	($5000),a  

	ld	a,$01		
	ld	($aff0),a

	ld	a,$AA
	ld	($9555),a
	ld	a,$55
	ld	($6AAA),a
	ld	a,$A0
	ld	($9555),a

	ld	de,$4000
	ld	hl,(COPY_FROM)
	ld	bc,$100
	dec    hl         
	dec    de         
	ld     b,(hl)     
CHKWRT:	ld     a,(de)     
	cp     b          
	jr     nz,CHKWRT

	ld	a,$00		
	ld	($aff0),a  

	ld	a,($f343)  
	ld	h,$80		
	call	$0024		

	ld	a,($f342)  
	ld	h,$40		
	call	$0024		

By RetroTechie

Paragon (1563)

RetroTechie's picture

10-03-2009, 08:02

Look at the exact bytes written, and addresses, before the 256 byte block transfer. Compare with "Software Data Protection Enable Algorithm" in the datasheet (page 10, about halfway). Perhaps this isn't the normal write code, but code that locks the flash chip against accidental writes?

Also this looks like a piece of code that might hang (at CHKWRT ) whenever something 'unexpected' occurs? Read: badly written code IMHO. Unexpected things should just cause error codes, not hangs. Hardware doesn't always behave the way you expect it to, and as a programmer you simply can't predict all possible corner cases that might occur sometimes. Basically: don't have your code panic, just flag the event.

Oh btw: you are using exact same type flash chip as above (Atmel AT29C040A, as in datasheet) ?

By cax

Prophet (3740)

cax's picture

10-03-2009, 12:31

RetroTechie, can you suggest a debugger that won't hang after page switch at 4000 and 8000 like in the code above ?

I am sure that "AA->9555, 55->6AAA, A0->9555" (and the loop afterwards) is the sequence used by ATLOAD itself to flash 0x100 bytes, but have doubt about the other steps required to flash properly. It may be some waiting required, before or after flashing, or some other operation that I can't guess.

This badly written loop is taken from ATLOAD as is.
I tried to eliminate the loop - and nothing was written in the end.
Once I continued playing with RAM and SCC pages manually in debugger, and discovered that 0x100 bytes were actually written, but this happened to me only once and I cannot reproduce this behavior.

And yes - I have the correct chip.

By Erikie

Champion (324)

Erikie's picture

10-03-2009, 13:54

Hi Cax,

I will try your code (little bit modified) tonight at home.
You defenitely need some nops after setting the chip to write.
as you need a small pause after setting the chip to write mode.
After writing to the chip I will verify with HW chip reader to see if my text got loaded or not


By sharksym

Resident (36)

sharksym's picture

10-03-2009, 15:25

Hi Cax and Erikie,

ATLOAD.COM uses page 0 for data buffer (4KBytes) & program code itself,
and uses page 1 & 2 for cartridge slot due to flashrom access,
and uses page 3 for usual way(stack & system variables).

Your disassembled code is correct as my source code.
Here's some explanation.

Current code uses the SDP function of AT29C040A.
When this feature is enabled once, all flash sector is protected by SDP sequence.
This feature prevent unintended writes on flashrom.
Becuse any sector cannot be rewritten without SDP sequence.
Below code is correct SDP sequnce as your code.
ld a,$AA
ld ($9555),a
ld a,$55
ld ($6AAA),a
ld a,$A0
ld ($9555),a

If you really want to disable SDP, you have to send SDP-disable command once.
After then, you can write any 256bytes sector without SDP sequence.

In every sector writing sequence, flashrom needs some time to flash sector for internal process.
It can be detected by reading data. An address is not important but address should be same during check.
During internal flash process, AT29C040A asserts Toggle-bit signal on data pins.
BIT6 will be toggled in every read.

In my source code, I just compare two bytes of last written data & read Toggle-bit code.
When flash process is over, it asserts correct written byte, instead of Toggle-bit code.
This process is normally over within 10ms.
You may exchange this code with simple delay code.
But in this case, you cannot see whether writing was success or not.
Anyway if some HW or any kind of error occured, you may see hangup. Tongue (as RetroTechi mentioned).

Hmmm, I want to suggest,
before digging flash-write routines, please check first your diskrom and memory usage,
and be noticed that ATLOAD.COM uses DOS variables of $f343,$f342 and ENASLT.
I don't know why you have trouble with ATLOAD.COM.
When I tested ATLOAD.COM on MSX1/2/2+/tR with DOS1/2, and RAMDISK of DOS2 also, I couldn't see any problem.

I'm not sure, but I think there is no HW problem, if hangup occurs after 8KBytes flashing.
It means software wrote 32 sectors succefully. Smile

By pitpan

Prophet (3155)

pitpan's picture

10-03-2009, 15:31

All I've done so far was related to Am29F040B, the flash chip included within the MegaFlash/SCC cartridge. I don't know if it's equivalent, but if so, the full cycle is ERASE, WRITE, CHECK. First you should erase flash contents, therefore write a byte and then check if it is ok.

Page 6/13
1 | 2 | 3 | 4 | 5 | | 7 | 8 | 9 | 10 | 11