1.5.1.3 Step 3. Verify Serial Output with MDB Script and the Simulator

You should verify that your serial output and printf works as expected before continuing with Unity.

Step 3.A – Test printf from main.c

The setup will differ from selected device and how printf was setup.

The following main.c example assumes that the device is ATtiny817 and that a configured USART is generated by MCC in the mcc_generated_files sub folder:

#define F_CPU 1000000UL

#include "mcc_generated_files/mcc.h"
#include <util/delay.h>

int main(void)
{
    // Initialize drivers from MCC
    SYSTEM_Initialize();
    _delay_ms(1000);
 
    printf("Hello world!\n");
}

Step 3.B – Create Simulator MDB Script

Create an MDB script that runs your program locally on the simulator and logs your serial communication to a local file.

An example of mdb.script using ATTiny817 is:

Note: You will need to modify the path to your elf file.
# Set tool and device
device ATtiny817
hwtool SIM

# Write serial communication from usart0 to file.
set usart0io.uartioenabled true
set usart0io.output file
set usart0io.outputfile ./sercom_output.txt

# Program and run your binary file
program ./dist/[INSERT_YOUR_BINARY_FILE_PATH_HERE].elf

run
# Wait 10 seconds before exiting
wait 10000
halt
quit

Step 3.C – Run MDB Script and Verify Output

Make sure that your project is built, then open a command line and navigate to your project. Run mdb.sh or mdb.bat with your mdb script as argument.

Here is an example:

me@mypc:/project_with_unittests.X$ "/opt/microchip/mplabx/6.00/mplab_platform/bin/mdb.bat" mdb.sh

device ATtiny817

hwtool SIM

Resetting SFRs
Resetting peripherals

set usart0io.uartioenabled true
set usart0io.output file
set usart0io.outputfile ./sercom_output.txt

program /project_with_unittests.X/dist/default/production/project_with_unittests.X.production.elf
Programming target...
Resetting SFRs
Resetting peripherals
Program succeeded.

run
Running

wait 10000
halt
Simulator halted
quit

If you now open sercom_output.txt you should get the output:

Hello world!