Skip to content

Commit 89e56a8

Browse files
committed
esp8266/modesp: Add flash_size() function.
Returns FlashROM size in bytes from vendor SDK's point of view, not physical size.
1 parent 3a5a35a commit 89e56a8

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

esp8266/modesp.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,23 @@ STATIC mp_obj_t esp_flash_erase(mp_obj_t sector_in) {
609609
}
610610
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_flash_erase_obj, esp_flash_erase);
611611

612+
STATIC mp_obj_t esp_flash_size(void) {
613+
extern char flashchip;
614+
// For SDK 1.5.2, either address has shifted and not mirrored in
615+
// eagle.rom.addr.v6.ld, or extra initial member was added.
616+
SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
617+
#if 0
618+
printf("deviceId: %x\n", flash->deviceId);
619+
printf("chip_size: %u\n", flash->chip_size);
620+
printf("block_size: %u\n", flash->block_size);
621+
printf("sector_size: %u\n", flash->sector_size);
622+
printf("page_size: %u\n", flash->page_size);
623+
printf("status_mask: %u\n", flash->status_mask);
624+
#endif
625+
return mp_obj_new_int_from_uint(flash->chip_size);
626+
}
627+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size);
628+
612629
STATIC mp_obj_t esp_neopixel_write_(mp_obj_t pin, mp_obj_t buf, mp_obj_t is800k) {
613630
mp_buffer_info_t bufinfo;
614631
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
@@ -639,6 +656,7 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
639656
{ MP_OBJ_NEW_QSTR(MP_QSTR_flash_read), (mp_obj_t)&esp_flash_read_obj },
640657
{ MP_OBJ_NEW_QSTR(MP_QSTR_flash_write), (mp_obj_t)&esp_flash_write_obj },
641658
{ MP_OBJ_NEW_QSTR(MP_QSTR_flash_erase), (mp_obj_t)&esp_flash_erase_obj },
659+
{ MP_OBJ_NEW_QSTR(MP_QSTR_flash_size), (mp_obj_t)&esp_flash_size_obj },
642660
#if MODESP_ESPCONN
643661
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&esp_socket_type },
644662
{ MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&esp_getaddrinfo_obj },

0 commit comments

Comments
 (0)