forked from letscontrolit/ESPEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuya_v2.patch
36 lines (34 loc) · 1.13 KB
/
puya_v2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
diff -urN 2.3.0.orig/cores/esp8266/Esp.cpp 2.3.0/cores/esp8266/Esp.cpp
--- 2.3.0.orig/cores/esp8266/Esp.cpp 2016-06-21 10:06:45.000000000 +0200
+++ 2.3.0/cores/esp8266/Esp.cpp 2018-02-25 00:15:28.424217374 +0100
@@ -508,10 +508,28 @@
}
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
- ets_isr_mask(FLASH_INT_MASK);
- int rc = spi_flash_write(offset, (uint32_t*) data, size);
- ets_isr_unmask(FLASH_INT_MASK);
- return rc == 0;
+ static uint32_t flash_chip_id = 0;
+
+ if (flash_chip_id == 0)
+ flash_chip_id = getFlashChipId();
+ ets_isr_mask(FLASH_INT_MASK);
+ int rc;
+ uint32_t* ptr = data;
+ if ((flash_chip_id & 0x000000ff) == 0x85) { // 0x146085 PUYA
+ static uint32_t read_buf[SPI_FLASH_SEC_SIZE / 4];
+ rc = spi_flash_read(offset, read_buf, size);
+ if (rc != 0) {
+ ets_isr_unmask(FLASH_INT_MASK);
+ return false;
+ }
+ for (size_t i = 0; i < size / 4; ++i) {
+ read_buf[i] &= data[i];
+ }
+ ptr = read_buf;
+ }
+ rc = spi_flash_write(offset, ptr, size);
+ ets_isr_unmask(FLASH_INT_MASK);
+ return rc == 0;
}
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {