Adding Dual-Bank EFL Support to F429/F439 Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
heliochronix
Posts: 34
Joined: Thu Aug 31, 2017 6:32 pm
Has thanked: 8 times
Been thanked: 6 times

Re: Adding Dual-Bank EFL Support to F429/F439

Postby heliochronix » Tue Feb 23, 2021 2:20 am

Okay, I'm taking a look at the registry option. It will involve making a duplicate of the entire stm32_registry section for these 4 devices to differentiate between G and I suffix devices as follows...

Code: Select all

#elif defined(STM32F439xx) || defined(STM32F429xx)
#define STM32F429_439xx
#define STM32F4XX

#elif defined(STM32F437xx) || defined(STM32F427xx)
#define STM32F427_437xx
#define STM32F4XX

...

/*===========================================================================*/
/* STM32F439xx, STM32F429xx, STM32F437xx, STM32F427xx.                       */
/*===========================================================================*/

#if defined(STM32F429_439xx) || defined(STM32F427_437xx)
...
#endif /* defined(STM32F429_439xx) || defined(STM32F427_437xx) */

becomes...

Code: Select all

#elif defined(STM32F439xG) || defined(STM32F429xG)
#define STM32F429_439xG
#define STM32F4XX

#elif defined(STM32F437xG) || defined(STM32F427xG)
#define STM32F427_437xG
#define STM32F4XX

#elif defined(STM32F439xI) || defined(STM32F429xI)
#define STM32F429_439xI
#define STM32F4XX

#elif defined(STM32F437xI) || defined(STM32F427xI)
#define STM32F427_437xI
#define STM32F4XX

...

/*===========================================================================*/
/* STM32F439xG, STM32F429xG, STM32F437xG, STM32F427xG.                       */
/*===========================================================================*/

#if defined(STM32F429_439xG) || defined(STM32F427_437xG)
...
/* Flash attributes.*/
#define STM32_FLASH_DUAL_BANK_PERMANENT     FALSE
...
#endif /* defined(STM32F429_439xG) || defined(STM32F427_437xG) */

/*===========================================================================*/
/* STM32F439xI, STM32F429xI, STM32F437xI, STM32F427xI.                       */
/*===========================================================================*/

#if defined(STM32F429_439xI) || defined(STM32F427_437xI)
...
/* Flash attributes.*/
#define STM32_FLASH_DUAL_BANK_PERMANENT     TRUE
...
#endif /* defined(STM32F429_439xI) || defined(STM32F427_437xI) */

We then need to go and edit os/common/ext/ST/STM32F4xx/stm32f4xx.h to change the check for these defined values to have the correct suffix for all 4 device types, and update all respective demo applications and board files to also use these suffix. However, this may also break any other projects that depend on ChibiOS that define STM32F427xx STM32F429xx STM32F437xx or STM32F439xx. Unless we don't change the original registry definition and instead just have that default to false? So effectively we'd have...

Code: Select all

#elif defined(STM32F439xx) || defined(STM32F429xx)
#define STM32F429_439xx
#define STM32F4XX

#elif defined(STM32F437xx) || defined(STM32F427xx)
#define STM32F427_437xx
#define STM32F4XX

#elif defined(STM32F439xI) || defined(STM32F429xI)
#define STM32F429_439xI
#define STM32F4XX

#elif defined(STM32F437xI) || defined(STM32F427xI)
#define STM32F427_437xI
#define STM32F4XX

...

/*===========================================================================*/
/* STM32F439xx, STM32F429xx, STM32F437xx, STM32F427xx.                       */
/*===========================================================================*/

#if defined(STM32F429_439xx) || defined(STM32F427_437xx)
...
/* Flash attributes.*/
#define STM32_FLASH_DUAL_BANK_PERMANENT     FALSE
...
#endif /* defined(STM32F429_439xx) || defined(STM32F427_437xx) */

/*===========================================================================*/
/* STM32F439xI, STM32F429xI, STM32F437xI, STM32F427xI.                       */
/*===========================================================================*/

#if defined(STM32F429_439xI) || defined(STM32F427_437xI)
...
/* Flash attributes.*/
#define STM32_FLASH_DUAL_BANK_PERMANENT     TRUE
...
#endif /* defined(STM32F429_439xI) || defined(STM32F427_437xI) */

If this was the case then it's up to the application developer to ensure they define the correct value in their board files.

It almost seems like it'd be more manageable to just check the flash size register (defined by FLASHSIZE_BASE), and if it's 2048 the function just returns true. The example implementation I presented above indirectly does this because the flash_descriptor_t "size" member will equal the scaled FLASH SIZE register value. But if it's preferred to offload this work to the compiler and we don't mind changing os/common/ext/ST/STM32F4xx/stm32f4xx.h, I can investigate the registry method further.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Adding Dual-Bank EFL Support to F429/F439

Postby Giovanni » Tue Feb 23, 2021 6:18 am

There is no way to check the device memory size at compile time, ST headers do not have that information so it is not available in the registry too.

