Porting to the Retevis RT50 (aka TYT MD-680D)

Discussions related to the firmware code development
VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Has anyone seen this IC in a chinese radio?

Post by VK3KYY » Tue Feb 14, 2023 12:28 am

EA5JAQ wrote:
Tue Feb 14, 2023 12:24 am
BTW, I might ask for help later with the rotary control. It's exactly the same as the MD-UV380/390 uses (not the one in the GD77S). I haven't figured out yet how it works, but first I need to make the firmware work and the radio boot up ;)
There seems to be some differnces in rotary encoders even if they look physically the same.

I forget the exact differences. I know one type, you set an interrupt when one pin changes from Low to High (or perhaps High to Low) and read the other pin. But the version in the RT3S seems to be different and generates multiple pulses.

The rotary encoder in my RT3S is terrible, it skips all the time :-(

Colin has tried many things to improve the functionality, but it still does not work well for me.


Anyway, initially just set an interrupt on when one pin changes and read the other pin.

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Has anyone seen this IC in a chinese radio?

Post by VK3KYY » Tue Feb 14, 2023 12:33 am

EA5JAQ wrote:
Tue Feb 14, 2023 12:22 am
VK3KYY wrote:
Mon Feb 13, 2023 10:48 pm
Another option for storage is to solder an I2S EEPROM to the I2S connections to the AT1846S. This is effectively what the GD-77 has, as both the EEPROM and AT1846S share the same I2S bus.

Or if you don't want GPS, then perhaps use the connectons to the AES chip
That's actually a great idea. I'll try to see if I can solder an EEPROM chip. Not to the AT1846S (the pins are really small and I already almost broke them while testing them), but to the AES chip, which is in the front and easily accessible. I think it won't interfere with the GPS, as this uses UART (but still, USB communication won't be possible). I could use the EEPROM for settings and to store some data from the codeplug that I could change from the radio itself (like per-channel power, etc).

Or maybe it'll be simpler just to avoid the hardware change and just use the 16 kB extra I get by not using a bootloader and the 20 or so kB I estimate I'll get by removing the language strings. Having those 36 kB of ROM should be enough for a simple codeplug and the settings (the AT24C512C has 64 kB if I remember correctly).

This radio has no screen so many of the things that take up a lot of space (channel, contact and zone names, mainly) are not needed.
Use a larger EEPROM if possible. The entire codeplug does not fit in the EEPROM on the GD77. I think the codeplug is at least 128k, but also because of the terrible programming in the official firmware, the lower part of the Flash is not used, becauase it is mapped to the same address space as the EEPROM

So the firmware uses the lower part of the Flash for additional settings like the boot melody and boot image.

Perhaps you can find a 256k EEPROM

It may be possible to interface to a Flash chip via I2S,but you would need to rewrite all the Flash interface code, because it uses SPI in the GD77 and you can't use SPI because the bus to the AES chip is I2S and there are only 2 data pins.

EA5JAQ
Posts: 86
Joined: Thu Jul 16, 2020 6:08 am

Re: Has anyone seen this IC in a chinese radio?

Post by EA5JAQ » Tue Feb 14, 2023 12:54 am

VK3KYY wrote:
Tue Feb 14, 2023 12:28 am
I forget the exact differences. I know one type, you set an interrupt when one pin changes from Low to High (or perhaps High to Low) and read the other pin. But the version in the RT3S seems to be different and generates multiple pulses.

