summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.txt2
-rw-r--r--main.c17
-rw-r--r--script.ld23
3 files changed, 30 insertions, 12 deletions
diff --git a/README.txt b/README.txt
index ab93862..faa5291 100644
--- a/README.txt
+++ b/README.txt
@@ -1,5 +1,5 @@
Compile and upload
-$ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -o a.elf main.c
+$ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -T script.ld -nostartfiles -nostdlib -o a.elf main.c
$ arm-none-eabi-objcopy -O ihex -j .text -j .data a.elf a.hex
$ avrdude -c arduino -p atmel_sam3x8e -v -b 115200 -U flash:w:a.hex
diff --git a/main.c b/main.c
index 8fcc9be..89c1e15 100644
--- a/main.c
+++ b/main.c
@@ -25,9 +25,9 @@
int main(void)
{
// enable peripheral clock
- PMC_WPMR = PMC_WPKEY << 8;
- PMC_PCER0 |= (1u << PMC_PID);
- PMC_WPMR = (PMC_WPKEY << 8) | 1u;
+ //PMC_WPMR = PMC_WPKEY << 8;
+ //PMC_PCER0 |= (1u << PMC_PID);
+ //PMC_WPMR = (PMC_WPKEY << 8) | 1u;
// enable port, set to output, disable pull-up
PIO_WPMR = PIO_WPKEY << 8;
@@ -44,3 +44,14 @@ int main(void)
return 0;
}
+
+extern const unsigned int StackTop;
+
+__attribute__ ((section(".vtor")))
+const void* VectorTable[] = {
+ &StackTop, /* CPU will automatically *
+ * set stack its pointer *
+ * to this value */
+
+ main, /* -15: Reset_IRQn */
+};
diff --git a/script.ld b/script.ld
index e8b0bb1..ac49459 100644
--- a/script.ld
+++ b/script.ld
@@ -1,3 +1,5 @@
+ENTRY(main)
+
MEMORY
{
rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000
@@ -6,21 +8,28 @@ MEMORY
SECTIONS
{
- . = ALIGN(4);
.text :
{
- KEEP(*(.vectors .vectors.*))
+ KEEP(*(.vtor))
+
*(.text*)
*(.rodata*)
+
+ . = ALIGN(4);
+ __end_of_text__ = .;
} > rom
- . = ALIGN(4);
.data :
{
- *(.data*);
+ __data_start_src__ = __end_of_text__;
+ __data_start__ = .;
+
+ *(.data*)
+
+ . = ALIGN(4);
+ __data_end__ = .;
} > ram AT >rom
- . = ALIGN(4);
.bss (NOLOAD) :
{
__bss_start__ = . ;
@@ -29,7 +38,5 @@ SECTIONS
__bss_end__ = . ;
} > ram
- _end = . ;
- __end__ = _end ;
- end = _end;
+ StackTop = ORIGIN(ram) + LENGTH(ram);
}