Skip to content

Instantly share code, notes, and snippets.

@ExpandOcean
Created June 25, 2014 07:50
Show Gist options
  • Save ExpandOcean/c1d81f67f568cae781ba to your computer and use it in GitHub Desktop.
Save ExpandOcean/c1d81f67f568cae781ba to your computer and use it in GitHub Desktop.

Revisions

  1. ExpandOcean created this gist Jun 25, 2014.
    18 changes: 18 additions & 0 deletions trace.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
    #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
    #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))

    #define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
    #define TRCENA 0x01000000

    struct __FILE { int handle; /* Add whatever is needed */ };
    FILE __stdout;
    FILE __stdin;

    int fputc(int ch, FILE *f) {
    if (DEMCR & TRCENA) {
    while (ITM_Port32(0) == 0);
    ITM_Port8(0) = ch;
    }
    return(ch);
    }