Commit graph

38 commits

Author SHA1 Message Date
Francois Ramu 7795558ad5 drivers: flash: stm32 flash base address from the DTS node
For the flash driver, the base address is the MCU internal flash
address (usually 0x8000000). This PR gets the that address
from the device tree node "st,stm32-nv-flash"
instead of relying on the CONFIG_FLASH_BASE_ADDRESS
which might differ when building for another flash memory.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2024-01-29 14:12:47 -06:00
Florian Vaussard 199486546a drivers: flash: stm32l5: use write-block-size when validating
STM32L5 have a write block size of 8, but STM32U5 and STM32H5 have a
write block size of 16. Use write-block-size from the device tree
instead of hardcoding this value when validating the range of write
operations.

Fixes #60724

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2023-07-28 09:02:17 +00:00
Guillaume Gautier cbf9f3d4c2 drivers: flash: stm32: add stm32wba support
Add Flash STM32WBA support

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2023-07-11 15:05:05 +02:00
Patryk Duda 417368e63d drivers: flash: Add support for defining custom RDP1 byte value
This patch makes possible to choose custom byte which should be used
to enable non-permanent readout protection (RDP1). Actually, any byte
except 0xAA and 0xCC (which are used by RDP0 and RDP2 respectively)
can be used to enable RDP1 but in multi-image environment, some other
image could check if RDP1 is enabled by comparing it to some hardcoded
value.

If property is not defined, 0x55 will be used to enable RDP1. The
default value comes from STM32 HAL.

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-03-28 15:43:16 +00:00
Patryk Duda d652da5acb drivers: flash: Introduce readout protection support for STM32F4
This patch adds flash readout protection support for STM32F4 devices
family. These devices can enable protection on entire flash content.

Readout protection functionality was exposed as vendor extended
operation. To change readout protection state, caller should provide a
structure which describes desired RDP state.

Enabling readout protection permanently or disabling readout protection
(changing from level 1 to level 0) is guarded by
CONFIG_FLASH_STM32_READOUT_PROTECTION_PERMANENT_ALLOW and
CONFIG_FLASH_STM32_READOUT_PROTECTION_DISABLE_ALLOW respectively.

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-03-28 15:43:16 +00:00
Patryk Duda b6078cc906 drivers: flash: Introduce write protection support for STM32F4
This patch adds sector write protection support for STM32F4 devices
family. These devices can protect flash content with sector precision.

Write protection functionality was exposed as vendor extended operation.
To change write protection state, caller should provide mask of enabled
and disabled sectors.

Function responsible for locking/unlocking option bytes was implemented
for all STM32 devices supported by this driver.

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-03-28 15:43:16 +00:00
Francois Ramu a62fc404be drivers: flash: stm32 flash drivers supports the new stm32h5 serie
Introduce the stm32h5 serie to the the existing flash driver
It is based on the stm32l5 model.
 Add a function to check if the flash is in dual
or single bank mode.
Some stm32 devices can map 2 or 1 flash banks.
Adapt the FLASH register names for the stm32h5 mcu.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2023-03-28 15:07:51 +02:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Francois Ramu bf49a04dcf drivers: flash: stm32 definition of all registered bitfield
redefine all the stm32 flash register bit Name from
FLASH_NSCR_xxx to FLASH_STM32_FLASH_NSCR_xxx
in all the zephyr drivers.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-04-13 13:55:34 -07:00
Francois Ramu 269adf5ca8 drivers: flash stm32 flash driver includes stm32u5 serie
This adds the stm32U5 soc family to the flash driver
The flash controller has particular register names in the Non-Secure
area to be adapted for the driver.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-04-13 13:55:34 -07:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00
Thomas Stranger 4c862c14c1 drivers: flash: stm32: wait for CFGBSY & BSY2 in wait_flash_idle
Some series (namely g0, u5, wb, wl, ?) use CFGBSY to indicate
that FLASH_CR is not ready to be modfied.

This commit adds this flag additionally to other the flash busy flags,
in flash_stm32_wait_flash_idle such that the driver waits before
trying to modify PG, PNB[6:0], PER, and MER bits in FLASH_CR.

Additionally, dual bank variants of STM32G0 have a seperarate BSY2 flag
for flash bank two.
Until now this was not yet checked in flash_stm32_wait_flash_idle.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2021-11-17 11:06:59 -05:00
Thomas Stranger f15f9dfd72 flash: stm32: fix g0 error flags and move ifdef-ery to header
In STM32G0 HAL FLASH_FLAG_xxx defines don't follow the pattern of
other Series to simply redefine the FLASH_SR_xxx Msk.
Instead an ID for the SR reg and the position of the Error flag
are defined.

As a result error checking in flash_stm32_check_status was not working
until this fix on stm32g0 series.

In order to avoid complexity in the driver, the ifdef-ery of the flags
was moved to the header file.
Other series except g0 use FLASH_FLAG_xxx defines, because those
are valid for both cores in dual core(wl) and in secure/non-secure
targets(l5,u5).
FLASH_STM32_SR_ERRORS mask is introduced to check for any active error
in the SR.

The flags for SIZERR, MISERR, FASTERR are newly introduced.
the latter two are only required once fast programming is used,
which is not yet the case for any series.

The FLASH_SR_OPTVERR flag (option validity flag) is also present
in the SR, but is not added.
Also ecc errors are generally not checked, but these are in a different
register.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2021-11-17 11:06:59 -05:00
Thomas Stranger 519f5ffcde drivers: flash: stm32: mv security-mode dependent defines to header
An attempt to simplify the ifdef-ery around FLASH_SR is made.
Define Registers and flags in the header file instead of including
several individual operations in the driver.

FLASH_FLAG_BSY is not only defined for STM32L5, but also other series.
Therefore use this flag instead of FLASH_SR_BSY.
Only the g0 series definition is not valid in our context,
therefore use FLASH_SR_BSY1 instead.

No functional changes, only refactoring.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2021-11-17 11:06:59 -05:00
Thomas Stranger 859b6d5bfe drivers/flash: STM32: Fix flash_stm32_priv definition for h7 series
This commit fixes missing pclken member if used for h7 series.
Additionally to the check if instance 0 of compatible
st_stm32_flash_controller has defined a clock,
this needs to be checked for compatible st_stm32h7_flash_controller.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2021-04-28 09:06:42 -05:00
Krishna Mohan Dani 3374bc128a drivers/flash: STM32: Getting clock settings from DT.
This commit uses DT APIs to get the flash clock settings.

Signed-off-by: Krishna Mohan Dani <krishnamohan.d@hcl.com>
2021-04-23 14:59:06 +02:00
Nicolas VINCENT 5b463353d7 drivers/flash: add support for stm32h7 devices
Fixes #29831: Implements flash driver for stm32h7 devices.
The driver is independant from the other stm32 families (flash_stm32.c),
only the header interface is (mainly) common.

Signed-off-by: Nicolas VINCENT <nicolas.vincent@vossloh.com>
2020-12-14 16:47:05 +01:00
Anas Nashif 2a19ad8068 Revert "drivers/flash: add support for stm32h7 devices"
This reverts commit 0964331df2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-07 19:02:48 -05:00
Nicolas VINCENT 0964331df2 drivers/flash: add support for stm32h7 devices
Fixes #29831: Implements flash driver for stm32h7 devices.
The driver is independant from the other stm32 families (flash_stm32.c),
only the header interface is (mainly) common.

Signed-off-by: Nicolas VINCENT <nicolas.vincent@vossloh.com>
2020-12-07 16:16:11 -05:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka 98d9b01322 device: Apply driver_api/data attributes rename everywhere
Via coccinelle:

@r_device_driver_api_and_data_1@
struct device *D;
@@
(
D->
-	driver_api
+	api
|
D->
-	driver_data
+	data
)

@r_device_driver_api_and_data_2@
expression E;
@@
(
net_if_get_device(E)->
-	driver_api
+	api
|
net_if_get_device(E)->
-	driver_data
+	data
)

And grep/sed rules for macros:

git grep -rlz 'dev)->driver_data' |
	xargs -0 sed -i 's/dev)->driver_data/dev)->data/g'

git grep -rlz 'dev->driver_data' |
	xargs -0 sed -i 's/dev->driver_data/dev->data/g'

git grep -rlz 'device->driver_data' |
	xargs -0 sed -i 's/device->driver_data/device->data/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Andreas Sandberg 69f0e3b15f drivers: flash: Add support for STM32L0X
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 <andreas@sandberg.pp.se>
2020-07-03 08:05:03 -04:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Sarvesh Patkar 4f2c107389 drivers: flash: stm32: Update flash driver implementation
Remove soc/arm/st_stm32/stm32YY/flash_registers.h files.
Change register accesses in stm32 flash drivers to use FLASH_TypeDef
from modules/hal/stm32/stm32cube/stm32YYxx/soc/stm32xxxxxx.h.

Fixes #16235

