From 5aa66780c09318e00cd95c5eabe447833fcbe6a4 Mon Sep 17 00:00:00 2001 From: sakman55 Date: Fri, 1 Nov 2024 21:38:52 -1000 Subject: [PATCH] Update LJPRO.ino Added support for new Flash chips - MX25L4005 and MX25L6405. The new chips were found in cart with PCB B1043-03B. Removed the ROM size selection as we detect the ROM size based on the Flash ID. --- Cart_Reader/LJPRO.ino | 362 +++++++++++++++++++++++++----------------- 1 file changed, 212 insertions(+), 150 deletions(-) diff --git a/Cart_Reader/LJPRO.ino b/Cart_Reader/LJPRO.ino index 07ed983c..5058409f 100644 --- a/Cart_Reader/LJPRO.ino +++ b/Cart_Reader/LJPRO.ino @@ -98,12 +98,6 @@ //****************************************** // VARIABLES //****************************************** -byte LJPRO[] = {2,4,6,8}; -byte ljprolo = 0; // Lowest Entry -byte ljprohi = 3; // Highest Entry -byte ljprosize; -byte newljprosize; - char mnfID[3]; char deviceID_str[5]; boolean ljproflash1found = false; @@ -118,7 +112,7 @@ byte ljproflash2size; // MENU //****************************************** // Base Menu -static const char* const menuOptionsLJPRO[] PROGMEM = { FSTRING_READ_ROM, FSTRING_SET_SIZE, FSTRING_RESET }; +static const char* const menuOptionsLJPRO[] PROGMEM = { FSTRING_READ_ROM, FSTRING_RESET }; // U1_HOLD#(PH4) - SNES /IRQ // U1_CS# - SNES A8 @@ -132,8 +126,8 @@ static const char* const menuOptionsLJPRO[] PROGMEM = { FSTRING_READ_ROM, FSTRIN void ljproMenu() { - convertPgm(menuOptionsLJPRO, 3); - uint8_t mainMenu = question_box(F("LITTLE JAMMER PRO"), menuOptions, 3, 0); + convertPgm(menuOptionsLJPRO, 2); + uint8_t mainMenu = question_box(F("LITTLE JAMMER PRO"), menuOptions, 2, 0); switch (mainMenu) { @@ -145,11 +139,6 @@ void ljproMenu() break; case 1: - // Set Size - setROMSize_LJPRO(); - break; - - case 2: // reset resetArduino(); break; @@ -198,7 +187,6 @@ void setup_LJPRO() PORTA = 0xFF; PORTJ |= (1 << 0); // TIME(PJ0) - checkStatus_LJPRO(); strcpy(romName, "LJPRO"); mode = CORE_LJPRO; @@ -207,7 +195,7 @@ void setup_LJPRO() //****************************************** // SERIAL MODE //****************************************** -// 25L1605/25L3205 +// 25L4005/25L1605/25L3205/25L6405 // Default Serial Mode void sendSerial_U1(uint8_t data) @@ -266,10 +254,115 @@ uint8_t readSerial_U2() return tempdata; } +// RDID +// Manufacturer 0xC2 +// Memory Density 0x20 +// Device ID 0x13 [25L4005]/0x15 [25L1605]/0x16 [25L3205]/0x17 [25L6405] + +void readSerialID_U1() +{ + CS1_LOW; + DDRF = 0x00; // U1 Data Input + sendSerial_U1(0x9F); // 0x9F = 10011111 + // Manufacturer Code + byte id0 = readSerial_U1(); + // Device Code + byte id1 = readSerial_U1(); + byte id2 = readSerial_U1(); + CS1_HIGH; + // Flash ID + sprintf(mnfID, "%02X", id0); + sprintf(deviceID_str, "%02X%02X", id1, id2); + if(strcmp(deviceID_str, "2013") == 0) { // MX25L4005 + ljproflash1found = 1; + ljproflash1size = 1; + println_Msg(F("U1 MX25L4005 FOUND")); + display_Update(); + } + else if(strcmp(deviceID_str, "2015") == 0) { // MX25L1605 + ljproflash1found = 1; + ljproflash1size = 2; + println_Msg(F("U1 MX25L1605 FOUND")); + display_Update(); + } + else if (strcmp(deviceID_str, "2016") == 0) { // MX25L3205 + ljproflash1found = 1; + ljproflash1size = 4; + println_Msg(F("U1 MX25L3205 FOUND")); + display_Update(); + } + else if (strcmp(deviceID_str, "2017") == 0) { // MX25L6405 + ljproflash1found = 1; + ljproflash1size = 8; + println_Msg(F("U1 MX25L6405 FOUND")); + display_Update(); + } +} + +void readSerialID_U2() +{ + CS2_LOW; + DDRC = 0x00; // U2 Data Input + sendSerial_U2(0x9F); // 0x9F = 10011111 + // Manufacturer Code + byte id0 = readSerial_U2(); + // Device Code + byte id1 = readSerial_U2(); + byte id2 = readSerial_U2(); + CS2_HIGH; + // Flash ID + sprintf(mnfID, "%02X", id0); + sprintf(deviceID_str, "%02X%02X", id1, id2); + if(strcmp(deviceID_str, "2013") == 0) { // MX25L4005 + ljproflash2found = 1; + ljproflash2size = 1; + println_Msg(F("U2 MX25L4005 FOUND")); + display_Update(); + } + else if(strcmp(deviceID_str, "2015") == 0) { // MX25L1605 + ljproflash2found = 1; + ljproflash2size = 2; + println_Msg(F("U2 MX25L1605 FOUND")); + display_Update(); + } + else if (strcmp(deviceID_str, "2016") == 0) { // MX25L3205 + ljproflash2found = 1; + ljproflash2size = 4; + println_Msg(F("U2 MX25L3205 FOUND")); + display_Update(); + } + else if (strcmp(deviceID_str, "2017") == 0) { // MX25L6405 + ljproflash2found = 1; + ljproflash2size = 8; + println_Msg(F("U2 MX25L6405 FOUND")); + display_Update(); + } +} + +void readSerialData_U1(uint32_t startaddr, uint32_t endaddr) +{ + for (uint32_t addr = startaddr; addr < endaddr; addr += 512) { + for (int x = 0; x < 512; x++) { + sdBuffer[x] = readSerial_U1(); + } + myFile.write(sdBuffer, 512); + } +} + +void readSerialData_U2(uint32_t startaddr, uint32_t endaddr) +{ + for (uint32_t addr = startaddr; addr < endaddr; addr += 512) { + for (int x = 0; x < 512; x++) { + sdBuffer[x] = readSerial_U2(); + } + myFile.write(sdBuffer, 512); + } +} + //****************************************** // PARALLEL MODE //****************************************** -// 25L1605/25L3205 +// 25L1605/25L3205/25L6405 // Parallel Mode - Command 0x55 // SCLK Frequency 1.2MHz (Cycle 833.33ns) // READ 0x03 @@ -327,11 +420,7 @@ void readData_U2(uint32_t startaddr, uint32_t endaddr) // RDID // Manufacturer 0xC2 // Memory Density 0x20 -// Device ID 0x15 [25L1605]/0x16 [25L3205] - -// REMS -// Manufacturer 0xC2 -// Device ID 0x14 [25L1605]/0x15 [25L3205] +// Device ID 0x15 [25L1605]/0x16 [25L3205]/0x17 [25L6405] void readID_U1() // Parallel Mode { @@ -342,14 +431,11 @@ void readID_U1() // Parallel Mode pulseClock_LJPRO(1); byte id1 = PINF; // 0x20 pulseClock_LJPRO(1); - byte id2 = PINF; // 0x15 [MX25L1605]/0x16 [MX25L3205] + byte id2 = PINF; // 0x15 [MX25L1605]/0x16 [MX25L3205]/0x17 [MX25L6405] CS1_HIGH; // U1 HIGH // Flash ID sprintf(mnfID, "%02X", id0); sprintf(deviceID_str, "%02X%02X", id1, id2); -// println_Msg(mnfID); -// println_Msg(deviceID_str); -// display_Update(); if(strcmp(deviceID_str, "2015") == 0) { // MX25L1605 ljproflash1found = 1; ljproflash1size = 2; @@ -364,6 +450,13 @@ void readID_U1() // Parallel Mode println_Msg(F("U1 MX25L3205 FOUND")); display_Update(); } + else if (strcmp(deviceID_str, "2017") == 0) { // MX25L6405 + ljproflash1found = 1; + ljproflash1size = 8; + display_Clear(); + println_Msg(F("U1 MX25L6405 FOUND")); + display_Update(); + } } void readID_U2() // Parallel Mode @@ -375,15 +468,12 @@ void readID_U2() // Parallel Mode pulseClock_LJPRO(1); byte id1 = PINC; // 0x20 pulseClock_LJPRO(1); - byte id2 = PINC; // 0x15 [MX25L1605]/0x16 [MX25L3205] + byte id2 = PINC; // 0x15 [MX25L1605]/0x16 [MX25L3205]/0x17 [MX25L6405] pulseClock_LJPRO(1); CS2_HIGH; // U2 HIGH // Flash ID sprintf(mnfID, "%02X", id0); sprintf(deviceID_str, "%02X%02X", id1, id2); -// println_Msg(mnfID); -// println_Msg(deviceID_str); -// display_Update(); if(strcmp(deviceID_str, "2015") == 0) { // MX25L1605 ljproflash2found = 1; ljproflash2size = 2; @@ -396,6 +486,12 @@ void readID_U2() // Parallel Mode println_Msg(F("U2 MX25L3205 FOUND")); display_Update(); } + else if (strcmp(deviceID_str, "2017") == 0) { // MX25L6405 + ljproflash2found = 1; + ljproflash2size = 8; + println_Msg(F("U2 MX25L6405 FOUND")); + display_Update(); + } } //****************************************** @@ -411,48 +507,102 @@ void readROM_LJPRO() // Test carts only have one 25L1605 (2MB) installed // PCB could possibly install two 25L3205 chips (2x4MB = 8MB) - // Set U1 FLASH to Parallel Mode - CS1_LOW; // U1 LOW - sendSerial_U1(0x55); // Parallel Mode - CS1_HIGH; // U1 HIGH - // Read ID - readID_U1(); - // Set U2 FLASH to Parallel Mode - CS2_LOW; // U2 LOW - sendSerial_U2(0x55); // Parallel Mode - CS2_HIGH; // U2 HIGH - // Read ID - readID_U2(); + // Little Jammer Pro PCB B1043-03B + // Footprints for 25L4005 + 25L6405 chips + // U1 = 25L4005 (512KB), U2 = 25L6405 (8MB) + + // Reset Flash Settings + ljproflash1found = 0; + ljproflash2found = 0; + ljproflash1size = 0; + ljproflash2size = 0; + + display_Clear(); + readSerialID_U1(); + if (!ljproflash1found) { + // Set U1 FLASH to Parallel Mode + CS1_LOW; // U1 LOW + sendSerial_U1(0x55); // Parallel Mode + CS1_HIGH; // U1 HIGH + readID_U1(); // Read ID using Parallel Mode + } + readSerialID_U2(); + if (!ljproflash2found) { + // Set U2 FLASH to Parallel Mode + CS2_LOW; // U2 LOW + sendSerial_U2(0x55); // Parallel Mode + CS2_HIGH; // U2 HIGH + readID_U2(); // Read ID using Parallel Mode + } + // NOTE: Setting Flash to Parallel Mode stays in effect until Power Cycle // Read U1 println_Msg(F("Reading U1...")); display_Update(); - CS1_LOW; // U1 LOW - DDRF = 0x00; // U1 Data Input - sendSerial_U1(0x03); // Read Array (Parallel) - sendSerial_U1(0x00); // Address A23-A16 - sendSerial_U1(0x00); // Address A15-A8 - sendSerial_U1(0x00); // Address A7-A0 - readData_U1(0x000000, 0x200000); - if (ljproflash1size == 4) { // 4MB - readData_U1(0x200000, 0x400000); + if (ljproflash1size == 1) { // 25L4005 - Serial Mode + CS1_LOW; // U1 LOW + DDRF = 0x00; // U1 Data Input + sendSerial_U1(0x03); // Read Array + sendSerial_U1(0x00); // Address A23-A16 + sendSerial_U1(0x00); // Address A15-A8 + sendSerial_U1(0x00); // Address A7-A0 + readSerialData_U1(0x00000,0x80000); // 512KB + CS1_HIGH; // U1 HIGH + } + else { // 25L1605/25L3205/25L6405 - Parallel Mode + // Set U1 FLASH to Parallel Mode + CS1_LOW; // U1 LOW + sendSerial_U1(0x55); // Parallel Mode + CS1_HIGH; // U1 HIGH + CS1_LOW; // U1 LOW + DDRF = 0x00; // U1 Data Input + sendSerial_U1(0x03); // Read Array + sendSerial_U1(0x00); // Address A23-A16 + sendSerial_U1(0x00); // Address A15-A8 + sendSerial_U1(0x00); // Address A7-A0 + readData_U1(0x000000, 0x200000); // 2MB + if (ljproflash1size > 2) { + readData_U1(0x200000, 0x400000); // +2MB = 4MB + if (ljproflash1size > 4) { + readData_U1(0x400000, 0x800000); // +4MB = 8MB + } + } + CS1_HIGH; // U1 HIGH } - CS1_HIGH; // U1 HIGH if (ljproflash2found) { // Read U2 println_Msg(F("Reading U2...")); display_Update(); - CS2_LOW; // U2 LOW - DDRC = 0x00; // U2 Data Input - sendSerial_U2(0x03); // Read Array (Parallel) - sendSerial_U2(0x00); // Address A23-A16 - sendSerial_U2(0x00); // Address A15-A8 - sendSerial_U2(0x00); // Address A7-A0 - readData_U2(0x000000, 0x200000); - if (ljproflash2size == 4) { // 4MB - readData_U2(0x200000, 0x400000); + if (ljproflash2size == 1) { // 25L4005 - Serial Mode + CS2_LOW; // U2 LOW + DDRC = 0x00; // U2 Data Input + sendSerial_U2(0x03); // Read Array + sendSerial_U2(0x00); // Address A23-A16 + sendSerial_U2(0x00); // Address A15-A8 + sendSerial_U2(0x00); // Address A7-A0 + readSerialData_U2(0x00000,0x80000); // 512KB + CS2_HIGH; // U2 HIGH + } + else { // 25L1605/25L3205/25L6405 - Parallel Mode + // Set U2 FLASH to Parallel Mode + CS2_LOW; // U2 LOW + sendSerial_U2(0x55); // Parallel Mode + CS2_HIGH; // U2 HIGH + CS2_LOW; // U2 LOW + DDRC = 0x00; // U2 Data Input + sendSerial_U2(0x03); // Read Array + sendSerial_U2(0x00); // Address A23-A16 + sendSerial_U2(0x00); // Address A15-A8 + sendSerial_U2(0x00); // Address A7-A0 + readData_U2(0x000000, 0x200000); // 2MB + if (ljproflash2size > 2) { + readData_U2(0x200000, 0x400000); // +2MB = 4MB + if (ljproflash2size > 4) { + readData_U2(0x400000, 0x800000); // +4MB = 8MB + } + } + CS2_HIGH; // U2 HIGH } - CS2_HIGH; // U2 HIGH } myFile.close(); @@ -463,92 +613,4 @@ void readROM_LJPRO() display_Update(); wait(); } - -//****************************************** -// ROM SIZE -//****************************************** - -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) -void printRomSize_LJPRO(int index) -{ - display_Clear(); - print_Msg(FS(FSTRING_ROM_SIZE)); - println_Msg(LJPRO[index]); -} -#endif - -void setROMSize_LJPRO() -{ - byte newljprosize; -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display_Clear(); - if (ljprolo == ljprohi) - newljprosize = ljprolo; - else { - newljprosize = navigateMenu(ljprolo, ljprohi, &printRomSize_LJPRO); - - display.setCursor(0, 56); // Display selection at bottom - } - print_Msg(FS(FSTRING_ROM_SIZE)); - print_Msg(LJPRO[newljprosize]); - println_Msg(F("KB")); - display_Update(); - delay(1000); -#else - if (ljprolo == ljprohi) - newljprosize = ljprolo; - else { -setrom: - String sizeROM; - for (int i = 0; i < (ljprohi - ljprolo + 1); i++) { - Serial.print(F("Select ROM Size: ")); - Serial.print(i); - Serial.print(F(" = ")); - Serial.print(LJPRO[i + ljprolo]); - Serial.println(F("KB")); - } - Serial.print(F("Enter ROM Size: ")); - while (Serial.available() == 0) {} - sizeROM = Serial.readStringUntil('\n'); - Serial.println(sizeROM); - newljprosize = sizeROM.toInt() + ljprolo; - if (newljprosize > ljprohi) { - Serial.println(F("SIZE NOT SUPPORTED")); - Serial.println(FS(FSTRING_EMPTY)); - goto setrom; - } - } - Serial.print(F("ROM Size = ")); - Serial.print(LJPRO[newljprosize]); - Serial.println(F("KB")); -#endif - EEPROM_writeAnything(8, newljprosize); - ljprosize = newljprosize; -} - -void checkStatus_LJPRO() -{ - EEPROM_readAnything(8, ljprosize); - if (ljprosize > ljprohi) { - ljprosize = 0; // default 2M - EEPROM_writeAnything(8, ljprosize); - } - -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display_Clear(); - println_Msg(F("LITTLE JAMMER PRO")); - println_Msg(FS(FSTRING_CURRENT_SETTINGS)); - println_Msg(FS(FSTRING_EMPTY)); - print_Msg(FS(FSTRING_ROM_SIZE)); - print_Msg(LJPRO[ljprosize]); - println_Msg(F("MB")); - display_Update(); - wait(); -#else - Serial.print(FS(FSTRING_ROM_SIZE)); - Serial.print(LJPRO[ljprosize]); - Serial.println(F("MB")); - Serial.println(FS(FSTRING_EMPTY)); -#endif -} #endif