moononournation / arduino-nofrendo

Clone from source http://www.baisoku.org/nofrendo-2.0pre1.zip
Other
87 stars 40 forks source link

E (1305) vfs_fat: open: no free file descriptors #15

Closed minghaojiang closed 6 months ago

minghaojiang commented 7 months ago

Hi, moononournation, I tried different ways to run this software but failed. So far, here are progress I made: I managed to light LCD screen (2 LCDs I tried. 7789 with 240x240 and 9341 with 320x240), both showed Nintendo logo picture and hanged there. My chip is ESP32 wrover. The Serial output I got was

16:35:49.507 -> ets Jun 8 2016 00:22:57 16:35:49.507 -> 16:35:49.507 -> rst:0x1 (POWERON_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT) ... 16:35:50.871 -> /fs/battlecity.nes 16:35:50.871 -> NoFrendo start! 16:35:50.871 -> 16:35:50.871 -> OSDMain hit filename = /fs/battlecity.nes 16:35:50.911 -> _my_malloc: 1468 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\ESP32Folder\esp32-nofrendo_sample_7789\sound.c:145 ... 16:35:50.951 -> _my_malloc: 19 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nofrendo.c:242 16:35:50.951 -> rom_findrom filename = /fs/battlecity.nesE (1190) vfs_fat: open: no free file descriptors 16:35:50.951 -> E (1198) vfs_fat: open: no free file descriptors 16:35:50.991 -> _my_malloc: 19 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nofrendo.c:152 16:35:50.991 -> system type unknown, playing nofrendo NES intro. 16:35:50.991 -> _my_malloc: 19 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nofrendo.c:152 ... 16:35:51.071 -> _my_malloc: 1068 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes_rom.c:427 16:35:51.071 -> rom_findrom filename = /fs/battlecity.nesE (1297) vfs_fat: open: no free file descriptors 16:35:51.071 -> E (1305) vfs_fat: open: no free file descriptors 16:35:51.071 -> GUI: /fs/battlecity.nes not found, will use default ROM ... 16:35:51.151 -> GUI: NES powered on 16:35:51.151 -> _my_malloc: 61440 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\bitmap.c:86 16:35:51.151 -> _my_malloc: 980 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\bitmap.c:48 16:35:51.151 -> Timer install, configTICK_RATE_HZ=1000, freq=60 16:36:00.819 -> addr: 0x3FFE46E4, size: 61440, line 86 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\bitmap.c -- block corrupt

The last line "block corrupt" I found in other issues that you mention it is correct. But the problem is seems game nes file was not loaded, GUI shows /fs/battlecitynes not found and use default ROM.

I tried another thing is I changed osd.c file, line 36 else clause to be same as if clause.

if (prefer_fast_memory)
{
    return heap_caps_malloc(size, MALLOC_CAP_8BIT);
}
else
{
            return heap_caps_malloc(size, MALLOC_CAP_8BIT);
    //return heap_caps_malloc_prefer(size, MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT);
}

Then I got repeatedly reboot, but serial print out shows:

16:38:49.104 -> rst:0xc (SW_CPU_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT) ... 16:38:50.468 -> /fs/battlecity.nes 16:38:50.468 -> NoFrendo start! 16:38:50.468 -> 16:38:50.468 -> OSDMain hit filename = /fs/battlecity.nes 16:38:50.468 -> _my_malloc: 1468 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\ESP32Folder\esp32-nofrendo_sample_7789\sound.c:145 ... 16:38:50.548 -> rom_findrom filename = /fs/battlecity.nes_my_malloc: 19 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nofrendo.c:152 16:38:50.548 -> _my_malloc: 808 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes.c:522 ... 16:38:50.628 -> _my_malloc: 1068 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes_rom.c:427 16:38:50.628 -> rom_findrom filename = /fs/battlecity.nes_my_malloc: 8192 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes_rom.c:131 16:38:50.708 -> GUI: ROM loaded: battlecity.nes [0] 16k/8k H 16:38:50.708 -> _my_malloc: 8 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes_mmc.c:241 16:38:50.708 -> created memory mapper: None 16:38:50.708 -> setting up mapper 0 16:38:50.708 -> reset memory mapper 16:38:50.708 -> GUI: NES powered on 16:38:50.708 -> _my_malloc: 61440 at C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\bitmap.c:86 16:38:50.748 -> ASSERT: line 266 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\memguard.c, malloc: out of memory at line 86 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\bitmap.c. block size: 61440 16:38:50.748 -> 16:38:50.748 -> memory leak - 9 unfreed blocks 16:38:50.748 -> 16:38:50.748 -> addr: 0x3FFCFDC8, size: 1468, line 145 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\ESP32Folder\esp32-nofrendo_sample_7789\sound.c 16:38:50.788 -> addr: 0x3FFD0BE4, size: 808, line 522 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes.c 16:38:50.788 -> addr: 0x3FFBC468, size: 92, line 539 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes.c 16:38:50.788 -> addr: 0x3FFD0F5C, size: 2048, line 546 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes.c 16:38:50.828 -> addr: 0x3FFD17AC, size: 296, line 990 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\sndhrdw\nes_apu.c 16:38:50.828 -> addr: 0x3FFD1924, size: 7584, line 127 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes_ppu.c 16:38:50.828 -> addr: 0x3FFD3714, size: 1068, line 427 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes_rom.c 16:38:50.868 -> addr: 0x3FFD3B90, size: 8192, line 131 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes_rom.c 16:38:50.868 -> addr: 0x3FFBC514, size: 8, line 241 of C:\Users\mjiang\OneDrive - Intel Corporation\Documents\Arduino\libraries\arduino-nofrendo\src\nes\nes_mmc.c 16:38:50.868 -> 16:38:50.868 -> abort() was called at PC 0x400fd17e on core 1 16:38:50.868 -> 16:38:50.868 -> 16:38:50.868 -> Backtrace: 0x40083975:0x3ffce6d0 0x4008d3d1:0x3ffce6f0 0x40092dc1:0x3ffce710 0x400fd17e:0x3ffce790 0x40123f77:0x3ffce7b0 0x400da61a:0x3ffce7d0 0x400da7ae:0x3ffce7f0 0x400d91e6:0x3ffce930 0x400daf12:0x3ffce950 0x400dabbb:0x3ffce970 0x400d29e9:0x3ffce9a0 0x400daaeb:0x3ffce9c0 0x400d30ce:0x3ffce9e0 0x400ed402:0x3ffceb90 16:38:50.908 -> 16:38:50.908 -> 16:38:50.908 -> 16:38:50.908 -> 16:38:50.908 -> ELF file SHA256: 442a6512c2c36aca 16:38:50.908 -> 16:38:51.269 -> Rebooting... 16:38:51.269 -> ets Jun 8 2016 00:22:57 16:38:51.269 -> 16:38:51.269 -> rst:0xc (SW_CPU_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT) ...

It shows the game rom was loaded, but mem allocate goes out of memory. Any idea to fix?

Thanks MJiang

minghaojiang commented 7 months ago

My chip info: 18:56:32.047 -> ESP32 Chip model = ESP32-D0WDQ6 Rev 1 18:56:32.047 -> This chip has 2 cores 18:56:32.047 -> Chip ID: 9275045 18:56:32.047 -> Flash Size: 4194304 bytes 18:56:32.047 -> PSRAM Size: 4192107 bytes 18:56:32.047 -> Free Memory: 310260 bytes 18:56:32.047 -> Total heap: 334804 bytes 18:56:32.047 -> Free PSRAM: 4191847 bytes

And, more findings: When osd.c file, line 36 else clause use SPIRAM, e.g.

if (prefer_fast_memory) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } else { // return heap_caps_malloc(size, MALLOC_CAP_8BIT); return heap_caps_malloc_prefer(size, MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); }

In lib folder, I added a debug print and find nes_rom.c line 244 fp = _fopen(rominfo->filename, "rb"); returns NULL, while osd.c always both if and else return heap_caps_malloc(size, MALLOC_CAP_8BIT) is not.

minghaojiang commented 6 months ago

After changing to use ESP32S2 mini, it works. Probably due to previous chip issue.