I have ported my old project “pNesX” game console emulator to the nucleo.
Dependencies: SDFileSystem mbed
Intro
I have ported my old project “pNesX” to the STM32 Nucleo. The pNesX is a NES emulator for the PlayStation that I have created 16 years ago!
Emulation part was almost without change, the sound part was newly added.
Parts
STM32 Nucleo F446RE |
QVGA 2.2 TFT SPI (with the SD card slot) |
Audio jack(TS or TRS) |
USB Connector |
Register 100k, 10k, 4.7k, 100 |
Capacitor 0.01uF, 2.2uF |
Breadboard |
Wires |
Computer Speakers |
USB GamePad |
Wiring diagram
TFT J2 | Nucleo |
---|---|
VCC | 3V3 |
GND | GND |
CS | PB_5(D4) |
Reset | PA_10(D2) Pull Up(100k) |
D/C | PA_8(D7) |
MOSI | PA_7(D11) |
SCK | PA_5(D13) |
LED | LED-100ohm-3V3 |
MISO | PA_6(D12) |
TFT J4 | Nucleo |
---|---|
SD_CS | PA_9 |
SD_MOSI | PB_15 |
SD_MISO | PB_14 |
SD_SCK | PB_13 |
Audio | Nucleo |
---|---|
TIP | PA_4(A2) |
USB con. | Nucleo |
---|---|
GND | GND |
+ | PA_12 |
- | PA_11 |
5V | 5V |
Limitations
- Since the rest of the RAM is about 50kbyte, maximum capacity of the game ROM is about 50kbyte.
- The length of the file name up to 32 characters.
- The number of files in the folder is up to 100.
Used Library
- SDFileSystem by Neil Thiessen
- F401RE-USBHost by Norimasa Okamoto
- USBHostGamepad by Yuuichi Akagawa
USBHost/USBHostHub.cpp
- Committer:
- beaglescout007
- Date:
- 2016-04-03
- Revision:
- 0:3dac1f1bc9e0
File content as of revision 0:3dac1f1bc9e0:
#include "USBHost.h" #define PORT_CONNECTION 0 #define PORT_ENABLE 1 #define PORT_SUSPEND 2 #define PORT_OVER_CURRENT 3 #define PORT_RESET 4 #define PORT_POWER 8 #define PORT_LOW_SPEED 9 #define C_PORT_CONNECTION 16 #define C_PORT_ENABLE 17 #define C_PORT_SUSPEND 18 #define C_PORT_OVER_CURRENT 19 #define C_PORT_RESET 20 bool USBHost::Hub(USBDeviceConnected* dev) { USB_INFO("New HUB: VID:%04x PID:%04x [dev: %p]", dev->getVid(), dev->getPid(), dev); HubDescriptor hubdesc; // get HUB descriptor int rc = controlRead(dev, USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS, GET_DESCRIPTOR, 0x29 << 8, 0, reinterpret_cast<uint8_t*>(&hubdesc), sizeof(HubDescriptor)); USB_TEST_ASSERT(rc == USB_TYPE_OK); if (rc != USB_TYPE_OK) { return false; } USB_DBG_HEX((uint8_t*)&hubdesc, sizeof(hubdesc)); uint32_t status; rc = controlRead( dev, 0xa0, 0, 0, 0, reinterpret_cast<uint8_t*>(&status), 4); USB_TEST_ASSERT(rc == USB_TYPE_OK); if (rc != USB_TYPE_OK) { return false; } USB_DBG("HUB STATUS: %08X\n", status); for(int i = 1; i <= hubdesc.bNbrPorts; i++) { SetPortPower(dev, i); // power on wait_ms(hubdesc.bPwrOn2PwrGood*2); uint32_t status; GetPortStatus(dev, i, &status); USB_DBG("port: %d status: %08X\n", i, status); if (status & 0x010000) { // Connect Status Change, has changed USB_TEST_ASSERT(status & 0x000001); ClearPortFeature(dev, C_PORT_CONNECTION, i); int lowSpeed = 0; if (status & 0x0200) { lowSpeed = 1; } PortReset(dev, i); if (!addDevice(dev, i, lowSpeed)) { ClearPortPower(dev, i); // power off } } else { ClearPortPower(dev, i); // power off } } return false; } int USBHost::SetPortPower(USBDeviceConnected* dev, int port) { return SetPortFeature(dev, PORT_POWER, port); } int USBHost::ClearPortPower(USBDeviceConnected* dev, int port) { return ClearPortFeature(dev, PORT_POWER, port); } int USBHost::SetPortFeature(USBDeviceConnected* dev, int feature, int index) { return controlWrite(dev, 0x23, SET_FEATURE,feature,index,0,0); } int USBHost::ClearPortFeature(USBDeviceConnected* dev, int feature, int index) { return controlWrite(dev, 0x23, CLEAR_FEATURE,feature,index,0,0); } int USBHost::SetPortReset(USBDeviceConnected* dev, int port) { return SetPortFeature(dev, PORT_RESET, port); } int USBHost::GetPortStatus(USBDeviceConnected* dev, int port, uint32_t* status) { return controlRead(dev, 0xa3, GET_STATUS, 0, port, (uint8_t*)status, 4); } int USBHost::PortReset(USBDeviceConnected* dev, int port) { USB_DBG("%p port=%d\n", this, port); USB_TEST_ASSERT(port >= 1); SetPortReset(dev, port); // wait reset for(int i = 0; i < 100; i++) { uint32_t status; GetPortStatus(dev, port, &status); USB_DBG("RESET port: %d status: %08X\n", port, status); if (status & 0x100000) { // Reset change , Reset complete return USB_TYPE_OK; } wait_ms(5); } return USB_TYPE_ERROR; }