/**************************************************************************/
typedef enum
{
- SPIFLASH_ERROR_OK = 0, // Everything executed normally
- SPIFLASH_ERROR_ADDROUTOFRANGE = 1, // Address out of range
- SPIFLASH_ERROR_TIMEOUT_READY = 2, // Timeout waiting for ready status
- SPIFLASH_ERROR_WRITEERR = 3, // Write Error
- SPIFLASH_ERROR_PROTECTIONERR = 4, // Write Protection Error
- SPIFLASH_ERROR_ADDROVERFLOW = 5, // Address overflow during read/write
- SPIFLASH_ERROR_UNEXPECTEDID = 6, // The manufacturer and/or device ID are different than expected
+ SPIFLASH_ERROR_OK = 0, // Everything executed normally
+ SPIFLASH_ERROR_ADDROUTOFRANGE = 1, // Address out of range
+ SPIFLASH_ERROR_TIMEOUT_READY = 2, // Timeout waiting for ready status
+ SPIFLASH_ERROR_WRITEERR = 3, // Write Error
+ SPIFLASH_ERROR_PROTECTIONERR = 4, // Write Protection Error
+ SPIFLASH_ERROR_ADDROVERFLOW = 5, // Address overflow during read/write
+ SPIFLASH_ERROR_UNEXPECTEDID = 6, // The manufacturer and/or device ID are different than expected
+ SPIFLASH_ERROR_NOTSTARTOFPAGE = 7, // The supplied address is not the start of a new page
+ SPIFLASH_ERROR_DATAEXCEEDSPAGESIZE = 9, // When writing page data, you can't exceed page size
+ SPIFLASH_ERROR_PAGEWRITEOVERFLOW = 10, // Page data will overflow beause (start address + len) > page size
SPIFLASH_ERROR_LAST
}
spiflashError_e;
/**************************************************************************/
/*!
- @brief Tries to initialise the flash device, and setups any HW
+ @brief Tries to initialise the flash device, and sets up any HW
required by the SPI flash
*/
/**************************************************************************/
@param[out] *buffer
Pointer to the buffer that will store the read results
@param[in] len
- Length of the buffer (zero-based).
+ Length of the buffer.
@section EXAMPLE
/**************************************************************************/
spiflashError_e spiflashReadBuffer (uint32_t address, uint8_t *buffer, uint32_t len);
-/**************************************************************************/
-/*!
- @brief Writes a single byte to the SPI flash
-
- @param[in] address
- The 24-bit address where the read will start.
- @param[out] *buffer
- Pointer to the buffer that will store the read results
- @param[in] len
- Length of the buffer (zero-based).
-*/
-/**************************************************************************/
-spiflashError_e spiflashWriteBuffer (uint32_t address, uint8_t *buffer, uint32_t len);
-
/**************************************************************************/
/*!
@brief Erases the contents of a single sector
/**************************************************************************/
spiflashError_e spiflashEraseChip (void);
+/**************************************************************************/
+/*!
+ @brief Writes up to 256 bytes of data to the specified page.
+
+ @note Before writing data to a page, make sure that the 4K sector
+ containing the specific page has been erased, otherwise the
+ data will be meaningless.
+
+ @param[in] address
+ The 24-bit address where the write will start.
+ @param[out] *buffer
+ Pointer to the buffer that will store the read results
+ @param[in] len
+ Length of the buffer. Valid values are from 1 to 256,
+ within the limits of the starting address and page length.
+
+ @section EXAMPLE
+
+ @code
+ spiflashError_e error;
+ uint8_t buffer[256];
+
+ buffer[0] = 0x12;
+ buffer[1] = 0x34;
+ buffer[2] = 0x56;
+ buffer[3] = 0x78;
+ buffer[4] = 0xDE;
+ buffer[5] = 0xAD;
+ buffer[6] = 0xC0;
+ buffer[7] = 0xDE;
+
+ error = spiflashWritePage (0, buffer, 8);
+ if (error)
+ {
+ // Check what went wrong
+ switch (error)
+ {
+ case SPIFLASH_ERROR_ADDROUTOFRANGE:
+ // Specified starting address is out of range
+ break;
+ case SPIFLASH_ERROR_DATAEXCEEDSPAGESIZE:
+ // Supplied data exceeds max page size
+ break;
+ case SPIFLASH_ERROR_PAGEWRITEOVERFLOW:
+ // The data length plus the start address offset exceeeds page limits
+ break;
+ case SPIFLASH_ERROR_TIMEOUT_READY:
+ // Timeout waiting for ready status (can be pre or post write)
+ break;
+ case SPIFLASH_ERROR_PROTECTIONERR:
+ // Unable to set write latch
+ break;
+ }
+ }
+ @endcode
+*/
+/**************************************************************************/
+spiflashError_e spiflashWritePage (uint32_t address, uint8_t *buffer, uint32_t len);
+
+/**************************************************************************/
+/*!
+ @brief Writes a continuous stream of data that will automatically
+ cross page boundaries.
+
+ @note Before writing data, make sure that the appropriate sectors
+ have been erased, otherwise the data will be meaningless.
+
+ @param[in] address
+ The 24-bit address where the write will start.
+ @param[out] *buffer
+ Pointer to the buffer that will store the read results
+ @param[in] len
+ Length of the buffer, within the limits of the starting
+ address and size of the flash device.
+
+ @section EXAMPLE
+
+ @code
+ spiflashError_e error;
+ uint8_t buffer[256];
+
+ buffer[0] = 0x12;
+ buffer[1] = 0x34;
+ buffer[2] = 0x56;
+ buffer[3] = 0x78;
+ buffer[4] = 0xDE;
+ buffer[5] = 0xAD;
+ buffer[6] = 0xC0;
+ buffer[7] = 0xDE;
+
+ error = spiflashWrite (0, buffer, 8);
+ if (error)
+ {
+ // Check what went wrong
+ switch (error)
+ {
+ case SPIFLASH_ERROR_ADDROUTOFRANGE:
+ // Specified starting address is out of range
+ break;
+ case SPIFLASH_ERROR_DATAEXCEEDSPAGESIZE:
+ // Supplied data exceeds max page size
+ break;
+ case SPIFLASH_ERROR_PAGEWRITEOVERFLOW:
+ // The data length plus the start address offset exceeeds page limits
+ break;
+ case SPIFLASH_ERROR_TIMEOUT_READY:
+ // Timeout waiting for ready status (can be pre or post write)
+ break;
+ case SPIFLASH_ERROR_PROTECTIONERR:
+ // Unable to set write latch
+ break;
+ }
+ }
+ @endcode
+*/
+/**************************************************************************/
+spiflashError_e spiflashWrite (uint32_t address, uint8_t *buffer, uint32_t len);
+
#endif