Unity_config include directory

I am trying to setup unit testing for an STM32 project, and I need to use a custom unity_config file to make it work. I need to include my usart.h file so I can setup the USART without having to copy and paste a lot of code, but when I run test I keep getting the same errors:

.pio/build/disco_f072rb/test/unity_config.o: In function `unityOutputStart':
unity_config.c:(.text.unityOutputStart+0x2): undefined reference to `MX_USART3_Init'
.pio/build/disco_f072rb/test/unity_config.o: In function `unityOutputChar':
unity_config.c:(.text.unityOutputChar+0x18): undefined reference to `husart3'
.pio/build/disco_f072rb/test/unity_config.o: In function `unityOutputFlush':
unity_config.c:(.text.unityOutputFlush+0x4): undefined reference to `HAL_USART_FlushRxFifo'
unity_config.c:(.text.unityOutputFlush+0xc): undefined reference to `husart3'

Here are my config files. Note that unity_config.h is unchanged from the example in the documentation and is included here for completeness only. Also note that I have tried both the relative path to usart.h as shown here, as well as just the name assuming the correct include directory the way I would do typically. Neither has worked.

unity_config.h

#ifndef UNITY_CONFIG_H

#define UNITY_CONFIG_H

#ifndef NULL

#ifndef __cplusplus

#define NULL (void*)0

#else

#define NULL 0

#endif

#endif

#ifdef __cplusplus

extern "C"

{

#endif

void unityOutputStart();

void unityOutputChar(char);

void unityOutputFlush();

void unityOutputComplete();

#define UNITY_OUTPUT_START() unityOutputStart()

#define UNITY_OUTPUT_CHAR(c) unityOutputChar(c)

#define UNITY_OUTPUT_FLUSH() unityOutputFlush()

#define UNITY_OUTPUT_COMPLETE() unityOutputComplete()

#ifdef __cplusplus

}

#endif /* extern "C" */

#endif /* UNITY_CONFIG_H */

unity_config.c

#include "unity_config.h"
#include "../Inc/usart.h"
void unityOutputStart() {
    MX_USART3_Init();
}
void unityOutputChar(char c) {
    HAL_USART_Transmit(&husart3, (uint8_t*)&c, 1, 0xFFFF);
}
void unityOutputFlush() {
    HAL_USART_FlushRxFifo(&husart3);
}
void unityOutputComplete() {}

Well where is that function implemented? In src/? Files in src/ are by default not build when unit testing (pio test). There is a reason why the official reference directly calls the HAL_ functions.

1 Like

Yeah I was hoping that there was a way to include it. It’s fine though, I just copied the appropriate functions from my references in the src directory and it works fine.

There is test_build_src but then you would have to make sure that everything else in your application but that code is deactivated.