Page 1 of 1

Treat UART as Base

Posted: Sun Dec 01, 2019 12:30 pm
by joaquin
I have a mixed combination of serial devices (UART, USB, USART) on my board. I'd like to avoid having several functions depending of the kind of serial devices (SerialDriver, SerialUSBDriver, UARTDriver) for printing data or getting input (I need timeout for input). I saw the solution on the chprintf code, that uses an BaseSequentialStream device; it's a good idea to have generic channels for functions shared on all serial devices. However when I tried it testing on UARTD6 on a STM32F427, writing to either BaseSequentialStream or BaseChannel throwed an unhandled exception. When I use SD6 as SerialDriver it does work, but I that way I need to implement functions for every kind of device.

Code: Select all

      palSetPadMode(GPIOC, GPIOC_USART6_TX, PAL_MODE_ALTERNATE(8));
      palSetPadMode(GPIOC, GPIOC_USART6_RX, PAL_MODE_ALTERNATE(8));
      uartStart(&UARTD6, &uart6_cfg);
      // test
      uartStartSend(&UARTD6,1,(uint8_t *)"Hello"); // it works
      chprintf((BaseSequentialStream *)&UARTD6,"Hello"); //unhandled_exception
      chnWrite((BaseChannel *)&UARTD6, (uint8_t *)"Hello", 1); //unhandled_exception  (if skip previous line)

My question, how can I use generic channels on the three serial drivers types?

Re: Treat UART as Base

Posted: Sun Dec 01, 2019 3:16 pm
by Giovanni
Hi,

The UART driver does not implement the stream interface, it is not buffered and cannot do that. This is why the serial driver exists.

If you need streams then use SDx.

Giovanni