Arduino to Freescale BDM protocol!

Hi there!

This is my first post in the forum! I own an Arduino UNO and i have created many projects on it with 100% success! It really solved many of my problems and i have made many ideas come true! In general i love it!

So time has come and i need some help on a project! The last few years i am working with Freescale (ex-Motorola) CPUs! More particular the 68hc(9)16 series of them! These are no longer in production and they where used in automotive applications like ECUs!
These CPUs have a debug port called BDM! This is used to debug the application that is uploaded to the CPU, monitor RAM, read, erase and write to the CPU! In order to communicate with the CPU we use a circuit that connects to the LPT port! Then i have created a winXP program that reads, erases and writes to the CPU! Everything works as it should!

Now i want to build a usb to bdm adapter using the arduino! So i started coding at the IDE but i have some problems! To read, erase or write to the ECU i need to enter in BDM mode, which motorola claims that it is pretty close the motorola SPI protocoll! Anyway i can reset and stop the CPU using the arduino so i am into BDM mode! Now in order to read,erase or write to it i need to call some routines! All these routines end up calling a routine called bdm_clk(). That one is the routine that clocks the data so that the cpu can recognise them! I think that this is where i have my problem!

As i told earlier we use a circuit connected to the lpt to communicate to the cpu! So all the commands have to do with the lpt! I changed the lpt out with digitalWrite(x,y) and in with digitalRead(x). I now about the reversed pins of the lpt port and the bdm circuit is 2 cmos gates, nothing more! A friend of mine have made a usb to bdm adapter using an AVR and he was kind enough to provide me the source code to take a look! Great, same as mine but still doesn’t work! So i am giving some pdfs and 2 sample codes for you just in case you can hepl me out!

Thank you in advance!
www.btinternet.com/~j_holland/denso/docs/AN1230.pdf This is the old motorola document about the dos bdm driver!
http://www.btinternet.com/~j_holland/denso/docs/BDM_Drivers.zip This is the dos driver that has all the routines!

My code:

static unsigned long bdm_clk (unsigned int value, int count)
{
  unsigned long ShiftRegister;
  unsigned char DataOut;
  unsigned stat = GetStatus ();

  ShiftRegister = ((unsigned long) value) << (32 - count);
  if (stat & TARGETRESET)
    bdm_error (BDM_FAULT_RESET);
  if (stat & TARGETNC)
    bdm_error (BDM_FAULT_CABLE);
  if (stat & TARGETPOWER)
    bdm_error (BDM_FAULT_POWER);
    
  pinMode(dsi, OUTPUT);
  while (count--)
  {
    DataOut = ((ShiftRegister & 0x80000000) ? true : false);
    ShiftRegister <<= 1;
    if (digitalRead(dso))
      ShiftRegister |=1;
    digitalWrite(dsclk, LOW);
    if (DataOut){
      digitalWrite(dsi, HIGH);
    }
    digitalWrite(dsclk, HIGH);
  }
  pinMode(dsi, INPUT);
  return ShiftRegister;
}

This is my friends code that works on his AVR based adapter!

void bdm_clk(uint16_t value, uint8_t num_bits)
{
	SETBIT(BDM_DIR, _BV(PIN_DSI) | _BV(PIN_BKPT));	

	// clock the value via BDM
	bdm_response = ((uint32_t)value) << (32 - num_bits);

	bool dsi;
	while (num_bits--)
	{
		// get DSI value
		dsi = (bdm_response & 0x80000000) ? true : false;
		bdm_response <<= 1;

		// read DSO
		if (CHECKBIT(BDM_PIN, _BV(PIN_DSO)))
		{
			bdm_response |= 1;
		}

		// set DSI bit
		CLEARBIT(BDM_PORT, _BV(PIN_DSI) | _BV(PIN_BKPT));
		if (dsi)
		{
			SETBIT(BDM_PORT, _BV(PIN_DSI));
		}

		// rising edge on BKPT/DSCLK
		SETBIT(BDM_PORT, _BV(PIN_BKPT));
	}

	CLEARBIT(BDM_PORT, _BV(PIN_DSI));
	CLEARBIT(BDM_DIR, _BV(PIN_DSI));
}

I have to tell that there no circuit needed between the AVR and the motolora CPU! Just connect the digital pins to the BDM port of the cpu! Guys i really need some help as i cant find a reason why it doesn’t work! I am researching it for almost 3 weeks!
And last, if this will work i will create a library for the arduino! Maybe there are other users who want to build an adapter like this!

bump :)

Did you ever progress any further with this? I've just started using an Arduino and have a Motorola Trionic 8 ECU I am trying to read using a BDM interface but to no avail, and I thought it may be possible to use the Arduino.

Hello, sorry for reviving this old topic.

I got an old PCB with alot of relays and digital inputs i will like to reuse for a DIY project. I have managed to use an arduino to implement the BDM interface using the SPI port, I can also dump all the FLASH to a file and using a HEX viewer i can see the original program inside the MCU and even some text. My next step was to try to write to the MCU FLASH, i have 12V applied to the Vfpe1/2 pins to supply the EEPROM with the programming voltage. And i can send to the MCU the WPMEM command followed by the bank, address and 16 bit data to write. But when i read back the same address location the original value is returned. I'm sending the write command exactly was explained in the CPU16RM but so far i havent had any luck.

If i try to write something into the Data space i can read it back and the value is exactly the one i wrote previously.

Using RPMEM and WPMEM for Program space and RDMEM and WDMEM for Data space.

Did psyche manage to make his implementation?

Hello all,

reading this post and having read all the work of psyche, I’am very interessted if anyone coulld give us more information on this subject.

Hi there I am trying to repair a Spirit 328 digital mixer. This is based around the Motorola MC68360 processor, and I am trying to communicate with it via bdm. I have had little success with the dos/lpt method as the processor drops into bdm mode but then straight back out again (I'm suspecting a clocking issue). I came across this thread which has awakened my interest in this project once again. Has anybody had any success with cpu32 bdm via arduino? I wonder if the op may kind enough to share his full code as a starting point... I would really like to revive this old thread and get something moving on the arduino bdm front.

Thanks in advance

Bump from the dead.. has anyone done any more with the BDM protocol?

I'm finding myself in the same boat of "ancient processor (CPU32) I want to do R&D with, but no easily accessible tools"

Arduino seems like the way to go so I can spread my work to others... but it's difficult to piece all of this info together into something that actually works

Hello there. I know this is old and probably not being seen by much, but was anyone able to mod or use the arduino as a BDM for these old CPU32 chips?