FlashMon51: Overview

Overview

The Keil FlashMon51 allows you to debug programs on your target hardware using the µVision2 Debugger. FlashMon51 is very flexible and can be configured to work with many 8051-based devices with Flash memory and In-Application Programming (IAP). Itruns on unmodified user hardware and communicates using any standard serial interface (UART). Target requirements are minimal-the entire monitor can fit in the on-chip resources of most 8051 Flash devices. Following is a typical configuration.

To get started with FlashMon51 you must properly configure and install the monitor firmware on your target hardware. FlashMon51 is located in the \KEIL\C51\FLASHMON\ folder. Prebuilt monitor configurations for several devices may be found in subfolders. Once it is configured, the monitor may be programmed into your Flash device using standard flash programming utilities.

Note

  • FlashMon51 is an extended version of MON51. It is available only in the PK51 Professional Developers Kit.

Working with Flash Monitor

Flash Monitor helps you easily debug your target programs in real-time. You may view program symbols, debug using your source code, watch program variables, examine memory contents, and more!

There are only a few things to consider when you are using Flash Monitor.

  1. Breakpoints are set by replacing instructions in your program with an ACALL instruction. This operation, while completely transparent, may have side effects that affect the operation of your target program.
  2. On hardware configurations where the Flash Monitor CODE is located at address 0, you need to relocate your startup code, program code segments, and interrupt vector table.
  3. Some devices (like the Atmel parts) share the same xdata address regions for on-chip XRAM and on-chip EEPROM. You cannot set breakpoints or single step into routines that disable the xdata RAM area which is use by Flash Monitor-51.
  4. You may enable or disable the HALT command on the toolbar in µVision2 Debugger. When enabled with the check box Stop Program Execution with Serial Interrupt under Options - Debug - Keil Monitor-51 Driver Settings, Monitor-51 uses the 8051 serial interrupt vector to signal that the target program should stop running. Therefore you may need to reserve the serial interrupt vector in your application.

Copyright (c) Keil Software, Inc. All rights reserved.


FlashMon51: What's New?

What's New?

Compared to Keil Monitor-51 Version 3, FlashMon51 Version 4 has several new features and improvements that are summarized below.

  • Support for Flash IAP Programming
    FlashMon51 supports IAP Flash programming and can write your target program into the Flash memory of your target system. Breakpoints may be set anywhere in Flash memory.

    Refer to configuring Flash IAP programming for more information.
  • Target Information
    µVision2 knows the start address of the application and configures the PC start address for you. The debugger emits warning messages when you try to overwrite Monitor CODE and XDATA areas.
  • µVision2 based Configuration
    Monitor-51 Version 4 can be easily configured with µVision2 project files. The configuration uses the enhanced features of the LX51 Extended Linker/Locater, but your target application can be developed with the standard BL51 Linker/Locater or the LX51 Linker/Locater.
  • COM Handshake Signals
    can be configured as hardware reset signal.


FlashMon51: Requirements

Requirements

Your hardware and software must meet the following requirements for FlashMon51 to operate correctly.

  • The device must be 8051-compatible.
  • Depending on the monitor configuration, 4-5K Bytes of CODE memory are required.
  • 256 Bytes of XDATA memory are required.
  • An on-chip or off-chip serial interface must be available.
  • Six 6 Bytes of stack space (IDATA) is required (for the monitor to interrupt the user program).

Any hardware components of your target system that are not specifically listed above are available to the user application.

Standard 8051 devices require that the reset vector address is located at 0000h. Many Flash devices provide alternate boot vectors that you can configure. On such devices, you can configure the monitor for a reset vector other than 0000h and debug your unmodified user program.


FlashMon51: Serial Interface

Serial Interface

FlashMon51 requires the following signals of a RS232 interface

  • TRANSMIT DATA
  • RECEIVE DATA
  • SIGNAL GROUND

Additional signals may be required to enable data transmission and reception.


FlashMon51: Monitor Configuration

Monitor Configuration

