Skip to content

Commit 49326ad

Browse files
jamikegalak
authored andcommitted
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 <[email protected]>
1 parent 95e5224 commit 49326ad

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

drivers/flash/flash_stm32.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void flash_stm32_flush_caches(struct flash_stm32_priv *p)
9595
static int flash_stm32_read(struct device *dev, off_t offset, void *data,
9696
size_t len)
9797
{
98-
if (!flash_stm32_valid_range(offset, len)) {
98+
if (!flash_stm32_valid_range(offset, len, false)) {
9999
return -EINVAL;
100100
}
101101

@@ -113,7 +113,7 @@ int flash_stm32_erase(struct device *dev, off_t offset, size_t len)
113113
struct flash_stm32_priv *p = dev->driver_data;
114114
int rc;
115115

116-
if (!flash_stm32_valid_range(offset, len)) {
116+
if (!flash_stm32_valid_range(offset, len, true)) {
117117
return -EINVAL;
118118
}
119119

@@ -138,7 +138,7 @@ int flash_stm32_write(struct device *dev, off_t offset,
138138
struct flash_stm32_priv *p = dev->driver_data;
139139
int rc;
140140

141-
if (!flash_stm32_valid_range(offset, len)) {
141+
if (!flash_stm32_valid_range(offset, len, true)) {
142142
return -EINVAL;
143143
}
144144

drivers/flash/flash_stm32.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct flash_stm32_priv {
3030
struct k_sem sem;
3131
};
3232

33-
bool flash_stm32_valid_range(off_t offset, u32_t len);
33+
bool flash_stm32_valid_range(off_t offset, u32_t len, bool write);
3434

3535
int flash_stm32_write_range(unsigned int offset, const void *data,
3636
unsigned int len, struct flash_stm32_priv *p);

drivers/flash/flash_stm32f4x.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
#include <flash_stm32.h>
1515

16-
bool flash_stm32_valid_range(off_t offset, u32_t len)
16+
bool flash_stm32_valid_range(off_t offset, u32_t len, bool write)
1717
{
18+
ARG_UNUSED(write);
1819
return offset >= 0 && (offset + len - 1 <= STM32F4X_FLASH_END);
1920
}
2021

drivers/flash/flash_stm32l4x.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
#define STM32L4X_FLASH_END \
2121
((u32_t)(STM32L4X_BANK_SIZE_MAX << STM32L4X_PAGE_SHIFT) - 1)
2222

23-
/* offset and len must be aligned on 8, positive and not beyond end of flash */
24-
bool flash_stm32_valid_range(off_t offset, u32_t len)
23+
/* offset and len must be aligned on 8 for write
24+
* , positive and not beyond end of flash */
25+
bool flash_stm32_valid_range(off_t offset, u32_t len, bool write)
2526
{
26-
return offset % 8 == 0 &&
27-
len % 8 == 0 &&
28-
offset >= 0 &&
29-
(offset + len - 1 <= STM32L4X_FLASH_END);
27+
return (!write || (offset % 8 == 0 && len % 8 == 0)) &&
28+
offset >= 0 &&
29+
(offset + len - 1 <= STM32L4X_FLASH_END);
3030
}
3131

3232
/* STM32L4xx devices can have up to 512 2K pages on two 256x2K pages banks */

0 commit comments

Comments
 (0)