cancel
Showing results for 
Search instead for 
Did you mean: 

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

Sam Sam
Associate

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

1 ACCEPTED SOLUTION

Accepted Solutions

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
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

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
Up vote any posts that you find helpful, it shows what's working..
Sam Sam
Associate

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

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
Up vote any posts that you find helpful, it shows what's working..