ESP32 Sparkfun Thing Plus - flash read err, 1000

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ltmerlin
Posts: 32
Joined: Fri Jun 28, 2019 12:34 pm

ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by ltmerlin » Fri Jun 28, 2019 12:38 pm

Hi,

I flashed a brand new Sparkfun ESP32 Thing Plus with a recent MicroPython firmware binary (from https://micropython.org/download/#esp32). (first erased properly and then flashing with the esptool as described below)

Code: Select all

esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART --baud 460800 --before default_reset --after hard_reset erase_flash

Code: Select all

esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART --baud 460800 write_flash -z --flash_freq 40m --flash_mode dio --flash_size=16MB 0x1000 esp32-20190529-v1.11.bin
Everything works fine except at startup I see the error message "flash read err, 1000
ets_main.c 371
" like you can see below at the first few lines:

Code: Select all

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371 
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4928
ho 0 tail 12 room 4
load:0x40078000,len:9332
load:0x40080400,len:6216
entry 0x400806e8
I (433) cpu_start: Pro cpu up.
I (433) cpu_start: Application information:
I (433) cpu_start: Compile time:     07:44:16
I (435) cpu_start: Compile date:     May 29 2019
I (441) cpu_start: ESP-IDF:          v3.3-beta1-268-g5c88c5996
I (447) cpu_start: Starting app cpu, entry point is 0x4008294c
I (0) cpu_start: App cpu up.
I (458) heap_init: Initializing. RAM available for dynamic allocation:
I (465) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (471) heap_init: At 3FFB9B88 len 00026478 (153 KiB): DRAM
I (477) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (483) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (490) heap_init: At 40093398 len 0000CC68 (51 KiB): IRAM
I (496) cpu_start: Pro cpu start user code
I (67) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
MicroPython v1.11 on 2019-05-29; ESP32 module with ESP32
Type "help()" for more information.
>>>
Using other firmware versions does not help to resolve it.


When I run the following commands to get the filesystem sizes:

Code: Select all

import os
fs_stat = os.statvfs('/')
fs_size = fs_stat[0] * fs_stat[2]
fs_free = fs_stat[0] * fs_stat[3]
print("File system size {:,} - Free space {:,}".format(fs_size, fs_free))

File system size 2,072,576 - Free space 2,068,480
I only get 2MB of availble or free space while I should get 16MB right?

Running

Code: Select all

import esp
esp.flash_size()
16777216
I get 16777216, which is the correct 16MB... I would like to write files to the filesystem (which SHOULD have 16MB of space) but I only can write max 2MB to the filesystem. Any ideas to resolve this flash memory issue? Or what am I doing wrong?

Online
User avatar
Roberthh
Posts: 2008
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by Roberthh » Fri Jul 05, 2019 7:08 pm

Sorry for replying late, I had seen your post but answered late. The problem is in the SD card driver flashbdev.py at https://github.com/micropython/micropyt ... ashbdev.py.
The last line sets a fixed file of the file system:

Code: Select all

    bdev = FlashBdev(2048 * 1024 // FlashBdev.SEC_SIZE)
 
The following change will use all available flash:

Code: Select all

    bdev = FlashBdev(size // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)
 
You have to build your own image to get that, and have to rebuild the file system once you loaded the firmware. Erasing the flash and reloading the firmware will recreate the file system too.
See also viewtopic.php?f=5&t=6325

ltmerlin
Posts: 32
Joined: Fri Jun 28, 2019 12:34 pm

Re: ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by ltmerlin » Tue Jul 09, 2019 3:29 pm

Thanks, it shows now almost 16MB. So that worked!

I first had to deal with some building issues before I could try it. (I had to use the xtensa-esp32-elf 5.0.2 version instead of the newer 8.0.2 to get "make" working properly)

pic-man
Posts: 4
Joined: Mon May 04, 2020 5:40 pm

Re: ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by pic-man » Mon May 04, 2020 5:59 pm

Roberthh wrote:
Fri Jul 05, 2019 7:08 pm
The problem is in the SD card driver flashbdev.py at https://github.com/micropython/micropyt ... ashbdev.py.
The last line sets a fixed file of the file system:

Code: Select all

    bdev = FlashBdev(2048 * 1024 // FlashBdev.SEC_SIZE)
 
The following change will use all available flash:

Code: Select all

    bdev = FlashBdev(size // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)
 
You have to build your own image to get that, and have to rebuild the file system once you loaded the firmware.
Great! However flashbdev.py looks like this now:

Code: Select all

from esp32 import Partition

bdev = Partition.find(Partition.TYPE_DATA, label="vfs")
bdev = bdev[0] if bdev else None
How should we work around it now on the Thing Plus?

Online
User avatar
Roberthh
Posts: 2008
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by Roberthh » Mon May 04, 2020 6:34 pm

That's right, the way the flash is partitioned changed recently. If you look into the https://github.com/micropython/micropyt ... orts/esp32 repository. you see a file named partitions.csv. So one option you have is changing that file - the last entry is the one for the file system - and rebuild the firmware. There may be ways to go- Someone else may chime in for that.

pic-man
Posts: 4
Joined: Mon May 04, 2020 5:40 pm

Re: ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by pic-man » Tue May 05, 2020 8:40 pm

Thanks.. partitions.csv indeed seems to be the way to go at the moment.

Setting it to 0x1000000 rather predictably overcommitted the space and failed, so I set it to (size - offset) = ( 0x1000000 - 0x200000 ) = 0xE00000 thus:

Code: Select all

vfs,      data, fat,     0x200000, 0xE00000,
a quick 'make -j4 deploy' later and I have:-

Code: Select all

File system size 14,680,064 - Free space 14,667,776
...which will do me nicely.

pic-man
Posts: 4
Joined: Mon May 04, 2020 5:40 pm

Re: ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by pic-man » Wed May 06, 2020 12:38 pm

Whoops! I'd failed to notice "flash read err, 1000" still occurs. A quick dig around the sources (micropython and espidf) doesn't find ets_main.c, so I can't chase line 371 to attempt to establish what the error really means. Guessing it's about not quite using every byte of flash as per the 2M issue at top of thread?

Examining partitions.csv more closely I see a gap, and fill it.

Code: Select all

# Notes: the offset of the partition table itself is set in
# $ESPIDF/components/partition_table/Kconfig.projbuild and the
# offset of the factory/ota_0 partition is set in makeimg.py
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 0x180000,
vfs,      data, fat,     0x190000, 0xE70000,
Checking the free space...

Code: Select all

import os
fs_stat = os.statvfs('/')
fs_size = fs_stat[0] * fs_stat[2]
fs_free = fs_stat[0] * fs_stat[3]
print("File system size {:,} - Free space {:,}".format(fs_size, fs_free))
File system size 15,138,816 - Free space 15,126,528
All seems to add up and so far it's working fine, but I'm still getting: flash read err,1000

Online
User avatar
Roberthh
Posts: 2008
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by Roberthh » Wed May 06, 2020 12:54 pm

As far as I recall, this is more a warning than an error. There is a note in the esp_idf about it:

Code: Select all

    config ESP32_DEEP_SLEEP_WAKEUP_DELAY
        int "Extra delay in deep sleep wake stub (in us)"
        default 2000
        range 0 5000
        help
            When ESP32 exits deep sleep, the CPU and the flash chip are powered on
            at the same time. CPU will run deep sleep stub first, and then
            proceed to load code from flash. Some flash chips need sufficient
            time to pass between power on and first read operation. By default,
            without any extra delay, this time is approximately 900us, although
            some flash chip types need more than that.

            By default extra delay is set to 2000us. When optimizing startup time
            for applications which require it, this value may be reduced.

            If you are seeing "flash read err, 1000" message printed to the
            console after deep sleep reset, try increasing this value.
You can add that to the boards/sdkconfig.base file and play with some larger values like

ESP32_DEEP_SLEEP_WAKEUP_DELAY=5000

If you do that, better go through a sequence of

make BOARD=<your type> clean
make BOARD=<your type> depoy

Edit: I have a board here which also shows this warning. Adding that value does not change anything.

pic-man
Posts: 4
Joined: Mon May 04, 2020 5:40 pm

Re: ESP32 Sparkfun Thing Plus - flash read err, 1000

Post by pic-man » Wed May 06, 2020 2:46 pm

Roberthh wrote:
Wed May 06, 2020 12:54 pm
Edit: I have a board here which also shows this warning. Adding that value does not change anything.
Thanks for that. CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=5000 has no obvious effect either, but as long as this is a harmless warning I'll ignore it now.

I've wrapped this up with nicer BOARD and MCU names, and the partition fix as a board definition below.

Code: Select all

mkdir -p ports/esp32/boards/THINGPLUS

cat > ports/esp32/boards/THINGPLUS/mpconfigboard.h << EOF
#define MICROPY_HW_BOARD_NAME "ESP32 Thing Plus"
#define MICROPY_HW_MCU_NAME "ESP32-WROOM-32D"
EOF

cat > ports/esp32/boards/THINGPLUS/mpconfigboard.mk << EOF
SDKCONFIG += boards/sdkconfig.base
PART_SRC = partitions-thingplus.csv
EOF

cat > ports/esp32/partitions-thingplus.csv << EOF
# Notes: the offset of the partition table itself is set in
# $ESPIDF/components/partition_table/Kconfig.projbuild and the
# offset of the factory/ota_0 partition is set in makeimg.py
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 0x180000,
vfs,      data, fat,     0x190000, 0xE70000,
EOF
cd to the ports/esp32 directory and then build with e.g.: make BOARD=THINGPLUS deploy.

Post Reply