Using Serial.print() in exploring cores/teensy4 source code

lutzray

Member
I'm trying to understand the data flow around AudioInputUSB, placing here and there some Serial.println().

I can use it in usb_audio.cpp but in usb.c I'm getting compilation error as Serial not being declared: which header file should I include? If I'm right, T4 Serial.println() is specific to the Teensyduino extension?

merci
 
You want to be very careful doing that, since Serial itself is a USB device (relying on the usb.c code) and could easily cause a recursive loop or deadlock.
 
As mentione, you may have to be careful.

Also .c files are c language, not C++ so you don’t have classes, as such you can not call Serial.print…

there are some c functions defined for output, i am not at computer so can not look them up right now


// C language implementation
#ifdef __cplusplus
extern "C" {
#endif
void usb_serial_reset(void);
void usb_serial_configure(void);
int usb_serial_getchar(void);
int usb_serial_peekchar(void);
int usb_serial_available(void);
int usb_serial_read(void *buffer, uint32_t size);
void usb_serial_flush_input(void);
int usb_serial_putchar(uint8_t c);
int usb_serial_write(const void *buffer, uint32_t size);
int usb_serial_write_buffer_free(void);
void usb_serial_flush_output(void);
extern uint32_t usb_cdc_line_coding[2];
extern volatile uint32_t usb_cdc_line_rtsdtr_millis;
extern volatile uint32_t systick_millis_count;
extern volatile uint8_t usb_cdc_line_rtsdtr;
extern volatile uint8_t usb_cdc_transmit_flush_timer;
extern volatile uint8_t usb_configuration;
extern void serialEvent(void) __attribute__((weak));
#ifdef __cplusplus
}
#endif
 
Last edited:
You can also just use regular printf or fput functions, by default anything written to stdout or stderr goes to Serial.
 
OK, thanks for the warnings, I'll then use teensy4/debug/printf.h and listen on Serial4 . And thanks for the "C" vs "C++" remark... it shows my noobness! :)
 
Back
Top