BSP430
20141115
Board Support Package for MSP430 microcontrollers
|
Support for M25P-compatible serial SPI flash memory devices. More...
Go to the source code of this file.
Data Structures | |
struct | sBSP430m25p |
Typedefs | |
typedef struct sBSP430m25p | sBSP430m25p |
typedef sBSP430m25p * | hBSP430m25p |
Functions | |
hBSP430m25p | hBSP430m25pInitialize (hBSP430m25p dev, unsigned char ctl0_byte, unsigned char ctl1_byte, unsigned int prescaler) |
int | iBSP430m25pStatus_rh (hBSP430m25p dev) |
static BSP430_CORE_INLINE int | iBSP430m25pStatus (hBSP430m25p dev) |
int | iBSP430m25pStrobeCommand_rh (hBSP430m25p dev, uint8_t cmd) |
int | iBSP430m25pStrobeAddressCommand_rh (hBSP430m25p dev, uint8_t cmd, unsigned long addr) |
int | iBSP430m25pInitiateCommand_rh (hBSP430m25p dev, uint8_t cmd) |
int | iBSP430m25pInitiateAddressCommand_rh (hBSP430m25p dev, uint8_t cmd, unsigned long addr) |
int | iBSP430m25pCompleteTxRx_rh (hBSP430m25p dev, const uint8_t *tx_data, size_t tx_len, size_t rx_len, uint8_t *rx_data) |
Support for M25P-compatible serial SPI flash memory devices.
Micron/Numonyx serial SPI flash devices such as the M25P16 and M25PE20 are commonly used on MSP430-based wireless sensor platforms. This module defines the command and status constants for the M25P interface; a structure holding the required SPI, CS#, and RESET# information to interact with the device, and declarations for module functions that encode and transmit commands.
The module also supports configBSP430_PLATFORM_M25P and BSP430_PLATFORM_M25P to allow applications to request access to a platform-supplied flash memory chip without encoding platform dependencies in the source code.
As with other parts of BSP430, this is a low-level interface that does not provide convenience wrappers for functions like erasing a sector or chip, or reading and writing the device contents. It does provide enough to allow the application to do this, including the ability to initiate a read or write operation and complete it using programmed I/O (iBSP430m25pCompleteTxRx_rh()), interrupt-driven SPI transactions, or DMA, based on the application's needs.
M25PE20 SPI flash memory on TrxEB or SuRF shows how to use this interface.
#define BSP430_M25P_CMD_BE 0xc7 |
BULK ERASE command
#define BSP430_M25P_CMD_DP 0xb9 |
DEEP POWER-DOWN command
#define BSP430_M25P_CMD_FAST_READ 0x0b |
READ DATA BYTES at HIGHER SPEED command
#define BSP430_M25P_CMD_PE 0xdb |
PAGE ERASE command. Not available on all devices. See BSP430_PLATFORM_M25P_SUPPORTS_PE.
#define BSP430_M25P_CMD_PP 0x02 |
PAGE PROGRAM command.
#define BSP430_M25P_CMD_PW 0x0a |
PAGE WRITE command. Not available on all devices. See BSP430_PLATFORM_M25P_SUPPORTS_PW.
#define BSP430_M25P_CMD_RDID 0x9f |
READ IDENTIFICATION command.
#define BSP430_M25P_CMD_RDLR 0xe8 |
READ LOCK REGISTER command
#define BSP430_M25P_CMD_RDSR 0x05 |
READ STATUS REGISTER command
#define BSP430_M25P_CMD_READ 0x03 |
READ DATA BYTES command
#define BSP430_M25P_CMD_RELDP 0xab |
RELEASE from DEEP POWER-DOWN command
#define BSP430_M25P_CMD_RES 0xab |
READ ELECTRONIC SIGNATURE command. Overloads BSP430_M25P_CMD_RELDP on some devices.
#define BSP430_M25P_CMD_SE 0xd8 |
SECTOR ERASE command
#define BSP430_M25P_CMD_SSE 0x20 |
SUBSECTOR ERASE command. Not available on all devices. BSP430_PLATFORM_M25P_SUBSECTOR_SIZE may indicate that support is available.
#define BSP430_M25P_CMD_WRDI 0x04 |
WRITE DISABLE command
#define BSP430_M25P_CMD_WREN 0x06 |
WRITE ENABLE command
#define BSP430_M25P_CMD_WRLR 0xe5 |
WRITE to LOCK REGISTER command
#define BSP430_M25P_CMD_WRSR 0x01 |
WRITE STATUS REGISTER command.
#define BSP430_M25P_CS_ASSERT | ( | dev_ | ) |
Assert the CS# signal in preparation for interacting with the device.
#define BSP430_M25P_CS_DEASSERT | ( | dev_ | ) |
De-assert the CS# signal after interacting with the device.
#define BSP430_M25P_RESET_CLEAR | ( | dev_ | ) |
Clear the RESET# signal to take the device out of reset
#define BSP430_M25P_RESET_SET | ( | dev_ | ) |
Set the RESET# signal to place the device into reset
#define BSP430_M25P_SR_BP0 0x04 |
Block protect bit BP0 within M25P status register. Not available on all devices.
#define BSP430_M25P_SR_BP1 0x08 |
Block protect bit BP1 within M25P status register. Not available on all devices.
#define BSP430_M25P_SR_SRWD 0x80 |
Status-register-write-disable bit within M25P status register. Not available on all devices.
#define BSP430_M25P_SR_WEL 0x02 |
Write-enable-latch bit within M25P status register.
#define BSP430_M25P_SR_WIP 0x01 |
Write-in-progress bit within M25P status register. Bit is read-only.
#define BSP430_PLATFORM_M25P include <bsp430/platform.h> |
Indicate that an M25P serial flash device is available on the platform. This is set by the platform-specific header when configBSP430_PLATFORM_M25P is true and the platform supports an M25P device.
See M25PE20 SPI flash memory on TrxEB or SuRF for how to use the following identifiers to configure and use the platform device:
#define BSP430_PLATFORM_M25P_CSn_PORT_BIT include <bsp430/platform.h> |
Port bit on BSP430_PLATFORM_M25P_CSn_PORT_PERIPH_HANDLE for SPI flash CSn
#define BSP430_PLATFORM_M25P_CSn_PORT_PERIPH_HANDLE include <bsp430/platform.h> |
BSP430 peripheral handle for port on which SPI flash chip-select (inverted) is placed.
#define BSP430_PLATFORM_M25P_PWR_PORT_BIT include <bsp430/platform.h> |
Port bit on BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE for SPI flash power
#define BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE include <bsp430/platform.h> |
BSP430 peripheral handle for port on which SPI flash power is placed.
#define BSP430_PLATFORM_M25P_RSTn_PORT_BIT include <bsp430/platform.h> |
Port bit on BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE for SPI flash power
#define BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE include <bsp430/platform.h> |
BSP430 peripheral handle for port on which SPI flash power is placed.
#define BSP430_PLATFORM_M25P_SECTOR_COUNT include <bsp430/platform.h> |
The number of sectors in the platform M25P device.
#define BSP430_PLATFORM_M25P_SECTOR_SIZE include <bsp430/platform.h> |
The number of bytes in each sector of the platform M25P device.
#define BSP430_PLATFORM_M25P_SPI_CTL0_BYTE BSP430_SERIAL_ADJUST_CTL0_INITIALIZER(UCCKPL | UCMSB | UCMST) |
SPI initialization constant required for M25P serial flash.
This value may be used by applications as the argument for ctl0_byte to hBSP430serialOpenSPI() when configuring SPI for an M25P serial flash memory.
#define BSP430_PLATFORM_M25P_SPI_PERIPH_HANDLE include <bsp430/platform.h> |
Peripheral handle for SPI access to platform-provided M25P serial flash
#define BSP430_PLATFORM_M25P_SUBSECTOR_SIZE include <bsp430/platform.h> |
The number of bytes in each subsector of the platform M25P device.
Undefined if the device does not support subsector operations.
#define BSP430_PLATFORM_M25P_SUPPORTS_PE include <bsp430/platform.h> |
Defined to a true value iff the M25P flash on the platform supports the BSP430_M25P_CMD_PE PAGE ERASE command. If false or absent, assume the device may be erased only by using BSP430_M25P_CMD_SE or BSP430_M25P_CMD_BE.
#define BSP430_PLATFORM_M25P_SUPPORTS_PW include <bsp430/platform.h> |
Defined to a true value iff the M25P flash on the platform supports the BSP430_M25P_CMD_PW PAGE WRITE command. If false or absent, assume the device may be written only by following a page erase, subsector erase, sector erase, or bulk erase with BSP430_M25P_CMD_PP.
#define configBSP430_PLATFORM_M25P 0 |
Define to request that platform enable its M25P flash.
Some platforms have an external serial flash memory suitable for control by the <bsp430/utility/m25p.h> interface. Defining this macro in your <bsp430_config.h> will register a request for that device. Define to a true value to enable any platform-provided M25P serial flash memory.
typedef sBSP430m25p* hBSP430m25p |
Handle used to access an M25P-based serial SPI flash device.
typedef struct sBSP430m25p sBSP430m25p |
Information required to access an M25P-based serial SPI flash device. Boards that allow control of power to the device must do so externally from this module.
hBSP430m25p hBSP430m25pInitialize | ( | hBSP430m25p | dev, |
unsigned char | ctl0_byte, | ||
unsigned char | ctl1_byte, | ||
unsigned int | prescaler | ||
) |
Initialize an M25P device.
This function initializes the SPI bus and peripheral ports to interact with the device. The SPI bus is configured as specified by the parameters. The CS# and RESET# ports are configured to output mode, with CS# de-asserted (not selected) and RESET# asserted (held in reset mode).
To comply with device power-up requirements, power should not be supplied to the device until this function has completed. Further interaction with the device should be delayed for a device-specific period following application of power.
dev | the M25P device handle |
ctl0_byte | as with hBSP430serialOpenSPI() |
ctl1_byte | as with hBSP430serialOpenSPI() |
prescaler | as with hBSP430serialOpenSPI() |
dev
if the initialization was successful, or a null handle if it failed. int iBSP430m25pCompleteTxRx_rh | ( | hBSP430m25p | dev, |
const uint8_t * | tx_data, | ||
size_t | tx_len, | ||
size_t | rx_len, | ||
uint8_t * | rx_data | ||
) |
Complete an initiated command using programmed I/O.
This simply wraps iBSP430spiTxRx_rh() to transmit data to the device and/or receive data from the device, ensuring that BSP430_M25P_CS_DEASSERT() is invoked to complete the transaction initiated by iBSP430m25pInitiateCommand_rh() or iBSP430m25pInitiateAddressCommand_rh().
dev | the M25P device handle |
tx_data | as with iBSP430spiTxRx_rh() |
tx_len | as with iBSP430spiTxRx_rh() |
rx_len | as with iBSP430spiTxRx_rh() |
rx_data | as with iBSP430spiTxRx_rh() |
int iBSP430m25pInitiateAddressCommand_rh | ( | hBSP430m25p | dev, |
uint8_t | cmd, | ||
unsigned long | addr | ||
) |
Initiate an M25P address-based command.
The CS# signal is asserted, the cmd
transmitted, and the address transmitted. CS# is de-asserted if an error occurs; otherwise CS# is left asserted and the call returns allowing the caller to write additional data to the device or to receive data from the device through programmed I/O, interrupt-driven I/O, or DMA.
To use programmed I/O to complete a read or write operation, see iBSP430m25pCompleteTxRx_rh().
dev | the M25P device handle |
cmd | the command to be executed, e.g. BSP430_M25P_CMD_RDSR |
addr | the address at which the command applies. |
int iBSP430m25pInitiateCommand_rh | ( | hBSP430m25p | dev, |
uint8_t | cmd | ||
) |
Initiate an M25P device command.
The CS# signal is asserted and the cmd
transmitted. CS# is de-asserted if an error occurs; otherwise CS# is left asserted and the call returns allowing the caller to write additional data to the device or to receive data from the device through programmed I/O, interrupt-driven I/O, or DMA.
To use programmed I/O to complete a read or write operation, see iBSP430m25pCompleteTxRx_rh().
dev | the M25P device handle |
cmd | the command to be executed, e.g. BSP430_M25P_CMD_RDSR |
|
static |
Read the M25P device status register regardless of interrupt state.
This wraps iBSP430m25pStatus_rh() with code that saves the interrupt state, reads the status register, then restores the interrupt state prior to returning the result.
int iBSP430m25pStatus_rh | ( | hBSP430m25p | dev | ) |
Read the M25P device status register assuming interrupts are disabled.
The status register can be polled to detect completion of long-running operations such as BSP430_M25P_CMD_BE. Generally you will need to wait until BSP430_M25P_SR_WIP is clear before executing a new command.
dev | the M25P device handle |
int iBSP430m25pStrobeAddressCommand_rh | ( | hBSP430m25p | dev, |
uint8_t | cmd, | ||
unsigned long | addr | ||
) |
Strobe an M25P address-based command.
This interface is appropriate for commands like BSP430_M25P_CMD_PE which affect an address but require no data be written or read. It is functionally equivalent to iBSP430m25pInitiateAddressCommand_rh() followed immediately by BSP430_M25P_CS_DEASSERT().
Note that for many of these commands BSP430_M25P_SR_WIP will remain set for a device/command-specific period until the requested operation has completed.
dev | the M25P device handle |
cmd | the command to be executed, e.g. BSP430_M25P_CMD_PE |
addr | the address at which the command applies. |
int iBSP430m25pStrobeCommand_rh | ( | hBSP430m25p | dev, |
uint8_t | cmd | ||
) |
Strobe an M25P device command.
The CS# signal is asserted, the cmd
transmitted, and CS# is de-asserted. This interface is used for commands like BSP430_M25P_CMD_WREN and BSP430_M25P_CMD_BE that neither provide nor receive data and do not use an address.
Note that for many of these commands BSP430_M25P_SR_WIP will remain set for a device/command-specific period until the requested operation has completed.
dev | the M25P device handle |
cmd | the command to be executed, e.g. BSP430_M25P_CMD_RDSR |