STM32F407 and USB / UART goes into idle thread forever
Posted: Tue Feb 02, 2021 6:49 pm
I have a working USB chprintf environment. However if I disconnect putty, after a buffer becomes full, it goes into a forever idle thread. Can I get the USB com port to discard data if putty is not there to take it? I would like to connect putty, see data scroll by, then disconnect putty and have the STM32 keep operating like normal.
Here is a simplified snippet of my code as it stands now. The function "ProcessSerial" will transfer data back and forth between 2x SPI channels and an USART channel. The USB printf is just for debugging purposes. My program functions as expected as long as a terminal is connected via the USB.
I have debug enabled, and I stepped through chprintf. However it is written at a higher level than I was able to understand. So I was not able to identify if I could some how prevent the full buffer.
Perhaps I can change a parameter in usbcfg.c or similar to disable the handshake and prevent the full buffer. I'm OK with discarding extra data.
This is ChibiOS 20.3 with GCC 7.0
Here is a simplified snippet of my code as it stands now. The function "ProcessSerial" will transfer data back and forth between 2x SPI channels and an USART channel. The USB printf is just for debugging purposes. My program functions as expected as long as a terminal is connected via the USB.
Code: Select all
// Make printf more normal.
#define printf(...) chprintf((BaseSequentialStream *)&SDU1, __VA_ARGS__)
...
int main(void) {
halInit();
chSysInit();
// Activates the USB serial driver and then the USB bus pull-up on D+.
// Note, a delay is inserted in order to not have to disconnect the cable after a reset.
sduObjectInit(&SDU1); // Clear the buffer to prevent old data from propagating.
sduStart(&SDU1, &serusbcfg);
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(2500);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(2500);
printf("Just booted Version 1\r\n");
while (true) {
...
ProcessSerial((unsigned char*)buffer); // <<<< Several printf's happen in this sub routine.
...
} // while true
I have debug enabled, and I stepped through chprintf. However it is written at a higher level than I was able to understand. So I was not able to identify if I could some how prevent the full buffer.
Perhaps I can change a parameter in usbcfg.c or similar to disable the handshake and prevent the full buffer. I'm OK with discarding extra data.
This is ChibiOS 20.3 with GCC 7.0