Created
November 27, 2016 07:48
-
-
Save louisom/5ffd9942be135d5d2d789030ce1181c7 to your computer and use it in GitHub Desktop.
Example semihosting code for Cortex-M4 stm32f429
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
#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_WRITEC = 0x03, | |
SYS_WRITE0 = 0x04, | |
SYS_WRITE = 0x05, | |
}; | |
void putchar(uint8_t chr) | |
{ | |
semihost_call(SYS_WRITEC, &chr); | |
} | |
void puts(uint8_t *str) | |
{ | |
semihost_call(SYS_WRITE0, str) | |
} | |
void print(uint8_t msg[]) | |
{ | |
uint32_t param[] = {1, (uint32_t) message, sizeof(message)}; | |
semihost_call(SYS_WRITE, (void *) param); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment