Skip to content

Commit be5d44e

Browse files
niedzwiecki-dawidkartben
authored andcommitted
drivers: flash: stm32: update ex_op API
Use uint64_t instead of uint32_t for the FLASH_STM32_EX_OP_SECTOR_WP extended operation. Some chips have two banks, more than 16 sectors each e.g. stm32h7a3xx chips, so more than 32 bits are required. Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
1 parent 2f2dd94 commit be5d44e

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

drivers/flash/flash_stm32.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ void flash_stm32_page_layout(const struct device *dev,
344344
#if defined(CONFIG_FLASH_STM32_WRITE_PROTECT)
345345

346346
int flash_stm32_update_wp_sectors(const struct device *dev,
347-
uint32_t changed_sectors,
348-
uint32_t protected_sectors);
347+
uint64_t changed_sectors,
348+
uint64_t protected_sectors);
349349

350350
int flash_stm32_get_wp_sectors(const struct device *dev,
351-
uint32_t *protected_sectors);
351+
uint64_t *protected_sectors);
352352
#endif
353353
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION)
354354
uint8_t flash_stm32_get_rdp_level(const struct device *dev);

drivers/flash/flash_stm32_ex_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int flash_stm32_ex_op_sector_wp(const struct device *dev, const uintptr_t in,
2828
(const struct flash_stm32_ex_op_sector_wp_in *)in;
2929
struct flash_stm32_ex_op_sector_wp_out *result =
3030
(struct flash_stm32_ex_op_sector_wp_out *)out;
31-
uint32_t change_mask;
31+
uint64_t change_mask;
3232
int rc = 0, rc2 = 0;
3333
#ifdef CONFIG_USERSPACE
3434
bool syscall_trap = z_syscall_trap();

drivers/flash/flash_stm32f4x.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ uint32_t flash_stm32_option_bytes_read(const struct device *dev)
273273

274274
#if defined(CONFIG_FLASH_STM32_WRITE_PROTECT)
275275
int flash_stm32_update_wp_sectors(const struct device *dev,
276-
uint32_t changed_sectors,
277-
uint32_t protected_sectors)
276+
uint64_t changed_sectors,
277+
uint64_t protected_sectors)
278278
{
279279
changed_sectors <<= FLASH_OPTCR_nWRP_Pos;
280280
protected_sectors <<= FLASH_OPTCR_nWRP_Pos;
@@ -286,12 +286,12 @@ int flash_stm32_update_wp_sectors(const struct device *dev,
286286
/* Sector is protected when bit == 0. Flip protected_sectors bits */
287287
protected_sectors = ~protected_sectors & changed_sectors;
288288

289-
return flash_stm32_option_bytes_write(dev, changed_sectors,
290-
protected_sectors);
289+
return flash_stm32_option_bytes_write(dev, (uint32_t)changed_sectors,
290+
(uint32_t)protected_sectors);
291291
}
292292

293293
int flash_stm32_get_wp_sectors(const struct device *dev,
294-
uint32_t *protected_sectors)
294+
uint64_t *protected_sectors)
295295
{
296296
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
297297

include/zephyr/drivers/flash/stm32_flash_api_extensions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ enum stm32_ex_ops {
6666

6767
#if defined(CONFIG_FLASH_STM32_WRITE_PROTECT)
6868
struct flash_stm32_ex_op_sector_wp_in {
69-
uint32_t enable_mask;
70-
uint32_t disable_mask;
69+
uint64_t enable_mask;
70+
uint64_t disable_mask;
7171
};
7272

7373
struct flash_stm32_ex_op_sector_wp_out {
74-
uint32_t protected_mask;
74+
uint64_t protected_mask;
7575
};
7676
#endif /* CONFIG_FLASH_STM32_WRITE_PROTECT */
7777

tests/drivers/flash/stm32/src/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ static const struct device *const flash_dev = TEST_AREA_DEVICE;
2424

2525
#if defined(CONFIG_FLASH_STM32_WRITE_PROTECT)
2626
static const struct flash_parameters *flash_params;
27-
static uint32_t sector_mask;
27+
static uint64_t sector_mask;
2828
static uint8_t __aligned(4) expected[EXPECTED_SIZE];
2929

3030
static int sector_mask_from_offset(const struct device *dev, off_t offset,
31-
size_t size, uint32_t *mask)
31+
size_t size, uint64_t *mask)
3232
{
3333
struct flash_pages_info start_page, end_page;
3434

@@ -67,15 +67,15 @@ static void *flash_stm32_setup(void)
6767
&sector_mask);
6868
zassert_equal(rc, 0, "Cannot get sector mask");
6969

70-
TC_PRINT("Sector mask for offset 0x%x size 0x%x is 0x%x\n",
70+
TC_PRINT("Sector mask for offset 0x%x size 0x%x is 0x%llx\n",
7171
TEST_AREA_OFFSET, EXPECTED_SIZE, sector_mask);
7272

7373
/* Check if region is not write protected. */
7474
rc = flash_ex_op(flash_dev, FLASH_STM32_EX_OP_SECTOR_WP,
7575
(uintptr_t)NULL, &wp_status);
7676
zassert_equal(rc, 0, "Cannot get write protect status");
7777

78-
TC_PRINT("Protected sectors: 0x%x\n", wp_status.protected_mask);
78+
TC_PRINT("Protected sectors: 0x%llx\n", wp_status.protected_mask);
7979

8080
/* Remove protection if needed. */
8181
if (wp_status.protected_mask & sector_mask) {

0 commit comments

Comments
 (0)