Skip to content

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions TESTS/storage_abstraction/basicAPI/basicAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

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 ?

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;
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has this timeout been changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);

Expand Down
6 changes: 3 additions & 3 deletions hal/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
"progen": {"target": "nucleo-f429zi"},
"macros": ["DEVICE_RTC_LSI=1", "TRANSACTION_QUEUE_SIZE_SPI=2"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "STORAGE", "TRNG"],
"detect_code": ["0796"],
"features": ["IPV4"],
"release_versions": ["2", "5"]
Expand Down Expand Up @@ -1075,7 +1075,7 @@
"macros": ["DEVICE_RTC_LSI=1","TRANSACTION_QUEUE_SIZE_SPI=2"],
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
"progen": {"target": "disco-f429zi"},
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "STORAGE", "TRNG"],
"release_versions": ["2", "5"]
},
"DISCO_F469NI": {
Expand All @@ -1088,7 +1088,7 @@
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"],
"progen": {"target": "disco-f469ni"},
"detect_code": ["0788"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "STORAGE", "TRNG"],
"release_versions": ["2", "5"]
},
"DISCO_L053C8": {
Expand Down
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);
Loading