PreviousNext
LoadCode
Help > Peripherals > OS > LoadCode

[sync] [comdown] Implemented at [C] and [N] devices. This advanced command allows OTA (over the air] update of the firmware as it loads a code previously stored at external EEPROM to the MCU Flash memory. Then the device is reset. External EEPROM can store more code images at one time. When storing the code for upload at the external EEPROM, make sure you do not overwrite another stored code or IO Setup.

 

Please note, that there might be a considerable delay before a response is ready because the command needs to read a larger amount of external EEPROM memory and compute the checksum.

 

The command can load two types of code:

1.     Custom DPA Handler code from the .hex file.


Custom DPA Handler code (but not the optional content of EEPROM and/or external EEPROM required by the handler) can be uploaded, updated, or just “switched” “over the air” without the need to reprogram the device using a hardware programmer.


It is necessary to read the output .hex file containing compiled Custom DPA Handler code to obtain the code before it can be stored as an image at external EEPROM. The continuous code block starts from the PIC address
CUSTOM_HANDLER_ADDRESS = 0x3A20 and is located up to address CUSTOM_HANDLER_ADDRESS_END - 1 = 0x3D7F. Because each MCU instruction takes 2 bytes the address inside the .hex file is doubled so the code starts from address 0x7440 at the .hex file. Please read the Custom DPA Handler Code from .hex File for more details.

 

The length of the image stored in the external EEPROM must be a multiple of 64 (used Flash memory page of MCU is 32 words long) otherwise the result is undefined. The checksum value is calculated from all the code bytes including unused trailing bytes that fill in the last 64‑byte block. We recommend filling in unused trailing bytes by value 0x34FF to get the same checksum value as IQRF IDE. The initial value of the Fletcher-16 checksum is 0x0001.

 

If loaded Custom DPA Handler code needs to use the certain content of EEPROM and/or external EEEPROM memory, then EEPROM and/or EEEPROM peripherals can be used to prepare the content before the handler is loaded. Disabling former Custom DPA Handler using Write TR Configuration byte (configuration byte at index 0x5, bit 0) and Restart is highly recommended (both commands might be the content of one Batch or Acknowledged broadcast - bits) if old or a new handler use EEPROM and/or EEEPROM peripherals. After a new handler is loaded it must be then enabled back.

 

2.     IQRF plug-in containing DPA protocol implementation (to perform DPA version change on the fly), Custom DPA Handler, or IQRF OS patch. The feature is supported starting from IQRF OS version 3.08D and the corresponding DPA version.


IQRF plug-in file is a text file containing an encrypted code. Only lines of the file that do not start with character # contain the code. Such lines contain 20 bytes stored by 2 hexadecimal characters (thus every line contains 40 characters in total). To create a code image for the external EEPROM from IQRF plug-in file just read all the consequential hexadecimal bytes from all code lines from the beginning to the end of the file, convert them to the real bytes and store them in the external EEPROM.

 

The length of the image stored in the external EEPROM must be multiple of 20. The initial value of the Fletcher-16 checksum is 0x0003.


Please note that only DPA IQRF plug-in version 2.26 or higher can be loaded.

 

Request

 

NADR

PNUM

PCMD

HWPID

0

1 … 2

3 … 4

5 … 6

NADR

0x02

0x0A

?

Flags

Address

Length

CheckSum

 

Flags                bit 0      Action:

0  Computes and matches the checksum only without loading code.

1  Same as above plus loads the code into Flash if the checksum matches.

bit 1      Code type:

0  Loads Custom DPA Handler.
1  Loads IQRF plug-in.

bits 2-7 Reserved, must equal 0.

Address           A physical address at external EEPROM memory to load the code image from.

Length              Length of the code image in bytes at the external EEPROM. See the text above.

CheckSum        One’s complement Fletcher-16 checksum of the code image. If the checksum does not match a checksum of the code stored in external EEPROM then writing the code to the Flash memory is not performed. See source code examples of the checksum calculation. For an initial checksum value see the text above. Different initial checksum values for both types of upload code ensure that code types cannot be confused.

 

Response

 

NADR

PNUM

PCMD

HWPID

ErrN

DpaValue

0

NADR

0x02

0x8A

?

0

?

Result

 

Result               bit 0      1  The checksum matches a checksum of the code at the external EEPROM.

The code will be loaded if Flags.0=1 was specified at the request.
            0  The checksum does not match.

                        bit 1-7   Unused, equals 0.