Closed zhangjinxing closed 1 year ago
Thanks for the feedback.
I notice that you mentioned "SCB_InvalidateDCache is not working". If you are adding cache validating, I would recommend add caching solutions (invalidating or copy to cache safe buffer) to host controller driver (HCD) so upper level can directly use regular memory instead of cache safe memory.
For operation with FileX, the FileX operation buffer is allocated in cache safe memory (in ux_host_class_storage_media_open.c:152), the FileX operations are expected to use the buffer, so the buffer passed to "_transport" is expected to be cache safe, please check if there is some issue to let the buffer "skipped" to cause the issue.
谢谢! 关于 FileX ,我看到 fx_file_read.c 281 行对 1 扇区读取使用了 fx_media_memory_buffer CACHESAFE 缓存再通过 _fx_utility_memory_copy 拷贝到目标内存。但是在 307 行对多个山区读取时使用 CACHESAFE 缓存,直接进行 USB IO 读取。
// 306 行 media_ptr -> fx_media_disable_burst_cache = file_ptr -> fx_file_disable_burst_cache; status = _fx_utility_logical_sector_read(media_ptr, file_ptr -> fx_file_current_logical_sector, destination_ptr, (ULONG) sectors, FX_DATA_SECTOR); media_ptr -> fx_media_disable_burst_cache = FX_FALSE;
这样 fx_file_read 读取的文件时,一部分使用 fx_media_memory_buffer 再 copy 到内存,另一部分使用 _fx_utility_logical_sector_read 直接读取数据,外面使用 SCB_InvalidateDCache() 函数由于读取的数据没有按 cache line 对齐而出错。
Thanks for the feedback. I think for cache safe copying, it's better in HCD. Note that the data copying decreases the performance, so from system side it's better considering to put appliation data in cache page aligned area or cache safe area to avoid re-copying of data.
我在 i.MX RT1052 项目中使用 FileX 和 USBX 读取 U 盘中的文件,发现 fx_file_read 读取文件时,必须提供 CACHESAFE 内存才能读取到正确的数据(使用 SCB_InvalidateDCache 不能正常工作)。如果挂载两个 FileX 文件系统,一个必须提供 CACHESAFE 内存才能工作 ,而另一个文件系统无需 CACHESAFE 内存就可以工作。这会导致程序不统一和混乱。
// CACHESAFE buff AT_NONCACHEABLE_SECTION(ULONG local_buffer[DEMO_BUFFER_SIZE / sizeof(ULONG)]); status = fx_file_read(&my_file, local_buffer, bufferSize, &requested_length);
我看到 FileX 使用了直接 IO 的方式读取数据,调用 _ux_host_class_storage_transport 读取数据。
UINT _ux_host_class_storage_transport(UX_HOST_CLASS_STORAGE storage, UCHAR data_pointer) { UINT status; UINT csw_status;
}
该函数最终调用 _ux_host_class_storage_transport_bo 完成传输请求,但是这种硬件传输请求在 ehci 中不是 cache 安全的。 能否根据 _ux_system -> ux_system_cache_safe_memory_pool_base 不为 NULL 增加额外的数据拷贝,为上层提供 cache 安全的操作接口: