2
\$\begingroup\$

These days I was testing a bootloader (AN1157.PDF) on a pic24fj256gb110 The bootloader can download the user app code through the uart and it is running well!

But there is a question: the bootloader configure word must be the same than the user app code configure word. When I change the app code configure word and download it through the bootloader, the configure word cannot be written into the mcu. Can configure word be changed when the MCU is running? (I didn't protect any code)

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

It depends on the specific PIC24 device, but in the case of the PIC24FJ256GB110, they can be reprogrammed. This is because the Configuration Bits are actually implemented in volatile memory starting at 0xF80000, and copied from another set of locations called the Flash Configuration Words every time the device resets. If your bootloader modifies these Flash Configuration Words, and then does a reset, the new values will be used by the application code.

The location of the Flash Configuration Words varies depending on the size of flash memory, but for the PIC24FJ256GB110 they are:

Configuration Word 1: 0x2ABFE
Configuration Word 2: 0x2ABFC
Configuration Word 3: 0x2ABFA

I assume these locations have to be programmed using the Table Write instructions which you are probably already using in the bootloader.

From the second reference cited below:

As mentioned before, changes to the actual device Configuration bits during run time would cause a Configuration Mismatch Reset. This does not prevent changes to Flash Configuration Words during normal operation. This also makes it possible for an application to change its hardware configuration by writing new data to these Flash Configuration Words, and then executing a RESET command, which results in reloading the new values.

References:

Section 25.0 (SPECIAL FEATURES) of the PIC24FJ256GB110 Family Data Sheet

Section 32. High-Level Device Integration

\$\endgroup\$
2
\$\begingroup\$

Usually no.

The "configure word" are usually called "fuses". Because in the good old days, theses were actual fuses that got burnt once externally programmed. And this was not a reversible process.

In the actual MCUs, the fuses are usually not made of actual fuse but their meaning remains the same. They are usually used to configure thing such as:

  • Kind of oscillator to use on boot
  • Which memory to boot from (internal or external)
  • Code protection
  • Is the debugger allowed?

This is the kind of thing that may have to be configured before running the first line of code.

Imagine a MCU without any internal oscillator. You therefore have to configure the external oscillator driver correctly or the oscillator will not start and you are stuck. This can't be done done by software because you don't have an oscillator yet... Fuses are used.

Now imagine that you can change the fuse from your software. What happens if you do a mistake in your code? If there is a fault at run time and you modify your startup oscillator configuration? Your device is broken.

Well, modern MCUs usually have an internal oscillator and the oscillator configuration is not in the fuses anymore. You can run your code using the default startup internal oscillator and then setup the rest in your code. Things have evolved. That was just an example of the usefulness of having something that can't be changed at run time.

Another reason: Security and IP protection. Imagine that it's possible to change the read protection or the debugger-enable bit: One could quite easily force your MCU to enable those bit and steal your binary containing your IP.

Once you burn the read protection fuse, you want to be sure there is no way to go back and read back the content of the chip.

In conclusion, it's usually not possible to reprogram the configuration bits at run time. Otherwise they would have been regular configuration registers.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.