-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
puya_v3.patch
61 lines (56 loc) · 1.8 KB
/
puya_v3.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 08:06:45.000000000 +0000
+++ 2.3.0/cores/esp8266/Esp.cpp 2018-11-07 11:28:34.852866182 +0000
@@ -507,11 +507,33 @@
return rc == 0;
}
+static uint32_t flash_chip_id = 0;
+
+bool EspClass::flashIsPuya(){
+ return ((flash_chip_id & 0x000000ff) == 0x85); // 0x146085 PUYA
+}
+
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;
+ if (flash_chip_id == 0)
+ flash_chip_id = getFlashChipId();
+ ets_isr_mask(FLASH_INT_MASK);
+ int rc;
+ uint32_t* ptr = data;
+ if (flashIsPuya()) {
+ 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) {
diff -urN 2.3.0.orig/cores/esp8266/Esp.h 2.3.0/cores/esp8266/Esp.h
--- 2.3.0.orig/cores/esp8266/Esp.h 2016-06-21 08:06:45.000000000 +0000
+++ 2.3.0/cores/esp8266/Esp.h 2018-11-06 22:49:47.711992085 +0000
@@ -23,6 +23,8 @@
#include <Arduino.h>
+#define PUYASUPPORT
+
/**
* AVR macros for WDT managment
*/
@@ -132,6 +134,7 @@
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
+ bool flashIsPuya();
uint32_t getSketchSize();
String getSketchMD5();
uint32_t getFreeSketchSpace();