You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2026/09/08 12:48:48 UTC
(mynewt-core) 01/03: mcu/apollo3: Add autogenerated linker config and SBL SRAM layout syscfg
This is an automated email from the ASF dual-hosted git repository.
sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 8b40b6abbe6d2464cbc76f4e79fe62678d7f7351
Author: Wiktor Kwiatkowski <wi...@codecoup.pl>
AuthorDate: Mon Aug 31 11:12:39 2026 +0200
mcu/apollo3: Add autogenerated linker config and SBL SRAM layout syscfg
Add linker include fragments for the generic boot/startup autogenerated
linker.
APOLLO3_SRAM_RESV must match INFO0 SECURITY.SRAM_RESV (programmable
via AmbiqSuite tools/apollo3_scripts/create_info0.py).
---
hw/mcu/ambiq/apollo3/apollo3.ld | 154 ---------------------
hw/mcu/ambiq/apollo3/include/mcu/cmsis_nvic.h | 8 +-
hw/mcu/ambiq/apollo3/include/mcu/mcu_vectors.h | 20 +++
.../apollo3/include/mcu/vectors/apollo3_vectors.h | 83 +++++++++++
hw/mcu/ambiq/apollo3/link/include/mcu_config.ld.h | 31 +++++
.../ambiq/apollo3/link/include/memory_regions.ld.h | 26 ++++
hw/mcu/ambiq/apollo3/syscfg.yml | 14 ++
7 files changed, 180 insertions(+), 156 deletions(-)
diff --git a/hw/mcu/ambiq/apollo3/apollo3.ld b/hw/mcu/ambiq/apollo3/apollo3.ld
deleted file mode 100644
index 3aa2098ee..000000000
--- a/hw/mcu/ambiq/apollo3/apollo3.ld
+++ /dev/null
@@ -1,154 +0,0 @@
-/* stack: dynamic */
-/* heap: dynamic */
-
-ENTRY(Reset_Handler)
-
-SECTIONS
-{
- .imghdr (NOLOAD):
- {
- . = . + _imghdr_size;
- } > FLASH
-
- __text = .;
-
- /* text: executable code */
- /* located in _flash_ */
- .text :
- {
- . = ALIGN(4);
- __isr_vector_start = .;
- KEEP(*(.isr_vector))
- KEEP(*(.ble_patch))
- __isr_vector_end = .;
- *(.text)
- *(.text*)
-
- KEEP(*(.init))
- KEEP(*(.fini))
-
- /* .ctors */
- *crtbegin.o(.ctors)
- *crtbegin?.o(.ctors)
- *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
- *(SORT(.ctors.*))
- *(.ctors)
-
- /* .dtors */
- *crtbegin.o(.dtors)
- *crtbegin?.o(.dtors)
- *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
- *(SORT(.dtors.*))
- *(.dtors)
-
- /* .rodata */
- . = ALIGN(4);
-INCLUDE "link_tables.ld.h"
- *(.rodata)
- *(.rodata*)
-
- PROVIDE(mynewt_main = main);
- . = ALIGN(4);
- } > FLASH
-
- .ARM.extab :
- {
- *(.ARM.extab* .gnu.linkonce.armextab.*)
- . = ALIGN(4);
- } > FLASH
-
- __exidx_start = .;
- .ARM.exidx :
- {
- *(.ARM.exidx* .gnu.linkonce.armexidx.*)
- . = ALIGN(4);
- } > FLASH
- __exidx_end = .;
-
- __etext = .;
-
- .vector_relocation :
- {
- . = ALIGN(4);
- __vector_tbl_reloc__ = .;
- . = . + (__isr_vector_end - __isr_vector_start);
- . = ALIGN(4);
- } > RAM
-
- /* data: uniquely initialized symbols */
- /* loaded into flash region, copied to sram region at startup */
- /* VMA appears in sram region, LMA is in flash region for initialization */
- /* _init_data used by startup to locate flash region copy of data */
- .data :
- {
- __data_start__ = .;
- *(vtable)
- *(.data)
- *(.data*)
-
- . = ALIGN(4);
- /* preinit data */
- PROVIDE_HIDDEN (__preinit_array_start = .);
- *(.preinit_array)
- PROVIDE_HIDDEN (__preinit_array_end = .);
-
- . = ALIGN(4);
- /* init data */
- PROVIDE_HIDDEN (__init_array_start = .);
- *(SORT(.init_array.*))
- *(.init_array)
- PROVIDE_HIDDEN (__init_array_end = .);
-
-
- . = ALIGN(4);
- /* finit data */
- PROVIDE_HIDDEN (__fini_array_start = .);
- *(SORT(.fini_array.*))
- *(.fini_array)
- PROVIDE_HIDDEN (__fini_array_end = .);
-
- *(.jcr)
- . = ALIGN(4);
- __data_end__ = .;
- } > RAM AT>FLASH
- _init_data = LOADADDR(.data); /* used by startup to initialize data */
-
- /* bss: zero-initialized symbols */
- /* don't require flash memory to remember their value */
- .bss :
- {
- . = ALIGN(4);
- __bss_start__ = .;
- *(.bss)
- *(.bss*)
- *(COMMON)
- . = ALIGN(4);
- __bss_end__ = .;
- } > RAM
-
- /* Heap starts after BSS */
- . = ALIGN(8);
- __HeapBase = .;
-
- /* .stack_dummy section doesn't contains any symbols. It is only
- * used for linker to calculate size of stack sections, and assign
- * values to stack symbols later */
- .stack_dummy (COPY):
- {
- *(.stack*)
- } > RAM
-
- _ram_start = ORIGIN(RAM);
-
- /* Set stack top to end of RAM, and stack limit move down by
- * size of stack_dummy section */
- __StackTop = ORIGIN(RAM) + LENGTH(RAM);
- __StackLimit = __StackTop - SIZEOF(.stack_dummy);
- PROVIDE(__stack = __StackTop);
-
- /* Top of head is the bottom of the stack */
- __HeapLimit = __StackLimit;
-
- /* Check if data + heap + stack exceeds RAM limit */
- ASSERT(__HeapBase <= __HeapLimit, "region RAM overflowed with stack")
-}
diff --git a/hw/mcu/ambiq/apollo3/include/mcu/cmsis_nvic.h b/hw/mcu/ambiq/apollo3/include/mcu/cmsis_nvic.h
index f1d4bd71c..571edacf8 100644
--- a/hw/mcu/ambiq/apollo3/include/mcu/cmsis_nvic.h
+++ b/hw/mcu/ambiq/apollo3/include/mcu/cmsis_nvic.h
@@ -9,8 +9,12 @@
#include <stdint.h>
-#define NVIC_NUM_VECTORS (16 + 26) // CORE + MCU Peripherals
-#define NVIC_USER_IRQ_OFFSET 16
+extern uint32_t __isr_vector_start[];
+extern uint32_t __isr_vector_end[];
+
+/* Extract number of vectors from .interrupt section size */
+#define NVIC_NUM_VECTORS (__isr_vector_end - __isr_vector_start)
+#define NVIC_USER_IRQ_OFFSET 16
#include "mcu/apollo3.h"
diff --git a/hw/mcu/ambiq/apollo3/include/mcu/mcu_vectors.h b/hw/mcu/ambiq/apollo3/include/mcu/mcu_vectors.h
new file mode 100644
index 000000000..b952eb68a
--- /dev/null
+++ b/hw/mcu/ambiq/apollo3/include/mcu/mcu_vectors.h
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "vectors/apollo3_vectors.h"
diff --git a/hw/mcu/ambiq/apollo3/include/mcu/vectors/apollo3_vectors.h b/hw/mcu/ambiq/apollo3/include/mcu/vectors/apollo3_vectors.h
new file mode 100644
index 000000000..4c790a17d
--- /dev/null
+++ b/hw/mcu/ambiq/apollo3/include/mcu/vectors/apollo3_vectors.h
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+INT_VECTOR_STACK_TOP(__StackTop)
+INT_VECTOR_RESET_HANDLER(Reset_Handler)
+INT_VECTOR_NMI_HANDLER(NMI_Handler)
+INT_VECTOR_HARDFAULT_HANDLER(HardFault_Handler)
+INT_VECTOR_MEMMANAGE_HANDLER(MemManage_Handler)
+INT_VECTOR_BUSFAULT_HANDLER(BusFault_Handler)
+INT_VECTOR_USAGEFAULT_HANDLER(UsageFault_Handler)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_SVC_HANDLER(SVC_Handler)
+INT_VECTOR_DEBUGMON_HANDLER(DebugMon_Handler)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_PENDSV_HANDLER(PendSV_Handler)
+INT_VECTOR_SYSTICK_HANDLER(SysTick_Handler)
+INT_VECTOR(BROWNOUT_IRQHandler)
+INT_VECTOR(WATCHDOG_IRQHandler)
+INT_VECTOR(RTC_IRQHandler)
+INT_VECTOR(VCOMP_IRQHandler)
+INT_VECTOR(IOSLAVE_IOS_IRQHandler)
+INT_VECTOR(IOSLAVE_ACC_IRQHandler)
+INT_VECTOR(IOMASTER0_IRQHandler)
+INT_VECTOR(IOMASTER1_IRQHandler)
+INT_VECTOR(IOMASTER2_IRQHandler)
+INT_VECTOR(IOMASTER3_IRQHandler)
+INT_VECTOR(IOMASTER4_IRQHandler)
+INT_VECTOR(IOMASTER5_IRQHandler)
+INT_VECTOR(BLE_IRQHandler)
+INT_VECTOR(GPIO_IRQHandler)
+INT_VECTOR(CTIMER_IRQHandler)
+INT_VECTOR(UART0_IRQHandler)
+INT_VECTOR(UART1_IRQHandler)
+INT_VECTOR(SCARD_IRQHandler)
+INT_VECTOR(ADC_IRQHandler)
+INT_VECTOR(PDM_IRQHandler)
+INT_VECTOR(MSPI_IRQHandler)
+INT_VECTOR(SOFTWARE0_IRQHandler)
+INT_VECTOR(STIMER_IRQHandler)
+INT_VECTOR(STIMER_CMPR0_IRQHandler)
+INT_VECTOR(STIMER_CMPR1_IRQHandler)
+INT_VECTOR(STIMER_CMPR2_IRQHandler)
+INT_VECTOR(STIMER_CMPR3_IRQHandler)
+INT_VECTOR(STIMER_CMPR4_IRQHandler)
+INT_VECTOR(STIMER_CMPR5_IRQHandler)
+INT_VECTOR(STIMER_CMPR6_IRQHandler)
+INT_VECTOR(STIMER_CMPR7_IRQHandler)
+INT_VECTOR(CLKGEN_IRQHandler)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
+INT_VECTOR_UNUSED(0)
diff --git a/hw/mcu/ambiq/apollo3/link/include/mcu_config.ld.h b/hw/mcu/ambiq/apollo3/link/include/mcu_config.ld.h
new file mode 100644
index 000000000..b13e3adad
--- /dev/null
+++ b/hw/mcu/ambiq/apollo3/link/include/mcu_config.ld.h
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <syscfg/syscfg.h>
+
+#if MYNEWT_VAL_APOLLO3_SRAM_RESV > 0
+#define RAM_SIZE \
+ (MYNEWT_VAL_MCU_RAM_SIZE - MYNEWT_VAL_APOLLO3_SRAM_RESV - \
+ MYNEWT_VAL_APOLLO3_SBL_STACK_MARGIN)
+#define NOINIT_RAM NOINIT_REGION
+#else
+#define RAM_SIZE \
+ (MYNEWT_VAL_MCU_RAM_SIZE - MYNEWT_VAL_APOLLO3_SBL_STACK_MARGIN)
+#define NOINIT_RAM RAM
+#endif
diff --git a/hw/mcu/ambiq/apollo3/link/include/memory_regions.ld.h b/hw/mcu/ambiq/apollo3/link/include/memory_regions.ld.h
new file mode 100644
index 000000000..2b3eddb25
--- /dev/null
+++ b/hw/mcu/ambiq/apollo3/link/include/memory_regions.ld.h
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <syscfg/syscfg.h>
+
+#if MYNEWT_VAL_APOLLO3_SRAM_RESV > 0
+NOINIT_REGION(rwx)
+ : ORIGIN = RAM_START + MYNEWT_VAL_MCU_RAM_SIZE - MYNEWT_VAL_APOLLO3_SRAM_RESV,
+ LENGTH = MYNEWT_VAL_APOLLO3_SRAM_RESV
+#endif
diff --git a/hw/mcu/ambiq/apollo3/syscfg.yml b/hw/mcu/ambiq/apollo3/syscfg.yml
index 361b2f8d1..d77ad8409 100644
--- a/hw/mcu/ambiq/apollo3/syscfg.yml
+++ b/hw/mcu/ambiq/apollo3/syscfg.yml
@@ -34,6 +34,18 @@ syscfg.defs:
chunks of this size. Buffer is created on stack.
value: 128
+ MCU_PATH:
+ value: '"repos/apache-mynewt-core/hw/mcu/ambiq/apollo3"'
+
+ APOLLO3_SRAM_RESV:
+ description: Must match INFO0 SECURITY.SRAM_RESV (top SRAM not cleared by SBL)
+ value: 0
+
+ APOLLO3_SBL_STACK_MARGIN:
+ description: >
+ Extra bytes below usable top SRAM (prevents SBL crash)
+ value: 8
+
UART_0:
description: 'Whether to enable UART0'
value: 1
@@ -479,4 +491,6 @@ syscfg.defs:
value: APOLLO3_TIMER_SOURCE_HFRC
syscfg.vals:
+ MCU_RAM_START: 0x10000000
+ MCU_RAM_SIZE: 0x60000
OS_TICKS_PER_SEC: 128