Skip to content

Commit 111ba5b

Browse files
committed
trax: Adds ESP32-S3 support
1 parent 5911eb3 commit 111ba5b

File tree

14 files changed

+160
-145
lines changed

14 files changed

+160
-145
lines changed

components/app_trace/Kconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ menu "Application Level Tracing"
1818

1919
config APPTRACE_DEST_TRAX
2020
bool
21-
depends on IDF_TARGET_ARCH_XTENSA && !ESP32_TRAX && !ESP32S2_TRAX
21+
depends on IDF_TARGET_ARCH_XTENSA && !ESP32_TRAX && !ESP32S2_TRAX && !ESP32S3_TRAX
2222
select ESP32_MEMMAP_TRACEMEM
2323
select ESP32S2_MEMMAP_TRACEMEM
24+
select ESP32S3_MEMMAP_TRACEMEM
2425
select ESP32_MEMMAP_TRACEMEM_TWOBANKS
2526
select ESP32S2_MEMMAP_TRACEMEM_TWOBANKS
27+
select ESP32S3_MEMMAP_TRACEMEM_TWOBANKS
2628
default n
2729
help
2830
Enables/disable TRAX tracing HW.

components/app_trace/port/xtensa/port.c

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@
149149
#include "sdkconfig.h"
150150
#include "soc/soc.h"
151151
#include "soc/dport_access.h"
152-
#if CONFIG_IDF_TARGET_ESP32
153152
#include "soc/dport_reg.h"
154-
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
153+
#include "soc/tracemem_config.h"
154+
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
155155
#include "soc/sensitive_reg.h"
156156
#endif
157157
#include "eri.h"
@@ -160,50 +160,6 @@
160160
#include "esp_app_trace_membufs_proto.h"
161161
#include "esp_app_trace_port.h"
162162

