UART test

Topics regarding the Uzebox hardware/AVCore/BaseBoard (i.e: PCB, resistors, connectors, part list, schematics, hardware issues, etc.) should go here.
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: UART test

Post by D3thAdd3r »

UzeSynth was originally MIDI port only, and it had older custom UART code which was/is different than the new stuff being used for ESP8266/etc. I don't know if that ever got updated to the new UART, but baud rates would have to match. Would be worth just porting it to the new version if it isn't. The older implementation could also miss characters at times. The newer implementation should never miss a character unless you use too small a buffer and don't read it clean each frame.

Limited testing I recall 115200 worked, but seems on the edge and requires a good buffer . I'm assuming UzeSynth has a hard coded baud rate, so that would have to match or it won't work. In theory it should work without the MIDI port if you send 5V, since that port that is basically just for voltage/optical isolation standard to MIDI.

Use a good size buffer, MIDI messages can be relatively large depending on modifiers/parameters/etc. If you get gibberish, it's usually a baud mismatch.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: UART test

Post by Artcfox »

danboid wrote: Thu Feb 02, 2023 8:58 pm Have you got a USB serial adapter Artcfox?
I don't think I have any that are 5V. I haven't messed with the UART on the Uzebox at all.

After I opened my case to take photos of the board for your soldering thread, I re-applied glue in the stripped screw holes. I had glued it like that before, but my kids are used to wireless controllers and they strayed a bit too far away and pulled it off the coffee table, so while it was still unglued I was able to take photos of the board inside. I don't really want to re-crack the glue on it. My son cannot sit still while playing any game on any system. He jumps when his character jumps, and pretty much uses the entire room to play it. It's kinda funny to watch, but he doesn't always watch where he is going.
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

Uze has replied:

"Hi Dan,

It's been a while since I did MIDI stuff. I assume your are using this project: https://github.com/Uzebox/uzebox/tree/m ... /MusicDemo.

I don't think anyone used the UART directly, always going through a DAW and outputting to a hardware MIDI interface. But I think there is no reasons it shouldn't work. The only thing is the UART speed must be right with a MIDI interface. From your video you seem to be using 57600 baud but it must be 31250 bauds. For direct UART use, I don't see why 57600 would fail.

That said, there seems to be something fishy with the Uzesynth code in the sense that I can't find where the UART is actually enabled and speed is set (amongst other things). So that could explain things. I need to take out my midi interface and tests it out. In the mean time you could try enabling the uart that the beginning of MusicDemo.c and set the speed.
MIDI channels 1-5 maps to the Uzebox voices 0 to 4.

Alec

Edit: I've added some code that should enable the UART. Could not test it though, I have to find my FTDI cable."

He attached a patched MusicDemo.c that I shall be trying later.
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

Hi Alec

I rebuilt MusicDemo with the patched file that you sent and I tried using it with qtractor and ttymidi at baud rates of 57600, 38400, 19200 and 9600. My qtractor MIDI track is set to send on channel 1, program 1 and I can see the TX LED on my USB serial adapter pulse in time to the beat when I play the track so qtractor and ttymidi appear to be working together OK going off that but I have yet to see uzesynth respond at all to any MIDI over UART data I've been sending its way.

You said I should try 31250 baud. That's an odd number, if its not a typo. ttymidi is happy to run at 57600 and 38400 baud but not 31250. it gives the error:

Baud rate 31250 is not supported.

I shall try to do the same under Windows with a Windows equivalent to ttymidi and see if I have any more luck using reaper.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: UART test

Post by uze6666 »

I was just about to say that we really must bring this discussion in the forums for the benefit of everyone. :)

