This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Changing unity printf to Segger RTT

I'm wondering if anyone uses unity.c for unit testing and managed to change the print function to segger rtt in order to read the output.

According to unity

By default, Unity prints its results to `stdout` as it runs. This works
perfectly fine in most situations where you are using a native compiler for
testing. It works on some simulators as well so long as they have `stdout`
routed back to the command line. There are times, however, where the simulator
will lack support for dumping results or you will want to route results
elsewhere for other reasons. In these cases, you should define the
`UNITY_OUTPUT_CHAR` macro. This macro accepts a single character at a time (as
an `int`, since this is the parameter type of the standard C `putchar` function
most commonly used). You may replace this with whatever function call you like.

    * Output*     - by default, Unity prints to standard out with putchar.  define UNITY_OUTPUT_CHAR(a) with a different function if desired
     
    /*-------------------------------------------------------
     * Output Method: stdout (DEFAULT)
     *-------------------------------------------------------*/
    #ifndef UNITY_OUTPUT_CHAR
    /* Default to using putchar, which is defined in stdio.h */
    #include <stdio.h>
    #define UNITY_OUTPUT_CHAR(a) (void)putchar(a)
    #else
      /* If defined as something else, make sure we declare it here so it's ready for use */
      #ifndef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION
    extern void UNITY_OUTPUT_CHAR(int);
      #endif
    #endif

I tried to define

#define UNITY_OUTPUT_CHAR(a) SEGGER_RTT_WriteString(0, a)

However i get the following

> $ make rm -rf _build echo  Makefile
> Makefile mkdir _build Compiling file:
> system_nrf51.c Compiling file: main.c
> C:/NXTSNS/nRF5_SDK_11.0.0_89a8197/examples/peripheral/blinky/main.c:31:53:
> error: expected declaration specifiers
> or '...' before numeric constant 
> #define UNITY_OUTPUT_CHAR(a) SEGGER_RTT_WriteString(0, a)
>                                                      ^
> C:/NXTSNS/Unittesting/unity/src/unity_internals.h:250:13:
> note: in expansion of macro
> 'UNITY_OUTPUT_CHAR'  extern void
> UNITY_OUTPUT_CHAR(int);
>              ^ Makefile:150: recipe for target '_build/main.o' failed
> make: *** [_build/main.o] Error 1

How should i define the macro such that i can send the output to segger or if there is a more suitable alternative what is it?

Parents
  • Hi,

    in nRF5 SDK team we are using Unity test framework to execute on target unit tests. We use UART to flush test report. Test cases are well isolated because each test case is separated by software reset. Pin reset triggers start of the suite. I have uploaded and example which is based on nRF5 SDK 13.0.0.

    See the readme.txt in the zip. It contains short 'howto'.

    test_example.zip

  • As I am using an NRF51822 XXAC board with PCA10028 i had to perform some modifications to the makefile/code in order to run the example. However after performing the modifications i could not see any output on Putty. Below is a list of the modiciations/changes performed, perhaps i missed something:

    1- changed the following flags (in both C Flags, ASM Flags & LD Flags) from mfloat-abi=hard -mfpu=fpv4-sp-d16 to mfloat-abi=soft from -mcpu=cortex-m4 to -mcpu=cortex-m0 from NRF52 to NRF51 from NF52832_XXAA to NRF51822 from BOARD_PCA10040 to BOARD_PCA10028

    2- Delete the NRF52_PANXX flags

    3- Changed the debug pin in app_test_runner.c from pin 27 to pin 7 which corresponds to the SCL pin on the PCA10028 board

    4- changed the test_example_gcc_nrf52.ld file to test_example_gcc_nrf51.ld (copied the values from the blinky example of SDK11 for PCA10028)

    Im running the code using the instructions in the readme file however unfortunately nothing is printing to Putty at a baudrate of 115200.

    I am running the code using SDK13.1 which is the same one used in initial example, I want to get it working there before i migrate it back to SDK 11.

    Can anyone spot where im going wrong/ why i cant see any output on Putty

Reply
  • As I am using an NRF51822 XXAC board with PCA10028 i had to perform some modifications to the makefile/code in order to run the example. However after performing the modifications i could not see any output on Putty. Below is a list of the modiciations/changes performed, perhaps i missed something:

    1- changed the following flags (in both C Flags, ASM Flags & LD Flags) from mfloat-abi=hard -mfpu=fpv4-sp-d16 to mfloat-abi=soft from -mcpu=cortex-m4 to -mcpu=cortex-m0 from NRF52 to NRF51 from NF52832_XXAA to NRF51822 from BOARD_PCA10040 to BOARD_PCA10028

    2- Delete the NRF52_PANXX flags

    3- Changed the debug pin in app_test_runner.c from pin 27 to pin 7 which corresponds to the SCL pin on the PCA10028 board

    4- changed the test_example_gcc_nrf52.ld file to test_example_gcc_nrf51.ld (copied the values from the blinky example of SDK11 for PCA10028)

    Im running the code using the instructions in the readme file however unfortunately nothing is printing to Putty at a baudrate of 115200.

    I am running the code using SDK13.1 which is the same one used in initial example, I want to get it working there before i migrate it back to SDK 11.

    Can anyone spot where im going wrong/ why i cant see any output on Putty

Children
No Data
Related