Write flash problem with the MFS driver.

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
Erdemege
Posts: 3
Joined: Tue Aug 16, 2022 10:13 am
Has thanked: 1 time

Write flash problem with the MFS driver.

Post by Erdemege »

Hello everyone, I'm new to ChibiOS and embedded development. I'm trying to use the MFS driver to write and read to the flash memory. I use the mfsWriteRecord() function to write. I can successfully write and read one record with the driver, however, when I try to write for the second time to a different location (by changing the id parameter) I get an MFS_ERR_FLASH_FAILURE error. To understand the problem I used a debugger and realized that at hal_efl_lld.c

Code: Select all

static inline flash_error_t stm32_flash_check_errors(EFlashDriver *eflp) {
  uint32_t sr = eflp->flash->SR;

  /* Clearing error conditions.*/
  eflp->flash->SR = sr & 0x0000FFFFU;

  /* Some errors are only caught by assertion.*/
  osalDbgAssert((sr & (FLASH_SR_FASTERR |
                       FLASH_SR_MISERR |
                       FLASH_SR_SIZERR)) == 0U, "unexpected flash error");

  /* Decoding relevant errors.*/
  if ((sr & FLASH_SR_WRPERR) != 0U) {
    return FLASH_ERROR_HW_FAILURE;
  }

  if ((sr & (FLASH_SR_PGAERR | FLASH_SR_PROGERR | FLASH_SR_OPERR)) != 0U) {
    return eflp->state == FLASH_PGM ? FLASH_ERROR_PROGRAM : FLASH_ERROR_ERASE;
  }

  return FLASH_NO_ERROR;
}


On here it returns FLASH_ERROR_PROGRAM at last if condition since the sr value is 168 which means my flash status registers' Bit 3 PROGERR, Bit 5 PGAERR and Bit 7 PGSERR are 1.

Am I using the mfsWriteRecord() function wrong? From what I understand from the documentation I just need to give unique id values for each different record. And of course, this id must be between 1 and MFS_CFG_MAX_RECORDS (32).
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Write flash problem with the MFS driver.

Post by Giovanni »

Hi,

You understanding is correct, it could be a problem in the flash driver.

Are you able to run the MFS test suite on your board? you should see failures in there too if it is an EFL problem, MFS_ERR_FLASH_FAILURE is a physical flash error.

It could also be an MFS configuration error, the 2 banks must be mapped on 2 physical flash sectors and not overlap.

Giovanni
Erdemege
Posts: 3
Joined: Tue Aug 16, 2022 10:13 am
Has thanked: 1 time

Re: Write flash problem with the MFS driver.

Post by Erdemege »

Hello,

First of all, thank you so much for your fast response.

It can be a silly question to ask but I don't where to find the MFS test suite since I'm quite new to the whole of this.

I'm using NUCLEO-L476RG and written my MFSConfig like this:

Code: Select all

const MFSConfig mfscfg1 = {

  .flashp           = (BaseFlash *)&EFLD1,

  .erased           = 0xFFFFFFFFU,

  .bank_size        = 4096U,

  .bank0_start      = 60U,

  .bank0_sectors    = 2U,

  .bank1_start      = 260U,

  .bank1_sectors    = 2U

};


If I understood the logic of the MSConfig this should be fine but I'm not sure.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Write flash problem with the MFS driver.

Post by Giovanni »

Hi,

There is a demo under /testhal/STM32/multi/EFL-MFS which supports a similar board, configuration appears correct.

Those EFL drivers are all contributed so I cannot make an absolute statement but should be fine because made by people who use them.

Giovanni
Erdemege
Posts: 3
Joined: Tue Aug 16, 2022 10:13 am
Has thanked: 1 time

Re: Write flash problem with the MFS driver.

Post by Erdemege »

Hello,

Thank you so much for your answer.
I switched to the oldest release of the chibios (21.11.2). mfsStart function which I call at the beginning to use mfs driver directly gives me an MFS_ERR_INTERNAL error. What can cause this problem? It says internal logic failure but can you expand this please?

Thank you so much for your time and support.
Erdem
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Write flash problem with the MFS driver.

Post by Giovanni »

That error can be caused by errors returned by the underlying EFL driver, moving this topic in "bug reports" but I cannot guarantee when I will be able to give it a try.

You may try to step into mfsStart() and see where exactly if fails, I suppose it is where it tries to read the header back which would hint to an EFL problem.

Giovanni
Post Reply