From ed415bb76f7563346a3f9b0ba3ef45f9a6898afb Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 14 Nov 2017 13:18:59 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10998 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/lib/complex/mfs/mfs.c | 167 +++----- os/hal/lib/complex/mfs/mfs.h | 6 +- test/mfs/configuration.xml | 613 ++++++++++++++-------------- testhal/STM32/multi/QSPI-MFS/main.c | 11 +- 4 files changed, 373 insertions(+), 424 deletions(-) diff --git a/os/hal/lib/complex/mfs/mfs.c b/os/hal/lib/complex/mfs/mfs.c index a1decd519..71bc8ab76 100644 --- a/os/hal/lib/complex/mfs/mfs.c +++ b/os/hal/lib/complex/mfs/mfs.c @@ -154,7 +154,7 @@ static mfs_error_t mfs_flash_read(MFSDriver *mfsp, flash_offset_t offset, ferr = flashRead(mfsp->config->flashp, offset, n, rp); if (ferr != FLASH_NO_ERROR) { - mfsp->state = MFS_READY; + mfsp->state = MFS_ERROR; return MFS_ERR_FLASH_FAILURE; } @@ -182,7 +182,7 @@ static mfs_error_t mfs_flash_write(MFSDriver *mfsp, ferr = flashProgram(mfsp->config->flashp, offset, n, wp); if (ferr != FLASH_NO_ERROR) { - mfsp->state = MFS_READY; + mfsp->state = MFS_ERROR; return MFS_ERR_FLASH_FAILURE; } @@ -192,7 +192,7 @@ static mfs_error_t mfs_flash_write(MFSDriver *mfsp, size_t chunk = n <= MFS_CFG_BUFFER_SIZE ? n : MFS_CFG_BUFFER_SIZE; RET_ON_ERROR(mfs_flash_read(mfsp, offset, chunk, mfsp->buffer.data8)); if (memcmp((void *)mfsp->buffer.data8, (void *)wp, chunk)) { - mfsp->state = MFS_READY; + mfsp->state = MFS_ERROR; return MFS_ERR_FLASH_FAILURE; } n -= chunk; @@ -314,17 +314,17 @@ static mfs_error_t mfs_bank_erase(MFSDriver *mfsp, mfs_bank_t bank) { ferr = flashStartEraseSector(mfsp->config->flashp, sector); if (ferr != FLASH_NO_ERROR) { - mfsp->state = MFS_READY; + mfsp->state = MFS_ERROR; return MFS_ERR_FLASH_FAILURE; } ferr = flashWaitErase(mfsp->config->flashp); if (ferr != FLASH_NO_ERROR) { - mfsp->state = MFS_READY; + mfsp->state = MFS_ERROR; return MFS_ERR_FLASH_FAILURE; } ferr = flashVerifyErase(mfsp->config->flashp, sector); if (ferr != FLASH_NO_ERROR) { - mfsp->state = MFS_READY; + mfsp->state = MFS_ERROR; return MFS_ERR_FLASH_FAILURE; } @@ -363,7 +363,7 @@ static mfs_error_t mfs_bank_verify_erase(MFSDriver *mfsp, mfs_bank_t bank) { return MFS_ERR_NOT_ERASED; } if (ferr != FLASH_NO_ERROR) { - mfsp->state = MFS_READY; + mfsp->state = MFS_ERROR; return MFS_ERR_FLASH_FAILURE; } @@ -795,17 +795,48 @@ void mfsObjectInit(MFSDriver *mfsp) { * * @param[in] mfsp pointer to the @p MFSDriver object * @param[in] config pointer to the configuration + * @return The operation status. + * @retval MFS_NO_ERROR if the operation has been successfully completed. + * @retval MFS_WARN_GC if the operation triggered a garbage collection. + * @retval MFS_ERR_FLASH_FAILURE if the flash memory is unusable because HW + * failures. Makes the driver enter the @p MFS_ERROR state. + * @retval MFS_ERR_INTERNAL if an internal logic failure is detected. * * @api */ -void mfsStart(MFSDriver *mfsp, const MFSConfig *config) { +mfs_error_t mfsStart(MFSDriver *mfsp, const MFSConfig *config) { + unsigned i; osalDbgCheck((mfsp != NULL) && (config != NULL)); - osalDbgAssert((mfsp->state == MFS_STOP) || (mfsp->state == MFS_READY), - "invalid state"); + osalDbgAssert((mfsp->state == MFS_STOP) || (mfsp->state == MFS_READY) || + (mfsp->state == MFS_ERROR), "invalid state"); + /* Storing configuration.*/ mfsp->config = config; - mfsp->state = MFS_READY; + + /* Resetting previous state.*/ + mfs_state_reset(mfsp); + + /* Attempting to mount the managed partition.*/ + for (i = 0; i < MFS_CFG_MAX_REPAIR_ATTEMPTS; i++) { + mfs_error_t err; + + err = mfs_try_mount(mfsp); + if (err == MFS_ERR_INTERNAL) { + /* Special case, do not retry on internal errors but report + immediately.*/ + mfsp->state = MFS_ERROR; + return err; + } + if (!MFS_IS_ERROR(err)) { + mfsp->state = MFS_READY; + return err; + } + } + + /* Driver start failed.*/ + mfsp->state = MFS_ERROR; + return MFS_ERR_FLASH_FAILURE; } /** @@ -818,99 +849,28 @@ void mfsStart(MFSDriver *mfsp, const MFSConfig *config) { void mfsStop(MFSDriver *mfsp) { osalDbgCheck(mfsp != NULL); - osalDbgAssert((mfsp->state == MFS_STOP) || (mfsp->state == MFS_READY), - "invalid state"); + osalDbgAssert((mfsp->state == MFS_STOP) || (mfsp->state == MFS_READY) || + (mfsp->state == MFS_ERROR), "invalid state"); mfsp->config = NULL; mfsp->state = MFS_STOP; } -/** - * @brief Mounts a managed flash storage. - * @details This functions checks the storage internal state and eventually - * performs the required initialization or repair operations. - * - * @param[in] mfsp pointer to the @p MFSDriver object - * @return The operation status. - * @retval MFS_NO_ERROR if the operation has been successfully completed. - * @retval MFS_WARN_REPAIR if the operation has been completed but a - * repair has been performed. - * @retval MFS_ERR_INV_STATE if the volume is mounted. - * @retval MFS_ERR_FLASH_FAILURE if the flash memory is unusable because HW - * failures. Causes the volume to be unmounted. - * - * @api - */ -mfs_error_t mfsMount(MFSDriver *mfsp) { - unsigned i; - - osalDbgCheck(mfsp != NULL); - osalDbgAssert((mfsp->state == MFS_READY) || (mfsp->state == MFS_MOUNTED), - "invalid state"); - - if (mfsp->state != MFS_READY) { - return MFS_ERR_INV_STATE; - } - - /* Clearing state.*/ - mfs_state_reset(mfsp); - - /* Attempting to mount the managed partition.*/ - for (i = 0; i < MFS_CFG_MAX_REPAIR_ATTEMPTS; i++) { - mfs_error_t err; - - err = mfs_try_mount(mfsp); - if (!MFS_IS_ERROR(err)) { - mfsp->state = MFS_MOUNTED; - return err; - } - } - - return MFS_ERR_FLASH_FAILURE; -} - -/** - * @brief Unmounts a managed flash storage. - * - * @param[in] mfsp pointer to the @p MFSDriver object - * @return The operation status. - * @retval MFS_NO_ERROR if the operation has been successfully completed. - * @retval MFS_ERR_INV_STATE if the volume is not mounted. - * - * @api - */ -mfs_error_t mfsUnmount(MFSDriver *mfsp) { - - osalDbgCheck(mfsp != NULL); - osalDbgAssert((mfsp->state == MFS_READY) || (mfsp->state == MFS_MOUNTED), - "invalid state"); - - if (mfsp->state != MFS_MOUNTED) { - return MFS_ERR_INV_STATE; - } - - mfsp->state = MFS_READY; - - return MFS_NO_ERROR; -} - /** * @brief Destroys the state of the managed storage by erasing the flash. * * @param[in] mfsp pointer to the @p MFSDriver object * @return The operation status. - * @retval MFS_ERR_INV_STATE if the volume is mounted. + * @retval MFS_ERR_INV_STATE if the driver is in not in @p MSG_READY state. * @retval MFS_NO_ERROR if the operation has been successfully completed. * @retval MFS_ERR_FLASH_FAILURE if the flash memory is unusable because HW - * failures. Causes the volume to be unmounted. + * failures. Makes the driver enter the @p MFS_ERROR state. * * @api */ mfs_error_t mfsErase(MFSDriver *mfsp) { osalDbgCheck(mfsp != NULL); - osalDbgAssert((mfsp->state == MFS_READY) || (mfsp->state == MFS_MOUNTED), - "invalid state"); if (mfsp->state != MFS_READY) { return MFS_ERR_INV_STATE; @@ -918,6 +878,7 @@ mfs_error_t mfsErase(MFSDriver *mfsp) { RET_ON_ERROR(mfs_bank_erase(mfsp, MFS_BANK_0)); RET_ON_ERROR(mfs_bank_erase(mfsp, MFS_BANK_1)); + /* TODO: Remount.*/ return MFS_NO_ERROR; } @@ -933,12 +894,12 @@ mfs_error_t mfsErase(MFSDriver *mfsp) { * @param[out] buffer pointer to a buffer for record data * @return The operation status. * @retval MFS_NO_ERROR if the operation has been successfully completed. - * @retval MFS_ERR_INV_STATE if the volume is not mounted. + * @retval MFS_ERR_INV_STATE if the driver is in not in @p MSG_READY state. * @retval MFS_ERR_INV_SIZE if the passed buffer is not large enough to * contain the record data. * @retval MFS_ERR_NOT_FOUND if the specified id does not exists. * @retval MFS_ERR_FLASH_FAILURE if the flash memory is unusable because HW - * failures. Causes the volume to be unmounted. + * failures. Makes the driver enter the @p MFS_ERROR state. * * @api */ @@ -948,10 +909,8 @@ mfs_error_t mfsReadRecord(MFSDriver *mfsp, uint32_t id, osalDbgCheck((mfsp != NULL) && (id >= 1) && (id <= MFS_CFG_MAX_RECORDS) && (np != NULL) && (buffer != NULL)); - osalDbgAssert((mfsp->state == MFS_READY) || (mfsp->state == MFS_MOUNTED), - "invalid state"); - if (mfsp->state != MFS_MOUNTED) { + if (mfsp->state != MFS_READY) { return MFS_ERR_INV_STATE; } @@ -975,7 +934,7 @@ mfs_error_t mfsReadRecord(MFSDriver *mfsp, uint32_t id, /* Checking CRC.*/ crc = crc16(0xFFFFU, buffer, *np); if (crc != mfsp->buffer.dhdr.fields.crc) { - mfsp->state = MFS_READY; + mfsp->state = MFS_ERROR; return MFS_ERR_FLASH_FAILURE; } @@ -993,11 +952,11 @@ mfs_error_t mfsReadRecord(MFSDriver *mfsp, uint32_t id, * @return The operation status. * @retval MFS_NO_ERROR if the operation has been successfully completed. * @retval MFS_WARN_GC if the operation triggered a garbage collection. - * @retval MFS_ERR_INV_STATE if the volume is not mounted. + * @retval MFS_ERR_INV_STATE if the driver is in not in @p MSG_READY state. * @retval MFS_ERR_OUT_OF_MEM if there is not enough flash space for the * operation. * @retval MFS_ERR_FLASH_FAILURE if the flash memory is unusable because HW - * failures. Causes the volume to be unmounted. + * failures. Makes the driver enter the @p MFS_ERROR state. * * @api */ @@ -1008,10 +967,8 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, uint32_t id, osalDbgCheck((mfsp != NULL) && (id >= 1) && (id <= MFS_CFG_MAX_RECORDS) && (n > 0U) && (buffer != NULL)); - osalDbgAssert((mfsp->state == MFS_READY) || (mfsp->state == MFS_MOUNTED), - "invalid state"); - if (mfsp->state != MFS_MOUNTED) { + if (mfsp->state != MFS_READY) { return MFS_ERR_INV_STATE; } @@ -1082,9 +1039,9 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, uint32_t id, * @return The operation status. * @retval MFS_NO_ERROR if the operation has been successfully completed. * @retval MFS_WARN_GC if the operation triggered a garbage collection. - * @retval MFS_ERR_INV_STATE if the volume is not mounted. + * @retval MFS_ERR_INV_STATE if the driver is in not in @p MSG_READY state. * @retval MFS_ERR_FLASH_FAILURE if the flash memory is unusable because HW - * failures. Causes the volume to be unmounted. + * failures. Makes the driver enter the @p MFS_ERROR state. * @retval MFS_ERR_INTERNAL if an internal logic failure is detected. * * @api @@ -1094,10 +1051,8 @@ mfs_error_t mfsEraseRecord(MFSDriver *mfsp, uint32_t id) { bool warning = false; osalDbgCheck((mfsp != NULL) && (id >= 1) && (id <= MFS_CFG_MAX_RECORDS)); - osalDbgAssert((mfsp->state == MFS_READY) || (mfsp->state == MFS_MOUNTED), - "invalid state"); - if (mfsp->state != MFS_MOUNTED) { + if (mfsp->state != MFS_READY) { return MFS_ERR_INV_STATE; } @@ -1151,19 +1106,17 @@ mfs_error_t mfsEraseRecord(MFSDriver *mfsp, uint32_t id) { * @param[in] mfsp pointer to the @p MFSDriver object * @return The operation status. * @retval MFS_NO_ERROR if the operation has been successfully completed. - * @retval MFS_ERR_INV_STATE if the volume is not mounted. + * @retval MFS_ERR_INV_STATE if the driver is in not in @p MSG_READY state. * @retval MFS_ERR_FLASH_FAILURE if the flash memory is unusable because HW - * failures. Causes the volume to be unmounted. + * failures. Makes the driver enter the @p MFS_ERROR state. * * @api */ mfs_error_t mfsPerformGarbageCollection(MFSDriver *mfsp) { osalDbgCheck(mfsp != NULL); - osalDbgAssert((mfsp->state == MFS_READY) || (mfsp->state == MFS_MOUNTED), - "invalid state"); - if (mfsp->state != MFS_MOUNTED) { + if (mfsp->state != MFS_READY) { return MFS_ERR_INV_STATE; } diff --git a/os/hal/lib/complex/mfs/mfs.h b/os/hal/lib/complex/mfs/mfs.h index 49b1a342b..66c5f57d4 100644 --- a/os/hal/lib/complex/mfs/mfs.h +++ b/os/hal/lib/complex/mfs/mfs.h @@ -132,7 +132,7 @@ typedef enum { MFS_UNINIT = 0, MFS_STOP = 1, MFS_READY = 2, - MFS_MOUNTED = 3 + MFS_ERROR = 3 } mfs_state_t; /** @@ -349,10 +349,8 @@ typedef struct { extern "C" { #endif void mfsObjectInit(MFSDriver *devp); - void mfsStart(MFSDriver *devp, const MFSConfig *config); + mfs_error_t mfsStart(MFSDriver *devp, const MFSConfig *config); void mfsStop(MFSDriver *devp); - mfs_error_t mfsMount(MFSDriver *devp); - mfs_error_t mfsUnmount(MFSDriver *devp); mfs_error_t mfsErase(MFSDriver *mfsp); mfs_error_t mfsReadRecord(MFSDriver *devp, uint32_t id, size_t *np, uint8_t *buffer); diff --git a/test/mfs/configuration.xml b/test/mfs/configuration.xml index e51d568f4..20f7362b7 100644 --- a/test/mfs/configuration.xml +++ b/test/mfs/configuration.xml @@ -1,6 +1,6 @@ - + Test Specification for ChibiOS/HAL MFS Complex Driver. @@ -35,10 +35,10 @@ - nil_ + mfs_ - The APIs are tested for functionality, correct cases and expected error cases are tested. + + + - -#include "key_storage.h" - -static const uint8_t pattern1[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 -}; - -static const uint8_t pattern2[] = { - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47 -}; - -static const uint8_t pattern3[] = { - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 -}; - -static const uint8_t pattern512[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 + +#include "key_storage.h" + +static const uint8_t pattern1[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 +}; + +static const uint8_t pattern2[] = { + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47 +}; + +static const uint8_t pattern3[] = { + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 +}; + +static const uint8_t pattern512[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 };]]> @@ -197,12 +200,12 @@ static const uint8_t pattern512[] = { - @@ -214,9 +217,9 @@ test_assert(!result, "Block 1 erase failure");]]> - @@ -228,9 +231,9 @@ test_assert(error == KS_NOERROR, "initialization error with erased flash");]]> - @@ -266,15 +269,15 @@ test_assert(error == KS_NOERROR, "initialization error with initialized flash"); - @@ -298,7 +301,7 @@ for (key = 0; key < KS_CFG_NUM_KEYS; key++) { - @@ -311,7 +314,7 @@ uint8_t *keyp;]]> - @@ -323,13 +326,13 @@ test_assert(error == KS_KEY_NOT_FOUND, "key was already present");]]> - @@ -341,13 +344,13 @@ test_assert(memcmp(pattern1, keyp, size) == 0, "wrong key content");]]> - @@ -359,13 +362,13 @@ test_assert(memcmp(pattern2, keyp, size) == 0, "wrong key content");]]> - @@ -377,11 +380,11 @@ test_assert(memcmp(pattern3, keyp, size) == 0, "wrong key content");]]> - @@ -399,8 +402,8 @@ test_assert(error == KS_KEY_NOT_FOUND, "key not erased");]]> - @@ -419,13 +422,13 @@ ksInit();]]> - @@ -437,17 +440,17 @@ test_assert(error == KS_NOERROR, "error creating the key");]]> - @@ -465,7 +468,7 @@ test_assert(error == KS_KEY_NOT_FOUND, "key 2 still present");]]> - @@ -484,21 +487,21 @@ ksErase();]]> - @@ -510,11 +513,11 @@ for (key = 0; key < kmax; key++) { - @@ -526,33 +529,33 @@ test_assert(error == KS_OUT_OF_MEM, "creation didn't fail");]]> - = sizeof(kskeyheader_t), "not enough space"); -test_assert((remaining & KS_LLD_PAGE_SIZE) == 0, "unaligned space"); - -if (remaining > sizeof(kskeyheader_t) * 2) { - error = ksWriteKey(KS_CFG_NUM_KEYS - 1, - remaining - (sizeof(kskeyheader_t) * 2), - pattern512); - test_assert(error == KS_NOERROR, "error filling remaining space"); -} -else { - if (remaining == sizeof(kskeyheader_t) * 2) { - error = ksEraseKey(1); - test_assert(error == KS_NOERROR, "error filling remaining space"); - } - error = ksEraseKey(0); - test_assert(error == KS_NOERROR, "error filling remaining space"); -} - -remaining = KS_LLD_BLOCK0_ADDRESS + KS_LLD_BLOCKS_SIZE - (size_t)ks.free_next; -test_assert(remaining == 0, "remaining space not zero"); - -ksDeinit(); -error = ksInit(); + = sizeof(kskeyheader_t), "not enough space"); +test_assert((remaining & KS_LLD_PAGE_SIZE) == 0, "unaligned space"); + +if (remaining > sizeof(kskeyheader_t) * 2) { + error = ksWriteKey(KS_CFG_NUM_KEYS - 1, + remaining - (sizeof(kskeyheader_t) * 2), + pattern512); + test_assert(error == KS_NOERROR, "error filling remaining space"); +} +else { + if (remaining == sizeof(kskeyheader_t) * 2) { + error = ksEraseKey(1); + test_assert(error == KS_NOERROR, "error filling remaining space"); + } + error = ksEraseKey(0); + test_assert(error == KS_NOERROR, "error filling remaining space"); +} + +remaining = KS_LLD_BLOCK0_ADDRESS + KS_LLD_BLOCKS_SIZE - (size_t)ks.free_next; +test_assert(remaining == 0, "remaining space not zero"); + +ksDeinit(); +error = ksInit(); test_assert(error == KS_NOERROR, "initialization error");]]> @@ -570,7 +573,7 @@ test_assert(error == KS_NOERROR, "initialization error");]]> - @@ -589,21 +592,21 @@ ksErase();]]> - @@ -615,13 +618,13 @@ for (key = 0; key < kmax; key++) { - @@ -633,19 +636,19 @@ test_assert(error == KS_KEY_NOT_FOUND, "key not erased");]]> - fields.instance == 1, "not first instance"); -error = ksWriteKey(16, sizeof(pattern512), pattern512); -test_assert(error == KS_WARNING, "error creating the key"); -test_assert(ks.header->fields.instance == 2, "not second instance"); -error = ksGetKey(16, &size, &keyp); -test_assert(error == KS_NOERROR, "key not found"); -test_assert(size == sizeof(pattern512), "unexpected key length"); -test_assert(memcmp(pattern512, keyp, size) == 0, "wrong key content"); -test_assert(ks.block == KS_BLOCK1, "unexpected block"); + fields.instance == 1, "not first instance"); +error = ksWriteKey(16, sizeof(pattern512), pattern512); +test_assert(error == KS_WARNING, "error creating the key"); +test_assert(ks.header->fields.instance == 2, "not second instance"); +error = ksGetKey(16, &size, &keyp); +test_assert(error == KS_NOERROR, "key not found"); +test_assert(size == sizeof(pattern512), "unexpected key length"); +test_assert(memcmp(pattern512, keyp, size) == 0, "wrong key content"); +test_assert(ks.block == KS_BLOCK1, "unexpected block"); test_assert(ks_lld_is_block_erased(KS_BLOCK0) == true, "block 0 not erased");]]> @@ -657,25 +660,25 @@ test_assert(ks_lld_is_block_erased(KS_BLOCK0) == true, "block 0 not erased");]]> - @@ -687,13 +690,13 @@ for (key = 0; key < KS_CFG_NUM_KEYS; key++) { - @@ -705,19 +708,19 @@ test_assert(error == KS_KEY_NOT_FOUND, "key not erased");]]> - fields.instance == 2, "not second instance"); -error = ksWriteKey(16, sizeof(pattern512), pattern512); -test_assert(error == KS_WARNING, "error creating the key"); -test_assert(ks.header->fields.instance == 3, "not third instance"); -error = ksGetKey(16, &size, &keyp); -test_assert(error == KS_NOERROR, "key not found"); -test_assert(size == sizeof(pattern512), "unexpected key length"); -test_assert(memcmp(pattern512, keyp, size) == 0, "wrong key content"); -test_assert(ks.block == KS_BLOCK0, "unexpected block"); + fields.instance == 2, "not second instance"); +error = ksWriteKey(16, sizeof(pattern512), pattern512); +test_assert(error == KS_WARNING, "error creating the key"); +test_assert(ks.header->fields.instance == 3, "not third instance"); +error = ksGetKey(16, &size, &keyp); +test_assert(error == KS_NOERROR, "key not found"); +test_assert(size == sizeof(pattern512), "unexpected key length"); +test_assert(memcmp(pattern512, keyp, size) == 0, "wrong key content"); +test_assert(ks.block == KS_BLOCK0, "unexpected block"); test_assert(ks_lld_is_block_erased(KS_BLOCK1) == true, "block 0 not erased");]]> @@ -729,25 +732,25 @@ test_assert(ks_lld_is_block_erased(KS_BLOCK1) == true, "block 0 not erased");]]> - @@ -765,7 +768,7 @@ for (key = 0; key < KS_CFG_NUM_KEYS; key++) { - @@ -784,21 +787,21 @@ ksErase();]]> - @@ -810,21 +813,21 @@ for (key = 0; key < kmax; key++) { - @@ -836,17 +839,17 @@ for (key = 0; key < n; key++) { - fields.instance == 1, "not first instance"); -error = ksEraseKey(16); -test_assert(error == KS_WARNING, "error erasing the key"); -test_assert(ks.header->fields.instance == 2, "not second instance"); -error = ksGetKey(16, &size, &keyp); -test_assert(error == KS_KEY_NOT_FOUND, "key not erased"); -test_assert(ks.block == KS_BLOCK1, "unexpected block"); + fields.instance == 1, "not first instance"); +error = ksEraseKey(16); +test_assert(error == KS_WARNING, "error erasing the key"); +test_assert(ks.header->fields.instance == 2, "not second instance"); +error = ksGetKey(16, &size, &keyp); +test_assert(error == KS_KEY_NOT_FOUND, "key not erased"); +test_assert(ks.block == KS_BLOCK1, "unexpected block"); test_assert(ks_lld_is_block_erased(KS_BLOCK0) == true, "block 0 not erased");]]> diff --git a/testhal/STM32/multi/QSPI-MFS/main.c b/testhal/STM32/multi/QSPI-MFS/main.c index 9a874e47c..870153684 100644 --- a/testhal/STM32/multi/QSPI-MFS/main.c +++ b/testhal/STM32/multi/QSPI-MFS/main.c @@ -93,7 +93,6 @@ static THD_FUNCTION(Thread1, arg) { */ int main(void) { mfs_error_t err; - uint8_t *addr; /* * System initializations. @@ -121,11 +120,8 @@ int main(void) { /* Mounting the MFS volume defined in the configuration.*/ mfsObjectInit(&mfs); - mfsStart(&mfs, &mfscfg1); - - err = mfsUnmount(&mfs); + err = mfsStart(&mfs, &mfscfg1); err = mfsErase(&mfs); - err = mfsMount(&mfs); err = mfsWriteRecord(&mfs, 1, 64, pattern); err = mfsWriteRecord(&mfs, 2, 64, pattern); @@ -134,10 +130,9 @@ int main(void) { err = mfsPerformGarbageCollection(&mfs); - /* Reading.*/ - flashRead(&m25q, 0, 128, buffer); + mfsStop(&mfs); - err = mfsUnmount(&mfs); + (void)err; /* * Normal main() thread activity, in this demo it does nothing.