1818 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919 */
2020
21- #include " Arduino .h"
21+ #include " Esp .h"
2222#include " flash_utils.h"
2323#include " eboot_command.h"
2424#include < memory>
@@ -36,6 +36,14 @@ extern struct rst_info resetInfo;
3636
3737// #define DEBUG_SERIAL Serial
3838
39+ #ifndef PUYA_SUPPORT
40+ #define PUYA_SUPPORT 1
41+ #endif
42+ #ifndef PUYA_BUFFER_SIZE
43+ // Good alternative for buffer size is: SPI_FLASH_SEC_SIZE (= 4k)
44+ // Always use a multiple of flash page size (256 bytes)
45+ #define PUYA_BUFFER_SIZE 256
46+ #endif
3947
4048/* *
4149 * User-defined Literals
@@ -577,7 +585,7 @@ bool EspClass::flashEraseSector(uint32_t sector) {
577585}
578586
579587#if PUYA_SUPPORT
580- static int spi_flash_write_puya (uint32_t offset, uint32_t *data, size_t size) {
588+ static SpiFlashOpResult spi_flash_write_puya (uint32_t offset, uint32_t *data, size_t size) {
581589 if (data == nullptr ) {
582590 return SPI_FLASH_RESULT_ERR;
583591 }
@@ -607,7 +615,7 @@ static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
607615 }
608616 rc = spi_flash_read (pos, flash_write_puya_buf, bytesNow);
609617 if (rc != SPI_FLASH_RESULT_OK) {
610- return ( int ) rc;
618+ return rc;
611619 }
612620 for (size_t i = 0 ; i < bytesNow / 4 ; ++i) {
613621 flash_write_puya_buf[i] &= *ptr;
@@ -616,7 +624,7 @@ static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
616624 rc = spi_flash_write (pos, flash_write_puya_buf, bytesNow);
617625 pos += bytesNow;
618626 }
619- return ( int ) rc;
627+ return rc;
620628}
621629#endif
622630
0 commit comments