APPLICATION NOTE 2783

Using the Keil C Compiler for the DS5250

Oct 20, 2003

Abstract: This application note describes how to get up and running using the Keil µVision2 suite of tools to build applications for the DS5250 secure microcontrollers in C. All development was done using the DS5250 Evaluation Kit and Keil µVision2 version 2.37, which includes the C compiler 'C51' version 7.05.

Overview

This application note describes how to use the Keil µVision2 suite of tools to create and compile a C application for the DS5240 or DS5250 High-Speed Secure microcontroller. The process for loading the compiled application into the microcontroller's external encrypted RAM using the ROM bootloader and Microcontroller Tool Kit is also described.

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 compiled application was loaded into the DS52x0 Evaluation Kit Board RAM using the Microcontroller Tool Kit version 2.2.0.

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 µVision2, 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 1. Under Database, select Dallas Semiconductor and DS5250. Check the boxes for Use Extended Linker and Use Extended Assembler, and then hit OK to continue.

Figure 1.  Selecting the DS5250 for a new Keil µVision2 Project.
Figure 1. Selecting the DS5250 for a new Keil µVision2 Project.

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 2):
  • 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 Eprom Start: 0x1400 and Eprom Size: 0x10000.
  • In the Off-chip Xdata Memory section of the dialog, set the top two fields to Ram Start: 0x80000 and Ram Size: 0x10000.
Figure 2.  Target option settings for the DS5250.
Figure 2. Target option dettings for the DS5250.

Finally, select the Output tab. In this tab, check the box for Create HEX file and select HEX Format: HEX-386.

Adding the Project Code

Open a new file and enter the following C code:
#include <stdio.h>
#include <reg5240.h>

// Initialize serial port 0 to 9600 baud using 22.1184 MHz crystal

void serialInit()
{
   PCON  |= 0x80;
   SCON0  = 0x50;
   TMOD  |= 0x21;
   TH1    = 0xDC;
   CKCON |= 0x10;
   TCON   = 0x50;
   SCON0 |= 0x02;
}

void main()
{
   serialInit();

   printf('Hello from serial port 0\r
');

   while (1) {
      P0 = 0x55;
	printf(".");
      P0 = 0xAA;
	printf(".");
   }
}
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


Also, change the line

#include <reg390.h>

to

#include <reg5240.h>

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 3.

Figure 3.  Compilation output from Keil µVision.
Figure 3. Compilation output from Keil µVision.

Loading the Compiled Application with the Microcontroller Tool Kit

The Microcontroller Tool Kit software is available on the Dallas/Maxim website at http://www.maximintegrated.com.

Before loading the compiled application on the DS52x0 Evaluation Kit board, the board should be set 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 22.1184 MHz crystal should be inserted.
  • All DIP switches should be OFF except for A1-A4, B1, and B2 which should be ON.
To load the application:
  1. Open Microcontroller Tool Kit. In the microcontroller type dialog, select DS5240/50.
  2. Turn power on to the DS52x0 Evaluation Kit Board.
  3. Select Options -> Configure Serial Port. Set the serial port options to COM1 and 9600 baud.
  4. Select Target -> Open COM1 at 9600 baud (or hit Ctrl+O).
  5. Select Target -> Connect to Loader (or hit Ctrl+L).
  6. A loader prompt should appear (DS5250 SECURE LOADER...)
  7. At the loader prompt, type "W MSIZE 12" and hit ENTER.
  8. At the loader prompt, type "W MCON 81" and hit ENTER.
  9. Select File -> Load from the menu (or hit Ctrl+H). Select the compiled application hex file.
  10. Once loading completes, set the DIP switch B1 to the OFF position.
Figure 4.  Output from microcontroller tool kit.
Figure 4. Output from microcontroller tool kit.

Summary

Together, Keil's µVision2 and Dallas/Maxim's Microcontroller Tool Kit ease building and loading applications on the DS5240 and DS5250 High-Speed Secure Microcontrollers.

Relevant Links

Keil Software Development Tools: http://www.keil.com
Dallas Semiconductor Microcontroller Software Downloads: http://www.maximintegrated.com/products/microcontrollers/software/index.cfm

Related Parts
DS5250 High-Speed Secure Microcontroller  


Next Steps
EE-Mail Subscribe to EE-Mail and receive automatic notice of new documents in your areas of interest.
Download Download, PDF Format (301kB)  
Share
Other Channels  Email this page to an associate or friend. 



APP 2783: Oct 20, 2003
APPLICATION NOTE 2783, AN2783, AN 2783, APP2783, Appnote2783, Appnote 2783

Share



More