Skip to content

Commit 2b49e7a

Browse files
Merge branch 'master' into SDFS
2 parents 241d0ff + 187f6a5 commit 2b49e7a

Some content is hidden

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

63 files changed

+1002
-533
lines changed

.travis.yml

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,70 @@ stages:
2020
jobs:
2121
include:
2222
# Build stage. To save time, run all kinds of builds and tests in parallel.
23-
- name: "Host tests"
23+
24+
- name: "Platformio (1)"
2425
stage: build
25-
script: $TRAVIS_BUILD_DIR/tests/ci/host_test.sh
26-
install: sudo apt-get install valgrind lcov
26+
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
27+
env:
28+
- BUILD_PARITY=even
29+
- name: "Platformio (2)"
30+
stage: build
31+
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
32+
env:
33+
- BUILD_PARITY=odd
2734

28-
# TODO: since we can now call different script for each job,
29-
# split the do-it-all common.sh into separate scripts responsible
30-
# for different types of jobs below:
3135
- name: "Build (1)"
32-
script: $TRAVIS_BUILD_DIR/tests/common.sh
36+
stage: build
37+
script: $TRAVIS_BUILD_DIR/tests/build.sh
3338
env:
34-
- BUILD_TYPE=build_even
39+
- BUILD_PARITY=even
3540
- name: "Build (2)"
36-
script: $TRAVIS_BUILD_DIR/tests/common.sh
41+
stage: build
42+
script: $TRAVIS_BUILD_DIR/tests/build.sh
3743
env:
38-
- BUILD_TYPE=build_odd
44+
- BUILD_PARITY=odd
45+
3946
- name: "Debug (1)"
40-
script: $TRAVIS_BUILD_DIR/tests/common.sh
47+
stage: build
48+
script: $TRAVIS_BUILD_DIR/tests/debug.sh
4149
env:
42-
- BUILD_TYPE=debug_even
50+
- BUILD_PARITY=even
4351
- name: "Debug (2)"
44-
script: $TRAVIS_BUILD_DIR/tests/common.sh
52+
stage: build
53+
script: $TRAVIS_BUILD_DIR/tests/debug.sh
4554
env:
46-
- BUILD_TYPE=debug_odd
47-
- name: "Platformio (1)"
48-
script: $TRAVIS_BUILD_DIR/tests/common.sh
55+
- BUILD_PARITY=odd
56+
57+
- name: "Build IPv6 (1)"
58+
stage: build
59+
script: $TRAVIS_BUILD_DIR/tests/build6.sh
4960
env:
50-
- BUILD_TYPE=platformio_even
51-
- name: "Platformio (2)"
52-
script: $TRAVIS_BUILD_DIR/tests/common.sh
61+
- BUILD_PARITY=even
62+
- name: "Build IPv6 (2)"
63+
stage: build
64+
script: $TRAVIS_BUILD_DIR/tests/build6.sh
5365
env:
54-
- BUILD_TYPE=platformio_odd
66+
- BUILD_PARITY=odd
67+
68+
- name: "Host tests"
69+
stage: build
70+
script: $TRAVIS_BUILD_DIR/tests/ci/host_test.sh
71+
install: sudo apt-get install valgrind lcov
5572

5673
- name: "Docs"
74+
stage: build
5775
script: $TRAVIS_BUILD_DIR/tests/ci/build_docs.sh
5876
install:
5977
- sudo apt-get install python3-pip
6078
- pip3 install --user -r doc/requirements.txt;
6179

6280
- name: "Style check"
81+
stage: build
6382
script: $TRAVIS_BUILD_DIR/tests/ci/style_check.sh
6483
install: tests/ci/install_astyle.sh
6584

6685
- name: "Boards"
86+
stage: build
6787
script: $TRAVIS_BUILD_DIR/tests/ci/build_boards.sh
6888

6989
# Deploy stage.

boards.txt

Lines changed: 120 additions & 120 deletions
Large diffs are not rendered by default.

cores/esp8266/Esp.cpp

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,18 @@ uint64_t EspClass::deepSleepMax()
132132

133133
}
134134

