PostHeaderIcon MSP430G2452: Why a Copied Image Boots and Then Will Not Communicate

A restored device that runs but cannot talk is one of the most misleading outcomes in this work, because everything that can be checked statically passes. The image verifies, the device starts, the program reaches its main loop, and then the serial port produces framing errors at every baud rate.

The cause is almost always the same: the main array was copied and the calibration was not, or the calibration was copied when it should not have been. Both are errors, they point in opposite directions, and telling them apart requires knowing what the calibration values actually describe.

Two regions, two meanings

The device has a main memory region holding the program, and an information region holding values written by the factory before the part was packaged.

The information region is not spare flash. It contains the constants that let the program configure the internal oscillator to a known frequency, and on parts with analog blocks it contains correction values for the reference, the gain stages and the temperature sensor. A program that reads those constants at startup is normal; a program that assumes fixed values is a program that will drift with temperature and part.

Region Contents Belongs to
Main array Program, constants, vector table The product
Information region A Factory calibration The individual die
Information region B and above Available to the application The product
Descriptor area Device identity and table structure The device type

The distinction in the third column is the whole article. The main array describes a product. The calibration describes a piece of silicon.

Why copying calibration is usually wrong

The calibration constants compensate for manufacturing variation in that specific die. Copy them to a different die and you apply one part’s correction to another part’s error. The result is a clock that is off by however much the two dies differ, which for an internal oscillator is easily several percent.

Several percent is fatal for asynchronous serial communication. A few percent is enough to push the sampling point outside the bit window at the end of a frame, so the first bytes arrive correctly and the later ones do not — a symptom that looks like a buffer problem and is a clock problem.

The correct treatment is therefore: copy the main array, leave the destination’s information region alone, and let the destination’s program read the destination’s own calibration.

When copying calibration is right

There is an exception, and it is common enough to check for.

Some programs do not read the calibration at runtime. The author read the constants once, during development, and wrote the values into the source as literals. The program then contains numbers that were correct for the development board and wrong for everything else.

On such a product, the calibration values in the source must be copied, because they are part of the program’s behaviour. The device will run at the frequency the original author intended rather than the frequency its own die would produce.

The way to tell which case you have is to look at the startup code. A program that loads a value from the information region address is reading its calibration. A program that loads an immediate constant is not.

The restoration sequence

  1. Read the source main array and record the destination’s information region separately.
  2. Inspect the source startup code and classify the calibration handling as read-at-runtime or compiled-in.
  3. Program the destination main array from the source image.
  4. Leave the destination’s information region untouched if the program reads it; program the source values into it if the program has them compiled in.
  5. Program the vector table as part of the main array, and confirm its contents.
  6. Power up and measure the clock at a test point before connecting any serial interface.
  7. Only then test communication.

Steps six is the one that saves the debugging session. A clock measurement takes a minute and distinguishes a calibration error from every other cause of a communication failure.

What a restored device must reproduce

Beyond the program, four properties have to match for the restoration to be complete:

  • the reset vector, so the device starts where the program expects,
  • the initial stack pointer, so the first push does not corrupt memory,
  • the oscillator configuration, so the timing of every peripheral is right,
  • the analog correction values, so measurements agree with the original.

The last one is where restored devices are quietly wrong. A unit that reads a sensor and reports a value within a few percent of the original is usually considered good, and a few percent is exactly what an uncorrected reference produces. Where the product’s function is measurement, that difference is the function.

Restoring into a device that was never the same type

A subtler problem: the destination may be a different density or a different variant of the same family, with the same pinout and a different information region layout. The program then reads calibration from an address that holds something else.

This is worth checking before programming, because the symptom appears only at runtime and looks like a hardware fault. Reading the destination’s information region and comparing its structure against the source’s is a two-minute check that eliminates the whole class of failure.

Verifying that the restoration is real

A restored device should be tested against the original on the properties that matter to the product, not only on whether it starts.

  1. Measure the clock frequency at the same test point on both.
  2. Compare the serial output of a known command byte for byte.
  3. Compare an analog measurement at a known input.
  4. Compare the behaviour at the temperature extremes the product specifies.

Steps three and four are the ones that catch calibration errors after the device has already been accepted as working. A unit tested at room temperature with a low-precision input will pass with a wrong reference value and fail in the field.

Related reading

FAQ

Should the destination’s calibration be overwritten? Only if the program contains the values as constants rather than reading them.

Why does the first part of a serial frame arrive correctly? Because the sampling error accumulates across the frame. Early bits are inside the window, later ones are not.

Is the information region protected? Usually not, which is why it is readable on an otherwise locked device.

Can the clock be checked without a scope? By measuring a periodic output the program already produces, if it produces one.

Conclusion

The main array is the product and the information region is the die. Copy the first, preserve the second, and check which convention the startup code follows before deciding. A restored device that boots and cannot communicate is almost always a calibration decision made backwards.

Comments are closed.