-
Notifications
You must be signed in to change notification settings - Fork 3k
STM32F4 - Add STORAGE driver #2556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,20 @@ | |
#include <string.h> | ||
#include <inttypes.h> | ||
|
||
#define ERASE_CASE_TIMEOUT (1000) | ||
|
||
using namespace utest::v1; | ||
|
||
#if defined(TARGET_K64F) | ||
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F; | ||
ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F; | ||
#elif defined(TARGET_STM) | ||
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_STM32; | ||
ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_STM32; | ||
#else | ||
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_(0); | ||
ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_(0); | ||
#endif | ||
|
||
/* temporary buffer to hold data for testing. */ | ||
static const unsigned BUFFER_SIZE = 16384; | ||
|
@@ -282,7 +292,7 @@ void programDataCompleteCallback(int32_t status, ARM_STORAGE_OPERATION operation | |
TEST_ASSERT(status >= 0); | ||
static unsigned programIteration = 0; | ||
|
||
static const uint32_t BYTE_PATTERN = 0xAA551122; | ||
static const uint8_t BYTE_PATTERN = 0xAA; | ||
ARM_STORAGE_BLOCK firstBlock; | ||
drv->GetNextBlock(NULL, &firstBlock); /* get first block */ | ||
TEST_ASSERT(ARM_STORAGE_VALID_BLOCK(&firstBlock)); | ||
|
@@ -301,9 +311,8 @@ void programDataCompleteCallback(int32_t status, ARM_STORAGE_OPERATION operation | |
|
||
size_t sizeofData = info.program_unit; | ||
TEST_ASSERT(BUFFER_SIZE >= sizeofData); | ||
TEST_ASSERT((sizeofData % sizeof(uint32_t)) == 0); | ||
for (size_t index = 0; index < sizeofData / sizeof(uint32_t); index++) { | ||
((uint32_t *)buffer)[index] = BYTE_PATTERN; | ||
for (size_t index = 0; index < sizeofData; index++) { | ||
((uint8_t *)buffer)[index] = BYTE_PATTERN; | ||
} | ||
|
||
status = drv->ProgramData(addr, buffer, sizeofData); | ||
|
@@ -371,17 +380,16 @@ control_t test_programDataUsingProgramUnit(const size_t call_count) | |
TEST_ASSERT(rc >= 0); | ||
if (rc == ARM_DRIVER_OK) { | ||
TEST_ASSERT_EQUAL(1, capabilities.asynchronous_ops); | ||
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(200) + CaseRepeatAll: CaseTimeout(200); | ||
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(ERASE_CASE_TIMEOUT) + CaseRepeatAll: CaseTimeout(ERASE_CASE_TIMEOUT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've combined two different things into a single commit. It is better to separate conceptually different changes into distinct commits. What is the justification for changing the erase Timeouts? Were you hitting this timeout on the ST NVM? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, i changed the erase timeouts because they were hitten. Typical erase time for a 128kB sector on STM32F429ZI is 1s and for a 16kB sector, 0.25 s. |
||
} else { | ||
TEST_ASSERT_EQUAL(firstBlock.attributes.erase_unit, rc); | ||
verifyBytePattern(addr, firstBlock.attributes.erase_unit, info.erased_value ? (uint8_t)0xFF : (uint8_t)0); | ||
|
||
static const uint32_t BYTE_PATTERN = 0xAA551122; | ||
static const uint8_t BYTE_PATTERN = 0xAA; | ||
size_t sizeofData = info.program_unit; | ||
TEST_ASSERT(BUFFER_SIZE >= sizeofData); | ||
TEST_ASSERT((sizeofData % sizeof(uint32_t)) == 0); | ||
for (size_t index = 0; index < sizeofData / sizeof(uint32_t); index++) { | ||
((uint32_t *)buffer)[index] = BYTE_PATTERN; | ||
for (size_t index = 0; index < sizeofData; index++) { | ||
((uint8_t *)buffer)[index] = BYTE_PATTERN; | ||
} | ||
|
||
/* program the sector at addr */ | ||
|
@@ -493,7 +501,7 @@ control_t test_programDataUsingOptimalProgramUnit(const size_t call_count) | |
TEST_ASSERT(rc >= 0); | ||
if (rc == ARM_DRIVER_OK) { | ||
TEST_ASSERT_EQUAL(1, capabilities.asynchronous_ops); | ||
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(200) + CaseRepeatAll: CaseTimeout(200); | ||
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(ERASE_CASE_TIMEOUT) + CaseRepeatAll: CaseTimeout(ERASE_CASE_TIMEOUT); | ||
} else { | ||
TEST_ASSERT_EQUAL(firstBlock.attributes.erase_unit, rc); | ||
verifyBytePattern(addr, firstBlock.attributes.erase_unit, info.erased_value ? (uint8_t)0xFF : (uint8_t)0); | ||
|
@@ -627,7 +635,7 @@ control_t test_erase(const size_t call_count) | |
int32_t rc = drv->Erase(addr, ERASE_UNITS_PER_ITERATION * firstBlock.attributes.erase_unit); | ||
if (rc == ARM_DRIVER_OK) { | ||
TEST_ASSERT_EQUAL(1, capabilities.asynchronous_ops); | ||
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(200) + CaseRepeatAll: CaseTimeout(200); | ||
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(ERASE_CASE_TIMEOUT) + CaseRepeatAll: CaseTimeout(ERASE_CASE_TIMEOUT); | ||
} else { | ||
TEST_ASSERT_EQUAL(ERASE_UNITS_PER_ITERATION * firstBlock.attributes.erase_unit, rc); | ||
|
||
|
@@ -911,7 +919,7 @@ control_t test_programDataWithMultipleProgramUnits(const size_t call_count) | |
TEST_ASSERT(rc >= 0); | ||
if (rc == ARM_DRIVER_OK) { | ||
TEST_ASSERT_EQUAL(1, capabilities.asynchronous_ops); | ||
return CaseTimeout(500); | ||
return CaseTimeout(1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why has this timeout been changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one was hitten too. I don't remember the N value but with this timeout the test pass. |
||
} else { | ||
TEST_ASSERT_EQUAL((N_UNITS * info.program_unit), rc); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* mbed Microcontroller Library | ||
******************************************************************************* | ||
* Copyright (c) 2016, STMicroelectronics | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************************************************************* | ||
*/ | ||
|
||
#include "Driver_Storage.h" | ||
|
||
ARM_STORAGE_BLOCK block_table[] = { | ||
{ | ||
.addr = 0x08000000, | ||
.size = 0x00010000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x4000, | ||
.protection_unit = 0x4000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08010000, | ||
.size = 0x00010000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x10000, | ||
.protection_unit = 0x10000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08020000, | ||
.size = 0x000E0000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x20000, | ||
.protection_unit = 0x20000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08100000, | ||
.size = 0x00010000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x4000, | ||
.protection_unit = 0x4000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08110000, | ||
.size = 0x00010000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x10000, | ||
.protection_unit = 0x10000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08120000, | ||
.size = 0x000E0000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x20000, | ||
.protection_unit = 0x20000, | ||
} | ||
} | ||
}; | ||
|
||
size_t block_table_size = sizeof(block_table) / sizeof(ARM_STORAGE_BLOCK); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* mbed Microcontroller Library | ||
******************************************************************************* | ||
* Copyright (c) 2016, STMicroelectronics | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************************************************************* | ||
*/ | ||
#ifndef STORAGE_DRIVER_INFO_H | ||
#define STORAGE_DRIVER_INFO_H | ||
|
||
/* Total size reserved for the storage */ | ||
#define STORAGE_TOTAL_SIZE (0x00200000) | ||
|
||
/* | ||
* Number of sector reserved for the firmware | ||
* This value must be block aligned. | ||
* The block repartition can be found in storage_driver_info.c | ||
*/ | ||
#define STORAGE_START_SECTOR (12) | ||
|
||
#endif /* STORAGE_DRIVER_INFO_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* mbed Microcontroller Library | ||
******************************************************************************* | ||
* Copyright (c) 2016, STMicroelectronics | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************************************************************* | ||
*/ | ||
|
||
#include "Driver_Storage.h" | ||
|
||
ARM_STORAGE_BLOCK block_table[] = { | ||
{ | ||
.addr = 0x08000000, | ||
.size = 0x00010000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x4000, | ||
.protection_unit = 0x4000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08010000, | ||
.size = 0x00010000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x10000, | ||
.protection_unit = 0x10000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08020000, | ||
.size = 0x000E0000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x20000, | ||
.protection_unit = 0x20000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08100000, | ||
.size = 0x00010000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x4000, | ||
.protection_unit = 0x4000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08110000, | ||
.size = 0x00010000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x10000, | ||
.protection_unit = 0x10000, | ||
} | ||
}, | ||
{ | ||
.addr = 0x08120000, | ||
.size = 0x000E0000, | ||
.attributes = { | ||
.erasable = 1, | ||
.programmable = 1, | ||
.executable = 1, | ||
.protectable = 1, | ||
.erase_unit = 0x20000, | ||
.protection_unit = 0x20000, | ||
} | ||
} | ||
}; | ||
|
||
size_t block_table_size = sizeof(block_table) / sizeof(ARM_STORAGE_BLOCK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonqhughes Is this renamed by accident ?