Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions samples/Basic_Debug/.cproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.cross.base.748705698">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.cross.base.748705698" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration buildProperties="" id="cdt.managedbuild.toolchain.gnu.cross.base.748705698" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.cross.base.748705698.761350396" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.1183930491" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base">
<option id="cdt.managedbuild.option.gnu.cross.prefix.672870641" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix"/>
<option id="cdt.managedbuild.option.gnu.cross.path.311936245" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1656812004" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder id="cdt.managedbuild.builder.gnu.cross.2032321088" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.builder.gnu.cross"/>
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1713388593" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler"/>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1002773843" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler"/>
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.2026560831" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.936150734" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker"/>
<tool id="cdt.managedbuild.tool.gnu.cross.archiver.925566031" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
<tool id="cdt.managedbuild.tool.gnu.cross.assembler.2047455488" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler"/>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.2032390008;cdt.managedbuild.tool.gnu.c.compiler.input.1700912488">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cross.c.compiler.1168221903;cdt.managedbuild.tool.gnu.c.compiler.input.313321806">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1999763015;cdt.managedbuild.tool.gnu.cpp.compiler.input.1330530366">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.454898447;cdt.managedbuild.tool.gnu.cpp.compiler.input.501261625">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="Basic_Debug_RTOS.null.1970648950" name="Basic_Debug_RTOS"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
28 changes: 28 additions & 0 deletions samples/Basic_Debug/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Basic_Debug</name>
<comment></comment>
<projects>
<project>SmingFramework</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
24 changes: 24 additions & 0 deletions samples/Basic_Debug/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#####################################################################
#### Please don't change this file. Use Makefile-user.mk instead ####
#####################################################################
# Including user Makefile.
# Should be used to set project-specific parameters
include ./Makefile-user.mk

# Important parameters check.
# We need to make sure SMING_HOME and ESP_HOME variables are set.
# You can use Makefile-user.mk in each project or use enviromental variables to set it globally.

ifndef SMING_HOME
$(error SMING_HOME is not set. Please configure it in Makefile-user.mk)
endif
ifndef ESP_HOME
$(error ESP_HOME is not set. Please configure it in Makefile-user.mk)
endif

# Include main Sming Makefile
ifeq ($(RBOOT_ENABLED), 1)
include $(SMING_HOME)/Makefile-rboot.mk
else
include $(SMING_HOME)/Makefile-project.mk
endif
33 changes: 33 additions & 0 deletions samples/Basic_Debug/Makefile-user.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Local build configuration
## Parameters configured here will override default and ENV values.
## Uncomment and change examples:

#Add your source directories here separated by space
MODULES = app

## ESP_HOME sets the path where ESP tools and SDK are located.
## Windows:
# ESP_HOME = c:/Espressif

## MacOS / Linux:
#ESP_HOME = /opt/esp-open-sdk

## SMING_HOME sets the path where Sming framework is located.
## Windows:
# SMING_HOME = c:/tools/sming/Sming

# MacOS / Linux
# SMING_HOME = /opt/sming/Sming

## COM port parameter is reqruied to flash firmware correctly.
## Windows:
# COM_PORT = COM3

# MacOS / Linux:
# COM_PORT = /dev/tty.usbserial

# Com port speed
# COM_SPEED = 115200
ENABLE_GDB=1

DISABLE_SPIFFS=1
81 changes: 81 additions & 0 deletions samples/Basic_Debug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
This project is an example of how to integrate GDB debugging into your project.
It relies on the GDBStub project to do the heavy-lifting.

Exception Handling
------------------
If there is an exception in your code usually ESP prints a message like the following one:

```
Fatal exception (0):
epc1=0x4020997c, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
```

That information can help you discover the function call that caused the exception.
Using the value of epc1 and executing a command like the one below:

```bash
xtensa-lx106-elf-objdump -dtr out/build/app.out | grep 4020997c
```

can give you an idea about the function. In my test case this is:
```
4020997c: fffe61 l32r a6, 40209974 <user_rf_pre_init+0x45c>
```

But that information might not be enough to find the issue. And finding the
root cause may take quite some time.

GDB Debugging
-------------
Debugging is a powerful technique giving better understanding of the code and
the things that went wrong.

There is already existing GDBStub that tries to make it easier to use software
debugger. And this project is an example of what you need to do in order to
integrate it.

Here are the commands that you need to execute:

1. You will need a version of the SmingRTOS library with enabled GDBStub functionality.
For that purpose you should compile SmingRTOS with ENABLE_GDB flag. Under Linux
you should do the following:

```bash
cd <path-to-sming-code>/SmingRTOS
make clean
make ENABLE_GDB=1
```

2. In your project inside of your Makefile-user.mk file you should add the following
variable:

```make
ENABLE_GDB=1
```

If you are looking for an example then take a look at the Makefile-user.mk file
that is in the same directory as this README.md file.

3. Now compile your project and flash it to the board.
```bash
make
make flash
```

4. Run gdb immediately after resetting the board or after it has run into an exception.
The easiest way to do it is to use the provided script:
```bash
xtensa-lx106-elf-gdb -x <path-to-sming-code->/Basic_Debug/gdbcmds -b 115200
```

115200 stands for the baud rate your program is using. Change it accordingly.
You may also need to change the gdbcmds script to fit the configuration of your hardware and build environment.

7. Software breakpoints ('br') only work on code that is in RAM. During development you can use the GDB_IRAM_ATTR attribute in your function declarations.
Code in flash can only have a hardware breakpoint ('hbr').

8. If you need help working with the command line debugger or with the visual debugger in Eclipse then take a look at that article [Live debugging with open-source tools](https://blog.attachix.com/live-debugging-with-open-source-tools-programming-for-esp8266-part-4/). The paragraphs that you should read are named **"Live Debugging with GDB from Command Line"** and **"Live Debugging with Eclipse CDT"**.

9. Recommended GDB version - make sure that you have version 7.5.x or newer. Windows users can download GDB.exe with the recommended version from [here](http://sysprogs.com/files/gnutoolchains/esp8266/esp8266-gcc5.2.0-r5.exe).

Read the [Notes](https://github.com/espressif/esp-gdbstub#notes) for more information.
23 changes: 23 additions & 0 deletions samples/Basic_Debug/app/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <user_config.h>
#include <SmingCore.h>

#define LED_PIN 2 // GPIO2

Timer procTimer;
bool state = true;

/*
* Notice: Software breakpoints work only on code that is in RAM.
* In Sming you have to use the GDB_IRAM_ATTR to do this.
*/
void GDB_IRAM_ATTR blink()
{
digitalWrite(LED_PIN, state);
state = !state;
}

void GDB_IRAM_ATTR init()
{
pinMode(LED_PIN, OUTPUT);
procTimer.initializeMs(1000, blink).start();
}
7 changes: 7 additions & 0 deletions samples/Basic_Debug/include/user_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __USER_CONFIG_H__
#define __USER_CONFIG_H__

// In this file you can define Sming Runtime parameters
// For possible options see : ....

#endif
30 changes: 29 additions & 1 deletion sming/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ LIBS = microc gcc hal phy pp net80211 wpa crypto main freertos lwip minic pwm

# compiler flags using during compilation of source files
#CFLAGS = -g -save-temps -Os -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -mno-serialize-volatile -D__ets__ -DICACHE_FLASH
CFLAGS = -Os -g -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 $(USER_CFLAGS)
CFLAGS = -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 $(USER_CFLAGS)

WIFI_SSID ?= ""
WIFI_PWD ?= ""
Expand All @@ -76,6 +76,15 @@ endif
CFLAGS += -DNDEBUG=1
CFLAGS += -DLWIP_DEBUG=0
# CXXFLAGS = $(CFLAGS) -std=c++11 -fno-rtti -fno-exceptions
ifeq ($(ENABLE_GDB), 1)
CFLAGS += -Og -ggdb -DGDBSTUB_FREERTOS=1 -DENABLE_GDB=1
MODULES += gdbstub
EXTRA_INCDIR += gdbstub
else
CFLAGS += -Os -g
endif


CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=c++11 -felide-constructors -Wno-literal-suffix
# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,-Map=$(BUILD_BASE)/firmware.map
Expand All @@ -97,6 +106,7 @@ SDK_INCDIR += include/lwip/ipv6
SDK_INCDIR += include/freertos

# select which tools to use as compiler, librarian and linker
AS := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
CXX := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-g++
AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar
Expand All @@ -111,10 +121,20 @@ USER_LIBDIR := compiler/lib
SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))


AS_SRC=
ifeq ($(ENABLE_GDB), 1)
AS_SRC += $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.S))
endif
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c*))
C_OBJ := $(patsubst %.c,%.o,$(SRC))
CXX_OBJ := $(patsubst %.cpp,%.o,$(C_OBJ))
OBJ := $(patsubst %.o,$(BUILD_BASE)/%.o,$(CXX_OBJ))
AS_OBJ=
ifeq ($(ENABLE_GDB), 1)
AS_OBJ += $(patsubst %.S,%.o,$(AS_SRC))
OBJ += $(patsubst %.o,$(BUILD_BASE)/%.o,$(AS_OBJ))
endif
LIBS := $(addprefix -l,$(LIBS))
APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET).a)