163-
// TODO: move these (and same definitions in trax.c to dport_reg.h)
164-
#if CONFIG_IDF_TARGET_ESP32
165-
#define TRACEMEM_MUX_PROBLK0_APPBLK1 0
166-
#define TRACEMEM_MUX_BLK0_ONLY 1
167-
#define TRACEMEM_MUX_BLK1_ONLY 2
168-
#define TRACEMEM_MUX_PROBLK1_APPBLK0 3
169-
#define TRACEMEM_BLK0_ADDR 0x3FFFC000UL
170-
#define TRACEMEM_BLK1_ADDR 0x3FFF8000UL
171-
#elif CONFIG_IDF_TARGET_ESP32S2
172-
#define TRACEMEM_MUX_BLK0_NUM 19
173-
#define TRACEMEM_MUX_BLK1_NUM 20
174-
#define TRACEMEM_BLK_NUM2ADDR(_n_) (0x3FFB8000UL + 0x4000UL*((_n_)-4))
175-
#define TRACEMEM_BLK0_ADDR TRACEMEM_BLK_NUM2ADDR(TRACEMEM_MUX_BLK0_NUM)
176-
#define TRACEMEM_BLK1_ADDR TRACEMEM_BLK_NUM2ADDR(TRACEMEM_MUX_BLK1_NUM)
177-
#elif CONFIG_IDF_TARGET_ESP32S3
178-
#define TRACEMEM_MUX_BLK0_NUM 22
179-
#define TRACEMEM_MUX_BLK0_ALLOC 0x0
180-
#define TRACEMEM_MUX_BLK1_NUM 23
181-
#define TRACEMEM_MUX_BLK1_ALLOC 0x1
182-
183-
#define TRACEMEM_CORE0_MUX_BLK_BIT(_n_, _a_) (BIT(((_n_)-2UL)/4UL) | ((_a_) << 14))
184-
#define TRACEMEM_CORE1_MUX_BLK_BIT(_n_, _a_) (BIT(7UL+(((_n_)-2UL)/4UL)) | ((_a_) << 16))
185-
186-
#if TRACEMEM_MUX_BLK0_NUM < 2
187-
#error Invalid block num!
188-
#elif TRACEMEM_MUX_BLK0_NUM < 6
189-
#define TRACEMEM_BLK0_ADDR (0x3FC88000UL + 0x2000UL*(TRACEMEM_MUX_BLK0_NUM-2))
190-
#elif TRACEMEM_MUX_BLK0_NUM < 30
191-
#define TRACEMEM_BLK0_ADDR (0x3FC90000UL + 0x4000UL*(TRACEMEM_MUX_BLK0_NUM-6))
192-
#else
193-
#error Invalid block num!
194-
#endif
195-
196-
#if TRACEMEM_MUX_BLK1_NUM < 2
197-
#error Invalid block num!
198-
#elif TRACEMEM_MUX_BLK1_NUM < 6
199-
#define TRACEMEM_BLK1_ADDR (0x3FC88000UL + 0x2000UL*(TRACEMEM_MUX_BLK1_NUM-2))
200-
#elif TRACEMEM_MUX_BLK1_NUM < 30
201-
#define TRACEMEM_BLK1_ADDR (0x3FC90000UL + 0x4000UL*(TRACEMEM_MUX_BLK1_NUM-6))
202-
#else
203-
#error Invalid block num!
204-
#endif
205-
#endif
206-
207163
// TRAX is disabled, so we use its registers for our own purposes
208164
// | 31..XXXXXX..24 | 23 .(host_connect). 23 | 22 .(host_data). 22| 21..(block_id)..15 | 14..(block_len)..0 |
209165
#define ESP_APPTRACE_TRAX_CTRL_REG ERI_TRAX_DELAYCNT
@@ -334,10 +290,10 @@ static inline void esp_apptrace_trax_select_memory_block(int block_num)
334290
WRITE_PERI_REG(DPORT_PMS_OCCUPY_3_REG, block_num ? BIT(TRACEMEM_MUX_BLK0_NUM-4) : BIT(TRACEMEM_MUX_BLK1_NUM-4));
335291
#elif CONFIG_IDF_TARGET_ESP32S3
336292
// select memory block to be exposed to the TRAX module (accessed by host)
337-
uint32_t block_bits = block_num ? TRACEMEM_CORE0_MUX_BLK_BIT(TRACEMEM_MUX_BLK0_NUM, TRACEMEM_MUX_BLK0_ALLOC)
338-
: TRACEMEM_CORE0_MUX_BLK_BIT(TRACEMEM_MUX_BLK1_NUM, TRACEMEM_MUX_BLK1_ALLOC);
339-
block_bits |= block_num ? TRACEMEM_CORE1_MUX_BLK_BIT(TRACEMEM_MUX_BLK0_NUM, TRACEMEM_MUX_BLK0_ALLOC)
340-
: TRACEMEM_CORE1_MUX_BLK_BIT(TRACEMEM_MUX_BLK1_NUM, TRACEMEM_MUX_BLK1_ALLOC);
293+
uint32_t block_bits = block_num ? TRACEMEM_CORE0_MUX_BLK_BITS(TRACEMEM_MUX_BLK0_NUM)
294+
: TRACEMEM_CORE0_MUX_BLK_BITS(TRACEMEM_MUX_BLK1_NUM);
295+
block_bits |= block_num ? TRACEMEM_CORE1_MUX_BLK_BITS(TRACEMEM_MUX_BLK0_NUM)
296+
: TRACEMEM_CORE1_MUX_BLK_BITS(TRACEMEM_MUX_BLK1_NUM);
341297
ESP_EARLY_LOGV(TAG, "Select block %d @ %p (bits 0x%x)", block_num, s_trax_blocks[block_num], block_bits);
342298
DPORT_WRITE_PERI_REG(SENSITIVE_INTERNAL_SRAM_USAGE_2_REG, block_bits);
343299
#endif

components/esp_system/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ menu "ESP System Settings"
453453
config ESP_DEBUG_STUBS_ENABLE
454454
bool
455455
default COMPILER_OPTIMIZATION_LEVEL_DEBUG
456-
depends on !ESP32_TRAX && !ESP32S2_TRAX
456+
depends on !ESP32_TRAX && !ESP32S2_TRAX && !ESP32S3_TRAX
457457
help
458458
Debug stubs are used by OpenOCD to execute pre-compiled onboard code
459459
which does some useful debugging stuff, e.g. GCOV data dump.

components/esp_system/port/arch/xtensa/trax.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11

2-
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
3-
//
4-
// Licensed under the Apache License, Version 2.0 (the "License");
5-
// you may not use this file except in compliance with the License.
6-
// You may obtain a copy of the License at
7-
//
8-
// http://www.apache.org/licenses/LICENSE-2.0
9-
//
10-
// Unless required by applicable law or agreed to in writing, software
11-
// distributed under the License is distributed on an "AS IS" BASIS,
12-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
// See the License for the specific language governing permissions and
14-
// limitations under the License.
2+
/*
3+
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
157

168
#include <stdio.h>
179
#include "esp_err.h"
@@ -20,12 +12,13 @@
2012
#include "trax.h"
2113
#include "hal/trace_ll.h"
2214
#include "soc/dport_reg.h"
15+
#include "soc/tracemem_config.h"
2316
#include "sdkconfig.h"
2417

2518
// Utility functions for enabling TRAX in early startup (hence the use
2619
// of ESP_EARLY_LOGX) in Xtensa targets.
2720

28-
#if defined(CONFIG_ESP32_TRAX) || defined(CONFIG_ESP32S2_TRAX)
21+
#if defined(CONFIG_ESP32_TRAX) || defined(CONFIG_ESP32S2_TRAX) || defined(CONFIG_ESP32S3_TRAX)
2922
#define WITH_TRAX 1
3023
#endif
3124

@@ -49,12 +42,33 @@ int trax_enable(trax_ena_select_t which)
4942
trace_ll_mem_enable(0, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_PRO));
5043
trace_ll_mem_enable(1, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_APP));
5144
return ESP_OK;
52-
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
45+
#elif CONFIG_IDF_TARGET_ESP32S2
5346
if (which != TRAX_ENA_PRO) {
5447
return ESP_ERR_INVALID_ARG;
5548
}
5649
trace_ll_set_mem_block(TRACEMEM_MUX_BLK1_NUM);
5750
return ESP_OK;
51+
#elif CONFIG_IDF_TARGET_ESP32S3
52+
if (which == TRAX_ENA_PRO) {
53+
trace_ll_set_mem_block(0, TRACEMEM_MUX_BLK0_NUM);
54+
}
55+
else if (which == TRAX_ENA_APP) {
56+
trace_ll_set_mem_block(1, TRACEMEM_MUX_BLK0_NUM);
57+
}
58+
#ifdef CONFIG_ESP32S3_TRAX_TWOBANKS
59+
else if (which == TRAX_ENA_PRO_APP) {
60+
trace_ll_set_mem_block(0, TRACEMEM_MUX_BLK0_NUM);
61+
trace_ll_set_mem_block(1, TRACEMEM_MUX_BLK1_NUM);
62+
}
63+
else if (which == TRAX_ENA_PRO_APP_SWAP) {
64+
trace_ll_set_mem_block(1, TRACEMEM_MUX_BLK0_NUM);
65+
trace_ll_set_mem_block(0, TRACEMEM_MUX_BLK1_NUM);
66+
}
67+
#endif
68+
else {
69+
return ESP_ERR_INVALID_ARG;
70+
}
71+
return ESP_OK;
5872
#endif
5973
}
6074

components/esp_system/port/cpu_start.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
#include "soc/rtc.h"
7373
#include "soc/spinlock.h"
7474

75-
#if CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX
75+
#if CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX || CONFIG_ESP32S3_TRAX
7676
#include "trax.h"
7777
#endif
7878

@@ -186,10 +186,9 @@ void IRAM_ATTR call_start_cpu1(void)
186186
//has started, but it isn't active *on this CPU* yet.
187187
esp_cache_err_int_init();
188188

189-
#if CONFIG_IDF_TARGET_ESP32
190-
#if CONFIG_ESP32_TRAX_TWOBANKS
189+
#if (CONFIG_IDF_TARGET_ESP32 && CONFIG_ESP32_TRAX_TWOBANKS) || \
190+
(CONFIG_IDF_TARGET_ESP32S3 && CONFIG_ESP32S3_TRAX_TWOBANKS)
191191
trax_start_trace(TRAX_DOWNCOUNT_WORDS);
192-
#endif
193192
#endif
194193

195194
s_cpu_inited[1] = true;
@@ -507,9 +506,9 @@ void IRAM_ATTR call_start_cpu0(void)
507506
#endif
508507

509508
//Enable trace memory and immediately start trace.
510-
#if CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX
511-
#if CONFIG_IDF_TARGET_ESP32
512-
#if CONFIG_ESP32_TRAX_TWOBANKS
509+
#if CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX || CONFIG_ESP32S3_TRAX
510+
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3
511+
#if CONFIG_ESP32_TRAX_TWOBANKS || CONFIG_ESP32S3_TRAX_TWOBANKS
513512
trax_enable(TRAX_ENA_PRO_APP);
514513
#else
515514
trax_enable(TRAX_ENA_PRO);
@@ -518,7 +517,7 @@ void IRAM_ATTR call_start_cpu0(void)
518517
trax_enable(TRAX_ENA_PRO);
519518
#endif
520519
trax_start_trace(TRAX_DOWNCOUNT_WORDS);
521-
#endif // CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX
520+
#endif // CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX || CONFIG_ESP32S3_TRAX
522521

523522
esp_clk_init();
524523
esp_perip_clk_init();
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
146

157
#pragma once
168
#include <stdlib.h>
179

1810
#include "soc/dport_reg.h"
11+
#include "soc/tracemem_config.h"
1912

20-
static inline void trace_ll_set_mem_block(int block)
13+
static inline void trace_ll_set_mem_block(int cpu, int block)
2114
{
22-
// IDF-1785
23-
abort();
15+
uint32_t block_bits = 0;
16+
17+
if (cpu == 0) {
18+
block_bits = TRACEMEM_CORE0_MUX_BLK_BITS(block);
19+
} else {
20+
block_bits = TRACEMEM_CORE1_MUX_BLK_BITS(block);
21+
}
22+
DPORT_SET_PERI_REG_MASK(SENSITIVE_INTERNAL_SRAM_USAGE_2_REG, block_bits);
2423
}

components/heap/port/esp32s2/memory_layout.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
// Copyright 2010-2019 Espressif Systems (Shanghai) PTE LTD
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
146
#ifndef BOOTLOADER_BUILD
157

168
#include <stdlib.h>
179
#include <stdint.h>
1810

1911
#include "sdkconfig.h"
2012
#include "soc/soc.h"
13+
#include "soc/tracemem_config.h"
2114
#include "heap_memory_layout.h"
2215
#include "esp_heap_caps.h"
2316

@@ -145,7 +138,8 @@ SOC_RESERVE_MEMORY_REGION( SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_HIGH, extram_dat
145138

146139
// Blocks 19 and 20 may be reserved for the trace memory
147140
#if CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM > 0
148-
SOC_RESERVE_MEMORY_REGION(0x3fffc000 - CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM, 0x3fffc000, trace_mem);
141+
SOC_RESERVE_MEMORY_REGION(TRACEMEM_BLK0_ADDR, TRACEMEM_BLK0_ADDR + CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM / 2, trace_mem0);
142+
SOC_RESERVE_MEMORY_REGION(TRACEMEM_BLK1_ADDR, TRACEMEM_BLK1_ADDR + CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM / 2, trace_mem1);
149143
#endif
150144

151145
// RTC Fast RAM region

components/heap/port/esp32s3/memory_layout.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "sdkconfig.h"
1212
#include "esp_attr.h"
1313
#include "soc/soc.h"
14+
#include "soc/dport_reg.h"
15+
#include "soc/tracemem_config.h"
1416
#include "heap_memory_layout.h"
1517
#include "esp_heap_caps.h"
1618

@@ -107,7 +109,8 @@ SOC_RESERVE_MEMORY_REGION( SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_HIGH, extram_dat
107109
#endif
108110

109111
#if CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM > 0
110-
SOC_RESERVE_MEMORY_REGION(0x3FCD0000, 0x3FCD0000 + CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM, trace_mem);
112+
SOC_RESERVE_MEMORY_REGION(TRACEMEM_BLK0_ADDR, TRACEMEM_BLK0_ADDR + CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM / 2, trace_mem0);
113+
SOC_RESERVE_MEMORY_REGION(TRACEMEM_BLK1_ADDR, TRACEMEM_BLK1_ADDR + CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM / 2, trace_mem1);
111114
#endif
112115

113116
// RTC Fast RAM region
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#define TRACEMEM_BLK0_ADDR 0x3FFFC000UL
13+
#define TRACEMEM_BLK1_ADDR 0x3FFF8000UL
14+
15+
#ifdef __cplusplus
16+
}
17+
#endif

components/soc/esp32s2/include/soc/dport_reg.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
146
#ifndef _SOC_DPORT_REG_H_
157
#define _SOC_DPORT_REG_H_
168

@@ -25,10 +17,6 @@ extern "C" {
2517

2618
#define DPORT_DATE_REG SYSTEM_DATE_REG
2719

28-
#define TRACEMEM_MUX_BLK0_NUM 19
29-
#define TRACEMEM_MUX_BLK1_NUM 20
30-
#define TRACEMEM_BLK_NUM2ADDR(_n_) (0x3FFB8000UL + 0x4000UL*((_n_)-4))
31-
3220
#ifndef __ASSEMBLER__
3321
#include "dport_access.h"
3422
#endif

0 commit comments

Comments
 (0)