|
最近在学Threadx,就想着用用filex+levelx玩玩,于是就用STM32H750的内部512K SRAM模拟了一个U盘,现在U盘可以发现,可以存小一点的文件,也可以正常读取,但是存400K左右非常缓慢,也不容易存进去,200K左右的秒存,读的也快,格式化一直不成功,非常郁闷,哪位大神帮忙看看是什么问题啊!这个问题困扰我好久了,一直搞不定!
下面是部分代码:
lx_stm32_nor_simulator_driver.c:
static UINT lx_nor_simulator_read(ULONG *flash_address, ULONG *destination, ULONG words)
{
memcpy((VOID *)destination, (VOID *)flash_address, words * sizeof(ULONG));
return(LX_SUCCESS);
}
static UINT lx_nor_simulator_write(ULONG *flash_address, ULONG *source, ULONG words)
{
memcpy((VOID *)flash_address, (VOID *)source, words * sizeof(ULONG));
return(LX_SUCCESS);
}
static UINT lx_nor_simulator_block_erase(ULONG block, ULONG erase_count)
{
uint32_t index;
ULONG *pointer;
//LX_PARAMETER_NOT_USED(erase_count);
/* Setup pointer. */
for(index=0;index < erase_count;index++){
pointer = (ULONG *) (LX_NOR_SIMULATOR_FLASH_BASE_ADDRESS + (block+index) * (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK));
/* Loop to erase block. */
mem_set((VOID *) pointer, 0xff, words_per_block * sizeof(ULONG));
}
return(LX_SUCCESS);
}
usb_device_msc.c:
UINT USBD_STORAGE_Read(VOID *storage_instance, ULONG lun, UCHAR *data_pointer,
ULONG number_blocks, ULONG lba, ULONG *media_status)
{
UINT status = UX_SUCCESS;
while(number_blocks--)
{
status = fx_media_read(&nor_simulator_flash_disk,lba,data_pointer);
data_pointer+=STORAGE_SECTOR_SIZE;
lba++;
}
return status;
}
UINT USBD_STORAGE_Write(VOID *storage_instance, ULONG lun, UCHAR *data_pointer,
ULONG number_blocks, ULONG lba, ULONG *media_status)
{
UINT status = UX_SUCCESS;
while(number_blocks--)
{
status = fx_media_write(&nor_simulator_flash_disk,lba,data_pointer);
data_pointer+=STORAGE_SECTOR_SIZE;
lba++;
}
/* USER CODE END USBD_STORAGE_Write */
return status;
}
app_filex.c:
if(flag == 0){
nor_sim_status = fx_media_format(&nor_simulator_flash_disk, // nor_simulator_flash_disk pointer
fx_stm32_levelx_nor_driver, // Driver entry
(VOID *)LX_NOR_SIMULATOR_DRIVER_ID, // Device info pointer //LX_NOR_SIMULATOR_DRIVER_ID
(UCHAR *) fx_nor_simulator_media_memory, // Media buffer pointer
sizeof(fx_nor_simulator_media_memory), // Media buffer size
FX_NOR_SIMULATOR_VOLUME_NAME, // Volume Name
FX_NOR_SIMULATOR_NUMBER_OF_FATS, // Number of FATs
32, // Directory Entries
FX_NOR_SIMULATOR_HIDDEN_SECTORS, // Hidden sectors
1024,//((LX_NOR_SIMULATOR_FLASH_SIZE - LX_NOR_SIMULATOR_SECTOR_SIZE) / FX_NOR_SIMULATOR_SECTOR_SIZE), // Total sectors minus one
512, // Sector size
8, // Sectors per cluster
1, // Heads
1); // Sectors per track
/* Check the format nor_sim_status */
if (nor_sim_status != FX_SUCCESS)
{
/* USER CODE BEGIN NOR Simulator format error */
while(1);
/* USER CODE END NOR Simulator format error */
}
}
/* Open the SIMULATOR NOR driver */
nor_sim_status = fx_media_open(&nor_simulator_flash_disk, FX_NOR_SIMULATOR_VOLUME_NAME, fx_stm32_levelx_nor_driver, (VOID *)LX_NOR_SIMULATOR_DRIVER_ID, (VOID *) fx_nor_simulator_media_memory, sizeof(fx_nor_simulator_media_memory));
/* Check the media open nor_sim_status */
if (nor_sim_status != FX_SUCCESS)
{
/* USER CODE BEGIN NOR Simulator open error */
while(1);
/* USER CODE END NOR Simulator open error */
}
/* USER CODE BEGIN fx_app_thread_entry 1 */
/* Get the available usable space */
nor_ospi_status = fx_media_space_available(&nor_simulator_flash_disk, &available_space_pre);
/* Check the get available state request status. */
if (nor_ospi_status != FX_SUCCESS)
{
Error_Hand();
}
/* Create a file called STM32.TXT in the root directory. */
nor_ospi_status = fx_file_create(&nor_simulator_flash_disk, "STM32.TXT");
/* Check the create status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Check for an already created status. This is expected on the
second pass of this loop! */
if (nor_ospi_status != FX_ALREADY_CREATED)
{
/* Create error, call error handler. */
Error_Hand();
}
}
/* Open the test file. */
nor_ospi_status = fx_file_open(&nor_simulator_flash_disk, &fx_file, "STM32.TXT", FX_OPEN_FOR_WRITE);
/* Check the file open status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error opening file, call error handler. */
Error_Hand();
}
/* Seek to the beginning of the test file. */
nor_ospi_status = fx_file_seek(&fx_file, 0);
/* Check the file seek status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error performing file seek, call error handler. */
Error_Hand();
}
/* Write a string to the test file. */
nor_ospi_status = fx_file_write(&fx_file, data, sizeof(data));
/* Check the file write status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error writing to a file, call error handler. */
Error_Hand();
}
/* Close the test file. */
nor_ospi_status = fx_file_close(&fx_file);
/* Check the file close status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error closing the file, call error handler. */
Error_Hand();
}
nor_ospi_status = fx_media_flush(&nor_simulator_flash_disk);
/* Check the media flush status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error closing the file, call error handler. */
Error_Hand();
}
/* Open the test file. */
nor_ospi_status = fx_file_open(&nor_simulator_flash_disk, &fx_file, "STM32.TXT", FX_OPEN_FOR_READ);
/* Check the file open status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error opening file, call error handler. */
Error_Hand();
}
/* Seek to the beginning of the test file. */
nor_ospi_status = fx_file_seek(&fx_file, 0);
/* Check the file seek status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error performing file seek, call error handler. */
Error_Hand();
}
/* Read the first 28 bytes of the test file. */
nor_ospi_status = fx_file_read(&fx_file, read_buffer, sizeof(data), &bytes_read);
/* Check the file read status. */
if ((nor_ospi_status != FX_SUCCESS) || (bytes_read != sizeof(data)))
{
/* Error reading file, call error handler. */
Error_Hand();
}
/* Close the test file. */
nor_ospi_status = fx_file_close(&fx_file);
/* Check the file close status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error closing the file, call error handler. */
Error_Hand();
}
#if 0
/* Get the available usable space, after the file has been created */
nor_ospi_status = fx_media_space_available(&nor_simulator_flash_disk, &available_space_post);
/* Check the get available state request status. */
if (nor_ospi_status != FX_SUCCESS)
{
Error_Hand();
}
/* Close the media. */
nor_ospi_status = fx_media_close(&nor_simulator_flash_disk);
/* Check the media close status. */
if (nor_ospi_status != FX_SUCCESS)
{
/* Error closing the media, call error handler. */
Error_Hand();
}
#endif
/* USER CODE END fx_app_thread_entry 1 */
/* USER CODE END fx_app_thread_entry 0 */
for(;;){
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
tx_thread_sleep(200);
}
}
|
|