diff --git a/components/newlib/test/test_shared_stack_printf.c b/components/newlib/test/test_shared_stack_printf.c index 65bbac0d03..e7e6d1f9d3 100644 --- a/components/newlib/test/test_shared_stack_printf.c +++ b/components/newlib/test/test_shared_stack_printf.c @@ -8,9 +8,14 @@ #include "test_utils.h" #include "esp_expression_with_stack.h" +#define SHARED_STACK_SIZE 8192 + +static StackType_t *shared_stack_sp = NULL; + void external_stack_function(void) { printf("Executing this printf from external stack! sp=%p\n", get_sp()); + shared_stack_sp = (StackType_t *)get_sp(); } void another_external_stack_function(void) @@ -19,11 +24,12 @@ void another_external_stack_function(void) printf("We can even use FreeRTOS resources delaying..., sp=%p\n", get_sp()); vTaskDelay(100); printf("Done!, sp=%p\n", get_sp()); + shared_stack_sp = (StackType_t *)get_sp(); } TEST_CASE("test printf using shared buffer stack", "[newlib]") { - portSTACK_TYPE *shared_stack = malloc(8192); + portSTACK_TYPE *shared_stack = malloc(SHARED_STACK_SIZE); TEST_ASSERT(shared_stack != NULL); @@ -32,8 +38,22 @@ TEST_CASE("test printf using shared buffer stack", "[newlib]") printf("SP: %p\n", get_sp()); printf("shared_stack: %p\n", (void *)shared_stack); - esp_execute_shared_stack_function(printf_lock, shared_stack,8192,external_stack_function); - esp_execute_shared_stack_function(printf_lock, shared_stack,8192,another_external_stack_function); + esp_execute_shared_stack_function(printf_lock, + shared_stack, + SHARED_STACK_SIZE, + external_stack_function); + + TEST_ASSERT(((shared_stack_sp >= shared_stack_sp) && + (shared_stack_sp < (shared_stack + SHARED_STACK_SIZE)))); + + esp_execute_shared_stack_function(printf_lock, + shared_stack, + SHARED_STACK_SIZE, + another_external_stack_function); + + TEST_ASSERT(((shared_stack_sp >= shared_stack_sp) && + (shared_stack_sp < (shared_stack + SHARED_STACK_SIZE)))); + vSemaphoreDelete(printf_lock); free(shared_stack); } diff --git a/components/xtensa/expression_with_stack_xtensa_asm.S b/components/xtensa/expression_with_stack_xtensa_asm.S index 6903baed3b..deac4f7e02 100644 --- a/components/xtensa/expression_with_stack_xtensa_asm.S +++ b/components/xtensa/expression_with_stack_xtensa_asm.S @@ -39,8 +39,9 @@ esp_shared_stack_invoke_function: movi a7, 1 s32i a7, a6, 0 /* hint the function was finished */ movi a6, shared_stack_env - movi a7, 0 - call4 longjmp /* jump to last clean state previously saved */ + movi a7, 0 + movi a12, longjmp + callx4 a12 /* jump to last clean state previously saved */ ret #else #error "this code is written for Window ABI" diff --git a/docs/en/api-reference/system/index.rst b/docs/en/api-reference/system/index.rst index 5cd0db3b62..7fd3ea5f16 100644 --- a/docs/en/api-reference/system/index.rst +++ b/docs/en/api-reference/system/index.rst @@ -19,7 +19,7 @@ System API High Resolution Timer :esp32: Himem (large external SPI RAM) API :esp32: Inter-Processor Call - Call function with external stack + Call function with external stack Interrupt Allocation Logging Miscellaneous System APIs