Skip to content

Commit 0a72b71

Browse files
committed
[PUYA] Apply generic patch on all builds checking for PUYA flash
Applied this patch made by @uzi18 esp8266/Arduino#4061 (comment) It is now included in all builds
1 parent 2f8962e commit 0a72b71

File tree

8 files changed

+49
-58
lines changed

8 files changed

+49
-58
lines changed

.travis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ install:
2525
- pip install -U platformio sphinx recommonmark sphinx_bootstrap_theme
2626

2727
script:
28+
# patch platformio core libs for PUYA bug (https://github.com/letscontrolit/ESPEasy/issues/650)
29+
- cd patches; ./check_puya_patch; cd ..
30+
2831
# - bash ./preflight.sh # make sure input files are OK before wasting time with prereqs
2932
# - cppcheck --enable=warning src/*.ino -q --force -I src --include=src/ESPEasy.ino --error-exitcode=1
3033
# - ./memanalyzer.py ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-objdump
3134
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run
3235
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run
3336

34-
# patch platformio core libs for PUYA bug (https://github.com/letscontrolit/ESPEasy/issues/650)
35-
- cd patches; ./check_puya_patch; cd ..
36-
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -s --environment dev_ESP8266PUYA_1024
37-
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -s --environment dev_ESP8266PUYA_1024
38-
39-
4037
before_deploy:
4138
- ./before_deploy
4239
- export RELEASE_FILE=$(ls ESPEasy*.zip)

before_deploy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ for ENV in \
2020
dev_ESP8266_1024\
2121
dev_ESP8266_4096\
2222
dev_ESP8285_1024\
23-
dev_ESP8266PUYA_1024\
24-
dev_ESP8266PUYA_1024_VCC\
2523
hard_SONOFF_POW\
2624
hard_SONOFF_POW_R2_4M\
2725
minimal_ESP8266_1024_OTA\

dist/README.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@ There is also a number of special builds:
2323
- normal_IR => "Normal" + IR receiver/transmitter plugins and library
2424
- hard_xxxxx => Special builds for some off-the-shelf hardware.
2525
- normal_core_241 => "Normal" using core 2.4.1, since 2.4.2 has issues with PWM
26+
- minimal_ESP82xx_1024_OTA => Minimum number of plugins and a limited set of controllers included to be able to perform a 2-step OTA on 1 MB flash nodes.
2627

2728
Chip can be:
2829
- ESP8266 => Most likely option
2930
- ESP8285 => Used in some Sonoff modules
3031
- ESP32 => Experimental support at this moment
31-
- ESP8266PUYA => For ESP modules with a flash chip labeled "PUYA" (often 1 MB)
32-
33-
The "PUYA" version deserves a bit more attention.
34-
If you cannot save settings, better try to see if the flash chip has "PUYA" written on it.
35-
If so, try the "PUYA" build.
3632

3733
MemorySize can be:
3834
- 1024 => 1 MB flash modules (e.g. almost all Sonoff modules)
@@ -62,7 +58,7 @@ for it to fetch the COM ports correctly. If you want you may save YOUR settings
6258
too small you can experiment with the "Pixels Per Inch" variable in the
6359
..\Settings\Default.ini file. Setting it to =96 is working for most users but the
6460
application will try to find the most optimal value by default. Sometimes it fails to
65-
do that. More information about the tool is found here:
61+
do that. More information about the tool is found here:
6662
https://github.com/Grovkillen/ESP_Easy_Flasher
6763

6864
Further reading:

patches/check_puya_patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22

3-
PATCH=puya.patch
3+
PATCH=puya_v2.patch
44

55
for DIR in ~/.platformio/packages/framework-arduinoespressif8266*/; do
66

77
#not applied yet? (in upstream or otherwise)
8-
if ! grep FLASH_QUIRK_WRITE_0_TO_1 $DIR/cores/esp8266/Esp.cpp >/dev/null; then
8+
if ! grep "0x146085 PUYA" $DIR/cores/esp8266/Esp.cpp >/dev/null; then
99
echo "Patching $DIR"
1010
patch -p1 -d $DIR < $PATCH
1111
fi

