Skip to content

Instantly share code, notes, and snippets.

@louisom
Created November 27, 2016 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisom/5ffd9942be135d5d2d789030ce1181c7 to your computer and use it in GitHub Desktop.
Save louisom/5ffd9942be135d5d2d789030ce1181c7 to your computer and use it in GitHub Desktop.
Example semihosting code for Cortex-M4 stm32f429
#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