Skip to content

Commit 5653b9a

Browse files
committed
Merge remote-tracking branch 'refs/remotes/upstream/master'
2 parents 1891241 + e7024fb commit 5653b9a

Some content is hidden

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

45 files changed

+1051
-972
lines changed

boards.txt

-818
This file was deleted.

cores/esp8266/Arduino.h

+3-5
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

+1-4
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.cpp

+45-25
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ void UpdaterClass::_reset() {
3838
bool UpdaterClass::begin(size_t size, int command) {
3939
if(_size > 0){
4040
#ifdef DEBUG_UPDATER
41-
DEBUG_UPDATER.println("already running");
41+
DEBUG_UPDATER.println("[begin] already running");
4242
#endif
4343
return false;
4444
}
4545

4646
#ifdef DEBUG_UPDATER
4747
if (command == U_SPIFFS) {
48-
DEBUG_UPDATER.println("Update SPIFFS.");
48+
DEBUG_UPDATER.println("[begin] Update SPIFFS.");
4949
}
5050
#endif
5151

@@ -73,6 +73,12 @@ bool UpdaterClass::begin(size_t size, int command) {
7373
//address where we will start writing the update
7474
updateStartAddress = updateEndAddress - roundedSize;
7575

76+
#ifdef DEBUG_UPDATER
77+
DEBUG_UPDATER.printf("[begin] roundedSize: 0x%08X (%d)\n", roundedSize, roundedSize);
78+
DEBUG_UPDATER.printf("[begin] updateEndAddress: 0x%08X (%d)\n", updateEndAddress, updateEndAddress);
79+
DEBUG_UPDATER.printf("[begin] currentSketchSize: 0x%08X (%d)\n", currentSketchSize, currentSketchSize);
80+
#endif
81+
7682
//make sure that the size of both sketches is less than the total space (updateEndAddress)
7783
if(updateStartAddress < currentSketchSize) {
7884
_error = UPDATE_ERROR_SPACE;
@@ -88,7 +94,7 @@ bool UpdaterClass::begin(size_t size, int command) {
8894
else {
8995
// unknown command
9096
#ifdef DEBUG_UPDATER
91-
DEBUG_UPDATER.println("Unknown update command.");
97+
DEBUG_UPDATER.println("[begin] Unknown update command.");
9298
#endif
9399
return false;
94100
}
@@ -100,6 +106,12 @@ bool UpdaterClass::begin(size_t size, int command) {
100106
_buffer = new uint8_t[FLASH_SECTOR_SIZE];
101107
_command = command;
102108

109+
#ifdef DEBUG_UPDATER
110+
DEBUG_UPDATER.printf("[begin] _startAddress: 0x%08X (%d)\n", _startAddress, _startAddress);
111+
DEBUG_UPDATER.printf("[begin] _currentAddress: 0x%08X (%d)\n", _currentAddress, _currentAddress);
112+
DEBUG_UPDATER.printf("[begin] _size: 0x%08X (%d)\n", _size, _size);
113+
#endif
114+
103115
_md5.begin();
104116
return true;
105117
}
@@ -168,9 +180,14 @@ bool UpdaterClass::end(bool evenIfRemaining){
168180
}
169181

170182
bool UpdaterClass::_writeBuffer(){
183+
184+
yield();
185+
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE);
186+
yield();
187+
if (result) {
188+
result = ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
189+
}
171190
yield();
172-
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE) &&
173-
ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
174191

175192
if (!result) {
176193
_error = UPDATE_ERROR_WRITE;
@@ -217,29 +234,32 @@ size_t UpdaterClass::write(uint8_t *data, size_t len) {
217234
}
218235

219236
size_t UpdaterClass::writeStream(Stream &data) {
220-
size_t written = 0;
221-
size_t toRead = 0;
222-
if(hasError() || !isRunning())
223-
return 0;
224-
225-
while(remaining()) {
226-
toRead = FLASH_SECTOR_SIZE - _bufferLen;
227-
toRead = data.readBytes(_buffer + _bufferLen, toRead);
228-
if(toRead == 0){ //Timeout
229-
_error = UPDATE_ERROR_STREAM;
230-
_currentAddress = (_startAddress + _size);
237+
size_t written = 0;
238+
size_t toRead = 0;
239+
if(hasError() || !isRunning())
240+
return 0;
241+
242+
while(remaining()) {
243+
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
244+
if(toRead == 0) { //Timeout
245+
delay(100);
246+
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
247+
if(toRead == 0) { //Timeout
248+
_error = UPDATE_ERROR_STREAM;
249+
_currentAddress = (_startAddress + _size);
231250
#ifdef DEBUG_UPDATER
232-
printError(DEBUG_UPDATER);
251+
printError(DEBUG_UPDATER);
233252
#endif
234-
return written;
253+
}
254+
return written;
255+
}
256+
_bufferLen += toRead;
257+
if((_bufferLen == remaining() || _bufferLen == FLASH_SECTOR_SIZE) && !_writeBuffer())
258+
return written;
259+
written += toRead;
260+
yield();
235261
}
236-
_bufferLen += toRead;
237-
if((_bufferLen == remaining() || _bufferLen == FLASH_SECTOR_SIZE) && !_writeBuffer())
238-
return written;
239-
written += toRead;
240-
yield();
241-
}
242-
return written;
262+
return written;
243263
}
244264

245265
void UpdaterClass::printError(Stream &out){

cores/esp8266/Updater.h

+1-1
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/WString.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ ICACHE_FLASH_ATTR String::~String() {
121121
if(buffer) {
122122
free(buffer);
123123
}
124+
init();
124125
}
125126

126127
// /*********************************************/
@@ -136,8 +137,7 @@ inline void String::init(void) {
136137
void ICACHE_FLASH_ATTR String::invalidate(void) {
137138
if(buffer)
138139
free(buffer);
139-
buffer = NULL;
140-
capacity = len = 0;
140+
init();
141141
}
142142

143143
unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size) {

cores/esp8266/WString.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ class String {
7676
// invalid string (i.e., "if (s)" will be true afterwards)
7777
unsigned char reserve(unsigned int size);
7878
inline unsigned int length(void) const {
79-
return len;
79+
if(buffer) {
80+
return len;
81+
} else {
82+
return 0;
83+
}
8084
}
8185

8286
// creates a copy of the assigned value. if the value is null or

cores/esp8266/abi.cpp

+4
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/base64.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* base64.cpp
3+
*
4+
* Created on: 09.12.2015
5+
*
6+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
7+
* This file is part of the ESP8266 core for Arduino.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*
23+
*/
24+
25+
#include "Arduino.h"
26+
extern "C" {
27+
#include "libb64/cdecode.h"
28+
#include "libb64/cencode.h"
29+
}
30+
#include "base64.h"
31+
32+
/**
33+
* convert input data to base64
34+
* @param data uint8_t *
35+
* @param length size_t
36+
* @return String
37+
*/
38+
String base64::encode(uint8_t * data, size_t length) {
39+
// base64 needs more size then the source data
40+
size_t size = ((length * 1.6f) + 1);
41+
char * buffer = (char *) malloc(size);
42+
if(buffer) {
43+
base64_encodestate _state;
44+
base64_init_encodestate(&_state);
45+
int len = base64_encode_block((const char *) &data[0], length, &buffer[0], &_state);
46+
len = base64_encode_blockend((buffer + len), &_state);
47+
48+
String base64 = String(buffer);
49+
free(buffer);
50+
return base64;
51+
}
52+
return String("-FAIL-");
53+
}
54+
55+
/**
56+
* convert input data to base64
57+
* @param text String
58+
* @return String
59+
*/
60+
String base64::encode(String text) {
61+
return base64::encode((uint8_t *) text.c_str(), text.length());
62+
}
63+

cores/esp8266/base64.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* base64.h
3+
*
4+
* Created on: 09.12.2015
5+
*
6+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
7+
* This file is part of the ESP8266 core for Arduino.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*
23+
*/
24+
25+
#ifndef CORE_BASE64_H_
26+
#define CORE_BASE64_H_
27+
28+
class base64 {
29+
public:
30+
static String encode(uint8_t * data, size_t length);
31+
static String encode(String text);
32+
private:
33+
};
34+
35+
36+
#endif /* CORE_BASE64_H_ */

cores/esp8266/cbuf.h

+8-9
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;

0 commit comments

Comments
 (0)