From 1d7f2f368b2b42eb575280d446fa2f5282dfd881 Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Tue, 22 Jun 2021 20:25:27 +0200 Subject: [PATCH] debugging support :) over gdbstub --- README.md | 3 --- extra_script.py => create_gz_files.py | 1 + doku.md | 21 +++++++++++++++ include/httpserver.h | 37 +++++++++++++++++++++++++++ scripts/gdboptions | 17 ++++++++++++ src/main.cpp | 29 ++++++++++----------- start_xtensa_gdb_stub.sh | 6 +++++ templ_platformio_ini | 21 +++++++++++---- 8 files changed, 112 insertions(+), 23 deletions(-) rename extra_script.py => create_gz_files.py (98%) create mode 100644 include/httpserver.h create mode 100644 scripts/gdboptions create mode 100755 start_xtensa_gdb_stub.sh diff --git a/README.md b/README.md index 4e1822d..8f4a298 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,5 @@ upload_port = upload_flags = --port=8266 --auth=admin - -lib_deps = - ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9 ``` diff --git a/extra_script.py b/create_gz_files.py similarity index 98% rename from extra_script.py rename to create_gz_files.py index 9339532..0c06809 100644 --- a/extra_script.py +++ b/create_gz_files.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 import os, gzip # https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/ diff --git a/doku.md b/doku.md index 114f4a0..20bbf7b 100644 --- a/doku.md +++ b/doku.md @@ -2,3 +2,24 @@ Hardware Timer didnt work https://github.com/khoih-prog/ESP8266TimerInterrupt#wh => Software Timer https://ullisroboterseite.de/esp8266-timing.html#timer + + + +### __Zum aktivieren von GDBStub:__ +```c +#include + +... + +void setup() { + Serial.begin(460800); + gdbstub_init(); +``` + +### __Achtung !__ +GDB muss dafür compiled werden +GDB-Version aus Arduino Toolchain hat Support + +```sh +$ ./start_xtensa_gdb_stub.sh +``` \ No newline at end of file diff --git a/include/httpserver.h b/include/httpserver.h new file mode 100644 index 0000000..2d5b305 --- /dev/null +++ b/include/httpserver.h @@ -0,0 +1,37 @@ +#ifndef __HTTPSERVER_H +#define __HTTPSERVER_H + +#include + +class HTTPServer { +private: + int port; + ESP8266WebServer* server; + +public: + HTTPServer(int port) { + server = new ESP8266WebServer; + + // server->on("/", handleRootGz); + // server->on("/style.css", handleCssGz); + // server->on("/favicon.png", handleFaviconGz); + // server->onNotFound(handleNotFound); + + server->begin(port); + } + ~HTTPServer() { + server->stop(); + delete server; + } + + void initialize() { + server->begin(port); + } + + void handleClient() { + server->handleClient(); + } +}; + + +#endif // __HTTPSERVER_H \ No newline at end of file diff --git a/scripts/gdboptions b/scripts/gdboptions new file mode 100644 index 0000000..33d4bd7 --- /dev/null +++ b/scripts/gdboptions @@ -0,0 +1,17 @@ +set remote hardware-breakpoint-limit 1 +set remote hardware-watchpoint-limit 1 +set remote interrupt-on-connect on +set remote kill-packet off +set remote symbol-lookup-packet off +set remote verbose-resume-packet off +mem 0x20000000 0x3fefffff ro cache +mem 0x3ff00000 0x3fffffff rw +mem 0x40000000 0x400fffff ro cache +mem 0x40100000 0x4013ffff rw cache +mem 0x40140000 0x5fffffff ro cache +mem 0x60000000 0x60001fff rw +set serial baud 460800 + +file .pio/build/debug/firmware.elf +target remote /dev/ttyUSB0 +thb loop diff --git a/src/main.cpp b/src/main.cpp index e90d976..5dd7ac2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,17 +1,19 @@ #include -#ifdef WITH_GDB_STUB + +// debugging support via GDBStub over UART +#ifdef WITH_DEBUGGING_ON #include #endif -// #include #include "PCA9685.h" +extern "C" { +#include "user_interface.h" +} #define ESP12_LED 2 #define NODEMCU_LED 16 -extern "C" { -#include "user_interface.h" -} + os_timer_t Timer1; // Verwaltungsstruktur des Timers int c; @@ -46,9 +48,9 @@ void timerCallback(void *pArg) #include #include -// #include "index.html.gz.h" -// #include "style.css.gz.h" -// #include "favicon.png.gz.h" +#include "index.html.gz.h" +#include "style.css.gz.h" +#include "favicon.png.gz.h" // images are possible // maybe check out FS <- SPIFFS @@ -69,21 +71,18 @@ PCA9685 pwmController; void handleRootGz() { const char* dataType = "text/html"; server.sendHeader(F("Content-Encoding"), F("gzip")); - server.send(404, dataType, "debug"); - // server.send(200, dataType, (const char*)index_html_gz, index_html_gz_len); + server.send(200, dataType, (const char*)index_html_gz, index_html_gz_len); } void handleCssGz() { const char* dataType = "text/css"; server.sendHeader(F("Content-Encoding"), F("gzip")); - server.send(404, dataType, "debug"); - // server.send(200, dataType, (const char*)style_css_gz, style_css_gz_len); + server.send(200, dataType, (const char*)style_css_gz, style_css_gz_len); } void handleFaviconGz() { const char* dataType = "image/png"; server.sendHeader(F("Content-Encoding"), F("gzip")); - server.send(404, dataType, "debug"); - // server.send(200, dataType, (const char*)favicon_png_gz, favicon_png_gz_len); + server.send(200, dataType, (const char*)favicon_png_gz, favicon_png_gz_len); } void handleNotFound() { @@ -184,7 +183,7 @@ void setup_pwm_pca9685() { } void setup() { -#ifdef WITH_GDB_STUB +#ifdef WITH_DEBUGGING_ON Serial.begin(460800); gdbstub_init(); #else diff --git a/start_xtensa_gdb_stub.sh b/start_xtensa_gdb_stub.sh new file mode 100755 index 0000000..7b5f96e --- /dev/null +++ b/start_xtensa_gdb_stub.sh @@ -0,0 +1,6 @@ +#!/bin/bash +GDB_PATH=~/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.0-newlib4.0.0-gnu23-48f7b08/bin/xtensa-lx106-elf-gdb + +cd .. +echo "Starting gdb" +$GDB_PATH -x scripts/gdboptions diff --git a/templ_platformio_ini b/templ_platformio_ini index a847e80..a333f62 100644 --- a/templ_platformio_ini +++ b/templ_platformio_ini @@ -8,14 +8,18 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:esp01_1m] +[env] platform = espressif8266 -board = esp01_1m +board = nodemcuv2 framework = arduino monitor_speed = 115200 - extra_scripts = pre:extra_script.py +[env:serial] +upload_protocol = esptool +upload_speed = 921600 + +[env:ota] ; stuff for OTA ; https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update upload_protocol = espota @@ -24,5 +28,12 @@ upload_flags = --port=8266 --auth=admin -lib_deps = - ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9 +[env:debug] +build_flags = -DWITH_DEBUGGING_ON -Os -g3 -ggdb3 +upload_protocol = esptool +upload_speed = 921600 + + + + +