Skip to main content

Integrating FlashMagic with Keil uVision4 for P89V51RD2

If you are using P89V51RD2 microcontroller with Keil uVision4 for your project, then you might find it convenient to add FlashMagic as a Tools Menu Option within Keil.
What this will do is allow you to download the program onto P89V51RD2 using a single click from within Keil.
Calling Flash Magic from within Keil to download the program into P89V51RD2 conveniently.
Note the console messages printed in the pane below by FlashMagic's Command Line utility (FM.exe)

Prerequisites:

  1. Keil uVision4 (with the hex output option enabled for your current project)
  2. FlashMagic from http://www.flashmagictool.com/
  3. A target board wired properly to allow DTR to control RESET. If you are using FT232 (USB <> UART) then refer the connection diagram below on how to design your circuit board appropriately.
Enable the "Create HEX File" option for your project in Keil uVision4

Schematic for wiring FT232 (USB <> UART) so as to allow the
computer to use DTR to control the RESET pin of P89V51RD2

Adding FlashMagic to Tools menu:

  1. Click on "Customize Tools" option from the Tools menu.
  2. Add a new tool by clicking on the New button. Type the tool name as "Flash Magic".
  3. Type the following lines in the "Command" and "Arguments" textboxes and click ok.
    Command:
    C:\Program Files (x86)\Flash Magic\fm.exe

    Arguments:
    DEVICE(89V51RD2, 11.0592, 0) ERASE(DEVICE, NOPROTECTISP) HEXFILE(#H, CHECKSUMS, NOFILL, NOPROTECTISP) COM(11, 9600) HARDWARE(BOOTEXEC, 50, 100)
  4. Now, after building your project, you can click on the "Flash Magic" option from the tools menu to download the hex file into the microcontroller

Explanation of FM.exe arguments:

  1. DEVICE(89V51RD2, 11.0592, 0)
    We are using P89V51RD2 with a 11.0592 MHz Crystal. The last zero refers to the flash block we want to program. In case of P89V51RD2, it is "0".
  2. ERASE(DEVICE, NOPROTECTISP)
    We want to erase the whole flash before programming it with the new hex file
  3. HEXFILE(#H, CHECKSUMS, NOFILL, NOPROTECTISP)
    Here we specify the hex file. #H is like a wildcard character which tells Keil to replace it with the actual path of the current project's hex file output.
  4. COM(11, 9600)
    We want to use COM11 at 9600 baud rate. You will have to change the COM port number according to the one on your system
  5. HARDWARE(BOOTEXEC, 50, 100)
    We want tell FM.exe to explicitly use the DTR line to control the RESET of P89V51RD2 and to release it after programming the flash. The values of T1 and T2 are 50 and 100 milliseconds respectively. Refer to the HARDWARE section under the Command Line Interface chapter of FlashMagic User Manual (C:\Program Files (x86)\Flash Magic\Manual.pdf)

Adding to Flash menu instead:

Instead of adding a FlashMagic to the tools menu, you can configure Keil to invoke Flash Magic (FM.exe) whenever the the user selects the Download option from the Flash menu. This is a per project setting which you will have to perform individually for each project. Just enter the same settings as above in the "Configure Flash Tools" dialog box:

Configure Flash Tools

Select "Use External Tool for Flash Programming"

"Download" option in the Flash menu can now be used to invoke FlashMagic

References:

  1. Integrating Flash Magic command line with Keil as ISP
  2. Interfacing Flashmagic with KEIL
  3. 89V51RD2 and FM command line
  4. Flash Magic Manual installed at C:\Program Files (x86)\Flash Magic\Manual.pdf

Comments