Skip to content

Commit 7b83bbb

Browse files
authored
Merge pull request #1519 from nodemcu/dev
Next 1.5.4.1 master drop
2 parents 8e48483 + d96d7f2 commit 7b83bbb

File tree

134 files changed

+45566
-1939
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+45566
-1939
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Use one of the two templates below and delete the rest.
77
### Actual behavior
88

99
### Test code
10-
Provide a minimal and isolated test which will reproduce the problem.
10+
Provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) which will reproduce the problem.
1111
```Lua
1212
-- add code here
1313
```

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ Fixes #\<GitHub-issue-number\>.
22

33
Make sure all boxes are checked (add x inside the brackets) when you submit your contribution, remove this sentence before doing so.
44

5-
- [ ] This PR is compliant with the [contributing guidelines](https://github.com/nodemcu/nodemcu-firmware/blob/dev/CONTRIBUTING.md) (if not, please describe why).
5+
- [ ] This PR is for the `dev` branch rather than for `master`.
6+
- [ ] This PR is compliant with the [other contributing guidelines](https://github.com/nodemcu/nodemcu-firmware/blob/dev/CONTRIBUTING.md) as well (if not, please describe why).
67
- [ ] I have thoroughly tested my contribution.
78
- [ ] The code changes are reflected in the documentation at `docs/en/*`.
89

9-
\<Description of and rational behind this PR\>
10-
11-
Committers supporting this PR: leave blank
10+
\<Description of and rational behind this PR\>

CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
The following is a set of guidelines for contributing to NodeMCU on GitHub. These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request.
66

7-
It is appreciated but optional if you raise an issue _before_ you start changing NodeMCU, discussing the proposed change; emphasising that the you are proposing to develop the patch yourself, and outling the strategy for implementation. This type of discussion is what we should be doing on the issues list and it is better to do this before or in parallel to developing the patch rather than having "you should have done it this way" type of feedback on the PR itself.
7+
It is appreciated but optional if you raise an issue _before_ you start changing NodeMCU, discussing the proposed change; emphasing that the you are proposing to develop the patch yourself, and outlining the strategy for implementation. This type of discussion is what we should be doing on the issues list and it is better to do this before or in parallel to developing the patch rather than having "you should have done it this way" type of feedback on the PR itself.
88

99
### Table Of Contents
1010

@@ -17,7 +17,7 @@ It is appreciated but optional if you raise an issue _before_ you start changing
1717

1818
## Development environment setup
1919
Use the platform and tools you feel most comfortable with. There are no constraints imposed by this project. You have (at least) two options to set up the toolchain to build the NodeMCU firmware:
20-
- [Full-fledged Linux enviroment](http://www.esp8266.com/wiki/doku.php?id=toolchain#how_to_setup_a_vm_to_host_your_toolchain), either physical or virtual.
20+
- [Full-fledged Linux environment](http://www.esp8266.com/wiki/doku.php?id=toolchain#how_to_setup_a_vm_to_host_your_toolchain), either physical or virtual.
2121
- [Docker image](https://hub.docker.com/r/marcelstoer/nodemcu-build/) which allows to run the build inside the container as if you were running a build script on your local machine.
2222

2323
## Writing Documentation
@@ -32,15 +32,15 @@ There are essentially only two things to keep in mind if you're contributing a P
3232

3333
If you also want to verify that all is well with your Markdown files you can install Python-based [MkDocs](http://www.mkdocs.org/), which is used by RTD to build the static HTML files, and run `mkdocs serve` in the root of your NodeMCU firmware directory.
3434

35-
A note on Markdown *syntax*. As Mkdocs is Python-based it's no surprise it uses a [Python Markdown implementation](https://pythonhosted.org/Markdown/). The good news is that it sticks pretty closely to John Gruber's Markdown and also [supports tables and fenced code blocks](http://www.mkdocs.org/user-guide/writing-your-docs/#markdown-extensions) just like GitHub does.
35+
A note on Markdown *syntax*. As MkDocs is Python-based it's no surprise it uses a [Python Markdown implementation](https://pythonhosted.org/Markdown/). The good news is that it sticks pretty closely to John Gruber's Markdown and also [supports tables and fenced code blocks](http://www.mkdocs.org/user-guide/writing-your-docs/#markdown-extensions) just like GitHub does.
3636

3737
A collection of doc-writing hints and tips is maintained on the [wiki](https://github.com/nodemcu/nodemcu-firmware/wiki/Notes-about-writing-docs).
3838

3939
If you're interested in some NodeMCU history you're welcome to read [issue #774](https://github.com/nodemcu/nodemcu-firmware/issues/774)
4040

4141
## Working with Git and GitHub
4242

43-
*Pull requests for new features and major fixes should be opened against the `dev` branch.*
43+
*Pull requests for new features and fixes should be opened against the `dev` branch.*
4444

4545
Avoid intermediate merge commits. [Rebase](https://www.atlassian.com/git/tutorials/merging-vs-rebasing) your feature branch onto `dev` to pull updates and verify your local changes against them before placing the pull request.
4646

@@ -52,12 +52,12 @@ Avoid intermediate merge commits. [Rebase](https://www.atlassian.com/git/tutoria
5252
1. `git checkout <branch-name>`
5353
1. Make changes to the code base and commit them using e.g. `git commit -a -m 'Look ma, I did it'`
5454
1. When you're done:
55-
1. [Squash your commits](http://www.andrewconnell.com/blog/squash-multiple-git-commits-into-one) into one. There are [several ways](http://stackoverflow.com/a/5201642/131929) of doing this.
55+
1. [Squash your commits](http://www.andrewconnell.com/blog/squash-multiple-git-commits-into-one). There are [several ways](http://stackoverflow.com/a/5201642/131929) of doing this.
5656
1. Bring your fork up-to-date with the NodeMCU upstream repo ([see below](#keeping-your-fork-in-sync)). Then rebase your branch on `dev` running `git rebase dev`.
5757
1. `git push`
5858
1. [Create a pull request](https://help.github.com/articles/creating-a-pull-request/) (PR) on GitHub.
5959

60-
This is just one way of doing things. If you're proficient in Git matters you're free to choose your own. If you want to read more then the [GitHub chapter in the Git book](http://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project#The-GitHub-Flow) is a way to start. [GitHub's own documenation](https://help.github.com/categories/collaborating/) contains a wealth of information as well.
60+
This is just one way of doing things. If you're proficient in Git matters you're free to choose your own. If you want to read more then the [GitHub chapter in the Git book](http://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project#The-GitHub-Flow) is a way to start. [GitHub's own documentation](https://help.github.com/categories/collaborating/) contains a wealth of information as well.
6161

6262
### Keeping your fork in sync
6363
You need to sync your fork with the NodeMCU upstream repository from time to time, latest before you rebase (see flow above).

Makefile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ SDK_DIR:=$(TOP_DIR)/sdk/esp_iot_sdk_v$(SDK_VER)
2424
CCFLAGS:= -I$(TOP_DIR)/sdk-overrides/include -I$(SDK_DIR)/include
2525
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS)
2626

27+
ifdef DEBUG
28+
CCFLAGS += -ggdb -O0
29+
LDFLAGS += -ggdb
30+
else
31+
CCFLAGS += -Os
32+
endif
33+
2734
#############################################################
2835
# Select compile
2936
#
@@ -38,11 +45,11 @@ ifeq ($(OS),Windows_NT)
3845
CPP = xt-cpp
3946
OBJCOPY = xt-objcopy
4047
#MAKE = xt-make
41-
CCFLAGS += -Os --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal
48+
CCFLAGS += --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal
4249
else
4350
# It is gcc, may be cygwin
4451
# Can we use -fdata-sections?
45-
CCFLAGS += -Os -ffunction-sections -fno-jump-tables -fdata-sections
52+
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections
4653
AR = xtensa-lx106-elf-ar
4754
CC = xtensa-lx106-elf-gcc
4855
NM = xtensa-lx106-elf-nm
@@ -69,7 +76,7 @@ else
6976
else
7077
ESPPORT = $(COMPORT)
7178
endif
72-
CCFLAGS += -Os -ffunction-sections -fno-jump-tables -fdata-sections
79+
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections
7380
AR = xtensa-lx106-elf-ar
7481
CC = xtensa-lx106-elf-gcc
7582
NM = xtensa-lx106-elf-nm
@@ -231,11 +238,22 @@ clobber: $(SPECIAL_CLOBBER)
231238
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clobber;)
232239
$(RM) -r $(ODIR)
233240

234-
flash:
241+
flash:
242+
@echo "use one of the following targets to flash the firmware"
243+
@echo " make flash512k - for ESP with 512kB flash size"
244+
@echo " make flash4m - for ESP with 4MB flash size"
245+
246+
flash512k:
247+
$(MAKE) -e FLASHOPTIONS="-fm qio -fs 4m -ff 40m" flashinternal
248+
249+
flash4m:
250+
$(MAKE) -e FLASHOPTIONS="-fm dio -fs 32m -ff 40m" flashinternal
251+
252+
flashinternal:
235253
ifndef PDIR
236-
$(MAKE) -C ./app flash
254+
$(MAKE) -C ./app flashinternal
237255
else
238-
$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(FIRMWAREDIR)0x00000.bin 0x10000 $(FIRMWAREDIR)0x10000.bin
256+
$(ESPTOOL) --port $(ESPPORT) write_flash $(FLASHOPTIONS) 0x00000 $(FIRMWAREDIR)0x00000.bin 0x10000 $(FIRMWAREDIR)0x10000.bin
239257
endif
240258

241259
.subdirs:
@@ -255,7 +273,7 @@ endif
255273
.PHONY: spiffs-image-remove
256274

257275
spiffs-image-remove:
258-
$(MAKE) -C tools remove-image
276+
$(MAKE) -C tools remove-image spiffsimg/spiffsimg
259277

260278
.PHONY: spiffs-image
261279

app/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ SUBDIRS= \
4242
dhtlib \
4343
tsl2561 \
4444
net \
45-
http
45+
http \
46+
fatfs \
47+
esp-gdbstub \
48+
websocket
4649

4750
endif # } PDIR
4851

@@ -82,11 +85,14 @@ COMPONENTS_eagle.app.v6 = \
8285
ucglib/ucglib.a \
8386
smart/smart.a \
8487
spiffs/spiffs.a \
88+
fatfs/libfatfs.a \
8589
cjson/libcjson.a \
8690
crypto/libcrypto.a \
8791
dhtlib/libdhtlib.a \
8892
tsl2561/tsl2561lib.a \
8993
http/libhttp.a \
94+
websocket/libwebsocket.a \
95+
esp-gdbstub/libgdbstub.a \
9096
net/libnodemcu_net.a \
9197
modules/libmodules.a \
9298

app/cjson/cjson_mem.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@
22
#include "../lua/lauxlib.h"
33
#include <c_stdlib.h>
44

5-
static lua_State *gL;
65
static const char errfmt[] = "cjson %salloc: out of mem (%d bytes)";
76

8-
void cjson_mem_setlua (lua_State *L)
9-
{
10-
gL = L;
11-
}
12-
137
void *cjson_mem_malloc (uint32_t sz)
148
{
159
void *p = (void*)c_malloc (sz);
16-
if (!p && gL)
17-
luaL_error (gL, errfmt, "m", sz);
10+
lua_State *L = lua_getstate();
11+
if (!p)
12+
luaL_error (L, errfmt, "m", sz);
1813
return p;
1914
}
2015

2116

2217
void *cjson_mem_realloc (void *o, uint32_t sz)
2318
{
2419
void *p = (void*)c_realloc (o, sz);
25-
if (!p && gL)
26-
luaL_error (gL, errfmt, "re", sz);
20+
lua_State *L = lua_getstate();
21+
if (!p)
22+
luaL_error (L, errfmt, "re", sz);
2723
return p;
2824
}

app/cjson/cjson_mem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#include "../lua/lua.h"
55

6-
void cjson_mem_setlua (lua_State *L);
7-
86
void *cjson_mem_malloc (uint32_t sz);
97
void *cjson_mem_realloc (void *p, uint32_t sz);
108

app/coap/coap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ typedef struct
155155
typedef struct coap_luser_entry coap_luser_entry;
156156

157157
struct coap_luser_entry{
158-
lua_State *L;
159158
// int ref;
160159
// char name[MAX_SEGMENTS_SIZE+1]; // +1 for string '\0'
161160
const char *name;

app/coap/endpoints.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
3737
const coap_option_t *opt;
3838
uint8_t count;
3939
int n;
40+
lua_State *L = lua_getstate();
4041
if (NULL != (opt = coap_findOptions(inpkt, COAP_OPTION_URI_PATH, &count)))
4142
{
4243
if ((count != ep->path->count ) && (count != ep->path->count + 1)) // +1 for /f/[function], /v/[variable]
@@ -58,19 +59,17 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
5859
NODE_DBG("/v1/v/");
5960
NODE_DBG((char *)h->name);
6061
NODE_DBG(" match.\n");
61-
if(h->L == NULL)
62-
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
6362
if(c_strlen(h->name))
6463
{
65-
n = lua_gettop(h->L);
66-
lua_getglobal(h->L, h->name);
67-
if (!lua_isnumber(h->L, -1) && !lua_isstring(h->L, -1)) {
64+
n = lua_gettop(L);
65+
lua_getglobal(L, h->name);
66+
if (!lua_isnumber(L, -1) && !lua_isstring(L, -1)) {
6867
NODE_DBG ("should be a number or string.\n");
69-
lua_settop(h->L, n);
68+
lua_settop(L, n);
7069
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
7170
} else {
72-
const char *res = lua_tostring(h->L,-1);
73-
lua_settop(h->L, n);
71+
const char *res = lua_tostring(L,-1);
72+
lua_settop(L, n);
7473
return coap_make_response(scratch, outpkt, (const uint8_t *)res, c_strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type);
7574
}
7675
}
@@ -94,6 +93,7 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
9493
const coap_option_t *opt;
9594
uint8_t count;
9695
int n;
96+
lua_State *L = lua_getstate();
9797
if (NULL != (opt = coap_findOptions(inpkt, COAP_OPTION_URI_PATH, &count)))
9898
{
9999
if ((count != ep->path->count ) && (count != ep->path->count + 1)) // +1 for /f/[function], /v/[variable]
@@ -116,37 +116,34 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
116116
NODE_DBG((char *)h->name);
117117
NODE_DBG(" match.\n");
118118

119-
if(h->L == NULL)
120-
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
121-
122119
if(c_strlen(h->name))
123120
{
124-
n = lua_gettop(h->L);
125-
lua_getglobal(h->L, h->name);
126-
if (lua_type(h->L, -1) != LUA_TFUNCTION) {
121+
n = lua_gettop(L);
122+
lua_getglobal(L, h->name);
123+
if (lua_type(L, -1) != LUA_TFUNCTION) {
127124
NODE_DBG ("should be a function\n");
128-
lua_settop(h->L, n);
125+
lua_settop(L, n);
129126
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
130127
} else {
131-
lua_pushlstring(h->L, inpkt->payload.p, inpkt->payload.len); // make sure payload.p is filled with '\0' after payload.len, or use lua_pushlstring
132-
lua_call(h->L, 1, 1);
133-
if (!lua_isnil(h->L, -1)){ /* get return? */
134-
if( lua_isstring(h->L, -1) ) // deal with the return string
128+
lua_pushlstring(L, inpkt->payload.p, inpkt->payload.len); // make sure payload.p is filled with '\0' after payload.len, or use lua_pushlstring
129+
lua_call(L, 1, 1);
130+
if (!lua_isnil(L, -1)){ /* get return? */
131+
if( lua_isstring(L, -1) ) // deal with the return string
135132
{
136133
size_t len = 0;
137-
const char *ret = luaL_checklstring( h->L, -1, &len );
134+
const char *ret = luaL_checklstring( L, -1, &len );
138135
if(len > MAX_PAYLOAD_SIZE){
139-
lua_settop(h->L, n);
140-
luaL_error( h->L, "return string:<MAX_PAYLOAD_SIZE" );
136+
lua_settop(L, n);
137+
luaL_error( L, "return string:<MAX_PAYLOAD_SIZE" );
141138
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
142139
}
143140
NODE_DBG((char *)ret);
144141
NODE_DBG("\n");
145-
lua_settop(h->L, n);
142+
lua_settop(L, n);
146143
return coap_make_response(scratch, outpkt, ret, len, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
147144
}
148145
} else {
149-
lua_settop(h->L, n);
146+
lua_settop(L, n);
150147
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
151148
}
152149
}
@@ -198,10 +195,10 @@ static int handle_get_id(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, c
198195
return coap_make_response(scratch, outpkt, (const uint8_t *)(&id), sizeof(uint32_t), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
199196
}
200197

201-
coap_luser_entry var_head = {NULL,NULL,NULL,0};
198+
coap_luser_entry var_head = {NULL,NULL,0};
202199
coap_luser_entry *variable_entry = &var_head;
203200

204-
coap_luser_entry func_head = {NULL,NULL,NULL,0};
201+
coap_luser_entry func_head = {NULL,NULL,0};
205202
coap_luser_entry *function_entry = &func_head;
206203

207204
const coap_endpoint_t endpoints[] =

app/crypto/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
4141
INCLUDES := $(INCLUDES) -I $(PDIR)include
4242
INCLUDES += -I ./
4343
INCLUDES += -I ../libc
44+
INCLUDES += -I ../platform
4445
PDIR := ../$(PDIR)
4546
sinclude $(PDIR)Makefile
4647

0 commit comments

Comments
 (0)