diff --git a/ref_app/src/sys/start/sys_start.cpp b/ref_app/src/sys/start/sys_start.cpp index 4ac3c5e85..8fe8659ed 100644 --- a/ref_app/src/sys/start/sys_start.cpp +++ b/ref_app/src/sys/start/sys_start.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2025. +// Copyright Christopher Kormanyos 2007 - 2026. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -11,9 +11,9 @@ #include #if (defined(__XTENSA__) && !defined(CONFIG_IDF_TARGET_ESP32S3)) -extern "C" auto app_main_loop() -> int ATTRIBUTE(used); +extern "C" auto app_main_loop() -> int ATTRIBUTE(used, noinline); #else -ATTRIBUTE(used) auto main() -> int; +ATTRIBUTE(used, noinline) auto main() -> int; #endif #if (defined(__XTENSA__) && !defined(CONFIG_IDF_TARGET_ESP32S3)) diff --git a/ref_app/target/micros/am6254_soc/Code/Appli/Core/a53/main.c b/ref_app/target/micros/am6254_soc/Code/Appli/Core/a53/main.c index 38e500cf4..75012d8d4 100644 --- a/ref_app/target/micros/am6254_soc/Code/Appli/Core/a53/main.c +++ b/ref_app/target/micros/am6254_soc/Code/Appli/Core/a53/main.c @@ -17,7 +17,7 @@ extern uint32_t GetActiveCoreId(void); -extern int main(void) ATTRIBUTE(used); +extern int main(void) ATTRIBUTE(used,noinline); //extern void main_core0(void); extern void main_core1(void); @@ -25,9 +25,9 @@ extern void main_core2(void); extern void main_core3(void); extern void main_core0_init(void); -void timer_isr(void) ATTRIBUTE(used); -void main_x(void) ATTRIBUTE(used); -static void main_init(const uint32_t ActiveCore) ATTRIBUTE(used); +void timer_isr(void) ATTRIBUTE(used,noinline); +void main_x(void) ATTRIBUTE(used,noinline); +static void main_init(const uint32_t ActiveCore) ATTRIBUTE(used,noinline); void main_x(void) { diff --git a/ref_app/target/micros/am6254_soc/Code/Startup/Core/a53/Startup.c b/ref_app/target/micros/am6254_soc/Code/Startup/Core/a53/Startup.c index 7874c261d..8275dd8fc 100644 --- a/ref_app/target/micros/am6254_soc/Code/Startup/Core/a53/Startup.c +++ b/ref_app/target/micros/am6254_soc/Code/Startup/Core/a53/Startup.c @@ -61,7 +61,7 @@ static void Startup_Unexpected_Exit(void); static void Startup_InitSystemClock(void); static void Startup_InitSystemPeripheral(void); -extern void main_x(void) ATTRIBUTE(used); +extern void main_x(void) ATTRIBUTE(used,noinline); void Startup_Init(void) { diff --git a/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld b/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld index 4f6e0a55e..ac1a7b1c4 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld +++ b/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld @@ -36,8 +36,8 @@ INPUT(libc.a libm.a libgcc.a) /****************************************************************************************** Globals ******************************************************************************************/ -__STACK_SIZE_CORE0 = 1K; -__STACK_SIZE_CORE1 = 1K; +__STACK_SIZE_CORE0 = 4K; +__STACK_SIZE_CORE1 = 4K; /****************************************************************************************** Memory configuration @@ -122,9 +122,15 @@ SECTIONS *(.data*) . = ALIGN(4); KEEP (*(.data*)) + *(.sdata) + . = ALIGN(4); + KEEP (*(.sdata)) + *(.sdata*) + . = ALIGN(4); + KEEP (*(.sdata*)) _data_end = .; } > RAM AT>FLASH - + /* The uninitialized (zero-cleared) data sections */ .bss : ALIGN(4) { @@ -135,6 +141,12 @@ SECTIONS *(.bss*) . = ALIGN(4); KEEP (*(.bss*)) + *(.sbss) + . = ALIGN(4); + KEEP (*(.sbss)) + *(.sbss*) + . = ALIGN(4); + KEEP (*(.sbss*)) _bss_end = .; } > RAM diff --git a/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk b/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk index 86c1f3dc3..221ac7ebd 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk +++ b/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk @@ -20,11 +20,9 @@ WARN_FLAGS := TGT_ALLFLAGS = -O2 \ -march=rv32imafc_zicsr_zifencei_xesppie \ -mabi=ilp32f \ - -msmall-data-limit=0 \ + -msmall-data-limit=32 \ -falign-functions=4 \ -fomit-frame-pointer \ - -fno-reorder-blocks-and-partition \ - -fno-reorder-functions \ -DHP_CORES_SMP_MODE TGT_CFLAGS = -std=c23 \ @@ -50,36 +48,24 @@ TGT_LDFLAGS = -nostdlib --specs=nosys.specs -# ------------------------------------------------------------------------------ -# Rule to assemble source file (*.S) to object file (*.o). -# ------------------------------------------------------------------------------ - -ifeq ($(TYP_OS),WIN) -TGT_GCC := $(PATH_TOOLS_CC)/$(GCC_PREFIX)-gcc.exe -TGT_GCC := $(subst /,\,$(TGT_GCC)) -else -TGT_GCC := $(GCC_PREFIX)-gcc -endif - - # ------------------------------------------------------------------------------ # Image file and flash batch file. # ------------------------------------------------------------------------------ -RULE_SPECIAL_MAKE_IMAGE_FILE := +RULE_SPECIAL_MAKE_IMAGE_FILE := ifeq ($(TYP_OS),WIN) ESP32S3_ESP_TOOL_DIR := $(PATH_TOOLS)/espressif/esptool-v4.11.0-windows-amd64 -ESP32S3_ESP_TOOL_FLAGS_PROG := --chip esp32p4 \ - -p COM5 -b 460800 \ - --before=default_reset \ - --after=hard_reset write_flash \ - --flash_mode dio \ - --flash_freq 80m \ - --flash_size 32MB \ - 0x2000 $(CURDIR)/$(PATH_TGT)/startup/Code/SBL/Output/SBL.bin \ +ESP32S3_ESP_TOOL_FLAGS_PROG := --chip esp32p4 \ + -p COM5 -b 460800 \ + --before=default_reset \ + --after=hard_reset write_flash \ + --flash_mode dio \ + --flash_freq 80m \ + --flash_size 32MB \ + 0x2000 $(CURDIR)/$(PATH_TGT)/startup/Code/SBL/Output/SBL.bin \ 0x5000 $(CURDIR)/$(basename $(APP).$(TGT_SUFFIX)).bin diff --git a/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Appli/main_cores.cpp b/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Appli/main_cores.cpp index 084834b1e..03e5dbafb 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Appli/main_cores.cpp +++ b/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Appli/main_cores.cpp @@ -16,10 +16,10 @@ extern "C" { extern auto osGetActiveCore(void) -> std::uint32_t; + extern auto main_caller(void) -> void; auto main_core0() -> void; auto main_core1() -> void; - auto main_caller() -> void; } auto main(void) -> int __attribute__((used,noinline)); diff --git a/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/Startup.c b/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/Startup.c index 92e55b9a2..7d3f1c878 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/Startup.c +++ b/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/Startup.c @@ -36,6 +36,8 @@ static void Startup_InitMcuSystem(void); // Extern function prototype //========================================================================================= extern int main_x(void) __attribute__((used,noinline)); +extern void crt_init_ram(void); +extern void crt_init_ctors(void); //----------------------------------------------------------------------------------------- /// \brief Startup_Init function @@ -68,9 +70,7 @@ void Startup_Init(void) //----------------------------------------------------------------------------------------- static void Startup_InitRam(void) { - // Use my own standard static RAM initialization. - - extern void crt_init_ram(void); + // Use the ref_app's standard static RAM initialization. crt_init_ram(); } @@ -84,9 +84,7 @@ static void Startup_InitRam(void) //----------------------------------------------------------------------------------------- static void Startup_InitCtors(void) { - // Use my own standard static constructor initialization. - - extern void crt_init_ctors(); + // Use the ref_app's standard static constructor initialization. crt_init_ctors(); } @@ -100,22 +98,18 @@ static void Startup_InitCtors(void) //----------------------------------------------------------------------------------------- static void Startup_RunApplication(void) { - /* check the weak function */ - if((unsigned int) &main_x != 0) - { -#ifdef HP_CORES_SMP_MODE - // note: RISC-V has no WFE/SEV instructions to synchronize SMP system - // so I am using CLINT to synchronize both HP cores on ESP32-P4 - - // Notify core1 that the setup of the runtime environment is done - // by setting the SW interrupt pending bit in CLINT on core1. - - *(volatile uint32_t*)0x20010000 = 1; -#endif - - // Call the main function. - main_x(); - } + #if defined(HP_CORES_SMP_MODE) + // note: RISC-V has no WFE/SEV instructions to synchronize SMP system + // so I am using CLINT to synchronize both HP cores on ESP32-P4 + + // Notify core1 that the setup of the runtime environment is done + // by setting the SW interrupt pending bit in CLINT on core1. + + *(volatile uint32_t*)0x20010000 = 1; + #endif + + // Call the main function. + main_x(); // Catch unexpected exit from main or if main does not exist. Startup_Unexpected_Exit(); diff --git a/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/intvect.c b/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/intvect.c index 391b26a49..0448f7a19 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/intvect.c +++ b/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/intvect.c @@ -33,7 +33,7 @@ // Functions prototype //===================================================================================================== static void UndefinedHandler(void); -static void UndefinedHandler(void){ for(;;); } +static void UndefinedHandler(void){ for(;;) { ; } } void Isr_SW_Interrupt (void) __attribute__((weak, alias("UndefinedHandler"))); void Isr_ExtInt00 (void) __attribute__((weak, alias("UndefinedHandler"))); diff --git a/ref_app/target/micros/xtensa_esp32_p4/startup/crt0_init_ram.cpp b/ref_app/target/micros/xtensa_esp32_p4/startup/crt0_init_ram.cpp index 0247ca261..f72e1d3aa 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/startup/crt0_init_ram.cpp +++ b/ref_app/target/micros/xtensa_esp32_p4/startup/crt0_init_ram.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2022. +// Copyright Christopher Kormanyos 2007 - 2026. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/ref_app/target/micros/xtensa_esp32_p4/startup/crt1.cpp b/ref_app/target/micros/xtensa_esp32_p4/startup/crt1.cpp index a31157e78..6e6f203b6 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/startup/crt1.cpp +++ b/ref_app/target/micros/xtensa_esp32_p4/startup/crt1.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2022. +// Copyright Christopher Kormanyos 2007 - 2026. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/main.cpp b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/main.cpp index eaec73d44..dd76c3a31 100644 --- a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/main.cpp +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/main.cpp @@ -31,7 +31,7 @@ #include -auto main() -> int ATTRIBUTE(used); +auto main() -> int ATTRIBUTE(used,noinline); namespace {