소스 검색

Add a flash linker script. Push the example into flash.

Michael Hope 5 년 전
부모
커밋
bfb966c6dc
3개의 변경된 파일21개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      Makefile
  2. 16 0
      first.c
  3. 1 0
      first.ld

+ 4 - 1
Makefile 파일 보기

@@ -8,7 +8,10 @@ CFLAGS = -mcpu=cortex-m0 -mthumb -O -nostdlib -std=gnu99 -fno-toplevel-reorder
8 8
 all: first.bin
9 9
 
10 10
 first.elf: first.o
11
-	$(CC) $(CFLAGS) -T first.ld -o $@ $<
11
+	$(CC) $(CFLAGS) -T flash.ld -o $@ $<
12 12
 
13 13
 %.bin: %.elf
14 14
 	$(OBJCOPY) -Obinary $< $@
15
+
16
+clean:
17
+	rm -f *.o *.elf *.bin

+ 16 - 0
first.c 파일 보기

@@ -15,8 +15,12 @@ typedef volatile uint32_t REG32;
15 15
 #define GPIO_GPIO2DATA                            (*(pREG32 (0x50023FFC)))    // Port data register
16 16
 #define GPIO_GPIO2DIR                             (*(pREG32 (0x50028000)))    // Data direction register
17 17
 
18
+#define RAM_START  0x10000000
19
+#define RAM_SIZE   8192
20
+
18 21
 void pwm(int level, int top);
19 22
 
23
+__attribute__((naked))
20 24
 void start(void)
21 25
 {
22 26
   GPIO_GPIO2DIR = 0xFFFF;
@@ -74,3 +78,15 @@ void startx(void)
74 78
 	}
75 79
     }
76 80
 }
81
+
82
+__attribute__((section(".vectors")))
83
+const void * vectors[] = {
84
+  (void *)(RAM_START + RAM_SIZE - 64),
85
+  start,
86
+  0,
87
+  0,
88
+  0,
89
+  0,
90
+  0,
91
+  0,
92
+};

+ 1 - 0
first.ld 파일 보기

@@ -4,6 +4,7 @@ SECTIONS
4 4
      {
5 5
        . = 0x10000400;
6 6
        .text : { *(.text) }
7
+       .vectors : { *(.vectors) }
7 8
        .data : { *(.data) }
8 9
        .bss : { *(.bss) }
9 10
      }