Treat UART as Base

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: barthess, RoccoMarco

joaquin
Posts: 34
Joined: Sat Jan 22, 2011 8:44 pm

Treat UART as Base

Postby joaquin » Sun Dec 01, 2019 12:30 pm

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?

User avatar
Giovanni
Site Admin
Posts: 12296
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 590 times
Been thanked: 504 times
Contact:

Re: Treat UART as Base

Postby Giovanni » Sun Dec 01, 2019 3:16 pm

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


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 3 guests