V30F: Fix writing MX29LV160

Reset pin needs to be connected to Reset of SNES slot.
This commit is contained in:
sanni 2017-11-24 21:36:33 +01:00 committed by GitHub
parent 76ae5c5408
commit 8c6d0960fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 63 deletions

View File

@ -2,8 +2,8 @@
Cartridge Reader for Arduino Mega2560 Cartridge Reader for Arduino Mega2560
Author: sanni Author: sanni
Date: 2017-11-22 Date: 2017-11-24
Version: V30E Version: V30F
SD lib: https://github.com/greiman/SdFat SD lib: https://github.com/greiman/SdFat
LCD lib: https://github.com/adafruit/Adafruit_SSD1306 LCD lib: https://github.com/adafruit/Adafruit_SSD1306
@ -35,7 +35,7 @@
infinest - help with GB Memory cart infinest - help with GB Memory cart
**********************************************************************************/ **********************************************************************************/
char ver[5] = "V30E"; char ver[5] = "V30F";
/****************************************** /******************************************
Define Starting Point Define Starting Point
@ -46,6 +46,7 @@ char ver[5] = "V30E";
/****************************************** /******************************************
Define Output Define Output
******************************************/ ******************************************/
// To use the Serial Monitor change
// enable_OLED to 0 and enable_Serial to 1 // enable_OLED to 0 and enable_Serial to 1
#define enable_OLED 1 #define enable_OLED 1
#define enable_Serial 0 #define enable_Serial 0
@ -59,7 +60,7 @@ char ver[5] = "V30E";
/****************************************** /******************************************
Define SD Speed Define SD Speed
******************************************/ ******************************************/
// Change to half speed if you get an sd error // Change to half speed if you get an sd error or it hangs when writing
#define sdSpeed SPI_FULL_SPEED #define sdSpeed SPI_FULL_SPEED
//#define sdSpeed SPI_HALF_SPEED //#define sdSpeed SPI_HALF_SPEED

View File

