byuu's message board

For discussion of projects related to www.byuu.org/


1, 2  Next
Trying to write to Cx4 ROM from the cart edge 
Author Message
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Trying to write to Cx4 ROM from the cart edge
I posted this question over at nesdev too, but I'm looking for all the suggestions I can get. I'm trying to figure out how to program this dev cart through the cart edge, and from what I'm seeing, it should be working, but it's not. I've managed to probe the address and data lines, and they are being asserted correctly, /OE is held high like it should be, /WE is strobed low like it should be, the only problem is that /CE is not strobed low for writes to the ROM address space, so I had to cut the ROM's /CE line and feed it with some glue logic combining the original /CE signal out of the Cx4 ANDed with the /WE signal out of the Cx4 (i.e. /ROM_CE = /CE_OUT & /WE_OUT).

Here is a logic analyzer log of a working erase command using this adapter that connects the ROM directly to my microcontroller (same flash ROM chip)
Image

And here is the log for the non-working cart edge interface (the zoom levels are different, but the cycle times are roughly the same, and the ~1us difference should be insignificant since the cycle times are ~10us, and the minimum write cycle time for the chip is 55ns):
Image

The only difference I see between them is the fact that in the cart edge interface, the data lines are de-asserted shortly after the /CE and /WE signals are pulled high, but the datasheet for the M29F160 states a hold time of 0ns after /CE or /WE is pulled high, so that shouldn't be a problem... I'm really stumped on this one. Any ideas?

Mon 16 Dec 2013, 09:29:45
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
Just in case it isn't clear from the zoom level on those photos, the data lines are de-asserted AFTER /CE and /WE are pulled high, so they should satisfy the 0ns hold time parameter by a long shot:
Image

Mon 16 Dec 2013, 09:34:52
User avatar

Joined: Tue 02 Nov 2010, 01:00:37

Posts: 181
Post Re: Trying to write to Cx4 ROM from the cart edge
#OE is asserted throughout your second set of pictures.

cYa,

Tauwasser

Mon 16 Dec 2013, 22:10:24
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
Tauwasser wrote:
#OE is asserted throughout your second set of pictures.

cYa,

Tauwasser


...d'oh! >_<

Actually, that makes me wonder if maybe I have the /CE and /OE outputs from the Cx4 mixed up... or maybe the /OE clip came loose, I'll have to check when I get home.

Mon 16 Dec 2013, 23:56:12
User avatar

Joined: Tue 02 Nov 2010, 01:00:37

Posts: 181
Post Re: Trying to write to Cx4 ROM from the cart edge
Just so we're clear: You do send the right commands to program/unlock and then program the flash, right? Your little dump would likely not have been enough to determine that part...

cYa,

Tauwasser

