Using the Keil µVision Debugger with the DS52x0 Secure Microcontrollers
Abstract
This application note describes how to use the Keil µVision® suite of tools to debug an application for the DS5250 High-Speed Secure microcontroller. This process involves loading a debug monitor application into the DS5250 which communicates with Keil µVision2 over a selected serial port.
Overview
This application note describes how to use the Keil µVision2 suite of tools to debug an application for the DS5250 High-Speed Secure microcontroller. The process involves loading a debug monitor application into the DS5250 which communicates with Keil µVision2 over a selected serial port.
All development for this application note was done using the DS5250 and the DS52x0 Evaluation Kit Board (Rev A). The C application was created and compiled using Keil's µVision2 version 2.40 and the Keil C51 Compiler version 7.10. The debugging monitor was loaded into the DS52x0 Evaluation Kit Board RAM using the Microcontroller Tool Kit (MTK) version 2.2.0.
Installing the Keil Debugging Monitor
There are three different variations of the Keil debugging monitor available for the DS5250, depending on which serial port will be used to communicate with Keil µVision2 on the host PC. This serial port will be unavailable for use by the application under debug.
Serial Port Used | Timer Used | Crystal Speed | Monitor File Name |
Serial Port 0 | Timer 1 | 11.0592 MHz | mon5250s0x11.hex |
Serial Port 0 | Timer 1 | 22.1184 MHz | mon5250s0x22.hex |
Serial Port 1 | Timer 1 | 11.0592 MHz | mon5250s1x11.hex |
Serial Port 1 | Timer 1 | 22.1184 MHz | mon5250s1x22.hex |
External Serial Port 2 | None | Any | mon5250s2.hex |
To obtain these files, please contact the microcontroller technical support group through our Analog Support Center.
Before loading the selected debugging monitor on the DS52x0 Evaluation Kit board, set the board up as follows:
- A 6-9 volt DC power supply (center post positive) should be connected to power plug J1.
- A straight-through, DB9 serial cable should be connected from J3 (SERIAL 0) to COM1 on the host PC.
- A 11.0592 MHz or 22.1184 MHz crystal should be inserted. (A different crystal speed may be used, but this will result in a different baud rate when communicating with the loader.)
- All DIP switches should be OFF except for A1-A4, B1, and B2 which should be ON.
Next, install the Microcontroller Tool Kit (MTK) software package, which is available at https://www.analog.com/en/product-category/microcontrollers.html To load the debugging monitor:
- Open MTK. In the microcontroller type dialog, select DS5240/50.
- Turn power on to the DS52x0 Evaluation Kit Board.
- Select Options -> Configure Serial Port. Set the serial port options to COM1 and 9600 baud.
- Select Target -> Open COM1 at 9600 baud.
- Select Target -> Connect to Loader.
- A loader prompt should appear (DS5250 SECURE LOADER...)
- At the loader prompt, type "W MSIZE 12" and hit ENTER.
- At the loader prompt, type "W MCEN E0" and hit ENTER.
- At the loader prompt, type "W MCON 81" and hit ENTER.
- Select File -> Load from the menu. Select the debug monitor file that you wish to use.
- Once loading completes, select Target -> Close COM1.
- Turn the power to the DS52x0 Evaluation Kit Board off. Set the DIP switch B1 to the OFF position.
See Figure 1 below for the output that should appear in MTK when following this procedure.
Creating and Compiling the C Application
This section describes the process to create and compile a sample C application for the DS5250 using Keil's µVision2 integrated development environment.
Creating a New Project
In Keil mVision2, select Project -> Create New Project from the menu. Enter the name of your new project.
The Select Device for Target dialog will appear as shown below in Figure 2. Under Database, select Dallas Semiconductor and DS5250. Check the boxes for Use Extended Linker and Use Extended Assembler, and then hit OK to continue.
A new dialog box will ask, "Copy Dallas 80C390 Startup Code to Project Folder and Add File to Project?" Select YES.
Setting Project Options
When the project window opens on the left, open up Target 1. Right click on Target 1, and select Options for Target 'Target 1'. An Option dialog box will appear.
Select the Target tab. Change the settings in this tab as follows (as shown below in Figure 3):
- Memory Model - Set to Large: Variables in XDATA.
- Code ROM Size - Set to Contiguous Mode: 16 MB program.
- Set the checkbox for Use multiple DPTR registers.
- In the Off-chip Code Memory section of the dialog, set the top two fields to Ram Start: 0x8000 and Ram Size: 0x10000.
- In the Off-chip Xdata Memory section of the dialog, set the top two fields to Ram Start: 0x8000 and Ram Size: 0x10000.
Next, select the Debug tab, and set the options as follows (as shown in Figure 4 below):
- Select Use and select MON390 - Dallas Contiguous Mode.
- Click the Settings button and select COM1 and 9600 baud.
- Set the checkboxes for Load Application at Startup and Go till main().
Adding the Project Code
Open a new file and enter the following C code:
#include <stdio.h> #include <reg5240.h> void main() { while (1) { P0 = 0x80; P0 = 0x40; P0 = 0x20; P0 = 0x10; P0 = 0x08; P0 = 0x04; P0 = 0x02; P0 = 0x01; } }
Save this file as main.c. The file will not be automatically added to the project. To add the file, right-click on Source Group 1 and select Add Files to Group 'Source Group 1'. Select main.c and click Add, then click Close.
Next, open the file START390.A51 and comment out the following lines (after the STARTUP1 label):
; MOV TA,#0xAA ; Enable access to P4CNT ; MOV TA,#0x55 ; P4CNT_VAL EQU (SBCAN SHL 6) OR (PCES SHL 3) OR (P4PF) ; MOV P4CNT,#P4CNT_VAL ; ; MOV TA,#0xAA ; Enable access to P5CNT ; MOV TA,#0x55 ; P5CNT_VAL EQU (SP1EC SHL 5) OR (CX_IO SHL 3) OR (P5PF) ; MOV P5CNT,#P5CNT_VAL
The Dallas Semiconductor DS5250 monitor automatically sets up the microcontroller for contiguous mode. Because of this, the microcontroller misinterprets the first instruction address. Make this additional change to the START390.A51 file:
?C_STARTUP LABEL NEAR $IF MONITOR LJMP STARTUP1 $ELSE DB 02H ; LJMP in Classic 8051 Mode DW WORD0 STARTUP1 RSEG ?C_C51STARTUP $ENDIF
Then create a new Target in Project - Components, Environment and Books - Project Components, and set that new target as current. Add the Conditional Assembly Control Symbol MONITOR in Project - Options for Target - AX51.
Compiling the Project
To compile the project, press F7, or select Project -> Build Target from the menu. If no errors occur, messages should appear indicating that compilation completed successfully, as shown in Figure 5.
Debugging the Project
Before starting the debugging session in Keil µVision2, power on the DS52x0 Evaluation Kit board and verify that the serial cable is connected as follows:
- If you are using the Serial 0 version of the debugging monitor, the serial cable should be connected from COM1 to the J3 / SERIAL 0 connector on the kit board.
- If you are using the Serial 1 version of the debugging monitor, the serial cable should be connected from COM1 to the J2 / SERIAL 1 connector on the kit board.
- If you are using the Serial 2 (external serial) version of the debugging monitor, the serial cable should be connected from COM1 to the J6 / SERIAL 2 connector on the kit board using a DB9-to-2x5 adapter cable.
Select Debug -> Start/Stop Debug Session from the menu in Keil µVision2. If everything is connected correctly, the compiled project file will be loaded and Keil µVision2 will enter debugging mode as shown in Figure 6 below. From this point, you can view register and variable values, perform step-by-step and breakpointing, and other operations. Refer to the Keil µVision documentation for more details.
The debugging monitors for the DS5250 have the following limitations.
- You cannot enable the extended stack when using the monitor. The monitor uses this area for data storage.
- Applications must start at 0x8000.
- Applications must not write into Vector RAM.
- When using the external serial monitor, serial break mode is not supported.