From 489c4b6c573bb101ed8163498cbaf8685413c699 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 15 Mar 2025 11:59:33 +0100 Subject: [PATCH] Get near-standard form esp32s3 riscv cop --- .../xtensa_esp32_s3_riscv_cop/mcal_led.cpp | 6 +- .../xtensa_esp32_s3_riscv_cop/mcal_port.cpp | 4 +- .../xtensa_esp32_s3_riscv_cop/mcal_port.h | 4 +- ref_app/target.vcxproj | 4 +- ref_app/target.vcxproj.filters | 12 +- .../startup/coprocessor_binary.S | 93 ++++++----- .../make/xtensa_esp32_s3_riscv_cop.ld | 66 +++----- .../make/xtensa_esp32_s3_riscv_cop_files.gmk | 10 +- .../startup/from_no_sdk/Code/Appli/main.cpp | 28 ++-- .../from_no_sdk/Code/Startup/Startup.c | 147 ------------------ .../startup/from_no_sdk/Code/Startup/crt0.cpp | 43 +++++ .../Code/Startup/crt0_init_ram.cpp | 57 +++++++ .../startup/from_no_sdk/Code/Startup/crt1.cpp | 37 +++++ 13 files changed, 248 insertions(+), 263 deletions(-) delete mode 100644 ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/Startup.c create mode 100644 ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0.cpp create mode 100644 ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0_init_ram.cpp create mode 100644 ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt1.cpp diff --git a/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_led.cpp b/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_led.cpp index 6a7984f65..1bd114faa 100644 --- a/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_led.cpp +++ b/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_led.cpp @@ -6,11 +6,13 @@ // #include -#include +#include mcal::led::led_base& mcal::led::led0() { - using led0_led_type = mcal::led::led_dummy; + using led0_port_type = mcal::port::port_pin; + + using led0_led_type = mcal::led::led_port; static led0_led_type the_led_00; diff --git a/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.cpp b/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.cpp index 60a35a7e3..ecd3c92fd 100644 --- a/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.cpp +++ b/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.cpp @@ -7,6 +7,8 @@ #include -void mcal::port::init(const config_type*) +auto mcal::port::init(const config_type*) -> void { + // Set all GPIO out registers to low. + mcal::reg::reg_access_static::reg_set(); } diff --git a/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.h b/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.h index 33924747a..72cb3b1b2 100644 --- a/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.h +++ b/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.h @@ -14,9 +14,9 @@ { namespace port { - typedef void config_type; + using config_type = void; - inline auto init(const config_type*) -> void { } + auto init(const config_type*) -> void; template class port_pin diff --git a/ref_app/target.vcxproj b/ref_app/target.vcxproj index 62b018396..334291a46 100644 --- a/ref_app/target.vcxproj +++ b/ref_app/target.vcxproj @@ -1149,7 +1149,9 @@ - + + + diff --git a/ref_app/target.vcxproj.filters b/ref_app/target.vcxproj.filters index a9424c730..e4e5971d0 100644 --- a/ref_app/target.vcxproj.filters +++ b/ref_app/target.vcxproj.filters @@ -1004,12 +1004,18 @@ micros\xtensa_esp32_s3\startup\Std - - micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup - micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Appli + + micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup + + + micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup + + + micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup + diff --git a/ref_app/target/micros/xtensa_esp32_s3/startup/coprocessor_binary.S b/ref_app/target/micros/xtensa_esp32_s3/startup/coprocessor_binary.S index cad13c049..aaee39f8c 100644 --- a/ref_app/target/micros/xtensa_esp32_s3/startup/coprocessor_binary.S +++ b/ref_app/target/micros/xtensa_esp32_s3/startup/coprocessor_binary.S @@ -2,23 +2,50 @@ .global coprocessor_bin coprocessor_bin: .byte 0x6F, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x17, 0x11, 0x00, 0x00, 0x13, 0x01, 0x01, 0x42, 0x6F, 0x00, 0x40, 0x04, 0xA9, 0x66, 0xA9, 0x67 - .byte 0x23, 0xA0, 0x06, 0x40, 0x03, 0xA6, 0x87, 0x4C, 0xB7, 0x05, 0x08, 0x00, 0x93, 0x86, 0x06, 0x40 - .byte 0x4D, 0x8E, 0x23, 0xA4, 0xC7, 0x4C, 0x23, 0xA6, 0x07, 0x46, 0x03, 0xA7, 0xC7, 0x40, 0x37, 0x06 - .byte 0x00, 0x08, 0x51, 0x8F, 0x23, 0xA6, 0xE7, 0x40, 0x98, 0x42, 0xB7, 0x07, 0x0C, 0x00, 0x31, 0x8F - .byte 0x98, 0xC2, 0x01, 0x00, 0xFD, 0x17, 0xF5, 0xFF, 0xC5, 0xBF, 0x00, 0x00, 0xB7, 0x16, 0x00, 0x50 - .byte 0x83, 0xA7, 0x86, 0x00, 0x41, 0x11, 0x06, 0xC6, 0x22, 0xC4, 0x26, 0xC2, 0x7D, 0x56, 0x93, 0x86 - .byte 0x86, 0x00, 0x63, 0x83, 0xC7, 0x02, 0xD8, 0x42, 0x63, 0x00, 0xC7, 0x02, 0x81, 0x47, 0x09, 0xCB - .byte 0x98, 0x42, 0x3E, 0x97, 0x23, 0x00, 0x07, 0x00, 0xD8, 0x42, 0x85, 0x07, 0xE3, 0xEA, 0xE7, 0xFE - .byte 0x9C, 0x46, 0xA1, 0x06, 0xE3, 0x91, 0xC7, 0xFE, 0x37, 0x17, 0x00, 0x50, 0x83, 0x27, 0x87, 0x01 - .byte 0xFD, 0x55, 0x13, 0x07, 0x87, 0x01, 0x05, 0x45, 0x63, 0x86, 0xB7, 0x04, 0x54, 0x43, 0x63, 0x83 - .byte 0xB6, 0x04, 0x1C, 0x47, 0x63, 0x80, 0xB7, 0x04, 0x95, 0xCB, 0x1C, 0x43, 0x83, 0xC7, 0x07, 0x00 - .byte 0x93, 0xF7, 0xF7, 0x0F, 0x23, 0x80, 0xF6, 0x00, 0x1C, 0x47, 0x63, 0x71, 0xF5, 0x02, 0x85, 0x47 - .byte 0x10, 0x43, 0x54, 0x43, 0x3E, 0x96, 0x03, 0x46, 0x06, 0x00, 0xBE, 0x96, 0x85, 0x07, 0x13, 0x76 - .byte 0xF6, 0x0F, 0x23, 0x80, 0xC6, 0x00, 0x14, 0x47, 0xE3, 0xE4, 0xD7, 0xFE, 0x5C, 0x47, 0x31, 0x07 - .byte 0xE3, 0x9E, 0xB7, 0xFA, 0xB7, 0x17, 0x00, 0x50, 0x83, 0xA7, 0x07, 0x00, 0x37, 0x14, 0x00, 0x50 - .byte 0xFD, 0x54, 0x13, 0x04, 0x44, 0x00, 0x63, 0x87, 0x97, 0x00, 0x82, 0x97, 0x1C, 0x40, 0x11, 0x04 - .byte 0xE3, 0x9D, 0x97, 0xFE, 0x21, 0x37, 0x01, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .byte 0x17, 0x11, 0x00, 0x00, 0x13, 0x01, 0xC1, 0x43, 0x6F, 0x00, 0x80, 0x20, 0x41, 0x11, 0x06, 0xC6 + .byte 0x21, 0x22, 0xB2, 0x40, 0x41, 0x01, 0x82, 0x80, 0xB7, 0x16, 0x00, 0x50, 0x03, 0xA7, 0x86, 0x01 + .byte 0xB7, 0x17, 0x00, 0x50, 0x93, 0x87, 0x07, 0x03, 0x3A, 0x95, 0x63, 0x74, 0xF5, 0x00, 0x23, 0xAC + .byte 0xA6, 0x00, 0x3A, 0x85, 0x82, 0x80, 0x00, 0x00, 0x82, 0x80, 0x00, 0x00, 0x82, 0x80, 0x00, 0x00 + .byte 0x01, 0x00, 0xFD, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00 + .byte 0x01, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xFD, 0xBF, 0x00, 0x00, 0x00, 0x00 + .byte 0x01, 0x00, 0xFD, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xFD, 0xBF, 0x00, 0x00, 0x00, 0x00 + .byte 0x01, 0x00, 0xFD, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x05, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00 + .byte 0x01, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x55, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00 + .byte 0x7D, 0x55, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00 + .byte 0x01, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00 + .byte 0x01, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x05, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00 + .byte 0x7D, 0x55, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x82, 0x80, 0x00, 0x00, 0x01, 0x45, 0x82, 0x80 + .byte 0x00, 0x00, 0x00, 0x00, 0x01, 0x45, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x82, 0x80, 0x00, 0x00 + .byte 0x01, 0x11, 0x2E, 0xC2, 0x32, 0xC4, 0x36, 0xC6, 0x3A, 0xC8, 0x3E, 0xCA, 0x42, 0xCC, 0x46, 0xCE + .byte 0x01, 0xA0, 0x00, 0x00, 0x37, 0x15, 0x00, 0x50, 0x13, 0x05, 0x05, 0x03, 0x82, 0x80, 0x00, 0x00 + .byte 0x41, 0x11, 0x06, 0xC6, 0xC5, 0x3F, 0x83, 0x47, 0x05, 0x00, 0x81, 0xE7, 0x85, 0x47, 0x23, 0x00 + .byte 0xF5, 0x00, 0xB2, 0x40, 0x41, 0x01, 0x82, 0x80, 0x01, 0x45, 0x81, 0x45, 0x82, 0x80, 0x00, 0x00 + .byte 0x03, 0x45, 0x45, 0x00, 0x82, 0x80, 0x00, 0x00, 0x82, 0x80, 0x00, 0x00, 0x82, 0x80, 0x00, 0x00 + .byte 0xA9, 0x67, 0x83, 0xA6, 0x07, 0x40, 0x03, 0x47, 0x45, 0x00, 0x37, 0x06, 0x00, 0x08, 0xB1, 0x8E + .byte 0x23, 0xA0, 0xD7, 0x40, 0x93, 0x47, 0x17, 0x00, 0x23, 0x02, 0xF5, 0x00, 0x82, 0x80, 0x00, 0x00 + .byte 0xA1, 0x45, 0xED, 0xB5, 0xB7, 0x17, 0x00, 0x50, 0x03, 0xC7, 0x87, 0x03, 0x41, 0x11, 0x22, 0xC4 + .byte 0x06, 0xC6, 0x37, 0x14, 0x00, 0x50, 0x19, 0xC7, 0xB2, 0x40, 0x13, 0x05, 0x04, 0x04, 0x22, 0x44 + .byte 0x41, 0x01, 0x82, 0x80, 0xA9, 0x66, 0x03, 0xA6, 0x06, 0x40, 0x37, 0x17, 0x00, 0x50, 0x93, 0x05 + .byte 0x04, 0x04, 0x37, 0x08, 0x00, 0x08, 0x13, 0x07, 0x87, 0x00, 0x98, 0xC1, 0x33, 0x66, 0x06, 0x01 + .byte 0x23, 0xA0, 0xC6, 0x40, 0x03, 0xA6, 0x86, 0x4C, 0x37, 0x05, 0x08, 0x00, 0x36, 0x87, 0x49, 0x8E + .byte 0x23, 0xA4, 0xC6, 0x4C, 0x23, 0xA6, 0x06, 0x46, 0x83, 0xA6, 0xC6, 0x40, 0x37, 0x05, 0x00, 0x50 + .byte 0x13, 0x05, 0xC5, 0x13, 0xB3, 0xE6, 0x06, 0x01, 0x23, 0x26, 0xD7, 0x40, 0x05, 0x47, 0x23, 0x82 + .byte 0x05, 0x00, 0x23, 0x8C, 0xE7, 0x02, 0x49, 0x35, 0xB2, 0x40, 0x13, 0x05, 0x04, 0x04, 0x22, 0x44 + .byte 0x41, 0x01, 0x82, 0x80, 0xA9, 0x67, 0x23, 0xA0, 0x07, 0x40, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00 + .byte 0x41, 0x11, 0x01, 0x45, 0x06, 0xC6, 0x22, 0xC4, 0xF5, 0x37, 0x01, 0x45, 0x11, 0x3F, 0x37, 0x14 + .byte 0x00, 0x50, 0x8D, 0x37, 0x1C, 0x41, 0x9C, 0x47, 0x82, 0x97, 0x37, 0x07, 0x06, 0x00, 0x83, 0x27 + .byte 0x84, 0x04, 0x7D, 0x17, 0x85, 0x07, 0x23, 0x24, 0xF4, 0x04, 0x75, 0xFB, 0xDD, 0xB7, 0x00, 0x00 + .byte 0x41, 0x11, 0x06, 0xC6, 0x31, 0x20, 0xAD, 0x20, 0xE1, 0x37, 0x01, 0x00, 0x01, 0x00, 0xF5, 0xBF + .byte 0xB7, 0x16, 0x00, 0x50, 0x37, 0x17, 0x00, 0x50, 0x93, 0x86, 0xC6, 0x01, 0x93, 0x05, 0x87, 0x01 + .byte 0xB7, 0x17, 0x00, 0x50, 0x33, 0x85, 0xB6, 0x40, 0x13, 0x86, 0x87, 0x01, 0x2A, 0x96, 0x63, 0x8D + .byte 0xB6, 0x00, 0x13, 0x07, 0x87, 0x01, 0x93, 0x87, 0x87, 0x01, 0x94, 0x43, 0x91, 0x07, 0x11, 0x07 + .byte 0x23, 0x2E, 0xD7, 0xFE, 0xE3, 0x1B, 0xF6, 0xFE, 0xB7, 0x17, 0x00, 0x50, 0x37, 0x17, 0x00, 0x50 + .byte 0x93, 0x86, 0x07, 0x02, 0x13, 0x07, 0xC7, 0x04, 0x63, 0x89, 0xE6, 0x00, 0x93, 0x87, 0x07, 0x02 + .byte 0x23, 0xA0, 0x07, 0x00, 0x91, 0x07, 0xE3, 0x9D, 0xE7, 0xFE, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00 + .byte 0x41, 0x11, 0x22, 0xC4, 0x26, 0xC2, 0x37, 0x14, 0x00, 0x50, 0xB7, 0x14, 0x00, 0x50, 0x06, 0xC6 + .byte 0x93, 0x07, 0x84, 0x01, 0x93, 0x84, 0x84, 0x01, 0x63, 0x8A, 0x97, 0x00, 0x13, 0x04, 0x84, 0x01 + .byte 0x83, 0x27, 0xC4, 0xFF, 0x71, 0x14, 0x82, 0x97, 0xE3, 0x1C, 0x94, 0xFE, 0xB2, 0x40, 0x22, 0x44 + .byte 0x92, 0x44, 0x41, 0x01, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -230,33 +257,5 @@ coprocessor_bin: .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x30, 0x10, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00 - .byte 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x30, 0x10, 0x00, 0x50, 0x30, 0x10, 0x00, 0x50 - .byte 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x01, 0x00, 0x50, 0x60, 0x01, 0x00, 0x50 + .byte 0x40, 0x01, 0x00, 0x50, 0x30, 0x01, 0x00, 0x50, 0x28, 0x10, 0x00, 0x50 diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop.ld b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop.ld index 637f70fdb..f601b8e1b 100644 --- a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop.ld +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop.ld @@ -1,3 +1,11 @@ +/* + Copyright Christopher Kormanyos 2025. + 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) +*/ + +/* Originally from: */ /****************************************************************************************** Filename : coprocessor.ld @@ -15,9 +23,6 @@ ******************************************************************************************/ -/****************************************************************************************** - ELF Entrypoint -******************************************************************************************/ ENTRY(_start) /****************************************************************************************** @@ -51,75 +56,50 @@ SECTIONS /* Read-only data (.rodata) (note: esp32-s3 has not data access path on I_SRAM, rodata must be move to D_SRAM) */ .rodata : ALIGN(4) { - PROVIDE(__RODATA_BASE_ADDRESS = .); *(.rodata) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); PROVIDE(__INTVECT_BASE_ADDRESS = .); *(.intvect_core*) + . = ALIGN(4); } > D_SRAM /* Section for constructors */ .ctors : ALIGN(4) { - PROVIDE(__CPPCTOR_LIST__ = .); + _ctors_begin = .; KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) KEEP (*(SORT(.init_array.*))) KEEP (*(.init_array)) - LONG(-1) ; - PROVIDE(__CPPCTOR_END__ = .); + _ctors_end = .; . = ALIGN(4); } > D_SRAM - - /* Section for destructors */ - .dtors : ALIGN(4) - { - PROVIDE(__CPPDTOR_LIST__ = .); - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array)) - LONG(-1) ; - PROVIDE(__CPPDTOR_END__ = .); - . = ALIGN(4); - } > D_SRAM - - /* Runtime clear table */ - .clear_sec : ALIGN(4) - { - PROVIDE(__RUNTIME_CLEAR_TABLE = .) ; - LONG(0 + ADDR(.bss)); LONG(SIZEOF(.bss)); - LONG(-1); LONG(-1); - . = ALIGN(4); - } > D_SRAM - - /* Runtime copy table (note: note needed on esp32-s3 bootROM copied the data from flash to SRAM) */ -#if 0 - .copy_sec : ALIGN(4) - { - PROVIDE(__RUNTIME_COPY_TABLE = .) ; - LONG(LOADADDR(.data)); LONG(0 + ADDR(.data)); LONG(SIZEOF(.data)); - LONG(-1); LONG(-1); LONG(-1); - . = ALIGN(4); - } > D_SRAM -#endif - /* The ROM-to-RAM initialized data section */ .data : ALIGN(4) { - PROVIDE(__DATA_BASE_ADDRESS = .); + _data_begin = .; *(.data) *(.data*) + _data_end = .; } > D_SRAM /* The uninitialized (zero-cleared) bss section */ .bss : ALIGN(4) { - PROVIDE(__BSS_BASE_ADDRESS = .); + _bss_begin = .; *(.bss) *(.bss*) + _bss_end = .; } > D_SRAM + PROVIDE(end = .); + PROVIDE(_fini = .); + + _rom_data_begin = LOADADDR(.data); + /* stack definition */ .stack : { diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop_files.gmk b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop_files.gmk index ada33d534..6e56f9041 100644 --- a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop_files.gmk +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop_files.gmk @@ -11,7 +11,13 @@ FILES_CPP := -FILES_TGT := $(PATH_TGT)/startup/from_no_sdk/Code/Appli/main \ +FILES_TGT := $(PATH_APP)/mcal/mcal_gcc_cxx_completion \ + $(PATH_APP)/mcal/$(TGT)/mcal_gpt \ + $(PATH_APP)/mcal/$(TGT)/mcal_led \ + $(PATH_APP)/mcal/$(TGT)/mcal_port \ + $(PATH_TGT)/startup/from_no_sdk/Code/Appli/main \ $(PATH_TGT)/startup/from_no_sdk/Code/Startup/boot \ $(PATH_TGT)/startup/from_no_sdk/Code/Startup/IntVectTable \ - $(PATH_TGT)/startup/from_no_sdk/Code/Startup/Startup + $(PATH_TGT)/startup/from_no_sdk/Code/Startup/crt0 \ + $(PATH_TGT)/startup/from_no_sdk/Code/Startup/crt0_init_ram \ + $(PATH_TGT)/startup/from_no_sdk/Code/Startup/crt1 diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Appli/main.cpp b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Appli/main.cpp index 62c89b66e..43c3d6e04 100644 --- a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Appli/main.cpp +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Appli/main.cpp @@ -23,31 +23,29 @@ ******************************************************************************************/ +#include +#include #include -#include - -extern "C" -void main(); - -extern "C" -void main() +namespace { - // Set all GPIO out registers to low. - mcal::reg::reg_access_static::reg_set(); + volatile std::uint32_t main_counter { }; +} - // Configure GPIO17 as output low. - using port_pin_type = mcal::port::port_pin; +extern "C" void main(); - port_pin_type::set_direction_output(); +extern "C" void main() +{ + mcal::port::init(nullptr); + mcal::gpt::init(nullptr); for(;;) { - port_pin_type::toggle_pin(); + mcal::led::led0().toggle(); - for(uint32_t i=0; i< 0xC0000; i++) + for(std::uint32_t loop { UINT32_C(0) }; loop < std::uint32_t { UINT32_C(0x00060000) }; ++loop) { - asm volatile("nop"); + main_counter = std::uint32_t { main_counter + UINT8_C(1) }; } } } diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/Startup.c b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/Startup.c deleted file mode 100644 index 2b9d33250..000000000 --- a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/Startup.c +++ /dev/null @@ -1,147 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2025. -// 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) -// - -// Originally from: -// *************************************************************************************** -// Filename : Startup.c -// -// Author : Chalandi Amine -// -// Owner : Chalandi Amine -// -// Date : 04.09.2024 -// -// Description : C/C++ Runtime Setup (Crt0) -// -// *************************************************************************************** - -#include -#include - -//========================================================================================= -// types definitions -//========================================================================================= -typedef struct -{ - unsigned long sourceAddr; /* Source Address (section in ROM memory) */ - unsigned long targetAddr; /* Target Address (section in RAM memory) */ - unsigned long size; /* length of section (bytes) */ -} runtimeCopyTable_t; - -typedef struct -{ - unsigned long Addr; /* source Address (section in RAM memory) */ - unsigned long size; /* length of section (bytes) */ -} runtimeClearTable_t; - -//========================================================================================= -// linker variables -//========================================================================================= -extern const runtimeCopyTable_t __RUNTIME_COPY_TABLE[]; -extern const runtimeClearTable_t __RUNTIME_CLEAR_TABLE[]; -extern unsigned long __CPPCTOR_LIST__[]; - -//========================================================================================= -// defines -//========================================================================================= -#define __STARTUP_RUNTIME_COPYTABLE (runtimeCopyTable_t*)(&__RUNTIME_COPY_TABLE[0]) -#define __STARTUP_RUNTIME_CLEARTABLE (runtimeClearTable_t*)(&__RUNTIME_CLEAR_TABLE[0]) -#define __STARTUP_RUNTIME_CTORS (unsigned long*)(&__CPPCTOR_LIST__[0]) - -//========================================================================================= -// function prototypes -//========================================================================================= -void Startup_Init(void) __attribute__((used)); -static void Startup_InitRam(void); -static void Startup_InitCtors(void); - -extern void main(void); - -//========================================================================================= -// macros -//========================================================================================= - -//----------------------------------------------------------------------------------------- -/// \brief Startup_Init function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -void Startup_Init(void) -{ - /* Initialize the RAM memory */ - Startup_InitRam(); - - /* Initialize the non-local C++ objects */ - Startup_InitCtors(); - - /* Start the application */ - main(); - - /* Catch unexpected exit from main. */ - for(;;) { ; } -} - - -//----------------------------------------------------------------------------------------- -/// \brief Startup_InitRam function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -static void Startup_InitRam(void) -{ - unsigned long ClearTableIdx = 0; - - /* Clear Table */ - - while((__STARTUP_RUNTIME_CLEARTABLE)[ClearTableIdx].Addr != (unsigned long)-1 && (__STARTUP_RUNTIME_CLEARTABLE)[ClearTableIdx].size != (unsigned long)-1) - { - for(unsigned int cpt = 0; cpt < (__STARTUP_RUNTIME_CLEARTABLE)[ClearTableIdx].size; cpt++) - { - *(volatile unsigned char*)((unsigned long)((__STARTUP_RUNTIME_CLEARTABLE)[ClearTableIdx].Addr) + cpt) = 0; - } - - ClearTableIdx++; - } - - unsigned long CopyTableIdx = 0; - - /* Copy Table */ - while((__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].sourceAddr != (unsigned long)-1 && - (__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].targetAddr != (unsigned long)-1 && - (__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].size != (unsigned long)-1 - ) - { - for(unsigned int cpt = 0; cpt < (__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].size; cpt++) - { - *(volatile unsigned char*)((unsigned long)((__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].targetAddr) + cpt) = - *(volatile unsigned char*)((unsigned long)((__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].sourceAddr) + cpt); - } - - CopyTableIdx++; - } -} - -//----------------------------------------------------------------------------------------- -/// \brief Startup_InitCtors function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -static void Startup_InitCtors(void) -{ - unsigned long CtorIdx = 0U; - - while((__STARTUP_RUNTIME_CTORS)[CtorIdx] != ((unsigned long)-1)) - { - ((void (*)(void))((__STARTUP_RUNTIME_CTORS)[CtorIdx++]))(); - } -} diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0.cpp b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0.cpp new file mode 100644 index 000000000..b9910975a --- /dev/null +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0.cpp @@ -0,0 +1,43 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2025. +// 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) +// + +// Generic code. + +#include + +namespace crt +{ + void init_ram(); + void init_ctors(); +} + +extern "C" +{ + extern auto main() -> int; + + void Startup_Init() __attribute__((used, noinline)); +} + +void Startup_Init() +{ + // Initialize statics from ROM to RAM. + // Zero-clear default-initialized static RAM. + crt::init_ram(); + + // Call all ctor initializations. + crt::init_ctors(); + + // Jump to main (and never return). + static_cast(main()); + + // Catch an unexpected return from main. + for(;;) + { + // Replace with a loud error if desired. + mcal::cpu::nop(); + } +} diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0_init_ram.cpp b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0_init_ram.cpp new file mode 100644 index 000000000..6029cf9fc --- /dev/null +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0_init_ram.cpp @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2025. +// 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) +// + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + +#include +#include +#include + +extern "C" +{ + extern std::uintptr_t _rom_data_begin; // Start address for the initialization values of the rom-to-ram section. + extern std::uintptr_t _data_begin; // Start address for the .data section. + extern std::uintptr_t _data_end; // End address for the .data section. + extern std::uintptr_t _bss_begin; // Start address for the .bss section. + extern std::uintptr_t _bss_end; // End address for the .bss section. +} + +namespace crt +{ + void init_ram(); +} + +void crt::init_ram() +{ + using memory_aligned_type = std::uint32_t; + + // Copy the data segment initializers from ROM to RAM. + // Note that all data segments are aligned by 4. + const std::size_t size_data = + std::size_t( static_cast(static_cast(&_data_end)) + - static_cast(static_cast(&_data_begin))); + + std::copy(static_cast(static_cast(&_rom_data_begin)), + static_cast(static_cast(&_rom_data_begin)) + size_data, + static_cast< memory_aligned_type*>(static_cast< void*>(&_data_begin))); + + // Clear the bss segment. + // Note that the bss segment is aligned by 4. + std::fill(static_cast(static_cast(&_bss_begin)), + static_cast(static_cast(&_bss_end)), + static_cast(0U)); +} + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#pragma GCC diagnostic pop +#endif diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt1.cpp b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt1.cpp new file mode 100644 index 000000000..33eb92ba9 --- /dev/null +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt1.cpp @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2025. +// 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) +// + +#include +#include + +extern "C" +{ + struct ctor_type + { + using function_type = void(*)(); + }; + + extern ctor_type::function_type _ctors_end; + extern ctor_type::function_type _ctors_begin; +} + +namespace crt +{ + void init_ctors(); +} + +void crt::init_ctors() +{ + using local_const_reverse_iterator = std::reverse_iterator; + + std::for_each(local_const_reverse_iterator(&_ctors_end), + local_const_reverse_iterator(&_ctors_begin), + [](const ctor_type::function_type pf) + { + pf(); + }); +}