瀏覽代碼

Merge pull request #521 from KurtE/Teensy4_debug_printf_usb

Allow cores\teensy4 printf debug optionally go to USB
main
Paul Stoffregen 3 年之前
父節點
當前提交
a2ba2b5282
沒有連結到貢獻者的電子郵件帳戶。
共有 2 個檔案被更改,包括 32 行新增2 行删除
  1. +8
    -1
      teensy4/debug/printf.h
  2. +24
    -1
      teensy4/debugprintf.c

+ 8
- 1
teensy4/debug/printf.h 查看文件

@@ -1,4 +1,11 @@
// #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
// defining printf this way breaks things like Serial.printf() in C++ :(

+ 24
- 1
teensy4/debugprintf.c 查看文件

@@ -5,6 +5,7 @@
#include "avr/pgmspace.h"
#include <stdarg.h>
#include "imxrt.h"
#include "usb_desc.h"

void putchar_debug(char c);
static void puint_debug(unsigned int num);
@@ -70,6 +71,28 @@ static void puint_debug(unsigned int num)
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)
{
while (!(LPUART3_STAT & LPUART_STAT_TDRE)) ; // wait
@@ -83,7 +106,7 @@ FLASHMEM void printf_debug_init(void)
LPUART3_BAUD = LPUART_BAUD_OSR(25) | LPUART_BAUD_SBR(8); // ~115200 baud
LPUART3_CTRL = LPUART_CTRL_TE;
}
#endif




Loading…
取消
儲存