Signed-off-by: Sarvesh Patkar <psarvesh314@gmail.com>
2020-01-28 15:30:12 -06:00
Peter Bigot 0b0d2e640b treewide: use full path to clock_control/stm32_clock_control.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
Feng Cheng ee57c8e749 drivers: flash: Add the flash driver of the stm32f1x family
Most of the code is copied from the stm32f0x family
Tested on stm32f103ze soc

Signed-off-by: Feng Cheng <i@fengch.me>
2019-12-11 12:40:33 -06:00
Richard Osterloh c68e027c28 drivers: flash: Add STM32G4X flash support
Add flash driver support for STM32G4X SoC series.

Signed-off-by: Richard Osterloh <richard.osterloh@gmail.com>
2019-10-04 18:44:24 -07:00
Francois Ramu bfc2ea6dd5 drivers: flash: Add STM32G0XX flash support
Add flash support for STM32G0X SoC series.

Signed-off-by: Philippe Retornaz <philippe@shapescale.com
Signed-off-by: Francois Ramu <francois.ramu@st.com>
2019-07-05 10:35:55 -05:00
Anas Nashif 17ddd1714c cleanup: include/: move clock_control.h to drivers/clock_control.h
move clock_control.h to drivers/clock_control.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Erwan Gouriou d777413b19 drivers/flash: stm32wb: Add driver for stm32wb
Add flash driver for stm32wb

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-03 09:38:19 -04:00
Erwan Gouriou 82403f68e2 drivers/flash: Move STM32F3 to generic STM32 series driver
A common driver is shared between stm32 chips, which was not the case
for stm32f3 series. As a consequence stm32f3 was not maintained
equally and was missing features such as flash layout or dts based
configuration.
Besides, drivers had some flows such as wrong bus clock and
missing HSI clock activation which lead to issues on boards not
using HSI as main clock.
As a consequence this commit moves stm32f3 series flash driver to
common stm32 flash drivers.

Fixes #4197

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-02-19 07:45:50 -06:00
Aurelien Jarno 6752b5df3f drivers: flash: add driver for STM32F7x series
This patch adds a flash driver for the STM32F7x series, inspired from
the STM32F4x one. It has been tested on the STM32F723, but should also
work on other SoCs of the family.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-17 08:15:59 -06:00
Flavio Ceolin 67ca176754 headers: Fix headers across the project
Any word started with underscore followed by and uppercase letter or a
second underscore is a reserved word according with C99.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-17 15:49:26 -04:00
Neil Armstrong 32cb3f0220 flash: stm32: add support for STM32F0 flash controller
Add the STM32F0 Embedded Flash support in the flash_stm32 driver
interface.
The STM32F0 has a particularity or use the HSI as clock source
for the flash controller interface, so this clock must be
enabled directly in the case HSE or another clock is used by
the system clock.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2017-12-12 12:36:08 -06:00
Marti Bolivar 32482e9cb8 flash: stm32: stm32f4: add page layout support
Add flash page layout support for STM32F4 SoCs.

This almost eliminates the need for flash_map.h, except for
STM32F4X_SECTOR_MASK, so delete the file and move the define into the
F4 implementation, to keep things simple.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-09-11 11:41:57 -04:00
Marti Bolivar 4fea6dfe76 flash: stm32: clean up L4/F4 internal API
This is a prep work commit for adding flash page layout support.

The internal flash APIs for STM32 on L4 and F4 are a bit
inconsistent. Some routines take a pointer to the private data, others
don't. Those that do take it as a last argument instead of a
first. Additionally, some APIs are declared in flash_stm32.h that
aren't ever used by the family-specific files.

Clean this up by making everything take a struct device*, and marking
routines static in the common driver code when possible.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-09-11 11:41:57 -04:00
Michel Jaouen e9153979f0 flash: stm32: distinguish read/write for flash range valid
L4 write access requires 64 bits alignment
while L4 read access does not require any alignment.
To support specific check according to read/write,erase
a parameter is added to stm32_valid_range.

Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
2017-06-16 16:18:12 -04:00
Neil Armstrong a9183cd518 flash: Rework and add flash device support for STM32L4x SoCs
The STM32L4x SoCs embeds a slightly different embedded flash controller
from the STM32F4x SoCs.

This particular controller has the following properties :
 - Up to 2 512KiB banks divided in 2KiB pages
 - Flash can be accessed in any sizes
 - Flash must be written in 64bit aligned 64bit double-words

The drivers/flash/flash_stm32f4x.c is refactored into a new common
drivers/flash/flash_stm32.c and drivers/flash/flash_stm32l4x.c is
created with the STM32L4x specific functions.

To ease the refactoring and keep common functions, the STM32L4x flash
headers are slightly modified to match the hardware reference naming
and solve compilation issues.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2017-05-19 10:06:48 -04:00