Skip to content

Commit 5163391

Browse files
committed
Merge branch 'master' into espino-support
2 parents 8847d7a + 93aaa86 commit 5163391

File tree

13 files changed

+178
-59
lines changed

13 files changed

+178
-59
lines changed

cores/esp8266/Arduino.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,12 @@ void loop(void);
219219
void yield(void);
220220
void optimistic_yield(uint32_t interval_us);
221221

222-
// Get the bit location within the hardware port of the given virtual pin.
223-
// This comes from the pins_*.c file for the active board configuration.
224222
#define digitalPinToPort(pin) (0)
225223
#define digitalPinToBitMask(pin) (1UL << (pin))
226224
#define digitalPinToTimer(pin) (0)
227-
#define portOutputRegister(port) ((volatile uint32_t*) GPO)
228-
#define portInputRegister(port) ((volatile uint32_t*) GPI)
229-
#define portModeRegister(port) ((volatile uint32_t*) GPE)
225+
#define portOutputRegister(port) ((volatile uint32_t*) &GPO)
226+
#define portInputRegister(port) ((volatile uint32_t*) &GPI)
227+
#define portModeRegister(port) ((volatile uint32_t*) &GPE)
230228

231229
#define NOT_A_PIN -1
232230
#define NOT_A_PORT -1

cores/esp8266/HardwareSerial.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,18 +617,15 @@ size_t HardwareSerial::write(uint8_t c) {
617617
size_t room = uart_get_tx_fifo_room(_uart);
618618
if(room > 0 && _tx_buffer->empty()) {
619619
uart_transmit_char(_uart, c);
620-
if(room < 10) {
621-
uart_arm_tx_interrupt(_uart);
622-
}
623620
return 1;
624621
}
625622

626623
while(_tx_buffer->room() == 0) {
627624
yield();
628-
uart_arm_tx_interrupt(_uart);
629625
}
630626

631627
_tx_buffer->write(c);
628+
uart_arm_tx_interrupt(_uart);
632629
return 1;
633630
}
634631

