Skip to content

deividAlfa/Alfa-166-CD-Changer-Unilink-Emulator

Repository files navigation

Alfa romeo 166 unilink CD changer emulator.

Introduction

This project aims to make a CD changer emulator for the Alfa Romeo 166.
If you want to learn how Unilink works, check DOCS folder, everything I learned came from there.
There's little information about Unilink on the net, most sites are long gone, some were dated back to the year 2000!
I could recover some thanks to www.archive.org.

Credits:

Project description

This project enables communication with the ICS emulating the presence of the CD changer.
It uses a STM32 "blackpill" board with STM32F411 running at 96MHz.
It's currently working pretty well, but there might be some bugs or wrong / unimplemented functions.
The project is done in STM32 Cube IDE and uses ST's HAL Library.
Part of the configuration is done in the .ioc file (CubeMX configuration).

Features

  • Unilink is handled using the SPI peripheral with interrupts.
  • Handles most of the Unilink protocol used in the ICS.
  • Uses the USB OTG function and it's able to play MP3 files from a USB drive.
    • Must be FAT32-formatted.
    • Songs must be stored inside CD01 ... CD06 folders.
    • Automatically scans these folders and its contents, and makes a listing for the ICS.
    • Tested up to 320Kbps without issues.
  • It's able to change tracks, discs, notify empty CD slots, etc, just like the original CD changer.
  • Repeat / Shuffle / Intro modes are not implemented.
  • Send the decoded audio to a I2S DAC.
    I used a PCM5102A, but better use a UDA1334A as it has lower output signal, see Issues.

Issues

The PCM5102A outputs 2Vrms, which is too much for the ICS input and will cause distortion.
Use the UDA1334A instead, it's a readily available alternative which should work much better, it outputs 0.9Vrms.
To fix the PCM5102A level, you need to halve the amplitude and buffer the signal.
Driving the audio input directly with the resistor divider will lead to a very poor sound quality!
Check the circuit below the PCM5102A connections.

Compiling

To compile:

  • Download STM32 Cube IDE. This project was made with v1.12.1, so better use that.
    ST has removed this version from their site, you can get it here.
  • Clone or download the repository.
  • Open STM32 Cube IDE, import existing project and select the folder where the code is.

It should recognize it and be ready for compiling or modifying for your own needs.

IMAGE

Use any programmer supporting SWD (ST-Link, J-Link, DAP-Link...).
You can also using the embedded bootloader (DFU): Download Cube Programmer.
Hold BOOT0 button down, connect the usb to the computer, release the button when detected.
After compiling, flash the binary with the tool, it'll be located in Release folder (.hex, .elf, .bin).

Working options

The settings are placed in config.h.

  • PASSIVE_MODE - Will disable the slave interface and set the device in sniffer mode.
    In this mode it can output the dialog between the ICS and the CD changer.

  • AUDIO_SUPPORT - Enable USB handling and MP3 decoding, fully integrated into Unilink.
    Needs a DAC to decode the I2S stream and possibly some signal conditioning.

  • BT_SUPPORT - Adds support for controlling a bluetooth module. Ideally this would be used with a module supporting AT commands, but this wasn't my case, so it's very specific.
    In my case I modified a RRD-305 module and customized both button inputs and LED outputs for my needs.

  • Alternatively, it can be used as Aux-in enabler and can connect any audio source into the CD input.
    For this, disable PASSIVE_MODE, AUDIO_SUPPORT and BT_SUPPORT (Add // before each #define).
    Connect power and unilink signals, this will be enough to keep the ICS happy.

Debugging

  • UNILINK_LOG_ENABLE - Prints Unilink frames.

  • UNILINK_LOG_DETAILED - Decodes and prints what each frame means.

  • UNILINK_LOG_TIMESTAMP - Adds timestamps to each frame.

  • UART_PRINT - Enables serial port logging to PA9 pin, 1Mbit baudrate.

  • SWO_PRINT - Enables SWO pin logging.
    Connect the ST-Link to the STM32 (SWC=PA14 SWD=PA13 SWO=PB3).
    Open Printf SWO viewer in ST-Link utility, set core clock to 96000000Hz.

  • USB_LOG - Enables USB logging, creating a file log.txt.

UNILINK_LOG_DETAILED disabled:

31 10 01 13 55
10 31 97 01 D9 79 99 59 10 54
31 10 01 13 55
70 31 90 00 31 02 00 41 1A 8E
31 10 84 95 5A 10 00 00 00 6A
10 31 95 B0 86 00 00 00 06 8C
31 10 01 12 54
10 31 00 00 41

UNILINK_LOG_DETAILED enabled:

<< [31 10 01 13][55]                                    MASTER REQUEST: Slave poll
  #[10 31 97 01][D9][79 99 59 10][54]                   DISC INFO: Disc:1 Tracks:79 99m:59s
<< [31 10 01 13][55]                                    MASTER REQUEST: Slave poll
  #[70 31 90 00][31][02 00 41 1A][8E]                   TIME: Disc:1 Track:02 00:41
<< [31 10 84 95][5A][10 00 00 00][6A]                   REQUEST FIELD: MAGAZINE INFO
  #[10 31 95 B0][86][00 00 00 06][8C]                   MAGAZINE INFO: CD1:Y CD2:Y CD3:N CD4:Y CD5:N CD6:N
<< [31 10 01 12][54]                                    MASTER REQUEST: Time poll
  #[10 31 00 00][41]                                    STATUS: Playing

UNILINK_LOG_TIMESTAMPS enabled:

00:02:04.957    << [31 10 01 13][55]                                    MASTER REQUEST: Slave poll
00:02:04.970      #[10 31 97 01][D9][79 99 59 10][54]                   DISC INFO: Disc:1 Tracks:79 99m:59s
00:02:05.087    << [31 10 01 13][55]                                    MASTER REQUEST: Slave poll
00:02:05.100      #[70 31 90 00][31][02 00 41 1A][8E]                   TIME: Disc:1 Track:02 00:41
00:02:05.166    << [31 10 84 95][5A][10 00 00 00][6A]                   REQUEST FIELD: MAGAZINE INFO
00:02:05.181      #[10 31 95 B0][86][00 00 00 06][8C]                   MAGAZINE INFO: CD1:Y CD2:Y CD3:N CD4:Y CD5:N CD6:N
00:02:05.206    << [31 10 01 12][54]                                    MASTER REQUEST: Time poll
00:02:05.218      #[10 31 00 00][41]                                    STATUS: Playing



There's an Excel sheet full of captured data in DOCS folder: ICS logs.xlsm.
It uses VBA to parse the data, so you need to enable macros. The function is called ParseUnilink().

01 MASTER REQUEST - BUS RESET    18 10 01 00 29 00
01 MASTER REQUEST - ANYONE?      18 10 01 02 2B 00
8C DEVICE INFO                   10 30 8C 11 DD 14 A8 17 60 10 00

Connections

The ICS connection is as follows:

IMAGE IMAGE

  • Audio

    • Audio gnd: C3-18 - Don't use other grounds as it might induce noise.
    • Left input: C3-19
    • Right input: C3-20
  • Unilink interface (Unilink Reset and Enable signals are not used)

    • Power: C2-8, permanent 12V. You'll need a 5V voltage regulator for the STM32 board.
    • BUS_ON: C2-7, makes some pulses at power-on to wake up the slave.
      Here it turns a mosfet on, then the stm32 will maintain the power with PWR_ON pin.
      It'll turn it off after 10 seconds with no communication with the ICS, so we don't drain the battery.
    • Ground: C2-9, it's missing in the ICS pinout, but fully correct. Don't use this ground for audio.
    • Data: C2-10, connect to STM32 PA6 (UNILINK_DATA).
    • Clk: C2-11, connect to STM32 PA5(UNILINK_CLOCK).

Basic connection

IMAGE

Stm32 pinout

IMAGE

Power switch circuit

These are generic components, any P-channel mosfet capable of driving 500mA and 30V will work, same for the npn transistor or the DC/DC module.

IMAGE

DAC connection (PCM5102A example)

IMAGE

PCM5102A output level fix (For each channel)

Most operational amplifiers with low noise will work here, make sure the output can swing between 0.5 and 3.5V with a 5V supply voltage or it will cause audio clipping.
Normally they have more problems getting the output close to V+ than to Gnd, that's why the input is biased a bit lower than VCC/2.

IMAGE


Some STM32F411 boards have an issue with USB OTG not working.
This is caused by diode, not allowing the power to go from the board to the USB.
The diode was removed on later revisions of the board. The fix is easy, just replace the diode with a jumper:

IMAGE

About

This project emulates the CD changer with the Alfa Romeo 166 ICS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages