Skip to content

Commit 1808443

Browse files
committed
drivers: flash: stm32 ospi flash driver get base address from DTS
Use the device tree to define the external NOR flash base address Put this as a field of the device configuration structure. Signed-off-by: Francois Ramu <[email protected]>
1 parent 7a48812 commit 1808443

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

drivers/flash/flash_stm32_ospi.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ LOG_MODULE_REGISTER(flash_stm32_ospi, CONFIG_FLASH_LOG_LEVEL);
4242

4343
#define STM32_OSPI_USE_DMA DT_NODE_HAS_PROP(STM32_OSPI_NODE, dmas)
4444

45-
/* The Base Address of the octo spi chosen by the Flash controller */
46-
#define STM32_NOR_FLASH_BASE_ADDRESS OCTOSPI2_BASE
47-
4845
#if STM32_OSPI_USE_DMA
4946
#include <zephyr/drivers/dma/dma_stm32.h>
5047
#include <zephyr/drivers/dma.h>
@@ -138,6 +135,7 @@ struct flash_stm32_ospi_config {
138135
const struct stm32_pclken pclken_mgr; /* clock subsystem */
139136
#endif
140137
irq_config_func_t irq_config;
138+
uint32_t flash_base_address;
141139
size_t flash_size;
142140
uint32_t max_frequency;
143141
int data_mode; /* SPI or QSPI or OSPI */
@@ -1283,9 +1281,10 @@ static int flash_stm32_ospi_read(const struct device *dev, off_t addr,
12831281
#ifdef CONFIG_STM32_XIP
12841282
if (stm32_ospi_is_memorymapped(dev)) {
12851283
LOG_DBG("MemoryMapped Read offset: 0x%lx, len: %zu",
1286-
(long)(STM32_NOR_FLASH_BASE_ADDRESS + addr),
1284+
(long)(dev_cfg->flash_base_address + addr),
12871285
size);
1288-
memcpy(data, (uint8_t *)STM32_NOR_FLASH_BASE_ADDRESS + addr, size);
1286+
1287+
memcpy(data, (uint8_t *)dev_cfg->flash_base_address + addr, size);
12891288

12901289
return 0;
12911290
}
@@ -1382,9 +1381,10 @@ static int flash_stm32_ospi_write(const struct device *dev, off_t addr,
13821381
#ifdef CONFIG_STM32_XIP
13831382
if (stm32_ospi_is_memorymapped(dev)) {
13841383
LOG_DBG("MemoryMapped Write offset: 0x%lx, len: %zu",
1385-
(long)(STM32_NOR_FLASH_BASE_ADDRESS + addr),
1384+
(long)(dev_cfg->flash_base_address + addr),
13861385
size);
1387-
memcpy((uint8_t *)STM32_NOR_FLASH_BASE_ADDRESS + addr, data, size);
1386+
1387+
memcpy((uint8_t *)dev_cfg->flash_base_address + addr, data, size);
13881388

13891389
return 0;
13901390
}
@@ -2400,11 +2400,18 @@ static int flash_stm32_ospi_init(const struct device *dev)
24002400
#ifdef CONFIG_STM32_XIP
24012401
/* Now configure the octo Flash in MemoryMapped (access by address) */
24022402
ret = stm32_ospi_set_memorymap(dev);
2403+
24032404
if (ret != 0) {
24042405
LOG_ERR("Error (%d): setting NOR in MemoryMapped mode", ret);
24052406
return -EINVAL;
24062407
}
2407-
LOG_INF("NOR in MemoryMapped mode");
2408+
if ((dev_cfg->flash_base_address == 0) || (dev_cfg->flash_size == 0)) {
2409+
LOG_ERR("Error wrong NOR base address/size");
2410+
return -EINVAL;
2411+
}
2412+
LOG_INF("NOR in MemoryMapped mode at 0x%x (0x%x bytes)",
2413+
dev_cfg->flash_base_address,
2414+
dev_cfg->flash_size);
24082415

24092416
#endif /* CONFIG_STM32_XIP */
24102417
return 0;
@@ -2472,7 +2479,8 @@ static const struct flash_stm32_ospi_config flash_stm32_ospi_cfg = {
24722479
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_OSPI_NODE, ospi_mgr, bits)},
24732480
#endif
24742481
.irq_config = flash_stm32_ospi_irq_config_func,
2475-
.flash_size = DT_INST_PROP(0, size) / 8U,
2482+
.flash_base_address = DT_REG_ADDR(DT_INST(0, st_stm32_ospi_nor)),
2483+
.flash_size = DT_REG_ADDR_BY_IDX(DT_INST(0, st_stm32_ospi_nor), 1),
24762484
.max_frequency = DT_INST_PROP(0, ospi_max_frequency),
24772485
.data_mode = DT_INST_PROP(0, spi_bus_width), /* SPI or OPI */
24782486
.data_rate = DT_INST_PROP(0, data_rate), /* DTR or STR */

dts/bindings/flash_controller/st,stm32-ospi-nor.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ on-bus: ospi
2525
properties:
2626
reg:
2727
required: true
28+
description: Flash Memory base address and size in bytes
2829
ospi-max-frequency:
2930
type: int
3031
required: true
3132
description: Maximum clock frequency of device's OSPI interface in Hz
32-
size:
33-
required: true
34-
description: Flash Memory size in bits
3533
reset-gpios:
3634
type: phandle-array
3735
description: RESETn pin

0 commit comments

Comments
 (0)