-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/p4_ulp_shared_mem' into 'master'
fix(lp-core): fixed ULP shared mem address being wrong on P4 See merge request espressif/esp-idf!32237
- Loading branch information
Showing
7 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include "ulp_lp_core_memory_shared.h" | ||
|
||
#include "sdkconfig.h" | ||
#include "soc/soc.h" | ||
#include "esp_rom_caps.h" | ||
#include "esp_assert.h" | ||
|
||
#define ALIGN_DOWN(SIZE, AL) (SIZE & ~(AL - 1)) | ||
|
||
/* The last CONFIG_ULP_SHARED_MEM bytes of the reserved memory are reserved for a shared cfg struct | ||
The main cpu app and the ulp binary can share variables automatically through the linkerscript generated from | ||
esp32ulp_mapgen.py, but this is not available when compiling the ULP library. | ||
For those special cases, e.g. config settings. We can use this shared area. | ||
*/ | ||
#define LP_CORE_SHARED_MEM_ADDR (SOC_RTC_DRAM_LOW + CONFIG_ULP_COPROC_RESERVE_MEM - CONFIG_ULP_SHARED_MEM) | ||
|
||
static ulp_lp_core_memory_shared_cfg_t *const s_shared_mem = (ulp_lp_core_memory_shared_cfg_t *)LP_CORE_SHARED_MEM_ADDR; | ||
|
||
#if IS_ULP_COCPU | ||
static ulp_lp_core_memory_shared_cfg_t __attribute__((section(".shared_mem"))) s_shared_mem = {}; | ||
ESP_STATIC_ASSERT(CONFIG_ULP_SHARED_MEM == sizeof(ulp_lp_core_memory_shared_cfg_t)); | ||
#endif | ||
|
||
ulp_lp_core_memory_shared_cfg_t* ulp_lp_core_memory_shared_cfg_get(void) | ||
{ | ||
return s_shared_mem; | ||
#if IS_ULP_COCPU | ||
return &s_shared_mem; | ||
#else | ||
#if ESP_ROM_HAS_LP_ROM | ||
extern uint32_t _rtc_ulp_memory_start; | ||
uint32_t ulp_base_addr = (uint32_t)&_rtc_ulp_memory_start; | ||
#else | ||
uint32_t ulp_base_addr = SOC_RTC_DRAM_LOW; | ||
#endif | ||
/* Ensure the end where the shared memory starts is aligned to 8 bytes | ||
if updating this also update the same in ulp_lp_core_riscv.ld | ||
*/ | ||
return (ulp_lp_core_memory_shared_cfg_t *)(ulp_base_addr + ALIGN_DOWN(CONFIG_ULP_COPROC_RESERVE_MEM, 0x8) - CONFIG_ULP_SHARED_MEM); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
components/ulp/test_apps/lp_core/lp_core_hp_uart/main/lp_core/test_shared.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#pragma once | ||
|
||
#define SHARED_MEM_INIT_VALUE 0xEE | ||
#define SHARED_MEM_END_VALUE 0xAA |
34 changes: 34 additions & 0 deletions
34
components/ulp/test_apps/lp_core/lp_core_hp_uart/main/lp_core/test_shared_mem_main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
#include "ulp_lp_core_print.h" | ||
#include "ulp_lp_core_memory_shared.h" | ||
#include "test_shared.h" | ||
|
||
int main(void) | ||
{ | ||
ulp_lp_core_memory_shared_cfg_t *shared_cfg = ulp_lp_core_memory_shared_cfg_get(); | ||
lp_core_printf("ULP shared memory address: %p\n", shared_cfg); | ||
|
||
volatile uint8_t* shared_mem = (uint8_t*)shared_cfg; | ||
for (int i = 0; i < sizeof(ulp_lp_core_memory_shared_cfg_t); i++) { | ||
if (shared_mem[i] != SHARED_MEM_INIT_VALUE) { | ||
lp_core_printf("Test failed: expected %X, got %X at %d\n", SHARED_MEM_INIT_VALUE, shared_mem[i], i); | ||
return 0; | ||
} | ||
} | ||
|
||
for (int i = 0; i < sizeof(ulp_lp_core_memory_shared_cfg_t); i++) { | ||
shared_mem[i] = SHARED_MEM_END_VALUE; | ||
} | ||
|
||
lp_core_printf("ULP shared memory test passed\n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters