You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unit testing with unity fails on Windows because of Serial.end #5359
I've been using the Unity framework for testing code for the RP2040 MCU on Arduino, however I have run into an issue with tests completing cleanly. I've narrowed this down to the call to Serial.end() in void unityOutputComplete(void) { Serial.end(); } [platformio/test/runners/unity.py] which then gets compiled into unity_config.cpp
This causes:
Final test results to not always come through
A permission denied error (due to closed serial port)
Prevents the MCU from software reboots (because the serial is not running), and thus requires manual intervention to run subsequent tests.
I want to know if Serial.end() is necessary here at all? Is there any downside to leaving the Serial running at the end of the test (for Arudino this will sit in loop(), which is normal behavior).
Similar with ESP32-C6 with Arduino HWCDC (ARDUINO_USB_CDC_ON_BOOT=1).
Serial.end() in the generated unity_config.cpp calls HWCDC::end() → HWCDC::deinit(), which pulls USB D+/D- low and fully de-enumerates the device. After the test finishes the board is gone from /dev/ttyACM*, and even after a reset the bootloader's USB CDC stays up for only ~2 seconds - which makes re-flashing more difficult.
Activity
maxgerhardt commentedon Jan 18, 2026
Just FYI, the default Arduino implementation of the Unity handlers are in
platformio-core/platformio/test/runners/unity.py
Lines 126 to 130 in d6141b3
And you can always supply your own ones that don't do this:
https://docs.platformio.org/en/latest/advanced/unit-testing/frameworks/unity.html#custom-unity-config-h
https://github.com/platformio/platformio-examples/tree/develop/unit-testing/stm32cube/test
dzid26 commentedon Apr 13, 2026
Similar with ESP32-C6 with Arduino HWCDC (
ARDUINO_USB_CDC_ON_BOOT=1).Serial.end() in the generated unity_config.cpp calls HWCDC::end() → HWCDC::deinit(), which pulls USB D+/D- low and fully de-enumerates the device. After the test finishes the board is gone from /dev/ttyACM*, and even after a reset the bootloader's USB CDC stays up for only ~2 seconds - which makes re-flashing more difficult.
Resolved an issue where Unit Testing failed on Windows due to imprope…
ivankravets commentedon Apr 14, 2026
Thanks for the report. Please re-test with
pio upgrade --dev.aaronfultonnz commentedon Apr 21, 2026
Thanks for the fix! I can confirm that this works a treat.
pio 6.2.0
build(scripts): Bump the python group with 4 updates (#2)