Skip to content

Commit 466b566

Browse files
committed
Merge pull request #11 from esp8266/esp8266
Esp8266
2 parents a561710 + fc83952 commit 466b566

Some content is hidden

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

50 files changed

+714
-155
lines changed

Diff for: .gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ hardware/arduino/bootloaders/caterina_LUFA/Caterina.lss
1313
hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf
1414
hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
1515
hardware/arduino/bootloaders/caterina_LUFA/.dep/
16-
build/libastylej-*.zip
16+
build/*.zip
1717
build/windows/work/
1818
build/windows/*.zip
1919
build/windows/*.tgz
@@ -56,6 +56,9 @@ avr-toolchain-*.zip
5656
/hardware/tools/esp8266/utils/
5757
/hardware/tools/esp8266/xtensa-lx106-elf
5858
/hardware/tools/esp8266/esptool.exe
59+
/hardware/esp8266com/esp8266/tools/xtensa*
60+
/hardware/esp8266com/esp8266/tools/esptool*
61+
/hardware/esp8266com/esp8266/tools/utils
5962
/hardware/tools/avr/
6063
/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/
6164
/hardware/tools/bossac.exe

Diff for: boards.txt

+4-10
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ generic.build.board=ESP8266_ESP01
2121
generic.build.core=esp8266
2222
generic.build.variant=generic
2323
generic.build.flash_mode=qio
24-
generic.build.flash_size=512K
25-
generic.build.flash_freq=40
26-
generic.build.flash_ld=eagle.flash.512k.ld
27-
generic.build.spiffs_start=0x6B000
28-
generic.build.spiffs_end=0x7B000
2924
generic.build.spiffs_pagesize=256
30-
generic.build.spiffs_blocksize=4096
3125

3226
generic.menu.CpuFrequency.80=80 MHz
3327
generic.menu.CpuFrequency.80.build.f_cpu=80000000L
@@ -123,10 +117,10 @@ generic.menu.FlashSize.4M.upload.maximum_size=1044464
123117
# generic.menu.FlashSize.16M.build.spiffs_end=0x1000000
124118
# generic.menu.FlashSize.16M.build.spiffs_blocksize=8192
125119

126-
# generic.menu.FlashFreq.40=40MHz
127-
# generic.menu.FlashFreq.40.build.flash_freq=40
128-
# generic.menu.FlashFreq.80=80MHz
129-
# generic.menu.FlashFreq.80.build.flash_freq=80
120+
generic.menu.FlashFreq.40=40MHz
121+
generic.menu.FlashFreq.40.build.flash_freq=40
122+
generic.menu.FlashFreq.80=80MHz
123+
generic.menu.FlashFreq.80.build.flash_freq=80
130124

131125
##############################################################
132126
modwifi.name=Olimex MOD-WIFI-ESP8266(-DEV)

Diff for: cores/esp8266/Arduino.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ void ets_intr_unlock();
143143
// level 15 will disable ALL interrupts,
144144
// level 0 will disable most software interrupts
145145
//
146-
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) "; esync; isync; dsync" : "=a" (state))
147-
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; esync" :: "a" (state) : "memory")
146+
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state))
147+
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
148148

149149
extern uint32_t interruptsState;
150150

151151
#define interrupts() xt_enable_interrupts(interruptsState)
152-
#define noInterrupts() __asm__ __volatile__("rsil %0,15; esync; isync; dsync" : "=a" (interruptsState))
152+
#define noInterrupts() __asm__ __volatile__("rsil %0,15" : "=a" (interruptsState))
153153

154154
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
155155
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
@@ -195,6 +195,7 @@ unsigned long micros(void);
195195
void delay(unsigned long);
196196
void delayMicroseconds(unsigned int us);
197197
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
198+
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
198199

199200
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
200201
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
@@ -236,21 +237,24 @@ void loop(void);
236237

237238
#define min(a,b) ((a)<(b)?(a):(b))
238239
#define max(a,b) ((a)>(b)?(a):(b))
240+
#define _min(a,b) ((a)<(b)?(a):(b))
241+
#define _max(a,b) ((a)>(b)?(a):(b))
239242

240243
uint16_t makeWord(uint16_t w);
241244
uint16_t makeWord(byte h, byte l);
242245

243246
#define word(...) makeWord(__VA_ARGS__)
244247

245248
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
249+
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
246250

247251
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
248252
void noTone(uint8_t _pin);
249253

250254
// WMath prototypes
251255
long random(long);
252256
long random(long, long);
253-
void randomSeed(unsigned int);
257+
void randomSeed(unsigned long);
254258
long map(long, long, long, long, long);
255259

256260

Diff for: cores/esp8266/Esp.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern struct rst_info resetInfo;
3232

3333
// #define DEBUG_SERIAL Serial
3434

35-
35+
3636
/**
3737
* User-defined Literals
3838
* usage:
@@ -97,8 +97,8 @@ void EspClass::wdtFeed(void)
9797

9898
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
9999
{
100-
system_deep_sleep_set_option(static_cast<int>(mode));
101-
system_deep_sleep(time_us);
100+
system_deep_sleep_set_option(static_cast<int>(mode));
101+
system_deep_sleep(time_us);
102102
}
103103

104104
extern "C" void esp_yield();
@@ -280,8 +280,8 @@ uint32_t EspClass::getFlashChipSizeByChipId(void) {
280280

281281
String EspClass::getResetInfo(void) {
282282
if(resetInfo.reason != 0) {
283-
char buff[150];
284-
sprintf(&buff[0], "Fatal exception:%d flag:%d epc1:0x%08x epc2:0x%08x epc3:0x%08x excvaddr:0x%08x depc:0x%08x", resetInfo.exccause, resetInfo.reason, resetInfo.epc1, resetInfo.epc2, resetInfo.epc3, resetInfo.excvaddr, resetInfo.depc);
283+
char buff[200];
284+
sprintf(&buff[0], "Fatal exception:%d flag:%d (%s) epc1:0x%08x epc2:0x%08x epc3:0x%08x excvaddr:0x%08x depc:0x%08x", resetInfo.exccause, resetInfo.reason, (resetInfo.reason == 0 ? "DEFAULT" : resetInfo.reason == 1 ? "WDT" : resetInfo.reason == 2 ? "EXCEPTION" : resetInfo.reason == 3 ? "SOFT_WDT" : resetInfo.reason == 4 ? "SOFT_RESTART" : resetInfo.reason == 5 ? "DEEP_SLEEP_AWAKE" : "???"), resetInfo.epc1, resetInfo.epc2, resetInfo.epc3, resetInfo.excvaddr, resetInfo.depc);
285285
return String(buff);
286286
}
287287
return String("flag: 0");
@@ -400,6 +400,13 @@ bool EspClass::updateSketch(Stream& in, uint32_t size) {
400400
return false;
401401
}
402402

403+
if(addr == freeSpaceStart) {
404+
// check for valid first magic byte
405+
if(*((uint8 *) buffer.get()) != 0xE9) {
406+
return false;
407+
}
408+
}
409+
403410
noInterrupts();
404411
rc = SPIWrite(addr, buffer.get(), willRead);
405412
interrupts();
@@ -426,7 +433,7 @@ bool EspClass::updateSketch(Stream& in, uint32_t size) {
426433
ebcmd.args[1] = 0x00000;
427434
ebcmd.args[2] = size;
428435
eboot_command_write(&ebcmd);
429-
436+
430437
ESP.restart();
431438
return true; // never happens
432439
}

Diff for: cores/esp8266/Esp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class EspClass {
129129
uint32_t EspClass::getCycleCount()
130130
{
131131
uint32_t ccount;
132-
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
132+
__asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
133133
return ccount;
134134
}
135135

Diff for: cores/esp8266/HardwareSerial.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ size_t HardwareSerial::write(uint8_t c) {
620620

621621
while(_tx_buffer->room() == 0) {
622622
yield();
623+
uart_arm_tx_interrupt(_uart);
623624
}
624625

625626
_tx_buffer->write(c);

Diff for: cores/esp8266/Print.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ size_t ICACHE_FLASH_ATTR Print::print(const Printable& x) {
127127
}
128128

129129
size_t ICACHE_FLASH_ATTR Print::println(void) {
130-
size_t n = print("\r\n");
131-
return n;
130+
return print("\r\n");
132131
}
133132

134133
size_t ICACHE_FLASH_ATTR Print::println(const String &s) {

Diff for: cores/esp8266/Stream.h

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class Stream: public Print {
6969
}
7070
// returns true if target string is found, false if timed out
7171

72+
bool find(char target) { return find (&target, 1); }
73+
7274
bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found
7375
bool findUntil(const uint8_t *target, const char *terminator) {
7476
return findUntil((char *) target, terminator);

Diff for: cores/esp8266/WMath.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
#include <stdlib.h>
2828
}
2929

30-
void randomSeed(unsigned int seed) {
30+
void randomSeed(unsigned long seed) {
3131
if(seed != 0) {
3232
srand(seed);
3333
}

Diff for: cores/esp8266/cbuf.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ class cbuf {
3939
}
4040

4141
size_t room() const {
42-
if(_end >= _begin) return _size - (_end - _begin) - 1;
43-
42+
if(_end >= _begin) {
43+
return _size - (_end - _begin) - 1;
44+
}
45+
if(_begin == _end) {
46+
return _size;
47+
}
4448
return _begin - _end - 1;
4549
}
4650

Diff for: cores/esp8266/core_esp8266_main.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ void init_done() {
121121

122122
extern "C" {
123123
void user_init(void) {
124-
system_rtc_mem_read(0, &resetInfo, sizeof(struct rst_info));
125-
struct rst_info info = { 0 };
126-
system_rtc_mem_write(0, &info, sizeof(struct rst_info));
124+
struct rst_info *rtc_info_ptr = system_get_rst_info();
125+
126+
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));
127+
127128

128129
uart_div_modify(0, UART_CLK_FREQ / (115200));
129130

Diff for: cores/esp8266/core_esp8266_phy.c

+11
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ static uint8_t phy_init_data[128] =
201201
// 18<=x<=36: use input voltage,
202202
// the value is voltage*10, 33 is 3.3V, 30 is 3.0V,
203203
// x<18 or x>36: default voltage is 3.3V
204+
//
205+
// the value of this byte depend from the TOUT pin usage (1 or 2):
206+
// 1)
207+
// analogRead function (system_adc_read()):
208+
// is only available when wire TOUT pin17 to external circuitry, Input Voltage Range restricted to 0 ~ 1.0V.
209+
// For this function the vdd33_const must be set as real power voltage of VDD3P3 pin 3 and 4
210+
// The range of operating voltage of ESP8266 is 1.8V~3.6V,the unit of vdd33_const is 0.1V,so effective value range of vdd33_const is [18,36]
211+
// 2)
212+
// getVcc function (system_get_vdd33):
213+
// is only available when TOUT pin17 is suspended (floating), this function measure the power voltage of VDD3P3 pin 3 and 4
214+
// For this function the vdd33_const must be set to 255 (0xFF).
204215
[107] = 33,
205216

206217
// disable RF calibration for certain number of times

Diff for: cores/esp8266/core_esp8266_wiring_pulse.c

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) {
3030
while(digitalRead(pin) == state && (micros() - start) < timeout);
3131
return micros() - start;
3232
}
33+
34+
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout) {
35+
return pulseIn(pin, state, timeout);
36+
}

Diff for: doc/eclipse/1_Install_New_Software.png

12.4 KB
Loading

Diff for: doc/eclipse/2_Install_software.png

62.4 KB
Loading

Diff for: doc/eclipse/eclipse.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Eclipse with Arduino ESP8266
2+
===========================================
3+
4+
### What to Download ###
5+
- [arduino IDE](https://www.arduino.cc/en/Main/Software)
6+
- [Eclipse IDE for C/C++ Developers](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/marsr)
7+
- [Java](http://www.java.com/)
8+
9+
### Setup Arduino ###
10+
see the [Readme](https://github.com/esp8266/Arduino#installing-with-boards-manager)
11+
12+
### Setup Eclipse ###
13+
- [step 1](http://www.baeyens.it/eclipse/how_to.shtml#/c)
14+
- [step 2](http://www.baeyens.it/eclipse/how_to.shtml#/e)
15+
- go to Window --> preferences --> Arduino
16+
- add as private hardware path the Part to the ESP8266
17+
18+
###### example private hardware path
19+
Windows: C:\Users\[username]\AppData\Roaming\Arduino15\packages\esp8266\hardware
20+
Linux: /home/[username]/.arduino15/packages/esp8266/hardware
21+
22+
### Eclipse wont build ###
23+
if eclipse dont find the path to the Compiler add to the platform.txt
24+
after:
25+
```
26+
version=1.6.4
27+
```
28+
this:
29+
```
30+
runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/../../../tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9
31+
runtime.tools.esptool.path={runtime.platform.path}/../../../tools/esptool/0.4.4
32+
```
33+
Note:
34+
- the path may changed, check the current version.
35+
- each update over the Arduino IDE will remove the fix
36+
- may not needed in future if Eclipse Plugin get an Update
37+
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <ESP8266WiFi.h>
2+
#include <DNSServer.h>
3+
#include <ESP8266WebServer.h>
4+
5+
const byte DNS_PORT = 53;
6+
IPAddress apIP(192, 168, 1, 1);
7+
DNSServer dnsServer;
8+
ESP8266WebServer webServer(80);
9+
10+
String responseHTML = ""
11+
"<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>"
12+
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
13+
"be redirected here.</p></body></html>";
14+
15+
void setup() {
16+
WiFi.mode(WIFI_AP);
17+
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
18+
WiFi.softAP("DNSServer CaptivePortal example");
19+
20+
// if DNSServer is started with "*" for domain name, it will reply with
21+
// provided IP to all DNS request
22+
dnsServer.start(DNS_PORT, "*", apIP);
23+
24+
// replay to all requests with same HTML
25+
webServer.onNotFound([]() {
26+
webServer.send(200, "text/html", responseHTML);
27+
});
28+
webServer.begin();
29+
}
30+
31+
void loop() {
32+
dnsServer.processNextRequest();
33+
webServer.handleClient();
34+
}

Diff for: libraries/DNSServer/examples/DNSServer/DNSServer.ino

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <ESP8266WiFi.h>
22
#include <DNSServer.h>
3+
#include <ESP8266WebServer.h>
34

45
const byte DNS_PORT = 53;
56
IPAddress apIP(192, 168, 1, 1);
67
DNSServer dnsServer;
8+
ESP8266WebServer webServer(80);
79

810
void setup() {
911
WiFi.mode(WIFI_AP);
@@ -19,10 +21,21 @@ void setup() {
1921
// default is DNSReplyCode::NonExistentDomain
2022
dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure);
2123

22-
//start DNS server for a specific domain name
24+
// start DNS server for a specific domain name
2325
dnsServer.start(DNS_PORT, "www.example.com", apIP);
26+
27+
// simple HTTP server to see that DNS server is working
28+
webServer.onNotFound([]() {
29+
String message = "Hello World!\n\n";
30+
message += "URI: ";
31+
message += webServer.uri();
32+
33+
webServer.send(200, "text/plain", message);
34+
});
35+
webServer.begin();
2436
}
2537

2638
void loop() {
2739
dnsServer.processNextRequest();
40+
webServer.handleClient();
2841
}

Diff for: libraries/DNSServer/library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DNSServer
2-
version=1.0.0
2+
version=1.1.0
33
author=Kristijan Novoselić
44
maintainer=Kristijan Novoselić, <kristijan.novoselic@gmail.com>
55
sentence=A simple DNS server for ESP8266.

Diff for: libraries/DNSServer/src/DNSServer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ void DNSServer::processNextRequest()
5454
if (_dnsHeader->QR == DNS_QR_QUERY &&
5555
_dnsHeader->OPCode == DNS_OPCODE_QUERY &&
5656
requestIncludesOnlyOneQuestion() &&
57-
getDomainNameWithoutWwwPrefix() == _domainName)
57+
(_domainName == "*" || getDomainNameWithoutWwwPrefix() == _domainName)
58+
)
5859
{
5960
replyWithIP();
6061
}

Diff for: libraries/DNSServer/src/DNSServer.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct DNSHeader
2727
unsigned char AA : 1; // authoritive answer
2828
unsigned char OPCode : 4; // message_type
2929
unsigned char QR : 1; // query/response flag
30-
unsigned char RCode : 4; // response code
30+
unsigned char RCode : 4; // response code
3131
unsigned char Z : 3; // its z! reserved
3232
unsigned char RA : 1; // recursion available
3333
uint16_t QDCount; // number of question entries
@@ -62,7 +62,6 @@ class DNSServer
6262
uint32_t _ttl;
6363
DNSReplyCode _errorReplyCode;
6464

65-
6665
void downcaseAndRemoveWwwPrefix(String &domainName);
6766
String getDomainNameWithoutWwwPrefix();
6867
bool requestIncludesOnlyOneQuestion();

0 commit comments

Comments
 (0)