Flash Monitor can be adapted to different devices. Its code and data can be located at every address. All hardware specific code such as flash programming algorithms and serial interface initialization can be modified in the Config.INC file.

You should perform the following steps to configure the Monitor-51 for a new Target Board:

  1. Create a new empty folder in ..\C51\FlashMon.
  2. Copy the contents of an example configuration (i.e. folder ..\C51\FlashMon\T89C51CC01 to this new folder.
  3. Load the project file Monitor.UV2 into uVision2 environment.
  4. Describe your target hardware in the file Abstract.TXT.
  5. Open the file Config.INC and specify your hardware configuration.
  6. Generate your Monitor configuration with Project - Build Target.
  7. The resulting hex file Monitor.HEX can now be programmed into the Flash or EPROM of your target system.

Notes

  • For devices with extended serial interface or expanded chip features, you need to adapt specific CPU features or the serial interface in the file INSTALL.A51.
  • The Folder ..\C51\FlashMon contains several pre-configured Monitor versions.

CONFIG.INC - Configuration Parameters

The file CONFIG.INC specifies the following configuration parameters:

Parameter | Description
XDATA_START | specifies the address of the xdata memory area used. Beginning from this address, the following 256 bytes are used for Monitor variables and cannot be used by the user application.
CODE_START | specifies address of the code memory area for the Monitor program code. The Monitor code requires typically 4 … 5 KBytes.
INT_ADR_OFF | Defines the Interrupt Vector Address relocation and is only required if CODE_START is 0. In this case, the application program cannot write the interrupt vectors at the standard addresses and you have to redirect the interrupt vectors. ToDo: Link
DEF_PC_VAL | Specifies the PC (program counter) value at debugger start. When CODE_START is set to 0 you should set DEF_PC_VAL to the beginning of the application code area.
SERIAL | Defines the UART and the baudrate generator that is used for Monitor configuration. The INSTALL.A51 file contains several pre-defined interface routines that are selected with this setting.
BAUDRATE | Defines the communication baudrate. For some serial interfaces you may set BAUDRATE to 0 for automatic baudrate detection.
EX_UART_CLK | Oscillator/crystal frequency of external off-chip UART.
EX_UART_ADR | XDATA memory address of external off-chip UART
CPU_CLOCK | Defines the CPU Clock frequency (external oscillator/crystal) and is used to calculate the baudrate.
FLASH_PAGESIZE | Defines the flash page size. The debugger does not send data blocks that cross this boundary. The Flash Programming algorithm is adapted in the INSTALL.A51 file.

Note

  • On device specific configurations, the CONFIG.INC file may contain additional setting for extended chip features.

INSTALL.A51 - Interface Functions

The file INSTALL.A51 allows the configuration of the Monitor interface functions listed below:

Parameter | Description
INSTAT | This function returns the receive status of the serial interface in the C-flag. C = 1 means character received; C = 0 means no character received.
OUTSTAT | This function returns the transmit status of the serial interface in the C-flag. C = 1 means character transmitted; C = 0 means character not yet transmitted.
INCHAR | This function returns the received character in the accumulator.
OUTCHAR | This function transmits the character in the accumulator to the serial interface.
CLR_TI | This function clears the transmit interrupt flag of the serial interface
SET_TI | This function sets the transmit interrupt flag of the serial interface.
CLR_RI | This function clears the receive interrupt flag of the serial interface.
CLR_SER_IE | This function clears the interrupt enable flag of the serial interface.
SET_SER_IE | This function sets the interrupt enable flag of the serial interface.
BEFORE_GO | This function is called before a application is started with GO or P-step. It is empty by default (only RET). This function can be used to generate a signal at a port pin or to change the memory configuration.
AFTER_GO | This function is called when a application has been stopped with a breakpoint. It is empty by default (only RET). It should do the opposite of BEFORE_GO.
WR_CODE | This function has to write one byte into the flash memory. The address is in DPTR and the value in the Accumulator.
PRE_PROG | This function configures the Flash for block programming
LD_FPAGE | This function loads data into a Flash page. The DPTR specifies the address and the Accumulator holds the data to be loaded. The carry flag (one bit of PSW) must be set before returning from this function.
POST_PROG | This function starts Flash programming. The previously loaded data (see LD_FPAGE) must be programmed into the Flash

Note

  • The functions above must not modify any other registers than the return values without saving and restoring them.


FlashMon51: uVision2 Driver

uVision2 Driver

µVision2 interfaces to target systems when you select Use: Keil Monitor-51 Driver in the dialog Options – Debug.

Click on Settings to open the dialog Monitor Driver Settings that allows you to configure various parameters such as COM port and baudrate.

The following table describes the Monitor Driver Settings page:

Dialog Item | Description
Comm Port Settings Select the PC COM port and the baudrate. The most common baudrate is 9600bps (so your try this frist). Sometimes non- standard baudrates allow you to use a different clockl frequency without Monitor modification, for example: a target board running at 12 MHz with 9600 bps can communicate at 12800 bps when running at 16MHz.

The COM handshake signals RTS and DTR can be configured as hardware reset signals:

  • Active: Signal is always active during µVision2 Debugger communication.
  • Inactive: Signal is always inactive during µVision2 Debugger communication.
  • Reset Active: Signal is active for 500 mSec on Reset Command of µVision2 Debugger.
  • Reset Inactive: Signal is inactive for 500 mSec on Reset Command of µVision2 Debugger.
Cache Options | To speed up the screen update, the Monitor driver implements several data caches. If you want to view the actual value of port pins, timers or memory mapped external peripherals you can switch off the cache for this memory area. To get the maximum performance you should enable all caches.
Stop Program Execution with | When Serial interrupt is enabled, you can terminate a running application program with the Stop toolbar button or the ESC key in the Command page. To support this, the serial interface is not longer available for the user program. In addition, it is not allowed to reset the global Interrupt Enable (SFR Bit EA in IE.7) in your application.
Monitor Identification | Displays target information like Monitor version number, code and xdata address regions used by Monitor-51, application start address, and Flash page sizes.


FlashMon51: Tool Configuration

Tool Configuration

The ROM and RAM areas that are entered in the dialog Options - Target - Off-chip Memory must not overlap with the memory areas used by Flash Monitor-51. These ranges are supplied to the Linker if you have enabled the option Use Memory Layout from Target Dialog in the L51 Locate dialog page. Therefore you should also check that this option is set.

Depending on the 8051 derivative, the checkboxes Use On-Chip ROM and Use On-chip XRAM should not be used because this area will overlap with the Flash Monitor code and xdata area.

When the Flash Monitor-51 is Installed at Code Address 0

When the 8051 derivative does not support an alternate boot vector, the Flash Monitor-51 needs to be installed at code address 0. In this case, the application to test must be relocated to a higher address. The following examples refers to a target system where the available code memory for user programs starts at address 0x1000.

  • In the Project Options -> Target the memory areas for Off-chip Code memory must exclude the memory areas used by monitor. Example for
  • All C modules which contain interrupt functions must be translated with the control directive INTVECTOR (0x1000). This option can be set under µVision2 in the dialog Project Options -> C51 -> Interrupt vectors at address.
  • Copy the file \KEIL\C51\LIB\STARTUP.A51 into your project folder and add this file to your µVision2 project. In this copy of the STARTUP.A51 the statement CSEG AT 0 must be replaced with CSEG AT 1000H.

Using Stop Program Execution with Serial Interrupt

When you have enabled the option Stop Program Execution with Serial Interrupt, the Monitor-51 uses the serial interrupt of the UART. If you are using the standard 8051 UART, three bytes at the interrupt vector location C:0x0023 are modified by Monitor-51. You must ensure that the user program does not use these code locations. This can be done with the following C statements:

char code reserve [3] _at_ 0x23;      /* for Monitor-51 serial interrupt */


FlashMon51: Debugging Programs

Debugging Programs

To test an application with Monitor-51, select Monitor-51 as target and build the project.

Debug Command | Description
Debug | Then you may start the debug session. The µVision2 debugger connects to the MCB517 board, downloads the monitor and the application program. In case of communication problems a dialog box opens that displays further options and instructions.
Step Into
Breakpoint
Run 		Monitor-51 supports most µVision2 debugger features. You may single step through code, set breakpoints and run your application. Variables can be viewed with the standard debugger features.
Serial Window

The Keil Monitor-51 allows you to share the serial interface that is used for Monitor communication with user I/O. The Serial Window #1 shows the printf and putchar output. Disable the option Monitor Driver Settings – Serial Interrupt to enter characters that are sent to the user program.

Note

  • It is important that you skip the initialization of the serial interface in the user application, since the Monitor performs the UART setup. You may use conditional compilation as shown in our program examples. Also it is impossible to single step through putchar or getkey I/O functions.
Stop | If the option Monitor Driver Settings – Serial Interrupt is enabled, you may stop program execution with Halt command from the Debug menu or the toolbar or type ESC in Output Window – Command page. The Monitor uses the serial interrupt to halt the user program. If the Monitor cannot stop your program (because the user application has disabled interrupts or so) a dialog box opens that displays further options and instructions.
Reset CPU | The µVision2 Reset command sets the program counter to 0. However it should be noted that peripherals and SFRs of the 8051 device are not set into reset state. Therefore this command it is not identical with a hardware reset of the CPU.


FlashMon51: Troubleshooting

Troubleshooting

It can be difficult to debug and diagnose FlashMon51 configuration failures. Fortunately, there are only a few things that cause FlashMon51 problems.

If FlashMon51 does not start correctly it is typically a problem with:

  • The Monitor Code Location
  • The Monitor Data Location
  • The Serial Interface Initialization.

If FlashMon51 stops working or behaves strangely while debugging, your application is most likely overwriting the monitor XDATA memory. To determine if this is the case, check the XDATA MEMORY MAPPING in the Linker MAP (*.M51) file and compare it with the monitor XDATA memory area listed under Peripherals -> Target Settings -> Monitor-51 Identification.

If FlashMon51 cannot single-step instructions or read or write SFR data then it is unable to modify the contents of the Flash memory. Double check the flash programming algorithms in the INSTALL.A51 configuration file.

During operation the Monitor might report the following errors:

  • CONNECTION TO TARGET SYSTEM LOST
    This error indicates that µVision2 has lost the serial connection to the Monitor program. It occurs if your program reinitializes the serial interface used by the monitor. This error may also occur if you single-step into the serial I/O routines of your application.
  • NO CODE MEMORY AT ADDRESS xxxx
    This error occurs if you attempt to download code into the ROM space or into non-existing memory. Make certain that you have valid Flash programming functions for the memory region.
  • CANNOT WRITE INTERRUPT VECTOR
    This error occurs when the monitor cannot install the interrupt vectors for the serial interface or when the code memory at address 0 cannot be accessed. If you receive this error, it is likely that the IAP Flash programming routine does not work for this address region.


FlashMon51: Restrictions and Limitations

Restrictions and Limitations

Not all debug features and capabilities are available while debugging with the Flash Monitor. Typically, this is due to the bandwidth available from the serial port connecting the target hardware to the PC. The following list describes those capabilities that are either limited or unavailable when debugging with FlashMon51.

  • The memory map of the target hardware is defined by the hardware configuration. Therefore, it is not possible to use the Debug – Memory Map command to change the memory map of the target system.
  • The Performance Analyzer and Code Coverage features require MCU access for each instruction executed. This would slow target program execution by at least 1,000 times. Therefore, these features are not available.
  • The Periodic Window Update feature requires that MCU halt every few instructions so that window contents can be updated. This would slow target program execution and is therefore, not available.
  • Execution Breakpoints are handled directly by FlashMon51. However, Access Breakpoints and Conditional Breakpoints require intervention from the PC (to check address ranges or conditionals). Therefore, when these breakpoints are used, the application executes in single steps and not in real time. Single step execution is at least 1,000 times slower than full speed execution.