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 three 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 (the 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.

 

3.     IQRF OS Change File containing IQRF OS and/or DPA update. See chapter IQRF OS Change and below for more information. Using LoadCode command at TR-7xG transceivers, the special handler CustomDpaHandler-ChangeIQRFOS.iqrf is not needed anymore.

 

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.

bits 1-2 Code type:

00  Loads Custom DPA Handler from .hex file.
01  Loads IQRF plug-in from .iqrf file.

1x  Loads IQRF OS Change File .bin file. This option is available at TR-7xG.

bits 3-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. When IQRF OS Change File .bin file is loaded, then the value must be 0x??55 otherwise the actual upload will not be performed but device only resets.

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.
When IQRF OS Change File .bin file is loaded then this parameter is ignored.

 

 

 

 

 

 

 

Response

 

NADR

PNUM

PCMD

HWPID

ErrN

DpaValue

0

NADR

0x02

0x8A

?

0

?

Result

 

Result               bit 0     

0                 An error occurred. The following bits of the result contain the detail.

1                 All conditions are met to load the code if requested. The code will be loaded if Flags.0 was set at the request.

 

bits 1-7 

0000.000      The checksum at the external EEPROM does not match the provided checksum in case of .hex/.iqrf upload.

0000.011      Old IQRF OS is not present (old checksum does not match) in case of .bin upload.

0000.100      The checksum of the IQRF OS Change File in the external EEPROM does not match in case of .bin upload.

0000.111      IQRF OS change file stored in the external EEPROM has an unsupported version in case of .bin upload.

other values Reserved.

 

Error codes

ERROR_FAIL      Invalid Flags value.