3.3Low voltage detect (LVD) system..................................................................................................................................40
3.5Power management control bits and registers................................................................................................................ 42
3.5.1System Power Management Status and Control 1 Register (PMC_SPMSC1)................................................42
3.5.2System Power Management Status and Control 2 Register (PMC_SPMSC2)................................................44
4.2Reset and interrupt vector assignments...........................................................................................................................46
4.3Register addresses and bit assignments.......................................................................................................................... 47
4.5Flash and EEPROM........................................................................................................................................................56
4.5.2.8Flash and EEPROM commands.......................................................................................................70
4.5.2.9Flash and EEPROM command summary........................................................................................ 72
4.6Flash and EEPROM registers descriptions.....................................................................................................................86
5.1.2Interrupt vectors, sources, and local masks......................................................................................................99
5.3.1Interrupt Pin Request Status and Control Register (IRQ_SC).........................................................................108
5.4Interrupt priority control register.................................................................................................................................... 109
5.4.1IPC Status and Control Register (IPC_SC)......................................................................................................110
6.3Reset and system initialization........................................................................................................................................113
6.6System Control Registers................................................................................................................................................118
6.6.1System Reset Status Register (SYS_SRS).......................................................................................................119
6.6.2System Background Debug Force Reset Register (SYS_SBDFR)..................................................................121
6.6.3System Device Identification Register: High (SYS_SDIDH)......................................................................... 121
7.2Port data and data direction.............................................................................................................................................133
7.5High current drive...........................................................................................................................................................134
7.6Pin behavior in stop mode...............................................................................................................................................134
7.7Port data registers............................................................................................................................................................134
7.7.1Port A Data Register (PORT_PTAD)..............................................................................................................135
7.7.2Port B Data Register (PORT_PTBD).............................................................................................................. 136
7.7.3Port C Data Register (PORT_PTCD).............................................................................................................. 136
7.7.4Port High Drive Enable Register (PORT_HDRVE)........................................................................................137
7.7.5Port A Output Enable Register (PORT_PTAOE)............................................................................................137
7.7.6Port B Output Enable Register (PORT_PTBOE)............................................................................................ 138
7.7.7Port C Output Enable Register (PORT_PTCOE)............................................................................................ 139
7.7.8Port A Input Enable Register (PORT_PTAIE)................................................................................................140
7.7.9Port B Input Enable Register (PORT_PTBIE)................................................................................................ 141
7.7.10Port C Input Enable Register (PORT_PTCIE)................................................................................................ 142
8.2.2Modes of operation.......................................................................................................................................... 156
8.2.3FLL lock and clock monitor.............................................................................................................................161
8.6ICS control registers....................................................................................................................................................... 166
8.6.1ICS Control Register 1 (ICS_C1).................................................................................................................... 167
8.6.2ICS Control Register 2 (ICS_C2).................................................................................................................... 168
8.6.3ICS Control Register 3 (ICS_C3).................................................................................................................... 169
8.6.4ICS Control Register 4 (ICS_C4).................................................................................................................... 169
8.6.5ICS Status Register (ICS_S)............................................................................................................................ 170
8.6.6OSC Status and Control Register (ICS_OSCSC)............................................................................................ 171
8.7System clock gating control registers............................................................................................................................. 172
8.7.1System Clock Gating Control 1 Register (SCG_C1).......................................................................................173
8.7.2System Clock Gating Control 2 Register (SCG_C2).......................................................................................174
8.7.3System Clock Gating Control 3 Register (SCG_C3).......................................................................................175
8.7.4System Clock Gating Control 4 Register (SCG_C4).......................................................................................175
9.2.1Central processor unit (CPU)...........................................................................................................................177
10.2 Programmer's Model and CPU Registers....................................................................................................................... 198
10.3.7Memory to memory Addressing Mode............................................................................................................ 206
10.3.7.1 Direct to Direct.................................................................................................................................206
10.3.7.2 Immediate to Direct......................................................................................................................... 206
10.3.7.3 Indexed to Direct, Post Increment....................................................................................................206
10.3.7.4 Direct to Indexed, Post-Increment................................................................................................... 207
10.6 Special Operations.......................................................................................................................................................... 211
10.7 Instruction Set Summary.................................................................................................................................................212
11.1.2Modes of Operation......................................................................................................................................... 225
11.1.2.1 KBI in Wait mode............................................................................................................................225
11.1.2.2 KBI in Stop modes...........................................................................................................................226
11.1.2.3 KBI in Active Background mode.....................................................................................................226
11.4 Memory Map and Registers............................................................................................................................................227
11.5.2Edge and level sensitivity................................................................................................................................ 230
12.1.3Modes of operation.......................................................................................................................................... 234
12.2 Signal description............................................................................................................................................................235
Status and Control (FTMx_SC)....................................................................................................................... 238
Counter High (FTMx_CNTH)......................................................................................................................... 239
12.4.3.1 Up counting......................................................................................................................................246
12.4.8Update of the registers with write buffers........................................................................................................254
13.2.1Modes of operation.......................................................................................................................................... 259
14.1.2Modes of operation.......................................................................................................................................... 269
14.2 SCI signal descriptions................................................................................................................................................... 272
14.2.1Detailed signal descriptions............................................................................................................................. 272
SCI Control Register 1 (SCIx_C1)...................................................................................................................274
SCI Control Register 2 (SCIx_C2)...................................................................................................................276
SCI Status Register 1 (SCIx_S1)..................................................................................................................... 277
SCI Status Register 2 (SCIx_S2)..................................................................................................................... 279
SCI Control Register 3 (SCIx_C3)...................................................................................................................280
SCI Data Register (SCIx_D)............................................................................................................................282
14.4.2.1 Send break and queued idle............................................................................................................. 284
14.4.3.1 Data sampling technique..................................................................................................................286
14.4.4Interrupts and status flags................................................................................................................................ 288
14.4.5.1 Slow data tolerance.......................................................................................................................... 289
14.4.5.2 Fast data tolerance............................................................................................................................291
14.4.6.1 8- and 9-bit data modes....................................................................................................................292
15.2 External Signal Description............................................................................................................................................ 296
15.2.1Analog Power (VDDA)................................................................................................................................... 297
15.2.3Voltage Reference High (VREFH).................................................................................................................. 297
15.3 ADC Control Registers...................................................................................................................................................298
15.3.1Status and Control Register 1 (ADC_SC1)......................................................................................................298
15.3.2Status and Control Register 2 (ADC_SC2)......................................................................................................300
15.3.3Status and Control Register 3 (ADC_SC3)......................................................................................................301
15.3.4Status and Control Register 4 (ADC_SC4)......................................................................................................302
15.3.5Conversion Result High Register (ADC_RH)................................................................................................. 303
15.3.6Conversion Result Low Register (ADC_RL).................................................................................................. 304
15.3.7Compare Value High Register (ADC_CVH)...................................................................................................305
15.3.8Compare Value Low Register (ADC_CVL)....................................................................................................305
15.3.9Pin Control 1 Register (ADC_APCTL1)......................................................................................................... 306
15.4.4.4 Power control................................................................................................................................... 311
15.4.4.5 Sample time and total conversion time............................................................................................311
15.6.1External pins and routing................................................................................................................................. 321
15.6.1.1 Analog supply pins...........................................................................................................................321
15.6.1.2 Analog reference pins...................................................................................................................... 321
15.6.1.3 Analog input pins.............................................................................................................................322
15.6.2Sources of error................................................................................................................................................ 323
16.1.2Modes of operation.......................................................................................................................................... 327
16.1.2.1 Operation in Wait mode...................................................................................................................328
16.1.2.2 Operation in Stop3 mode................................................................................................................. 328
16.1.2.3 Operation in Debug mode................................................................................................................328
16.2 External signal description..............................................................................................................................................329
16.3 Memory map and register definition...............................................................................................................................329
16.3.1ACMP Control and Status Register (ACMP_CS)........................................................................................... 330
16.3.2ACMP Control Register 0 (ACMP_C0).......................................................................................................... 331
16.3.3ACMP Control Register 1 (ACMP_C1).......................................................................................................... 331
16.3.4ACMP Control Register 2 (ACMP_C2).......................................................................................................... 332
16.5 Setup and operation of ACMP........................................................................................................................................333
17.3.1.2 Refreshing the Watchdog.................................................................................................................344
17.3.1.3 Example code: Refreshing the Watchdog........................................................................................345
17.3.2Configuring the Watchdog...............................................................................................................................345
17.3.2.1 Reconfiguring the Watchdog........................................................................................................... 345
17.3.2.2 Unlocking the Watchdog................................................................................................................. 346
17.3.2.3 Example code: Reconfiguring the Watchdog.................................................................................. 346
17.3.6Functionality in debug and low-power modes................................................................................................. 348
17.3.7Fast testing of the watchdog.............................................................................................................................349
17.3.7.1 Testing each byte of the counter...................................................................................................... 349
17.3.7.2 Entering user mode.......................................................................................................................... 350
18.1.1Forcing active background...............................................................................................................................351
18.3 On-chip debug system (DBG)........................................................................................................................................ 359
18.3.1Comparators A and B.......................................................................................................................................360
18.3.2Bus capture information and FIFO operation.................................................................................................. 360
18.3.4Tag vs. force breakpoints and triggers............................................................................................................. 362
19.1.2Modes of operation.......................................................................................................................................... 372
19.2 Signal description............................................................................................................................................................373
19.3 Memory map and registers..............................................................................................................................................373
19.3.1Debug Comparator A High Register (DBG_CAH)......................................................................................... 374
19.3.2Debug Comparator A Low Register (DBG_CAL).......................................................................................... 375
19.3.3Debug Comparator B High Register (DBG_CBH)..........................................................................................376
19.3.4Debug Comparator B Low Register (DBG_CBL)...........................................................................................376
19.3.5Debug Comparator C High Register (DBG_CCH)..........................................................................................377
19.3.6Debug Comparator C Low Register (DBG_CCL)...........................................................................................378
19.3.7Debug FIFO High Register (DBG_FH)...........................................................................................................378
19.3.9Debug Comparator A Extension Register (DBG_CAX)................................................................................. 380
19.3.10 Debug Comparator B Extension Register (DBG_CBX)..................................................................................381
19.3.11 Debug Comparator C Extension Register (DBG_CCX)..................................................................................382
19.3.12 Debug FIFO Extended Information Register (DBG_FX)................................................................................383
19.3.13 Debug Control Register (DBG_C)...................................................................................................................383
19.3.15 Debug Status Register (DBG_S)......................................................................................................................386
19.3.16 Debug Count Status Register (DBG_CNT)..................................................................................................... 387
19.4.4Trigger break control (TBC)............................................................................................................................ 390
19.4.4.1 Begin- and end-trigger..................................................................................................................... 391
19.4.4.2 Arming the DBG module.................................................................................................................391
19.4.5.1 Storing data in FIFO........................................................................................................................ 395
19.4.5.2 Storing with begin-trigger................................................................................................................395
19.4.5.3 Storing with end-trigger...................................................................................................................395
19.4.5.4 Reading data from FIFO.................................................................................................................. 395
These devices are members of the low-cost, high-performance HCS08 family of 8-bit
microcontroller units (MCUs). All MCUs in the family use the enhanced HCS08 central
processor unit and are available with a variety of modules, memory sizes and types, and
package types. The following table summarizes the peripheral availability per package
type for the devices available.
1. PTA4/ACMPO/BKGD/MS is an output-only pin when used as port pin.
1
2
3. PTB4 and PTB5 can provide high sink/source current drive.
2-CH FLEX TIMER
MODULE (FTM2 )
Chapter 1 Device Overview
Figure 1-1. MCU block diagram
1.3
These series contain three on-chip clock sources:
NXP Semiconductors25
System clock distribution
• Internal clock source (ICS) module — The main clock source generator providing
bus clock and other reference clocks to peripherals
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
ICSLCLK
ICSFFCLK
XTAL
EXTAL
WDG
RTC
FTM0
FTM1
ADC
SCI0
CPUBDCFLASH
ACMP
RAM
LPOCLK
ICS
OSC
OSCOUT
1-kHz
LPO
ICSIRCLK
IPCDBG
KBI0
TCLK1
TCLK0
ICSCLK (~8 MHz after reset)
1/2
FTM2
System clock distribution
• External oscillator (XOSC) module — The external oscillator providing reference
clock to internal clock source (ICS), the real-time clock counter clock module (RTC)
and other MCU sub-systems.
• Low-power oscillator (LPO) module — The on-chip low-power oscillator providing
1 kHz reference clock to RTC and watchdog (WDOG).
NOTE
For this device, the system clock is the bus clock.
The following figure shows a simplified clock connection diagram.
Figure 1-2. System clock distribution diagram
The clock system supplies:
• ICSCLK(BUS) — This up to 20 MHz clock source is used as the bus clock that is
the reference to CPU and all peripherals. Control bits in the ICS control registers
determine which of the clock sources is connected:
• Internal reference clock
• External reference clock
• Frequency-locked loop (FLL) output
• ICSLCLK — This clock source is derived from the digitally controlled oscillator
(DCO) of the ICS when the ICS is configured to run off of the internal or external
reference clock. Development tools can select this internal self-clocked source (8
MHz) to speed up BDC communications in systems where the bus clock is slow.
26NXP Semiconductors
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
Chapter 1 Device Overview
• ICSIRCLK — This is the internal reference clock and can be selected as the clock
source to the WDOG module.
• ICSFFCLK — This generates the fixed frequency clock (FFCLK) after being
synchronized to the bus clock. It can be selected as clock source to the FTM
modules. The frequency of the ICSFFCLK is determined by the setting of the ICS.
• LPOCLK — This clock is generated from an internal low power oscillator (≈1 kHz)
that is completely independent of the ICS module. The LPOCLK can be selected as
the clock source to the RTC or WDOG modules.
• OSCOUT — This is the direct output of the external oscillator module and can be
selected as the clock source for RTC, WDOG and ADC.
• TCLK0 — This is an optional external clock source for the FTM0 module. The
TCLK0 must be limited to 1/4th frequency of the bus clock for synchronization.
• TCLK1 — This is an optional external clock source for the FTM1 module. The
TCLK1 must be limited to 1/4th frequency of the bus clock for synchronization.
VDD and VSS are the primary power supply pins for the MCU. This voltage source
supplies power to all I/O buffer circuitry and to an internal voltage regulator. The internal
voltage regulator provides a regulated lower-voltage source to the CPU and to the MCU's
other internal circuitry.
Typically, application systems have two separate capacitors across the power pins. In this
case, there should be a bulk electrolytic capacitor, such as a 10 µF tantalum capacitor,
that provides bulk charge storage for the overall system and a 0.1 µF ceramic bypass
capacitor located as near to the paired VDD and VSS power pins as practical to suppress
high-frequency noise.
30NXP Semiconductors
Figure 2-4. Power supply bypassing
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
MCU
EXTAL
XTAL
R
s
R
F
C1
C2
X1
Chapter 2 Pins and connections
2.2.2Oscillator (XTAL, EXTAL)
The XTAL and EXTAL pins are used to provide the connections for the on-chip
oscillator. The oscillator (XOSC) in this MCU is a Pierce oscillator that can
accommodate a crystal or ceramic resonator. Optionally, an external clock source can be
connected to the EXTAL input pin. The oscillator can be configured to run in stop3
mode.
Refer to the following figure, RS (when used) and RF must be low-inductance resistors
such as carbon composition resistors. Wire-wound resistors, and some metal film
resistors, have too much inductance. C1 and C2 normally must be high-quality ceramic
capacitors that are specifically designed for high-frequency applications.
Figure 2-5. Typical crystal or resonator circuit
RF is used to provide a bias path to keep the EXTAL input in its linear range during
crystal startup; its value is not generally critical. Typical systems use 1 M to 10 M.
Higher values are sensitive to humidity and lower values reduce gain and (in extreme
cases) could prevent startup.
C1 and C2 are typically in the 5 pF to 25 pF range and are chosen to match the
requirements of a specific crystal or resonator. Take into account printed circuit board
(PCB) capacitance and MCU pin capacitance when selecting C1 and C2. The crystal
manufacturer typically specifies a load capacitance, which is the series combination of
C1 and C2 (which are usually the same size). As a first-order approximation, use 10 pF as
an estimate of combined pin and PCB capacitance for each oscillator pin (EXTAL and
XTAL).
NXP Semiconductors31
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
MCU
V
DD
PTA5/IRQ/FTM1CH0/RESET
V
SS
F
0.1
4.7k
10k
Pin functions
2.2.3External reset pin (RESET) and interrupt pin (IRQ)
A low on the RESET pin forces the MCU to an known startup state. RESET is
bidirectional, allowing a reset of the entire system. It is driven low when any internal
reset source is asserted. This pin contains an internal pullup resistor.
RESET shares an I/O pin with PTA5. The RESET pin function is enabled by default after
POR reset, because internal power-on reset and low-voltage reset circuitry typically make
external reset circuitry unnecessary. This pin is normally connected to the standard 6-pin
background debug connector so that a development system can directly reset the MCU
system. If RESET function of PTA5/IRQ/FTM1CH0/RESET pin is enabled, a manual
external reset can be added by supplying a simple switch to ground (pull reset pin low to
force a reset). When the RESET pin function is enabled, an internal pullup resistor is
connected to this pin and a reset signal can feed into MCU with an input hysteresis. POR
reset brings RESET pin into its default configuration, reset other than POR has no effect
on the RESET pin function configuration.
When PTA5/IRQ/FTM1CH0/RESET is enabled as IRQ pin, it is the input source for the
IRQ interrupt and is also the input for the BIH and BIL instructions. IRQ is asynchronous
external interrupt pins.
In EMC-sensitive applications, an external RC filter is recommended on the reset pin.
See the following figure for example.
During a power-on-reset (POR) or background debug force reset, the PTA4/ACMPO/
BKGD/MS pin functions as a mode select pin. Immediately after internal reset rises the
pin functions as the background pin and can be used for background debug
communication. While the pin functions as a background/mode selection pin, it includes
an internal pullup device and a standard output driver.
The background debug communication function is enabled when SOPT1[BKGDPE] bit
is set. SOPT1[BKGDPE] is set following any reset of the MCU and must be cleared to
use the PTA4/ACMPO/BKGD/MS pin's alternative pin functions.
If this pin is floating, the MCU will enter normal operating mode at the rising edge of
reset. If a debug system is connected to the 6-pin standard background debug header, it
can hold BKGD/MS low during the POR or immediately after issuing a background
debug force reset, which will force the MCU into active background mode.
The BKGD pin is used primarily for background debug controller (BDC)
communications using a custom protocol that uses 16 clock cycles of the target MCU's
BDC clock per bit time. The target MCU's BDC clock can run as fast as the bus clock, so
there should never be any significant capacitance connected to the BKGD/MS pin that
interferes with background serial communications. When the pin performs output only
PTA4, it can drive only capacitance-limited MOSFET. Driving a bipolar transistor
directly by PTA4 is prohibited because this can cause mode entry fault and BKGD errors.
Although the BKGD pin is a pseudo open-drain pin, the background debug
communication protocol provides brief, actively driven, high speedup pulses to ensure
fast rise time. Small capacitances from cables and the absolute value of the internal
pullup device play almost no role in determining rise and fall time on the BKGD pin.
NXP Semiconductors33
Figure 2-7. Typical debug circuit
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
Pin functions
2.2.5Port A input/output (I/O) pins (PTA5–PTA0)
PTA5–PTA0 except PTA4 are general-purpose, bidirectional I/O port pins. These port
pins also have selectable pullup devices when configured for input mode except PTA4.
The pullup devices are selectable on an individual port bit basis. The pulling devices are
disengaged when configured for output mode.
PTA4 is output only when used as port pin. The pulling device is disabled at this
condition.
2.2.6
PTB7–PTB0 are general-purpose, bidirectional I/O port pins. These port pins also have
selectable pullup devices when configured for input mode, the pullup devices are
selectable on an individual port bit basis. The pulling devices are disengaged when
configured for output mode.
PTB0 provide true open drain when operated as output.
2.2.7
PTC3–PTC0 are general-purpose, bidirectional I/O port pins. These port pins also have
selectable pullup devices when configured for input mode, and the pullup devices are
selectable on an individual port bit basis. The pulling devices are disengaged when
configured for output mode.
2.2.8
Port B input/output (I/O) pins (PTB7–PTB0)
Port C input/output (I/O) pins (PTC3–PTC0)
True open drain pins (PTB0)
PTB0 operates in true open drain mode.
2.2.9
When high current function is enabled, PTB4 and PTB5 can drive output current. Each
high current drive pin can drive higher sink/source current than the other normal pins,
please refer to data sheet for the drive capacity.
34NXP Semiconductors
High current drive pins (PTB4, PTB5)
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
Chapter 2 Pins and connections
2.3Peripheral pinouts
These MCUs support up to 18 general-purpose I/O pins, which are shared with on-chip
peripheral functions (FTM, ACMP, ADC, SCI, KBI, etc.). These 18 general-purpose I/O
pins include one output-only pin (PTA4).
When a port pin is configured as general-purpose input, or when a peripheral uses the
port pin as an input, the software can enable a pullup device.
When a high current drive port pin is configured as general-purpose output or when a
peripheral uses the port pin as an output, software can select alternative drive strengths.
For information about controlling these pins as general-purpose I/O pins, see the Parallel
input/output. For information about how and when on-chip peripheral systems use these
pins, see the appropriate module chapter.
Immediately after reset, all pins are configured as high-impedance general-purpose IO
1. This is a high current drive pin when operated as output. Please see High current drive for more information.
2. This is a high current drive pin when operated as output. Please see High current drive for more information.
3. This is a true open-drain pin when operated as output.
Note
When an alternative function is first enabled, it is possible to
get a spurious edge to the module. User software must clear any
associated flags before interrupts are enabled. The table above
illustrates the priority if multiple modules are enabled. The
highest priority module will have control over the pin. Selecting
a higher priority pin function with a lower priority function
already enabled can cause spurious edges to the lower priority
module. Disable all modules that share a pin before enabling
another module.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
36NXP Semiconductors
Chapter 3
Power management
3.1Introduction
The operating modes of the device are described in this chapter. Entry into each mode,
exit from each mode, and functionality while in each of the modes are described.
3.2
These MCUs feature the following power modes:
3.2.1
Features
• Run mode
• Wait mode
• CPU shuts down to conserve power
• Bus clocks are running
• Full voltage regulation is maintained
• Stop3 modes
• System clocks stopped; voltage regulator in standby
• all internal circuits powered for fast recovery
Run mode
This is the normal operating mode. In this mode, the CPU executes code from internal
memory with execution beginning at the address fetched from memory at 0xFFFE:
0xFFFF after reset. The power supply is fully regulating and all peripherals can be active
in run mode.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors37
Features
3.2.2Wait mode
Wait mode is entered by executing a WAIT instruction. Upon execution of the WAIT
instruction, the CPU enters a low-power state in which it is not clocked. The I bit in CCR
is cleared when the CPU enters the wait mode, enabling interrupts. When an interrupt
request occurs, the CPU exits the wait mode and resumes processing, beginning with the
stacking operations leading to the interrupt service routine.
While the MCU is in wait mode, there are some restrictions on which background debug
commands can be used. Only the BACKGROUND command and memory-access-withstatus commands are available when the MCU is in wait mode. The memory-access-withstatus commands do not allow memory access, but they report an error indicating that the
MCU is in either stop or wait mode. The BACKGROUND command can be used to
wake the MCU from wait mode and enter active background mode.
3.2.3
Stop3 mode
To enter stop3, the user must execute a STOP instruction with stop mode enabled
(SOPT1[STOPE] = 1). Upon entering the stop3 mode, all of the clocks in the MCU are
halted by default, but OSC clock and internal reference clock can be turned on by setting
the ICS control registers. The ICS enters its standby state, as does the voltage regulator
and the ADC. The states of all of the internal registers and logic, as well as the RAM
content, are maintained. The I/O pin states are not latched at the pin. Instead they are
maintained by virtue of the states of the internal logic driving the pins being maintained.
Exit from stop3 is done by asserting reset or through an interrupt. The interrupt include
the asynchronous interrupt from the IRQ or KBI pins, the SCI receive interrupt, the ADC,
ACMP or LVI interrupt and the real-time interrupt.
If stop3 is exited by means of the
RESET pin, then the MCU will be reset and operation
will resume after taking the reset vector. Exit by means of an asynchronous interrupt or
the real-time interrupt will result in the MCU taking the appropriate interrupt vector.
The LPO (≈1 kHz) for the real-time counter clock allows a wakeup from stop3 mode with
no external components. When RTC_SC2[RTCPS] is clear, the real-time counter clock
function is disabled.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
38NXP Semiconductors
Chapter 3 Power management
3.2.4Active BDM enabled in stop3 mode
Entry into the active background mode from run mode is enabled if the
BDC_SCR[ENBDM] bit is set. This register is described in the development support. If
BDC_SCR[ENBDM] is set when the CPU executes a STOP instruction, the system
clocks to the background debug logic remain active when the MCU enters stop mode, so
background debug communication is still possible. In addition, the voltage regulator does
not enter its low-power standby state but maintains full internal regulation.
Most background commands are not available in stop mode. The memory-access-withstatus commands do not allow memory access, but they report an error indicating that the
MCU is in either stop or wait mode. The BACKGROUND command can be used to
wake the MCU from stop and enter active background mode if the BDC_SCR[ENBDM]
bit is set. After entering background debug mode, all background commands are
available.
3.2.5
LVD enabled in stop mode
The LVD system is capable of generating either an interrupt or a reset when the supply
voltage drops below the LVD voltage. If the LVD is enabled in stop (LVDE and LVDSE
bits in SPMSC1 both set) at the time the CPU executes a STOP instruction, then the
voltage regulator remains active during stop3 mode.
3.2.6
Power modes behaviors
Executing the WAIT or STOP command puts the MCU in a low power consumption
mode for standby situations. The system integration module (SIM) holds the CPU in a
non-clocked state. The operation of each of these modes is described in the following
subsections. Both STOP and WAIT clear the interrupt mask (I) in the condition code
register, allowing interrupt to occur. The following table shows the low power mode
behaviors.
Table 3-1. Low power mode behavior
ModeRunWaitStop3
PMCFull regulationFull regulationLoose regulation
ICSOnOnOptional on
OSCOnOnOptional on
LPOOnOnOn
CPUOnStandbyStandby
FLASHOnOnStandby
Table continues on the next page...
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors39
Low voltage detect (LVD) system
Table 3-1. Low power mode behavior (continued)
ModeRunWaitStop3
RAMOnStandbyStandby
ADCOnOnOptional on
ACMPOnOnOptional on
I/OOnOnStates held
SCIOnOnStandby
FTMOnOnStandby
WDOGOnOnStandby
DBGOnOnStandby
IPCOnOnStandby
RTCOnOnOptional on
LVDOnOnOptional on
3.3Low voltage detect (LVD) system
This device includes a system to protect against low voltage conditions in order to protect
memory contents and control MCU system states during supply voltage variations. This
system consists of a power-on reset (POR) circuit and an LVD circuit with a user
selectable trip voltage, either high (V
when SPMSC1[LVDE] is set and the trip voltage is selected by SPMSC2[LVDV]. The
LVD is disabled upon entering the stop modes unless the SPMSC1[LVDSE] bit is set or
active BDM enabled (BDCSCR[ENBDM]=1). If SPMSC1[LVDSE] and
SPMSC1[LVDE] are both set, the current consumption in stop3 with the LVD enabled
will be greater.
LVDH
) or low (V
). The LVD circuit is enabled
LVDL
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
40NXP Semiconductors
Bandgap
+
vD
D
v
ss
v
BG
R
1
R
7
LVDV:LVDWV
LVD0
LVD1
LVD
+
LVW
LVW0
LVW1
LVW2
LVW3
Chapter 3 Power management
Figure 3-1. Low voltage detect (LVD) block diagram
3.3.1
Power-on reset (POR) operation
When power is initially applied to the MCU, or when the supply voltage drops below the
V
LVD circuit will hold the chip in reset until the supply has risen above the V
level, the POR circuit will cause a reset condition. As the supply voltage rises, the
POR
LVDL
level.
Both the SRS[POR] and SRS[LVD] are set following a POR.
3.3.2
LVD reset operation
The LVD can be configured to generate a reset upon detection of a low voltage condition
by setting SPMSC1[LVDRE] to 1. After an LVD reset has occurred, the LVD system
will hold the MCU in reset until the supply voltage has risen above the level determined
by LVDV. The SRS[LVD] bit is set following either an LVD reset or POR.
3.3.3
Low-voltage warning (LVW)
The LVD system has a low voltage warning flag to indicate that the supply voltage is
approaching the LVD voltage. When a low voltage condition is detected and the LVD
circuit is configured for interrupt operation (SPMSC1[LVDE] set, SPMSC1[LVWIE]
set), SPMSC1[LVWF] will be set and LVW interrupt will occur. There are four userselectable trip voltages for the LVW upon each LVDV configuration. The trip voltage is
selected by SPMSC2[LVWV].
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors41
Bandgap reference
3.4Bandgap reference
This device includes an on-chip bandgap reference (≈1.2V) connected to ADC channel
and ACMP. The bandgap reference voltage will not drop under the full operating voltage
even when the operating voltage is falling. This reference voltage acts as an ideal
reference voltage for accurate measurements.
3.5Power management control bits and registers
PMC memory map
Absolute
address
(hex)
3040
3041
Register name
System Power Management Status and Control 1 Register
(PMC_SPMSC1)
System Power Management Status and Control 2 Register
(PMC_SPMSC2)
Width
(in bits)
Access Reset value
8R/W1Ch3.5.1/42
8R/W00h3.5.2/44
Section/
page
3.5.1System Power Management Status and Control 1 Register
(PMC_SPMSC1)
This high page register contains status and control bits to support the low-voltage
detection function, and to enable the bandgap voltage reference for use by the ADC
module. This register should be written during the user's reset initialization program to
set the desired controls, even if the desired settings are the same as the reset settings.
Address:
3040h base + 0h offset = 3040h
Bit76543210
ReadLVWF0
WriteLVWACK
Reset
00011100
LVWIELVDRELVDSELVDEBGBDSBGBE
PMC_SPMSC1 field descriptions
FieldDescription
7
LVWF
42NXP Semiconductors
Low-Voltage Warning Flag
The LVWF bit indicates the low-voltage warning status.
Table continues on the next page...
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
PMC_SPMSC1 field descriptions (continued)
FieldDescription
6
LVWACK
5
LVWIE
4
LVDRE
NOTE:
0Low-voltage warning is not present.
1Low-voltage warning is present or was present.
Low-Voltage Warning Acknowledge
If LVWF = 1, a low-voltage condition has occurred. To acknowledge this low-voltage warning, write 1 to
LVWACK, which automatically clears LVWF to 0 if the low-voltage warning is no longer present.
Low-Voltage Warning Interrupt Enable
This bit enables hardware interrupt requests for LVWF.
0Hardware interrupt disabled (use polling).
1Request a hardware interrupt when LVWF = 1.
Low-Voltage Detect Reset Enable
This write-once bit enables LVD events to generate a hardware reset (provided LVDE = 1).
LVWF will be set in the case when V
is already below V
. LVWF bit may be 1 after power on reset, therefore, to use LVW interrupt
LVW
transitions below the trip point or after reset and V
Supply
function, before enabling LVWIE, LVWF must be cleared by writing LVWACK first.
Chapter 3 Power management
Supply
3
LVDSE
2
LVDE
1
BGBDS
0
BGBE
NOTE:
This bit can be written only one time after reset. Additional writes are ignored.
0LVD events do not generate hardware resets.
1Force an MCU reset when an enabled low-voltage detect event occurs.
Low-Voltage Detect Stop Enable
Provided LVDE = 1, this read/write bit determines whether the low-voltage detect function operates when
the MCU is in stop mode.
0Low-voltage detect disabled during stop mode.
1Low-voltage detect enabled during stop mode.
Low-Voltage Detect Enable
This write-once bit enables low-voltage detect logic and qualifies the operation of other bits in this register.
NOTE:
This bit can be written only one time after reset. Additional writes are ignored.
0LVD logic disabled.
1LVD logic enabled.
Bandgap Buffer Drive Select
This bit is used to select the high drive mode of the bandgap buffer.
0Bandgap buffer enabled in low drive mode if BGBE = 1.
1Bandgap buffer enabled in high drive mode if BGBE = 1.
Bandgap Buffer Enable
This bit enables an internal buffer for the bandgap voltage reference for use by the ADC module on one of
its internal channels.
3.5.2System Power Management Status and Control 2 Register
(PMC_SPMSC2)
This register is used to report the status of the low-voltage warning function, and to
configure the stop mode behavior of the MCU. This register should be written during the
user's reset initialization program to set the desired controls, even if the desired settings
are the same as the reset settings.
Address: 3040h base + 1h offset = 3041h
Bit76543210
Read0
Write
Reset
00000000
LVDVLVWV
PMC_SPMSC2 field descriptions
FieldDescription
7
Reserved
6
LVDV
This field is reserved.
This read-only field is reserved and always has the value 0.
Low-Voltage Detect Voltage Select
This write-once bit selects the low-voltage detect (LVD) trip point setting. See data sheet for details.
0
0Low trip point selected (V
1High trip point selected (V
5–4
LVWV
ReservedThis field is reserved.
Low-Voltage Warning Voltage Select
This bit selects the low-voltage warning (LVW) trip point voltage. See data sheet for details.
00Low trip point selected (V
01Middle 1 trip point selected (V
10Middle 2 trip point selected (V
11High trip point selected (V
This read-only field is reserved and always has the value 0.
LVD
LVD
LVW
LVW
= V
= V
= V
= V
LVW
LVW
LVDL
LVDH
LVW1
= V
= V
LVW4
).
).
).
LVW2
LVW3
).
).
).
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
44NXP Semiconductors
Chapter 4
Memory map
4.1Memory map
The HCS08 core processor can address 64 KB of memory space. The memory map,
shown in the following figure, includes:
• User flash memory (flash)
• MC9S08PA4: 4,096 bytes; 8 pages of 512 bytes each
The following table shows address assignments for reset and interrupt vectors. The vector
names shown in this table are the labels used in the header files for the device.
0xFFFA:FFFBIRQ or WatchdogVirq or Vwdog
0xFFFC:FFFDSWIVswi
0xFFFE:FFFFResetVreset
VectorVector name
4.3Register addresses and bit assignments
The register definitions vary in different memory sizes. The register addresses of unused
peripherals are reserved. The following table shows the register availability of the
devices.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors47
Register addresses and bit assignments
Table 4-2. Peripheral registers availability
AddressBytesPeripheral registers
0x0000—0x00023Port data
0x0010—0x00178ADC
0x0020—0x002A11FTM0
The registers in the devices are divided into two groups:
• Direct-page registers are located in the first 64 locations in the memory map, so they
can be accessed with efficient direct addressing mode instructions.
• High-page registers are used much less often, so they are located above 0x3000 in
the memory map. This leaves room in the direct page for more frequently used
registers and variables.
Direct-page registers can be accessed with efficient direct addressing mode instructions.
Bit manipulation instructions can be used to access any bit in a direct-page register.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
48NXP Semiconductors
Chapter 4 Memory map
The direct page registers can use the more efficient direct addressing mode, which
requires only the lower byte of the address.
The following tables are summaries of all user-accessible direct-page and high-page
registers and control bits. Cells that are not associated with named bits are shaded. A
shaded cell with a 0 indicates this unused bit always reads as a 0; and a shaded cell with a
1 indicates this unused bit always reads as a 1. Shaded cells with dashes indicate unused
or reserved bit locations that could read as 1s or 0s.
Several reserved flash memory locations, shown in the following table, are used for
storing values used by several registers. These registers include an 8-byte backdoor key,
NV_BACKKEY, which can be used to gain access to secure memory resources. During
reset events, the contents of NVPROT and NVOPT in the reserved flash memory are
transferred into corresponding FPROT and FOPT registers in the high-page registers area
to control security and block protection options.
The 8-byte comparison key can be used to temporarily disengage memory security
provided the key enable field, NV_FSEC[KEYEN], is 10b. This key mechanism can be
accessed only through user code running in secure memory. A security key cannot be
entered directly through background debug commands. This security key can be disabled
completely by programming the NV_FSEC[KEYEN] bit to 0. If the security key is
disabled, the only way to disengage security is by mass erasing the flash if needed,
normally through the background debug interface and verifying that flash is blank. To
avoid returning to secure mode after the next reset, program the security bits,
NV_FSEC[SEC], to the unsecured state (10b).
4.4
Random-access memory (RAM)
This section describes the 512 bytes of RAM (random-access memory).
These devices include static RAM. The locations in RAM below 0x0100 can be accessed
using the more efficient direct addressing mode. Any single bit in this area can be
accessed with the bit manipulation instructions (BCLR, BSET, BRCLR, and BRSET).
The RAM retains data when the MCU is in low-power wait, or stop3 mode. At power-on,
the contents of RAM are uninitialized. RAM data is unaffected by any reset provided that
the supply voltage does not drop below the minimum value for RAM retention.
For compatibility with older M68HC05 MCUs, the HCS08 resets the stack pointer to
0x00FF. In this series, re-initialize the stack pointer to the top of the RAM so that the
direct-page RAM can be used for frequently accessed RAM variables and bit-addressable
program variables. Include the following 2-instruction sequence in your reset
initialization routine (where RamLast is equated to the highest address of the RAM in the
equate file).
LDHX #RamLast+1 ;point one past RAM
TXS ;SP<-(H:X-1)
When security is enabled, the RAM is considered a secure memory resource and is not
accessible through BDM or code executing from non-secure memory.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors55
Flash and EEPROM
4.5Flash and EEPROM
4.5.1Overview
This device includes various configuration of flash and EEPROM. The controller for
flash and EEPROM is ideal for single-supply applications for field programming without
external high voltage sources for program or erase operations.
The flash memory is ideal for single-supply applications that allow for field
reprogramming without requiring external high voltage sources for program or erase
operations. The flash module includes a memory controller that executes commands to
modify flash memory contents. The user interface to the memory controller consists of
the indexed flash common command object (FCCOB) register, which is written to with
the command, global address, data, and any required command parameters. The memory
controller must complete the execution of a command before the FCCOB register is
written to with a new command.
CAUTION
A flash byte or longword must be in the erased state before
being programmed. Cumulative programming of bits within a
flash byte or longword is not allowed.
The flash memory is read as bytes. Read access time is one bus
cycle for bytes. For flash memory, an erased bit reads 1 and a
programmed bit reads 0. It is possible to read from flash
memory while commands are being executed on EEPROM
memory. It is not possible to read from EEPROM memory
while a command (erase/program) is executing on flash
memory. Simultaneous EEPROM memory are implemented
with error correction codes (ECC) that can resolve single bit
faults and detect double bit faults.
The following figure shows the block diagram of the flash and EEPROM module.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
56NXP Semiconductors
Divider
Clock
Command Interrupt Request
Protection
Registers
Security
Sector 1
Sector 1
Sector 7
Sector 0
Sector 0
FLASH
EEPROM
Interface
NVM controller
Bus Clock
Error Interrupt Request
CPU
1K
x3
2
128x8
Sector 63
Flash
Chapter 4 Memory map
Figure 4-2. Flash and EEPROM block diagram
Flash features:
• 4 KB of flash memory composed of one 4 KB flash block divided into 8 sectors of
512 bytes
• Automated program and erase algorithm with verification
• Fast sector erase and longword program operation
• Ability to read the flash memory while programming a word in the EEPROM
memory
• Flexible protection scheme to prevent accidental program or erase of flash memory
EEPROM features:
• 128 bytes of EEPROM memory composed of one 128 byte EEPROM block divided
into 64 sectors of 2 bytes
• Single bit fault correction and double bit fault detection within a word during read
operations
• Automated program and erase algorithm with verification and generation of ECC
parity bits
• Fast sector erase and byte program operation
• Protection scheme to prevent accidental program or erase of EEPROM memory
• Ability to program up to four bytes in a burst sequence
Other features
• No external high-voltage power supply required for flash memory program and erase
operations
• Interrupt generation on flash command completion and flash error detection
• Security mechanism to prevent unauthorized access to the flash memory
NXP Semiconductors57
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
Flash and EEPROM
4.5.2Function descriptions
4.5.2.1Modes of operation
The flash and EEPROM module provides the normal user mode of operation. The
operating mode is determined by module-level inputs and affects the FCLKDIV,
FCNFG, and EEPROT registers.
4.5.2.1.1Wait mode
The flash and EEPROM module is not affected if the MCU enters wait mode. The flash
module can recover the MCU from wait via the CCIF interrupt. See Flash and EEPROM
interrupts.
4.5.2.1.2Stop mode
If a flash and EEPROM command is active, that is, FSTAT[CCIF] = 0, when the MCU
requests stop mode, the current NVM operation will be completed before the MCU is
allowed to enter stop mode.
4.5.2.2
Flash and EEPROM memory map
The MCU places the flash memory between global address 0x0000 and 0xFFFF as
shown in the following table. Not all flash are available to users because some addresses
are overlapped with RAM, EEPROM, and registers.
MC9S08PA4 contains a piece of 4 KB flash that is fully available for users. This flash
block is divided into 8 sectors of 512 bytes.
4.5.2.3Flash and EEPROM initialization after system reset
On each system reset, the flash and EEPROM module executes an initialization sequence
that establishes initial values for the flash and EEPROM block configuration parameters,
the FPROT and EEPROT protection registers, and the FOPT and FSEC registers. The
initialization routine reverts to built-in default values that leave the module in a fully
protected and secured state if errors are encountered during execution of the reset
sequence. If a double bit fault is detected during the reset sequence, both
FSTAT[MGSTAT] bits will be set.
FSTAT[CCIF] is cleared throughout the initialization sequence. The NVM module holds
off all CPU access for a portion of the initialization sequence. Flash and EEPROM reads
are allowed after the hold is removed. Completion of the initialization sequence is
marked by setting FSTAT[CCIF] high, which enables user commands.
If a reset occurs while any flash or EEPROM command is in progress, that command will
be immediately aborted. The state of the word being programmed or the sector/block
being erased is not guaranteed.
4.5.2.4Flash and EEPROM command operations
Flash and EEPROM command operations are used to modify flash and EEPROM
memory contents.
The command operations contain three steps:
1. Configure the clock for flash or EEPROM program and erase command operations.
2. Use command write sequence to set flash and EEPROM command parameters and
launch execution.
3. Execute valid flash and EEPROM commands according to MCU functional mode
and MCU security state.
The figure below shows a general flowchart of the flash or EEPROM command write
sequence.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors59
Read: FCLKDIV
START
FDIV
Read: FSTAT
Read: FSTAT
CCIF
Write: FCLKDIV
register
NOTE: FCLKDIV must be
set after each reset
Set?
CCIF
ACCERR
Results from previous Command
Write to FCCOBIX register
to identify specific command
parameter to load
Write to FCCOB register
to load required command
parameter
More
Write: FSTAT register
(to launch command)
Read: FSTAT register
CCIF Set?
Bit Polling for
Command Completion Check
Clear CCIF 0x80
Parameters?
Write: FSTAT register
Clear ACCERR
FPVIOL 0x30
or FPVIOL Set?
Access Error and
Protection Violation Check
Set?
No
No
No
Yes
Yes
Yes
No
Yes
END
register
No
No
Yes
Yes
Clock Divider
Value Check
FCCOB
Availability Check
register
Correct?
register
Flash and EEPROM
Figure 4-3. Generic flash and EEPROM command write sequence flowchart
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
60NXP Semiconductors
Chapter 4 Memory map
4.5.2.4.1Writing the FCLKDIV register
Prior to issuing any flash and EEPROM program or erase command after a reset, the user
is required to write the FCLKDIV register to divide BUSCLK down to a target FCLK of
1MHz. The following table shows recommended values for the FDIV field based on
BUSCLK frequency.
Table 4-7. FDIV values for various BUSCLK frequencies
BUSCLK frequency
(MHz)
1
MIN
1.01.60x00
1.62.60x01
2.63.60x02
3.64.60x03
4.65.60x04
5.66.60x05
6.67.60x06
7.68.60x07
8.69.60x08
9.610.60x09
10.611.60x0A
11.612.60x0B
12.613.60x0C
13.614.60x0D
14.615.60x0E
15.616.60x0F
16.617.60x10
17.618.60x11
18.619.60x12
19.620.00x13
MAX
2
FDIV[5:0]
1. BUSCLK is greater than this value
2. BUSCLK is less than or equal to this value
CAUTION
Programming or erasing the flash and EEPROM memory
cannot be performed if the bus clock runs at less than 0.8 MHz.
Setting FCLKDIV[FDIV] too high can destroy the flash and
EEPROM memory due to overstress. Setting FCLKDIV[FDIV]
too low can result in incomplete programming or erasure of the
flash and EEPROM memory cells.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors61
Flash and EEPROM
When the FCLKDIV register is written, the FCLKDIV[FDIVLD] bit is set automatically.
If the FCLKDIV[FDIVLD] bit is 0, the FCLKDIV register has not been written since the
last reset. If the FCLKDIV register has not been written, any flash and EEPROM
program or erase command loaded during a command write sequence will not execute
and the FSTAT[ACCERR] bit will be set.
4.5.2.4.2Command write sequence
The memory controller will launch all valid flash and EEPROM commands entered using
a command write sequence.
Before launching a command, the FSTAT[ACCERR] and FSTAT[FPVIOL] bits must be
clear and the FSTAT[CCIF] flag will be tested to determine the status of the current
command write sequence. If FSTAT[CCIF] is 0, indicating that the previous command
write sequence is still active, a new command write sequence cannot be started and all
writes to the FCCOB register are ignored.
The FCCOB parameter fields must be loaded with all required parameters for the flash
and EEPROM command being executed. Access to the FCCOB parameter fields is
controlled via FCCOBIX[CCOBIX] bits.
Flash and EEPROM command mode uses the indexed FCCOB register to provide a
command code and its relevant parameters to the memory controller. First, the user must
set up all required FCCOB field. Then they can initiate the command's execution by
writing a 1 to the FSTAT[CCIF] bit. This action clears the CCIF command completion
flag to 0. When the user clears the FSTAT[CCIF] bit all FCCOB parameter field are
locked and cannot be changed by the user until the command completes (evidenced by
the memory controller returning FSTAT[CCIF] to1). Some commands return information
to the FCCOB register array.
The generic format for the FCCOB parameter fields in flash and EEPROM command
mode is shown in the following table. The return values are available for reading after the
FSTAT[CCIF] flag has been returned to 1 by the memory controller. Writes to the
unimplemented parameter fields, FCCOBIX[CCOBIX] =110b and FCCOBIX[CCOBIX]
= 111b, are ignored with read from these fields returning 0x0000.
The table below shows the generic flash command format. The high byte of the first word
in the CCOB array contains the command code, followed by the parameters for this
specific flash command. For details on the FCCOB settings required by each command,
see the flash command descriptions in Flash and EEPROM command summary .
CCOBIX[2:0]ByteFCCOB parameter fields in flash and EEPROM command mode
000
001
010
011
100
101
HIFCMD[7:0] defining flash command
LOGlobal address [23:16]
HIGlobal address [15:8]
LOGlobal address [7:0]
HIData 0 [15:8]
LOData 0 [7:0]
HIData 1 [15:8]
LOData 1 [7:0]
HIData 2 [15:8]
LOData 2 [7:0]
HIData 3 [15:8]
LOData 3 [7:0]
The contents of the FCCOB parameter fields are transferred to the memory controller
when the user clears the FSTAT[CCIF] command completion flag by writing 1. The
CCIF flag will remain clear until the flash and EEPROM command has completed. Upon
completion, the memory controller will return FSTAT[CCIF] to 1 and the FCCOB
register will be used to communicate any results.
The following table presents the valid flash and EEPROM commands, as enabled by the
combination of the functional MCU mode with the MCU security state of unsecured or
secured.
MCU secured state is selected by NVM_FSEC[SEC].
Table 4-9. Flash and EEPROM commands by mode and security state
The flash and EEPROM module can generate an interrupt when a flash command
operation has completed or when a flash and EEPROM command operation has detected
an ECC fault.
4.5.2.5.1Description of flash and EEPROM interrupt operation
The flash module uses the FSTAT[CCIF] flag in combination with the FCNFG[CCIE]
interrupt enable bit to generate the flash command interrupt request. The flash module
uses the DFDIF and SFDIF flags in combination with the FERSTAT[DFDIE] and
FERSTAT[SFDIE] interrupt enable bits to generate the flash error interrupt request.
The logic used for generating the flash module interrupts is shown in the following
figure.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
64NXP Semiconductors
CCIE
CCIF
SFDIF
Flash and EEPROM Command
Flash and EEPROM
Complete Interrupt Request
Error Interrupt Request
CPU Interrupt
Flash Configuration Field 16 bytes (0xFF70
0xFF7F)
Flash Protected/Unprotected Higher Region 1, 2, 3, 4Kbytes
Protection Fixed End
0x0000
Flash START = 0xF000
0xF400
0xFC00
0xFFFF
0xF800
Chapter 4 Memory map
Figure 4-4. Flash and EEPROM module interrupts implementation
4.5.2.6Protection
The FPROT register can be set to protect regions in the flash memory from accidental
programming or erasing. Two separate memory regions, one growing downward from
global address 0xFFFF in the flash memory, called the higher region; and the remaining
addresses in the flash memory, can be activated for protection. The flash memory
addresses covered by these protectable regions are shown in the flash memory map. The
higher address region is mainly targeted to hold the boot loader code because it covers
the vector space.
Default protection settings as well as security information that allows the MCU to restrict
access to the flash module are stored in the flash configuration field as described in the
table below.
NXP Semiconductors65
Figure 4-5. Flash protection memory map
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
Flash and EEPROM
Table 4-11. Flash configuration field
Global addressSize (Bytes)Description
0xFF70 — 0xFF77
0xFF78 — 0xFF7B4Reserved
0xFF7C
0xFF7D
0xFF7E
0xFF7F
1. 0xFF78–0xFF7F for a flash phrase and must be programmed in a single command write sequence. Each byte in the
0xFF78-0xFF7B reserved field must be programmed to 0xFF.
Backdoor comparison key. See Verify backdoor access key command and
Unsecuring the MCU using backdoor key access.
The flash and EEPROM module provides protection to the MCU. During the reset
sequence, the FPROT register is loaded with the contents of the flash protection byte in
the flash configuration field at global address 0xFF7C in flash memory. The protection
functions depend on the configuration of bit settings in FPORT register.
Table 4-12. Flash protection function
FPOPENFPHDISFunction
11No flash protection
10Protected high range
01Full flash memory protected
00Unprotected high range
1
1. For range size, seeTable 4.
The flash protection scheme can be used by applications requiring reprogramming in
single chip mode while providing as much protection as possible if reprogramming is not
required.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
66NXP Semiconductors
FPHDIS = 1
FPHDIS = 0
Protected region
not defined by FPHS
Unprotected region
Protected region with size
defined by FPHS
FPHS[1:0]
FPOPEN = 1
FPOPEN = 1
Scenario 3
Scenario 2
Scenario 1
Scenario 0
Flash Start Address
0xFFFF
FPOPEN = 0
FPOPEN = 0
FPHDIS = 1
FPHDIS = 0
Figure 4-6. Flash protection scenarios
Chapter 4 Memory map
The general guideline is that flash protection can only be added and not removed. The
following table specifies all valid transitions between flash protection scenarios. Any
attempt to write an invalid scenario to the FPROT register will be ignored. The contents
of the FPROT register reflect the active protection scenario. See the FPROT[FPHS] and
FPROT[FPLS] bit descriptions for additional restrictions.
The flash protection address range is listed in the following two tables regarding the
scenarios in the table above.
During the reset sequence, fields NVM_EEPROT[DPOPEN] and NVM_EEPROT[DPS]
are loaded with the contents of the EEPROM protection byte in the flash configuration
field at global address 0xFF7D located in flash memory. EEPROM protection address
range is specified by the NVM_EEPROT[DPS].
All possible flash protection scenarios are shown in Figure 4-6. Although the protection
scheme is loaded from the flash memory at global address 0xFF7C during the reset
sequence, it can be changed by the user.
4.5.2.7Security
The flash and EEPROM module provides security information to the MCU. The flash
security state is defined by the NVM_FSEC[SEC] bits. During reset, the flash module
initializes the NVM_FSEC register using data read from the security byte of the flash and
EEPROM configuration field at global address 0xFF7F. The security state out of reset
can be permanently changed by programming the security byte, assuming that the MCU
is starting from a mode where the necessary flash and EEPROM erase and program
commands are available and that the upper region of the flash is unprotected. If the flash
security byte is successfully programmed, its new value will take affect after the next
MCU reset.
The following subsections describe these security-related subjects:
• Unsecuring the MCU using backdoor key access
• Unsecuring the MCU using BDM
• Mode and security effects on flash and EEPROM command availability
4.5.2.7.1
Unsecuring the MCU using backdoor key access
The MCU may be unsecured by using the backdoor key access feature which requires
knowledge of the contents of the backdoor keys, which are four 16-bit words
programmed at addresses 0xFF70–0xFF77. If the KEYEN[1:0] bits are in the enabled
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
68NXP Semiconductors
Chapter 4 Memory map
state, the verify backdoor access key command – see Verify backdoor access key
command, allows the user to present four prospective keys for comparison to the keys
stored in the flash and EEPROM memory via the memory controller. If the keys
presented in the verify backdoor access key command match the backdoor keys stored in
the flash and EEPROM memory, the FSEC[SEC] bits will be changed to unsecure the
MCU. Key values of 0x0000 and 0xFFFF are not permitted as backdoor keys. While the
Verify Backdoor Access Key command is active, flash memory and EEPROM memory
will not be available for read access and will return invalid data.
The user code stored in the flash memory must have a method of receiving the backdoor
keys from an external stimulus. This external stimulus would typically be through one of
the on-chip serial ports.
If the KEYEN[1:0] bits are in the enabled state, the MCU can be unsecured by the
backdoor key access sequence described below:
1. Follow the command sequence for the verify backdoor access key command as
explained in Verify backdoor access key command.
2. If the verify backdoor access key command is successful, the MCU is unsecured and
the FSEC[SEC] bits are forced to the unsecure state of 10.
The verify backdoor access key command is monitored by the memory controller and an
illegal key will prohibit future use of the verify backdoor access key command. A reset of
the MCU is the only method to re-enable the verify backdoor access key command. The
security as defined in the flash and EEPROM security byte (0xFF7F) is not changed by
using the verify backdoor access key command sequence. The backdoor keys stored in
addresses 0xFF70–0xFF77 are unaffected by the verify backdoor access key command
sequence. The verify backdoor access key command sequence has no effect on the
program and erase protections defined in the flash and EEPROM protection register,
FPORT.
After the backdoor keys have been correctly matched, the MCU will be unsecured. After
the MCU is unsecured, the sector containing the flash and EEPROM security byte can be
erased and the flash and EEPROM security byte can be reprogrammed to the unsecure
state, if desired. In the unsecure state, the user has full control of the contents of the
backdoor keys by programming addresses 0xFF70–0xFF77 in the flash configuration
field.
4.5.2.7.2
Unsecuring the MCU using BDM
A secured MCU can be unsecured by using the following method to erase the flash and
EEPROM memory:
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors69
Flash and EEPROM
1. Reset the MCU.
2. Set FCDIV register as described in Writing the FCLKDIV register.
3. Configure registers NVM_FERSTAT and NVM_FPROT to disable protection in the
flash and EEPROM memory.
4. Execute the erase all blocks command write sequence to erase the flash and
EEPROM memory. Alternately, the unsecure NVM command can be executed.
If the flash and EEPROM memory are verified as erased, the MCU will be
unsecured. All BDM. commands will now be enabled and the flash security byte may
be programmed to the unsecure state by continuing with the steps that follow.
5. Execute the program flash command write sequence to program the flash security
byte to the unsecured state.
6. Reset the MCU.
4.5.2.7.3Mode and security effects on flash and EEPROM command
availability
The availability of flash and EEPROM module commands depends on the MCU
operating mode and security state as shown in Table 4-9.
4.5.2.8
Flash and EEPROM commands
4.5.2.8.1Flash commands
The following table summarizes the valid flash commands as well as the effects of the
commands on the flash block and other resources within the flash and EEPROM module.
Table 4-16. Flash commands
FCMDCommandFunction on flash memory
0x01Erase verify all blocksVerify that all flash (and EEPROM) blocks are erased
0x02Erase verify blockVerify that a flash block is erased
0x03Erase verify flash sectionVerify that a given number of words starting at the address provided are erased
0x04Read Once
0x06Program flashProgram up to two longwords in a flash block
0x07Program once
0x08Erase all blockErase all flash and EEPROM blocks
Read a dedicated 64 byte field in the nonvolatile information register in flash
block that was previously programmed using the program once command
Program a dedicated 64 byte field in the nonvolatile information register in flash
block that is allowed to be programmed only once
Table continues on the next page...
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
70NXP Semiconductors
Chapter 4 Memory map
Table 4-16. Flash commands (continued)
FCMDCommandFunction on flash memory
An erase of all flash blocks is possible only when the FPROT[FPHDIS], and
FPROT[FPOEN] bits and the EEPROT[DPOPEN] bit are set prior to launching
the command
Erase a flash or EEPROM block
0x09Erase flash block
0x0AErase flash sectorErase all bytes in a flash sector
0x0BUnsecure flash
0x0CVerify backdoor access keySupports a method of releasing MCU security by verifying a set of security keys
0x0DSet user margin levelSpecifies a user margin read level for all flash blocks
An erase of the full flash block is possible only when FPROT[FPHDIS], and
FPROT[FPOEN] bits are set prior to launching the command
Supports a method of releasing MCU security by erasing all flash (and
EEPROM) blocks and verifying that all flash (and EEPROM) blocks are erased
4.5.2.8.2EEPROM commands
The following table summarizes the valid EEPROM commands along with the effects of
the commands on the EEPROM block.
Table 4-17. EEPROM commands
FCMDCommandFunction on flash memory
0x01Erase verify all blocksVerify that all EEPROM (and flash) blocks are erased.
0x02Erase verify blockVerify that an EEPROM block is erased.
Erase all EEPROM and flash blocks
0x08Erase all block
0x09Erase EEPROM Block
0x0BUnsecure EEPROM
0x0DSet User Margin LevelSpecifies a user margin read level for all flash blocks.
0x10
0x11Program EEPROMProgram up to four bytes in the EEPROM block.
0x12Erase EEPROM SectorErase all bytes in a sector of the EEPROM block.
Erase Verify EEPROM
Section
An erase of all EEPROM blocks is possible only when the FPROT[FPHDIS], and
FPROT[FPOEN] bits and the DPOPEN bit in the EEPORT register are set prior
to launching the command.
Erase a EEPROM and flash block
An erase of the full flash block is possible only when FPROT[FPHDIS] and
FPROT[FPOPEN] bits are set prior to launching the command.
Supports a method of releasing MCU security by erasing all EEPROM and flash
blocks and verifying that all EEPROM and flash blocks are erased.
Verify that a given number of bytes starting at the address provided are erased.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors71
Flash and EEPROM
4.5.2.8.3Allowed simultaneous flash and EEPROM operations
Only the operations marked 'OK' in the following table are permitted to be run
simultaneously on the flash and EEPROM blocks. Some operations cannot be executed
simultaneously because certain hardware resources are shared by the two memories. The
priority has been placed on permitting flash reads while program and erase operations
execute on the EEPROM, providing read (flash) while write (EEPROM) functionality.
Table 4-18. Allowed simultaneous flash and EEPROM operations
Program flash
ReadOKOKOK
Margin Read
Program
Sector Erase
Mass Erase
1. A 'Margin read' is any read after executing the margin setting commands 'Set user margin level' or 'Set field margin level'
with anything but the 'normal' level specified. See the Note on margin settings in
2. The 'Mass erase' operations are commands 'Erase all blocks' and 'Erase flash block'
1
2
ReadMargin readProgramSector eraseMass erase
EEPROM
OK
4.5.2.9Flash and EEPROM command summary
This section provides details of all available flash commands launched by a command
write sequence. The FSTAT[ACCERR] bit will be set during the command write
sequence if any of the following illegal steps are performed, causing the command not to
be processed by the memory controller:
• Starting any command write sequence that programs or erases flash memory before
initializing the FLCKDIV register.
• Writing an invalid command as part of the command write sequence.
• For additional possible errors, refer to the error handling table provided for each
command.
If a flash block is read during the execution of an algorithm (FSTAT[CCIF] = 0) on that
same block, the read operation will return invalid data if both flags FERSTAT[SFDIF]
and FERSTAT[DFDIF] are set. If the FERSTAT[SFDIF] or FERSTAT[DFDIF] flags
were not previously set when the invalid read operation occurred, both the
FERSTAT[SFDIF] and FERSTAT[DFDIF] flags will be set.
If the FSTAT[ACCERR] or FSTAT[FPVIOL] bits are set, the user must clear these bits
before starting any command write sequence.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
72NXP Semiconductors
Chapter 4 Memory map
CAUTION
An EEPROM byte or flash longword must be in the erased state
before being programmed. Cumulative programming of bits
within an EEPROM byte or flash longword is not allowed.
4.5.2.9.1Erase verify all blocks command
The erase verify all blocks command will verify that all flash and EEPROM blocks have
been erased.
Table 4-19. Erase verify all blocks command FCCOB requirements
Upon clearing NVM_FSTAT[CCIF] to launch the erase verify all blocks command, the
memory controller will verify that the entire flash memory space is erased. The
NVM_FSTAT[CCIF] flag will set after the erase verify all blocks operation has
completed. If all blocks are not erased, it means blank check failed and both
NVM_FSTAT[MGSTAT] bits will be set.
Table 4-20. Erase verify all blocks command error handling
RegisterError bitError condition
ACCERRSet if CCOBIX[2:0] != 000 at command launch
FPVIOLNone
NVM_FSTAT
1. As found in the memory map for NVM
MGSTAT1
MGSTAT0
Set if any errors have been encountered during the read1 or if blank check
failed
Set if any non-correctable errors have been encountered during the read
or if blank check failed
4.5.2.9.2Erase verify block command
The erase verify block command allows the user to verify that an entire flash or
EEPROM block has been erased. The FCCOB global address [23:0] bits determine which
block must be verified.
0000x02Global address [23:16] to identify Flash block
001Global address [15:0] in flash block to be verified
1
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors73
Flash and EEPROM
1. Global address [23] selects between flash (0) or EEPROM (1) block, that can otherwise eventually share the same
address on the MCU global memory map.
Upon clearing NVM_FSTAT[CCIF] to launch the erase verify block command, the
memory controller will verify that the selected flash or EEPROM block is erased. The
NVM_FSTAT[CCIF] flag will set after the erase verify block operation has completed. If
the block is not erased, it means blank check failed and both NVM_FSTAT[MGSTAT]
bits will be set.
Set if CCOBIX[2:0] != 000 at command launch
Set if an invalid global address [23:0] is supplied
Set if any errors have been encountered during the read or if blank check
failed
Set if any non-correctable errors have been encountered during the read
or if blank check failed
1
1. As found in the memory map for NVM
4.5.2.9.3Erase verify flash section command
The erase verify flash section command will verify that a section of code in the flash
memory is erased. The erase verify flash section command defines the starting point of
the code to be verified and the number of longwords.
0000x03Global address [23:16] of flash block
001Global address [15:0] of the first longwords to be verified
010Number of long words to be verified
Upon clearing NVM_FSTAT[CCIF] to launch the erase verify flash section command,
the memory controller will verify that the selected section of flash memory is erased. The
NVM_FSTAT[CCIF] flag will set after the erase verify flash section operation has
completed. If the section is not erased, it means blank check failed and both
FSTAT[MGSTAT] bits will be set.
Set if command not available in current mode (see Table 4-9)
1
2
FPVIOLNone
MGSTAT1
MGSTAT0
1. As defined by the memory map for NVM
2. As found in the memory map for NVM
Set if an invalid global address [23:0] is supplied (see Table 4-6)
Set if a misaligned long words address is supplied (global address[1:0] !=
00)
Set if the requested section crosses flash address boundary
Set if any errors have been encountered during the read2 or if blank check
failed
Set if any non-correctable errors have been encountered during the read
or if blank check failed
4.5.2.9.4Read once command
The read once command provides read access to a reserved 64 byte field (8 phrase)
located in the nonvolatile information register of flash. The read once field can only be
programmed once and can not be erased. It can be used to store the product ID or any
other information that can be written only once. It is programmed using the program once
command described in Program once command. To avoid code runaway, the read once
command must not be executed from the flash block containing the program once
reserved field.
Table 4-25. Read once command FCCOB requirements
CCOBIX[2:0]FCCOB parameters
0000x04Not required
001Read once phrase index (0x0000 – 0x0007)
010Read once word 0 value
011Read once word 1 value
100Read once word 2 value
101Read once word 3 value
Upon clearing FSTAT[CCIF] to launch the read once command, a read once phrase is
fetched and stored in the FCCOB indexed register. The FSTAT[CCIF] flag will set after
the read once operation has completed. Valid phrase index values for the read once
command range from 0x0000 to 0x0007. During execution of the read once command,
any attempt to read addresses within flash block will return invalid data.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors75
Flash and EEPROM
Table 4-26. Read once command error handling
RegisterError bitError condition
Set if CCOBIX[2:0] != 001 at command launch
FSTAT
ACCERR
FPVIOLNone
MGSTAT1Set if any errors have been encountered during the read
MGSTAT0Set if any non-correctable errors have been encountered during the read
Set if command is not available in current mode (see Table 4-9)
Set if an invalid phrase index is supplied
4.5.2.9.5Program flash command
The program flash operation will program up to two previously erased longwords in the
flash memory using an embedded algorithm.
Note
A flash phrase must be in the erased state before being
programmed. Cumulative programming of bits within a flash
phrase is not allowed.
Table 4-27. Program flash command FCCOB requirements
0000x06Global address [23:16] to identify flash block
001Global address [15:0] of longwords location to be programmed
010Word 0 (longword 0) program value
011Word 1 (longword 0) program value
100Word 2 (longword 1) program value
101Word 3 (longword 1) program value
1. Global address [1:0] must be 00.
1
Upon clearing NVM_FSTAT[CCIF] to launch the program flash command, the memory
controller will program the data words to the supplied global address and will then
proceed to verify the data words read back as expected. The NVM_FSTAT[CCIF] flag
will set after the program flash operation has completed.
Table 4-28. Program flash command error handling
RegisterError bitError condition
Set if CCOBIX[2:0] ≠ 011 or 101 at command launch
NVM_FSTATACCERR
Set if command not available in current mode (see Table 4-9)
Set if an invalid global address [23:0] is supplied (see Table 4-6)
1
Table continues on the next page...
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
76NXP Semiconductors
Chapter 4 Memory map
Table 4-28. Program flash command error handling (continued)
RegisterError bitError condition
Set if a misaligned longword address is supplied (global address [1:0] !=
00)
Set if the requested group of words breaches the end of the flash block.
FPVIOLSet if the global address [23:0] points to a protected data
MGSTAT1Set if any errors have been encountered during the verify operation
MGSTAT0
1. As defined by the memory map of NVM
Set if any non-correctable errors have been encountered during the verify
operation
4.5.2.9.6Program once command
The program once command restricts programming to a reserved 64 byte field (8 phrases)
in the nonvolatile information register located in flash. The program once reserved field
can be read using the read once command as described in Read once command. The
program once command must be issued only because the nonvolatile information register
in flash cannot be erased. To avoid code runaway, the read once command must not be
executed from the flash block containing the program once reserved field.
Table 4-29. Program once command FCCOB requirements
CCOBIX[2:0]FCCOB parameters
0000x07Not required
001Program Once phrase index (0x000 – 0x0007)
010Program once Word 0 value
011Program once Word 1value
100Program once Word 2 value
101Program once Word 3 value
Upon clearing FSTAT[CCIF] to launch the program once command, the memory
controller first verifies that the selected phrase is erased. If erased, then the selected
phrase will be programmed and then verified with read back. The FSTAT[CCIF] flag will
remain clear, setting only after the program once operation has completed.
The reserved nonvolatile information register accessed by the program once command
cannot be erased, and any attempt to program one of these phrases a second time will not
be allowed. Valid phrase index values for the program once command range from 0x0000
to 0x0007. During execution of the program once command, any attempt to read
addresses within flash will return invalid data.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors77
Flash and EEPROM
Table 4-30. Program once command error handling
RegisterError bitError condition
Set if CCOBIX[2:0] != 101 at command launch
ACCERR
FSTAT
FPVIOLNone
MGSTAT1Set if any errors have been encountered during the verify operation
MGSTAT0
1. If a program once phrase is initially programmed to 0xFFFF_FFFF_FFFF_FFFF, the program once command will be
allowed to execute again on that same phrase.
Set if command not available in current mode (see Table 4-9)
Set if an invalid phrase index is supplied
Set if the requested phrase has already been programmed
Set if any non-correctable errors have been encountered during the verify
operation
1
4.5.2.9.7Erase all blocks command
The erase all blocks operation will erase the entire flash and EEPROM memory space.
Table 4-31. Erase all blocks command FCCOB requirements
Upon clearing NVM_FSTAT[CCIF] to launch the erase all blocks command, the
memory controller will erase the entire NVM memory space and verify that it is erased. If
the memory controller verifies that the entire NVM memory space was properly erased,
security will be released. Therefore, the device is in unsecured state. During the execution
of this command (NVM_FSTAT[CCIF] = 0) the user must not write to any NVM module
register. The NVM_FSTAT[CCIF] flag will set after the erase all blocks operation has
completed.
Table 4-32. Erase all blocks command error handling
RegisterError bitError condition
Set if CCOBIX[2:0] ≠ 000 at command launch
Set if command not available in current mode (see Table 4-9)
1
Set if any non-correctable errors have been encountered during the verify
operation
1
NVM_FSTAT
ACCERR
FPVIOLSet if any area of the flash or EEPROM memory is protected
MGSTAT1Set if any errors have been encountered during the verify operation
MGSTAT0
1. As found in the memory map for NVM
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
78NXP Semiconductors
Chapter 4 Memory map
4.5.2.9.8Erase flash block command
The erase flash block operation will erase all addresses in a flash or EEPROM block.
0000x09Global address [23:16] to identify flash block
001Global address[15:0] in flash block to be erased
1. Global address [23] selects between flash (0) or EEPROM (1) block, that can otherwise eventually share the same
address on the MCU global memory map.
1
Upon clearing FSTAT[CCIF] to launch the erase flash block command, the memory
controller will erase the selected flash block and verify that it is erased. The
FSTAT[CCIF] flag will set after the erase flash block operation has completed.
0000x0AGlobal address [23:16] to identify flash block to be erased
001
Global address [15:0] anywhere within the sector to be erased. Refer to Overview for the flash
sector size
Upon clearing FSTAT[CCIF] to launch the erase flash sector command, the memory
controller will erase the selected flash sector and then verify that it is erased. The
FSTAT[CCIF] flag will be set after the erase flash sector operation has completed.
Upon clearing FSTAT[CCIF] to launch the unsecure flash command, the memory
controller will erase the entire flash and EEPROM memory space and verify that it is
erased. If the memory controller verifies that the entire flash and EEPROM memory
space was properly erased, security will be released. If the erase verify is not successful,
the unsecure flash operation sets FSTAT[MGSTAT1] and terminates without changing
the security state. During the execution of this command (FSTAT[CCIF] = 0), the user
must not write to any flash and EEPROM module register. The FSTAT[CCIF] flag is set
after the unsecure flash operation has completed.
Table 4-38. Unsecure flash command error handling
RegisterError bitError condition
Set if CCOBIX[2:0] != 000 at command launch
Set if command is not available in current mode (see Table 4-9)
1
Set if any non-correctable errors have been encountered during the verify
operation
1
FSTAT
ACCERR
FPVIOLSet if any area of the flash or EEPROM memory is protected
MGSTAT1Set if any errors have been encountered during the verify operation
MGSTAT0
1. As found in the memory map for NVM
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
80NXP Semiconductors
Chapter 4 Memory map
4.5.2.9.11Verify backdoor access key command
The verify backdoor access key command will execute only if it is enabled by the
NVM_FSEC[KEYEN] bits. The verify backdoor access key command releases security
if user-supplied keys match those stored in the flash security bytes of the flash
configuration field. See Table 4-6 for details. The code that performs verifying backdoor
access command must be running from RAM or EEPROM.
Upon clearing NVM_FSTAT[CCIF] to launch the verify backdoor access key command,
the memory controller will check the NVM_FSEC[KEYEN] bits to verify that this
command is enabled. If not enabled, the memory controller sets the
NVM_FSTAT[ACCERR] bit. If the command is enabled, the memory controller
compares the key provided in FCCOB to the backdoor comparison key in the flash
configuration field with Key 0 compared to 0xFF70, and so on. If the backdoor keys
match, security will be released. If the backdoor keys do not match, security is not
released and all future attempts to execute the verify backdoor access key command are
aborted (set NVM_FSTAT[ACCERR]) until a reset occurs. The NVM_FSTAT[CCIF]
flag is set after the verify backdoor access key operation has completed.
Set if an incorrect backdoor key is supplied
Set if backdoor key access has not been enabled (KEYEN[1:0] ≠ 10
Set if the backdoor key has mismatched since the last reset
Flash and EEPROM
4.5.2.9.12Set user margin level command
The user margin is a small delta to the normal read reference level and, in effect, is a
minimum safety margin. That is, if the reads pass at the tighter tolerances of the user
margins, the normal reads have at least that much safety margin before users experience
data loss.
The set user margin level command causes the memory controller to set the margin level
for future read operations of the flash or EEPROM block.
Table 4-41. Set user margin level command FCCOB requirements
0000x0DGlobal address [23:16] to identify flash block
001Global address [15:0] to identify flash block
010Margin level setting
1. Global Address [23] selects between flash (0) or EEPROM (1) block, that can otherwise eventually share the same
address on the MCU global memory map.
1
Upon clearing NVM_FSTAT[CCIF] to launch the set user margin level command, the
memory controller will set the user margin level for the targeted block and then set the
NVM_FSTAT[CCIF] flag.
Note
When the EEPROM block is targeted, the EEPROM user
margin levels are applied only to the EEPROM reads. However,
when the Flash block is targeted, the flash user margin levels
are applied to both Flash and EEPROM reads. It is not possible
to apply user margin levels to the flash block only.
Valid margin level settings for the set user margin level command are defined in the
following tables.
Table 4-42. Valid set user margin level settings
CCOB
(CCOBIX = 010)
0x0000Return to normal level
0x0001User margin-1 level
0x0002User margin-0 level
1. Read margin to the erased state
2. Read margin to the programmed state
Level description
1
2
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
82NXP Semiconductors
Table 4-43. Set user margin level command error handling
RegisterError bitError condition
Set if CCOBIX[2:0] != 010 at command launch
ACCERR
NVM_FSTAT
FPVIOLNone
MGSTAT1None
MGSTAT0None
Set if command is not available in current mode (see Table 4-9)
Set if an invalid global address [23:0] is supplied
Set if an invalid margin level setting is supplied
Note
User margin levels can be used to check that NVM memory
contents have adequate margin for normal level read operations.
If unexpected results are encountered when checking NVM
memory contents at user margin levels, a potential loss of
information has been detected.
Chapter 4 Memory map
4.5.2.9.13
Erase verify EEPROM section command
The erase verify EEPROM section command will verify that a section of code in the
EEPROM is erased. The erase verify EEPROM section command defines the starting
point of the data to be verified and the number of bytes.
0000x10Global address [23:16] to identify the EEPROM block
001Global address [15:0] of the first byte to be verified
010Number of bytes to be verified
Upon clearing NVM_FSTAT[CCIF] to launch the erase verify that EEPROM section
command, the memory controller will verify the selected section of EEPROM memory is
erased. The NVM_FSTAT[CCIF] flag will set after the erase verify EEPROM section
operation has completed. If the section is not erased, which means that blank check
failed, both NVM_FSTAT[MGSTAT] bits will be set.
Set if an invalid global address [23:0] is supplied
Set if the requested section breaches the end of the EEPROM block
FPVIOLNone
MGSTAT1
MGSTAT0
Set if any errors have been encountered during the read or if blank check
failed
Set if any non-correctable errors have been encountered during the read
or it blank check failed.
4.5.2.9.14Program EEPROM command
The program EEPROM operation programs one to four previously erased bytes in the
EEPROM block. The program EEPROM operation will confirm that the targeted
location(s) were successfully programmed upon completion.
Note
A EEPROM byte must be in the erased state before being
programmed. Cumulative programming of bits within a
EEPROM byte is not allowed.
Table 4-46. Program EEPROM command FCCOB requirements
0000x11Global address [23:16] to identify the EEPROM block
001Global address [15:0] of the first word to be verified
010Byte 0 program value
011Byte 1 program value, if desired
100Byte 2 program value, if desired
101Byte 3 program value, if desired
Upon clearing NVM_FSTAT[CCIF] to launch the program EEPROM command, the
user-supplied words will be transferred to the memory controller and be programmed if
the area is unprotected. The CCOBIX index value at program EEPROM command
launch determines how many bytes will be programmed in the EEPROM block. The
NVM_FSTAT[CCIF] flag is set when the operation has completed.
Table 4-47. Program EEPROM command error handling
RegisterError BitError condition
NVM_FSTATACCERR
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
84NXP Semiconductors
Set if CCOBIX[2:0] < 010 at command launch
Set if CCOBIX[2:0] >101 at command launch
Table continues on the next page...
Chapter 4 Memory map
Table 4-47. Program EEPROM command error handling (continued)
RegisterError BitError condition
Set if command is not available in current mode (see Table 4-9)
Set if an invalid global address [23:0] is supplied
Set if the requested group of words breaches the end of the EEPROM
block
FPVIOLSet if the selected area of the EEPROM memory is protected
MGSTAT1Set if any errors have been encountered during the verify operation
MGSTAT0
Set if any non-correctable errors have been encountered during the verify
operation
4.5.2.9.15Erase EEPROM sector command
The erase EEPROM sector operation will erase all addresses in a sector of the EEPROM
block.
0000x12Global address [23:16] to identify EEPROM block
001
Global address [15:0] anywhere within the sector to be erased. See Overview for EEPROM sector
size
Upon clearing NVM_FSTAT[CCIF] to launch the erase EEPROM sector command, the
memory controller will erase the selected EEPROM sector and verify that it is erased.
The NVM_FSTAT[CCIF] flag will set after the erase EEPROM sector operation has
completed.
FPVIOLSet if the selected area of the EEPROM memory is protected
MGSTAT1Set if any errors have been encountered during the verify operation
MGSTAT0
Set if command is not available in current mode (see Table 4-9)
Set if an invalid global address [23:0] is supplied (see Table 4-6)
Set if any non-correctable errors have been encountered during the verify
operation
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors85
Flash and EEPROM registers descriptions
4.6Flash and EEPROM registers descriptions
The flash module contains a set of 16 user control and status registers located between
0x3020 and 0x302F. In the case of the writable registers, the write accesses are forbidden
during flash command execution. For more details, see Caution note in Flash and
EEPROM memory map. A summary of the flash module registers is given in the
following table with detailed descriptions in the following subsections.
Flash Common Command Object Register:High
(NVM_FCCOBHI)
Flash Common Command Object Register: Low
(NVM_FCCOBLO)
Register name
Width
(in bits)
Access Reset value
8R/W00h4.6.10/94
8R/W00h4.6.11/95
4.6.1Flash Clock Divider Register (NVM_FCLKDIV)
Section/
page
The FCLKDIV register is used to control timed events in program and erase algorithms.
NOTE
The FCLKDIV register must not be written while a flash
command is executing (NVM_FSTAT[CCIF] = 0)
Address:
86NXP Semiconductors
3020h base + 0h offset = 3020h
Bit76543210
ReadFDIVLD
Write
Reset
00000000
FDIVLCKFDIV
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NVM_FCLKDIV field descriptions
FieldDescription
7
FDIVLD
6
FDIVLCK
FDIVClock Divider Bits
Clock Divider Loaded
0FCLKDIV register has not been written since the last reset.
1FCLKDIV register has been written since the last reset.
Clock Divider Locked
0FDIV field is open for writing.
1FDIV value is locked and cannot be changed. After the lock bit is set high, only reset can clear this bit
and restore writability to the FDIV field in user mode.
FDIV[5:0] must be set to effectively divide BUSCLK down to 1MHz to control timed events during flash
program and erase algorithms. Refer to the table in the Writing the FCLKDIV register for the
recommended values of FDIV based on the BUSCLK frequency.
4.6.2Flash Security Register (NVM_FSEC)
Chapter 4 Memory map
The FSEC register holds all bits associated with the security of the MCU and NVM
module. All bits in the FSEC register are readable but not writable. During the reset
sequence, the FSEC register is loaded with the contents of the flash security byte in the
flash configuration field at global address 0xFF7F located in flash memory.
See Security for security function.
Address:
* Notes:
3020h base + 1h offset = 3021h
Bit76543210
ReadKEYENReservedSEC
Write
Reset
x = Undefined at reset.•
x*x*x*x*x*x*x*x*
NVM_FSEC field descriptions
FieldDescription
7–6
KEYEN
Backdoor Key Security Enable Bits
The KEYEN[1:0] bits define the enabling of backdoor key access to the flash module.
NOTE:
00Disabled
01Disabled
10Enabled
11Disabled
01 is the preferred KEYEN state to disable backdoor key access.
Table continues on the next page...
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors87
Flash and EEPROM registers descriptions
NVM_FSEC field descriptions (continued)
FieldDescription
5–2
Reserved
SECFlash Security Bits
This field is reserved.
The SEC[1:0] bits define the security state of the MCU. If the flash module is unsecured using backdoor
key access, the SEC bits are forced to 10.
NOTE:
00Secured
01Secured
10Unsecured
11Secured
01 is the preferred SEC state to set MCU to secured state.
4.6.3Flash CCOB Index Register (NVM_FCCOBIX)
The FCCOBIX register is used to index the FCCOB register for NVM memory
operations.
Address:
3020h base + 2h offset = 3022h
Bit76543210
Read0
Write
Reset
00000000
CCOBIX
NVM_FCCOBIX field descriptions
FieldDescription
7–3
Reserved
CCOBIXCommon Command Register Index
This field is reserved.
This read-only field is reserved and always has the value 0.
The CCOBIX bits are used to select which word of the FCCOB register array is being read or written to.
4.6.4Flash Configuration Register (NVM_FCNFG)
The FCNFG register enables the flash command complete interrupt and forces ECC
faults on flash array read access from the CPU.
Address:
88NXP Semiconductors
3020h base + 4h offset = 3024h
Bit76543210
Read
Write
Reset
CCIE
00000000
0
IGNSF
0
FDFDFSFD
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NVM_FCNFG field descriptions
FieldDescription
7
CCIE
6–5
Reserved
4
IGNSF
3–2
Reserved
1
FDFD
Command Complete Interrupt Enable
The CCIE bit controls interrupt generation when a flash command has completed.
0Command complete interrupt disabled.
1An interrupt will be requested whenever the CCIF flag in the FSTAT register is set.
This field is reserved.
This read-only field is reserved and always has the value 0.
Ignore Single Bit Fault
The IGNSF controls single bit fault reporting in the FERSTAT register.
0All single bit faults detected during array reads are reported.
1Single bit faults detected during array reads are not reported and the single bit fault interrupt will not
be generated.
This field is reserved.
This read-only field is reserved and always has the value 0.
Force Double Bit Fault Detect
The FDFD bit allows the user to simulate a double bit fault during flash array read operations and check
the associated interrupt routine. The FDFD bit is cleared by writing a 0 to FDFD.
Chapter 4 Memory map
0Flash array read operations will set the FERSTAT[DFDIF] flag only if a double bit fault is detected.
1Any flash array read operation will force the FERSTAT[DFDIF] flag to be set and an interrupt will be
generated as long as the DFDIE interrupt enable in the FERCNFG register is set.
0
FSFD
Force Single Bit Fault Detect
The FSFD bit allows the user to simulate a single bit fault during flash array read operations and check the
associated interrupt routine. The FSFD bit is cleared by writing a 0 to FSFD.
0Flash array read operations will set the SFDIF flag in the FERSTAT register only if a single bit fault is
detected.
1Flash array read operation will force the SFDIF flag in the FERSTAT register to be set and an interrupt
will be generated as long as the SFDIE interrupt enable in the FERCNFG register is set.
The FERCNFG register enables the flash error interrupts for the FERSTAT flags.
Address:
3020h base + 5h offset = 3025h
Bit76543210
Read0
Write
Reset
00000000
DFDIESFDIE
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors89
Flash and EEPROM registers descriptions
NVM_FERCNFG field descriptions
FieldDescription
7–2
Reserved
1
DFDIE
0
SFDIE
This field is reserved.
This read-only field is reserved and always has the value 0.
Double Bit Fault Detect Interrupt Enable
The DFDIE bit controls interrupt generation when a double bit fault is detected during a flash block read
operation.
0DFDIF interrupt disabled.
1An interrupt will be requested whenever the DFDIF flag is set.
Single Bit Fault Detect Interrupt Enable
The SFDIE bit controls interrupt generation when a single bit fault is detected during a flash block read
operation.
0SFDIF interrupt disabled whenever the SFDIF flag is set.
1An interrupt will be requested whenever the SFDIF flag is set.
4.6.6Flash Status Register (NVM_FSTAT)
The FSTAT register reports the operational status of the flash and EEPROM module.
Address:
3020h base + 6h offset = 3026h
Bit76543210
Read
Write
Reset
CCIF
10000000
0
ACCERRFPVIOL
MGBUSY0MGSTAT
NVM_FSTAT field descriptions
FieldDescription
7
CCIF
6
Reserved
5
ACCERR
Command Complete Interrupt Flag
The CCIF flag indicates that a flash command has completed. The CCIF flag is cleared by writing a 1 to
CCIF to launch a command and CCIF will stay low until command completion or command violation.
0Flash command in progress.
1Flash command has completed.
This field is reserved.
This read-only field is reserved and always has the value 0.
Flash Access Error Flag
The ACCERR bit indicates an illegal access has occurred to the flash memory caused by either a violation
of the command write sequence or issuing an illegal flash command. While ACCERR is set, the CCIF flag
cannot be cleared to launch a command. The ACCERR bit is cleared by writing a 1 to ACCERR. Writing a
0 to the ACCERR bit has no effect on ACCERR.
Reserved
MGSTATMemory Controller Command Completion Status Flag
Flash Protection Violation Flag
The FPVIOL bit indicates an attempt was made to program or erase an address in a protected area of
flash or EEPROM memory during a command write sequence. The FPVIOL bit is cleared by writing a 1 to
FPVIOL. Writing a 0 to the FPIOL bit has no effect on FPIOL. While FPIOL is set, it is not possible to
launch a command or start a command write sequence.
The MGBUSY flag reflects the active state of the memory controller.
0Memory controller is idle.
1Memory controller is busy executing a flash command (CCIF = 0).
This field is reserved.
This read-only field is reserved and always has the value 0.
Chapter 4 Memory map
One or more MGSTAT flag bits are set if an error is detected during execution of a flash command or
during the flash reset sequence.
NOTE:
Reset value can deviate from the value shown if a double bit fault is detected during the reset
sequence.
4.6.7Flash Error Status Register (NVM_FERSTAT)
The FERSTAT register reflects the error status of internal flash and EEPROM
operations.
Address:
3020h base + 7h offset = 3027h
Bit76543210
Read0
Write
Reset
00000000
DFDIFSFDIF
NVM_FERSTAT field descriptions
FieldDescription
7–2
Reserved
1
DFDIF
This field is reserved.
This read-only field is reserved and always has the value 0.
Double Bit Fault Detect Interrupt Flag
The setting of the DFDIF flag indicates that a double bit fault was detected in the stored parity and data
bits during a flash array read operation or that a flash array read operation returning invalid data was
Table continues on the next page...
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors91
Flash and EEPROM registers descriptions
NVM_FERSTAT field descriptions (continued)
FieldDescription
attempted on a flash block that was under a flash command operation. The DFDIF flag is cleared by
writing a 1 to DFDIF. Writing a 0 to DFDIF has no effect on DFDIF.
0
SFDIF
NOTE:
NOTE:
0No double bit fault detected.
1Double bit fault detected or a flash array read operation returning invalid data was attempted while
Single Bit Fault Detect Interrupt Flag
With the IGNSF bit in the FCNFG register clear, the SFDIF flag indicates that a single bit fault was
detected in the stored parity and data bits during a flash array read operation or that a flash array read
operation returning invalid data was attempted on a flash block that was under a flash command
operation. The SFDIF flag is cleared by writing a 1 to SFDIF. Writing a 0 to SFDIF has no effect on
SRFDIF.
0No single bit fault detected.
1Single bit fault detected and corrected or a flash array read operation returning invalid data was
The single bit fault and double bit fault flags are mutually exclusive for parity errors, meaning that
an ECC fault occurrence can be either single fault or double fault but never both. A simultaneous
access collision, when the flash array read operation is returning invalid data attempted while a
command is running, is indicated when both SFDIF and DFDIF flags are high.
There is a one cycle delay in storing the ECC DFDIF and SFDIF fault flags in the register. At least
one NOP is required after a flash memory read before checking FERSTAT for the occurrence of
EEC errors.
command running.
attempted while command running.
4.6.8Flash Protection Register (NVM_FPROT)
The FPROT register defines which flash sectors are protected against program and erase
operations.
The unreserved bits of the FPROT register are writable with the restriction that the size of
the protected region can only be increased (see Protection).
During the reset sequence, the FPROT register is loaded with the contents of the flash
protection byte in the flash configuration field at global address 0xFF7C located in flash
memory. To change the flash protection that will be loaded during the reset sequence, the
upper sector of the flash memory must be unprotected, then the flash protection byte must
be reprogrammed.
Trying to alter data in any protected area in the flash memory will result in a protection
violation error and the FPVIOL bit will be set in the FSTAT register. The block erase of a
flash block is not possible if any of the flash sectors contained in the same flash block are
protected.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
92NXP Semiconductors
Address: 3020h base + 8h offset = 3028h
Bit76543210
* Notes:
x = Undefined at reset.•
Read
Write
Reset
FPOPEN
x*x*x*x*x*x*x*x*
1
FPHDISFPHS
NVM_FPROT field descriptions
FieldDescription
7
FPOPEN
6
Reserved
5
FPHDIS
Flash Protection Operation Enable
The FPOPEN bit determines the protection function for program or erase operations.
0When FPOPEN is clear, the FPHDIS and FPLDIS bits define unprotected address ranges as specified
by the corresponding FPHS and FPLS bits.
1When FPOPEN is set, the FPHDIS and FPLDIS bits enable protection for the address range specified
by the corresponding FPHS and FPLS bits.
This field is reserved.
This read-only field is reserved and always has the value 1.
Flash Protection Higher Address Range Disable
The FPHDIS bit determines whether there is a protected/unprotected area in a specific region of the flash
memory ending with global address 0xFFFF.
The FPHS bits determine the size of the protected/unprotected area in flash memory. The FPHS bits can
be written to only while the FPHDIS bit is set.
This read-only field is reserved and always has the value 0.
4.6.9EEPROM Protection Register (NVM_EEPROT)
The EEPROT register defines which EEPROM sectors are protected against program and
erase operations.
The unreserved bits of the EEPROT register are writable with the restriction that
protection can be added but not removed. Writes must increase the DPS value and the
DPOPEN bit can only be written from 1, protection disabled, to 0, protection enabled. If
the DPOPEN bit is set, the state of the DPS bits is irrelevant.
During the reset sequence, fields DPOPEN and DPS of the EEPROT register are loaded
with the contents of the EEPROM protection byte in the flash configuration field at
global address 0xFF7D located in flash memory. To change the EEPROM protection that
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors93
Flash and EEPROM registers descriptions
will be loaded during the reset sequence, the flash sector containing the EEPROM
protection byte must be unprotected. Then the EEPROM protection byte must be
programmed.
Trying to alter data in any protected area in the EEPROM memory will result in a
protection violation error and the FPVIOL bit will be set in the FSTAT register. Block
erase of the EEPROM memory is not possible if any of the EEPROM sectors are
protected.
Address: 3020h base + 9h offset = 3029h
Bit76543210
* Notes:
x = Undefined at reset.•
Read
Write
Reset
DPOPEN
x*x*x*x*x*x*x*x*
NVM_EEPROT field descriptions
0
DPS
FieldDescription
7
DPOPEN
6–2
Reserved
DPSEEPROM Protection Size
EEPROM Protection Control
0Enables EEPROM memory protection from program and erase with protected address range defined
by DPS bits.
1Disables EEPROM memory protection from program and erase.
This field is reserved.
This read-only field is reserved and always has the value 0.
These bits determine the size of the protected area in the EEPROM memory.
4.6.10Flash Common Command Object Register:High
(NVM_FCCOBHI)
The FCCOB is an array of six words addressed via the CCOBIX index found in the
FCCOBIX register. Byte-wide reads and writes are allowed to the FCCOB register.
Address:
3020h base + Ah offset = 302Ah
Bit76543210
Read
Write
Reset
00000000
CCOB
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
94NXP Semiconductors
Chapter 4 Memory map
NVM_FCCOBHI field descriptions
FieldDescription
CCOBCommon Command Object Bit 15:8
High 8 bits of common command object register
4.6.11Flash Common Command Object Register: Low
(NVM_FCCOBLO)
The FCCOB is an array of six words addressed via the CCOBIX index found in the
FCCOBIX register. Byte-wide reads and writes are allowed to the FCCOB register.
Address:
3020h base + Bh offset = 302Bh
Bit76543210
Read
Write
Reset
00000000
CCOB
NVM_FCCOBLO field descriptions
FieldDescription
CCOBCommon Command Object Bit 7:0
Low 8 bits of common command object register
4.6.12Flash Option Register (NVM_FOPT)
The FOPT register is the flash option register.
During the reset sequence, the FOPT register is loaded from the flash nonvolatile byte in
the flash configuration field at global address 0xFF7E located in flash memory as
indicated by reset condition.
Address:
* Notes:
NXP Semiconductors95
3020h base + Ch offset = 302Ch
Bit76543210
ReadNV
Write
Reset
x = Undefined at reset.•
x*x*x*x*x*x*x*x*
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
Flash and EEPROM registers descriptions
NVM_FOPT field descriptions
FieldDescription
NVNonvolatile Bits
The NV[7:0] bits are available as nonvolatile bits. During the reset sequence, the FOPT register is loaded
from the flash nonvolatile byte in the flash configuration field at global address 0xFF7E located in flash
memory.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
96NXP Semiconductors
Chapter 5
Interrupt
5.1Interrupts
Interrupts save the current CPU status and registers, execute an interrupt service routine
(ISR), and then restore the CPU status so that processing resumes where it left off before
the interrupt. Other than the software interrupt (SWI), which is a program instruction,
interrupts are caused by hardware events such as an edge on the IRQ pin or a timeroverflow event. The debug module can also generate an SWI under certain
circumstances.
If an event occurs in an enabled interrupt source, an associated read-only status flag will
be set. The CPU will not respond unless only the local interrupt enable is a logic 1. The I
bit in the CCR is 0 to allow interrupts. The global interrupt mask (I bit) in the CCR is
initially set after reset that masks (prevents) all maskable interrupt sources. The user
program initializes the stack pointer and performs other system setups before clearing the
I bit to allow the CPU to respond to interrupts.
When the CPU receives a qualified interrupt request, it completes the current instruction
before responding to the interrupt. The interrupt sequence obeys the same cycle-by-cycle
sequence as the SWI instruction and consists of:
• Saving the CPU registers on the stack.
• Setting the I bit in the CCR to mask further interrupts.
• Fetching the interrupt vector for the highest-priority interrupt that is currently
pending.
• Filling the instruction queue with the first three bytes of program information starting
from the address fetched from the interrupt vector locations.
While the CPU is responding to the interrupt, the I bit is automatically set to prevent
another interrupt from interrupting the ISR itself, which is called nesting of interrupts.
Normally, the I bit is restored to 0 when the CCR is restored from the value stacked on
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors97
Interrupts
entry to the ISR. In rare cases, the I bit may be cleared inside an ISR, after clearing the
status flag that generated the interrupt, so that other interrupts can be serviced without
waiting for the first service routine to finish. This practice is recommended only for the
most experienced programmers because it can lead to subtle program errors that are
difficult to debug.
The interrupt service routine ends with a return-from-interrupt (RTI) instruction that
restores the CCR, A, X, and PC registers to their pre-interrupt values by reading the
previously saved information off the stack.
Note
For compatibility with the M68HC08, the H register is not
automatically saved and restored. Push H onto the stack at the
start of the interrupt service routine (ISR) and restore it
immediately before the RTI that is used to return from the ISR.
When two or more interrupts are pending when the I bit is cleared, the highest priority
source is serviced first.
5.1.1
Interrupt stack frame
The following figure shows the contents and organization of a stack frame. Before the
interrupt, the stack pointer (SP) points at the next available byte location on the stack.
The current values of CPU registers are stored on the stack, starting with the low-order
byte of the program counter (PC) and ending with the CCR. After stacking, the SP points
at the next available location on the stack, which is the address that is one less than the
address where the CCR was saved. The PC value that is stacked is the address of the
instruction in the main program that would have executed next if the interrupt had not
occurred.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
98NXP Semiconductors
* High byte (H) of index register is not automatically stacked.
ORDER
7
5
5
4
4
3
3
*
1
1
2
2
0
UNSTACKING
ORDER
PROGRAM COUNTER LOW
CONDITION CODE REGISTER
ACCUMULATOR
INDEX REGISTER (LOW BYTE X)
PROGRAM COUNTER HIGH
TOWARD LOWER ADDRESSES
TOWARD HIGHER ADDRESSES
SP BEFORE
SP AFTER
INTERRUPT STACKING
THE INTERRUPT
Chapter 5 Interrupt
Figure 5-1. Interrupt stack frame
When an RTI instruction executes, these values are recovered from the stack in reverse
order. As part of the RTI sequence, the CPU fills the instruction pipeline by reading three
bytes of program information, starting from the PC address recovered from the stack.
The status flag causing the interrupt must be acknowledged (cleared) before returning
from the ISR. Typically, the flag must be cleared at the beginning of the ISR because if
another interrupt is generated by this source it will be registered so that it can be serviced
after completion of the current ISR.
5.1.2
Interrupt vectors, sources, and local masks
The following table provides a summary of all interrupt sources. High-priority sources
are located toward the bottom of the table. The high-order byte of the address for the
interrupt service routine is located at the first address in the vector address column, and
the low-order byte of the address for the interrupt service routine is located at the next
higher address.
When an interrupt condition occurs, an associated flag bit is set. If the associated local
interrupt enable is 1, an interrupt request is sent to the CPU. If the global interrupt mask
(I bit in the CCR) is 0, the CPU finishes the current instruction, stacks the PCL, PCH, X,
A, and CCR CPU registers, sets the I bit, and then fetches the interrupt vector for the
highest priority pending interrupt. Processing then continues in the interrupt service
routine.
MC9S08PA4 Reference Manual, Rev. 5, 08/2017
NXP Semiconductors99
Interrupts
Table 5-1. Vector summary (from lowest to highest priority)