Expand All @@ -135,8 +155,16 @@ endif

vpath %.c $(SRC_DIR)
vpath %.cpp $(SRC_DIR)
ifeq ($(ENABLE_GDB), 1)
vpath %.S $(SRC_DIR)
endif

define compile-objects
ifeq ($(ENABLE_GDB), 1)
$1/%.o: %.S
$(vecho) "AS $$<"
$(Q) $(AS) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
endif
$1/%.o: %.c
$(vecho) "CC $$<"
$(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
Expand Down
8 changes: 7 additions & 1 deletion sming/Makefile-project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ USER_LIBDIR = $(SMING_HOME)/compiler/lib/
LIBS = microc gcc hal phy pp net80211 wpa crypto main freertos lwip minic pwm sming

# compiler flags using during compilation of source files
CFLAGS = -Os -g -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 $(USER_CFLAGS)
CFLAGS = -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 $(USER_CFLAGS)
ifeq ($(ENABLE_GDB), 1)
CFLAGS += -Og -ggdb -DGDBSTUB_FREERTOS=1 -DENABLE_GDB=1
EXTRA_INCDIR += $(SMING_HOME)/gdbstub
else
CFLAGS += -Os -g
endif
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=c++11 -felide-constructors -Wno-literal-suffix

# we will use global WiFi settings from Eclipse Environment Variables, if possible
Expand Down
8 changes: 7 additions & 1 deletion sming/Makefile-rboot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ EXTRA_INCDIR += $(SDK_BASE)/include/espressif


# compiler flags using during compilation of source files
CFLAGS = -Os -g -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 $(USER_CFLAGS)
CFLAGS = -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 $(USER_CFLAGS)
ifeq ($(ENABLE_GDB), 1)
CFLAGS += -Og -ggdb -DGDBSTUB_FREERTOS=1 -DENABLE_GDB=1
EXTRA_INCDIR += $(SMING_HOME)/gdbstub
else
CFLAGS += -Os -g
endif
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=c++11 -felide-constructors -Wno-literal-suffix

# libmain must be modified for rBoot big flash support (just one symbol gets weakened)
Expand Down
1 change: 1 addition & 0 deletions sming/gdbstub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.output/
24 changes: 24 additions & 0 deletions sming/gdbstub/License
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ESPRESSIF MIT License

Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>

Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, it is free of charge, to any person obtaining a copy of this software and associated documentation files (the ��Software��), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ��AS IS��, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


���� MIT ����֤

��Ȩ (c) 2015 <������Ϣ�Ƽ����Ϻ������޹�˾>

������֤��Ȩ������������Ϣ�Ƽ� ESP8266 ��Ʒ��Ӧ�ÿ������ڴ�����£�������֤�����Ȩ�κλ�ø�������������ĵ���ͳ��Ϊ�������������������Ƶؾ�Ӫ�����������������Ƶ�ʹ�á����ơ��޸ġ��ϲ������淢�С�ɢ��������Ȩ������������������������Ȩ��������Ȩ����������ЩȨ����ͬʱ������������������

�����������������и����ж�����������ϵİ�Ȩ��������Ȩ������

�������������������ṩ��û���κ���ȷ�򰵺��ĵ������������������ڹ��������ԡ��ʺ�ijһ�ض���;�ͷ���Ȩ�ı�֤�����ߺͰ�Ȩ���������κ�����¾�����������������ʹ��������Ժ�ͬ��ʽ��������Ȩ��������ʽ������κ����⡢�𺦻��������θ���




Loading