Skip to content

Commit 38b267f

Browse files
authored
Merge branch 'master' into ota_commands_in_flash
2 parents 9377af5 + 5af402e commit 38b267f

File tree

22 files changed

+130
-164
lines changed

22 files changed

+130
-164
lines changed

README.md

+5-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ESP8266 Arduino core comes with libraries to communicate over WiFi using TCP and
1616
# Contents
1717
- Installing options:
1818
- [Using Boards Manager](#installing-with-boards-manager)
19-
- [Using git version](#using-git-version-basic-instructions)
19+
- [Using git version](#using-git-version)
2020
- [Using PlatformIO](#using-platformio)
2121
- [Building with make](#building-with-make)
2222
- [Documentation](#documentation)
@@ -38,35 +38,13 @@ Boards manager link: `https://arduino.esp8266.com/stable/package_esp8266com_inde
3838

3939
Documentation: [https://arduino-esp8266.readthedocs.io/en/2.5.2/](https://arduino-esp8266.readthedocs.io/en/2.5.2/)
4040

41-
### Using git version (basic instructions)
41+
### Using git version
4242
[![Linux build status](https://travis-ci.org/esp8266/Arduino.svg)](https://travis-ci.org/esp8266/Arduino)
4343

44+
Also known as latest git or master branch.
45+
4446
- Install the current upstream Arduino IDE at the 1.8 level or later. The current version is on the [Arduino website](https://www.arduino.cc/en/main/software).
45-
- Go to Arduino directory
46-
- For Mac OS X, it is `Arduino.app` showing as the Arduino icon.
47-
This location may be your `~/Downloads`, `~/Desktop` or even `/Applications`.
48-
```bash
49-
cd <application-directory>/Arduino.app/Contents/Java
50-
```
51-
- For Linux, it is ~/Arduino by default.
52-
```bash
53-
cd ~/Arduino
54-
```
55-
- Clone this repository into hardware/esp8266com/esp8266 directory (or clone it elsewhere and create a symlink)
56-
```bash
57-
cd hardware
58-
mkdir esp8266com
59-
cd esp8266com
60-
git clone https://github.com/esp8266/Arduino.git esp8266
61-
cd esp8266
62-
git submodule update --init
63-
```
64-
- Download binary tools (you need Python 2.7)
65-
```bash
66-
cd esp8266/tools
67-
python get.py
68-
```
69-
- Restart Arduino
47+
- Follow the [instructions in the documentation](https://arduino-esp8266.readthedocs.io/en/latest/installing.html#using-git-version).
7048

7149
### Using PlatformIO
7250

cores/esp8266/Arduino.h

-4
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,6 @@ void configTime(const char* tz, const char* server1,
285285

286286
#include "pins_arduino.h"
287287

288-
#ifndef PUYA_SUPPORT
289-
#define PUYA_SUPPORT 1
290-
#endif
291-
292288
#endif
293289

294290
#ifdef DEBUG_ESP_OOM

cores/esp8266/Esp.cpp

+23-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21-
#include "Arduino.h"
21+
#include "Esp.h"
2222
#include "flash_utils.h"
2323
#include "eboot_command.h"
2424
#include <memory>
@@ -36,6 +36,14 @@ extern struct rst_info resetInfo;
3636

3737
//#define DEBUG_SERIAL Serial
3838

39+
#ifndef PUYA_SUPPORT
40+
#define PUYA_SUPPORT 1
41+
#endif
42+
#ifndef PUYA_BUFFER_SIZE
43+
// Good alternative for buffer size is: SPI_FLASH_SEC_SIZE (= 4k)
44+
// Always use a multiple of flash page size (256 bytes)
45+
#define PUYA_BUFFER_SIZE 256
46+
#endif
3947

4048
/**
4149
* User-defined Literals
@@ -494,7 +502,7 @@ uint32_t EspClass::getSketchSize() {
494502

495503
image_header_t image_header;
496504
uint32_t pos = APP_START_OFFSET;
497-
if (spi_flash_read(pos, (uint32_t*) &image_header, sizeof(image_header))) {
505+
if (spi_flash_read(pos, (uint32_t*) &image_header, sizeof(image_header)) != SPI_FLASH_RESULT_OK) {
498506
return 0;
499507
}
500508
pos += sizeof(image_header);
@@ -506,7 +514,7 @@ uint32_t EspClass::getSketchSize() {
506514
++section_index)
507515
{
508516
section_header_t section_header = {0, 0};
509-
if (spi_flash_read(pos, (uint32_t*) &section_header, sizeof(section_header))) {
517+
if (spi_flash_read(pos, (uint32_t*) &section_header, sizeof(section_header)) != SPI_FLASH_RESULT_OK) {
510518
return 0;
511519
}
512520
pos += sizeof(section_header);
@@ -578,26 +586,27 @@ bool EspClass::flashEraseSector(uint32_t sector) {
578586
}
579587

580588
#if PUYA_SUPPORT
581-
static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
589+
static SpiFlashOpResult spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
582590
if (data == nullptr) {
583-
return 1; // SPI_FLASH_RESULT_ERR
591+
return SPI_FLASH_RESULT_ERR;
584592
}
585593
// PUYA flash chips need to read existing data, update in memory and write modified data again.
586594
static uint32_t *flash_write_puya_buf = nullptr;
587-
int rc = 0;
588-
uint32_t* ptr = data;
589595

590596
if (flash_write_puya_buf == nullptr) {
591597
flash_write_puya_buf = (uint32_t*) malloc(PUYA_BUFFER_SIZE);
592598
// No need to ever free this, since the flash chip will never change at runtime.
593599
if (flash_write_puya_buf == nullptr) {
594600
// Memory could not be allocated.
595-
return 1; // SPI_FLASH_RESULT_ERR
601+
return SPI_FLASH_RESULT_ERR;
596602
}
597603
}
604+
605+
SpiFlashOpResult rc = SPI_FLASH_RESULT_OK;
606+
uint32_t* ptr = data;
598607
size_t bytesLeft = size;
599608
uint32_t pos = offset;
600-
while (bytesLeft > 0 && rc == 0) {
609+
while (bytesLeft > 0 && rc == SPI_FLASH_RESULT_OK) {
601610
size_t bytesNow = bytesLeft;
602611
if (bytesNow > PUYA_BUFFER_SIZE) {
603612
bytesNow = PUYA_BUFFER_SIZE;
@@ -606,7 +615,7 @@ static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
606615
bytesLeft = 0;
607616
}
608617
rc = spi_flash_read(pos, flash_write_puya_buf, bytesNow);
609-
if (rc != 0) {
618+
if (rc != SPI_FLASH_RESULT_OK) {
610619
return rc;
611620
}
612621
for (size_t i = 0; i < bytesNow / 4; ++i) {
@@ -621,7 +630,7 @@ static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
621630
#endif
622631

623632
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
624-
int rc = 0;
633+
SpiFlashOpResult rc = SPI_FLASH_RESULT_OK;
625634
#if PUYA_SUPPORT
626635
if (getFlashChipVendorId() == SPI_FLASH_VENDOR_PUYA) {
627636
rc = spi_flash_write_puya(offset, data, size);
@@ -631,12 +640,12 @@ bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
631640
{
632641
rc = spi_flash_write(offset, data, size);
633642
}
634-
return rc == 0;
643+
return rc == SPI_FLASH_RESULT_OK;
635644
}
636645

637646
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {
638-
int rc = spi_flash_read(offset, (uint32_t*) data, size);
639-
return rc == 0;
647+
auto rc = spi_flash_read(offset, (uint32_t*) data, size);
648+
return rc == SPI_FLASH_RESULT_OK;
640649
}
641650

642651
String EspClass::getSketchMD5()

cores/esp8266/Esp.h

-9
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@
2323

2424
#include <Arduino.h>
2525

26-
#ifndef PUYA_SUPPORT
27-
#define PUYA_SUPPORT 0
28-
#endif
29-
#ifndef PUYA_BUFFER_SIZE
30-
// Good alternative for buffer size is: SPI_FLASH_SEC_SIZE (= 4k)
31-
// Always use a multiple of flash page size (256 bytes)
32-
#define PUYA_BUFFER_SIZE 256
33-
#endif
34-
3526
// Vendor IDs taken from Flashrom project
3627
// https://review.coreboot.org/cgit/flashrom.git/tree/flashchips.h?h=1.0.x
3728
typedef enum {

cores/esp8266/HardwareSerial.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,16 @@ int HardwareSerial::available(void)
108108

109109
void HardwareSerial::flush()
110110
{
111+
uint8_t bit_length = 0;
111112
if(!_uart || !uart_tx_enabled(_uart)) {
112113
return;
113114
}
114115

116+
bit_length = uart_get_bit_length(_uart_nr); // data width, parity and stop
115117
uart_wait_tx_empty(_uart);
116118
//Workaround for a bug in serial not actually being finished yet
117119
//Wait for 8 data bits, 1 parity and 2 stop bits, just in case
118-
delayMicroseconds(11000000 / uart_get_baudrate(_uart) + 1);
120+
delayMicroseconds(bit_length * 1000000 / uart_get_baudrate(_uart) + 1);
119121
}
120122

121123
void HardwareSerial::startDetectBaudrate()

cores/esp8266/base64.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ extern "C" {
3131

3232
/**
3333
* convert input data to base64
34-
* @param data uint8_t *
34+
* @param data const uint8_t *
3535
* @param length size_t
3636
* @return String
3737
*/
38-
String base64::encode(uint8_t * data, size_t length, bool doNewLines) {
38+
String base64::encode(const uint8_t * data, size_t length, bool doNewLines) {
3939
// base64 needs more size then the source data, use cencode.h macros
4040
size_t size = ((doNewLines ? base64_encode_expected_len(length)
4141
: base64_encode_expected_len_nonewlines(length)) + 1);
@@ -62,10 +62,10 @@ String base64::encode(uint8_t * data, size_t length, bool doNewLines) {
6262

6363
/**
6464
* convert input data to base64
65-
* @param text String
65+
* @param text const String&
6666
* @return String
6767
*/
68-
String base64::encode(String text, bool doNewLines) {
69-
return base64::encode((uint8_t *) text.c_str(), text.length(), doNewLines);
68+
String base64::encode(const String& text, bool doNewLines) {
69+
return base64::encode((const uint8_t *) text.c_str(), text.length(), doNewLines);
7070
}
7171

cores/esp8266/base64.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class base64 {
3030
// NOTE: The default behaviour of backend (lib64)
3131
// is to add a newline every 72 (encoded) characters output.
3232
// This may 'break' longer uris and json variables
33-
static String encode(uint8_t * data, size_t length, bool doNewLines = true);
34-
static String encode(String text, bool doNewLines = true);
33+
static String encode(const uint8_t * data, size_t length, bool doNewLines = true);
34+
static String encode(const String& text, bool doNewLines = true);
3535
private:
3636
};
3737

cores/esp8266/cont.S

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21-
.text
21+
.section .irom0.text
2222
.align 4
2323
.literal_position
2424
.global cont_yield
@@ -84,7 +84,7 @@ cont_wrapper:
8484

8585
////////////////////////////////////////////////////
8686

87-
.text
87+
.section .irom0.text
8888
.align 4
8989
.literal_position
9090
.global cont_run

cores/esp8266/coredecls.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ extern bool timeshift64_is_set;
1717
void esp_yield();
1818
void esp_schedule();
1919
void tune_timeshift64 (uint64_t now_us);
20-
void settimeofday_cb (void (*cb)(void));
2120
void disable_extra4k_at_link_time (void) __attribute__((noinline));
2221

2322
uint32_t sqrt32 (uint32_t n);
2423
uint32_t crc32 (const void* data, size_t length, uint32_t crc = 0xffffffff);
2524

2625
#ifdef __cplusplus
2726
}
27+
28+
#include <functional>
29+
30+
using TrivialCB = std::function<void()>;
31+
32+
void settimeofday_cb (TrivialCB&& cb);
33+
void settimeofday_cb (const TrivialCB& cb);
34+
2835
#endif
2936

3037
#endif // __COREDECLS_H

cores/esp8266/sntp-lwip2.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,22 @@
4242
#include <osapi.h>
4343
#include <os_type.h>
4444
#include "coredecls.h"
45+
#include "Schedule.h"
4546

46-
extern "C" {
47+
static TrivialCB _settimeofday_cb;
4748

48-
static void (*_settimeofday_cb)(void) = NULL;
49+
void settimeofday_cb (TrivialCB&& cb)
50+
{
51+
_settimeofday_cb = std::move(cb);
52+
}
4953

50-
void settimeofday_cb (void (*cb)(void))
54+
void settimeofday_cb (const TrivialCB& cb)
5155
{
5256
_settimeofday_cb = cb;
5357
}
5458

59+
extern "C" {
60+
5561
#if LWIP_VERSION_MAJOR == 1
5662

5763
#include <pgmspace.h>
@@ -478,7 +484,7 @@ int settimeofday(const struct timeval* tv, const struct timezone* tz)
478484
sntp_set_system_time(tv->tv_sec);
479485

480486
if (_settimeofday_cb)
481-
_settimeofday_cb();
487+
schedule_function(_settimeofday_cb);
482488
}
483489
return 0;
484490
}

cores/esp8266/uart.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
#include "user_interface.h"
4949
#include "uart_register.h"
5050

51+
#define MODE2WIDTH(mode) (((mode%16)>>2)+5)
52+
#define MODE2STOP(mode) (((mode)>>5)+1)
53+
#define MODE2PARITY(mode) (mode%4)
54+
5155
/*
5256
Some general architecture for GDB integration with the UART to enable
5357
serial debugging.
@@ -204,7 +208,14 @@ uart_read_char_unsafe(uart_t* uart)
204208
return -1;
205209
}
206210

207-
size_t
211+
uint8_t
212+
uart_get_bit_length(const int uart_nr)
213+
{
214+
// return bit length from uart mode, +1 for the start bit which is always there.
215+
return MODE2WIDTH(USC0(uart_nr)) + MODE2PARITY(USC0(uart_nr)) + MODE2STOP(USC0(uart_nr)) + 1;
216+
}
217+
218+
size_t
208219
uart_rx_available(uart_t* uart)
209220
{
210221
if(uart == NULL || !uart->rx_enabled)

cores/esp8266/uart.h

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ int uart_get_debug();
147147
void uart_start_detect_baudrate(int uart_nr);
148148
int uart_detect_baudrate(int uart_nr);
149149

150+
uint8_t uart_get_bit_length(const int uart_nr);
150151

151152
#if defined (__cplusplus)
152153
} // extern "C"

0 commit comments

Comments
 (0)