The rotary encoder in my RT3S is terrible, it skips all the time :-(

Colin has tried many things to improve the functionality, but it still does not work well for me.


Anyway, initially just set an interrupt on when one pin changes and read the other pin.
Yeah, a couple days ago I checked the OpenRTX source and that was my first guess. But I didn't look much into it, as first I need a working firmware and then I'll start adding functionality.

I think the GD77S used a 4-bit encoder with 16 positions, while the one in my radio, rt3s, etc just has two pins. So I'll just try with the interrupts.
VK3KYY wrote:
Tue Feb 14, 2023 12:33 am
It may be possible to interface to a Flash chip via I2S,but you would need to rewrite all the Flash interface code, because it uses SPI in the GD77 and you can't use SPI because the bus to the AES chip is I2S and there are only 2 data pins.
Now that I remember, there are several terminals on the right side of the pcb (you can see them in the second pic), 5 of them are connected to 5 available GPIO pins, so I could potentially use them to connect an SPI flash. Originally, they were used to connect another pcb (kind of like the Raspberry Pi hats are connected) that provided voice scrambling.

That would be interesting. I'd have the flash connected there and the EEPROM to the I2C pins of the AES chip. That way, the radio could just "pretend" it's a GD77 when connected to the CPS, and the codeplug could be copied to the flash and eeprom without modifying anything in the CPS. I could even have voice prompts! Still, I'll have to flash the MCU using SWD, but I won't have to do it to change the codeplug. A massive improvement.

If I can get the USB communication working (and not interfering with the GPS), I'll definitely explore this option.

Thank you so much.

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Has anyone seen this IC in a chinese radio?

Post by VK3KYY » Tue Feb 14, 2023 2:33 am

EA5JAQ wrote:
Tue Feb 14, 2023 12:54 am
VK3KYY wrote:
Tue Feb 14, 2023 12:28 am
I forget the exact differences. I know one type, you set an interrupt when one pin changes from Low to High (or perhaps High to Low) and read the other pin. But the version in the RT3S seems to be different and generates multiple pulses.

The rotary encoder in my RT3S is terrible, it skips all the time :-(

Colin has tried many things to improve the functionality, but it still does not work well for me.


Anyway, initially just set an interrupt on when one pin changes and read the other pin.
Yeah, a couple days ago I checked the OpenRTX source and that was my first guess. But I didn't look much into it, as first I need a working firmware and then I'll start adding functionality.

I think the GD77S used a 4-bit encoder with 16 positions, while the one in my radio, rt3s, etc just has two pins. So I'll just try with the interrupts.
VK3KYY wrote:
Tue Feb 14, 2023 12:33 am
It may be possible to interface to a Flash chip via I2S,but you would need to rewrite all the Flash interface code, because it uses SPI in the GD77 and you can't use SPI because the bus to the AES chip is I2S and there are only 2 data pins.
Now that I remember, there are several terminals on the right side of the pcb (you can see them in the second pic), 5 of them are connected to 5 available GPIO pins, so I could potentially use them to connect an SPI flash. Originally, they were used to connect another pcb (kind of like the Raspberry Pi hats are connected) that provided voice scrambling.

That would be interesting. I'd have the flash connected there and the EEPROM to the I2C pins of the AES chip. That way, the radio could just "pretend" it's a GD77 when connected to the CPS, and the codeplug could be copied to the flash and eeprom without modifying anything in the CPS. I could even have voice prompts! Still, I'll have to flash the MCU using SWD, but I won't have to do it to change the codeplug. A massive improvement.

If I can get the USB communication working (and not interfering with the GPS), I'll definitely explore this option.

Thank you so much.

Re: Rotary swicth
OK. AFIK the GD-77S has 4 GPIO pins which signify the value that is selected.
The source code for the GD77S version is part of the GD77 via conditional compilation

If the rotary switch is similar to the MD9600 / UV380, you will need to do some experiments to determine the exact type of rotary encoder hardware is fitted to the radio.


Unfortunately developing firmware for each radio takes a very long time, even if there is some information e.g. schematics for that radio.
In this case theres does not seem to be any information on the web, even about the GPIO pin connections.

What I did one some other radios is write a pin scanning function, which writes to Segger RTT Print. It constantly scans all pins and prints if any pin changes its value.

I could then just press buttons on the radio e.g. PTT and see which pin is connected.

Or for other pins e.g. C6000 I tried manually pulling each pin high via 10k using a probe

For the LEDS, I traced the signal connection on the board, and I also did this for the audio amp and other things like the Rx preamp
However for teh Rx Preamp, I still did not know which is VHF and which is for UHF, so I had to enabled VHF and then enable UHF and compare signal RSSI readings, to see which preamp worked best for each band.

As you know it takes many hours / days / months to fully understand the radio hardware.

EA5JAQ
Posts: 86
Joined: Thu Jul 16, 2020 6:08 am

Re: Has anyone seen this IC in a chinese radio?

Post by EA5JAQ » Tue Feb 14, 2023 3:13 am

VK3KYY wrote:
Tue Feb 14, 2023 2:33 am
What I did one some other radios is write a pin scanning function, which writes to Segger RTT Print. It constantly scans all pins and prints if any pin changes its value.
My method was a bit more rudimentary :lol: I used a multimeter to test for continuity pin by pin. Then I could find out what each pin does and correct gpio.h, but it took me ages.
VK3KYY wrote:
Tue Feb 14, 2023 2:33 am
For the LEDS, I traced the signal connection on the board, and I also did this for the audio amp and other things like the Rx preamp
However for teh Rx Preamp, I still did not know which is VHF and which is for UHF, so I had to enabled VHF and then enable UHF and compare signal RSSI readings, to see which preamp worked best for each band.
For this radio, finding the preamps was a bit easier, as it's UHF-only. I left the radio on with the stock firmware while receiving, and the only one that was on was the Rx one.

However, the radio has three preamps, each connected to a different GPIO pin. One of them is definitely the Rx one, the other two are turned on in Tx, but I can't figure out why there's two of them (the DM-1801 only turns one on, as far as I know). Maybe it's because it's 10W, but it doesn't make any sense... I still need to do some more testing.

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Has anyone seen this IC in a chinese radio?

Post by VK3KYY » Tue Feb 14, 2023 3:35 am

EA5JAQ wrote:
Tue Feb 14, 2023 3:13 am
.... but I can't figure out why there's two of them (the DM-1801 only turns one on, as far as I know). Maybe it's because it's 10W, but it doesn't make any sense... I still need to do some more testing.
I think the UV380 has multiple GPIO's which need to be enabled when transmitting, or receiving, but we don't know why

EA5JAQ
Posts: 86
Joined: Thu Jul 16, 2020 6:08 am

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by EA5JAQ » Tue Feb 14, 2023 12:45 pm

VK3KYY wrote:
Tue Feb 14, 2023 3:35 am
I think the UV380 has multiple GPIO's which need to be enabled when transmitting, or receiving, but we don't know why
Good. The more I investigate this hardware, the more I'm sure it's in some kind of middle ground between the GD77 and the MD-UV3x0. It uses the same rotary and a similar amp section to the latter, and also an identical battery pack, but inside it has the MK22 MCU.

In fact, there was a previous version to this radio (the MD-680) that was non-waterproof and had a slightly smaller battery. More or less what happens between the MD-UV380 and 390.

Anyway, I just bought a couple AT24C512 and W25Q64 modules (originally intended for arduino, so it'll be easier to solder them rather than a small chip) and as soon as I receive them I'll solder them and that'll make waaaay easier the coding part. It makes much more sense than storing the codepug in hard-coded variables, as that'll enable the radio to be programed via the CPS, have voice prompts, etc.

The only thing I have to check is whether the 25Q64 can be connected via SPI to the ports C0, C3, C5, C6 and C14, which are the ones that are wired to the terminals on the side. But I believe that won't be problematic. The AT24C512 can be easily connected in parallel to the AES chip I2C pins.

I'll also be receiving an ATGM336H UART GPS chip, which I'll wire to the UART terminals at the bottom of the PCB (and the ON/OFF pin to whatever GPIO pin I can find available). As the UART and USB pins of the MK22 are connected together in this radio, I'll have to make sure the GPS module is off before connecting the usb to a computer, so they don't interfere with each other.

This is starting to look really promising. It could mean that only with a slight hardware modification (just adding the flash and eeprom, way easier than the mods you have to do to have M17 with the OpenRTX firmware, which in my opinion are too hard just for an experimental mode) the radio could be fully compatible with OpenGD77. So this could be useful not only to me, but to anyone willing to make this mod to the radio and flash the firmware via SWD.

Thank you so much, I will be posting my findings here as soon as I get everything.

EA5JAQ
Posts: 86
Joined: Thu Jul 16, 2020 6:08 am

Re: Porying to the Retevis RT50 (aka TYT MD-680D)

Post by EA5JAQ » Tue Feb 14, 2023 2:48 pm

A bit tricky to solder, but it might just work ;) Hope I'm not too crazy :lol:

***pinout deleted, will add it back when it's corrected***

I checked and I think there's enough space in that part of the radio to fit all the components (there's no keyboard or anything so the front bottom part is empty
Last edited by EA5JAQ on Wed Feb 15, 2023 5:01 pm, edited 1 time in total.

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Porying to the Retevis RT50 (aka TYT MD-680D)

Post by VK3KYY » Tue Feb 14, 2023 8:09 pm

Do you plan to connect a better display

EA5JAQ
Posts: 86
Joined: Thu Jul 16, 2020 6:08 am

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by EA5JAQ » Wed Feb 15, 2023 5:00 pm

VK3KYY wrote:
Tue Feb 14, 2023 8:09 pm
Do you plan to connect a better display
Not really, as I'd have to make a hole in the casing. The stock screen is kind of "hidden" behind the case, and only appears when it's on. I think it's kind of cool. A better display would add more functionality but as I use this radio as a kind of simple and hard platform to use in the mountain, etc it's enough for me. If I want more functionality I can always use the MD-UV390 (in fact, the battery pack is the same).

BTW I'm deleting the pinout I posted before. One of the connectors on the side is a UART1 RX pin, so that would make more sense instead of connecting the GPS to UART0, whose pins are connected together with USB and the PTT button, and the GPS would interfere. This radio is extremely badly designed, I'd like to meet the person who thought that connecting the PTT, USB_DP, and UART0_RX together was a good idea. If you press PTT while loading a codeplug, the communication with the radio is lost.

I also realised that the C6000's U SPI is not connected to SPI0 pins like in the DM-1801, etc. It's connected to random GPIO pins (like the flash memory in the rest of platforms). I suppose I'll have to re-write all the C6000 SPI0 code in a similar way to how the communication with the flash chip is handled (I think it's called bit-banging, but I've never used it, that's a chance to learn something new). I'm sure there will be some code on GitHub I can use, or the Flash SPI code itself. Won't be too hard.

At least the problems I'm encountering can be solved... for now

Post Reply