ramapcsx2 / gbs-control

GNU General Public License v3.0
773 stars 110 forks source link

Properly apply Bypass video mode from custom preset #418

Closed nyanpasu64 closed 1 year ago

nyanpasu64 commented 1 year ago

Fixes:

draft. applies on top of PR #415 (not yet merged), so the github diff view includes irrelevant changes. will be rebased once that's merged.

todo:

Fixes #416.

nyanpasu64 commented 1 year ago

saving presets can lead to flash write corruption:

gbs-control preset overflow

corruption is usually (possibly always?) seen after the ESP hangs and the hardware watchdog reboots it. sometimes the hardware watchdog reboots the ESP but the flash appears intact afterwards.

was it caused by reading chip registers while performing flash operations? no, we call GBS::GBS_PRESET_ID::read() before SPIFFS.open(SLOTS_FILE, "w").

nyanpasu64 commented 1 year ago

read corruption after saving a preset:

Screenshot_20230222_030406

refreshing the page fixes the contents read from the slots file. usually the web UI automatically reloads the slot list with the correct list a split-second later. this time it didn't, so I was able to take a screenshot.

I was able to reproduce flash corruption on master c4babdd49da0a7d299b3e246d89fb9bb9a5efaaa.

I now think flash corruption is not caused by the changes made in this PR, but instead caused by https://github.com/me-no-dev/ESPAsyncWebServer/issues/204:

the corruption problems seem to have disappeared after I moved the web pages in the firmware image (which is a nice feature of EspAsyncWebServer). In other words, the webserver is not using SPIFFS for static web content anymore. The flash file system is only accessed by the "server.on" functions to read log data and output it in JSON. The same data is also accessed by the logging functions in the main loop, but concurrent access is avoided by means of synchronisation flags. This was not possible when the web pages were loaded from SPIFFS, because the webserver accessed them asynchronously and there was no way to synchronise access with flags.

sounds like it's illegal to even access different SPIFFS files concurrently, if you don't manually lock the filesystem. that would explain the separate write and read corruption modes I've observed.

options:

nyanpasu64 commented 1 year ago

marking as draft. you can't yield in a http callback. and reading registers over i2c yields.

fuck AsyncWebServer.

nyanpasu64 commented 1 year ago

apparently Bypass (both directly applied and from a preset) generates EMI that interferes with WiFi channel 11 communications. This is unrelated to this PR, but makes testing trickier.