kbeckmann / game-and-watch-retro-go

Emulator collection for Nintendo® Game & Watch™
GNU General Public License v2.0
440 stars 133 forks source link

SPI-Flash not detected #153

Closed drandreas closed 3 years ago

drandreas commented 3 years ago

I've upgraded from 67312e82bf41fd8504eb1c13ddbc1d8ecd238ec7 to 23f147240cb4b9c348b7b647de0943d63af1a341 since than the SPI-Flash chip is not detected. The JEDEC ID shown in is error message is always FF FF FF. The Correct JEDEC ID would be C2 95 3A (MX25U51245G-54).

I've bi-sected the code and found a solution. However the change I've to make is rather strange:

--- a/Core/Src/main.c
+++ b/Core/Src/main.c
@@ -291,7 +291,7 @@ void GW_EnterDeepSleep(void)
   // Enable wakup by PIN1, the power button
   HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW);

-  lcd_backlight_off();
+  //lcd_backlight_off();

   // Deinit the LCD, save power.

Could the lcd_backlight status influence the supply voltage of the Flash and trigger this melfunction?

Additional Info: Im flashing RetroGo to the second bank and loading it from the Homebrew Menu:

--- a/Makefile.common
+++ b/Makefile.common
@@ -13,11 +13,11 @@ CHECK_DIRTY_SUBMODULE ?= 1
 CHECK_TOOLS ?= 1

 # Set to 1 to enable 16MB external flash support. (deprecated, use EXTFLASH_SIZE_MB instead!)
-LARGE_FLASH ?= 0
+LARGE_FLASH ?= 1

 # Configure where data is stored in the external flash by
 # setting EXTFLASH_OFFSET. Useful if the first 1MB are to be preserved.
-EXTFLASH_OFFSET ?= 0
+EXTFLASH_OFFSET=1048576

 # Configure external flash size by setting EXTFLASH_SIZE
 ifeq ($(LARGE_FLASH),1)
@@ -29,8 +29,8 @@ else
 endif

 # Configure external flash size in MB (Megabytes)
-EXTFLASH_SIZE_MB ?= 1
-INTFLASH_BANK ?= 1
+EXTFLASH_SIZE_MB=48
+INTFLASH_BANK=2
kbeckmann commented 3 years ago

That's an interesting issue for sure!

23f1472 is not in this repo. Do you get the issue if you're running a normal build from the latest main branch, without dual booting and so on?

lcd_backlight_off controls the DACs which control the MOSFETs that are connected to the backlight. However, there have been reports that the backlight may sink too much current when powered over USB and the battery is disconnected. This will cause problems like brownouts, and it would explain that the external flash might be underpowered and not work properly.

We changed the default backlight setting to account for this, however if you have a high brightness setting, it will consume more power. Make sure that the battery is connected. If the battery is connected and you still see the issue, then I am not sure what the problem might be.

drandreas commented 3 years ago

You are right 23f1472 is from a different repo.

I've rebuilt everything from a clean checkout and flashed it to bank 1 that version works flawlessly. I've then moved it over to bank 2 and refreshed the original FW with Homebrew Menu patched in. Now SPI-Flash is broken again. So the chain loading musst be triggering some unclean state...

kbeckmann commented 3 years ago

Can you post exactly the steps you do to build and flash, and from which repositories you do that from?

If you are using Tim's firmware patcher, I can't help you much because it's closed source. But if you are using https://github.com/BrianPugh/game-and-watch-patch then we can track down the issue.

drandreas commented 3 years ago

Thank you for suggesting an alternative to Tim's patcher. I didn't knew it existed. I'll look into that path.