No Unity output from SAMD21 with SerialUSB


Serial on my SAMD21 (Sodaq One) is hardware and the main console is SerialUSB

As such, pio test with unity just hangs with no output. (it is running, as I can blink in setup etc)

I’ve tried to create alternate implementations to drive the serial port output (for example)

#include "unity_config.h"

void unityOutputStart()

But This won’t compile:

test/unity_config.c: In function 'unityOutputStart':
test/unity_config.c:7:5: error: 'SerialUSB' undeclared (first use in this function)

It seems like the board variant (or something, I’m guessing at terminology here) isn’t brought into the test sources.

Thanks for any pointers

SerialUSB is a C++ object. You can’t directly access that from a .c file. You should rename it to unity_config.cpp and give all wanted Unity C functions their C name linkage with

extern "C" void unityOutputStart() {

Note that redefining unityOutputStart() alone is not sufficient, ther are still read, flush, end functions etc to implement (the last of which should be a NOP so that the USB port doesn’t disappear)

Thank you for the great advice.

Firstly, yes I appreicate all the wanted untity functions - I ommitted the rest for brevity.

May I ask for another pointer?

After your suggestion of renaming to unity_config.cpp and adding the C linkage name, I get:

test/unity_config.cpp: In function 'void unityOutputStart()':
test/unity_config.cpp:5:18: error: conflicting declaration of 'void unityOutputStart()' with 'C' linkage
 extern "C"  void unityOutputStart()
In file included from test/unity_config.cpp:3:0:
test/unity_config.h:231:6: note: previous declaration with 'C++' linkage
 void unityOutputStart();

Otherwise, If I drop the C linkage name from the cpp implemntation, I get what I think are linker errors:

.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o): In function `UnityPrintNumberUnsigned':
unity.c:(.text.UnityPrintNumberUnsigned+0x28): undefined reference to `unityOutputChar'
.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o): In function `UnityPrintNumber':
unity.c:(.text.UnityPrintNumber+0x8): undefined reference to `unityOutputChar'
.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o): In function `UnityPrintNumberHex':
unity.c:(.text.UnityPrintNumberHex+0x2c): undefined reference to `unityOutputChar'
.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o): In function `UnityPrint.part.0':
unity.c:(.text.UnityPrint.part.0+0x14): undefined reference to `unityOutputChar'
unity.c:(.text.UnityPrint.part.0+0x22): undefined reference to `unityOutputChar'
.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o):unity.c:(.text.UnityPrint.part.0+0x30): more undefined references to `unityOutputChar' follow
.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o): In function `UnityConcludeTest':
unity.c:(.text.UnityConcludeTest+0x1c): undefined reference to `unityOutputFlush'
.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o): In function `UnityFail':
unity.c:(.text.UnityFail+0x2e): undefined reference to `unityOutputChar'
unity.c:(.text.UnityFail+0x64): undefined reference to `unityOutputChar'
unity.c:(.text.UnityFail+0x72): undefined reference to `unityOutputFlush'
.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o): In function `UnityBegin':
unity.c:(.text.UnityBegin+0x1a): undefined reference to `unityOutputStart'
.pio/build/sodaq_one/liba57/libUnity.a(unity.c.o): In function `UnityEnd':
unity.c:(.text.UnityEnd+0x4): undefined reference to `unityOutputChar'
unity.c:(.text.UnityEnd+0x10): undefined reference to `unityOutputChar'
unity.c:(.text.UnityEnd+0x3c): undefined reference to `unityOutputChar'
unity.c:(.text.UnityEnd+0x50): undefined reference to `unityOutputChar'
unity.c:(.text.UnityEnd+0x54): undefined reference to `unityOutputFlush'
unity.c:(.text.UnityEnd+0x58): undefined reference to `unityOutputComplete'

I don’t have enough C++ experience to get this gonig so I’m grateful of your help.



Then that header file is missing an

#ifdef __cplusplus
extern "C" {

// all functions

#ifdef __cplusplus