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

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

Postby heliochronix » Fri Feb 12, 2021 7:46 pm

Hello all,

I'm looking to add EFL with dual-bank support for the STM32F429xI/STM32F439xI. In my efforts, I noticed that there seems to be a little bit of inconsistency with regards to the implementation of EFL between different STM32 platforms, and I wanted to clarify if the existing STM32F4xx code should be brought in line with the rest of the system.

In particular, I'm noticing that in all the other platforms, the value of STM32_FLASH_NUMBER_OF_BANKS is defined in stm32_registry.h, but in the STM32F4xx platform it seems to be defined in the hal_efl_lld.h file. Should this be moved to the per-device sections of stm32_registry.h?

Also, it looks like the STM32L4xx+ is one of the only ones with an actual dual-bank implementation with EFL currently in ChibiOS. Would you say this device is a good reference for implementation on the F429xI/F439xI?

The purpose of all this is to be able to support live firmware updates and redundant images for a project I'm involved with. Hopefully using EFL is the right path to take for that purpose. I am planning to contribute the additions upstream through this topic once it's up to ChibiOS standards.

Thank you!

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 » Fri Feb 12, 2021 7:59 pm

Hi,

EFL drivers have been contributed as various points so the state in not homogeneous, the L4 is the most recent one and could be used as reference.

Defining that value in the registry or in the driver is correct either ways, you need to put it in the registry if there are a lot of different devices in the sub-family.

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 » Fri Feb 19, 2021 10:54 pm

Thank you for your feedback Giovanni!

If I may ask a couple questions about implementation... I'm trying to define the "flash_descriptor_t" structs for these STM32F4xx devices, and I'm not exactly sure what the correct way to do this is. Is a given "flash_descriptor_t" supposed to describe an entire flash memory (that is, both banks together) or just a single bank of the flash memory in dual-bank systems? The goal being to write to one bank or another when configured for dual-bank mode, but not necessarily having to write both banks simultaneously.

It seems the STM32L4+ implementation seems to treat both banks as one flash descriptor, and it seems if you want to handle the banks independently we would want them described separately. Perhaps I am not understanding the meaning of the "flash_descriptor_t" structure though?

Thank you

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 » Fri Feb 19, 2021 11:48 pm

Reading some of the other code, I may have answered my own question. It seems it's supposed to be a descriptor of the entire flash memory, with a dual bank descriptor combining both banks together as one. However, I've ran into another issue..

Part of the difficulty of implementing dual bank support for the F4 devices is that the 2MB devices (F42xI/F43xI) are permanently configured for dual-bank mode, so the following code would always evaluate to false because either there would either be a single descriptor (STM32_FLASH_NUMBER_OF_BANKS=1) or it would test for the DB1M bit being set but this bit is doesn't exist on 2MB devices.

Code: Select all

static inline bool stm32_flash_dual_bank(EFlashDriver *eflp) {

#if STM32_FLASH_NUMBER_OF_BANKS > 1
  return ((eflp->flash->OPTCR & FLASH_OPTCR_DB1M) != 0U);
#endif
  (void)eflp;
  return false;
}


Do you have any preference on how this might be solved? Or are you okay with my attempting a solution and just doing a code review when I have patches ready for you?

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 » Sat Feb 20, 2021 7:33 am

Hi,

You could check if FLASH_OPTCR_DB1M is defined in header files or not.

Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

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

Postby FXCoder » Sat Feb 20, 2021 8:02 am

Hi,
FYI DB1M (bit 30 of OPTCR) is shown in the Ref Manual (page 108 of RM0090 - DocID018909 Rev 15) as being in the F42xxx and F43xxx MCUs.
However, DB1M is not defined in the ST header for F423 but is for F427 & F429 header files.

If you have an F423 then you could use ST-LINK to inspect flash options to see what is actually there?
--
Bob

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 » Sat Feb 20, 2021 11:49 pm

The bit field is defined in the header files, that is not really the problem. Rather, take for example the STM32F439VI (the device we are working with). This device is a 2MB flash device with dual bank support, but it is not configurable via the FLASH_OPTCR_DB1M bit because that bit is only for the 1MB devices. When the OPTCR register is read from the STM32F439VI it shows this bit to be a 0, but the device is inherently in dual-bank mode all the time because it does not have a single bank mode. However, if we were using the STM32F439VG (the 1MB device), this bit would in fact control the bank mode and it could be referenced to determine the mode of operation.

