Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal semihosted ARM Cortex-M "Hello World"
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CROSS_COMPILE ?= arm-none-eabi- | ||
CC := $(CROSS_COMPILE)gcc | ||
CFLAGS = -fno-common -O0 -std=gnu99 \ | ||
-mcpu=cortex-m3 -mthumb \ | ||
-T semi.ld -nostartfiles \ | ||
|
||
TARGET = semi.bin | ||
all: $(TARGET) | ||
|
||
$(TARGET): semi.c startup.c | ||
$(CC) $(CFLAGS) $^ -o semi.elf | ||
$(CROSS_COMPILE)objcopy -Obinary semi.elf semi.bin | ||
$(CROSS_COMPILE)objdump -S semi.elf > semi.list | ||
|
||
qemu: $(TARGET) | ||
@qemu-system-arm -M ? | grep stm32-p103 >/dev/null || exit | ||
@echo "Press Ctrl-A and then X to exit QEMU" | ||
@echo | ||
qemu-system-arm -M stm32-p103 -semihosting -nographic -kernel semi.bin | ||
|
||
clean: | ||
rm -f *.o *.bin *.elf *.list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <stdint.h> | ||
|
||
static int semihost_call(int service, void *opaque) | ||
{ | ||
register int r0 asm("r0") = service; | ||
register void *r1 asm("r1") = opaque; | ||
register int result asm("r0"); | ||
asm volatile("bkpt 0xab" | ||
: "=r" (result) : "r" (r0), "r" (r1)); | ||
return result; | ||
} | ||
|
||
enum SEMIHOST_SVC { | ||
SYS_WRITE = 0x05, | ||
}; | ||
|
||
void main(void) | ||
{ | ||
char message[] = "Hello World!\n"; | ||
uint32_t param[] = { 1, (uint32_t) message, sizeof(message) }; | ||
semihost_call(SYS_WRITE, (void *) param); | ||
while (1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ENTRY(reset_handler) | ||
|
||
MEMORY | ||
{ | ||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K | ||
} | ||
|
||
SECTIONS | ||
{ | ||
.text : | ||
{ | ||
KEEP(*(.isr_vector)) | ||
*(.text) | ||
} >FLASH | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdint.h> | ||
|
||
extern void main(void); | ||
void reset_handler(void) | ||
{ | ||
/* jump to C entry point */ | ||
main(); | ||
} | ||
|
||
__attribute((section(".isr_vector"))) | ||
uint32_t *isr_vectors[] = { | ||
0, | ||
(uint32_t *) reset_handler, /* code entry point */ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a89bd60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't exit qemu-stm32 via "Ctrl A+X"
My computer environment is x64 Lubuntu 14.04
a89bd60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should press Ctrl-A and release the keys. Then, press 'X'.
a89bd60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,I ask a stupid question 0_0