Background Debug Module (S12SBDMV1)
MM912_637, Rev. 3.0
Freescale Semiconductor 292
5.21.4.10 Instruction Tracing
When a TRACE1 command is issued to the BDM in active BDM, the CPU exits the standard BDM firmware and executes a single
instruction in the user code. Once this has occurred, the CPU is forced to return to the standard BDM firmware, the BDM is active,
and ready t o receive a ne w comm and. If the TRACE1 command is issued again, the next user instruction will be executed. This
facilitates stepping or tracing through the user code one instruction at a time .
If an interrupt is pending when a TRACE1 command is issued, the interrupt stacking operation occurs but no user instruction is
executed. Once back in standard BDM firmware execution, the program counter points to the first instruction in the interrupt
service routine.
Be aware when tracing through the user code that the execution of the user code is done step by step, but peripherals are free
running. Hence possible timing relations between CPU code execution and occurrence of events of other peripherals no longer
exist.
Do not trace the CPU instruction BGND used for soft breakpoints. T racing over the BGND instruction will result in a return address
pointing to BDM firmware address space.
When tracing through user code which contains stop or wait instructions the following will happen when the stop or wait instruction
is traced:
The CPU enters stop or wait mode and the TRACE1 command can not be finished before leaving the low power mode.
This is the case because BDM active mode can not be entered after the CPU executed the stop instruction. However,
all BDM hardware commands except the BACKGROUND command are operational after tracing a stop or wait
instruction, and still being in stop or wait mode. If system stop mode is entered (all bus masters are in stop mode), no
BDM command is operational.
As soon as stop or wait mode is exi te d, the CPU enters BDM active mode and the saved PC value points to the entry
of the corresponding interrupt service routine.
If the handshake feature is enabled, the corresponding ACK pulse of the TRACE1 command will be discarded when
tracing a stop or wait instruction. Hence, there is no ACK pulse when BDM active mode is entered as part of the TRACE1
command, after CPU exited from stop or wait mode. All valid commands sent during CPU being in stop or wait mode or
after CPU exited from stop or wait mode will have an ACK pulse. The handshake feature becomes disabled only when
system stop mode has been reached. After a system stop mode, the handshake feature must be enabled again by
sending the ACK_ENABLE command.
5.21.4.11 Serial Communication Timeout
The host initiates a host-to-target serial transmission by generating a falling edge on the BKGD pin. If BKGD is kept low for more
than 128 target clock cycles, the target understands that a SYNC command was issued. In this case, the target will keep waiting
for a rising edge on BKGD, to answer the SYNC request pulse. If the rising ed ge is not detected, the target will keep waiting
forever without any timeout limit.
Consider now the case where the host returns BKGD to a logic one before 128 cycles. This is interpreted as a valid bit
transmission, and not as a SYNC request. The target will keep waiting for another falling edge, marking the start of a new bit. If,
a new falling edge is not detected by the target within 512 clock cycles, since the last falling edge, a timeout occurs and the current
command is discarded without affecting memory or the operating mode of the MCU. This is referred to as a soft-reset.
If a read command is issued, but the data is not retrieved within 512 serial clock cycles, a soft-reset will occur causing the
command to be disregarded. The data is not available for retrieval after the timeout has occurred. This is expected behavior if
the handshake protocol is not enabled. To allow the data to be retrieved, even with a large clock frequency mismatch (between
BDM and CPU) when the hardware handshake protocol is enabled, the timeout between a read command and the data retrieval
is disabled. Therefore, the host could wait for more then 512 serial clock cycles, and still be able to retrieve the data from an
issued read command. However, once the handshake pulse (ACK pulse) is issued, the timeout feature is re-activated, meaning
that the target will timeout after 512 clock cycles. The host needs to retrieve the dat a within a 512 serial clock cyc les time frame
after the ACK pulse had been issued. After that period, the read command is discarded and the data is no longer available for
retrieval. Any negative edge in the BKGD pin after the timeout peri od is considered to be a new command or a SYNC request.
Note that whenever a partially issued command, or partially retrieved data has occurred, the timeout in the serial communication
is active. This means that if a time frame higher than 512 serial clock cycles is observed between two consecutive negative edges
and the command being issued or data being retrieved is not complete, a soft-reset will occur causing the partially received
command or data retrieved to be disregarded. The next negative edge in th e BKGD pin, after a soft-reset has occurred, is
considered by the target as the start of a new BDM command, or the start of a SYNC request pulse.