Both the STM32F439VI and STM32F439VG fall under the same registry entry, and they both have this bit defined in the header files. The problem is that on the F439VI the bit has no meaning despite the device being dual banked.

I guess the question is, what would be the best method of having stm32_flash_dual_bank() return true for the 2MB flash devices?

One solution I can think of is to have the STM32_FLASH_NUMBER_OF_BANKS set to 2 and the flash_descriptor_t table defined twice for the 2MB devices, then have it check for the flash size being equal to the 2M device as follows...

Code: Select all

/* The descriptors for 2M device. */
static const flash_descriptor_t efl_lld_size2[STM32_FLASH_NUMBER_OF_BANKS] = {
      { /* Dual bank organisation. */
       .attributes        = FLASH_ATTR_ERASED_IS_ONE |
                            FLASH_ATTR_MEMORY_MAPPED,
       .page_size         = STM32_FLASH_LINE_SIZE,
       .sectors_count     = STM32_FLASH_SECTORS_TOTAL_2M,
       .sectors           = efl_lld_sect_2m,
       .sectors_size      = 0,
       .address           = (uint8_t *)FLASH_BASE,
       .size              = STM32_FLASH_SIZE_2M * STM32_FLASH_SIZE_SCALE
      },
      { /* Dual bank organisation. */
       .attributes        = FLASH_ATTR_ERASED_IS_ONE |
                            FLASH_ATTR_MEMORY_MAPPED,
       .page_size         = STM32_FLASH_LINE_SIZE,
       .sectors_count     = STM32_FLASH_SECTORS_TOTAL_2M,
       .sectors           = efl_lld_sect_2m,
       .sectors_size      = 0,
       .address           = (uint8_t *)FLASH_BASE,
       .size              = STM32_FLASH_SIZE_2M * STM32_FLASH_SIZE_SCALE
      }
};

Code: Select all

static inline bool stm32_flash_dual_bank(EFlashDriver *eflp) {

#if STM32_FLASH_NUMBER_OF_BANKS > 1
  return ((eflp->flash->OPTCR & FLASH_OPTCR_DB1M) != 0U ||
           eflp->descriptor->size == STM32_FLASH_SIZE_2M * STM32_FLASH_SIZE_SCALE);
#endif
  (void)eflp;
  return false;
}


Does that seem reasonable? It seems a little dirty with the redundant entries for 2MB devices... but I think it should return a true for the 2MB devices

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

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

Postby FXCoder » Mon Feb 22, 2021 1:26 am

The F4 series certainly has its quirks.
It would be nice to fill out the F4 EFL setup completely but probably not ATM.

Anyway the F439 flash could be best described as dual bank but not switchable.
If so then there could be a new #define FLASH_DUAL_BANK_PERMANENT TRUE (or whatever) within the STM32F429xx section along with a guard in efl_lld.c local definitions for !defined(FLASH_DUAL_BANK_PERMANENT).

Then stm32_flash_dual_bank() could be something like this..

Code: Select all

static inline bool stm32_flash_dual_bank(EFlashDriver *eflp) {

#if STM32_FLASH_NUMBER_OF_BANKS > 1
  return ((eflp->flash->OPTCR & FLASH_OPTCR_DB1M) != 0U && !FLASH_DUAL_BANK_PERMANENT );
#endif
  (void)eflp;
  return false;
}


I'm sure this needs more consideration and other handling in functions (such as bank erase) so please provide further thoughts...
--
Bob

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 » Mon Feb 22, 2021 5:40 pm

The STM32F439VG is switchable though. and such a change would cause this 1MB device to permanently be considered dual-banked. The only devices which are dual bank but not switchable are 2MB devices (that is, anything suffixed with an "I" as follows: STM32F4xxxI). It seems to me we'd either have to change the granularity of the registry to include the flash size suffix of the devices, or we check it at run-time somehow.

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

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

Postby FXCoder » Tue Feb 23, 2021 12:35 am

Hi,
Adding "I suffix" device IDs to registry would seem a reasonable option versus runtime checking.
So flash tables would then be defined for the specific device which does have the benefit of making the situation more clear (as far as it can be for F4....)
A dummy bank entry for the non-switchable case like you already proposed seems a reasonable solution.
That approach would allow the MER function code to work as is.

Maybe Giovanni has some thoughts to add?
--
Bob


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 6 guests