kbembedded / Flipper-Zero-Game-Boy-Pokemon-Trading

Pokemon trade from Flipper Zero to Game Boy for Generation I & II games (Pokemon Red, Blue, Yellow, Gold, Silver, and Crystal)
MIT License
325 stars 18 forks source link

Furi crash when selecting pokemon #9

Closed matthewwwillard closed 1 year ago

matthewwwillard commented 1 year ago

Describe the bug.

Flipper crashes on a furi_check failed after selecting a pokemon. When building from source, looked to be an issue when opening up the serial / gpio ports.

Reproduction

  1. Open app
  2. Select Pokemon

Target Framework

latest official firmware

Logs

No response

Anything else?

No response

EstebanFuentealba commented 1 year ago

Does it show any error? or simply goes back to the Flipper Zero's home screen? 0.82.3 ?

matthewwwillard commented 1 year ago

Screenshot-20230428-151514 Yea, 0.82.3

kbembedded commented 1 year ago

I've also had the same issue with latest binary pulled from flipC.org. Havn't tried hand-building yet. Spinning up on some hardware stuff to make a board before I really dive in to this.

EstebanFuentealba commented 1 year ago

This week or perhaps the next, I will acquire a Flipper Zero to try out.

kbembedded commented 1 year ago

I did some quick debug rounds (I'm still learning all of the workflows) and found this patch so far at least fixes the furi_check crash and gets to a point where it wants to connect to a real Game Boy:

diff --git a/pokemon_app.cpp b/pokemon_app.cpp
index ce274d6..2ef73e9 100644
--- a/pokemon_app.cpp
+++ b/pokemon_app.cpp
@@ -124,10 +124,7 @@ extern "C" int32_t pokemon_app(void* p) {
     furi_hal_light_set(LightRed, 0x00);
     furi_hal_light_set(LightGreen, 0x00);
     furi_hal_light_set(LightBlue, 0x00);
-    view_dispatcher_enable_queue(app->view_dispatcher);
-    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
     //switch view  and run dispatcher
-    view_dispatcher_switch_to_view(app->view_dispatcher, AppViewSelectPokemon);
     view_dispatcher_run(app->view_dispatcher);

     // Free resources
@@ -135,4 +132,4 @@ extern "C" int32_t pokemon_app(void* p) {
     furi_record_close(RECORD_GUI);

     return 0;
-}
\ No newline at end of file
+}
diff --git a/views/trade.cpp b/views/trade.cpp
index ad503bb..f6d1f93 100644
--- a/views/trade.cpp
+++ b/views/trade.cpp
@@ -327,6 +327,7 @@ void trade_enter_callback(void* context) {
         GpioModeInterruptRise,
         GpioPullNo,
         GpioSpeedVeryHigh); // <-- This line causes the "OK" to stop functioning when exiting the application, so a reboot of the Flipper Zero is required.
+    furi_hal_gpio_remove_int_callback(&GAME_BOY_CLK);
     furi_hal_gpio_add_int_callback(&GAME_BOY_CLK, input_clk_gameboy, trade);

     // furi_hal_gpio_disable_int_callback(&GAME_BOY_CLK);
@@ -384,4 +385,4 @@ void trade_free(App* app) {
 View* trade_get_view(App* app) {
     furi_assert(app);
     return app->trade->view;
-}
\ No newline at end of file
+}

The first calls that were removed from pokemon_app() were being called prior in pokemon_alloc() and calling a second time will assert trip. Only seen while debugging since I don't think normal release builds enable assert calls.

The added call to remove_init_callback was needed since that pin already had a callback set up on it to nfc_isr(). This might be a bug in flipper FW, but I'm not sure.

Hope this helps. I'll be playing around with this more when I have more time.

kbembedded commented 1 year ago

After looking at this a bit closer, I do really think this is a bug with the FW.

The reason the issue appeared is that there was a furi_assert that was changed to a runtime furi_check. So, this has always technically been a problem.

I've posted some notes in the Flipper discord and am waiting on feedback to see if its worth opening a GH issue about.

kbembedded commented 1 year ago

This is a known issue, not marked in current GPIO/documentation, and is not safe at this time to be used as EXTI for any other application. Sounds like it is being addressed in the refactor and will potentially be safe to use.

https://github.com/flipperdevices/flipperzero-firmware/issues/2690

Potential options moving forward:

EstebanFuentealba commented 1 year ago

Yes, is not safe at this time to be used as EXTI. PC3 uses EXTI3 line which is shared among all Px3 pins on all ports. https://github.com/flipperdevices/flipperzero-firmware/issues/2538

Moving the interface to different pins is the best option, although it would require updating the documentation, images, and wiring diagrams.