aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system-clock/linker/linker_script.ld18
-rw-r--r--system-clock/src/isr_vector.c39
2 files changed, 56 insertions, 1 deletions
diff --git a/system-clock/linker/linker_script.ld b/system-clock/linker/linker_script.ld
index fe0c14b..b9a8d4b 100644
--- a/system-clock/linker/linker_script.ld
+++ b/system-clock/linker/linker_script.ld
@@ -1,6 +1,8 @@
MEMORY
{
flash : org = 0x08000000, len = 256k
+ sram1 : org = 0x20000000, len = 48k
+ sram2 : org = 0x10000000, len = 16k
}
SECTIONS
@@ -11,4 +13,20 @@ SECTIONS
*(.vectors); /* All .vector sections go here. */
*(.text); /* All .text sections go here. */
} >flash
+
+ .data : {
+ /* Data segment as defined in the flash. */
+ INIT_DATA_VALUES = LOADADDR(.data);
+
+ /* Data segment where it will be in memory. */
+ DATA_SEGMENT_START = .;
+ *(.data);
+ DATA_SEGMENT_STOP = .;
+ } >sram1 AT>flash
+
+ BSS_START = .;
+ .bss : {
+ *(.bss);
+ } > sram1
+ BSS_END = .;
}
diff --git a/system-clock/src/isr_vector.c b/system-clock/src/isr_vector.c
index a56a8dc..b432732 100644
--- a/system-clock/src/isr_vector.c
+++ b/system-clock/src/isr_vector.c
@@ -5,9 +5,46 @@
/* Forward-declare the main function. This is implemented in main.c. */
void main();
+
+/* These are defined in the linker script. */
+extern uint8_t INIT_DATA_VALUES;
+extern uint8_t DATA_SEGMENT_START;
+extern uint8_t DATA_SEGMENT_STOP;
+extern uint8_t BSS_START;
+extern uint8_t BSS_END;
+
+
+/*
+ * Runs before main. Initializes the data and bss segments by loading them
+ * into memory.
+ */
+void init()
+{
+ uint8_t* src;
+ uint8_t* dest;
+
+ src = &INIT_DATA_VALUES;
+ dest = &DATA_SEGMENT_START;
+
+ /* Copy the values from flash into the data segment. */
+ while (dest != &DATA_SEGMENT_STOP) {
+ *(dest ++) = *(src ++);
+ }
+
+ /* Everything in the BSS segment is set to zero. */
+ dest = &BSS_START;
+ while (dest != &BSS_END) {
+ *(dest ++) = 0;
+ }
+
+
+ /* Jump to main. */
+ main();
+}
+
const void* vectors[] __attribute__((section(".vectors"))) = {
(void *) 0x2000c000, /* Top of stack at top of sram1. 48k */
- main, /* Reset handler */
+ init, /* Reset handler */
unhandled_isr, /* NMI */
unhandled_isr, /* Hard Fault */
unhandled_isr, /* MemManage */