diff options
-rw-r--r-- | os/ex/Micron/n25q128.c | 56 | ||||
-rw-r--r-- | os/ex/Micron/n25q128.h | 2 | ||||
-rw-r--r-- | os/hal/lib/peripherals/flash/hal_flash.h | 6 |
3 files changed, 56 insertions, 8 deletions
diff --git a/os/ex/Micron/n25q128.c b/os/ex/Micron/n25q128.c index 53e54aecd..6107dafff 100644 --- a/os/ex/Micron/n25q128.c +++ b/os/ex/Micron/n25q128.c @@ -62,15 +62,63 @@ static const struct N25Q128DriverVMT n25q128_vmt = { /* Driver local variables and types. */ /*===========================================================================*/ +static flash_descriptor_t descriptor = { + .attributes = FLASH_ATTR_ERASED_IS_ONE | FLASH_ATTR_REWRITABLE, + .page_size = 256, + .sectors_count = 4096, + .sectors = NULL, + .sectors_size = 4096, + .address = 0 +}; + /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ +static void spi_send_cmd_read(N25Q128Driver *devp, uint8_t cmd, + uint8_t *rp, size_t n) { + +#if N25Q128_SHARED_SPI == TRUE + spiStart(devp->config->spip, devp->config->spicfg); + spiAcquireBus(devp->config->spip); +#endif + spiSelect(devp->config->spip); + spiSend(devp->config->spip, 1, &cmd); + spiReceive(devp->config->spip, n, rp); + spiUnselect(devp->config->spip); +#if N25Q128_SHARED_SPI == TRUE + spiReleaseBus(devp->config->spip); +#endif +} + +static void spi_send_cmd_addr_read(N25Q128Driver *devp, + uint8_t cmd, + flash_address_t addr, + uint8_t *rp, size_t n) { + uint8_t buf[4]; + +#if N25Q128_SHARED_SPI == TRUE + spiStart(devp->config->spip, devp->config->spicfg); + spiAcquireBus(devp->config->spip); +#endif + buf[0] = cmd; + buf[1] = (uint8_t)(addr >> 16); + buf[2] = (uint8_t)(addr >> 8); + buf[3] = (uint8_t)(addr >> 0); + spiSelect(devp->config->spip); + spiSend(devp->config->spip, 4, buf); + spiReceive(devp->config->spip, n, rp); + spiUnselect(devp->config->spip); +#if N25Q128_SHARED_SPI == TRUE + spiReleaseBus(devp->config->spip); +#endif +} + static const flash_descriptor_t *get_attributes(void *instance) { (void)instance; - return FLASH_NO_ERROR; + return &descriptor; } static flash_error_t erase_all(void *instance) { @@ -116,10 +164,8 @@ static flash_error_t program(void *instance, flash_address_t addr, static flash_error_t read(void *instance, flash_address_t addr, uint8_t *rp, size_t n) { - (void)instance; - (void)addr; - (void)rp; - (void)n; + spi_send_cmd_addr_read((N25Q128Driver *)instance, N25Q128_CMD_READ, + addr, rp, n); return FLASH_NO_ERROR; } diff --git a/os/ex/Micron/n25q128.h b/os/ex/Micron/n25q128.h index e0f301a30..bdc500463 100644 --- a/os/ex/Micron/n25q128.h +++ b/os/ex/Micron/n25q128.h @@ -82,7 +82,7 @@ * @note The default is @p FALSE. Requires SPI_USE_MUTUAL_EXCLUSION */ #if !defined(N25Q128_SHARED_SPI) || defined(__DOXYGEN__) -#define N25Q128_SHARED_SPI FALSE +#define N25Q128_SHARED_SPI TRUE #endif /** @} */ diff --git a/os/hal/lib/peripherals/flash/hal_flash.h b/os/hal/lib/peripherals/flash/hal_flash.h index 9905abb2a..736fbb201 100644 --- a/os/hal/lib/peripherals/flash/hal_flash.h +++ b/os/hal/lib/peripherals/flash/hal_flash.h @@ -36,6 +36,7 @@ #define FLASH_ATTR_ERASED_IS_ONE 0x00000001
#define FLASH_ATTR_MEMORY_MAPPED 0x00000002
#define FLASH_ATTR_REWRITABLE 0x00000004
+#define FLASH_ATTR_READ_ECC_CAPABLE 0x00000008
/** @} */
/*===========================================================================*/
@@ -57,8 +58,9 @@ typedef enum { FLASH_NO_ERROR = 0, /* No error. */
FLASH_PARAMETER_ERROR = 1, /* Error in a function parameter. */
FLASH_ADDRESS_ERROR = 2, /* Operation overlaps invalid addresses. */
- FLASH_VERIFY_FAILURE = 3, /* Write or erase operation failed. */
- FLASH_HW_FAILURE = 4 /* Controller or communication error. */
+ FLASH_ECC_ERROR = 3, /* ECC error during read operation. */
+ FLASH_VERIFY_FAILURE = 4, /* Write or erase operation failed. */
+ FLASH_HW_FAILURE = 5 /* Controller or communication error. */
} flash_error_t;
/**
|