lioryb
Posts: 5
Joined: Thu Jul 12, 2018 11:02 am

Connecting external raw nand using GPIO - RPI3b

Thu Jul 12, 2018 12:10 pm

Hi.

I'm trying to define a device tree for connecting an external raw NAND using GPIO on RPI3. I found that there are available drivers, and I found an example in the sources' "Documentation" directory (Documentation/devicetree/bindings/mtd/gpio-control-nand.txt) Yet, while using this example, I couldn't find how to define the banka label that appears there, and although DTB compilation doesn't fail, when trying to load the device tree (using dtoverlay command) it fails to load with issue on this banka component. I found a banka declaration on pichochip dts file, but it when trying to copy it to my dts, it doesn't compile. Moreover, I couldn't find how am I suppose to connect the RAW NAND to the GPIO connectors, which pins to use (specifically the data/address pins, which are supposed to be "address mapped").

Can any one point to a solution for that? I am struggling this issue for a couple of days now...

Thanks.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1755
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Connecting external raw nand using GPIO - RPI3b

Thu Jul 12, 2018 2:02 pm

The exact form of a gpio declaration is system-specific. But the first term is a reference to a label in the Device Tree, where the label is meant to be attached to a GPIO controller. On Raspberry Pi devices the main user-accessible GPIOs (the ones on the 40-pin header) are provided by a DT node with the label "gpio" and a compatible string of "brcm,bcm2835-gpio". The file "Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt" says:
- #gpio-cells : Should be two. The first cell is the pin number and the
second cell is used to specify optional parameters:
- bit 0 specifies polarity (0 for normal, 1 for inverted)
This means that unless you want an active-low output then your gpio reference should look like "<&gpio gpio-number 0>", where "gpio-number" is replaced with the number of the GPIO in the Broadcom numbering scheme (not the header pin number, or any other pseudo-helpful scheme). "<0>" is used to indicate an absent signal - some of them are optional.

Unfortunately I'm not sure how you would be able to provide the "address mapped" I/O port to read from and write to the NAND. I think the idea is that a small (byte wide?) register in your device reads/writes the state of 8/16 pins that can be wired to the device. By configuring the address of that register in Device Tree you can avoid writing a device-specific driver. However, I don't think there is such a port in the Raspberry Pi. In a sense the GPIO controller could be thought of in that way, but it would need some configuration beforehand and a read/modify/write sequence to write less than 32-bits at once.

Are there no I2C- or SPI-addressable devices that would do what you want?

lioryb
Posts: 5
Joined: Thu Jul 12, 2018 11:02 am

Re: Connecting external raw nand using GPIO - RPI3b

Sun Jul 15, 2018 8:20 am

Thanks Phil for you reply.
Reading deeper into BCM2835 datasheet shows that some of the GPIO pins may be configured to Secondary Module Interface, and the example in "Documentation/devicetree/bindings/misc/brcm,bcm2835-smi.txt" specifically mentions the use for NAND.
Wouldn't that answer my issue?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1755
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Connecting external raw nand using GPIO - RPI3b

Mon Jul 16, 2018 8:39 am

I have been only dimly aware of SMI - I've used I2C, SPI, SD, but not SMI - so when you mentioned NAND I didn't immediately think of it. But yes - the BCM2835 has an SMI interface, and there is a driver and overlay for it in the RPi kernel trees. There is also a NAND adaptation layer driver and overlay.

Note that the generic SMI overlay tries to claim GPIOs 2-25, while the SMI NAND overlays wants GPIOs 0-15 for an 8-bit data bus.

There isn't a lot of documentation available, but have a read through this thread and I'll try to answer any questions you have.

lioryb
Posts: 5
Joined: Thu Jul 12, 2018 11:02 am

Re: Connecting external raw nand using GPIO - RPI3b

Mon Jul 16, 2018 9:43 am

Thanks again for your help.
I did notice that there is that smi-nand ovleray and went through the thread you mentioned. Unfortunately, the thread hardly mentions the nand issue, so I couldn't find any help there. The only thing I could get from there, is that looks like I need to load both smi overlay and smi-nand overlay, which sounds quiet weird. I though only nand-smi is to be used.

Moreover, Looking at the pinout connectivity of ALT2 (https://elinux.org/RPi_BCM2835_GPIOs), I couldn't understand the correct physical connection.
The only signals I could be sure to connect are OE/RE to J8-31 and WE to J8-26.
The nand uses the same pins both for address and for data, so I guess that would be on SD0-SD7 (since SAx is only available up to SA5).
So I am missing the connectivity for the rest of the signals: CLE, ALE, R_B and CE. Is there anyway to understand what is connected where, according to the driver/device tree?

Thanks, again, for you major help.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1755
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Connecting external raw nand using GPIO - RPI3b

Mon Jul 16, 2018 10:00 am

The post is a bit ambiguous, but the smi-nand overlay (at least as it is now) is standalone.

I don't know whether the SMI interface can multiplex address and data on the same lines - that's clearly not the way this overlay is expected to be used. I've pinged LukeW, the author of the driver, in case he has any insights or suggestions.

lioryb
Posts: 5
Joined: Thu Jul 12, 2018 11:02 am

Re: Connecting external raw nand using GPIO - RPI3b

Mon Jul 16, 2018 10:28 am

Address and Data are multiplexed on NAND device, That is how NAND works. The main issue is that it should support both output and input.
Is there any 'thumb-rule' where I can find how to connect the RPI3 headers pin? How can I find each pins' connectivity, from the smi-nand driver?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1755
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Connecting external raw nand using GPIO - RPI3b

Mon Jul 16, 2018 10:40 am

The GPIO alternate function assignments are listed on page 102 of the BCM2835 ARM Peripherals guide.

lioryb
Posts: 5
Joined: Thu Jul 12, 2018 11:02 am

Re: Connecting external raw nand using GPIO - RPI3b

Mon Jul 16, 2018 11:01 am

I know that guide, but on ALT1, which is the relevant assignment for the SMI-NAND, GPIO-GPIO, are called SA5-SA0, while it should have CE, R/B ALE, CLE ext.

I noticed, on the driver code, the following defines:
#define SMI_NAND_CLE_PIN 0x01
#define SMI_NAND_ALE_PIN 0x02

and I wonder does these pins are GPIO1 and GPIO2?

Return to “Device Tree”

Who is online

Users browsing this forum: qphan734 and 1 guest