Author Topic: Interfacing NAND Flash to USB Driver  (Read 15635 times)

Harish

  • Member
  • ***
  • Posts: 8
Interfacing NAND Flash to USB Driver
« on: February 23, 2017, 03:15:53 am »
Hello Everyone,

I am developing a system where NAND flash is connected to Xilinx Zynq controller and this has to be interfaced as a USB mass storage device.
Standard is USB 2.0 system and mass storage device memory is 256MB.

USB driver is in Xilinx Zynq controller which is connected to USB ULPI Transceiver.
https://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf

I am able to develop USB driver for internal memory and also driver to read and write to NAND flash.
But I am not able to connect both memories.  I need suggestions from this forum to finish.

1. How do I link the NAND flash memory to USB driver
Eg: When I connect mass storage device to Laptop I should be able to see the file system and files of NAND flash visible to host.

2. For transfer between host and device, how can I address the memory of NAND flash.

Please help me to debug this issue.

Thank you!!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interfacing NAND Flash to USB Driver
« Reply #1 on: February 23, 2017, 09:09:50 am »
The USB device needs to respond to enumeration requests and events from the host's USB driver and SCSI commands from the host's mass-storage driver.

If you have specific questions about how to accomplish these, feel free to ask.

Mass storage:

http://janaxelson.com/mass_storage.htm

USB:

http://janaxelson.com/usb.htm

Harish

  • Member
  • ***
  • Posts: 8
Re: Interfacing NAND Flash to USB Driver
« Reply #2 on: February 24, 2017, 12:09:49 am »
Thanks for the reply Jan,

I am able to develop the basic driver and SCSI commands for internal memory of 64MB.
Now I have to interface NAND Flash to SCSI command for writing and reading.

How to do this is I am not able to understand.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interfacing NAND Flash to USB Driver
« Reply #3 on: February 24, 2017, 11:36:38 am »
How to address the NAND Flash is specific to your device architecture.

If you have the device successfully responding to SCSI commands in USB mass-storage requests with other internal memory, I would think that you would just need to translate the addressing from the internal memory to the NAND Flash. This assumes that the NAND Flash has a supported file system.

If that is what you are attempting and it's not working, what is the problem you are seeing?

Harish

  • Member
  • ***
  • Posts: 8
Re: Interfacing NAND Flash to USB Driver
« Reply #4 on: March 21, 2017, 12:36:14 am »
Reading from NAND Flash takes lot of time. To read 1 page it takes 250micro seconds and to get the length of 64kbytes it takes 7.6ms.
So when host asks for data, I would like to send NACK (say data is not ready) then when data is ready I send data and then ACK.

I would like to know how to send NAK to host from device?

Thank you!!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interfacing NAND Flash to USB Driver
« Reply #5 on: March 21, 2017, 11:44:38 am »
How to configure the endpoints is specific to the device architecture.

See section 15.6.3 in the user guide you linked to in your original question.

Harish

  • Member
  • ***
  • Posts: 8
Re: Interfacing NAND Flash to USB Driver
« Reply #6 on: March 22, 2017, 09:29:41 am »
As SCSI states are called from Interrupt and If reading flash is taking more time interrupt will halt other tasks.
I thought we can send NAK and get another interrupt from host but its not working.

Can you help me in how to handle this situation?

In a way i have to get the logical address and length first and exit the ISR.
Later when I read the NAND flash for that data. I have to respond host.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interfacing NAND Flash to USB Driver
« Reply #7 on: March 22, 2017, 12:07:42 pm »
A bulk IN endpoint should be set to return NAK at all times except when there is new data ready to go out in the endpoint's buffer. On receiving NAK, the host will try again, multiple times if needed.

So yes, if the host sends a SCSI command to request data, the device should accept the command and prepare the IN endpoint to send the data. Typically, the device triggers an interrupt AFTER the IN endpoint sends data so it can prepare to refill the buffer if needed.


Harish

  • Member
  • ***
  • Posts: 8
Re: Interfacing NAND Flash to USB Driver
« Reply #8 on: March 23, 2017, 09:24:04 am »
It means can I send the data of 10kb in terms of 2kb, after 10kb sent send acknowledge.
Will it work like this?

Or any easy method to do it.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interfacing NAND Flash to USB Driver
« Reply #9 on: March 23, 2017, 01:50:59 pm »
I'm not sure I understand your question.

A SCSI READ command will request a number of bytes. In the data transport phase, the device returns the data, using as many transactions as needed. Each transaction begins with an IN token packet from the host, and the device responds with data or NAK if new data isn't yet ready to send. The amount of data in each transaction depends on the MaxPacketSize specified in the endpoint's descriptor.

Harish

  • Member
  • ***
  • Posts: 8
Re: Interfacing NAND Flash to USB Driver
« Reply #10 on: May 05, 2017, 09:56:14 am »
Hi Jan,

I am able to access the NAND flash with windows driver file system of FAT32 but not able to do the same in Linux.
I think the way transfer descriptors are responding to Linux OS is not right.

Is there any thing which is required to Linux which needs to be taken care?
Please help me.

Thanks!!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interfacing NAND Flash to USB Driver
« Reply #11 on: May 05, 2017, 08:53:29 pm »
A protocol analyzer will show the commands and responses on each system and may offer a clue to what is going wrong though you may have to decode them if your analyzer doesn't provide that. If you don't have a protocol analyzer, use whatever debugging tools you have (monitor program, watchpoints, etc.) to try to isolate the problem.

If the device complies with the specifications, the OSes will be happy.

See the links under Debugging here:

http://janaxelson.com/mass_storage.htm

If the problem is in transferring the descriptors, the device won't enumerate successfully and applications won't be able to access the device at all.