Skip to content

Commit 7f13961

Browse files
wmrsouzakartben
authored andcommitted
soc: esp32: replace hard-coded addresses and sizes by DT macros
Replaces hard-coded memory addresses and sizes with macros that retrieve such values from the device tree. Signed-off-by: Marcio Ribeiro <[email protected]>
1 parent 98277c9 commit 7f13961

File tree

6 files changed

+35
-34
lines changed

6 files changed

+35
-34
lines changed

soc/espressif/esp32/memory.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
#pragma once
66

77
/* SRAM0 (192kB) instruction cache+memory */
8-
#define SRAM0_IRAM_START 0x40070000
8+
#define SRAM0_IRAM_START DT_REG_ADDR(DT_NODELABEL(sram0))
99
#define SRAM0_CACHE_SIZE 0x10000
10-
#define SRAM0_SIZE 0x30000
10+
#define SRAM0_SIZE DT_REG_SIZE(DT_NODELABEL(sram0))
1111

1212
/* SRAM1 (128kB) instruction/data memory */
13-
#define SRAM1_IRAM_START 0x400a0000
14-
#define SRAM1_DRAM_START 0x3ffe0000
15-
#define SRAM1_SIZE 0x20000
16-
#define SRAM1_DRAM_END (SRAM1_DRAM_START + SRAM1_SIZE)
13+
#define SRAM1_IRAM_START (SRAM0_IRAM_START + SRAM0_SIZE)
14+
#define SRAM1_DRAM_START DT_REG_ADDR(DT_NODELABEL(sram1))
15+
#define SRAM1_SIZE DT_REG_SIZE(DT_NODELABEL(sram1))
16+
#define SRAM1_DRAM_END (SRAM1_DRAM_START + SRAM1_SIZE)
1717
#define SRAM1_DRAM_PROAPP_PRIV_SIZE 0x8000
18-
#define SRAM1_DRAM_USER_START 0x3ffe8000
19-
#define SRAM1_USER_SIZE (0x40000000 - SRAM1_DRAM_USER_START)
18+
#define SRAM1_DRAM_USER_START (SRAM1_DRAM_START + SRAM1_DRAM_PROAPP_PRIV_SIZE)
19+
#define SRAM1_USER_SIZE (0x40000000 - SRAM1_DRAM_USER_START)
2020

2121
/* SRAM2 (200kB) data memory */
22-
#define SRAM2_DRAM_START 0x3ffae000
23-
#define SRAM2_DRAM_SIZE 0x32000
22+
#define SRAM2_DRAM_START DT_REG_ADDR(DT_NODELABEL(sram2))
23+
#define SRAM2_DRAM_SIZE DT_REG_SIZE(DT_NODELABEL(sram2))
2424
#define SRAM2_DRAM_SHM_SIZE 0x2000
2525
#define SRAM2_DRAM_END (SRAM2_DRAM_START + SRAM2_DRAM_SIZE)
2626
#define SRAM2_DRAM_USER_START (SRAM2_DRAM_START + SRAM2_DRAM_SHM_SIZE)
@@ -46,6 +46,7 @@
4646
/* Convert IRAM address to its DRAM counterpart in SRAM1 memory */
4747
#define SRAM1_IRAM_DRAM_CALC(addr_iram) ((addr_iram > SRAM1_IRAM_START) ? \
4848
(SRAM1_SIZE - (addr_iram - SRAM1_IRAM_START) + SRAM1_DRAM_START) : (SRAM1_DRAM_END))
49+
4950
/* Convert DRAM address to its IRAM counterpart in SRAM1 memory */
5051
#define SRAM1_DRAM_IRAM_CALC(addr_dram) \
5152
(SRAM1_SIZE - (addr_dram - SRAM1_DRAM_START) + SRAM1_IRAM_START)

soc/espressif/esp32c2/memory.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#pragma once
66

77
/* SRAM0 (16kB) memory */
8-
#define SRAM0_IRAM_START 0x4037c000
9-
#define SRAM0_SIZE 0x4000
8+
#define SRAM0_IRAM_START DT_REG_ADDR(DT_NODELABEL(sram0))
9+
#define SRAM0_SIZE DT_REG_SIZE(DT_NODELABEL(sram0))
1010

1111
/* SRAM1 (256kB) memory */
12-
#define SRAM1_DRAM_START 0x3fca0000
13-
#define SRAM1_IRAM_START 0x40380000
14-
#define SRAM1_SIZE 0x40000
12+
#define SRAM1_IRAM_START (SRAM0_IRAM_START + SRAM0_SIZE)
13+
#define SRAM1_DRAM_START DT_REG_ADDR(DT_NODELABEL(sram1))
14+
#define SRAM1_SIZE DT_REG_SIZE(DT_NODELABEL(sram1))
1515

1616
/* ICache size is fixed to 16KB on ESP32-C2 */
1717
#define ICACHE_SIZE SRAM0_SIZE

soc/espressif/esp32c3/memory.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#pragma once
66

77
/* SRAM0 (16kB) memory */
8-
#define SRAM0_IRAM_START 0x4037c000
9-
#define SRAM0_SIZE 0x4000
8+
#define SRAM0_IRAM_START DT_REG_ADDR(DT_NODELABEL(sram0))
9+
#define SRAM0_SIZE DT_REG_SIZE(DT_NODELABEL(sram0))
1010
/* SRAM1 (384kB) memory */
11-
#define SRAM1_DRAM_START 0x3fc80000
12-
#define SRAM1_IRAM_START 0x40380000
13-
#define SRAM1_SIZE 0x60000
11+
#define SRAM1_DRAM_START DT_REG_ADDR(DT_NODELABEL(sram1))
12+
#define SRAM1_IRAM_START (SRAM0_IRAM_START + SRAM0_SIZE)
13+
#define SRAM1_SIZE DT_REG_SIZE(DT_NODELABEL(sram1))
1414
/* ICache size is fixed to 16KB on ESP32-C3 */
1515
#define ICACHE_SIZE SRAM0_SIZE
1616

soc/espressif/esp32c6/memory.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#pragma once
66

77
/* LP-SRAM (16kB) memory */
8-
#define LPSRAM_IRAM_START 0x50000000
9-
#define LPSRAM_SIZE 0x4000
8+
#define LPSRAM_IRAM_START DT_REG_ADDR(DT_NODELABEL(sramlp))
9+
#define LPSRAM_SIZE DT_REG_SIZE(DT_NODELABEL(sramlp))
1010
/* HP-SRAM (512kB) memory */
11-
#define HPSRAM_START 0x40800000
12-
#define HPSRAM_SIZE 0x80000
13-
#define HPSRAM_DRAM_START 0x40800000
14-
#define HPSRAM_IRAM_START 0x40800000
11+
#define HPSRAM_START DT_REG_ADDR(DT_NODELABEL(sramhp))
12+
#define HPSRAM_SIZE DT_REG_SIZE(DT_NODELABEL(sramhp))
13+
#define HPSRAM_DRAM_START HPSRAM_START
14+
#define HPSRAM_IRAM_START HPSRAM_START
1515
/* ICache size is fixed to 32KB on ESP32-C6 */
1616
#define ICACHE_SIZE 0x8000
1717

soc/espressif/esp32s2/memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
/* SRAM0 (32k) with adjacted SRAM1 (288k)
88
* Ibus and Dbus address space
99
*/
10-
#define SRAM_IRAM_START 0x40020000
11-
#define SRAM_DRAM_START 0x3ffb0000
10+
#define SRAM_IRAM_START (SRAM_DRAM_START + IRAM_DRAM_OFFSET)
11+
#define SRAM_DRAM_START DT_REG_ADDR(DT_NODELABEL(sram0))
1212
#define SRAM_CACHE_SIZE (CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE + CONFIG_ESP32S2_DATA_CACHE_SIZE)
1313

1414
/** Simplified memory map for the bootloader.

soc/espressif/esp32s3/memory.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
/* SRAM0 (32k), SRAM1 (416k), SRAM2 (64k) memories
88
* Ibus and Dbus address space
99
*/
10-
#define SRAM0_IRAM_START 0x40370000
11-
#define SRAM0_SIZE 0x8000
12-
#define SRAM1_DRAM_START 0x3fc88000
13-
#define SRAM1_IRAM_START 0x40378000
10+
#define SRAM0_IRAM_START DT_REG_ADDR(DT_NODELABEL(sram0))
11+
#define SRAM0_SIZE DT_REG_SIZE(DT_NODELABEL(sram0))
12+
#define SRAM1_DRAM_START DT_REG_ADDR(DT_NODELABEL(sram1))
13+
#define SRAM1_IRAM_START (SRAM0_IRAM_START + SRAM0_SIZE)
1414
#define SRAM_USER_IRAM_START (SRAM0_IRAM_START + CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE)
1515

16-
#define SRAM2_DRAM_START 0x3fcf0000
17-
#define SRAM2_SIZE 0x10000
16+
#define SRAM2_DRAM_START DT_REG_ADDR(DT_NODELABEL(sram2))
17+
#define SRAM2_SIZE DT_REG_SIZE(DT_NODELABEL(sram2))
1818
#define SRAM2_USER_DRAM_START (SRAM2_DRAM_START + CONFIG_ESP32S3_DATA_CACHE_SIZE)
1919
#define SRAM2_USER_DRAM_SIZE (SRAM2_SIZE - CONFIG_ESP32S3_DATA_CACHE_SIZE)
2020

0 commit comments

Comments
 (0)