Changing UART clock speed

Hello,

I am attempting to get MIDI communication over UART4 working. I have the device enabled via the overlay, and can communicate with it via /dev/ttyS4. However, the MIDI protocol runs at 31250 baud, and that is not a baud rate that can be used. Raspberry PI’s get around this by changing the UART clock frequency to scale down 38400 baud to 31250. This is exposed in a configuration variable. Does anybody know how I could do a similar thing here? I believe this should be possible, maybe by using the device tree overlay in some fashion. Any ideas? Thanks.

I have solved this problem. I found this code https://gist.github.com/sentinelt/3f1a984533556cf890d9 which lets you set arbitrary tty clock speeds. I then integrated it into ttymidi. Here is a fork - https://github.com/geneshuman/ttymidi . This opens /dev/ttySX at 31250 baud & creates a virtual alsa device, which is then available to the system. No need to mess around with the device tree or clocks.

2 Likes

Nice! Many thanks for sharing your solution.