diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2016-05-08 17:43:06 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2016-05-08 17:43:06 +0000 |
commit | eede81d5622ea3e3712a4b5dc76b8d7bbee588e5 (patch) | |
tree | 06246a07e04e6f055a1f841cd7e4d3d557b82b89 | |
parent | ceb256ed74e5f8cb5bf32f8268b2bd70f8850c1b (diff) | |
download | ChibiOS-eede81d5622ea3e3712a4b5dc76b8d7bbee588e5.tar.gz ChibiOS-eede81d5622ea3e3712a4b5dc76b8d7bbee588e5.tar.bz2 ChibiOS-eede81d5622ea3e3712a4b5dc76b8d7bbee588e5.zip |
N25Q128 driver complete, to be tested.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9452 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | os/ex/Micron/n25q128.c | 51 | ||||
-rw-r--r-- | os/hal/lib/peripherals/flash/hal_flash.h | 10 |
2 files changed, 41 insertions, 20 deletions
diff --git a/os/ex/Micron/n25q128.c b/os/ex/Micron/n25q128.c index c152ee58d..57ff6df5e 100644 --- a/os/ex/Micron/n25q128.c +++ b/os/ex/Micron/n25q128.c @@ -50,9 +50,9 @@ static flash_error_t erase_all(void *instance); static flash_error_t erase_sectors(void *instance, flash_sector_t sector, flash_sector_t n); -static flash_error_t are_sectors_erased(void *instance, - flash_sector_t sector, - flash_sector_t n); +static flash_error_t verify_erase(void *instance, + flash_sector_t sector, + flash_sector_t n); static flash_error_t program(void *instance, flash_address_t addr, const uint8_t *pp, size_t n); static flash_error_t read(void *instance, flash_address_t addr, @@ -62,8 +62,7 @@ static flash_error_t read(void *instance, flash_address_t addr, * @brief Virtual methods table. */ static const struct N25Q128DriverVMT n25q128_vmt = { - get_descriptor, erase_all, erase_sectors, are_sectors_erased, - program, read + get_descriptor, erase_all, erase_sectors, verify_erase, program, read }; /** @@ -182,7 +181,7 @@ static flash_error_t erase_sectors(void *instance, SPIDriver *spip = devp->config->spip; flash_address_t addr = (flash_address_t)(sector * SECTOR_SIZE); - osalDbgCheck(instance != NULL); + osalDbgCheck((instance != NULL) && (n > 0U)); osalDbgCheck(sector + n <= descriptor.sectors_count); osalDbgAssert(devp->state == FLASH_READY, "invalid state"); @@ -227,19 +226,42 @@ static flash_error_t erase_sectors(void *instance, return err; } -static flash_error_t are_sectors_erased(void *instance, - flash_sector_t sector, - flash_sector_t n) { +static flash_error_t verify_erase(void *instance, + flash_sector_t sector, + flash_sector_t n) { N25Q128Driver *devp = (N25Q128Driver *)instance; SPIDriver *spip = devp->config->spip; + flash_error_t err; - osalDbgCheck(instance != NULL); + osalDbgCheck((instance != NULL) && (n > 0U)); osalDbgCheck(sector + n <= descriptor.sectors_count); osalDbgAssert(devp->state == FLASH_READY, "invalid state"); - (void)spip; +#if N25Q128_SHARED_SPI == TRUE + spiAcquireBus(spip); + spiStart(spip, devp->config->spicfg); +#endif + devp->state = FLASH_ACTIVE; - return FLASH_NO_ERROR; + /* Read command.*/ + spiSelect(spip); + flash_send_cmd_addr(devp, N25Q128_CMD_READ, (size_t)(sector * SECTOR_SIZE)); + n *= SECTOR_SIZE; + while (--n) { + if (spiPolledExchange(spip, 0xFF) != 0xFF) { + err = FLASH_VERIFY_FAILURE; + goto skip; + } + } + spiUnselect(spip); + + err = FLASH_NO_ERROR; +skip: + devp->state = FLASH_READY; +#if N25Q128_SHARED_SPI == TRUE + spiReleaseBus(spip); +#endif + return err; } static flash_error_t program(void *instance, flash_address_t addr, @@ -248,7 +270,7 @@ static flash_error_t program(void *instance, flash_address_t addr, SPIDriver *spip = devp->config->spip; flash_error_t err; - osalDbgCheck((instance != NULL) && (pp != NULL)); + osalDbgCheck((instance != NULL) && (pp != NULL) && (n > 0U)); osalDbgCheck((size_t)addr + n <= (size_t)descriptor.sectors_count * (size_t)descriptor.sectors_size); osalDbgAssert(devp->state == FLASH_READY, "invalid state"); @@ -294,7 +316,6 @@ static flash_error_t program(void *instance, flash_address_t addr, } devp->state = FLASH_READY; - #if N25Q128_SHARED_SPI == TRUE spiReleaseBus(spip); #endif @@ -306,7 +327,7 @@ static flash_error_t read(void *instance, flash_address_t addr, N25Q128Driver *devp = (N25Q128Driver *)instance; SPIDriver *spip = devp->config->spip; - osalDbgCheck((instance != NULL) && (rp != NULL)); + osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U)); osalDbgCheck((size_t)addr + n <= (size_t)descriptor.sectors_count * (size_t)descriptor.sectors_size); osalDbgAssert(devp->state == FLASH_READY, "invalid state"); diff --git a/os/hal/lib/peripherals/flash/hal_flash.h b/os/hal/lib/peripherals/flash/hal_flash.h index b3c47b377..3544b328f 100644 --- a/os/hal/lib/peripherals/flash/hal_flash.h +++ b/os/hal/lib/peripherals/flash/hal_flash.h @@ -146,9 +146,9 @@ typedef struct { flash_sector_t sector, \
flash_sector_t n); \
/* Erase single sector.*/ \
- flash_error_t (*are_sectors_erased)(void *instance, \
- flash_sector_t sector, \
- flash_sector_t n); \
+ flash_error_t (*verify_erase)(void *instance, \
+ flash_sector_t sector, \
+ flash_sector_t n); \
/* Write operation.*/ \
flash_error_t (*program)(void *instance, flash_address_t addr, \
const uint8_t *pp, size_t n); \
@@ -241,8 +241,8 @@ typedef struct { *
* @api
*/
-#define flashAreSectorsErased(ip, sector, n) \
- (ip)->vmt_baseflash->are_sectors_erased(ip, sector, n)
+#define flashVerifyErase(ip, sector, n) \
+ (ip)->vmt_baseflash->verify_erase(ip, sector, n)
/**
* @brief Write operation.
|