adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.09k stars 1.21k forks source link

Unable to build picow with `-DMICROPY_DEBUG_PRINTERS=1` #7080

Closed justbuchanan closed 1 year ago

justbuchanan commented 1 year ago

CircuitPython version

Current `main` branch as of 10/17/2022. https://github.com/adafruit/circuitpython/commit/6e350a65cf6fa625aa4f2f213ad4e733dffc85f7

Code/REPL

This works: `make BOARD=raspberry_pi_pico_w`

This doesn't: `make BOARD=raspberry_pi_pico_w CFLAGS=-DMICROPY_DEBUG_PRINTERS=1`

Behavior

Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
../../extmod/ulab/code/numpy/poly.c:15:10: fatal error: py/obj.h: No such file or directory
   15 | #include "py/obj.h"
      |          ^~~~~~~~~~
compilation terminated.
../../extmod/ulab/code/scipy/signal/signal.c:17:10: fatal error: py/runtime.h: No such file or directory
   17 | #include "py/runtime.h"
      |          ^~~~~~~~~~~~~~
../../extmod/ulab/code/scipy/scipy.c:16:10: fatal error: py/runtime.h: No such file or directory
   16 | #include "py/runtime.h"
      |          ^~~~~~~~~~~~~~
compilation terminated.
../../extmod/ulab/code/scipy/special/special.c:16:10: fatal error: py/runtime.h: No such file or directory
   16 | #include "py/runtime.h"
      |          ^~~~~~~~~~~~~~
compilation terminated.
compilation terminated.
Command '['arm-none-eabi-gcc', '-E', '-DNO_QSTR', '-x', 'c', '-Ibuild-raspberry_pi_pico_w/tmp', '-DMICROPY_DEBUG_PRINTERS=1', '../../extmod/ulab/code/numpy/poly.c']' returned non-zero exit status 1.
../../extmod/ulab/code/scipy/optimize/optimize.c:16:10: fatal error: py/obj.h: No such file or directory
   16 | #include "py/obj.h"
      |          ^~~~~~~~~~
compilation terminated.
../../extmod/ulab/code/scipy/linalg/linalg.c:16:10: fatal error: py/obj.h: No such file or directory
   16 | #include "py/obj.h"
      |          ^~~~~~~~~~
../../extmod/ulab/code/user/user.c:15:10: fatal error: py/obj.h: No such file or directory
   15 | #include "py/obj.h"
      |          ^~~~~~~~~~
compilation terminated.

(there's more, but I truncated the output)

Description

No response

Additional information

Is this the correct way to enable debug printing? I'm interested in debugging a wifi-related issue on the picow (I'm aware this is under active development) and would like to see the output of the various DEBUG_printf() calls.

jepler commented 1 year ago

I mostly enable it on a file by file basis by manually making DEBUG_print be defined appropriately.

diff --git a/ports/raspberrypi/common-hal/socketpool/Socket.c b/ports/raspberrypi/common-hal/socketpool/Socket.c
index 37c37445de..1c73eb23e4 100644
--- a/ports/raspberrypi/common-hal/socketpool/Socket.c
+++ b/ports/raspberrypi/common-hal/socketpool/Socket.c
@@ -56,8 +56,8 @@

 #define MICROPY_PY_LWIP_SOCK_RAW (1)

-#if 0 // print debugging info
-#define DEBUG_printf DEBUG_printf
+#if 1 // print debugging info
+#define DEBUG_printf(...) mp_printf(&mp_plat_print, __VA_ARGS__)
 #else // don't print debugging info
 #define DEBUG_printf(...) (void)0
 #endif

I don't see any documentation from us or micropython on how to actually enable MICROPY_DEBUG_PRINTERS "correctly". This is one way that does at least build:

diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.h b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.h
index 58a291b18b..95304699ed 100644
--- a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.h
+++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.h
@@ -3,3 +3,6 @@

 #define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (1)
 #define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (1)
+
+#undef MICROPY_DEBUG_PRINTERS
+#define MICROPY_DEBUG_PRINTERS (1)
diff --git a/ports/raspberrypi/common-hal/socketpool/Socket.c b/ports/raspberrypi/common-hal/socketpool/Socket.c
index 37c37445de..479fed2f9e 100644
--- a/ports/raspberrypi/common-hal/socketpool/Socket.c
+++ b/ports/raspberrypi/common-hal/socketpool/Socket.c
@@ -56,7 +56,7 @@

 #define MICROPY_PY_LWIP_SOCK_RAW (1)

-#if 0 // print debugging info
+#if 1 // print debugging info
 #define DEBUG_printf DEBUG_printf
 #else // don't print debugging info
 #define DEBUG_printf(...) (void)0

If you find out more about how Micropython intends debug printers to "work" in terms of enabling them, I'd sure be happy to incorporate PRs that bring us closer to upstream.

justbuchanan commented 1 year ago

Thanks for the quick response! I'll give that a try.

dhalbert commented 1 year ago

Yes, don't use CFLAGS=... on the command line; that will probably mess up other uses of CFLAGS, which is used all over the place.