COSA
An Object-Oriented Platform for Arduino Programming
W25X40CL Class Reference

#include <W25X40CL.hh>

Inheritance diagram for W25X40CL:
Inheritance graph
Collaboration diagram for W25X40CL:
Collaboration graph

Classes

union  status_t
 

Public Member Functions

 W25X40CL (Board::DigitalPin csn=Board::D15)
 
virtual bool begin ()
 
virtual bool is_ready ()
 
virtual int read (void *dest, uint32_t src, size_t size)
 
virtual int erase (uint32_t dest, uint8_t size=4)
 
virtual int write (uint32_t dest, const void *src, size_t size)
 
virtual int write_P (uint32_t dest, const void *buf, size_t size)
 
uint8_t read_status ()
 
virtual bool end ()
 

Public Attributes

const uint32_t SECTOR_BYTES
 
const uint32_t SECTOR_MASK
 
const uint16_t SECTOR_MAX
 
const uint32_t DEVICE_BYTES
 

Static Public Attributes

static const size_t PAGE_MAX = 256
 
static const size_t PAGE_MASK = PAGE_MAX - 1
 
static const uint32_t DEFAULT_SECTOR_BYTES = 4096
 

Protected Types

enum  Command {
  WREN = 0x06, WREVSR = 0x50, WRDI = 0x04, RDSR = 0x05,
  WRR = 0x01, READ = 0x03, FRD = 0x0b, FRDDIO = 0xbb,
  PP = 0x02, SER = 0x20, B32ER = 0x52, B64ER = 0xd8,
  CER = 0x60, PWD = 0xb9, RLPWD = 0xab, RDID = 0x90,
  RDIDDIO = 0x92, RDJID = 0x9f, RDUID = 0x4b
}
 

Protected Member Functions

uint8_t issue (Command cmd)
 
void set_clock (Clock rate)
 
void set_clock (uint32_t freq)
 

Static Protected Member Functions

static Clock clock (uint32_t freq)
 
static Clock cycle (uint16_t ns)
 

Protected Attributes

status_t m_status
 
Driverm_next
 List of drivers. More...
 
Interrupt::Handlerm_irq
 Interrupt handler. More...
 
OutputPin m_cs
 Device chip select pin. More...
 
Pulse m_pulse
 Chip select pulse width. More...
 
uint8_t m_spcr
 SPI/SPCR hardware control register setting. More...
 
uint8_t m_spsr
 SPI/SPSR hardware status register. More...
 

Static Protected Attributes

static const uint8_t MANUFACTURER = 0xef
 
static const uint8_t DEVICE = 0x12
 

Detailed Description

Cosa Winbond W25X40CL flash device driver class. Implements the Cosa Flash device driver interface with erase, read and write/program flash memory blocks.

References

  1. Winbond W25X40CL, spiflash, 2.5/3/3.3V 4M-bit, Serial Flash Memory with 4KB Sectors and Dual I/O SPI, Rev. E, Publication Release Date: October 15, 2012.

Definition at line 38 of file W25X40CL.hh.

Member Enumeration Documentation

enum W25X40CL::Command
protected

Instruction Set (chap. 8.2.2, pp. 15)

Enumerator
WREN 

Write Enable.

WREVSR 

Write Enable for Volatile Status Register.

WRDI 

Write Disable.

RDSR 

Read Status Register.

WRR 

Write Status Register.

READ 

Read Data.

FRD 

Fast Read.

FRDDIO 

Fast Read Dual.

PP 

Page Program.

SER 

Sector Erase (4 kB).

B32ER 

Block Erase (32 kB).

B64ER 

Block Erase (64kB).

CER 

Chip Erase.

PWD 

Power-down.

RLPWD 

Release Power-down/Device ID.

RDID 

Read Manufacturer/Device ID.

RDIDDIO 

Read Manufacturer/Device ID Dual I/O.

RDJID 

Read JEDEC ID.

RDUID 

Read Unique ID.

Definition at line 163 of file W25X40CL.hh.

Constructor & Destructor Documentation

W25X40CL::W25X40CL ( Board::DigitalPin  csn = Board::D15)
inline

Construct W25X40CL device driver with given chip select pin.

Parameters
[in]csnchip select pin (default D15/D3).

Definition at line 51 of file W25X40CL.hh.

Member Function Documentation

bool W25X40CL::begin ( )
virtual

Initiate the flash memory device driver and check for valid identification. Return true(1) if the successful otherwise false(0).

Returns
bool

Reimplemented from Flash::Device.

Definition at line 24 of file W25X40CL.cpp.

static Clock SPI::Driver::clock ( uint32_t  freq)
inlinestaticinherited

Calculate SPI clock rate (scale factor) for given frequency.

Parameters
[in]freqdevice max frequency (in Hz).
Returns
clock rate.

Definition at line 117 of file SPI.hh.

static Clock SPI::Driver::cycle ( uint16_t  ns)
inlinestaticinherited

Calculate SPI clock rate (scale factor) for given clock cycle time in nano seconds.

Parameters
[in]nsmin device clock cycle time.
Returns
clock rate.

Definition at line 135 of file SPI.hh.

virtual bool Flash::Device::end ( )
inlinevirtualinherited

Terminate the flash memory device driver. Return true(1) if the successful otherwise false(0).

Returns
bool.

Definition at line 78 of file Flash.hh.

int W25X40CL::erase ( uint32_t  dest,
uint8_t  size = 4 
)
virtual

Erase given flash block for given byte address. The size of the erased sector/block is either 4/32/64 KB or 255 for chip erase. The flash memory consists of 128 X 4 KB sectors. The highest sector is reserved. Returs zero(0) if successful otherwise an negative error code (EINVAL if illegal sector size).

Parameters
[in]destdestination block byte address to erase.
[in]sizeof sector to erase in Kbyte (Default 4 KByte).
Returns
zero or negative error code.

Implements Flash::Device.

Definition at line 80 of file W25X40CL.cpp.

bool W25X40CL::is_ready ( )
virtual

Return true(1) if the device is ready, write cycle is completed, otherwise false(0).

Returns
bool

Implements Flash::Device.

Definition at line 46 of file W25X40CL.cpp.

uint8_t W25X40CL::issue ( Command  cmd)
protected

Issue given command and return result.

Parameters
[in]cmdcommand code.
Returns
result.

Definition at line 205 of file W25X40CL.cpp.

int W25X40CL::read ( void *  dest,
uint32_t  src,
size_t  size 
)
virtual

Read flash block with the given size into the buffer from the source address. Return number of bytes read or negative error code.

Parameters
[in]destbuffer to read from flash into.
[in]srcaddress in flash to read from.
[in]sizenumber of bytes to read.
Returns
number of bytes or negative error code.

Implements Flash::Device.

Definition at line 61 of file W25X40CL.cpp.

uint8_t W25X40CL::read_status ( )
inline

Read device status register.

Returns
status code.

Definition at line 154 of file W25X40CL.hh.

void SPI::Driver::set_clock ( Clock  rate)
inherited

Set SPI master clock rate.

Parameters
[in]clockrate.

Definition at line 297 of file SPI.cpp.

void SPI::Driver::set_clock ( uint32_t  freq)
inlineinherited

Set SPI master clock frequency.

Parameters
[in]freqdevice max frequency (in Hz).

Definition at line 157 of file SPI.hh.

int W25X40CL::write ( uint32_t  dest,
const void *  src,
size_t  size 
)
virtual

Write flash block at given destination address with the contents of the source buffer. Return number of bytes written or negative error code.

Parameters
[in]destaddress in flash to write to.
[in]srcbuffer to write to flash.
[in]sizenumber of bytes to write.
Returns
number of bytes or negative error code.

Implements Flash::Device.

Definition at line 113 of file W25X40CL.cpp.

int W25X40CL::write_P ( uint32_t  dest,
const void *  buf,
size_t  size 
)
virtual

Write flash block at given destination address with contents of the source buffer in program memory. Return number of bytes written or negative error code.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or EOF(-1).

Implements Flash::Device.

Definition at line 159 of file W25X40CL.cpp.

Member Data Documentation

const uint32_t Flash::Device::DEFAULT_SECTOR_BYTES = 4096
staticinherited

Default size of sector in bytes.

Definition at line 37 of file Flash.hh.

const uint8_t W25X40CL::DEVICE = 0x12
staticprotected

Device code

Definition at line 189 of file W25X40CL.hh.

const uint32_t Flash::Device::DEVICE_BYTES
inherited

Number of bytes of device.

Definition at line 46 of file Flash.hh.

OutputPin SPI::Driver::m_cs
protectedinherited

Device chip select pin.

Definition at line 166 of file SPI.hh.

Interrupt::Handler* SPI::Driver::m_irq
protectedinherited

Interrupt handler.

Definition at line 165 of file SPI.hh.

Driver* SPI::Driver::m_next
protectedinherited

List of drivers.

Definition at line 164 of file SPI.hh.

Pulse SPI::Driver::m_pulse
protectedinherited

Chip select pulse width.

Definition at line 167 of file SPI.hh.

uint8_t SPI::Driver::m_spcr
protectedinherited

SPI/SPCR hardware control register setting.

Definition at line 173 of file SPI.hh.

uint8_t SPI::Driver::m_spsr
protectedinherited

SPI/SPSR hardware status register.

Definition at line 174 of file SPI.hh.

status_t W25X40CL::m_status
protected

Latest status; is_ready() call

Definition at line 199 of file W25X40CL.hh.

const uint8_t W25X40CL::MANUFACTURER = 0xef
staticprotected

Manufacturer code

Definition at line 186 of file W25X40CL.hh.

const size_t W25X40CL::PAGE_MASK = PAGE_MAX - 1
static

Definition at line 44 of file W25X40CL.hh.

const size_t W25X40CL::PAGE_MAX = 256
static

Default programming page buffer size (pp. 61, 97).

Definition at line 43 of file W25X40CL.hh.

const uint32_t Flash::Device::SECTOR_BYTES
inherited

Size of sector in bytes.

Definition at line 34 of file Flash.hh.

const uint32_t Flash::Device::SECTOR_MASK
inherited

Sector address mask.

Definition at line 40 of file Flash.hh.

const uint16_t Flash::Device::SECTOR_MAX
inherited

Number of sectors.

Definition at line 43 of file Flash.hh.


The documentation for this class was generated from the following files: