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?