Internal Flash Driver

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.
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: Internal Flash Driver

Post by faisal »

Giovanni, see the attachment. This should give you a head start. It's a working driver for the STM32L4 series based on the hal_flash abstraction.
Attachments
stm32_internal_flash.zip
(3.66 KiB) Downloaded 642 times
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: Internal Flash Driver

Post by alex31 »

Hello,

Thanks for this flash driver for the L4

Is it possible for you to send a minimal example that use this library ?

Thanks
Alexandre
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: Internal Flash Driver

Post by faisal »

alex31 wrote:Hello,

Thanks for this flash driver for the L4

Is it possible for you to send a minimal example that use this library ?

Thanks
Alexandre


Sorry, I don't have one at this time. It should be fairly simple to use - below is an example for erasing.

Code: Select all

STM32Flash flashDevBank2;
stm32FlashObjectInit(&flashDevBank2, 2);

BaseFlash * pFlashDev = getBaseFlash(&flashDevBank1);

// Erasing
while(flashWaitErase(pFlashDev) != FLASH_NO_ERROR) {};
flashStartEraseAll(pFlashDev);
if(flashWaitErase(pFlashDev) != FLASH_NO_ERROR)
{
  // handle error
}


As you can see, it uses the hal_flash abstraction. So for programming you would use the flashProgram() function. There is also a flashRead() function in hal_flash ..

If you can put together a simple example - that would help Giovanni integrating it, as an example code would be required in testhal .

Keep in mind the double word alignment requirements the STM32 has for writing to flash if I remember correctly.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Internal Flash Driver

Post by Giovanni »

Hi,

In preparation for this I am introducing a proper EFL driver in HAL, implementations will be normal LLD drivers, I will try to transform the L4 code into that. Should not take long.

Giovanni
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: Internal Flash Driver

Post by faisal »

If you're taking suggestions for the order of including device support, consider the stm32F72x next :)

Thanks for turning your attention to the internal flash driver. We may have some test/example code to contribute for testhal as well. I'll look into it if it would help.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Internal Flash Driver

Post by Giovanni »

Hi,

I added the new driver to trunk, it is not tested but you are welcome to give it a try :)

Currently it manages both banks as a single driver instance but I am thinking to modify it to have one instance for each bank like it was in the original proposal.

Giovanni
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: Internal Flash Driver

Post by FXCoder »

Hi,
First option to try it would be on L4+ but probably 2 weeks before I get to that.
I'll check for differences L4 -> L4+ then and update L4+ .mk etc. accordingly.

Meanwhile, so I can keep up to date with the latest trunk, I added #if (HAL_USE_FLASH) conditionals in hal_flash.c/h and guard in halconf to avoid collision with existing flash driver macro/function names in use on my project.
If you could put those in to trunk it would be helpful.
--
Bob
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Internal Flash Driver

Post by Giovanni »

I just committed more changes and a demo EFL+MFS, please work on the latest version.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Internal Flash Driver

Post by Giovanni »

Just a note regarding the flash drivers.

There is this scenario:
- Program flash.
- Power loss results in ECC on read on next boot.
- CPU gets and NMI as result.

Giovanni
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: Internal Flash Driver

Post by FXCoder »

OK. Noted.
I'm migrating the code to L4+ from F413 and the flash driver is sort of disabled for now.
The flash driver in the F413 version of the project was used to keep log data in internal flash.
I will adopt the new ChibiOS EFL driver system for L4+ as part of the migration and generalization of the code.
It is multi-project so can be built for the L4+, F413, L072 and likely other MCUs.

I found the legacy flash driver (which is still built in the project) collided with ChibiOS hal_flash.h macro flashRead (one extra parameter... offset).
Hence my comment about (HAL_USE_FLASH) conditionals.
I will strip out the old flash driver but just not got to that yet and it didn't break compile until a recent update from trunk was moved into the project.
--
Bob
Post Reply