flash

package
v0.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockSize is the number of bytes in a block for most/all NOR flash memory
	BlockSize = 64 * 1024

	// SectorSize is the number of bytes in a sector for most/all NOR flash memory
	SectorSize = 4 * 1024

	// PageSize is the number of bytes in a page for most/all NOR flash memory
	PageSize = 256
)

Variables

View Source
var DefaultDeviceIdentifier = DeviceIdentifierFunc(func(id JedecID) Attrs {
	switch id.Uint32() {
	case 0x010617:
		return S25FL064L()
	case 0x014015:
		return S25FL216K()
	case 0x1F4501:
		return AT25DF081A()
	case 0xC22015:
		return MX25L1606()
	case 0xC22016:
		return MX25L3233F()
	case 0xC22817:
		return MX25R6435F()
	case 0xC84015:
		return GD25Q16C()
	case 0xC84017:
		return GD25Q64C()
	case 0xEF4015:
		return W25Q16JVIQ()
	case 0xEF4016:
		return W25Q32FV()
	case 0xEF4017:
		return W25Q64JVIQ()
	case 0xEF4018:
		return W25Q128JVSQ()
	case 0xEF6014:
		return W25Q80DL()
	case 0xEF6015:
		return W25Q16FW()
	case 0xEF6016:
		return W25Q32BV()
	case 0xEF7015:
		return W25Q16JVIM()
	case 0xEF7016:
		return W25Q32JVIM()
	case 0xEF7017:
		return W25Q64JVIM()
	case 0xEF7018:
		return W25Q128JVPM()
	default:
		return Attrs{JedecID: id}
	}
})

DefaultDeviceIndentifier is a DeviceIdentifier that is capable of recognizing JEDEC IDs for all of the known memory devices in this package. If you are have no way to be sure about the type of memory device that might be on a board you are targeting, this can be a good starting point to use. The downside of using this function is that it will prevent the compiler from being able to mark any of the functions for the various devices as unused, resulting in larger code size. If code size is a concern, and if you know ahead of time you are only dealing with a limited set of memory devices, it might be worthwhile to use your own implementation of a DeviceIdentifier that only references those devices, so that more methods are marked unused.

Functions

This section is empty.

Types

type Attrs

type Attrs struct {

	// TotalSize is the number of bytes that the flash device can store
	TotalSize uint32

	// StartUp is the duration of time between when the device is reset and when
	// it is ready to operation
	StartUp time.Duration

	// Three response bytes to 0x9f JEDEC ID command.
	JedecID

	// Max clock speed for all operations and the fastest read mode.
	MaxClockSpeedMHz uint8

	// Bitmask for Quad Enable bit if present. 0x00 otherwise. This is for the
	// highest byte in the status register.
	QuadEnableBitMask uint8

	HasSectorProtection bool

	// Supports the 0x0b fast read command with 8 dummy cycles.
	SupportsFastRead bool

	// Supports the fast read, quad output command 0x6b with 8 dummy cycles.
	SupportsQSPI bool

	// Supports the quad input page program command 0x32. This is known as 1-1-4
	// because it only uses all four lines for data.
	SupportsQSPIWrites bool

	// Requires a separate command 0x31 to write to the second byte of the status
	// register. Otherwise two byte are written via 0x01.
	WriteStatusSplit bool

	// True when the status register is a single byte. This implies the Quad
	// Enable bit is in the first byte and the Read Status Register 2 command
	// (0x35) is unsupported.
	SingleStatusByte bool
}

Attrs represent the differences in hardware characteristics and capabilities of various SPI flash memory devices.

func AT25DF081A

func AT25DF081A() Attrs

Settings for the Adesto Tech AT25DF081A 1MiB SPI flash. Its on the SAMD21 Xplained board. Datasheet: https://www.adestotech.com/wp-content/uploads/doc8715.pdf

func GD25Q16C

func GD25Q16C() Attrs

Settings for the Gigadevice GD25Q16C 2MiB SPI flash. Datasheet: http://www.gigadevice.com/datasheet/gd25q16c/

func GD25Q64C

func GD25Q64C() Attrs

Settings for the Gigadevice GD25Q64C 8MiB SPI flash. Datasheet: http://www.elm-tech.com/en/products/spi-flash-memory/gd25q64/gd25q64.pdf

func MX25L1606

func MX25L1606() Attrs

Settings for the Macronix MX25L1606 2MiB SPI flash. Datasheet:

