From 032c17dd00dfcc49925afb66e8e622fef0ceb911 Mon Sep 17 00:00:00 2001 From: lowfatcode Date: Sun, 24 Jan 2021 21:14:44 +0000 Subject: [PATCH] temporary fix to avoid micropython locking up on subsequent runs with unicorn (#22) Co-authored-by: Jonathan Williamson --- libraries/pico_unicorn/pico_unicorn.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/pico_unicorn/pico_unicorn.cpp b/libraries/pico_unicorn/pico_unicorn.cpp index 563f09f8..f2c79821 100644 --- a/libraries/pico_unicorn/pico_unicorn.cpp +++ b/libraries/pico_unicorn/pico_unicorn.cpp @@ -198,6 +198,14 @@ namespace pimoroni { gpio_set_function(pin::X, GPIO_FUNC_SIO); gpio_set_dir(pin::X, GPIO_IN); gpio_pull_up(pin::X); gpio_set_function(pin::Y, GPIO_FUNC_SIO); gpio_set_dir(pin::Y, GPIO_IN); gpio_pull_up(pin::Y); + // todo: shouldn't need to do this if things were cleaned up properly but without + // this any attempt to run a micropython script twice will fail + static bool already_init = false; + + if(already_init) { + return; + } + // setup dma transfer for pixel data to the pio dma_channel = dma_claim_unused_channel(true); dma_channel_config config = dma_channel_get_default_config(dma_channel); @@ -212,6 +220,8 @@ namespace pimoroni { dma_channel_set_trans_count(dma_channel, BITSTREAM_LENGTH / 4, false); dma_channel_set_read_addr(dma_channel, bitstream, true); + + already_init = true; } void PicoUnicorn::clear() {