|
| 1 | +Debugging |
| 2 | +========= |
| 3 | + |
| 4 | +Introduction |
| 5 | +------------ |
| 6 | + |
| 7 | +Since 2.1.0-rc1 the core includes a Debugging feature that is |
| 8 | +controllable over the IDE menu. |
| 9 | + |
| 10 | +The new menu points manage the real-time Debug messages. |
| 11 | + |
| 12 | +Requirements |
| 13 | +~~~~~~~~~~~~ |
| 14 | + |
| 15 | +For usage of the debugging a Serial connection is required (Serial or |
| 16 | +Serial1). |
| 17 | + |
| 18 | +The Serial Interface need to be initialized in the ``setup()``. |
| 19 | + |
| 20 | +Set the Serial baud rate as high as possible for your Hardware setup. |
| 21 | + |
| 22 | +Minimum sketch to use debugging: |
| 23 | + |
| 24 | +.. code:: cpp |
| 25 | +
|
| 26 | + void setup() { |
| 27 | + Serial.begin(115200); |
| 28 | + } |
| 29 | +
|
| 30 | + void loop() { |
| 31 | + } |
| 32 | +
|
| 33 | +Usage |
| 34 | +~~~~~ |
| 35 | + |
| 36 | +1. Select the Serial interface for the Debugging messages: |Debug-Port| |
| 37 | + |
| 38 | +2. Select which type / level you want debug messages for: |Debug-Level| |
| 39 | + |
| 40 | +3. Check if the Serial interface is initialized in ``setup()`` (see |
| 41 | + `Requirements <#requirements>`__) |
| 42 | + |
| 43 | +4. Flash sketch |
| 44 | + |
| 45 | +5. Check the Serial Output |
| 46 | + |
| 47 | +Informations |
| 48 | +------------ |
| 49 | + |
| 50 | +It work with every sketch that enables the Serial interface that is |
| 51 | +selected as debug port. |
| 52 | + |
| 53 | +The Serial interface can still be used normal in the Sketch. |
| 54 | + |
| 55 | +The debug output is additional and will not disable any interface from |
| 56 | +usage in the sketch. |
| 57 | + |
| 58 | +For Developers |
| 59 | +~~~~~~~~~~~~~~ |
| 60 | + |
| 61 | +For the debug handling uses defines. |
| 62 | + |
| 63 | +The defined are set by command line. |
| 64 | + |
| 65 | +Debug Port |
| 66 | +^^^^^^^^^^ |
| 67 | + |
| 68 | +The port has the define ``DEBUG_ESP_PORT`` possible value: - Disabled: |
| 69 | +define not existing - Serial: Serial - Serial1: Serial1 |
| 70 | + |
| 71 | +Debug Level |
| 72 | +^^^^^^^^^^^ |
| 73 | + |
| 74 | +All defines for the different levels starts with ``DEBUG_ESP_`` |
| 75 | + |
| 76 | +a full list can be found here in the |
| 77 | +`boards.txt <https://github.com/esp8266/Arduino/blob/master/boards.txt#L180>`__ |
| 78 | + |
| 79 | +Example for own debug messages |
| 80 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 81 | + |
| 82 | +The debug messages will be only shown when the Debug Port in the IDE |
| 83 | +menu is set. |
| 84 | + |
| 85 | +.. code:: cpp |
| 86 | +
|
| 87 | + #ifdef DEBUG_ESP_PORT |
| 88 | + #define DEBUG_MSG(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ ) |
| 89 | + #else |
| 90 | + #define DEBUG_MSG(...) |
| 91 | + #endif |
| 92 | +
|
| 93 | + void setup() { |
| 94 | + Serial.begin(115200); |
| 95 | + |
| 96 | + delay(3000); |
| 97 | + DEBUG_MSG("bootup...\n"); |
| 98 | + } |
| 99 | +
|
| 100 | + void loop() { |
| 101 | + DEBUG_MSG("loop %d\n", millis()); |
| 102 | + delay(1000); |
| 103 | + } |
| 104 | +
|
| 105 | +.. |Debug-Port| image:: debug_port.png |
| 106 | +.. |Debug-Level| image:: debug_level.png |
| 107 | + |
0 commit comments