USE KERNEL 3.8.13. I spent days trying to figure out why 4.4.1/2/3-bone-rt-5 wasn’t working. Selecting the omap-serial driver (rather than the 8250-omap driver) won’t work because some of the rs485 patches didn’t get included in later kernels.
Since last Thursday, my job was getting RS485 working on BBB.
I used a MikroElectrinika MikroBUS cape*, and an RS485 Click** plugged into mikroBUS socket 1. I actually rather like this setup.
*http://www.mikroe.com/click/mikrobus-cape/
**http://www.mikroe.com/click/rs485-3.3v/
For mikroBUS socket 1, RX and TX pins are routed to the Sitara uart2, and the data direction control connects to J9 pin 14 (a.k.a gpio1[18], a.k.a. “echo 50 >/sys/class/gpio/exports”). It’s only necessary to load the BB-UART2 overlay (“echo BB-UART2 >/sys/devices/capemgr.*/slots” or “capemgr.enable_partno=BB-UART2” in the uEnv.txt boot file) and do your programming.
Use this for the RS485 setup structure:
struct omap_serial_rs485 {
__u32 flags; /* RS485 feature flags /
#define OMAP_SER_RS485_ENABLED (1 << 0) / If enabled /
#define OMAP_SER_RS485_RTS_ON_SEND (1 << 1) / Logical level for
RTS pin when
sending /
#define OMAP_SER_RS485_RTS_AFTER_SEND (1 << 2) / Logical level for
RTS pin after sent*/
#define OMAP_SER_RS485_RTS_BEFORE_SEND (1 << 3)
#define OMAP_SER_RS485_USE_GPIO (1 << 5)
__u32 delay_rts_before_send; /* Delay before send (milliseconds) /
__u32 delay_rts_after_send; / Delay after send (milliseconds) /
__u32 gpio_pin; / GPIO Pin Index /
__u32 padding[4]; / Memory is cheap, new structs
are a royal PITA … */
};
… because the omap-serial rs485 patches slightly enhanced the regular struct serial_rs485 you find in sys/serial.h
Here’s my rs485 setup code (error checking omitted):
struct omap_serial_rs485 rs485;
i = ioctl(m_fd, TIOCGRS485, &rs485); // whats’ the current setup?
rs485.flags |= OMAP_SER_RS485_ENABLED; // Enable RS485 mode
rs485.flags |= OMAP_SER_RS485_USE_GPIO; // use a GPIO pin for
// direction control
rs485.flags &= ~(OMAP_SER_RS485_RTS_AFTER_SEND|OMAP_SER_RS485_RTS_ON_SEND);
rs485.delay_rts_before_send = 0; // No delay from RTS-assert before xmit
rs485.delay_rts_after_send = 0; // No delay after xmit until RTS-negate
rs485.gpio_pin = m_pin; // select the direction control pin
i = ioctl(m_fd, TIOCSRS485, &rs485); // establish
I built and installed kernel 3.8.13-bone79 this morning. Finally I’m working well.