PostHeaderIcon PIC18F23K20: Reading the Configuration Word Before Anything Else

There is a strong instinct, when confronted with a device that will not give up its program, to attack the program directly. That instinct is usually wrong on this family, because the most informative thing on the device is not the array — it is a short run of registers in a separate address space that says what the device is configured to do.

Those registers are readable when the array is not, they are small, and they answer the questions that otherwise become guesswork: is the array protected, is the watchdog running, what clock does the board have to provide, can the device be entered through a low-voltage interface.

Where the configuration lives

The configuration registers sit in their own region of the address map, outside the program array. Each is a byte, they are consecutive, and together they decide the device’s operating envelope.

Because they are byte-wide while the core is word-oriented, tools present them inconsistently: some show eight bytes, some show a merged word, some show a single hex value with fields labelled. The inconsistency is a nuisance rather than a problem, as long as the field positions are taken from the programming specification rather than inferred from a tool’s display.

Group Decides Why it matters for analysis
Oscillator Clock source, PLL, fail-safe What the board must supply
Reset and watchdog Watchdog, brown-out, power-up timer Whether timing measurements are stable
Memory protection Code protect, table-read protect Whether a read can succeed at all
Write protection Per-block write protect Whether the array can be modified
Programming Low-voltage programming How the device can be entered

Protection bits are not one bit

On this family the protection fields are several, and they answer different questions:

  • Code protection, per block, gates reads from outside.
  • Table-read protection, per block, gates reads from running code.
  • Data EEPROM protection, a separate bit for the data array.
  • Boot block protection, which applies to the small region holding the reset vectors.

Reading the configuration tells you which of these are set. It does not tell you the password, because there is no password on this family — the bits are the whole mechanism.

That is worth stating explicitly, because it is a common misconception carried over from parts that do have a password. Here, protection is a set of configuration bits and nothing else. There is no value to guess.

Why the configuration is readable when the array is not

The programmer needs it. Before it can read or write anything, it must know the device’s programming voltage, its oscillator setting and its code-protect state, and it obtains those from the configuration registers.

This is a deliberate design choice and it costs the protection scheme very little: knowing that a device is protected does not help you read it. What it does is make analysis possible, because the state of the device is knowable in advance.

What the oscillator setting tells you

An unexpected amount of diagnostic value sits in the oscillator field.

A device configured for an external crystal needs a crystal on the board, and a board whose crystal has failed presents a device that does not run — indistinguishable, from the outside, from a device with a corrupted program. A device configured for the internal oscillator runs with nothing on the board at all.

The failure modes are opposite and the configuration distinguishes them in one read. That single fact resolves a category of “dead device” reports that would otherwise consume a bench session.

Write protection as evidence of intent

Write-protect bits record decisions made at production time, and they persist. A device whose boot block is write-protected and whose application block is not was designed to be field-updated. A device with everything write-protected was not.

That history is often more useful than the code. It tells you whether an update path exists, whether the vendor expected units to be reprogrammed, and therefore whether an update image is likely to be obtainable from the vendor’s own distribution.

The order of operations

  1. Read the configuration registers and record them verbatim.
  2. Interpret the oscillator and programming fields; they decide how to connect.
  3. Interpret the protection fields; they decide what is possible.
  4. Attempt an array read only after the first three are established.
  5. If the array is protected, decide between erase-and-restore, behavioural reconstruction, and stopping.

Step five is a real option and is chosen less often than it should be. On a part with 8K of program memory and no unique behaviour, the cost of reconstruction can exceed the value of the result, and the configuration read has already told you everything the device was configured to reveal.

Limits

  • The configuration registers say nothing about what the array contains.
  • They say nothing about whether the device is the part its marking claims; a remarked device can carry different configuration behaviour.
  • They are writable, so a device that has been through an update may carry configuration set by the bootloader rather than by the factory.

That last point argues for reading the configuration twice: once immediately after reset, and once after the application has had time to run.

Related reading

FAQ

Is there a password on this family? No. Protection is a set of configuration bits; there is no value to supply.

Can the configuration be read when the array is protected? Yes. The programmer needs it to operate, so it remains accessible.

Does a protected device still run? Yes. Protection gates reads, not execution.

Why read the configuration twice? A bootloader can rewrite it at runtime, so the value after reset and the value during operation may differ.

Does write protection hide contents? No. It prevents modification only.

Conclusion

The configuration registers are the cheapest and most informative read on this part: they say whether the array is protected, what the board must provide, how the device can be entered, and what the vendor intended at production time. Starting there converts a speculative job into a planned one — and sometimes into the conclusion that no further work is warranted.

Comments are closed.