Tue 17 Dec 2013, 00:39:27
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
I don't have to unlock the flash, because I never locked it in the first place. All that's shown here is me sending the erase command, which works perfectly when the microcontroller is connected directly to the ROM without the Cx4 in the middle. What I normally do is to send the erase command and then continuously read address 0x0000 until it returns 0xFF (not technically the *correct* way to determine that the erase has completed, but it works because reading from any address on the chip during an erase returns a status byte which AFAICT will never equal 0xFF, so it's good enough for me...). Once I get 0xFF back, I then proceed to program the chip using the program command sequence for each byte. I don't believe that this chip supports paged writes, but the single-byte writes work just fine, just not through the Cx4. I'll know more when I get home and can check the /OE signal. If it's really low through the entire thing, then obviously that's a problem...

But anyway, what you see in the dump is the result of the following code:

Code:
ROMWriteByte(0xAAA, 0xAA);
ROMWriteByte(0x555, 0x55);
ROMWriteByte(0xAAA, 0x80);
ROMWriteByte(0xAAA, 0xAA);
ROMWriteByte(0x555, 0x55);
ROMWriteByte(0xAAA, 0x10);
while(ROMReadByte(0x0000) != 0xFF);


You can see that the read loop is just returning the data currently programmed to the first byte of the ROM (0x78, I forgot to re-name the channel labels, it's actually D0-3, not D4-7, so you see it reading 8 over and over). That shouldn't happen, you should see a status byte instead, which at the very least should be toggling D2 each time you read.

Tue 17 Dec 2013, 02:02:26
User avatar

Joined: Tue 02 Nov 2010, 01:00:37

Posts: 181
Post Re: Trying to write to Cx4 ROM from the cart edge
qwertymodo wrote:
I don't have to unlock the flash, because I never locked it in the first place.


You're confusing protect and lock. The flash is locked at power-up.
Anyway, it wasn't clear to me that this is supposed to be an erase cycle, not a programming cycle. You should probably use the toggle bit/data polling bit as the datasheet suggests.

qwertymodo wrote:
But anyway, what you see in the dump is the result of the following code:

Code:
ROMWriteByte(0xAAA, 0xAA);
ROMWriteByte(0x555, 0x55);
ROMWriteByte(0xAAA, 0x80);
ROMWriteByte(0xAAA, 0xAA);
ROMWriteByte(0x555, 0x55);
ROMWriteByte(0xAAA, 0x10);
while(ROMReadByte(0x0000) != 0xFF);


I assume it's somehow guaranteed that these addresses are actually the adresses mapped by the Cx4? Speaking from game boy only, usually one needs to communicate with the mapper to map the higher address lines correctly. It seems the Cx4 is supposed to remap the complete memory region if necessary, not just high address lines? Or so your pin-out shows.

cYa,

Tauwasser

Tue 17 Dec 2013, 02:57:08
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
Yes, the Cx4 controls the entire ROM address bus, not just the high address lines. And you were right about the /OE line... I just checked my original RMX3 board that I messed up awhile back, and the /OE pad is connected to GND on PCB. So, that's the problem right there. Or at least it's *a* problem. Due to the way it's connected to the GND plane, it'll be a pain to disconnect, and I'll need to add more glue logic to drive it. I'm thinking it should be possible with a 74LVC1G19 1-to-2 decoder. /CE should remain connected directly between the Cx4 and /ROM_CE, but the decoder will drive the ROM's /WE and /OE signals using the Cx4's /WE output.

So:

ROM /CE = Cx4 /CE_OUT
ROM /OE = '1G19 Y1
ROM /WE = '1G19 Y0
'1G19 /E = Cx4 /CE_OUT
'1G19 A = Cx4 /WE_OUT


I'll give it a shot and see how it goes.

Tue 17 Dec 2013, 04:15:18
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
K, that didn't work, but I just realized the logic was faulty...

/CO, /WO - Cx4 /CE and /WE output pins
/RC, /RWE, /ROE - ROM /CE, /WE, and /OE input pins

/CO /WO | /RCE /RWE /ROE
X 0 | 0 0 1
0 1 | 0 1 0
1 0 | 0 0 1
1 1 | 1 1 1

X - /CO is always high during a write, so it is a don't care when /WO is low

So:
/RCE = /CO & /WO
/RWE = /WO
/ROE = /CO | !/WO

If I can find a single logic chip that performs this function, that would be awesome... bonus points if I can get it in a SOT23 package, like the '1G19.

Tue 17 Dec 2013, 07:15:54
User avatar

Joined: Tue 02 Nov 2010, 01:00:37

Posts: 181
Post Re: Trying to write to Cx4 ROM from the cart edge
So I saw that you suspect /CO = /ROM_OE on nesdev. If that holds, then

/RCE = /ROM_OE & /ROM_WE
/RWE = /ROM_WE <-- This should be a wire anyway? (as in the design thread)
/ROE = /ROM_OE <-- This can also be a wire.

You could use SN74AHC1G08 for that. The Cx4 probably already incorporates logic for the case that /OE and /WE are both asserted anyway.

cYa,

Tauwasser

Tue 17 Dec 2013, 20:41:59
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
Even better, pin 27 on the Cx4 seems to be the actual /CE signal.

Image

Wed 18 Dec 2013, 07:32:21
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
EHRMEHGERD SERCSERRRSSSS :D

Well... close, anyway. Random errors in the writes, but I'd be willing to wager I shorted an address or data line somewhere in all of the re-work, but the erase completed successfully, and I did manage to write to the ROM, so it DOES work. Gonna re-do all of the solder joints, and we'll go from there.

Wed 18 Dec 2013, 07:39:31
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
Touched up all of the solder joints, washed off the flux, hot-glued down the jumper wires so they (and the ROM /OE pin I had to lift) don't tear out, and it's 100% working. I've completely re-written the entire ROM 3 times now, with random data each time, then read it all back and it matched. As an added bonus, I managed to speed up my data transfer, so I'm able to burn the entire 2MB chip in 59 seconds, down from ~12 minutes previously. 'tis a good day.

Wed 18 Dec 2013, 08:58:26
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: Trying to write to Cx4 ROM from the cart edge
Just for kicks, I'm playing MMX1 on this RMX3 board... even though MMX1 doesn't use the Cx4, the memory map matches up, so it doesn't matter. I tried playing Zelda:aLttP, but you can't get past the name selection screen without SRAM :/

Wed 18 Dec 2013, 10:11:34

Joined: Fri 10 Apr 2009, 15:00:08

Posts: 13668
Post Re: Trying to write to Cx4 ROM from the cart edge
Hooray! :D

Congratulations in your success, and thanks so much for all the effort that went into this!

Wed 18 Dec 2013, 12:03:43
1, 2  Next

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum