Skip to main content
October 11, 2020
Solved

STM32F105 mass storage device: file system breaks when writing a file larger than 12 KB

  • October 11, 2020
  • 3 replies
  • 1067 views

Hello! If I write less than 12KB #MSD works fine. If I write more than 12KB, Windows7 will ask me to format the drive. If the MSD is not reconnected to the PC, everything works fine. Everything breaks down if Ireconnect the device to the PC. Please tell me what could be wrong?

I am using flash with page size 264 B (2048 pages) [AT45DB041]

The defines looks like this

 STORAGE_BLK_NBR               1024

 STORAGE_BLK_SIZ                  512

The write operation looks like this

int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)

{

  /* USER CODE BEGIN 7 */

  AT45dbxx_WritePage(buf, 256, (uint16_t)blk_addr*2);

  AT45dbxx_WritePage(buf+256, 256, ((uint16_t)blk_addr*2)+1);

  return (USBD_OK);

  /* USER CODE END 7 */

}

I write two pages of 256 bytes

W / R memory operations are working properly.

Memory addressing also works correctly. Checked read / write of all 2048 pages

#msd

#AT45DB

This topic has been closed for replies.
Best answer by Tesla DeLorean

Do you need to erase the blocks?

Don't seem to handle multiple block writes.

Test the read/write functionality oitside of the USB operation.​

3 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
October 11, 2020

Do you need to erase the blocks?

Don't seem to handle multiple block writes.

Test the read/write functionality oitside of the USB operation.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
October 11, 2020

Thanks for the answer. Yes, I tested it separately. That being said, if I write files less than 12 KB, everything works well.

Tesla DeLorean
Guru
October 13, 2020

The code presented writes a single block, it will clearly fail to do the job if asked to write more than one.

blk_len is a count of 512 byte blocks

https://github.com/geoffreymbrown/stm32cubef3-examples/blob/master/ramdisk/Src/usbd_storage_if.c#L264

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..