STM32F765@216MHz running NES emulator [code] [video]
[Copy link]
This post was last edited by Kεnny on 2019-2-22 15:10 This article is public from "STM32F765@216MHz output I2S test ES9023P audio listening experience" link (https://bbs.eeworld.com.cn/thread-1069926-1-1.html) Performance: The author's development board uses STM32F765VIT6@216MHz. The development board uses an active crystal oscillator in a 3225 package to provide a 25MHz (-+20PPM) HSE. The frequency is multiplied to 216MHz through PLL. In actual tests, the frequency multiplier parameters are modified, and the core clock can be overclocked to 270MHz without running away (the test time is about 40 minutes, and higher frequencies or longer test times have not been tested). In the MCU industry, the performance is already unrivaled. Idea: Then the author has an idea. The development board has Button, LCD and Audio. Can it run some multimedia or make it into an interactive entertainment device? I saw some NES games running on the Internet. After a closer look, it is actually to simulate the CPU 6502 and peripheral RAM of the 1980s and 1990s through software, and then run NES games on the simulator.
About 6502: After a careful understanding, the author's evaluation of 6502 is: great. In that era, it was used in many scenarios, in addition to Nintendo's FC, there were also Jobs's early Apple PC, Commodore's mainframe, Las Vegas casino slot machines, early domestic Wenquxing, and even Skynet's T800 series Terminator were equipped with this CPU (just a joke). This CPU has created countless excellent programmers and brought joy to countless people. It is well-deserved to be called a masterpiece of the era. Back to the topic: In today's world of open source software, in the spirit of standing on the shoulders of giants, the author directly found three emulators on the Internet, including InfoNES, Neil's 6502 emulator and NES by netizen ye781205. a. First of all, InfoNES, mainly creating a new InfoNES_System.c and implementing the interface in InfoNES_System.h in InfoNES_System.c; then appropriately modifying the hardware-related files InfoNES.c, InfoNES.h, and K6502_rw.h, including the memory implementation of simulating SRAM, allocating memory in the heap (note the modification of the Heap Size), or using the wild way of specifying the first address. The author runs InfoNES on the development board, and the FPS is about 9 @ 216MHz. This makes people not want to continue to implement audio. Although it can be played by skipping 2 frames, I still give up after looking at the effect of PPT. b. Next is Neil's 6502 emulator. This emulator does not have audio. The source code has been ported to stm32f1. The author only needs to modify it to his own development board, get the key to fill the global array JoyPad[0] (player 1) and JoyPad[1] (player 2) in the timer interrupt, and implement NES_LCD_DisplayLine() in PPU.c to adapt LCD filling and stretching. Read the NES file from the USB drive into the array rom_file[ROM_FILE_SIZE], then run nes_main() to start the game (ROM_FILE_SIZE macro is modified to 200Kbytes by the author, array rom_file is defined in Rom_files.c, and declared as an external variable in rom.h). The author measured FPS at 30@216MHz, but there is no sound, and not many games are supported, which is still not perfect. c. Finally, openedvNES by netizen ye781205. This NES core is implemented in assembly, and the punctual atoms are improved, which is very efficient. The source code that the author searched online comes from the project package of Zhengdian Atom, and the project runs on stm32f1. The author is not sure whether M7 is backward compatible with assembly, so he started with a try-it attitude. The specific process includes: (1) In nes_main.c, nes_load(char *pname) is used to open the file, f_stat is used to determine the file size information and malloc memory space for romfile, the file is read into romfile, nes_load_rom() is used to initialize the file, and then it is started through nes_emulate_frame(); (2) In nes_main.c, nes_set_window() is used to adapt the LCD display area; (3) In nes_main.c, nes_get_gamepadval() is used to obtain the key to fill the global variables PAData0 and PAData1, which will be used in 6502.s; (4) In nes_ppu.c, scanline_draw() is used to fill and stretch the LCD pixels; (5) Implement nes_apu_fill_buffer(), nes_sound_open(), nes_sound_close() to output audio in nes_main.c (6) In nes_apu.h, set the audio sampling frequency, and set the maximum frame rate limit. (7) Modify the custom memory management of the atom, change it to use the malloc provided by the compiler, use the internal SRAM of the SOC, and increase the Heap_Size in the startup code. Audio: The author uses wavebuf to fill the left and right channels in the send buffer (left and right are the same), 16-bit, and finally directly outputs to ES9023P through I2S1 via DMA. The DMA is set to circular mode and the byte alignment is set to half word (16-bit). The send completion flag is set in the HAL_I2S_TxCpltCallback() send completion callback. In nes_apu_fill_buffer(), it is determined whether the audio buffer is sent. In this way, the maximum frame rate of the simulator can be limited. Frame rate: The author has tested that without adding frame rate limit and optimizing LCD refresh, FPS can reach 95@216MHz. If we optimize the 6-stage dual-issue superscalar pipeline of M7 and use L1 Cache, we should be able to get higher frame rate. The author limits the FPS to 60 frames, reads nes through a USB disk and runs it. The actual effect is as follows: If the video cannot be played, please copy the link to view it separately (http://v.youku.com/v_show/id_XND ... 3ff6c5cfbdcb930c939) The author did not use OS, but used the standard HAL project established by CubeMX. As usual, I offer it to everyone for use: [Attachment, project compression package, copy the link and open it to download] https://en.eeworld.com/bbs/forum.php?mod=attachment&aid=NDAyOTUyfDYyZmRkOGViYTEzZTMxZjFjMWJjOTk2MzRiNTVhZjQ3fDE3MzIyMzYwNzQ%3D&request=yes&_f=.7z As for the rom file, please prepare it by yourself, it is not provided in this article. [Friendly reminder] According to the legal common sense the author knows, if you crack ROM or save collection ROM in the United States, you will be sentenced if you are held accountable. There are corresponding laws and regulations in China, please abide by them consciously. This article was originally created by Kεnny, a netizen of EEWORLD forum. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source.
|