【求助】ESP32通过spi外接flash的fat格式与PC不能兼容?

jame113
Posts: 19
Joined: Fri Dec 25, 2020 4:47 am

Re: 【求助】ESP32通过spi外接flash的fat格式与PC不能兼容?

Postby jame113 » Tue Aug 10, 2021 8:51 am

@ESP_igrr 大神, 我已按您建议的1,2,3修改了代码, 现在可以正常挂载,并且读取windows下拷贝的文件了。
但ff_raw_write函数写入部分,因为我水平太低, 并且对文件系统底层基本不懂, 我尝试了很多遍,都没写出来, 这个需求阻塞在我这快两个礼拜了, 能否帮实现一下ff_raw_write函数? 多谢。:)


ESP_igrr wrote:
Tue Aug 10, 2021 6:23 am
I think the reason why you can't mount the filesystem created by Windows is that the firmware code uses 4096 bytes as the sector size.
When you format the partition in Windows, it allows you to choose the cluster size, not sector size. Windows sets sector size to 512 bytes.

You can try to modify the code in diskio_rawflash as follows:
1. In ff_raw_ioctl, return 512 bytes from GET_SECTOR_SIZE.
2. In the same function, change GET_SECTOR_COUNT calculation to divide the size by 512.
3. In ff_raw_read use 512 bytes instead of SPI_FLASH_SEC_SIZE as the unit.
4. In ff_raw_write, the logic becomes more complex. Allocate a temporary 4kB buffer, read the 4kb aligned flash sector containing the block you need into the buffer. Replace the part that needs to be overwritten. Erase the 4kB flash sector. Write the 4kb sector to flash.

Note that if your device can be suddenly powered off, this read-modify-write approach in ff_raw_write may result in a loss of data. I don't think it makes things a lot worse, though, as FATFS has pretty poor tolerance to such power-off scenarios anyway.

jame113
Posts: 19
Joined: Fri Dec 25, 2020 4:47 am

Re: 【求助】ESP32通过spi外接flash的fat格式与PC不能兼容?

Postby jame113 » Tue Aug 10, 2021 11:18 am

我尝试在ff_raw_write中按照您说的方法操作, 但好像在write方法中, 不能进行read操作? 测试代码和日志错下:

Code: Select all

	DRESULT ff_raw_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
{
	ESP_LOGV(TAG, "ff_raw_write - pdrv=%i, sector=%d, count=%d, char:%s", (unsigned int)pdrv, (unsigned int)sector, (unsigned int)count, buff);

	BYTE *buff4096 = malloc(4096);
	//计算sector第一页所在的位置
	uint32_t page4096 = sector / 8;
	uint32_t page4096max = (sector + count) / 8;
	const esp_partition_t *part = ff_raw_handles[pdrv];
	if (page4096 == page4096max)
	{ //是同一个4k页内
		uint32_t real_page = sector / 8 * 8;
		////////////////////////////////////////////////
		 //执行到这行就异常重启了
		DRESULT ret = ff_raw_read(pdrv, buff4096, real_page, 4096);
		ESP_LOGV(TAG, "inner read %d", ret);
		if (ret == ESP_OK)
		{ //替换内容
			uint32_t start = sector % 8;
			BYTE *ptd = buff4096;
			ptd += start;
			memcpy(ptd, buff, count * 512);

			esp_partition_erase_range(part, real_page * 512, 4096);
			esp_partition_write(part, real_page * 512, buff4096, 4096);
		}
	}
	else
	{ //不在同一个4k页内
	}
	return ESP_OK;
}

日志:

Code: Select all

I (8225) example: Initializing external SPI Flash
I (8225) example: Pin assignments:
I (8225) example: MOSI: 23   MISO: 19   SCLK: 18   CS:  5
D (8229) spi: SPI3 use iomux pins.
V (8232) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (8239) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0x80E
D (8247) intr_alloc: Connected src 31 to int 13 (cpu 0)
D (8252) FLASH_HAL: extra_dummy: 0
V (8256) memspi: raw_chip_id: 1640EF

V (8260) memspi: chip_id: EF4016

V (8263) memspi: raw_chip_id: 1640EF

V (8267) memspi: chip_id: EF4016