You could assume to have put a definition in the Makefile for the less frequent case.

Giovanni

heliochronix
Posts: 34
Joined: Thu Aug 31, 2017 6:32 pm
Has thanked: 8 times
Been thanked: 6 times

Re: Adding Dual-Bank EFL Support to F429/F439

Postby heliochronix » Tue Feb 23, 2021 6:31 am

I'm not sure I understand. The registry depends on device name as defined in the board file, does it not? How do we differentiate between the 2MB and 1MB devices in the registry otherwise?

Apologies, I think your message changed. Would a runtime check of flash size be acceptable as well? Or just the compile-time check. We check device flash size at other points in the code as well.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Adding Dual-Bank EFL Support to F429/F439

Postby Giovanni » Tue Feb 23, 2021 3:09 pm

it is better to avoid runtime checks, basically it is dead code.

Giovanni

heliochronix
Posts: 34
Joined: Thu Aug 31, 2017 6:32 pm
Has thanked: 8 times
Been thanked: 6 times

Re: Adding Dual-Bank EFL Support to F429/F439

Postby heliochronix » Tue Feb 23, 2021 4:20 pm

Okay, sounds good! I've set it to use the value FXCoder suggested (STM32_FLASH_DUAL_BANK_PERMANENT). I have it pretty much complete and just need to test it a bit on our device.

We're hoping to see this added to stable_20.3.x if possible. It would not break any existing code I think. Would it be better to create the patch set against stable_20.3.x or the latest trunk? If it was on trunk, would it be backported to stable_20.3.x? It looks like there have been no changes to the files between stable_20.3.x and trunk, so perhaps it does not make a difference?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Adding Dual-Bank EFL Support to F429/F439

Postby Giovanni » Tue Feb 23, 2021 5:02 pm

I will add it to 20.3 only if it does not break anything, it has to be compatible. For sure it will go in trunk.

Giovanni

heliochronix
Posts: 34
Joined: Thu Aug 31, 2017 6:32 pm
Has thanked: 8 times
Been thanked: 6 times

Re: Adding Dual-Bank EFL Support to F429/F439

Postby heliochronix » Thu Feb 25, 2021 1:37 am

Hello again!

I've implemented the EFL driver for the STM32F427/429/437/439 devices that support dual bank operations. I've managed to test this new code fairly thoroughly on an STM32F439VI, and it works nicely.

I found some bugs with what looked like manual edits of the CMSIS files for these devices where someone did a #define of the bank 2 erase bit to the bank 1 erase bit's value, and these have been corrected to the proper values.

As far as changes that may affect things outside of the scope of these specific devices, the driver now will check for a compile-time definition of STM32_FLASH_DUAL_BANK_PERMANENT being TRUE to have dual bank checking function return true, but this value defaults to FALSE (the common case). As such, this should not affect any other projects unless they want to make use of it. Another change to the common code is a check for sector numbers >= 12 on dual-bank devices only, where the FLASH_CR_SNB value starts numbering sector 12+ as 0b10000 and up. While the other device that the EFL is implemented for does not offset sector 12+ like this, they do not have the dual bank bit defined that the compiler checks for, so this code should never be compiled for these other devices and as such should also not affect them. The final common code change is a check for which bank is currently being executed from (on dual-bank devices only), and having the erase_all command erase the opposite bank. Whereas before it always erased bank 2, even if it was being executed from.

Beyond these things, the rest of the code is part of new #elseif pre-compiler checks and as such should not affect existing projects unless they want to make use of the functionality.

Hopefully this clearly explains the changes made. I think this should be safe for addition to the stable branch, but I would not mind a second pair of eyes looking over it to verify. The interesting thing is, there was a bunch of code for dual bank stuff, but none of the currently defined devices actually had this dual-bank functionality.
Attachments
stm32f42x_f43x_efl.zip
(2.93 KiB) Downloaded 150 times

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Adding Dual-Bank EFL Support to F429/F439

Postby Giovanni » Thu Feb 25, 2021 6:27 am

Hi,

Editing the CMSIS files is not a good idea, on the next headers update the change will be lost. Is it possible to make the driver to not rely on that?

Giovanni

heliochronix
Posts: 34
Joined: Thu Aug 31, 2017 6:32 pm
Has thanked: 8 times
Been thanked: 6 times

Re: Adding Dual-Bank EFL Support to F429/F439

Postby heliochronix » Thu Feb 25, 2021 6:55 am

Ah fascinating. Okay, good to know. I can probably make it use the existing values for now. They are definitely inconsistent with the Reference Manual, so if future updates fix that issue it will probably break the driver anyway, but I've made the appropriate changes and attached the file below.

Just out of curiosity, where are these CMSIS files sourced from?
Attachments
stm32f42x_43x_efl.zip
(2.58 KiB) Downloaded 156 times

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Adding Dual-Bank EFL Support to F429/F439

Postby Giovanni » Thu Feb 25, 2021 8:12 am

Those are from ST Cube software, we import the new versions from time to time, that kind of errors are not infrequent.

Giovanni


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 7 guests