[Flash Driver] Implementation guidelines request

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.
bash
Posts: 3
Joined: Fri Dec 16, 2016 12:34 pm
Been thanked: 1 time

[Flash Driver] Implementation guidelines request

Postby bash » Fri Dec 16, 2016 5:12 pm

Hi,
I'm trying to create an open source bootloader with USB-DFU HID capability using ChibiOS/RT.

Actually (on a STM32F103xB) I can read/write internal flash partition using ST "STM32F10x standard peripheral library".

I would like to contribute with ChibiOS by implementing a Flash Driver for HAL; I read the following threads but I don't know how to start.

Could you help me to choose files, interfaces, and methods that I should implent?

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

Re: [Flash Driver] Implementation guidelines request

Postby Giovanni » Fri Dec 16, 2016 6:16 pm

Hi,

A flash driver should implement the "interface" defined in \os\hal\lib\peripherals\flash\hal_flash.h.

Note that the interface is new and could change based on feedback. Post your questions in this thread.

Giovanni

bash
Posts: 3
Joined: Fri Dec 16, 2016 12:34 pm
Been thanked: 1 time

Re: [Flash Driver] Implementation guidelines request

Postby bash » Fri Jan 13, 2017 12:10 pm

Hi,

sorry for delay, but I've been busy.

attached you can find a draft of FlashDriver that I will implement when you confirm the structure.

I added these files:
  • os/hal/ports/STM32/STM32F1xx/hal_flash_lld.c
  • os/hal/ports/STM32/STM32F1xx/hal_flash_lld.h
  • os/hal/src/hal_iflash.c
  • os/hal/include/hal_iflash.h

hal_flash_lld, only for STM32F1xx, implements all methods exposed by hal_flash class.
Then it exports init, start and stop functions in order to align with other LLD.
Anyway I think internal flash is always "started", so only init function is necessary in order to initialize internal structures; start and stop functions could be removed ??

hal_iflash (I don't know how to call, because hal_flash was already present) provides FlashDriver structure with filled VMT.

I also modified these files:
  • os/hal/hal.mk
  • os/hal/include/hal.h
  • os/hal/ports/STM32/STM32F1xx/platform.mk
  • os/hal/src/hal.c

Do you approve this structure? Should I modify something before proceed?
Attachments
hal_flash.tgz
HAL flash driver draft
(5.36 KiB) Downloaded 163 times

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

Re: [Flash Driver] Implementation guidelines request

Postby Giovanni » Fri Jan 13, 2017 1:07 pm

Hi,

Thanks for the code, I am in the middle of merging other things so this will go in queue.

I see a problem with hal_iflash being added as an HAL generic driver, that would force me to update all halconf.h files in all (internal and external) demos and we are late in this development cycle. Release is supposed to be 17.2.

Probably it would be better to make a device-specific mini driver placed inside the various STM32 directories and named stm32_iflash.c/.h. Alternatively we could create FLASHv1, FLASHv2 etc under STM32/LLD if some of those drivers could be shared between multiple STM32s.

The flash object could be constant and static unless you have variable data there, start/stop functions could be omitted. Inclusion would be made in the makefile.

In the next HAL we may discuss an high level flash module in the HAL.

Giovanni

bash
Posts: 3
Joined: Fri Dec 16, 2016 12:34 pm
Been thanked: 1 time

Re: [Flash Driver] Implementation guidelines request

Postby bash » Fri Jan 20, 2017 11:14 am

Hi,

attached you can find a working flash driver for STM32F1xx.

Based on ST's PM0075 programming manual, it does not currently support bank2 of STM32F1xx_XL devices.
A warning is generated at compile time.

I modified STM32F1xx/platform.mk only into USE_SMART_BUILD section and the driver could be enabled by adding
UDEFS += -DHAL_USE_FLASH=TRUE in project Makefile.
Is it ok?


Could you explain me this sentence?
Giovanni wrote:The flash object could be constant and static unless you have variable data there [...]

Other LLD drivers are not static because they are global variables. How could I set static FlashDriver instance?
Then FlashDriver could not be const because the driver needs flash_state_t state variable.


At this time it is not thread safe. Is it mandatory to have thread safeness for all drivers?


I suggest to export lock/unlock interface to hal_flash.h because these functions are invoked at every erase/program calls.
Instead a possible workflow could be (1)unlock flash, (2) erase page, (3) program page, repeat (2) and (3) for every pages in flash and, at last, (4) lock flash.
What do you think?


Edited:
I changed the attachment in order to align with new ChibiOS commits.
Attachments
FLASHv1_r2.tgz
(3.72 KiB) Downloaded 189 times

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

Re: [Flash Driver] Implementation guidelines request

Postby Giovanni » Fri Jan 20, 2017 1:15 pm

Hi,

Looks good, just one thing I noticed is that the driver is not able to suspend erase but the capability bit is set, a minor thing.

Lets wait for feedback.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 65 guests