Skip to content

Commit ef4c305

Browse files
Update ESP32 port to ESP-IDF release v4.2 and add ESP-IDF version check (#231)
* Revert "Reintroduce Espressif's IDF v4.2 changes to ESP32 port (#193)" This reverts commit 3d4d171. * Update ESP32 port files to work with ESP-IDF v4.2 as well as ESP-IDF v3.3 Add changes required to support ESP32-S2 * portmacro.h: Change return type of vApplicationSleep to void This fixes build failure when automatic light sleep is enabled * prevent header checks for files with different licensing Co-authored-by: David Chalco <[email protected]>
1 parent 341e9f0 commit ef4c305

33 files changed

+327
-6890
lines changed

.github/scripts/kernel_checker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#--------------------------------------------------------------------------------------------------
77
# CONFIG
88
#--------------------------------------------------------------------------------------------------
9+
KERNEL_IGNORED_FILES = [
10+
'FreeRTOS-openocd.c'
11+
]
12+
913
KERNEL_IGNORED_EXTENSIONS = [
1014
'.yml',
1115
'.css',
@@ -30,7 +34,13 @@
3034
]
3135

3236
KERNEL_IGNORED_PATTERNS = [
33-
r'.*\.git.*'
37+
r'.*\.git.*',
38+
r'.*portable.*Xtensa_ESP32\/include\/portmacro\.h',
39+
r'.*portable.*Xtensa_ESP32.*port\.c',
40+
r'.*portable.*Xtensa_ESP32.*portasm\.S',
41+
r'.*portable.*Xtensa_ESP32.*xtensa_.*',
42+
r'.*portable.*Xtensa_ESP32.*portmux_impl.*',
43+
r'.*portable.*Xtensa_ESP32.*xt_asm_utils\.h'
3444
]
3545

3646
KERNEL_HEADER = [
@@ -70,6 +80,7 @@ def main():
7080
checker = HeaderChecker(KERNEL_HEADER)
7181
checker.ignoreExtension(*KERNEL_IGNORED_EXTENSIONS)
7282
checker.ignorePattern(*KERNEL_IGNORED_PATTERNS)
83+
checker.ignoreFile(*KERNEL_IGNORED_FILES)
7384
checker.ignoreFile(os.path.split(__file__)[-1])
7485

7586
return checker.processArgs(args)

portable/ThirdParty/GCC/Xtensa_ESP32/include/portmacro.h

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include <xtensa/xtruntime.h>
8383
#include "esp_timer.h" /* required for FreeRTOS run time stats */
8484
#include "esp_system.h"
85+
#include "esp_idf_version.h"
8586

8687

8788
#include <esp_heap_caps.h>
@@ -134,9 +135,9 @@
134135
/* owner field values:
135136
* 0 - Uninitialized (invalid)
136137
* portMUX_FREE_VAL - Mux is free, can be locked by either CPU
137-
* CORE_ID_PRO / CORE_ID_APP - Mux is locked to the particular core
138+
* CORE_ID_REGVAL_PRO / CORE_ID_REGVAL_APP - Mux is locked to the particular core
138139
*
139-
* Any value other than portMUX_FREE_VAL, CORE_ID_PRO, CORE_ID_APP indicates corruption
140+
* Any value other than portMUX_FREE_VAL, CORE_ID_REGVAL_PRO, CORE_ID_REGVAL_APP indicates corruption
140141
*/
141142
uint32_t owner;
142143

@@ -283,8 +284,11 @@
283284

284285
/*Because the ROM routines don't necessarily handle a stack in external RAM correctly, we force */
285286
/*the stack memory to always be internal. */
286-
#define pvPortMallocTcbMem( size ) heap_caps_malloc( size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT )
287-
#define pvPortMallocStackMem( size ) heap_caps_malloc( size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT )
287+
#define portTcbMemoryCaps (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)
288+
#define portStackMemoryCaps (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)
289+
290+
#define pvPortMallocTcbMem(size) heap_caps_malloc(size, portTcbMemoryCaps)
291+
#define pvPortMallocStackMem(size) heap_caps_malloc(size, portStackMemoryCaps)
288292

289293
/*xTaskCreateStatic uses these functions to check incoming memory. */
290294
#define portVALID_TCB_MEM( ptr ) ( esp_ptr_internal( ptr ) && esp_ptr_byte_accessible( ptr ) )
@@ -307,6 +311,14 @@
307311
uint32_t compare,
308312
uint32_t * set )
309313
{
314+
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0))
315+
__asm__ __volatile__ (
316+
"WSR %2,SCOMPARE1 \n"
317+
"S32C1I %0, %1, 0 \n"
318+
: "=r" ( *set )
319+
: "r" ( addr ), "r" ( compare ), "0" ( *set )
320+
);
321+
#else
310322
#if ( XCHAL_HAVE_S32C1I > 0 )
311323
__asm__ __volatile__ (
312324
"WSR %2,SCOMPARE1 \n"
@@ -333,11 +345,21 @@
333345

334346
*set = old_value;
335347
#endif /* if ( XCHAL_HAVE_S32C1I > 0 ) */
348+
#endif /* #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)) */
336349
}
337350

351+
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0))
338352
void uxPortCompareSetExtram( volatile uint32_t * addr,
339353
uint32_t compare,
340354
uint32_t * set );
355+
#else
356+
static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
357+
{
358+
#if defined(CONFIG_ESP32_SPIRAM_SUPPORT)
359+
compare_and_set_extram(addr, compare, set);
360+
#endif
361+
}
362+
#endif
341363

342364
/*-----------------------------------------------------------*/
343365

@@ -408,11 +430,37 @@
408430
#define PRIVILEGED_DATA
409431
#endif
410432

411-
bool vApplicationSleep( TickType_t xExpectedIdleTime );
433+
void vApplicationSleep( TickType_t xExpectedIdleTime );
434+
void vPortSetStackWatchpoint( void* pxStackStart );
412435

413436
#define portSUPPRESS_TICKS_AND_SLEEP( idleTime ) vApplicationSleep( idleTime )
414437

438+
/*-----------------------------------------------------------*/
415439

440+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0))
441+
/* Architecture specific optimisations. */
442+
443+
#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
444+
445+
/* Check the configuration. */
446+
#if( configMAX_PRIORITIES > 32 )
447+
#error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 different priorities as tasks that share a priority will time slice.
448+
#endif
449+
450+
/* Store/clear the ready priorities in a bit map. */
451+
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
452+
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
453+
454+
/*-----------------------------------------------------------*/
455+
456+
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __builtin_clz( ( uxReadyPriorities ) ) )
457+
458+
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
459+
460+
#endif /* ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) */
461+
462+
/*-----------------------------------------------------------*/
463+
416464

417465
void _xt_coproc_release( volatile void * coproc_sa_base );
418466

@@ -429,6 +477,15 @@
429477
#define xPortGetFreeHeapSize esp_get_free_heap_size
430478
#define xPortGetMinimumEverFreeHeapSize esp_get_minimum_free_heap_size
431479

480+
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0))
481+
/*
482+
* Send an interrupt to another core in order to make the task running
483+
* on it yield for a higher-priority task.
484+
*/
485+
486+
void vPortYieldOtherCore( BaseType_t coreid ) PRIVILEGED_FUNCTION;
487+
488+
#endif /* ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0) */
432489

433490
/*
434491
* Callback to set a watchpoint on the end of the stack. Called every context switch to change the stack
@@ -442,6 +499,7 @@
442499
*/
443500
BaseType_t xPortInIsrContext();
444501

502+
445503
/*
446504
* This function will be called in High prio ISRs. Returns true if the current core was in ISR context
447505
* before calling into high prio ISR context.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2017, Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
/* File adapted to use on IDF FreeRTOS component, extracted
23+
* originally from zephyr RTOS code base:
24+
* https://github.com/zephyrproject-rtos/zephyr/blob/dafd348/arch/xtensa/include/xtensa-asm2-s.h
25+
*/
26+
27+
#ifndef __XT_ASM_UTILS_H
28+
#define __XT_ASM_UTILS_H
29+
30+
/*
31+
* SPILL_ALL_WINDOWS
32+
*
33+
* Spills all windowed registers (i.e. registers not visible as
34+
* A0-A15) to their ABI-defined spill regions on the stack.
35+
*
36+
* Unlike the Xtensa HAL implementation, this code requires that the
37+
* EXCM and WOE bit be enabled in PS, and relies on repeated hardware
38+
* exception handling to do the register spills. The trick is to do a
39+
* noop write to the high registers, which the hardware will trap
40+
* (into an overflow exception) in the case where those registers are
41+
* already used by an existing call frame. Then it rotates the window
42+
* and repeats until all but the A0-A3 registers of the original frame
43+
* are guaranteed to be spilled, eventually rotating back around into
44+
* the original frame. Advantages:
45+
*
46+
* - Vastly smaller code size
47+
*
48+
* - More easily maintained if changes are needed to window over/underflow
49+
* exception handling.
50+
*
51+
* - Requires no scratch registers to do its work, so can be used safely in any
52+
* context.
53+
*
54+
* - If the WOE bit is not enabled (for example, in code written for
55+
* the CALL0 ABI), this becomes a silent noop and operates compatbily.
56+
*
57+
* - Hilariously it's ACTUALLY FASTER than the HAL routine. And not
58+
* just a little bit, it's MUCH faster. With a mostly full register
59+
* file on an LX6 core (ESP-32) I'm measuring 145 cycles to spill
60+
* registers with this vs. 279 (!) to do it with
61+
* xthal_spill_windows().
62+
*/
63+
64+
.macro SPILL_ALL_WINDOWS
65+
#if XCHAL_NUM_AREGS == 64
66+
and a12, a12, a12
67+
rotw 3
68+
and a12, a12, a12
69+
rotw 3
70+
and a12, a12, a12
71+
rotw 3
72+
and a12, a12, a12
73+
rotw 3
74+
and a12, a12, a12
75+
rotw 4
76+
#elif XCHAL_NUM_AREGS == 32
77+
and a12, a12, a12
78+
rotw 3
79+
and a12, a12, a12
80+
rotw 3
81+
and a4, a4, a4
82+
rotw 2
83+
#else
84+
#error Unrecognized XCHAL_NUM_AREGS
85+
#endif
86+
.endm
87+
88+
#endif

portable/ThirdParty/GCC/Xtensa_ESP32/include/xtensa_context.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ NOTE: The Xtensa architecture requires stack pointer alignment to 16 bytes.
4545
#include <xtensa/corebits.h>
4646
#include <xtensa/config/system.h>
4747
#include <xtensa/xtruntime-frames.h>
48+
#include <esp_idf_version.h>
4849

4950

5051
/* Align a value up to nearest n-byte boundary, where n is a power of 2. */
@@ -325,8 +326,19 @@ STRUCT_END(XtSolFrame)
325326
.endm
326327
#endif
327328

329+
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0))
328330
#define CORE_ID_PRO 0xCDCD
329331
#define CORE_ID_APP 0xABAB
332+
#else
333+
#define CORE_ID_REGVAL_PRO 0xCDCD
334+
#define CORE_ID_REGVAL_APP 0xABAB
335+
336+
/* Included for compatibility, recommend using CORE_ID_REGVAL_PRO instead */
337+
#define CORE_ID_PRO CORE_ID_REGVAL_PRO
338+
339+
/* Included for compatibility, recommend using CORE_ID_REGVAL_APP instead */
340+
#define CORE_ID_APP CORE_ID_REGVAL_APP
341+
#endif
330342

331343
/*
332344
-------------------------------------------------------------------------------

portable/ThirdParty/GCC/Xtensa_ESP32/port.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,31 @@
9696
#include <xtensa/config/core.h>
9797

9898
#include "xtensa_rtos.h"
99+
#include "esp_idf_version.h"
99100

101+
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0))
102+
#include "rom/ets_sys.h"
103+
#include "esp_panic.h"
104+
#include "esp_crosscore_int.h"
105+
#else
100106
#if CONFIG_IDF_TARGET_ESP32S2
101107
#include "esp32s2/rom/ets_sys.h"
102108
#elif CONFIG_IDF_TARGET_ESP32
103109
#include "esp32/rom/ets_sys.h"
104110
#endif
111+
#include "esp_private/panic_reason.h"
112+
#include "esp_debug_helpers.h"
113+
#include "esp_private/crosscore_int.h"
114+
#include "esp_log.h"
115+
#endif /* ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0) */
105116
#include "soc/cpu.h"
106117

107118
#include "FreeRTOS.h"
108119
#include "task.h"
109120

110-
#include "esp_private/panic_reason.h"
111-
#include "esp_debug_helpers.h"
112121
#include "esp_heap_caps.h"
113-
#include "esp_private/crosscore_int.h"
114122

115123
#include "esp_intr_alloc.h"
116-
#include "esp_log.h"
117124

118125
/* Defined in portasm.h */
119126
extern void _frxt_tick_timer_init( void );
@@ -488,6 +495,8 @@ void vPortSetStackWatchpoint( void * pxStackStart )
488495
{
489496
uint32_t prev;
490497

498+
uint32_t oldlevel = portENTER_CRITICAL_NESTED();
499+
491500
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
492501
vPortCPUAcquireMutexIntsDisabled( &extram_mux, portMUX_NO_TIMEOUT, __FUNCTION__, __LINE__ );
493502
#else
@@ -506,6 +515,8 @@ void vPortSetStackWatchpoint( void * pxStackStart )
506515
#else
507516
vPortCPUReleaseMutexIntsDisabled( &extram_mux );
508517
#endif
518+
519+
portEXIT_CRITICAL_NESTED(oldlevel);
509520
}
510521
#endif //defined(CONFIG_SPIRAM_SUPPORT)
511522

portable/ThirdParty/GCC/Xtensa_ESP32/portasm.S

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "xtensa_rtos.h"
2727
#include "sdkconfig.h"
28+
#include "esp_idf_version.h"
2829

2930
#define TOPOFSTACK_OFFS 0x00 /* StackType_t *pxTopOfStack */
3031
#define CP_TOPOFSTACK_OFFS 0x04 /* xMPU_SETTINGS.coproc_area */
@@ -138,23 +139,27 @@ _frxt_int_enter:
138139
mull a2, a4, a2
139140
add a1, a1, a2 /* for current proc */
140141

142+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0))
141143
#ifdef CONFIG_FREERTOS_FPU_IN_ISR
142144
#if XCHAL_CP_NUM > 0
143145
rsr a3, CPENABLE /* Restore thread scope CPENABLE */
144146
addi sp, sp,-4 /* ISR will manage FPU coprocessor by forcing */
145147
s32i a3, a1, 0 /* its trigger */
146148
#endif
147149
#endif
150+
#endif /* ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) */
148151

149152
.Lnested:
150153
1:
154+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0))
151155
#ifdef CONFIG_FREERTOS_FPU_IN_ISR
152156
#if XCHAL_CP_NUM > 0
153157
movi a3, 0 /* whilst ISRs pending keep CPENABLE exception active */
154158
wsr a3, CPENABLE
155159
rsync
156160
#endif
157161
#endif
162+
#endif /* ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) */
158163

159164
mov a0, a12 /* restore return addr and return */
160165
ret
@@ -192,6 +197,7 @@ _frxt_int_exit:
192197
s32i a2, a3, 0 /* save nesting count */
193198
bnez a2, .Lnesting /* !=0 after decr so still nested */
194199

200+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0))
195201
#ifdef CONFIG_FREERTOS_FPU_IN_ISR
196202
#if XCHAL_CP_NUM > 0
197203
l32i a3, sp, 0 /* Grab last CPENABLE before leave ISR */
@@ -200,6 +206,7 @@ _frxt_int_exit:
200206
rsync /* ensure CPENABLE was modified */
201207
#endif
202208
#endif
209+
#endif /* ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) */
203210

204211
movi a2, pxCurrentTCB
205212
addx4 a2, a4, a2

0 commit comments

Comments
 (0)