Help regarding MFSConfig

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
akshaim
Posts: 8
Joined: Tue Sep 21, 2021 9:47 am
Has thanked: 3 times

Help regarding MFSConfig

Postby akshaim » Tue Sep 21, 2021 1:04 pm

Hi All,

I am new to ChibiOS and was trying to configure an STM32F767ZI (dual bank) to use MFS (Managed Flash Storage). I came across this descriptor for the driver `testhal/STM32/multi/EFL-MFS/main.c` about which I am a bit confused.

Code: Select all

const MFSConfig mfscfg1 = {
  .flashp           = (BaseFlash *)&EFLD1,
  .erased           = 0xFFFFFFFFU,
  .bank_size        = 4096U,
  .bank0_start      = 128U,
  .bank0_sectors    = 2U,
  .bank1_start      = 130U,
  .bank1_sectors    = 2U
};


What does .bank_size, bank0_start, .bank0_sectors, .bank1_start and .bank1_sectors mean and how do we arrive at the values ? The parent structure does not provide much information about how to arrive at the values hence the forum post.

Any help is appreciated :)

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

Re: Help regarding MFSConfig

Postby Giovanni » Tue Sep 21, 2021 1:56 pm

Hi,

MFS operates on 2 backs with equal size, 4096 in that example.

The two banks can be formed by multiple flash sectors, you need to specify the 1st sector of each bank and how many sectors you need to reach the bank size (4096).

Giovanni

akshaim
Posts: 8
Joined: Tue Sep 21, 2021 9:47 am
Has thanked: 3 times

Re: Help regarding MFSConfig

Postby akshaim » Tue Sep 21, 2021 2:43 pm

Hi Giovanni,

Thanks for the quick reply. From what I understand , for dual bank operation with sector size 128KB, this should be okay, right ?

Code: Select all

const MFSConfig mfscfg1 = {
    .flashp           = (BaseFlash *)&EFLD1,
    .erased           = 0xFFFFFFFFU,
    .bank_size        = 131,072U, //128 Sector size x 1024
    .bank0_start      = 19U, //Sector 19
    .bank0_sectors    = 1U,
    .bank1_start      = 20U, //Sector 20
    .bank1_sectors    = 1U
};


On a side note , does the MFS driver check if the program code is already flashed into the sector or not ?

- Akshai

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

Re: Help regarding MFSConfig

Postby Giovanni » Tue Sep 21, 2021 5:35 pm

That should be fine.

Banks are initialized on the 1st call to mfsInit() and are ready to use.

Giovanni

akshaim
Posts: 8
Joined: Tue Sep 21, 2021 9:47 am
Has thanked: 3 times

Re: Help regarding MFSConfig

Postby akshaim » Thu Sep 30, 2021 3:52 pm

Hi Giovanni,

Thanks for the help :)

Need a suggestion from you on the following issue.

Question in Summary :
Is there an internal state machine that limits the device to access bank 0 while booting from bank 1 ?

Question in detail :
I have now moved to an STM32L475VC and it has two banks ( Bank 0 : 0x0800 0000 and Bank 1 0x0808 0000 ) . I have used the following configuration to flash an MFS test application by flashing the same to bank 0 and boot from bank0

Code: Select all

const MFSConfig mfscfg1 = {
        .flashp           = (BaseFlash *)&EFLD1,
        .erased           = 0xFFFFFFFFU,
        .bank_size        = 4096U,
        .bank0_start      = 60U,
        .bank0_sectors    = 2U,
        .bank1_start      = 120U, //As per the readout from STM32Cube programmer ( 0-63 Bank 0 and 63-128 Bank1)
        .bank1_sectors    = 2U
};


The above configuration works fine. But however, I tried to use the same configuration and flashed the program to Bank 1 and tried to boot from Bank 1 . Then the program would hang while doing

Code: Select all

mfsStart(&mfs1, &mfscfg1);
.

Can you help ?

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

Re: Help regarding MFSConfig

Postby Giovanni » Thu Sep 30, 2021 4:23 pm

Hi,

I am a little confused by MFS "banks" and L4 banks, those are two different things.

You should try to have both "MFS banks" in the same "L4 bank" and execute the program from the other "L4 bank". If you don't do this then you will have a RWW issue (red while write), that could be the hang you are experiencing. You should not read (or execute from) a bank while you are programming/erasing it.

Giovanni

akshaim
Posts: 8
Joined: Tue Sep 21, 2021 9:47 am
Has thanked: 3 times

Re: Help regarding MFSConfig

Postby akshaim » Fri Oct 01, 2021 10:29 am

Hi Giovanni,

Good day to you. Thanks for the reply.

I tried your suggestion with the following configuration and flashed the program to bank 1 ( 0x08020000) but it does not seem to work. The program just hangs at mfsStart(&mfs1, &mfscfg1);

Code: Select all

const MFSConfig mfscfg1 = {
    .flashp           = (BaseFlash *)&EFLD1,
    .erased           = 0xFFFFFFFFU,
    .bank_size        = 4096U,
    .bank0_start      = 120U,
    .bank0_sectors    = 2U,
    .bank1_start      = 125U,
    .bank1_sectors    = 2U
};




The following is the flash bank organisation of STM32L475VC ( 256KB)
https://imgur.com/a/4xR5v1a

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

Re: Help regarding MFSConfig

Postby Giovanni » Fri Oct 01, 2021 12:00 pm

Hi,

It hangs how? you need to understand how and where exactly it fails.

Giovanni

akshaim
Posts: 8
Joined: Tue Sep 21, 2021 9:47 am
Has thanked: 3 times

Re: Help regarding MFSConfig

Postby akshaim » Mon Oct 04, 2021 12:47 pm

Hi Giovanni,

I have added debug statements and here are the errors.

Code: Select all

 MFS Start Success 0 // mfsStart(&mfs1, &mfscfg1);
 MFS Erase Error -8 // mfsErase(&mfs1); 
 Write Error -1 //mfsWriteRecord(...);
 Read Error -1 // // mfsReadRecord(...)


-8 would mean a MFS_ERR_FLASH_FAILURE. Driver does not seem to allow RW operation while booting from second bank.

The configuration of MFS is

Code: Select all

const MFSConfig mfscfg1 = {
    .flashp           = (BaseFlash *)&EFLD1,
    .erased           = 0xFFFFFFFFU,
    .bank_size        = 4096U,
    .bank0_start      = 124U,
    .bank0_sectors    = 2U,
    .bank1_start      = 126U,
    .bank1_sectors    = 2U
};



Regards,

Akshai M

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

Re: Help regarding MFSConfig

Postby Giovanni » Mon Oct 04, 2021 1:17 pm

Hi,

I suggest you look at the "Read-while-write (RWW)" paragraph in the STM32 RM, the driver does no magic, it is subject to all limitations described there.

Anyway, those errors seem to originate in the flash driver not MFS itself. You may try to step into the driver and see exactly where it fails.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 1 guest