Open Source BDM Interface Users Manual
Open Source BDM Interface Users Manual
1
Open Source BDM Interface Users Manual
microcontroller’s on-chip flash. Programming and debugger functionality is made possible by the
HCS08 microcontroller’s Background Debug Controller (BDC) and In-Circuit Emulator (ICE)
Debug (DBG) modules.
The primary function of this pin is for bidirectional serial communication of active background
mode commands and data. During reset, this pin is used to select between starting in active
background mode or starting the user’s application program. Additionally, this pin requests a
timed sync response pulse, allowing a host development tool to determine the correct clock
frequency for background debug serial communications.
BDC commands are sent serially from a host computer to the BKGD pin of the target HCS08
MCU. All commands and data are sent MSB-first using a custom BDC communications protocol.
Two groups of BDC commands are listed below. A complete list of these commands is provided
in the Development Tools chapter.
1. Active Background Mode Commands: These commands allow the CPU registers to be
read or written. Users can also trace one user instruction at a time, or begin the user
program in this mode.
2
Introduction to Open Source BDM
between the host PC and the pod. Functionality provided by the BDC and ICE DBG modules
include:
• Single pin for mode selection and background communications
• BDC registers not located in the memory map
• SYNC command to determine target communications rate
• Non-intrusive commands for memory access
• Active background mode commands for CPU register access
• GO and TRACE1 commands
• BACKGROUND command can wake CPU from Stop or Wait modes
• One hardware address breakpoint built into BDC
• Oscillator runs in Stop mode when BDC is enabled
• COP watchdog disabled while in Active Background mode
• Features of the debug module (DBG) include:
— Two trigger comparators: Two address + read/write (R/W) or One full address + data
+ R/W
— Flexible 8-word by 16-bit first-in, first-out (FIFO) buffer for capture information:
change-of-flow addresses or event-only data
— Two types of breakpoints: Tag breakpoints for instruction opcodes and force
breakpoints for any address access
— Nine trigger modes
3
Open Source BDM Interface Users Manual
• GB60
• AW6
• QG8
• RCx
As other HCS08 families are developed and released, the open source community may have to
modify the Open Source BDM along with installation of CodeWarrior Studio HCS08 version 5.0
service packs. Other features of the Open Source BDM are:
• Open source distribution
• Low-cost development tools
• Designed for the modern and widely available USB interface
• Firmware developed with the HCS08 CodeWarrior Special Edition version
• Supports targets with operating voltages from 1.8 to 5.0V
• Supports target bus speeds from 1.0 to 20MHz
• Double-side PCB uses mostly though-hole design for ease of assembly
• PCB can optionally supply 5.0V power to the MCU target board
• PCB has an optional 16-pin MONO8 header to program the JB16
• PC USB DLL drivers source code is provided in ANSI C
• JB16 firmware source is mostly C with some assembly for time critical operations
• Firmware can be flash programmed using USB and Freescale interface. See AN2399 -
these procedures are documented within this document.
• Windows USB drivers included using Open Source LIBUSB USB drivers
• Uses a JB16 MCU with 12MHz crystal clock source
• Documented API for easy integration into debuggers
As indicated, all the Open Source BDM source code is provided without charge. In addition, the
Open Source BDM hardware uses low-cost components and is very simple to assemble.
Unassembled PCB cost approximately under five U.S. dollars and the components can also be
obtained for less than U.S. five dollars, depending on volume. Subsequent sections provide a
detailed description of both the Open Source BDM hardware and software.
4
Introduction to Open Source BDM
Figure 3 illustrates five primary components, four software in nature and one hardware; these
are itemized below. All of the software components are intended to be used as binaries by
majority of users. For those who would like to look deeper, the source code of the JB16 firmware
and the Open Source BDM interface DLL is provided in Table 1.
5
Open Source BDM Interface Users Manual
File - OpenSourceBDM_gdi.dll
Open Source Software interfacing with the CW V5.0 This software is available only as object
BDM GDI driver debugger GDI interface, providing function code in the form of a DLL.
call to the Open Source BDM USB driver.
File - OpenSourceBDM.s19
Software running on the JB16 that receives
commands via USB from the PC and converts This file is provide as a S-recorded and
JB16 USB/BDM
them into commands as defined by the BDC. need to be programmed the the JB16 on-
firmware
These command are serial outputted - “bit - chip flash
banged” - by the JB16 using port pins to drive
the BKGD pin on the user’s target.
6
Open Source BDM PCB Hardware and MC68HC908JB16
7
Open Source BDM Interface Users Manual
• PCB provides optional circuitry used to update the Open Source BDM PCB to support
other targets besides HCS08 devices
• Double-side PCB uses mostely through-hole design for ease of assembly
• PCB can optionally supply 5.0V power to the MCU target board
• PCB has an optional 16-pin MONO8 header to program the JB16
8
Open Source BDM PCB Hardware and MC68HC908JB16
9
Open Source BDM Interface Users Manual
Open Source BDM is designed to use USB as the means of talking to the computer because:
• The development environment and the hiwave debugger looks the same for both HC08
and HC(S)08
• The development environment is available free of charge for the size of project
10
Open Source BDM PCB Hardware and MC68HC908JB16
11
Open Source BDM Interface Users Manual
Note: PCB is provided with footprint for the USB B connector. This is actually in violation of
the USB specification as low-speed devices should have the cable hard-wired to
them, but a detachable cable is very useful. If violation of the specification is not
desired, solder the cable straight into the PCB.
Data transfer Commands which transfer large blocks of data. 6.7 kB/s
When programming the flash of the target MCU, there is additional overhead created by the flash
programming routines. The speed is also dependant on crystal frequency; the higher, the better.
The Metrowerks hiwave debugger with Open Source BDM interface connected to HCS08 target
with 4.0MHz crystal typically programs the flash at 2.7kB/s rate.
12
Open Source BDM PCB Hardware and MC68HC908JB16
Table 3 BOM
Generic Part Description Package Component No. Digi-Key Part No. Qty
MC68HC908JB16DW MCU 28-Pin SOIC U1 MC68HC908JB16DW-ND 1
SN74LVC1T45DBVR Level Shifter 6-Pin SOT-23 U2, U13 296-16843-1-ND 2
Crystal, 12 MHz Citizen HC49US12.000MABJB-UB HC-49US Y1 300-8492-ND 1
Capcitator, Electronic, 4.7µF Panasonic ECE-A1VKG4R7 Radial Lead C3, C7, C10, C18 P920-ND 4
Capcitator, Ceramic, 27pF EPCOS B37979N1270J054 Radial Lead C12, C13 495-1005-1-ND 2
Capcitator, 0.1µF Kemet C320C104K5R5CA Radial Lead C4, C6, C17, C19 399-2054-ND 4
Resistor, 10 1/4W 5% Axial Lead R2, R3 10QBK-ND 2
Resistor, 470K 1/4W, 5% Axial Lead R18, R19 470KQBK-ND 2
Resistor, 10M 1/4W 5% Axial Lead R10 10MQBK-ND 1
Resistor, 470 1/4W 5% Axial Lead R11 470QBK-ND 1
Resistor, 47 1/4W 5% Axial Lead R22, R23 47QBK-ND 2
Resistor, 1.5K 1/4W 1% Axial Lead R20 1.5KXBK-ND 1
Resistor, 10K 1/4W 5% Axial Lead R21, R8* 10KQBK-ND 2
LED, Green, Round, 5mm, T13/4 Fairchild HLMP3950A Radial Lead D3 HLMP3950AFS-ND 1
USB Connector, Type B, PCB Tyco 292304-1 Through Hole PCB S1 A31725-ND 1
Power Connector, 2-Pin Terminal Blk On-Shore Tech ED555/2 Through Hole PCB J1 ED1514-ND 1
Dual Row Header, 22-Pin Molex/Waldom Electronics Corp. Through Hole PCB JP2, J2 WM6822-ND 1
Single Row Header, 9-Pin Molex/Waldom Electronics Corp. Through Hole PCB JP1, JP3, JP4, JP5 WM6509-ND 1
13
Open Source BDM Interface Users Manual
14
JB16 USB/BDM Firmware
2. Close Jumpers JP3 and JP4. Also make sure R20 is not placed. This configures
the JB16 for USB In Circuit Programming.
3. Connect the Open Source BDM board to your computer through the USB cable.
4. Once the Open Source BDM board to the computer, you should be prompted that
a new device has been detected and the Hardware Wizard should appear. Select
Install from a list or specific location, illustrated in Figure 10.
15
Open Source BDM Interface Users Manual
5. Direct the install to the folder where the USBICP files reside. Your computer
should now recognize a USBICP device is connected.
Note: It may be necessary to attempt this install many times, sometimes the
computer will not recognize the board. If this occurs try connecting reset to
GND before plugging in the USB cable, then releasie reset. Reset and GND
are accessible at the MON08 header.
6. Open USBICP.exe, see Figure 11, when prompted for an IMP file select
jb16_icp_me.imp.
16
JB16 USB/BDM Firmware
Selection of the Flash operation in the above screen results in the following screen in Figure 12.
17
Open Source BDM Interface Users Manual
18
Open Source BDM PC Software
Note: Firmware installed on Alpha Units (Boards Pre-Programmed with the firmware)
does not contain the ability to do this.
4.1 Overview
This section describes the Open Source BDM solution PC software components. These
components include:
• Open Source BDM Generic Debug Instrument (GDI) DLL plug-in for the CodeWarrior
hiwave debugger
• Open Source BDM interface DLL
• USB driver (libusb.lib)
Figure 14 illustrates these software components and a simplification of their interfaces.
19
Open Source BDM Interface Users Manual
4.3.1 Command.h
Command.h provides command code use within the USB messages. This file matches the
command.h file in the Open Source BDM firmware.
4.3.2 OpenSourceBDM.h/.c
OpenSourceBDM.c/.h provides the API functions for the Open Source BDM DLL. These
functions are called by the Open Source BDM GDI DLL. The functions in turn call functions of
LIBUSB. These functions are encapsulated into the OpenSourceBDM.dll. OpenSourceBDM.dll
is a part of the Windows USB install package for the Open Source BDM. The Open Source BDM
DLL functions are listed and briefly described below.
void OpenSourceBDM_close(void)
Closes communication with currently opened device.
20
Open Source BDM PC Software
21
Open Source BDM Interface Users Manual
float OpenSourceBDM_get_speed(void)
Returns crystal (or external source) frequency of the target in MHz.
22
Open Source BDM PC Software
LIBUSB
The LIBUSB is Open Source software available under combination of GNU general and lesser
general public licenses. The Open Source BDM DLL functions utilize the following LIBUSB API
functions:
23
Open Source BDM Interface Users Manual
• usb_find_buses
• usb_find_devices
• usb_close
• usb_open
• usb_get_version
• usb_init
• usb_control_msg
• usb_bulk_write
• usb_bulk_read
24
Installation and Operation of the Open Source BDM
6.2 Installing Windows Open Source BDM DLL and USB Drivers
The following procedure specifies the installing of the Open Source BDM USB hardware drivers
under the Windows operating system. This procedure assumes Open Source BDM windows
USB driver package is unpacked onto the development PC, running the CodeWarrior Studio.
With the Open Source BDM PCB configured, the Open Source BDM PCB can be connected to
the development PC USB port. When the configured Open Source BDM PCB is connected to the
PC for the first time, the Windows operating system recognizes a new USB device, the Open
Source BDM PCB. This initial connection starts the Windows driver installation procedure. Figure
16 illustrates the Windows New Hardware Wizard dialog box that opens.
25
Open Source BDM Interface Users Manual
For this installation, select the option to Install from a Specific Location, then click Next. When
the Next button is selected, the Specify Location of the Drivers dialog box opens, illustrated in
Figure 17.
26
Installation and Operation of the Open Source BDM
BDM windows driver package, select the Next button. This will initiate the installation of the Open
Source BDM USB required driver and DLL file, ilustrated in Figure 18.
Once the installation procedure is completed, the device will be ready to use, illustrated in Figure
19. Select the Finish button at this point. Because of the plug and play nature of USB, a reboot
of Windows is not required.
Figure 19. Finishing Installation Open Source BDM Windows USB Driver
27
Open Source BDM Interface Users Manual
6.3 Configuring the Hiwave Debugger for the Open Source BDM GDI DLL
Plug-in
Once the Open Source BDM device is recognized by Windows, the CodeWarrior version 5.0
hiwave debugger is one step closer to programming and debugging targets with the Open
Source BDM development tool. The initial release of the CodeWarrior version 5.0 and the
hiwave debugger does not have obvious support for the Open Source BDM. A patch is planned
for the CodeWarrior version 5.0 Studio, adding more visible Open Source BDM support. This
section describes configuration of the hiwave for the Open Source BDM with and without the
patch to add Open Source BDM support.
The procedure detailed in this section explains how to configure the hiwave debugger to work
with the Open Source BDM interface. Please be certain to download the latest version of the
tools from Metrowerks. The debugger interface of older versions do not support the required
features. The Open Source BDM was tested with the minimum required debugger version 6.1.
28
Installation and Operation of the Open Source BDM
When the set gdi command is executed, the GDI Setup DLL dialog box opens. To use the Open
Source BDM, select the Browse button to choose the required OpenSourceBDM_gdi.dll file. The
GDI Setup DLL dialog box is illustrated in Figure 21.
Sometimes the "set gdi" command does not force a change of the GDI DLL setup (note the active
GDI setup is shown in the debugger menu, i.e. Open Source BDM menu option vs.
MultilinkCyclonePro vs. MONITOR-HCS08 vs. Softec-HCS08). This issue occurs when the
Softec-HCS08 debugger target is selected in the Code Warrior IDE. The solutions is to NOT to
select the Softec-HCS08 debugger target (select P&E instead). When a service patch for Code
Warrior to add support for the Open Source BDM is avaiable, the set gdi command is not
necessary since the Open Source BDM target will be selectable from the Code Warrior IDE.
29
Open Source BDM Interface Users Manual
Alternatively, if the project was built with other connection using the New Project Debugger
Interface Connections dialog box, it can be easily changed in the CodeWarrior IDE project
manager, illustrated Figure 23. Also, the set gdi command can still be used in the hiwave
debugger.
30
Installation and Operation of the Open Source BDM
31
Open Source BDM Interface Users Manual
32
Installation and Operation of the Open Source BDM
Figure 25. Cable Connections Between the PC and the Open Source BDM
33
Open Source BDM Interface Users Manual
Figure 27 illustrates the hiwave program again. Selecting the Load... or Flash command in the
Open Source BDM menu initiates flash programming algorithms to erase and reprogram the
target MCU. The Load... menu command will first allow a selected file to upload during the flash
programming operation.
34
Installation and Operation of the Open Source BDM
3. The user must navigate to the file that will be used to program the part and select it
4. Before pressing the "Open Button," the "Automatically erase and program into FLASH
and EEPROM" checkbox must be checked
To make the "Automatically erase and program into FLASH and EEPROM" option the default
setting for a project, the user must configure the debugger accordingly. These steps are provide
below:
1. Select File > Configuration from the menu
2. The "Preference" dialog box opens
3. Select the "Load" Tab
35
Open Source BDM Interface Users Manual
4. Check the "Automatically erase and program into FLASH and EEPROM" checkbox
5. Close "Preference" dialog box by pressing the "OK" button
6. Select File > Save Configuration from the menu
7. Next time, auto erase and flash functions will be performed by default
36
Installation and Operation of the Open Source BDM
37
Open Source BDM Interface Users Manual
9. To close the "Non Volatile Memory Control" dialog box, press the "Unselect All"
10. Then press the "OK" button"
7.0 References
1. LIBUSB documentation, http://libusb.sourceforge.net/
2. Data sheet to HC908JB16, MC68HC908JB16.PDF available from Freescale
3. Documentation to Generic Debugging Interface, available from Tasking,
www.tasking.com
4. TBDML HCS12 project, see either http://forums.freescale.com or www.freegeeks.net
38