Skip to content

Conversation

@andysan
Copy link
Contributor

@andysan andysan commented May 12, 2020

Several STM32 chips have identical chip-specific code that has been duplicated in different source files. To avoid adding another nearly identical backend, unify the F0x, F1x, and F3x (some of these only differed in copyright!) to use a single implementation and extend this to support the L0.

Some of the other implementations seem nearly identical as well, so we could likely get rid of the custom G0, G4, L4, and WBX implementation.

Testing: Tested with littlefs example on a b_l072z_lrwan1. Built the flash shell for an stm32f3_disco board. I don't have access to any boards to test the F0, F1, and F3 implementation.

@de-nordic de-nordic self-requested a review June 19, 2020 08:01
@de-nordic
Copy link
Contributor

@andysan Would you comment here: #25947, it seems that L0/L1 flash does not have standard 0xFF erase value.

Copy link
Contributor

@nvlsianpu nvlsianpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks sane to me
Can you align to API changes introduced in #25947 (rebase needed) ?

@erwango erwango requested a review from FRASTM June 22, 2020 15:37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the introduction of #25947 the WRITE_BLOCK_SIZE should be also assigned to flash_parameters.write_block_size , specific for the flash device.

Copy link
Contributor Author

@andysan andysan Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this done already in the #25947? The code looked corrected when I rebased.

Comment on lines 33 to 37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar situation as with WRITE_BLOCK_SIZE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar situation as with WRITE_BLOCK_SIZE

I have updated flash_stm32.c to reflect this.

@Laczen
Copy link
Contributor

Laczen commented Jun 23, 2020

@andysan, from your code I would conclude that the L0/L1 don't have flash but an eeprom instead. If this is the case flash support for these devices is best added as a layer on top of the eeprom driver. Doing it like this would allow support for both a eeprom section and flash section on these devices. Also the flash erase can in that case be implemented as a write of 0xff.

@de-nordic, @nvlsianpu, @pabigot, @carlescufi, the excellent work done in #25947 might have been unnecessary.

@andysan
Copy link
Contributor Author

andysan commented Jun 23, 2020

@andysan, from your code I would conclude that the L0/L1 don't have flash but an eeprom instead. If this is the case flash support for these devices is best added as a layer on top of the eeprom driver. Doing it like this would allow support for both a eeprom section and flash section on these devices. Also the flash erase can in that case be implemented as a write of 0xff.

I think you are right about the L0/L1 using an EEPROM for program memory. However, the manual refers to this as a flash, presumably because it requires explicit erase of 128 byte pages. In practice, that can't be implemented using the EEPROM API.

IMO, the fact that we have different APIs for EEPROMs and FLASH memories is very problematic. It seems like the only real difference between the APIs is that the EEPROM API doesn't support explicit erase. Assuming that only NVMs with implicit erase operations are implemented using the EEPROM API, that's functionally OK. However, many of these devices support explicit erase operations which make future write operations.

@carlescufi
Copy link
Member

@andysan, from your code I would conclude that the L0/L1 don't have flash but an eeprom instead. If this is the case flash support for these devices is best added as a layer on top of the eeprom driver. Doing it like this would allow support for both a eeprom section and flash section on these devices. Also the flash erase can in that case be implemented as a write of 0xff.

@de-nordic, @nvlsianpu, @pabigot, @carlescufi, the excellent work done in #25947 might have been unnecessary.

Maybe we will encounter actual flash devices in the future that do use an erase value different from 0xFF :) we'll be ready for it.

@de-nordic
Copy link
Contributor

Maybe we will encounter actual flash devices in the future that do use an erase value different from 0xFF :) we'll be ready for it.

Or we will end up merging bot APIs under one common for NVM API.

@andysan
Copy link
Contributor Author

andysan commented Jun 23, 2020

Maybe we will encounter actual flash devices in the future that do use an erase value different from 0xFF :) we'll be ready for it.

Or we will end up merging bot APIs under one common for NVM API.

I think that would be ideal. The current approach makes it really annoying to write code that either uses a flash or a data EEPROM since most subsystems seem to use the flash api. I imagine we would currently have to use the EEPROM API for things like FRAM or ReRAM, which seems a bit weird since they aren’t EEPROMs. It would be nice if the api could expose direct access to memory mapped devices as well to avoid additional copying.

