Printf | Developers

Printf

Estimated reading time: 3 minutes

Introduction

The firmware supports the PRINTF macro debugging feature, which is defined it in the Makefile.
DEFINES += HAVE_SPRINTF HAVE_PRINTF PRINTF=screen_printf

Usually, PRINTF is defined as void, with this line DEFINES += PRINTF\(...\)=.
Check if PRINTF is already defined somewhere in your Makefile, and if so, comment out this definition so it doesn’t override.

Important
The PRINTF macro is a debugging feature, it must not be used in production.
When compiling an application for release, please check that PRINTF is disabled in the Makefile:
insert the line DEFINES += PRINTF\(...\)= and comment out the other one.

Setup

The PRINTF macro triggers messages from the MCU to the host computer, through the USB link. The USBTool reads these messages and prints their payload in a terminal.

  1. Download USBTool
  2. Unzip the file and execute this command: ./usbtool -v 0x2c97 log

When you launch your app on your Nano, every PRINTF will be printed on the host computer, allowing you to debug your program more easily.

How to use

Important
The PRINTF macro can only be used in between successive calls to io_exchange. Calling it outside of io_exchange will result in unexpected behaviour. PRINTF sends a status on the SEPH . Only one status can be sent in a row, otherwise the SEPH crashes. For this reason, don't use PRINTF just after status-sending calls, such as UX_DISPLAY. This macro packs a call to io_seproxyhal_display and is often the reason for application crashes. The only solution is to move your call to PRINTF somewhere else in your code.

This macro can be used like a classical printf function in stdio.h. However, it is improved with a useful feature to easily print byte arrays:

uint8_t buffer[4] = {0xDE, 0xAD, 0xBE, 0xEF};

// PRINTF(string, array length, array);
// .*H for uppercase, .*h for lowercase
PRINTF("What a lovely buffer:\n %.*H \n\n", 4, buffer);
PRINTF("I prefer it lower-cased:\n %.*h \n", 4, buffer);
Result of the example code printed in a terminal
Result of the example code printed in a terminal

Did you find this page helpful?


How would you improve this page for developers?



Speculos emulator
PIN bypass
Getting Started
Theme Features
Customization

Embedded Apps