Browse Source

Merge pull request #521 from KurtE/Teensy4_debug_printf_usb

Allow cores\teensy4 printf debug optionally go to USB
teensy4-core
Paul Stoffregen 3 years ago
parent
commit
a2ba2b5282
No account linked to committer's email address
2 changed files with 32 additions and 2 deletions
  1. +8
    -1
      teensy4/debug/printf.h
  2. +24
    -1
      teensy4/debugprintf.c

+ 8
- 1
teensy4/debug/printf.h View File

// #define PRINT_DEBUG_STUFF
// uncommenting the line below will enable the debug printf statements in cores\teensy4
// by default it will print to the Serial4 TX pin at baud rate of 115200
//#define PRINT_DEBUG_STUFF

// uncommenting the line below will switch to doing outputs to USB Serial or SEREMU instead of Serial4
// However some of the earlier print statements that happen before USB is initialized will be lost
// if you need those outputs, better to use Serial 4.
//#define PRINT_DEBUG_USING_USB // if both defined will try to direct stuff out USB Serial or SEREMU


#ifdef PRINT_DEBUG_STUFF #ifdef PRINT_DEBUG_STUFF
// defining printf this way breaks things like Serial.printf() in C++ :( // defining printf this way breaks things like Serial.printf() in C++ :(

+ 24
- 1
teensy4/debugprintf.c View File

#include "avr/pgmspace.h" #include "avr/pgmspace.h"
#include <stdarg.h> #include <stdarg.h>
#include "imxrt.h" #include "imxrt.h"
#include "usb_desc.h"


void putchar_debug(char c); void putchar_debug(char c);
static void puint_debug(unsigned int num); static void puint_debug(unsigned int num);
printf_debug(buf + i); printf_debug(buf + i);
} }


// first is this normal Serial?
#if defined(PRINT_DEBUG_USING_USB) && defined(CDC_STATUS_INTERFACE) && defined(CDC_DATA_INTERFACE)
#include "usb_dev.h"
#include "usb_serial.h"
FLASHMEM void putchar_debug(char c)
{
usb_serial_putchar(c);
}

FLASHMEM void printf_debug_init(void) {}

#elif defined(PRINT_DEBUG_USING_USB) && defined(SEREMU_INTERFACE) && !defined(CDC_STATUS_INTERFACE) && !defined(CDC_DATA_INTERFACE)
#include "usb_dev.h"
#include "usb_seremu.h"
FLASHMEM void putchar_debug(char c)
{
usb_seremu_putchar(c);
}

FLASHMEM void printf_debug_init(void) {}

#else
FLASHMEM void putchar_debug(char c) FLASHMEM void putchar_debug(char c)
{ {
while (!(LPUART3_STAT & LPUART_STAT_TDRE)) ; // wait while (!(LPUART3_STAT & LPUART_STAT_TDRE)) ; // wait
LPUART3_BAUD = LPUART_BAUD_OSR(25) | LPUART_BAUD_SBR(8); // ~115200 baud LPUART3_BAUD = LPUART_BAUD_OSR(25) | LPUART_BAUD_SBR(8); // ~115200 baud
LPUART3_CTRL = LPUART_CTRL_TE; LPUART3_CTRL = LPUART_CTRL_TE;
} }
#endif







Loading…
Cancel
Save