My last answer to Dan was that I found my FTDI USB-to-UART cable and was trying to see what is going on. For one, I realised that I removed the UART support in Uzesynth because I wanted to add the PCM channel (#5) and, at that time, either we didn't have the inline mixer or I could not fit the UART and channel 5 code in the inline mixer. So I reverted to using the vsync mixer. And because it's only invoked once every frame (60Hz), I could not poll the UART faster than that (other that doing in a while loop in the main program). In other words, it was pretty useless on a framework level. The good news is, since then and as you know, the inline mixer supports Channel 5 and UART at the same time.

So after a bit of fiddling, good news, it works (except for now the PCM channel for some reason). I have some refactored UART code pretty much ready to be moved to the kernel. As part of this, I plan to replace the whole content of the old kernel/uart.c and uart.h with the most recent code that were in UzeboxCore.c. I don't think anyone ever used those so let me know if you think it breaks some existing apps.

I've attached a quickly hacked C file that enabled the UART and can received MIDI data via the UART at arbitrary speed.

So in the MusicDemo project, replace the C file with the attached one and tweak the Makefile by using the following kernel settings:

Code: Select all

## Kernel settings
KERNEL_DIR = ../../../kernel
KERNEL_OPTIONS  = -DVIDEO_MODE=1 -DINTRO_LOGO=0 -DMIDI_IN=1 -DMODE1_FAST_VSYNC=0
KERNEL_OPTIONS += -DUART_RX_BUFFER_SIZE=256 -DUART=1 -DSOUND_MIXER=1 -DSOUND_CHANNEL_5_ENABLE=1
There's a little bit of code you can uncomment to just dump the UART RX data on the screen.
Anyhow, as a music composer, I'm very happy to see this old program running as it was when I made the Youtube video.

Edit: As a side note, after the UART code was working, I needed to send a sequence of bytes through my terminal representing a MIDI event. But of course, I could not remember anything about that. Did a Google search and it was that usual semi-depressing feeling: Shoot, I will need to scan through many pages of specs and random data to get my answer. Then I thought, huh, let's try ChatGPT. And sure enough:
Me: What's the byte sequence for a MIDI note on playing on channel 1

ChatGPT: A MIDI note on message on channel 1 is represented by the hexadecimal byte sequence 90, followed by the note number (for example, 60 for middle C), and the velocity (for example, 7F for maximum). So the full byte sequence for a MIDI note on message on channel 1 playing middle C at maximum velocity would be 90 3C 7F.

Mind blown. Now I understand with Google was freaking out. This is the future of search.


MusicDemo.hex
(95.89 KiB) Downloaded 74 times
MusicDemo.c
(6.63 KiB) Downloaded 81 times
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

Using Uze's latest Uzesynth, I can send MIDI data to it using ttymidi and qtractor. Fantastic! We are getting closer to fixing the Uzebox music workflow. I presume you will be commiting this to the Uzebox repo now I've tested it works for Linux users too.

I love how Uzesynth boots instantly! Take that *insert any modern MIDI player that requires a full OS to run*!

Now we need to extend Uzesynth so that it can load patch data off SD card and it needs a way to transfer new patch data onto the Uzebox via UART. I presume this is entirely possible but not at the same time as the UART is being used for MIDI, obviously. Currently, the user has to rebuild and reflash Uzesynth every time they want to change their patches which is not a nice workflow!

A quick and easy way to mute or reset any one of the channels would be very useful too, say if you could just scroll the Uzesynth menu pointer to the row that displays the numbers of the channels then could move an arrow left and right to mute or reset that channel.

Thanks and great work Alec!
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

This is how I see it might work:

Uzesynth requires at least two new menu options - 'Load patches from SD' and 'Receive patches from UART'. It would be cool if it was possible to use the 'Receive' option even if the user didn't have an SD card inserted to save the received patch set onto, there would ideally be the option to use whatever has been received (or typed in manually, if you have the PS2 keyboard adapter) without having to save it first. I am presuming there is nothing peculiar to the Uzebox kernel that might stop the UART being used alternately to receive MIDI or receive other data (ie the contents of a patch include file) within the same program?

On my PC, I might be preparing the patches in Uzebox patch studio. UPS outputs as text files so I'd just have to to put Uzesynth into receive mode, paste my patch data into a terminal running screen (when my Uzebox is connected up) and thats it, new patches transferred and ready to use in Uzesynth.
Last edited by danboid on Sun Feb 05, 2023 4:45 pm, edited 1 time in total.
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

I should've noted that I have to use:

Code: Select all

ttymidi -b 57600
To get it to work with Uzesynth and qtractor. I expect ttymidi defaults to 115200 baud but that doesn't work for me.

Being able to mute individual channels woud be nice but I suppose a kill switch that stops and resets everything is more important. You can also use the reset button for this I suppose but I'd like to be able to avoid that.
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

I have updated the UART wiki page with a Linux UART MIDI section that explains how to use the Uzebox as a MIDI controlled synth under Linux.

https://uzebox.org/wiki/UART

It doesn't look like Uze has committed his latest Uzesynth update to the Uzebox repo yet, which makes me think he might still be tweaking it?
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

The LinuxMusicians forum is likely to have a few people who'd enjoy messing with a Uzebox via MIDI so I've just done a post over there:

https://linuxmusicians.com/viewtopic.php?t=25408

No doubt there must be a few chiptune and retro gaming related forums who'd be into this too.
Post Reply