D (8270) spi_flash: trying chip: issi
D (8274) spi_flash: trying chip: gd
D (8278) spi_flash: trying chip: generic
I (8282) spi_flash: detected chip: generic
I (8287) spi_flash: flash io: dio
V (8291) memspi: raw_chip_id: 1640EF

V (8294) memspi: chip_id: EF4016

I (8298) example: Initialized external Flash, size=4096 KB, ID=0xef4016
I (8305) example: Adding external Flash as a partition, label="storage", size=4096 KB
D (8314) partition: Loading the partition table
V (8319) calculated md5: 0x3ffb47e8   bf 25 82 2c 0f a6 d8 64  1b d9 30 25 1e 06 b4 c4  |.%.,...d..0%....|
V (8328) stored md5: 0x3f4180d0   bf 25 82 2c 0f a6 d8 64  1b d9 30 25 1e 06 b4 c4  |.%.,...d..0%....|
D (8337) partition: Partition table MD5 verified
I (8342) example: Listing data partitions:
I (8347) example: - partition 'nvs', subtype 2, offset 0x9000, size 16 kB
I (8354) example: - partition 'otadata', subtype 0, offset 0xd000, size 8 kB
I (8362) example: - partition 'phy_init', subtype 1, offset 0xf000, size 4 kB
I (8370) example: - partition 'storage', subtype 129, offset 0x0, size 4096 kB
I (8378) example: Mounting FAT filesystem
D (8382) vfs_fat_spiflash: using pdrv=0
V (8386) diskio_rawflash: ff_raw_ioctl: cmd=2
V (8391) diskio_rawflash: ff_raw_read - pdrv=0, sector=0, count=1n
V (8397) diskio_rawflash: ff_raw_read - pdrv=0, sector=8, count=1n
V (8404) diskio_rawflash: ff_raw_read - pdrv=0, sector=9, count=1n
V (8410) diskio_rawflash: ff_raw_read - pdrv=0, sector=10, count=1n
V (8416) diskio_rawflash: ff_raw_read - pdrv=0, sector=11, count=1n
V (8422) diskio_rawflash: ff_raw_read - pdrv=0, sector=12, count=1n
V (8429) diskio_rawflash: ff_raw_read - pdrv=0, sector=13, count=1n
V (8435) diskio_rawflash: ff_raw_read - pdrv=0, sector=14, count=1n
V (8441) diskio_rawflash: ff_raw_read - pdrv=0, sector=15, count=1n
V (8448) diskio_rawflash: ff_raw_read - pdrv=0, sector=16, count=1n
V (8454) diskio_rawflash: ff_raw_read - pdrv=0, sector=17, count=1n
V (8460) diskio_rawflash: ff_raw_read - pdrv=0, sector=18, count=1n
V (8467) diskio_rawflash: ff_raw_read - pdrv=0, sector=19, count=1n
I (8473) example: FAT FS: 4064 kB total, 4027 kB free
I (8479) example: Reading file before
V (8483) vfs_fat: vfs_fat_open: path="/4.mp3", flags=0, mode=1b6
V (8489) diskio_rawflash: ff_raw_read - pdrv=0, sector=32, count=1n
D (8495) vfs_fat: vfs_fat_open: fresult=4
E (8499) example: Failed to open file for reading
I (8505) example: Opening file write
V (8509) vfs_fat: vfs_fat_open: path="/4.mp3", flags=601, mode=1b6
V (8516) diskio_rawflash: ff_raw_write - pdrv=0, sector=32, count=1, char:4       MP3 
V (8523) diskio_rawflash: ff_raw_read - pdrv=0, sector=32, count=4096n
Guru Meditation Error: Core  0 panic'ed (Double exception)
Core 0 register dump:
PC      : 0x40087d0b  PS      : 0x00040d36  A0      : 0x3ffb4420  A1      : 0x3ffb4500  
0x40087d0b: _xt_context_save at /Users/local/esp/esp-idf/components/freertos/xtensa_context.S:195

A2      : 0x00000000  A3      : 0x40080284  A4      : 0x00000000  A5      : 0x00000000  
0x40080284: _DebugExceptionVector at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:519

A6      : 0x00000040  A7      : 0x00000000  A8      : 0x8008ade9  A9      : 0x00000000  
A10     : 0x00000001  A11     : 0x40080244  A12     : 0x00040000  A13     : 0x00000040  
0x40080244: _Level5Vector at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1683

A14     : 0x3ff65000  A15     : 0x00040000  SAR     : 0x0000001f  EXCCAUSE: 0x00000002  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000  

ELF file SHA256: 0064cd0c6fcba6ae

Backtrace: 0x40087d08:0x3ffb4500 0x3ffb441d:0x3ffb4410 |<-CORRUPTED
0x40087d08: _xt_context_save at /Users/local/esp/esp-idf/components/freertos/xtensa_context.S:194


Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_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:1
load:0x3fff0030,len:4
load:0x3fff0034,len:6956
load:0x40078000,len:13128
load:0x40080400,len:3884
0x40080400: _init at ??:?

entry 0x40080688
I (29) boot: ESP-IDF v4.1.1-351-g935deb4082-dirty 2nd stage bootloader
I (29) boot: compile time 10:24:10
I (30) boot: chip revision: 1
I (34) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot.esp32: SPI Speed      : 80MHz
I (45) boot.esp32: SPI Mode       : DIO
I (50) boot.esp32: SPI Flash Size : 4MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (78) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (86) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (93) boot:  3 factory          factory app      00 00 00010000 00100000
I (101) boot:  4 ota_0            OTA app          00 10 00110000 00100000
I (108) boot:  5 ota_1            OTA app          00 11 00210000 00100000
I (116) boot: End of partition table
I (120) boot: Defaulting to factory image
I (125) boot_comm: chip revision: 1, min. application chip revision: 0
I (132) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x07ed8 ( 32472) map
I (151) esp_image: segment 1: paddr=0x00017f00 vaddr=0x3ffb0000 size=0x0216c (  8556) load
I (155) esp_image: segment 2: paddr=0x0001a074 vaddr=0x40080000 size=0x00404 (  1028) load
0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

I (159) esp_image: segment 3: paddr=0x0001a480 vaddr=0x40080404 size=0x05b98 ( 23448) load
I (177) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x18bbc (101308) map
0x400d0020: _stext at ??:?

I (209) esp_image: segment 5: paddr=0x00038be4 vaddr=0x40085f9c size=0x053d0 ( 21456) load
0x40085f9c: xQueueGenericSendFromISR at /Users/local/esp/esp-idf/components/freertos/queue.c:1177

I (224) boot: Loaded app from partition at offset 0x10000
I (224) boot: Disabling RNG early entropy source...
I (225) cpu_start: Pro cpu up.
I (228) cpu_start: Application information:
I (233) cpu_start: Project name:     MWiFi
I (238) cpu_start: App version:      123
I (242) cpu_start: Compile time:     Aug 10 2021 10:24:04
I (248) cpu_start: ELF file SHA256:  0064cd0c6fcba6ae...
I (254) cpu_start: ESP-IDF:          v4.1.1-351-g935deb4082-dirty
I (261) cpu_start: Starting app cpu, entry point is 0x40081140
0x40081140: call_start_cpu1 at /Users/local/esp/esp-idf/components/esp32/cpu_start.c:276

I (254) cpu_start: App cpu up.
V (272) memory_layout: reserved range is 0x3f407ed0 - 0x3f407ef8
D (278) memory_layout: Checking 7 reserved memory ranges:
D (283) memory_layout: Reserved memory range 0x3ffae000 - 0x3ffae6e0
D (289) memory_layout: Reserved memory range 0x3ffb0000 - 0x3ffb29c0
D (296) memory_layout: Reserved memory range 0x3ffe0000 - 0x3ffe0440
D (302) memory_layout: Reserved memory range 0x3ffe3f20 - 0x3ffe4350
D (309) memory_layout: Reserved memory range 0x40070000 - 0x40078000
D (315) memory_layout: Reserved memory range 0x40078000 - 0x40080000
0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

D (322) memory_layout: Reserved memory range 0x40080000 - 0x4008b36c
0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

D (328) memory_layout: Building list of available memory regions:
V (334) memory_layout: Examining memory region 0x3ffae000 - 0x3ffb0000
V (341) memory_layout: Start of region 0x3ffae000 - 0x3ffb0000 overlaps reserved 0x3ffae000 - 0x3ffae6e0
D (350) memory_layout: Available memory region 0x3ffae6e0 - 0x3ffb0000
V (357) memory_layout: Examining memory region 0x3ffb0000 - 0x3ffb8000
V (363) memory_layout: Start of region 0x3ffb0000 - 0x3ffb8000 overlaps reserved 0x3ffb0000 - 0x3ffb29c0
D (373) memory_layout: Available memory region 0x3ffb29c0 - 0x3ffb8000
V (380) memory_layout: Examining memory region 0x3ffb8000 - 0x3ffc0000
D (386) memory_layout: Available memory region 0x3ffb8000 - 0x3ffc0000
V (393) memory_layout: Examining memory region 0x3ffc0000 - 0x3ffc2000
D (399) memory_layout: Available memory region 0x3ffc0000 - 0x3ffc2000
V (406) memory_layout: Examining memory region 0x3ffc2000 - 0x3ffc4000
D (413) memory_layout: Available memory region 0x3ffc2000 - 0x3ffc4000
V (419) memory_layout: Examining memory region 0x3ffc4000 - 0x3ffc6000
D (426) memory_layout: Available memory region 0x3ffc4000 - 0x3ffc6000
V (432) memory_layout: Examining memory region 0x3ffc6000 - 0x3ffc8000
D (439) memory_layout: Available memory region 0x3ffc6000 - 0x3ffc8000
V (446) memory_layout: Examining memory region 0x3ffc8000 - 0x3ffca000
D (452) memory_layout: Available memory region 0x3ffc8000 - 0x3ffca000
V (459) memory_layout: Examining memory region 0x3ffca000 - 0x3ffcc000
D (465) memory_layout: Available memory region 0x3ffca000 - 0x3ffcc000
V (472) memory_layout: Examining memory region 0x3ffcc000 - 0x3ffce000
D (479) memory_layout: Available memory region 0x3ffcc000 - 0x3ffce000
V (485) memory_layout: Examining memory region 0x3ffce000 - 0x3ffd0000
D (492) memory_layout: Available memory region 0x3ffce000 - 0x3ffd0000
V (498) memory_layout: Examining memory region 0x3ffd0000 - 0x3ffd2000
D (505) memory_layout: Available memory region 0x3ffd0000 - 0x3ffd2000
V (512) memory_layout: Examining memory region 0x3ffd2000 - 0x3ffd4000
D (518) memory_layout: Available memory region 0x3ffd2000 - 0x3ffd4000
V (525) memory_layout: Examining memory region 0x3ffd4000 - 0x3ffd6000
D (531) memory_layout: Available memory region 0x3ffd4000 - 0x3ffd6000
V (538) memory_layout: Examining memory region 0x3ffd6000 - 0x3ffd8000
D (545) memory_layout: Available memory region 0x3ffd6000 - 0x3ffd8000
V (551) memory_layout: Examining memory region 0x3ffd8000 - 0x3ffda000
D (558) memory_layout: Available memory region 0x3ffd8000 - 0x3ffda000
V (564) memory_layout: Examining memory region 0x3ffda000 - 0x3ffdc000
D (571) memory_layout: Available memory region 0x3ffda000 - 0x3ffdc000
V (578) memory_layout: Examining memory region 0x3ffdc000 - 0x3ffde000
D (584) memory_layout: Available memory region 0x3ffdc000 - 0x3ffde000
V (591) memory_layout: Examining memory region 0x3ffde000 - 0x3ffe0000
D (597) memory_layout: Available memory region 0x3ffde000 - 0x3ffe0000
V (604) memory_layout: Examining memory region 0x3ffe0000 - 0x3ffe4000
V (611) memory_layout: Start of region 0x3ffe0000 - 0x3ffe4000 overlaps reserved 0x3ffe0000 - 0x3ffe0440
V (620) memory_layout: End of region 0x3ffe0440 - 0x3ffe4000 overlaps reserved 0x3ffe3f20 - 0x3ffe4350
D (629) memory_layout: Available memory region 0x3ffe0440 - 0x3ffe3f20
V (636) memory_layout: Examining memory region 0x3ffe4000 - 0x3ffe8000
V (643) memory_layout: Start of region 0x3ffe4000 - 0x3ffe8000 overlaps reserved 0x3ffe3f20 - 0x3ffe4350
D (652) memory_layout: Available memory region 0x3ffe4350 - 0x3ffe8000
V (659) memory_layout: Examining memory region 0x3ffe8000 - 0x3fff0000
D (665) memory_layout: Available memory region 0x3ffe8000 - 0x3fff0000
V (672) memory_layout: Examining memory region 0x3fff0000 - 0x3fff8000
D (679) memory_layout: Available memory region 0x3fff0000 - 0x3fff8000
V (685) memory_layout: Examining memory region 0x3fff8000 - 0x3fffc000
D (692) memory_layout: Available memory region 0x3fff8000 - 0x3fffc000
V (698) memory_layout: Examining memory region 0x3fffc000 - 0x40000000
D (705) memory_layout: Available memory region 0x3fffc000 - 0x40000000
V (712) memory_layout: Examining memory region 0x40070000 - 0x40078000
V (718) memory_layout: Region 0x40070000 - 0x40078000 inside of reserved 0x40070000 - 0x40078000
V (727) memory_layout: Examining memory region 0x40078000 - 0x40080000
0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

V (734) memory_layout: Region 0x40078000 - 0x40080000 inside of reserved 0x40078000 - 0x40080000
0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

V (742) memory_layout: Examining memory region 0x40080000 - 0x40082000
0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

0x40082000: xPortGetCoreID at /Users/local/esp/esp-idf/components/freertos/include/freertos/portable.h:210
 (inlined by) xPortInterruptedFromISRContext at /Users/local/esp/esp-idf/components/freertos/port.c:350

V (749) memory_layout: Region 0x40080000 - 0x40082000 inside of reserved 0x40080000 - 0x4008b36c
0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

0x40082000: xPortGetCoreID at /Users/local/esp/esp-idf/components/freertos/include/freertos/portable.h:210
 (inlined by) xPortInterruptedFromISRContext at /Users/local/esp/esp-idf/components/freertos/port.c:350

0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

V (758) memory_layout: Examining memory region 0x40082000 - 0x40084000
0x40082000: xPortGetCoreID at /Users/local/esp/esp-idf/components/freertos/include/freertos/portable.h:210
 (inlined by) xPortInterruptedFromISRContext at /Users/local/esp/esp-idf/components/freertos/port.c:350

0x40084000: timer_count_reload at /Users/local/esp/esp-idf/components/esp32/esp_timer_esp32.c:166
 (inlined by) timer_alarm_isr at /Users/local/esp/esp-idf/components/esp32/esp_timer_esp32.c:281

V (765) memory_layout: Region 0x40082000 - 0x40084000 inside of reserved 0x40080000 - 0x4008b36c
0x40082000: xPortGetCoreID at /Users/local/esp/esp-idf/components/freertos/include/freertos/portable.h:210
 (inlined by) xPortInterruptedFromISRContext at /Users/local/esp/esp-idf/components/freertos/port.c:350

0x40084000: timer_count_reload at /Users/local/esp/esp-idf/components/esp32/esp_timer_esp32.c:166
 (inlined by) timer_alarm_isr at /Users/local/esp/esp-idf/components/esp32/esp_timer_esp32.c:281

0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

V (773) memory_layout: Examining memory region 0x40084000 - 0x40086000
0x40084000: timer_count_reload at /Users/local/esp/esp-idf/components/esp32/esp_timer_esp32.c:166
 (inlined by) timer_alarm_isr at /Users/local/esp/esp-idf/components/esp32/esp_timer_esp32.c:281

0x40086000: xQueueGenericSendFromISR at /Users/local/esp/esp-idf/components/freertos/queue.c:1205

V (780) memory_layout: Region 0x40084000 - 0x40086000 inside of reserved 0x40080000 - 0x4008b36c
0x40084000: timer_count_reload at /Users/local/esp/esp-idf/components/esp32/esp_timer_esp32.c:166
 (inlined by) timer_alarm_isr at /Users/local/esp/esp-idf/components/esp32/esp_timer_esp32.c:281

0x40086000: xQueueGenericSendFromISR at /Users/local/esp/esp-idf/components/freertos/queue.c:1205

0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

V (789) memory_layout: Examining memory region 0x40086000 - 0x40088000
0x40086000: xQueueGenericSendFromISR at /Users/local/esp/esp-idf/components/freertos/queue.c:1205

0x40088000: xthal_window_spill_nw at /Users/igrokhotkov/e/esp32/hal/hal/windowspill_asm.S:267

V (795) memory_layout: Region 0x40086000 - 0x40088000 inside of reserved 0x40080000 - 0x4008b36c
0x40086000: xQueueGenericSendFromISR at /Users/local/esp/esp-idf/components/freertos/queue.c:1205

0x40088000: xthal_window_spill_nw at /Users/igrokhotkov/e/esp32/hal/hal/windowspill_asm.S:267

0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

V (804) memory_layout: Examining memory region 0x40088000 - 0x4008a000
0x40088000: xthal_window_spill_nw at /Users/igrokhotkov/e/esp32/hal/hal/windowspill_asm.S:267

0x4008a000: spi_flash_hal_read at /Users/local/esp/esp-idf/components/soc/src/hal/spi_flash_hal_common.inc:99

V (811) memory_layout: Region 0x40088000 - 0x4008a000 inside of reserved 0x40080000 - 0x4008b36c
0x40088000: xthal_window_spill_nw at /Users/igrokhotkov/e/esp32/hal/hal/windowspill_asm.S:267

0x4008a000: spi_flash_hal_read at /Users/local/esp/esp-idf/components/soc/src/hal/spi_flash_hal_common.inc:99

0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

V (820) memory_layout: Examining memory region 0x4008a000 - 0x4008c000
0x4008a000: spi_flash_hal_read at /Users/local/esp/esp-idf/components/soc/src/hal/spi_flash_hal_common.inc:99

V (826) memory_layout: Start of region 0x4008a000 - 0x4008c000 overlaps reserved 0x40080000 - 0x4008b36c
0x4008a000: spi_flash_hal_read at /Users/local/esp/esp-idf/components/soc/src/hal/spi_flash_hal_common.inc:99

0x40080000: _WindowOverflow4 at /Users/local/esp/esp-idf/components/freertos/xtensa_vectors.S:1778

D (836) memory_layout: Available memory region 0x4008b36c - 0x4008c000
V (842) memory_layout: Examining memory region 0x4008c000 - 0x4008e000
D (849) memory_layout: Available memory region 0x4008c000 - 0x4008e000
V (856) memory_layout: Examining memory region 0x4008e000 - 0x40090000
jame113 wrote:
Tue Aug 10, 2021 8:51 am
@ESP_igrr 大神, 我已按您建议的1,2,3修改了代码, 现在可以正常挂载,并且读取windows下拷贝的文件了。
但ff_raw_write函数写入部分,因为我水平太低, 并且对文件系统底层基本不懂, 我尝试了很多遍,都没写出来, 这个需求阻塞在我这快两个礼拜了, 能否帮实现一下ff_raw_write函数? 多谢。:)


ESP_igrr wrote:
Tue Aug 10, 2021 6:23 am
I think the reason why you can't mount the filesystem created by Windows is that the firmware code uses 4096 bytes as the sector size.
When you format the partition in Windows, it allows you to choose the cluster size, not sector size. Windows sets sector size to 512 bytes.

You can try to modify the code in diskio_rawflash as follows:
1. In ff_raw_ioctl, return 512 bytes from GET_SECTOR_SIZE.
2. In the same function, change GET_SECTOR_COUNT calculation to divide the size by 512.
3. In ff_raw_read use 512 bytes instead of SPI_FLASH_SEC_SIZE as the unit.
4. In ff_raw_write, the logic becomes more complex. Allocate a temporary 4kB buffer, read the 4kb aligned flash sector containing the block you need into the buffer. Replace the part that needs to be overwritten. Erase the 4kB flash sector. Write the 4kb sector to flash.

Note that if your device can be suddenly powered off, this read-modify-write approach in ff_raw_write may result in a loss of data. I don't think it makes things a lot worse, though, as FATFS has pretty poor tolerance to such power-off scenarios anyway.

Who is online

Users browsing this forum: No registered users and 56 guests