patches/puya_v2.patch

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
diff -urN 2.3.0.orig/cores/esp8266/Esp.cpp 2.3.0/cores/esp8266/Esp.cpp
2+
--- 2.3.0.orig/cores/esp8266/Esp.cpp 2016-06-21 10:06:45.000000000 +0200
3+
+++ 2.3.0/cores/esp8266/Esp.cpp 2018-02-25 00:15:28.424217374 +0100
4+
@@ -508,10 +508,28 @@
5+
}
6+
7+
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
8+
- ets_isr_mask(FLASH_INT_MASK);
9+
- int rc = spi_flash_write(offset, (uint32_t*) data, size);
10+
- ets_isr_unmask(FLASH_INT_MASK);
11+
- return rc == 0;
12+
+ static uint32_t flash_chip_id = 0;
13+
+
14+
+ if (flash_chip_id == 0)
15+
+ flash_chip_id = getFlashChipId();
16+
+ ets_isr_mask(FLASH_INT_MASK);
17+
+ int rc;
18+
+ uint32_t* ptr = data;
19+
+ if ((flash_chip_id & 0x000000ff) == 0x85) { // 0x146085 PUYA
20+
+ static uint32_t read_buf[SPI_FLASH_SEC_SIZE / 4];
21+
+ rc = spi_flash_read(offset, read_buf, size);
22+
+ if (rc != 0) {
23+
+ ets_isr_unmask(FLASH_INT_MASK);
24+
+ return false;
25+
+ }
26+
+ for (size_t i = 0; i < size / 4; ++i) {
27+
+ read_buf[i] &= data[i];
28+
+ }
29+
+ ptr = read_buf;
30+
+ }
31+
+ rc = spi_flash_write(offset, ptr, size);
32+
+ ets_isr_unmask(FLASH_INT_MASK);
33+
+ return rc == 0;
34+
}
35+
36+
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {

platformio.ini

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -580,48 +580,6 @@ build_unflags = ${esp8266_4M.build_unflags}
580580
build_flags = ${esp8266_4M.build_flags} ${dev.build_flags}
581581

582582

583-
584-
;;; DEV + PUYA ; ****; ****; ****; ****; ****; ****; ****; ****; ****; ****; ****; ****;;;
585-
; special patched version for PUYA flash chips, see issue ;650 at Github ;
586-
; *********************************************************************
587-
588-
; DEV+PUYA : 1024k version -----------------------
589-
[env:dev_ESP8266PUYA_1024]
590-
platform = ${dev.platform}
591-
lib_deps = ${common.lib_deps}
592-
lib_ignore = ${common.lib_ignore}
593-
lib_ldf_mode = ${common.lib_ldf_mode}
594-
lib_archive = ${common.lib_archive}
595-
framework = ${common.framework}
596-
board = ${common.board}
597-
upload_speed = ${common.upload_speed}
598-
monitor_speed = ${common.monitor_speed}
599-
board_upload.maximum_size = ${esp8266_1M.board_upload.maximum_size}
600-
board_build.f_cpu = ${esp8266_1M.board_build.f_cpu}
601-
board_build.flash_mode = ${esp8266_1M.board_build.flash_mode}
602-
build_unflags = ${esp8266_1M.build_unflags}
603-
build_flags = ${esp8266_1M.build_flags} ${dev.build_flags} -D FLASH_QUIRK_WRITE_0_TO_1
604-
605-
; DEV+PUYA : 1024k version + FEATURE_ADC_VCC -----
606-
[env:dev_ESP8266PUYA_1024_VCC]
607-
platform = ${dev.platform}
608-
lib_deps = ${common.lib_deps}
609-
lib_ignore = ${common.lib_ignore}
610-
lib_ldf_mode = ${common.lib_ldf_mode}
611-
lib_archive = ${common.lib_archive}
612-
framework = ${common.framework}
613-
board = ${common.board}
614-
upload_speed = ${common.upload_speed}
615-
monitor_speed = ${common.monitor_speed}
616-
board_upload.maximum_size = ${esp8266_1M.board_upload.maximum_size}
617-
board_build.f_cpu = ${esp8266_1M.board_build.f_cpu}
618-
board_build.flash_mode = ${esp8266_1M.board_build.flash_mode}
619-
build_unflags = ${esp8266_1M.build_unflags}
620-
build_flags = ${esp8266_1M.build_flags} ${dev.build_flags} -D FLASH_QUIRK_WRITE_0_TO_1 -D FEATURE_ADC_VCC=true
621-
622-
623-
624-
625583
;;; HARDWARE SPECIFIC VERSIONS ; ****; ****; ****; ****; ****; ****; ****; ****; ****;;;;;
626584
; versions specially designed to fit, and contents only needed plugins for each hardware ;
627585
; *********************************************************************

src/ESPEasy.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ void updateLoopStats() {
409409
return;
410410
}
411411
const long usecSince = usecPassedSince(lastLoopStart);
412+
miscStats[LOOP_STATS].add(usecSince);
413+
412414
loop_usec_duration_total += usecSince;
413415
lastLoopStart = micros();
414416
if (usecSince <= 0 || usecSince > 10000000)

src/WebServer.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5865,6 +5865,10 @@ void handle_sysinfo() {
58655865
// Where manufacturer is 0xE0 and device is 0x4016.
58665866
TXBuffer += F("Vendor: ");
58675867
TXBuffer += formatToHex(flashChipId & 0xFF);
5868+
if ((flashChipId & 0x000000ff) == 0x85) { // 0x146085 PUYA
5869+
TXBuffer += F(" (PUYA)");
5870+
TXBuffer += F(HTML_SYMBOL_WARNING);
5871+
}
58685872
TXBuffer += F(" Device: ");
58695873
uint32_t flashDevice = (flashChipId & 0xFF00) | ((flashChipId >> 16) & 0xFF);
58705874
TXBuffer += formatToHex(flashDevice);

0 commit comments

Comments
 (0)