func MX25L3233F

func MX25L3233F() Attrs

Settings for the Macronix MX25L3233F 4MiB SPI flash. Datasheet: http://www.macronix.com/Lists/Datasheet/Attachments/7426/MX25L3233F,%203V,%2032Mb,%20v1.6.pdf

func MX25R6435F

func MX25R6435F() Attrs

Settings for the Macronix MX25R6435F 8MiB SPI flash. Datasheet: http://www.macronix.com/Lists/Datasheet/Attachments/7428/MX25R6435F,%20Wide%20Range,%2064Mb,%20v1.4.pdf By default its in lower power mode which can only do 8mhz. In high power mode it can do 80mhz.

func S25FL064L

func S25FL064L() Attrs

Settings for the Cypress (was Spansion) S25FL064L 8MiB SPI flash. Datasheet: http://www.cypress.com/file/316661/download

func S25FL116K

func S25FL116K() Attrs

Settings for the Cypress (was Spansion) S25FL116K 2MiB SPI flash. Datasheet: http://www.cypress.com/file/196886/download

func S25FL216K

func S25FL216K() Attrs

Settings for the Cypress (was Spansion) S25FL216K 2MiB SPI flash. Datasheet: http://www.cypress.com/file/197346/download

func W25Q128JVPM

func W25Q128JVPM() Attrs

Settings for the Winbond W25Q128JV-PM 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf

func W25Q128JVSQ

func W25Q128JVSQ() Attrs

Settings for the Winbond W25Q128JV-SQ 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf

func W25Q16FW

func W25Q16FW() Attrs

Settings for the Winbond W25Q16FW 2MiB SPI flash. Datasheet: https://www.winbond.com/resource-files/w25q16fw%20revj%2005182017%20sfdp.pdf

func W25Q16JVIM

func W25Q16JVIM() Attrs

Settings for the Winbond W25Q16JV-IM 2MiB SPI flash. Note that JV-IQ has a different .memory_type (0x40) Datasheet: https://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf

func W25Q16JVIQ

func W25Q16JVIQ() Attrs

Settings for the Winbond W25Q16JV-IQ 2MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) Datasheet: https://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf

func W25Q32BV

func W25Q32BV() Attrs

Settings for the Winbond W25Q32BV 4MiB SPI flash. Datasheet: https://www.winbond.com/resource-files/w25q32bv_revi_100413_wo_automotive.pdf

func W25Q32FV

func W25Q32FV() Attrs

Settings for the Winbond W25Q32FV 4MiB SPI flash. Datasheet:http://www.winbond.com/resource-files/w25q32fv%20revj%2006032016.pdf?__locale=en

func W25Q32JVIM

func W25Q32JVIM() Attrs

Settings for the Winbond W25Q32JV-IM 4MiB SPI flash. Datasheet: https://www.winbond.com/resource-files/w25q32jv%20revg%2003272018%20plus.pdf

func W25Q64JVIM

func W25Q64JVIM() Attrs

Settings for the Winbond W25Q64JV-IM 8MiB SPI flash. Note that JV-IQ has a different .memory_type (0x40) Datasheet: http://www.winbond.com/resource-files/w25q64jv%20revj%2003272018%20plus.pdf

func W25Q64JVIQ

func W25Q64JVIQ() Attrs

Settings for the Winbond W25Q64JV-IQ 8MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) Datasheet: http://www.winbond.com/resource-files/w25q64jv%20revj%2003272018%20plus.pdf

func W25Q80DL

func W25Q80DL() Attrs

Settings for the Winbond W25Q80DL 1MiB SPI flash. Datasheet: https://www.winbond.com/resource-files/w25q80dv%20dl_revh_10022015.pdf

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device represents a NOR flash memory device accessible using SPI

func NewSPI

func NewSPI(spi *machine.SPI, sdo, sdi, sck, cs machine.Pin) *Device

NewSPI returns a pointer to a flash device that uses a SPI peripheral to communicate with a serial memory chip.

func (*Device) Attrs

func (dev *Device) Attrs() Attrs

Attrs returns the attributes of the device determined from the most recent call to Configure(). If no call to Configure() has been made, this will be the zero value of the Attrs struct.

func (*Device) Configure

func (dev *Device) Configure(config *DeviceConfig) (err error)

