I'm completely new to ChibiOS, and I just inherited a ChibiOS 2.4.0 project. The board with an STM32F407 CPU has both and RS-232 and RS-485 transceiver ICs that are muxed together on USART1. Up until this time, only the RS-232 portion has been used, along with the HAL serial driver (not the UART). Now I want to enable the RS-485 section. This is a half-duplex setup, and I have to enable the transmit driver when sending data, and disable the transmit driver when the transmission is done. I can set the enable bit right before I begin the transmission, but I need a way to know when the last bit has gone out the wire, so I can disable the driver, and listen for more commands. From the searching I've done on the 'net and this forum, it appears that there is an event called "IO_TRANSMISSION_END" that sounds like it would be just what I'm looking for. It looks like that event was added in ChibiOS 2.3.0. But I'm not quite sure about the details. Could someone point me in the direction of the documentation or examples that could help me understand what events are possible from the Serial driver, and how they get used? Am I getting close with the code snippet below?
Code: Select all
/*
* Thread for putting RS-485 driver back into Hi-Z state after transmission.
*/
static WORKING_AREA(waThread4, 128);
static msg_t Thread4(void *arg) {
EventListener el1;
(void)arg;
chRegSetThreadName("RS-485 Enable");
chEvtRegisterMask(chnGetEventSource(&SD1), &el1, IO_TRANSMISSION_END);
while (TRUE) {
chEvtWaitOne(IO_TRANSMISSION_END);
chEvtGetAndClearFlags(&el1); //is this necessary?
palClearPad(GPIOA, RS485MYLINE); //Disable TX driver.
}
} ...fwiw, I've found these messages with some related and similar content.
serial write completion and documentation mismatch
sdWrite only two bytes
Issues with Serial and Event
STM32 sd Spurious Character
Thanks,
Greg