No output in pio CLI when unit testing

Hey folks, I’m pulling my hair out trying to figure this out. I must be missing something basic.

I have an Adafruit Feather M0 Adalogger board connected to my computer (MacOS) via its built-in microUSB port. No other wires or devices are connected to the Arduino.

I have platformio installed on my computer via brew, available as the pio command. I edit the code in CLion, but run pio-related commands in the terminal.

I created an empty platformio project and a test/test_main.cpp file with a simple blink test, file contents the same as here, verbatim (yes, it has the 2 second delay).

My platformio.ini file content is:

[env:adafruit_feather_m0]
platform = atmelsam
board = adafruit_feather_m0
framework = arduino
upload_port = /dev/cu.usbmodem146101

When I run pio test -v, it uploads and executes the test_main.cpp program (I can tell by the LED blinking five times with the right delays), however it does not print the test output, it is stuck on:

Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)

(See full log at the bottom of the post)

Pressing the reset button on the board executes the program again, but the pio command does not write any output.

On the other hand, if I press the reset button on the board and then open a separate serial monitor, it will print out the raw messages:

$ pio device monitor -p /dev/cu.usbmodem146101
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at <link to pio-monitor-filters>
--- Miniterm on /dev/cu.usbmodem146101  9600,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
test/test_main.cpp:26:test_led_builtin_pin_number:PASS
test/test_main.cpp:37:test_led_state_high:PASS
test/test_main.cpp:39:test_led_state_low:PASS
test/test_main.cpp:37:test_led_state_high:PASS
test/test_main.cpp:39:test_led_state_low:PASS
test/test_main.cpp:37:test_led_state_high:PASS
test/test_main.cpp:39:test_led_state_low:PASS
test/test_main.cpp:37:test_led_state_high:PASS
test/test_main.cpp:39:test_led_state_low:PASS
test/test_main.cpp:37:test_led_state_high:PASS
test/test_main.cpp:39:test_led_state_low:PASS

-----------------------
11 Tests 0 Failures 0 Ignored
OK

So, the output is there, but the pio test command is not picking it up. I have no idea why.

What I tried:

  • Waiting 10 seconds, resetting the board (see above)

  • Increasing the delay in setup() to more than 2 seconds – no effect

  • Adding test_speed = 9600 to platformio.ini, and putting Serial.begin(9600) as the first line in void setup() (before the delay) – no effect

  • Adding test_port = /dev/tty.usbmodem146101 to platformio.ini – in this case the test command says it can’t open port:

    Testing...
    If you don't see any output for the first 10 secs, please reset board (press reset button)
    
    [Errno 2] could not open port /dev/tty.usbmodem146101: [Errno 2] No such file or directory: '/dev/tty.usbmodem146101'
    
  • Similar error if I set test_port = /dev/cu.usbmodem146101. I don’t know what test_port is supposed to be, or how to find it out.

  • Calling pio test -v with --monitor-rts 0 --monitor-dtr 0 params (but also (0, 1), (1, 0), and (1, 1) combinations) – no effect.

Note:

  • When I press the reset button on my board, the /dev/cu.usbmodem146101 device becomes temporarily unavailable, and the pio device monitor -p /dev/cu.usbmodem146101 command crashes with a python error: OSError: [Errno 6] Device not configured. I assume this is expected.

  • After I Ctrl+C out of the pio test -v command when it gets stuck, the uploads to this board always fail with the following “no device found on ” error:

    Forcing reset using 1200bps open/close on port /dev/cu.usbmodem146101
    Waiting for the new upload port...
    bossac --info --debug --port "cu.usbmodem146101" --write --verify --reset --erase -U true .pio/build/adafruit_feather_m0/firmware.bin
    No device found on cu.usbmodem146101
    Set binary mode
    Send auto-baud
    Set binary mode
    *** [upload] Error 1
    =========================================== [FAILED] Took 11.32 seconds ===========================================
    
    Test    Environment          Status    Duration
    ------  -------------------  --------  ------------
    *       adafruit_feather_m0  FAILED    00:00:11.318
    ====================================== 1 failed, 0 succeeded in 00:00:11.318 ======================================
    
  • The upload error goes away eventually after I press the reset button on the board enough times. I can never tell if I need to press it once or double-press it, that part doesn’t make sense to me.

  • In pio device list, my /dev/cu.usbmodem146101 Feather M0 is third behind /dev/cu.Bluetooth-Incoming-Port and /dev/cu.usbmodemCHIDMK1, the latter being an Arduino Leonardo based keyboard. Just in case, I tried disconnecting the keyboard right after pressing “Enter” on pio test -v, but no effect.

So… I’m out of ideas. I’m just trying to do the most basic testing example. I looked through the docs and past threads on this issue, but didn’t see any solution that would work. Do I need some special hardware like J-Link? I don’t have it yet. Since the serial monitor does show the test results, I’m hoping this is just some kind of pio command misconfiguration.

Full log of pio test -v:

