File tree 2 files changed +29
-4
lines changed
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -569,11 +569,33 @@ bool EspClass::flashEraseSector(uint32_t sector) {
569
569
return rc == 0 ;
570
570
}
571
571
572
+ static uint32_t flash_chip_id = 0 ;
573
+
574
+ bool EspClass::flashIsPuya (){
575
+ return ((flash_chip_id & 0x000000ff ) == 0x85 ); // 0x146085 PUYA
576
+ }
577
+
572
578
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 ;
577
599
}
578
600
579
601
bool EspClass::flashRead (uint32_t offset, uint32_t *data, size_t size) {
Original file line number Diff line number Diff line change 23
23
24
24
#include < Arduino.h>
25
25
26
+ #define PUYASUPPORT
27
+
26
28
/* *
27
29
* AVR macros for WDT managment
28
30
*/
@@ -141,6 +143,7 @@ class EspClass {
141
143
bool flashWrite (uint32_t offset, uint32_t *data, size_t size);
142
144
bool flashRead (uint32_t offset, uint32_t *data, size_t size);
143
145
146
+ bool flashIsPuya ();
144
147
uint32_t getSketchSize ();
145
148
String getSketchMD5 ();
146
149
uint32_t getFreeSketchSpace ();
You can’t perform that action at this time.
0 commit comments