Skip to content

Commit a835833

Browse files
committed
[PUYA] Applied ESPeasy puya_v3.patch
Applied the patch to get the starting point as described in esp8266#5493
1 parent e9d052c commit a835833

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

cores/esp8266/Esp.cpp

+26-4
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,33 @@ bool EspClass::flashEraseSector(uint32_t sector) {
569569
return rc == 0;
570570
}
571571

572+
static uint32_t flash_chip_id = 0;
573+
574+
bool EspClass::flashIsPuya(){
575+
return ((flash_chip_id & 0x000000ff) == 0x85); // 0x146085 PUYA
576+
}
577+
572578
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
573-
ets_isr_mask(FLASH_INT_MASK);
574-
int rc = spi_flash_write(offset, (uint32_t*) data, size);
575-
ets_isr_unmask(FLASH_INT_MASK);
576-
return rc == 0;
579+
if (flash_chip_id == 0)
580+
flash_chip_id = getFlashChipId();
581+
ets_isr_mask(FLASH_INT_MASK);
582+
int rc;
583+
uint32_t* ptr = data;
584+
if (flashIsPuya()) {
585+
static uint32_t read_buf[SPI_FLASH_SEC_SIZE / 4];
586+
rc = spi_flash_read(offset, read_buf, size);
587+
if (rc != 0) {
588+
ets_isr_unmask(FLASH_INT_MASK);
589+
return false;
590+
}
591+
for (size_t i = 0; i < size / 4; ++i) {
592+
read_buf[i] &= data[i];
593+
}
594+
ptr = read_buf;
595+
}
596+
rc = spi_flash_write(offset, ptr, size);
597+
ets_isr_unmask(FLASH_INT_MASK);
598+
return rc == 0;
577599
}
578600

579601
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {

cores/esp8266/Esp.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <Arduino.h>
2525

26+
#define PUYASUPPORT
27+
2628
/**
2729
* AVR macros for WDT managment
2830
*/
@@ -141,6 +143,7 @@ class EspClass {
141143
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
142144
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
143145

146+
bool flashIsPuya();
144147
uint32_t getSketchSize();
145148
String getSketchMD5();
146149
uint32_t getFreeSketchSpace();

0 commit comments

Comments
 (0)