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!