Comment out some of the main programs debug print statements plus add yield call to main loop. yield can now call SerialEvent. Put hack in that if the user has not overwritten the SerialEvent function, the weak linked one will turn off calling itself...teensy4-core
tempmon_init(); | tempmon_init(); | ||||
while (millis() < 300) ; // wait at least 300ms before calling user code | while (millis() < 300) ; // wait at least 300ms before calling user code | ||||
printf("before C++ constructors\n"); | |||||
//printf("before C++ constructors\n"); | |||||
__libc_init_array(); | __libc_init_array(); | ||||
printf("after C++ constructors\n"); | |||||
printf("before setup\n"); | |||||
//printf("after C++ constructors\n"); | |||||
//printf("before setup\n"); | |||||
setup(); | setup(); | ||||
printf("after setup\n"); | |||||
//printf("after setup\n"); | |||||
while (1) { | while (1) { | ||||
//printf("loop\n"); | //printf("loop\n"); | ||||
loop(); | loop(); | ||||
yield(); | |||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
#endif // F_CPU | #endif // F_CPU | ||||
uint8_t usb_enable_serial_event_processing = 1; | |||||
void serialEvent() __attribute__((weak)); | void serialEvent() __attribute__((weak)); | ||||
void serialEvent() {} | |||||
void serialEvent() {usb_enable_serial_event_processing = 0;} |
extern volatile uint8_t usb_cdc_line_rtsdtr; | extern volatile uint8_t usb_cdc_line_rtsdtr; | ||||
extern volatile uint8_t usb_cdc_transmit_flush_timer; | extern volatile uint8_t usb_cdc_transmit_flush_timer; | ||||
extern volatile uint8_t usb_configuration; | extern volatile uint8_t usb_configuration; | ||||
extern uint8_t usb_enable_serial_event_processing; | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
} | } | ||||
#endif | #endif |
if (running) return; // TODO: does this need to be atomic? | if (running) return; // TODO: does this need to be atomic? | ||||
running = 1; | running = 1; | ||||
// USB Serail - Add hack to minimize impact... | |||||
if (usb_enable_serial_event_processing && Serial.available()) serialEvent(); | |||||
// Current workaround until integrate with EventResponder. | // Current workaround until integrate with EventResponder. | ||||
HardwareSerial::processSerialEvents(); | HardwareSerial::processSerialEvents(); | ||||