'Android usb serial setting custom baud rate

I know how to set standard baud rates with the method UsbDeviceConnection.controlTransfer().
But how can I set a non standard baud rate, like 3000000 or 4000000?
This topic is little documented and I don't know how to do it.



Solution 1:[1]

I found how to do it:

controlTransfer(65, 30, 0, 0, new byte[]{-64, -58, 45, 0}, 0, 4, 5000);

(this is for 3000000 bps).
I found it by adding logs to the method controlTransfer() (and building the ROM), and using the apk Serial USB Terminal from google play.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1