cores/esp8266/Updater.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class UpdaterClass {
2626
Call this to check the space needed for the update
2727
Will return false if there is not enough space
2828
*/
29-
bool begin(size_t size, int = U_FLASH);
29+
bool begin(size_t size, int command = U_FLASH);
3030

3131
/*
3232
Writes a buffer to the flash and increments the address

cores/esp8266/abi.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ void __throw_length_error(char const*) {
6868
void __throw_bad_alloc() {
6969
panic();
7070
}
71+
72+
void __throw_logic_error(const char* str) {
73+
panic();
74+
}
7175
}
7276

7377
// TODO: rebuild windows toolchain to make this unnecessary:

cores/esp8266/cbuf.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ class cbuf {
4242
if(_end >= _begin) {
4343
return _size - (_end - _begin) - 1;
4444
}
45-
if(_begin == _end) {
46-
return _size;
47-
}
4845
return _begin - _end - 1;
4946
}
5047

@@ -62,7 +59,7 @@ class cbuf {
6259
if(getSize() == 0) return -1;
6360

6461
char result = *_begin;
65-
if(++_begin == _bufend) _begin = _buf;
62+
_begin = wrap_if_bufend(_begin + 1);
6663
return static_cast<int>(result);
6764
}
6865

@@ -78,16 +75,15 @@ class cbuf {
7875
dst += top_size;
7976
}
8077
memcpy(dst, _begin, size_to_read);
81-
_begin += size_to_read;
82-
if(_begin == _bufend) _begin = _buf;
78+
_begin = wrap_if_bufend(_begin + size_to_read);
8379
return size_read;
8480
}
8581

8682
size_t write(char c) {
8783
if(room() == 0) return 0;
8884

8985
*_end = c;
90-
if(++_end == _bufend) _end = _buf;
86+
_end = wrap_if_bufend(_end + 1);
9187
return 1;
9288
}
9389

@@ -103,8 +99,7 @@ class cbuf {
10399
src += top_size;
104100
}
105101
memcpy(_end, src, size_to_write);
106-
_end += size_to_write;
107-
if(_end == _bufend) _end = _buf;
102+
_end = wrap_if_bufend(_end + size_to_write);
108103
return size_written;
109104
}
110105

@@ -114,6 +109,10 @@ class cbuf {
114109
}
115110

116111
private:
112+
inline char* wrap_if_bufend(char* ptr) {
113+
return (ptr == _bufend) ? _buf : ptr;
114+
}
115+
117116
size_t _size;
118117
char* _buf;
119118
char* _bufend;

cores/esp8266/esp8266_peri.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ extern uint8_t esp8266_gpioToFn[16];
494494

495495
//SPI Phase Length Locations
496496
#define SPILCOMMAND 28 //4 bit in SPIxU2 default 7 (8bit)
497-
#define SPILADDR 16 //6 bit in SPIxU1 default:23 (24bit)
497+
#define SPILADDR 26 //6 bit in SPIxU1 default:23 (24bit)
498498
#define SPILDUMMY 0 //8 bit in SPIxU1 default:0 (0 cycles)
499499
#define SPILMISO 8 //9 bit in SPIxU1 default:0 (1bit)
500500
#define SPILMOSI 17 //9 bit in SPIxU1 default:0 (1bit)

cores/esp8266/pgmspace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
7878
(__extension__({ \
7979
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
8080
ptrdiff_t __offset = ((uint32_t)__local & 0x00000003); /* byte aligned mask */ \
81-
const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local)-__offset); \
81+
const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local)-__offset); \
8282
uint8_t __result = ((*__addr32) >> (__offset * 8)); \
8383
__result; \
8484
}))
@@ -87,7 +87,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
8787
(__extension__({ \
8888
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
8989
ptrdiff_t __offset = ((uint32_t)__local & 0x00000002); /* word aligned mask */ \
90-
const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local) - __offset); \
90+
const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local) - __offset); \
9191
uint16_t __result = ((*__addr32) >> (__offset * 8)); \
9292
__result; \
9393
}))

cores/esp8266/spiffs_api.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,17 @@ class SPIFFSDirImpl : public DirImpl {
410410
FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode) {
411411
int mode = getSpiffsMode(openMode, accessMode);
412412
int fd = SPIFFS_open(&_fs, path, mode, 0);
413+
if (fd < 0 && _fs.err_code == SPIFFS_ERR_DELETED && (openMode & OM_CREATE)) {
414+
DEBUGV("SPIFFSImpl::open: fd=%d path=`%s` openMode=%d accessMode=%d err=%d, trying to remove\r\n",
415+
fd, path, openMode, accessMode, _fs.err_code);
416+
auto rc = SPIFFS_remove(&_fs, path);
417+
if (rc != SPIFFS_OK) {
418+
DEBUGV("SPIFFSImpl::open: SPIFFS_ERR_DELETED, but failed to remove path=`%s` openMode=%d accessMode=%d err=%d\r\n",
419+
path, openMode, accessMode, _fs.err_code);
420+
return FileImplPtr();
421+
}
422+
fd = SPIFFS_open(&_fs, path, mode, 0);
423+
}
413424
if (fd < 0) {
414425
DEBUGV("SPIFFSImpl::open: fd=%d path=`%s` openMode=%d accessMode=%d err=%d\r\n",
415426
fd, path, openMode, accessMode, _fs.err_code);

doc/eclipse/makefile.init

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
vecho := @echo
2+
Q := @
3+
4+
PROJECT_NAME=project_name
5+
6+
OTA_IP=192.168.254.100
7+
OTA_PORT=8266
8+
9+
SERIAL_PORT=COM3
10+
SERIAL_BAUD=230400
11+
12+
ARDUINO_BASE = D:/Coding/avr/Programme/arduino-nightly
13+
ESP8266_BASE = $(ARDUINO_BASE)/hardware/esp8266com/esp8266
14+
ESP8266_TOOLS = $(ESP8266_BASE)/tools
15+
XTENSA_TOOLS_ROOT = $(ESP8266_TOOLS)/xtensa-lx106-elf/bin
16+
17+
PYTHON_BIN = python
18+
ESPTOOL_PY_BIN = $(ESP8266_TOOLS)/esptool.py
19+
ESPOTA_PY_BIN = $(ESP8266_TOOLS)/espota.py
20+
ESPTOOL_BIN = $(ESP8266_TOOLS)/esptool/esptool.exe
21+
22+
ota:
23+
$(vecho) ota...
24+
$(PYTHON_BIN) $(ESPOTA_PY_BIN) -i $(OTA_IP) -p $(OTA_PORT) --auth= -f ./$(PROJECT_NAME).bin
25+
26+
ota_spiffs:
27+
$(vecho) ota spiffs...
28+
$(PYTHON_BIN) $(ESPOTA_PY_BIN) -i $(OTA_IP) -p $(OTA_PORT) --auth= -s -f ./$(PROJECT_NAME)_spiffs.bin
29+
30+
erase_flash:
31+
$(vecho) "Erase Flash"
32+
$(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(SERIAL_PORT) -b $(SERIAL_BAUD) erase_flash
33+
34+
dumpmem:
35+
$(vecho) "Read Flash need some time..."
36+
$(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(SERIAL_PORT) -b $(SERIAL_BAUD) read_flash 0 4194304 dump.bin
37+
38+
objdump:
39+
"$(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump" -S $(PROJECT_NAME).elf > $(PROJECT_NAME).dobj

libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ void loop() {
7171
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
7272
"Host: " + host + "\r\n" +
7373
"Connection: close\r\n\r\n");
74-
delay(10);
74+
int timeout = millis() + 5000;
75+
while (client.available() == 0) {
76+
if (timeout - millis() < 0) {
77+
Serial.println(">>> Client Timeout !");
78+
client.stop();
79+
return;
80+
}
81+
}
7582

7683
// Read all the lines of the reply from server and print them to Serial
7784
while(client.available()){
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This sketch sends a message to a TCP server
3+
*
4+
*/
5+
6+
#include <ESP8266WiFi.h>
7+
#include <ESP8266WiFiMulti.h>
8+
9+
ESP8266WiFiMulti WiFiMulti;
10+
11+
void setup() {
12+
Serial.begin(115200);
13+
delay(10);
14+
15+
// We start by connecting to a WiFi network
16+
WiFiMulti.addAP("SSID", "passpasspass");
17+
18+
Serial.println();
19+
Serial.println();
20+
Serial.print("Wait for WiFi... ");
21+
22+
while(WiFiMulti.run() != WL_CONNECTED) {
23+
Serial.print(".");
24+
delay(500);
25+
}
26+
27+
Serial.println("");
28+
Serial.println("WiFi connected");
29+
Serial.println("IP address: ");
30+
Serial.println(WiFi.localIP());
31+
32+
delay(500);
33+
}
34+
35+
36+
void loop() {
37+
const uint16_t port = 80;
38+
const char * host = "192.168.1.1"; // ip or dns
39+
40+
41+
42+
Serial.print("connecting to ");
43+
Serial.println(host);
44+
45+
// Use WiFiClient class to create TCP connections
46+
WiFiClient client;
47+
48+
if (!client.connect(host, port)) {
49+
Serial.println("connection failed");
50+
Serial.println("wait 5 sec...");
51+
delay(5000);
52+
return;
53+
}
54+
55+
// This will send the request to the server
56+
client.print("Send this data to server");
57+
58+
//read back one line from server
59+
String line = client.readStringUntil('\r');
60+
client.println(line);
61+
62+
Serial.println("closing connection");
63+
client.stop();
64+
65+
Serial.println("wait 5 sec...");
66+
delay(5000);
67+
}
68+

0 commit comments

Comments
 (0)