My stm32 board uses the USB interface of the MCU to implement a serial over USB connection to the host, and with the -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC, -D USBCON, build flags I indeed see a com port on my PC and the program output (good).
However, when I try to run a unit test, the loaded binary doesn’t include the serial over USB functionality, I don’t see a com port on my PC, and platformio can’t get the results from the tested device.
Is there a way to cause the unit test binary to include also the serial over USB functionality?
platformio.ini
[env:stm32]
build_type = debug
debug_init_break = tbreak setup
platform = ststm32
board = genericSTM32F401CD
framework = arduino
debug_tool = stlink
upload_protocol = stlink
debug_build_flags = -O0 -ggdb3 -g3
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-Werror
-fmax-errors=3
-D SERIAL_TX_BUFFER_SIZE=4096
-D SERIAL_RX_BUFFER_SIZE=4096
Unit test (empty)
#include <unity.h>
void setUp(void) {
// set stuff up here
}
void tearDown(void) {
// clean stuff up here
}
int main( int argc, char **argv) {
UNITY_BEGIN();
UNITY_END();
}
Test log:
* Executing task: C:\Users\user\.platformio\penv\Scripts\platformio.exe run --target upload
Processing stm32 (platform: ststm32; board: genericSTM32F401CD; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F401CD.html
PLATFORM: ST STM32 (15.6.0) > STM32F401CD (96k RAM. 384k Flash)
HARDWARE: STM32F401CDU6 84MHz, 96KB RAM, 384KB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES:
- framework-arduinoststm32 @ 4.20400.0 (2.4.0)
- framework-cmsis @ 2.50700.210515 (5.7.0)
- tool-dfuutil @ 1.11.0
- tool-openocd @ 2.1100.211028 (11.0)
- tool-stm32duino @ 1.0.2
- toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 13 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Compiling .pio\build\stm32\src\main.cpp.o
Compiling .pio\build\stm32\src\packet_encoder.cpp.o
Linking .pio\build\stm32\firmware.elf
Checking size .pio\build\stm32\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 14.0% (used 13800 bytes from 98304 bytes)
Flash: [= ] 14.8% (used 58204 bytes from 393216 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, dfu, jlink, serial, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\stm32\firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
debug_level: 1
hla_swd
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0800606c msp: 0x20018000
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
================================================================ [SUCCESS] Took 14.40 seconds ================================================================ * Terminal will be reused by tasks, press any key to close it.