© 2008 Microchip Technology Inc. DS01157A-page 5
AN1157
BOOTING A DEVICE
Entering and Leaving Boot Mode
With the bootloader firmware loaded, there are two dis-
tinct modes of operation: Boot mode and User mode. A
1-byte value should be placed at the location specified
by DELAY_TIME_ADDR, which is defined in config.h.
A value of FFh indicates that the bootloader will remain
in Boot mode and not switch to User mode without a
command to do so. Thus, a new part with no valid user
code will automatically enter Boot mode until user code
is successfully programmed. Any other value indicates
a number of seconds the bootloader will wait prior to
switching to User mode. A value of 0 will immediately
run User mode. The delay time will not be written into
Flash by the bootloader until the VERIFY_OK com-
mand is sent. This command indicates to the boot-
loader that the user application has been successfully
programmed, and is done in order to prevent possible
bootloader lockout.
To leave Boot mode, a device Reset (hardware or soft-
ware) must be initiated or a RESET command must be
sent.
Program Memory Operations
The bootloader supports reads, writes and erases to
Flash memory. Depending on the command being
used, there is a minimum amount of data which can be
referenced. Reading Flash is done at the instruction
level. Each instruction has three bytes of program data
and one byte of zeroes, called the “phantom byte”, for
a total of four bytes. Write operations are performed in
64 instruction blocks called rows (256 bytes). Erase
instructions are performed in blocks of 8 rows called
pages (2048 bytes). For detailed information on the
PIC24F Flash program memory, refer to the PIC24F
program memory section in the “PIC24F Family
Reference Manual” or device data sheets.
When programming memory on PIC24F devices, first
the page needs to be erased. Most locations in Flash
operate such that erase operations set bits and
program operations can only clear bits. Therefore, it is
not recommended to write to a location multiple times
without erasing. Additionally, this means that it is not
possible to recover from a situation where the boot-
loader is partially or completely corrupted by writes or
erases to the memory space it occupies. For this
reason, it is recommended to use either software or
hardware boot block protection.
Data EEPROM Operations
Some PIC24F devices have built-in data Flash memory
EEPROM. The bootloader allows data Flash to be read
and erased at a word level, 2 bytes at a time. Erases
are done on a word level prior to performing a write.
Not all devices have data EEPROM. The functions that
support this can be removed through the bootloader
configuration at compile time.
Device Configuration
PIC24F devices implement device configuration in one
of two ways: Flash Configuration Words and Configu-
ration bits. Note that having access to the device
configuration, though useful, is potentially dangerous.
If the configuration is changed to a mode not supported
in the application, such as switching from a high-speed
crystal to the LPRC oscillator, it will cause the system
to function incorrectly, and in some cases, break the
bootloader’s ability to fix the configuration. For this
reason, care should be taken when performing
configuration changes.
FLASH CONFIGURATION WORDS
Devices with Flash Configuration Words store their
configuration information in the last few instructions in
user program memory. These values are copied into
volatile registers in the configuration memory space
when the part resets. Since they are a part of user
memory, a page erase performed on the final page of
Flash memory also erases the device configuration. If
the Flash Configuration Words are changed during run
time, the device continues to run using its original
configuration until a Reset occurs.
The PIC24F serial bootloader treats the configuration
information on these devices as normal user memory,
and programs it along with of the last row of Flash
memory. A bootloader configuration option is provided
to protect the last page of memory from erases and
writes to prevent configuration corruption.
CONFIGURATION BITS
Devices using Configuration bits implement device
configuration in 8-bit registers in the configuration mem-
ory space, starting at address F80000h. Configuration
bits are read and written in single bits and do not need to
be erased prior to writing. However, some of the Config-
uration bits are unidirectional bits, and cannot be
self-programmed back to a ‘1’ if they are set to ‘0’. An
example is any of the code protection bits, which cannot
be disabled using device self-programming.
For devices with Configuration bits, configuration
information is read and written separately from Flash
program memory with separate commands. These
commands can optionally be removed from the
bootloader for devices that use Flash Configuration
Words instead of Configuration bits to save program
space.
Note: The bootloader will not wait the correct
amount of time before entering User mode
if the User mode instruction speed (F
CY) is
not defined correctly.