Fix SPI bus contention crash on serial game upload
Serial uploader was crashing the Pico when launching games because it accessed SD card (SPI) while Core 1 was refreshing display (also SPI). Display and SD card share the same SPI bus and cannot be accessed simultaneously. Split game launch into prepare and execute phases: - prepare: Re-scan games directory (safe, SD access done immediately) - execute: Load Lua script from SD (deferred until display is idle) Main loop now checks !is_refresh_in_progress() before completing launch, preventing SPI conflicts. Also updated SD card best practices skill to document SPI bus contention as the #1 most critical issue to avoid. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -153,7 +153,10 @@ void SerialUploader::launch_game() {
|
||||
// Note: LuaGameLoader::register_all_games handles SPI speed internally
|
||||
int new_games = LuaGameLoader::register_all_games(game_launcher);
|
||||
printf("Found %d Lua games after re-scan\n", new_games);
|
||||
}
|
||||
|
||||
bool SerialUploader::complete_launch() {
|
||||
// This should only be called when it's safe (no display refresh in progress)
|
||||
// Now try to launch the newly uploaded game by name
|
||||
printf("Attempting to launch game: %s\n", last_uploaded_name);
|
||||
bool launched = game_launcher->select_game_by_name(last_uploaded_name);
|
||||
@@ -163,6 +166,11 @@ void SerialUploader::launch_game() {
|
||||
} else {
|
||||
printf("ERROR Failed to launch game: %s\n", last_uploaded_name);
|
||||
}
|
||||
|
||||
// Reset state back to IDLE
|
||||
reset();
|
||||
|
||||
return launched;
|
||||
}
|
||||
|
||||
bool SerialUploader::process() {
|
||||
@@ -305,6 +313,8 @@ bool SerialUploader::process() {
|
||||
if (state == WRITING_FILE) {
|
||||
if (write_file_to_sd()) {
|
||||
state = LAUNCHING_GAME;
|
||||
// Prepare for launch by scanning games, but don't actually launch yet
|
||||
launch_game();
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
@@ -312,9 +322,8 @@ bool SerialUploader::process() {
|
||||
}
|
||||
|
||||
if (state == LAUNCHING_GAME) {
|
||||
launch_game();
|
||||
reset();
|
||||
return true; // Signal that game was launched
|
||||
// Stay in this state until main loop calls complete_launch() when safe
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user