Using the AN2548 (SerMon) Monitor With NoICE for the HC12

The Motorola/Freescale AN2548 serial monitor, also known as SerMon, can provide many of the HC12 debug features of a BDM, but at almost no cost except the loss of a serial port on the MC9S12. However, the monitor has a number of peculiarities which the user must understand, and in some cases work around, in order to achieve good results.

Some of these peculiarities could be removed by modifying the monitor code. However, reburning the monitor would require the use of a BDM pod, and is therefore not an option for many users. Thus, we will limit our discussion to the standard AN2548 monitor as provided by Motorola/Freescale and on many demo boards. Advanced users may wish to consider making the appropriate modifications.

Please read this entire document before attempting to use AN2548 with NoICE. The final section tells how to configure NoICE to use the AN2548 monitor. We strongly recommended that you download AN2548 from Motorola/Freescale's web site and read it as well.

Interrupt Vectors

The normal interrupt vectors on the MC9S12 are in the range 0xFF00 to 0xFFFF.  This range falls within the 2K range 0xF800 to 0xFFFF that is used by the AN2548 monitor and is protected against erasure and writing, so user programs cannot place their interrupt vectors here.

In order to allow user programs to use interrupts, the AN2548 monitor redirects interrupt vectors to a set of "pseudo-vectors" in Flash just below the monitor, namely from 0xF700 to 0xF7FF. All this is handled by the monitor, so you can build your program withe the vectors in their normal locations. (With the AN2140 monitor on the HC08 you have to relocate the vectors yourself.)

The AN2548 monitor requires the use of the SWI, ICG, and SCI (tx, rx and error) vectors. Thus, these interrupts are not available to user programs, and must not be used in the hex files that your download to the AN2548 monitor.

Entering Monitor Mode

At reset, the chip will enter monitor mode only if at least one of the following conditions is present

Many demo boards have a pushbutton on the port bit in order to force an entry to the monitor. However, it is highly annoying to try and remember to push the button each time you power on or reset your target.  Use of this option also restricts what your application program can do with the port bit.

In order to avoid the need to hold the port pin low at reset, NoICE offers the "Don't burn reset vector" option. When this is checked, NoICE will not burn the user reset vector during program load/burn.  Instead, NoICE retains the value that would have been written to this vector and stores it in the Windows Registry.

When the target powers up with the user reset vector blank, it enters the monitor and sets the initial PC to 0xFFFF. If NoICE has been configured not to burn the reset vector, it will change the PC to the retained value from the last load.  The effect during debugging is as if the user reset vector had been burned. This is usually the most convenient setting when debugging under NoICE. However, if you want your program to run without entering the monitor, you will need to de-select the option and reburn your program, including the user reset vector.

Whether or not the user reset vector is blank, the chip can be forced to start up in monitor mode by holding the serial receive line low as the chip comes out of reset.  This is not really practical when you power up your target board, since NoICE has no way of knowing that you intend to do so. However, when you use the NoICE RESET command (on the Run menu), NoICE sends the AN2548 CMD_RESET command, followed by a 200 msec serial break.  This should cause a reset into monitor mode regardless of whether or not the reset vector is blank or the port pin is being held low.

In contrast, BDM has control of processor reset, and can generally force entry into debug mode without any of these restrictions.

Stopping a Running Program

The AN2548 protocol has a CMD_HALT to stop a target program. However, in order to be acted upon this command must be seen by the target monitor. The monitor initializes the SCI for receive interrupts.  If your program enables interrupts with a CLI instruction or by other means, then NoICE will be able to stop a running program.

If your program doesn’t enable interrupts, or disables them for long periods, or disables the SCI in some fashion, then the target will not be able to respond to CMD_HALT, and NoICE will not be able to stop your program.

Note that even if your program has disabled interrupts (or never enabled them), the program can still re-enter the monitor if it reaches a previously set breakpoint.  Thus, by careful positioning of breakpoints you can debug programs even if interrupts cannot be enabled.

In contrast, BDM is able to stop a program regardless of its interrupt state.

CMD_HALT will not work if the target has executed the STOP instruction, because STOP stops system clocks, including the one that makes the SCI operate. The demo program provided by Motorola/Freescale with their GB60 demo board includes one (the default) that spends most of its time in the STOP state.  This program is not a good choice for experimenting with the serial monitor!

Using printf Output

While the target is running, the target program may use the UART to communicate with NoICE on the PC. If the target sends a byte in the range 0 to 127 decimal, NoICE will display it in the Output Window. Values 128 (0x80) and above are used by the Serial Monitor, and may not be used. If your target sends such a character, NoICE communications may be disrupted.

The AN2548 monitor uses receive interrupts. This allows NoICE to stop a running program, and to read and write memory while the target is running. However, it also means that if NoICE sends a keyhit character, the receive interrupt will cause entry to the monitor, where the character will be seen as an illegal command. The target program will never see it.

Thus, your AN2548 target can use printf, but not getchar during debugging.

Accessing Memory While a Program is Running

The AN2548 protocol allows NoICE to read and write target memory even while a target program is running. As with CMD_HALT, however, the commands must be seen by the target monitor in order to be acted upon .  So as with CMD_HALT, if you want to read and write memory while your program is running, you must enable interrupts and avoid the STOP instruction.

There are a few additional cautions

In contrast BDM is able access target memory during dead bus cycles, and thus usually has no impact on the timing of a running program.

Other Restrictions on User Programs

In addition to the restrictions on interrupts mentioned in the previous section, the AN2548 monitor initializes certain peripheral devices.  In general, your application program should not reinitialize them, as doing so is likely to cause the monitor to stop operating.  Peripherals include the PLL, COP and SCI.  Please examine the source code for the AN2548 monitor being used on your target in order to understand what initialization is being done by the AN2548 monitor.

A related note is that since the AN2548 monitor does this initialization for your, and also initializes SP, it is easy to forget that when your program needs to run without the monitor, it must perform this initialization itself.  This is one of the most common sorts of bugs in embedded systems work.

Summary

There is no question that BDM provides features that cannot be matched by the AN2548 serial monitor.  On the other hand, the monitor is almost free, and does not incur the expense of a BDM pod.

When NoICE was first released in 1993, it depended on a target monitor similar to the AN2548 monitor. Indeed, this monitor is still in use on HC11, Z80, 6502 and 8051 targets.  For over ten years, hundreds of users have found NoICE and the target monitor to be a useful and valuable debugging tool.  The same is certainly true of NoICE and the AN2548 monitor.

NoICE Setup for AN2548


MC9S08 AN2548 Setup
Click on a field for more information about its function.

Port and Baud Rate

NoICE allows you to select a standard baud rate from a drop-list. You can also enter a non-standard rate, should your application require it. However, be aware that a standard PC serial port can only generate baud rates that are exact integer divisors of 115,200. Thus, the PC can generate 9600 baud (115200/12), or 10472.73 baud (115200/11), but not 10000 baud. If you enter a baud rate of 10000, Windows will chose the closest available baud rate. Since the closest available rate in this case is about 4 percent off, operation is not likely to be satisfactory. In such a case, you might try to find a lower baud rate that can be suppored by both the target and the PC.

If NoICE is unable to communicate with the target at the rate you specify, it will try again at 230400, 115200, 57600, 38400, 19200, and 9600 baud before declaring a failure.

AN2548 works well with USB-serial adapters, as well as "real" PC serial ports.

Processor Configuration

Motorola/Freescale likes to change peripheral addresses from one processor to another. Among the addresses moved are the hardware breakpoint. Because of this, you must select your processor chip from the drop-list in the NoICE communications dialog. A status box shows the configuration of the selected chip.


NoICE (tm) Debugger, Copyright © 2012 by John Hartman

Using NoICE - Contact us - NoICE Home