135-
/*
135+
/*
136136
Layout of RTC Memory is as follows:
137137
Ref: Espressif doc 2C-ESP8266_Non_OS_SDK_API_Reference, section 3.3.23 (system_rtc_mem_write)
138138
139139
|<------system data (256 bytes)------->|<-----------------user data (512 bytes)--------------->|
140140
141-
SDK function signature:
141+
SDK function signature:
142142
bool system_rtc_mem_read (
143-
uint32 des_addr,
144-
void * src_addr,
143+
uint32 des_addr,
144+
void * src_addr,
145145
uint32 save_size
146-
)
146+
)
147147
148148
The system data section can't be used by the user, so:
149149
des_addr must be >=64 (i.e.: 256/4) and <192 (i.e.: 768/4)
@@ -160,7 +160,7 @@ Same for write
160160
Note: If the Updater class is in play, e.g.: the application uses OTA, the eboot
161161
command will be stored into the first 128 bytes of user data, then it will be
162162
retrieved by eboot on boot. That means that user data present there will be lost.
163-
Ref:
163+
Ref:
164164
- discussion in PR #5330.
165165
- https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers
166166
- Arduino/bootloaders/eboot/eboot_command.h RTC_MEM definition
@@ -266,7 +266,16 @@ uint8_t EspClass::getCpuFreqMHz(void)
266266

267267
uint32_t EspClass::getFlashChipId(void)
268268
{
269-
return spi_flash_get_id();
269+
static uint32_t flash_chip_id = 0;
270+
if (flash_chip_id == 0) {
271+
flash_chip_id = spi_flash_get_id();
272+
}
273+
return flash_chip_id;
274+
}
275+
276+
uint8_t EspClass::getFlashChipVendorId(void)
277+
{
278+
return (getFlashChipId() & 0x000000ff);
270279
}
271280

272281
uint32_t EspClass::getFlashChipRealSize(void)
@@ -569,9 +578,61 @@ bool EspClass::flashEraseSector(uint32_t sector) {
569578
return rc == 0;
570579
}
571580

581+
#if PUYA_SUPPORT
582+
static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
583+
if (data == nullptr) {
584+
return 1; // SPI_FLASH_RESULT_ERR
585+
}
586+
// PUYA flash chips need to read existing data, update in memory and write modified data again.
587+
static uint32_t *flash_write_puya_buf = nullptr;
588+
int rc = 0;
589+
uint32_t* ptr = data;
590+
591+
if (flash_write_puya_buf == nullptr) {
592+
flash_write_puya_buf = (uint32_t*) malloc(PUYA_BUFFER_SIZE);
593+
// No need to ever free this, since the flash chip will never change at runtime.
594+
if (flash_write_puya_buf == nullptr) {
595+
// Memory could not be allocated.
596+
return 1; // SPI_FLASH_RESULT_ERR
597+
}
598+
}
599+
size_t bytesLeft = size;
600+
uint32_t pos = offset;
601+
while (bytesLeft > 0 && rc == 0) {
602+
size_t bytesNow = bytesLeft;
603+
if (bytesNow > PUYA_BUFFER_SIZE) {
604+
bytesNow = PUYA_BUFFER_SIZE;
605+
bytesLeft -= PUYA_BUFFER_SIZE;
606+
} else {
607+
bytesLeft = 0;
608+
}
609+
rc = spi_flash_read(pos, flash_write_puya_buf, bytesNow);
610+
if (rc != 0) {
611+
return rc;
612+
}
613+
for (size_t i = 0; i < bytesNow / 4; ++i) {
614+
flash_write_puya_buf[i] &= *ptr;
615+
++ptr;
616+
}
617+
rc = spi_flash_write(pos, flash_write_puya_buf, bytesNow);
618+
pos += bytesNow;
619+
}
620+
return rc;
621+
}
622+
#endif
623+
572624
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
573625
ets_isr_mask(FLASH_INT_MASK);
574-
int rc = spi_flash_write(offset, (uint32_t*) data, size);
626+
int rc = 0;
627+
#if PUYA_SUPPORT
628+
if (getFlashChipVendorId() == SPI_FLASH_VENDOR_PUYA) {
629+
rc = spi_flash_write_puya(offset, data, size);
630+
}
631+
else
632+
#endif
633+
{
634+
rc = spi_flash_write(offset, data, size);
635+
}
575636
ets_isr_unmask(FLASH_INT_MASK);
576637
return rc == 0;
577638
}

cores/esp8266/Esp.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,52 @@
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+
35+
// Vendor IDs taken from Flashrom project
36+
// https://review.coreboot.org/cgit/flashrom.git/tree/flashchips.h?h=1.0.x
37+
typedef enum {
38+
SPI_FLASH_VENDOR_ALLIANCE = 0x52, /* Alliance Semiconductor */
39+
SPI_FLASH_VENDOR_AMD = 0x01, /* AMD */
40+
SPI_FLASH_VENDOR_AMIC = 0x37, /* AMIC */
41+
SPI_FLASH_VENDOR_ATMEL = 0x1F, /* Atmel (now used by Adesto) */
42+
SPI_FLASH_VENDOR_BRIGHT = 0xAD, /* Bright Microelectronics */
43+
SPI_FLASH_VENDOR_CATALYST = 0x31, /* Catalyst */
44+
SPI_FLASH_VENDOR_EON = 0x1C, /* EON Silicon Devices, missing 0x7F prefix */
45+
SPI_FLASH_VENDOR_ESMT = 0x8C, /* Elite Semiconductor Memory Technology (ESMT) / EFST Elite Flash Storage */
46+
SPI_FLASH_VENDOR_EXCEL = 0x4A, /* ESI, missing 0x7F prefix */
47+
SPI_FLASH_VENDOR_FIDELIX = 0xF8, /* Fidelix */
48+
SPI_FLASH_VENDOR_FUJITSU = 0x04, /* Fujitsu */
49+
SPI_FLASH_VENDOR_GIGADEVICE = 0xC8, /* GigaDevice */
50+
SPI_FLASH_VENDOR_HYUNDAI = 0xAD, /* Hyundai */
51+
SPI_FLASH_VENDOR_INTEL = 0x89, /* Intel */
52+
SPI_FLASH_VENDOR_ISSI = 0xD5, /* ISSI Integrated Silicon Solutions, see also PMC. */
53+
SPI_FLASH_VENDOR_MACRONIX = 0xC2, /* Macronix (MX) */
54+
SPI_FLASH_VENDOR_NANTRONICS = 0xD5, /* Nantronics, missing prefix */
55+
SPI_FLASH_VENDOR_PMC = 0x9D, /* PMC, missing 0x7F prefix */
56+
SPI_FLASH_VENDOR_PUYA = 0x85, /* Puya semiconductor (shanghai) co. ltd */
57+
SPI_FLASH_VENDOR_SANYO = 0x62, /* Sanyo */
58+
SPI_FLASH_VENDOR_SHARP = 0xB0, /* Sharp */
59+
SPI_FLASH_VENDOR_SPANSION = 0x01, /* Spansion, same ID as AMD */
60+
SPI_FLASH_VENDOR_SST = 0xBF, /* SST */
61+
SPI_FLASH_VENDOR_ST = 0x20, /* ST / SGS/Thomson / Numonyx (later acquired by Micron) */
62+
SPI_FLASH_VENDOR_SYNCMOS_MVC = 0x40, /* SyncMOS (SM) and Mosel Vitelic Corporation (MVC) */
63+
SPI_FLASH_VENDOR_TENX = 0x5E, /* Tenx Technologies */
64+
SPI_FLASH_VENDOR_TI = 0x97, /* Texas Instruments */
65+
SPI_FLASH_VENDOR_TI_OLD = 0x01, /* TI chips from last century */
66+
SPI_FLASH_VENDOR_WINBOND = 0xDA, /* Winbond */
67+
SPI_FLASH_VENDOR_WINBOND_NEX = 0xEF, /* Winbond (ex Nexcom) serial flashes */
68+
69+
SPI_FLASH_VENDOR_UNKNOWN = 0xFF
70+
} SPI_FLASH_VENDOR_t;
71+
2672
/**
2773
* AVR macros for WDT managment
2874
*/
@@ -123,6 +169,8 @@ class EspClass {
123169
uint8_t getCpuFreqMHz();
124170

125171
uint32_t getFlashChipId();
172+
uint8_t getFlashChipVendorId();
173+
126174
//gets the actual chip size based on the flash id
127175
uint32_t getFlashChipRealSize();
128176
//gets the size of the flash as set by the compiler

cores/esp8266/HardwareSerial.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <stdio.h>
2828
#include <string.h>
2929
#include <inttypes.h>
30+
#include <PolledTimeout.h>
3031
#include "Arduino.h"
3132
#include "HardwareSerial.h"
3233
#include "Esp.h"
@@ -132,6 +133,22 @@ unsigned long HardwareSerial::detectBaudrate(time_t timeoutMillis)
132133
return detectedBaudrate;
133134
}
134135

