Flash storage mount stops working (urgent)

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Flash storage mount stops working (urgent)

Postby snahmad75 » Fri Jun 01, 2018 11:28 am

I think it was working fine before.

My custom partition.

# Name, Type, SubType, Offset, Size
nvs, data, nvs, 0x9000, 0x4000
otadata, data, ota, 0xd000, 0x2000
phy_init, data, phy, 0xf000, 0x1000
ota_0, app, ota_0, 0x10000, 0x1A0000
ota_1, app, ota_1, , 0x1A0000
storage, data, fat, ,0x80000



on start ram usage
Stack free: 2680
Internal Heap free: 346288
Heap free: 267068:346288
on start free heap=267068
D (6258) nvs: nvs_erase_key serial_num

D (6262) CPPNVS: >> set: key: serial_num, u32: value=456
D (6266) nvs: nvs_set serial_num 4 456
D (6271) CPPNVS: << set
D (6273) nvs: nvs_get serial_num 4
serial num=456
V (6278) wl_flash: config start_addr=0x00000000, full_mem_size=0x00080000, pag
e_size=0x00001000, sector_size=0x00001000, updaterate=0x00000010, wr_size=0x00
000010, version=0x00000001, temp_buff_size=0x00000020
V (6296) wl_flash: config - this->addr_state1=0x0007d000
V (6302) wl_flash: config - this->addr_state2=0x0007e000
D (6307) wl_flash: init - config ID=1, stored ID=1, access_count=0, block_size
=4096, max_count=16, pos=0, move_count=0
D (6318) wl_flash: init starts: crc1=-1312139876, crc2 = -1312139876, this->st
ate.crc=-1312139876, state_copy->crc=-1312139876
D (6329) wl_flash: init: crc1=-1312139876, crc2 = -1312139876, result=0
D (6336) wl_flash: recoverPos - this->state.pos=0x00000000, result=00000000
D (6343) vfs_fat_spiflash: using pdrv=0
V (6347) ff_diskio_spiflash: ff_wl_ioctl: cmd=2

V (6352) ff_diskio_spiflash: ff_wl_read - pdrv=0, sector=0, count=1

V (6358) wl_flash: read - src_addr=0x00000000, size=0x00001000
V (6364) wl_flash: calcAddr - addr=0x00000000 -> result=0x00001000
W (6371) vfs_fat_spiflash: f_mount failed (13)
I (6376) vfs_fat_spiflash: Formatting FATFS partition, allocation unit size=52
4288
V (6384) ff_diskio_spiflash: ff_wl_ioctl: cmd=3

V (6389) ff_diskio_spiflash: ff_wl_ioctl: cmd=2

V (6393) ff_diskio_spiflash: ff_wl_ioctl: cmd=1

E (6398) vfs_fat_spiflash: f_mkfs failed (14)
ESP_ERROR_CHECK failed: esp_err_t 0xffffffff at 0x401152aa
file: "C:/Work/LibDev/esp32/esp-idf/components/cpp_utils/FATFS_VFS.cpp" line 4
9
func: void FATFS_VFS::mount()
expression: esp_vfs_fat_spiflash_mount(m_mountPath.c_str(), m_partitionName.c_
str(), &mountConfig, &m_wl_handle)

Backtrace: 0x4008ac8b:0x3ffbd0f0 0x4008b175:0x3ffbd110 0x401152aa:0x3ffbd130 0
x400d4187:0x3ffbd160 0x400d4331:0x3ffbd1b0 0x400d26a8:0x3ffbd200

Entering gdb stub now.
$T0b#e6

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Flash storage mount stops working (urgent)

Postby snahmad75 » Fri Jun 01, 2018 12:04 pm

SD card mount work but not spiflash mount.

Any idea?

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Flash storage mount stops working (urgent)

Postby snahmad75 » Fri Jun 01, 2018 2:15 pm

This example is working.

https://github.com/espressif/esp-idf/tr ... _levelling


But below example does not work. crash.

https://github.com/nkolban/ESP32_Explorer

Strange?

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Flash storage mount stops working (urgent)

Postby snahmad75 » Fri Jun 01, 2018 3:49 pm

Fix by specifying allocation_unit_size

Code: Select all

void FATFS_VFS::mount() {
esp_vfs_fat_mount_config_t mountConfig;
mountConfig.max_files = m_maxFiles;
mountConfig.format_if_mount_failed = true;
mountConfig.allocation_unit_size = 4096;

ESP_LOGD(LOG_TAG, "FATFS_VFS::mount(%s,%s)", m_mountPath.c_str(), m_partitionName.c_str());
ESP_ERROR_CHECK(esp_vfs_fat_spiflash_mount(m_mountPath.c_str(), m_partitionName.c_str(), &mountConfig

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Flash storage mount stops working (urgent)

Postby kolban » Fri Jun 01, 2018 5:54 pm

Very good find and AWESOME work. This field was apparently added back in January and the code library you are playing with pre-dates that and wasn't upgraded (or known) to be changed. What we can now do is make sure that it has a "good value" by default.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Flash storage mount stops working (urgent)

Postby kolban » Fri Jun 01, 2018 10:31 pm

Hmmm ... it gets more interesting. I went to examine this problem in more depth and found that it appears that this option is not present in v3.0 (the current latest stable) of ESP-IDF ... see:

https://github.com/espressif/esp-idf/bl ... _vfs_fat.h

Are you working with ESP-IDF master or with a stable release of the ESP-IDF?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Flash storage mount stops working (urgent)

Postby snahmad75 » Sat Jun 02, 2018 10:08 am

I download esp-idf few month back. not using latest.
I will try latest code base.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Flash storage mount stops working (urgent)

Postby ESP_Angus » Mon Jun 04, 2018 5:12 am

kolban wrote:Very good find and AWESOME work. This field was apparently added back in January and the code library you are playing with pre-dates that and wasn't upgraded (or known) to be changed. What we can now do is make sure that it has a "good value" by default.
kolban wrote:Hmmm ... it gets more interesting. I went to examine this problem in more depth and found that it appears that this option is not present in v3.0
This field was added for v3.1, back in February. It will choose a "good value" by default if the field is left unset with value zero. The problem is that the code as-written does not zero this field:

Code: Select all

esp_vfs_fat_mount_config_t mountConfig;
mountConfig.max_files = m_maxFiles;
mountConfig.format_if_mount_failed = true;
In this code, all values not given are uninitialized memory (garbage values). To fix the issue for IDF V3.0 and V3.1, initialise the structure so any un-set fields have value zero:

Code: Select all

esp_vfs_fat_mount_config_t mountConfig = { 0 };
mountConfig.max_files = m_maxFiles;
mountConfig.format_if_mount_failed = true;
Or you can use a C99-style initializer list, although these are a little fiddly to employ in C++.

Always initializing structures declared on the stack is a very good habit to get into when writing C (or C++ with C types). Even if you set every member of the structure *now*, you never know what may change in the future (and if you do set every member of the structure now, the compiled binary will be identical whether you pre-initialize to zero or not.)

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Flash storage mount stops working (urgent)

Postby snahmad75 » Mon Jun 04, 2018 8:23 am

ok, good advise. thanks.

Who is online

Users browsing this forum: No registered users and 84 guests