Skip to main content
Explorer
January 21, 2025
Question

stm32F10x MSC with SPI Flash (W25Q256) problem

  • January 21, 2025
  • 2 replies
  • 649 views

Hello,

I am trying make a USB device MSC.

It works fine with SD card, but I want both SD card and flash.( I set max_lun to 1.)

I have wrote the SPI_Flash_Write and  SPI_Flash_Read that can be called by MAL_Write and MAL_Read.

It seems work fine cause I can format the flash disk on my computer and put files into the disk.

However, everytime I turn off my board and turn on it, it ask me to format the disk again and again.

I have searched many solutions. Someone said that I should use FATFS f_mkfs to format first.

I tried but not worked , is that true or any other problem I missed ? 

 

Regards,

thonsha

 

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    January 23, 2025

    Hi @thonsha 

    Would you provide some code snippets for these functions " SPI_Flash_Write and  SPI_Flash_Read that can be called by MAL_Write and MAL_Read" .

    I suggest you as a first step to isolate the problem and start with an example FATFS with micro SD card. Then we can move and use it as MSC Device.

    Graduate II
    January 23, 2025

    >>It seems work fine cause I can format the flash disk on my computer and put files into the disk.

    Seems a bit subjective, given it's not actually retaining content. The caching on the host will hide a lot of ills.

    Perhaps use 4KB sectors on the FLASH, and test the read returns the same data that was written. Have a big enough sector buffer, and MAX_SS is adequate.

    You should only need to format the content once, either from the Host or via f_mkfs()

    thonshaAuthor
    Explorer
    February 3, 2025

    Hi @Tesla DeLorean 

    Sorry for the late response. Just come back from the long vacation. :)

    4KB sectors on the FLASH might be the key problem.

    I can only format the FLASH with 512 byte sector, maybe it's why FLASH don't retain content.

    I failed to format when using 4KB sector.

    I guess something wrong with  Write_Memory( ) function in memory.c because it support SD card with 512 byte sector.

    I have no idea how to fix it . Is there any good suggestion ? 

    Thanks.