Configure sets up the device and the underlying transport mechanism. The DeviceConfig argument allows the caller to specify an instance of the DeviceIdentifier interface that, if provided, will be used to retrieve the attributes of the device based on the JEDEC ID.

func (*Device) EraseAll

func (dev *Device) EraseAll() error

EraseChip erases the entire flash memory chip

func (*Device) EraseBlock

func (dev *Device) EraseBlock(blockNumber uint32) error

EraseBlock erases a block of memory at the specified index

func (*Device) EraseBlockSize

func (dev *Device) EraseBlockSize() int64

EraseBlockSize returns the smallest erasable area on this particular chip in bytes. This is used for the block size in EraseBlocks. For SPI NOR flash this is the sector size, usually/always 4096.

func (*Device) EraseBlocks

func (dev *Device) EraseBlocks(start, len int64) error

EraseBlocks erases the given number of blocks. An implementation may transparently coalesce ranges of blocks into larger bundles if the chip supports this. The start and len parameters are in block numbers, use EraseBlockSize to map addresses to blocks.

func (*Device) EraseSector

func (dev *Device) EraseSector(sectorNumber uint32) error

EraseSector erases a sector of memory at the given index

func (*Device) ReadAt

func (dev *Device) ReadAt(buf []byte, addr int64) (int, error)

ReadAt satisfies the io.ReaderAt interface, and fills the provided buffer with memory read from the device starting at the provided address.

func (*Device) ReadJEDEC

func (dev *Device) ReadJEDEC() (JedecID, error)

ReadJEDEC reads the JEDEC ID from the device; this ID can then be used to ascertain the attributes of the chip from a list of known devices.

func (*Device) ReadSerialNumber

func (dev *Device) ReadSerialNumber() (SerialNumber, error)

ReadSerialNumber reads the serial numbers from the connected device. TODO: maybe check if byte order / endianess is correct, probably is not

func (*Device) ReadStatus

func (dev *Device) ReadStatus() (status byte, err error)

ReadStatus reads the value from status register 1 of the device

func (*Device) ReadStatus2

func (dev *Device) ReadStatus2() (status byte, err error)

ReadStatus2 reads the value from status register 2 of the device

func (*Device) Size

func (dev *Device) Size() int64

Size returns the size of this memory, in bytes.

func (*Device) WaitUntilReady

func (dev *Device) WaitUntilReady() error

WaitUntilReady queries the status register until the device is ready for the next operation.

func (*Device) WriteAt

func (dev *Device) WriteAt(buf []byte, addr int64) (n int, err error)

WriteAt satisfies the io.WriterAt interface and writes data to the device, one page at a time, starting at the provided address. This method assumes that the destination is already erased.

func (*Device) WriteBlockSize

func (dev *Device) WriteBlockSize() int64

WriteBlockSize returns the block size in which data can be written to memory. It can be used by a client to optimize writes, non-aligned writes should always work correctly. For SPI NOR flash this is the page size, usually/always 256.

func (*Device) WriteEnable

func (dev *Device) WriteEnable() error

type DeviceConfig

type DeviceConfig struct {
	Identifier DeviceIdentifier
}

DeviceConfig contains the parameters that can be set when configuring a flash memory device.

type DeviceIdentifier

type DeviceIdentifier interface {
	// Identify returns an Attrs struct based on the provided JEDEC ID
	Identify(id JedecID) Attrs
}

A DeviceIdentifier can be passed to the Configure() method of a flash Device in order provide a means of discovery of device-specific attributes based on the JEDEC ID read from the device.

type DeviceIdentifierFunc

type DeviceIdentifierFunc func(id JedecID) Attrs

DeviceIdentifierFunc is a functional Identifier implementation

func (DeviceIdentifierFunc) Identify

func (fn DeviceIdentifierFunc) Identify(id JedecID) Attrs

Identify implements the Identifier interface

type Error

type Error uint8
const (
	ErrInvalidClockSpeed Error = iota
	ErrInvalidAddrRange
	ErrWaitExpired
)

func (Error) Error

func (err Error) Error() string

type JedecID

type JedecID struct {
	ManufID  uint8
	MemType  uint8
	Capacity uint8
}

JedecID encapsules the ID values that unique identify a flash memory device.

func (JedecID) Uint32

func (id JedecID) Uint32() uint32

Uint32 returns the JEDEC ID packed into a uint32

type SerialNumber

type SerialNumber uint64

SerialNumber represents a serial number read from a flash memory device

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL