Page 1 of 1

How to add a debug print

Posted: Wed Sep 22, 2021 9:08 pm
by volkerjaenisch
Dear Micropython Developers!

ATM I use the following code to write debug output to the console:

Code: Select all

STATIC mp_obj_t mono_horiz_get_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
    /*
        Return the raw bytes of a rectangle given by its x ,y ,w ,h definition.
        Caution! Bytes overlapping the left/right border will transferred completely.
        The rectangle will be returned in the same order the buffer is aligned.
    */

   mp_printf(&mp_plat_print,"get_rect=%d %d %d %d\n", x, y, w, h);

This is surely not the best way!
Is there a way to do it controlled by a micropython-DEBUG switch.

Any help appreciated,
Volker

Re: How to add a debug print

Posted: Thu Sep 23, 2021 6:13 am
by stijn
Typical way is using DEBUG_printf and eventually mp_obj_print_helper(MICROPY_DEBUG_PRINTER, ...), guarded by e.g. MICROPY_DEBUG_VERBOSE. There are many examples in various source files in core/extmod/...

But what's the purpose? If it's just for debugging your own code it doesn't really matter (though DEBUG_printf is still shorter to write).