Skip to content

STM32F437: remove flash api implementation #4868

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

Merged
merged 2 commits into from
Aug 8, 2017

Conversation

0xc0170
Copy link
Contributor

@0xc0170 0xc0170 commented Aug 7, 2017

STM32F4 already contains generic flash api implementation, use it. However still fails to compile for me. Seems like F437xG has only first bank flash memory. But in the generic F4 flash driver, it is defined that it should have more flash sectors

this is taken from STM32 flash driver

#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) ||\
    defined(STM32F469xx) || defined(STM32F479xx)
#define FLASH_SECTOR_0     0U  /*!< Sector Number 0   */
#define FLASH_SECTOR_1     1U  /*!< Sector Number 1   */
#define FLASH_SECTOR_2     2U  /*!< Sector Number 2   */
#define FLASH_SECTOR_3     3U  /*!< Sector Number 3   */
#define FLASH_SECTOR_4     4U  /*!< Sector Number 4   */
#define FLASH_SECTOR_5     5U  /*!< Sector Number 5   */
#define FLASH_SECTOR_6     6U  /*!< Sector Number 6   */
#define FLASH_SECTOR_7     7U  /*!< Sector Number 7   */
#define FLASH_SECTOR_8     8U  /*!< Sector Number 8   */
#define FLASH_SECTOR_9     9U  /*!< Sector Number 9   */
#define FLASH_SECTOR_10    10U /*!< Sector Number 10  */
#define FLASH_SECTOR_11    11U /*!< Sector Number 11  */
#define FLASH_SECTOR_12    12U /*!< Sector Number 12  */
#define FLASH_SECTOR_13    13U /*!< Sector Number 13  */
#define FLASH_SECTOR_14    14U /*!< Sector Number 14  */
#define FLASH_SECTOR_15    15U /*!< Sector Number 15  */
#define FLASH_SECTOR_16    16U /*!< Sector Number 16  */
#define FLASH_SECTOR_17    17U /*!< Sector Number 17  */
#define FLASH_SECTOR_18    18U /*!< Sector Number 18  */
#define FLASH_SECTOR_19    19U /*!< Sector Number 19  */
#define FLASH_SECTOR_20    20U /*!< Sector Number 20  */
#define FLASH_SECTOR_21    21U /*!< Sector Number 21  */
#define FLASH_SECTOR_22    22U /*!< Sector Number 22  */
#define FLASH_SECTOR_23    23U /*!< Sector Number 23  */
#endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx || STM32F469xx || STM32F479xx */

We can see that for F437xx , there is defined flash sector 12. But this one is missing for ublox F437xG targets. @RobMeades any pointers?

@LMESTM

STM32F4 already contains generic flash api implementation, use it.
@0xc0170
Copy link
Contributor Author

0xc0170 commented Aug 7, 2017

cc @adustm

One of these two are not correct : #4835 or #4854 (the very last 2 PR that got in STM32F4 folder)

@adustm
Copy link
Member

adustm commented Aug 8, 2017

Hello @0xc0170
STM32F437 device have 2 flash sizes : stm32f437xG has 1Mb flash, ans stm32f437xI has 2Mb flash.

Removing TARGET_STM32F4/TARGET_STM32F437xG/device/flash_api.c to use the common one TARGET_STM32F4/flash_api.c is correct
Adding FLASH_SIZE = 0x10000000 in flash_data.h is correct.

We should use ADDR_FLASH_SECTOR_12 instead of FLASH_SECTOR_12 in flash_api.c in order to check the presence of the second bank of flash on the device

diff --git a/targets/TARGET_STM/TARGET_STM32F4/flash_api.c b/targets/TARGET_STM/TARGET_STM32F4/flash_api.c
index 485023a..a173c0a 100644
--- a/targets/TARGET_STM/TARGET_STM32F4/flash_api.c
+++ b/targets/TARGET_STM/TARGET_STM32F4/flash_api.c
@@ -151,7 +151,7 @@ static uint32_t GetSector(uint32_t address)
     uint32_t sector = 0;
     uint32_t tmp = address - ADDR_FLASH_SECTOR_0;
     /* This function supports 1Mb and 2Mb flash sizes */
-#if defined(FLASH_SECTOR_12)
+#if defined(ADDR_FLASH_SECTOR_12)
     if (address & 0x100000) { // handle 2nd bank
         sector = FLASH_SECTOR_12;
         tmp = address - ADDR_FLASH_SECTOR_12;

Could you add this modification in this PR ?
Thanks in advance
Armelle

@0xc0170
Copy link
Contributor Author

0xc0170 commented Aug 8, 2017

Thanks @adustm , I am looking at this currently. I'll do ADDR_FLASH_SECTOR_12 as proposed.

Use ADDR_FLASH_SECTOR_12 as this is defined by target (the flash size varies, for
instance for some F437xx is up to 2MB (2nd bank might not be there)).
@0xc0170
Copy link
Contributor Author

0xc0170 commented Aug 8, 2017

@adustm Added, please review

@0xc0170
Copy link
Contributor Author

0xc0170 commented Aug 8, 2017

Nina C030 now compiles

Elf2Bin: basic
+-------------+-------+-------+-------+
| Module      | .text | .data |  .bss |
+-------------+-------+-------+-------+
| BUILD/tests | 22290 |   228 | 19567 |
| Fill        |   148 |     0 |    20 |
| Misc        | 21507 |  2488 |   117 |
| Subtotals   | 43945 |  2716 | 19704 |
+-------------+-------+-------+-------+
Allocated Heap: unknown
Allocated Stack: unknown
Total Static RAM memory (data + bss): 22420 bytes
Total RAM memory (data + bss + heap + stack): 22420 bytes
Total Flash memory (text + data + misc): 46661 bytes
Image: BUILD/tests/UBLOX_C030_N211/GCC_ARM/TESTS/mbedmicro-rtos-mbed/basic/basic.bin

@0xc0170
Copy link
Contributor Author

0xc0170 commented Aug 8, 2017

/morph test

@RobMeades
Copy link
Contributor

RobMeades commented Aug 8, 2017

I'm not in a position to run any tests for the next few days but it's likely I missed the subtlety of using ADDR_FLASH_SECTOR_12 instead of FLASH_SECTOR_12. Hence this change looks like a step in the right direction. In the unlikely event that there's an issue with C030 I can fix subsequently as the board is not yet publicly available.

@mbed-bot
Copy link

mbed-bot commented Aug 8, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 960

All builds and test passed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants