cancel
Showing results for 
Search instead for 
Did you mean: 

problem mapping NAND flash to PC through USB_MSC

MVV.1
Associate II

I just made a FS_USB_MSC project and I wanted to access the flash from my windows computer.

when I use RAM space for the STORAGE_Read_FS and STORAGE_Write_FS I can Access the RAM without any problem. and also I can format the space in windows to be able to access it.

but when I use HAL_NAND functions the windows says "windows was unable to complete the format". the fucntions that I wrote to access the flash memory are :

*************************************************************************

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

{

 /* USER CODE BEGIN 6 */

pAddressz = (NAND_AddressTypeDef){blk_addr%64,0,blk_addr/64}; //page,plane,block

if(HAL_NAND_Read_Page_8b(&hnand1, &pAddressz, buf, blk_len) != HAL_OK){

return USBD_FAIL;

}

 return (USBD_OK);

 /* USER CODE END 6 */

}

/**

 * @brief .

 * @param lun: .

 * @retval USBD_OK if all operations are OK else USBD_FAIL

 */

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

{

 /* USER CODE BEGIN 7 */

pAddressz = (NAND_AddressTypeDef){blk_addr%64,0,blk_addr/64}; //page,plane,block

if(HAL_NAND_Write_Page_8b(&hnand1, &pAddressz, buf, blk_len) != HAL_OK){

return USBD_FAIL;

}

 return (USBD_OK);

 /* USER CODE END 7 */

}

**********************************************************************

pls help find the problem.

1 ACCEPTED SOLUTION

Accepted Solutions

For the write you'll need to manage the erase and larger erase block size

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

9 REPLIES 9

For the write you'll need to manage the erase and larger erase block size

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

what do you mean by "manage the erase"?

and what do you mean by "larger erase block size"?

You have to erase data in flash before you can re-write over it.

The erase size is likely 128KB, or more, you're writing 512 byte blocks into the middle of that, the mass storage device expects the other data to be kept safe, not disappear.

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

I set the MSC block size to 2048 bytes and its number to 65536.

my memory is a " 1024 block * 64 page * 2048 byte " one.

so each block of the MSC is mapped to a page in the flash memory.

also I have erased the whole flash before starting the write process. I don't understand why the windows is unable to format the device!

I actually want to transfer all the data in the flash memory to my computer. is there any better way to do this in a high transfer rate than mass storage?

>> I don't understand why the windows is unable to format the device!

In simple terms because the block storage functionality isn't returning the same data that was previously written. You should validate the functionality rigorously. Perhaps some simple instrumentation on the read/write showing the block(s) involved in the transfer and the CRC for the data in that block. Do the format and look at the data written, vs that subsequently read back.

You don't indicate what make/model of NAND memory involved here.

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

my NAND memory is "K9F1G08U0E". does it help in answering my question about choosing a better way to do this task? (my question was "I actually want to transfer all the data in the flash memory to my computer. is there any better way to do this in a high transfer rate than mass storage?")

I will try this and come back in few days and be looking for your answer

Ok, so it is 128K, so in a situation where you are writing multiple blocks, and they aren't suitably aligned, you'll need to handle the case where you selectively overwrite part of a 128KB erase block. Aligning the file system structures, and clusters to fit the larger 128K expectations will simplify things a little. SD Cards are typically cleverly formatted so as to not be unduly slow.

Better is subjective. On the supposition you don't want to write drivers and applications on the Windows/Linux side you need to fit into a more standardized form. If the data is read-only from the PC's perspective, emulating a CD/DVD MSC might be more efficient. Pretending to be a hard drive with 512-byte sectors, and FAT File System, would be the most ubiquitous.

In terms of bus utilization, USB MSC is close to optimal

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MVV.1
Associate II

Thanks for helping me Tesla DeLorean!