From 2cbabd86d8dc6b118d8f814f4c5794e426ea4136 Mon Sep 17 00:00:00 2001 From: Winford Date: Sat, 17 Feb 2024 16:43:22 -0800 Subject: [PATCH] Make rp2040 wait for usb serial timeout configurable Adds Pico `cmake` configuration option `AVM_USB_WAIT_SECONDS` to set a timeout to wait for USB serial connection before starting the application. This is set to 20 seconds by default, and can be changed by supplying the cmake option: -DAVM_USB_WAIT_SECONDS={seconds-to-wait} This setting is overridden if `AVM_WAIT_FOR_USB_CONNECT=on` is used, which will wait forever for a USB console connection before starting the application. This allows testing `blinky` and network applications without requiring opening a console connection to the device, while still waiting a reasonable ammount of time for the user to make a console connection to the serial to see the output of applications like `hello_world`. Signed-off-by: Winford --- CHANGELOG.md | 1 + src/platforms/rp2040/src/CMakeLists.txt | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d6b238f8..2718392d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `binary_to_atom/1` and `atom_to_binary/1` that default to utf8 (they were introduced with OTP23) - Added Pico cmake option `AVM_WAIT_BOOTSEL_ON_EXIT` (default `ON`) to allow tools to use automated `BOOTSEL` mode after main application exits - Use UTF-8 encoding for atoms when using `erlang:term_to_binary/1`, in conformance with OTP-26 +- Pico: Wait for USB serial connection `cmake` configuration option `AVM_USB_WAIT_SECONDS` added with 20 second default. ### Fixed diff --git a/src/platforms/rp2040/src/CMakeLists.txt b/src/platforms/rp2040/src/CMakeLists.txt index 9f4e913ec..94962fdf0 100644 --- a/src/platforms/rp2040/src/CMakeLists.txt +++ b/src/platforms/rp2040/src/CMakeLists.txt @@ -43,6 +43,12 @@ endif() if (AVM_WAIT_FOR_USB_CONNECT) target_compile_definitions(AtomVM PRIVATE PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=-1) +elseif (AVM_USB_WAIT_SECONDS) + math(EXPR WAIT_FOR_USB_TIMEOUT "1000 * ${AVM_USB_WAIT_SECONDS}") + message(STATUS "Wait for USB serial connection timeout ${WAIT_FOR_USB_TIMEOUT} ms") + target_compile_definitions(AtomVM PRIVATE PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=${WAIT_FOR_USB_TIMEOUT}) +else() + target_compile_definitions(AtomVM PRIVATE PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=20000) endif() if (AVM_WAIT_BOOTSEL_ON_EXIT)