DocID14024 Rev 4 27/39
UM0470 Debug module (DM)
38
4.11 Application notes
4.11.1 Illegal memory access
To verify if the program attempts to write or read in an illegal part of the memory (a reserved
area), select the “Data R/W on BK1<=@<=BK2” condition, where BK1 and BK2 are the
lower and upper addresses of the reserved memory.
4.11.2 Forbidden stack access
If part of the stack contains specific data or instructions that should not be overwritten, the
DM can be used to prevent the access to these locations. Select one of the “Data Write in
Stack on @<=BK1” conditions and set BK1 to the upper value where the specific data is
located in the stack. If the STM8 device tries to overwrite these values (after an interrupt or
a CALL), the DM will generate a break. The four possible associated conditions allow to
manage another breakpoint capability at the same time.
4.11.3 DM break
After a DM break, the CPU is stalled (through the EMU_Stall signal). While the CPU is
stalled, the SWIM can read/write any memory location or any memory mapped register. The
program can be continued from the breakpoint, by resetting the stall bit.
If a change of PC is needed, the SWIM must write the new PC value using the method
described in
Section 3.7: CPU register access on page 16. In order to fetch the code from
the new PC address, the SWIM must set the FLUSH bit in the DM control/status register 2
(DM_CSR2) (refer to
Section 4.12.10 on page 33) before resetting the STALL bit.