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