$ blink pio test -v
Collected 1 items

Processing * in adafruit_feather_m0 environment
--------------------------------------------------------------------------------------------------------------------
Building...
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_feather_m0.html
PLATFORM: Atmel SAM (6.3.1) > Adafruit Feather M0
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES:
 - framework-arduino-samd-adafruit 1.7.2
 - framework-cmsis 2.50400.181126 (5.4.0)
 - framework-cmsis-atmel 1.2.2
 - toolchain-gccarmnoneeabi 1.90301.200702 (9.3.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/adafruit_feather_m0/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  10.7% (used 3516 bytes from 32768 bytes)
Flash: [          ]   4.7% (used 12412 bytes from 262144 bytes)
.pio/build/adafruit_feather_m0/firmware.elf  :
section            size        addr
.text             12156        8192
.data               256   536870912
.bss               3260   536871168
.ARM.attributes      40           0
.comment             67           0
.debug_frame        692           0
Total             16471
Uploading...
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_feather_m0.html
PLATFORM: Atmel SAM (6.3.1) > Adafruit Feather M0
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES:
 - framework-arduino-samd-adafruit 1.7.2
 - framework-cmsis 2.50400.181126 (5.4.0)
 - framework-cmsis-atmel 1.2.2
 - tool-bossac 1.10700.190624 (1.7.0)
 - toolchain-gccarmnoneeabi 1.90301.200702 (9.3.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/adafruit_feather_m0/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  10.7% (used 3516 bytes from 32768 bytes)
Flash: [          ]   4.7% (used 12412 bytes from 262144 bytes)
.pio/build/adafruit_feather_m0/firmware.elf  :
section            size        addr
.text             12156        8192
.data               256   536870912
.bss               3260   536871168
.ARM.attributes      40           0
.comment             67           0
.debug_frame        692           0
Total             16471
<lambda>(["upload"], [".pio/build/adafruit_feather_m0/firmware.bin"])
AVAILABLE: atmel-ice, blackmagic, jlink, sam-ba
CURRENT: upload_protocol = sam-ba
BeforeUpload(["upload"], [".pio/build/adafruit_feather_m0/firmware.bin"])
Use manually specified: /dev/cu.usbmodem146101
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem146101
Waiting for the new upload port...
bossac --info --debug --port "cu.usbmodem146101" --write --verify --reset --erase -U true .pio/build/adafruit_feather_m0/firmware.bin
Set binary mode
readWord(addr=0)=0x20002de0
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
version()=v1.1 [Arduino:XYZ] Oct 27 2020 20:25:30
chipId=0x10010005
Connected at 921600 baud
readWord(addr=0)=0x20002de0
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Atmel SMART device 0x10010005 found
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x10)
writeWord(addr=0x20004020,value=0x20008000)
Device       : ATSAMD21G18A
readWord(addr=0)=0x20002de0
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Chip ID      : 10010005
version()=v1.1 [Arduino:XYZ] Oct 27 2020 20:25:30
Version      : v1.1 [Arduino:XYZ] Oct 27 2020 20:25:30
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security     : false
Boot Flash   : true
readWord(addr=0x40000834)=0x7000a
BOD          : true
readWord(addr=0x40000834)=0x7000a
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 0.849 seconds

Write 12412 bytes to flash (194 pages)
write(addr=0x20005000,size=0x1000)
writeBuffer(scr_addr=0x20005000, dst_addr=0x2000, size=0x1000)

[=========                     ] 32% (64/194 pages)write(addr=0x20005000,size=0x1000)
writeBuffer(scr_addr=0x20005000, dst_addr=0x3000, size=0x1000)

[===================           ] 65% (128/194 pages)write(addr=0x20005000,size=0x1000)
writeBuffer(scr_addr=0x20005000, dst_addr=0x4000, size=0x1000)

[============================= ] 98% (192/194 pages)write(addr=0x20005000,size=0x80)
writeBuffer(scr_addr=0x20005000, dst_addr=0x5000, size=0x80)

[==============================] 100% (194/194 pages)
done in 0.095 seconds

Verify 12412 bytes of flash with checksum.
checksumBuffer(start_addr=0x2000, size=0x1000) = e768
checksumBuffer(start_addr=0x3000, size=0x1000) = 8ad7
checksumBuffer(start_addr=0x4000, size=0x1000) = 620d
checksumBuffer(start_addr=0x5000, size=0x7c) = aa82
Verify successful
done in 0.034 seconds
CPU reset.
readWord(addr=0)=0x20002de0
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
writeWord(addr=0xe000ed0c,value=0x5fa0004)
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)

Exactly that is one half of the needed solution, the other half is Teensy 4.1 Unit Testing Issue - #5 by maxgerhardt.

1 Like

Awesome, thank you so much @maxgerhardt, your extra_scripts delay(5) + void setup() delay(5000) workaround in that linked comment was exactly what I needed. I’m getting proper test output via the pio test command now.