@carlescufi
Copy link
Member

IMO, the fact that we have different APIs for EEPROMs and FLASH memories is very problematic. It seems like the only real difference between the APIs is that the EEPROM API doesn't support explicit erase. Assuming that only NVMs with implicit erase operations are implemented using the EEPROM API, that's functionally OK. However, many of these devices support explicit erase operations which make future write operations.

Please feel free to start a proposal to deprecate the EEPROM API and fold it into the flash API. We can continue the conversation there, and then we can bring it up in the API meeting. Thanks!

@de-nordic
Copy link
Contributor

(...) the excellent work done in #25947 might have been unnecessary.

disregarding the "unnecessary", I am happy :)

@Laczen
Copy link
Contributor

Laczen commented Jun 23, 2020

(...) the excellent work done in #25947 might have been unnecessary.

disregarding the "unnecessary", I am happy :)

After reading through some of the stm32 datasheets I can also remove the "unnecessary", the flash on these devices should be considered flash devices with an erase value of 0x00.

Given their properties the flash page size could be defined as either the page size (128 bytes/ 256 bytes) or the sector size (4kB). Probably they are not a good fit for nvs (very slow word writes 3.2ms if the datasheet is correct) and it might be better to define them as flash with a write_block_size of a half page (64 bytes / 128 bytes) and to use them with fcb.

I am also in favour of grouping support of NV devices under a NVM api, it is possible to add the type under nvm_parameters.type, as well as nvm_parameters.auto_erase for devices that do not require an erase.

@erwango erwango self-requested a review June 24, 2020 07:58
Copy link
Contributor

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK

@erwango erwango added the block: HW Test Testing on hardware required before merging label Jun 26, 2020
@erwango
Copy link
Member

erwango commented Jun 26, 2020

@andysan I'll do some testing, but I don't have the boards right now. Should be done next week.

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ok on F0/F1/F3 targets

@erwango erwango removed the block: HW Test Testing on hardware required before merging label Jul 2, 2020
@erwango erwango requested a review from MaureenHelm July 2, 2020 13:11
@erwango
Copy link
Member

erwango commented Jul 2, 2020

BK Failures:
tests/kernel/interrupt/arch.interrupt in qemu_arc_em:tests/kernel/interrupt/arch.interrupt
tests/kernel/interrupt/arch.interrupt in qemu_arc_hs:tests/kernel/interrupt/arch.interrupt

@nvlsianpu
Copy link
Contributor

@erwango @nashif ^^ Are these related to patch?

@erwango
Copy link
Member

erwango commented Jul 2, 2020

@erwango @nashif ^^ Are these related to patch?

@nvlsianpu not at all

andysan added 2 commits July 2, 2020 21:53
Several STM32 chips have identical chip-specific code that has been
duplicated in different source files. Unify the F0x, F1x, and F3x to
use a single implementation.

Signed-off-by: Andreas Sandberg <[email protected]>
Add support for STM32L0X using the generic STM32 backend. This is
quite a significant change since the L0 series uses a slightly
different flash controller. Refactor the generic backend to better
support different block sizes and the L0's register interface.

Signed-off-by: Andreas Sandberg <[email protected]>
@andysan
Copy link
Contributor Author

andysan commented Jul 2, 2020

@erwango @nashif ^^ Are these related to patch?

@nvlsianpu not at all

I just pushed a rebase to trigger a rebuild to make sure it's all clean.

@erwango
Copy link
Member

erwango commented Jul 3, 2020

One new unrelated CI failure:
tests/subsys/logging/log_immediate/logging.log_immediate.clean_output in qemu_arc_hs:tests/subsys/logging/log_immediate/logging.log_immediate

@erwango @nashif ^^ Are these related to patch?

@nvlsianpu not at all

I just pushed a rebase to trigger a rebuild to make sure it's all clean.

One new unrelated CI failure:
tests/subsys/logging/log_immediate/logging.log_immediate.clean_output in qemu_arc_hs:tests/subsys/logging/log_immediate/logging.log_immediate

@nvlsianpu
Copy link
Contributor

@superna9999 @nashif CI failures are not related to PR content. Can this be merged?

@nashif nashif merged commit 69f0e3b into zephyrproject-rtos:master Jul 3, 2020
@andysan andysan deleted the stm32l0-flash branch July 3, 2020 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants