Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: RPi2 UART Baud Rate

Mon Feb 29, 2016 11:51 am

The information about mmap() provided here works for Arch Linux kernel 4.1.13. I've not updated my kernel because I have the Cirrus/Element14 sound board and the driver comes as part of a pre-patched kernel. I currently have it running with the console UART port at 31250 baud. The "hack" uses the mmap() function to give access to the UART device registers directly which bypasses whatever they did in the kernel. Instead of changing the UART clock, the code instead leaves the UART clock at 3000000 and instead uses a clock divider of 6. This sets the bit clock at 3000000/6 or 500000 which just happens to be 16 times 31250.

I used the code posted by StuartF to first get ttymidi working at 31250. There were a couple of things missing from the code that StuartF kindly provided (all documented in this thread). And yes, once I got the code to compile, ttymidi stopped producing crap data. I used ZynAddSubFX to test it.

Currently, I've developed my own MIDI synthesizer (a 32 voice Karplus-Strong Synth) that uses the same technique to change the UART baud rate to 31250.

Unfortunately, it's not just a simple function call and your done, you have to understand what ttymidi is doing to set the UART up and modify it with the mmap() method. I would prefer not to post my ttymidi code because I don't feel I'm qualified to add to the project (which is where the code ought to be posted).
Last edited by JovianPyx on Mon Feb 29, 2016 12:30 pm, edited 1 time in total.

Posts: 6
Joined: Fri Mar 06, 2015 10:22 pm

Re: RPi2 UART Baud Rate

Mon Feb 29, 2016 12:25 pm

Thanks for your prompt answer JovianPyx!

I can imagine that it isn't as easy to cut/paste the code provided by StuartF in ttymidi.c and compile it to be done :roll: ...
Actually I don't know what to do with this piece of code.
Is there another way to make ttymidi working at 31250?

From what I understood in previous messages, the trick using Python script is not really working since ttymidi re-assigns baud rate when it is launched isn't it?


Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: RPi2 UART Baud Rate

Mon Feb 29, 2016 12:36 pm

Yeah, I tried the Python code and it did not work as you say because ttymidi just over-writes the settings. Please see the PM I sent you.

Posts: 4
Joined: Mon Mar 07, 2016 5:31 am

Re: RPi2 UART Baud Rate

Mon Mar 07, 2016 10:58 am

I've had same problems with my Rpi 2. Whatever settings I've put in cmdline.txt and config.txt the results have been the same. I'll test this next time I have time but if this works you're my hero!

Return to “Interfacing (DSI, CSI, I2C, etc.)”