136+
size_t HardwareSerial::readBytes(char* buffer, size_t size)
137+
{
138+
size_t got = 0;
139+
140+
while (got < size)
141+
{
142+
esp8266::polledTimeout::oneShot timeOut(_timeout);
143+
size_t avail;
144+
while ((avail = available()) == 0 && !timeOut);
145+
if (avail == 0)
146+
break;
147+
got += read(buffer + got, std::min(size - got, avail));
148+
}
149+
return got;
150+
}
151+
135152
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
136153
HardwareSerial Serial(UART0);
137154
#endif

cores/esp8266/HardwareSerial.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ class HardwareSerial: public Stream
132132
// return -1 when data is unvailable (arduino api)
133133
return uart_read_char(_uart);
134134
}
135-
size_t readBytes(char* buffer, size_t size) override
135+
// ::read(buffer, size): same as readBytes without timeout
136+
size_t read(char* buffer, size_t size)
136137
{
137138
return uart_read(_uart, buffer, size);
138139
}
140+
size_t readBytes(char* buffer, size_t size) override;
139141
size_t readBytes(uint8_t* buffer, size_t size) override
140142
{
141-
return uart_read(_uart, (char*)buffer, size);
143+
return readBytes((char*)buffer, size);
142144
}
143145
int availableForWrite(void)
144146
{

cores/esp8266/IPAddress.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class IPAddress: public Printable {
149149
/*
150150
lwIP address compatibility
151151
*/
152+
IPAddress(const ipv4_addr& fw_addr) { setV4(); v4() = fw_addr.addr; }
152153
IPAddress(const ipv4_addr* fw_addr) { setV4(); v4() = fw_addr->addr; }
153-
IPAddress(const ip_addr_t& lwip_addr) { _ip = lwip_addr; }
154154

155155
operator ip_addr_t () const { return _ip; }
156156
operator const ip_addr_t*() const { return &_ip; }
@@ -163,6 +163,9 @@ class IPAddress: public Printable {
163163

164164
#if LWIP_IPV6
165165

166+
IPAddress(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); }
167+
IPAddress(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); }
168+
166169
uint16_t* raw6()
167170
{
168171
setV6();

0 commit comments

Comments
 (0)