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:
@@ -49,7 +49,7 @@ function init()
|
||||
game.vars.won = false
|
||||
|
||||
-- Enable continuous updates
|
||||
game.set_frame_updates(true)
|
||||
-- game.set_frame_updates(true)
|
||||
|
||||
print("2048 initialized")
|
||||
end
|
||||
@@ -124,7 +124,7 @@ function draw()
|
||||
if state == STATE_MENU then
|
||||
renderer.text_scaled(game.width() / 2 - 15, game.height() / 2 - 30, "2048", true, 2)
|
||||
renderer.text_scaled(game.width() / 2 - 50, game.height() / 2, "Tap to Start", true, 2)
|
||||
renderer.text_scaled(game.width() / 2 - 50, game.height() / 2 + 30, "Welcome Adolfo2!", true, 2)
|
||||
renderer.text_scaled(game.width() / 2 - 50, game.height() / 2 + 30, "Welcome Adolfo", true, 2)
|
||||
|
||||
elseif state == STATE_PLAYING or state == STATE_WIN or state == STATE_GAME_OVER then
|
||||
-- Draw grid
|
||||
@@ -159,10 +159,10 @@ function draw()
|
||||
|
||||
-- Draw value (simplified)
|
||||
local text = tostring(value)
|
||||
if string.len(text) <= 2 then
|
||||
renderer.text_scaled(tile_x + tile_size / 2 - 4, tile_y + tile_size / 2 - 4, text, false, 2)
|
||||
if string.len(text) < 2 then
|
||||
renderer.text_scaled(tile_x + tile_size / 2 - 4, tile_y + tile_size / 2 - 8, text, false, 2)
|
||||
else
|
||||
renderer.text_scaled(tile_x + tile_size / 2 - 8, tile_y + tile_size / 2 - 4, text, false, 2)
|
||||
renderer.text_scaled(tile_x + tile_size / 2 - 12, tile_y + tile_size / 2 - 8, text, false, 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user