@ -128,12 +128,10 @@ void flashromMenu8() {
else if (flashromType == 2) { else if (flashromType == 2) {
if (strcmp(flashid, "C2F3") == 0) if (strcmp(flashid, "C2F3") == 0)
writeFlash29F1601(); writeFlash29F1601();
else if (strcmp(flashid, "C2A8") == 0) else if (strcmp(flashid, "C2F1") == 0)
writeFlash29LV320();
else if (strcmp(flashid, "C2C9") == 0)
writeFlash29LV640();
else
writeFlash29F1610(); writeFlash29F1610();
else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C2A8") == 0) || (strcmp(flashid, "C2C9") == 0))
writeFlash29LV640();
} }
delay(100); delay(100);
// Reset twice just to be sure // Reset twice just to be sure
@ -301,10 +299,10 @@ void setup_Flash8() {
//A16-A23 //A16-A23
DDRL = 0xFF; DDRL = 0xFF;
// Set Control Pins to Output OE(PH1) WE(PH4) CE(PH6) // Set Control Pins to Output RST(PH0) OE(PH1) WE(PH4) CE(PH6)
DDRH |= (1 << 1) | (1 << 4) | (1 << 6); DDRH |= (1 << 0) | (1 << 1) | (1 << 4) | (1 << 6);
// Setting OE(PH1) WE(PH4) HIGH // Setting RST(PH0) OE(PH1) WE(PH4) HIGH
PORTH |= (1 << 1) | (1 << 4); PORTH |= (1 << 0) | (1 << 1) | (1 << 4);
// Setting CE(PH6) LOW // Setting CE(PH6) LOW
PORTH &= ~(1 << 6); PORTH &= ~(1 << 6);
@ -342,13 +340,21 @@ idtheflash:
flashSize = 4194304; flashSize = 4194304;
flashromType = 2; flashromType = 2;
} }
else if (strcmp(flashid, "C2C4") == 0) {
println_Msg(F("MX29LV160 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 2097152;
flashromType = 2;
}
else if (strcmp(flashid, "C2A8") == 0) { else if (strcmp(flashid, "C2A8") == 0) {
println_Msg(F("MX29LV320")); println_Msg(F("MX29LV320"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 4194304; flashSize = 4194304;
flashromType = 2; flashromType = 2;
} }
else if (strcmp(flashid, "C2C9") == 0) { else if (strcmp(flashid, "C2C9") == 0) {
println_Msg(F("MX29LV640")); println_Msg(F("MX29LV640"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 8388608; flashSize = 8388608;
flashromType = 2; flashromType = 2;
} }
@ -911,54 +917,6 @@ void busyCheck29LV640(unsigned long myAddress, byte myData) {
dataOut(); dataOut();
} }
void writeFlash29LV320() {
// Create filepath
sprintf(filePath, "%s/%s", filePath, fileName);
println_Msg(F("Flashing file "));
println_Msg(filePath);
display_Update();
// Open file on sd card
if (myFile.open(filePath, O_READ)) {
// Get rom size from file
fileSize = myFile.fileSize();
if (fileSize > flashSize)
print_Error(F("File size exceeds flash size."), true);
// Set data pins to output
dataOut();
for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) {
// Fill sdBuffer
myFile.read(sdBuffer, 512);
// Blink led
if (currByte % 2048 == 0)
PORTB ^= (1 << 4);
for (int c = 0; c < 512; c++) {
// Write command sequence
writeByte_Flash(0x555 << 1, 0xaa);
writeByte_Flash(0x2aa << 1, 0x55);
writeByte_Flash(0x555 << 1, 0xa0);
// Write current byte
writeByte_Flash(currByte + c, sdBuffer[c]);
// Check if write is complete
busyCheck29F032(sdBuffer[c]);
}
}
// Set data pins to input again
dataIn8();
// Close the file:
myFile.close();
}
else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
}
void writeFlash29LV640() { void writeFlash29LV640() {
// Create filepath // Create filepath
sprintf(filePath, "%s/%s", filePath, fileName); sprintf(filePath, "%s/%s", filePath, fileName);
@ -978,7 +936,7 @@ void writeFlash29LV640() {
// Fill sdBuffer // Fill sdBuffer
myFile.read(sdBuffer, 512); myFile.read(sdBuffer, 512);
// Blink led // Blink led
if (currByte % 2048 == 0) if (currByte % 4096 == 0)
PORTB ^= (1 << 4); PORTB ^= (1 << 4);
for (int c = 0; c < 512; c++) { for (int c = 0; c < 512; c++) {
// Write command sequence // Write command sequence
@ -988,6 +946,7 @@ void writeFlash29LV640() {
// Write current byte // Write current byte
writeByte_Flash(currByte + c, sdBuffer[c]); writeByte_Flash(currByte + c, sdBuffer[c]);
// Check if write is complete // Check if write is complete
//busyCheck29F032(sdBuffer[c]);
busyCheck29LV640(currByte + c, sdBuffer[c]); busyCheck29LV640(currByte + c, sdBuffer[c]);
} }
} }

View File

@ -893,9 +893,12 @@ void readROM_GBA() {
// Read rom // Read rom
for (int myAddress = 0; myAddress < cartSize; myAddress += 512) { for (int myAddress = 0; myAddress < cartSize; myAddress += 512) {
// Blink led
if (myAddress % 16384 == 0)
PORTB ^= (1 << 4);
for (int currWord = 0; currWord < 512; currWord += 2) { for (int currWord = 0; currWord < 512; currWord += 2) {
word tempWord = readWord_GBA(myAddress + currWord); word tempWord = readWord_GBA(myAddress + currWord);
sdBuffer[currWord] = tempWord & 0xFF; sdBuffer[currWord] = tempWord & 0xFF;
sdBuffer[currWord + 1] = (tempWord >> 8) & 0xFF; sdBuffer[currWord + 1] = (tempWord >> 8) & 0xFF;
} }

View File

@ -1750,6 +1750,7 @@ void writeFram(byte flashramType) {
// Delay between banks // Delay between banks
delay(20); delay(20);
} }
println_Msg("");
// Close the file: // Close the file:
myFile.close(); myFile.close();
} }