Memory Write Commands#

The writemem command writes data directly to device memory. You can provide the data as an input file, one or more --patch options, or both. You can provide only one input file at a time. Commander automatically detects the file format based on the file extension (.bin, .hex, or .s37). For more information about supported file formats, see File Format Overview.

Unlike the flash command, writemem performs a direct memory write. It does not erase flash pages, verify written data, or reset the device when it is finished. For flashing applications, use the flash command. By default, Commander resumes the target after writing. Use the --halt option to leave the target halted.

Note: Like flash, all commands in this section all require a working debug connection to communicate with the device. Normally, use one of the J-Link connection options when running writemem. The examples omit these options to keep them concise.

The --address option specifies the address at which to write data from a .bin file. Commander interprets the value as follows:

  • A value that starts with 0x is interpreted as base 16.

  • A value that starts with 0 is interpreted as base 8.

  • Any other value is interpreted as base 10.

The --address option does not apply to .hex or .s37 files because these formats contain address information. If you do not specify --address when writing a .bin file, writing starts at address 0.

Use the --binary option to interpret all file types as flat binaries, bypassing the parsing of S-record or Intel Hex files. The --binary option requires the --address option.

Write File to Memory#

Writes the image in the specified filename to the target device.

Command Line Syntax

$ commander writemem <filename> [--address <address> --binary --halt]

Command Line Input Example

$ commander writemem blink.s37

Writes the contents of blink.s37 to the addresses specified in the file.

Command Line Output Example

Writing 2812 bytes to address 0x00000000...
DONE

Write Binary File at Address#

Writes a binary file to the specified address.

Command Line Syntax

$ commander writemem <filename> --address <address>

Command Line Input Example

$ commander writemem data.bin --address 0x20000000

Writes the contents of data.bin to address 0x20000000.

Command Line Output Example

Writing 128 bytes to address 0x20000000...
DONE

Patch Memory Contents#

Writes the specified byte or bytes to target memory. When you use the --patch option, Commander interprets the patch data as an unsigned integer. Use the optional length argument to specify the number of bytes, up to 8. If you do not specify a length, Commander patches 1 byte by default.

You can use --patch without a file or combine it with an input file. If a patch address overlaps data in the input file, the patch data overwrites those bytes before Commander writes the data to the device.

Command Line Syntax

$ commander writemem --patch <address>:<data>[:length]

OR

Command Line Syntax

$ commander writemem <filename> --patch <address>:<data>[:length]

Command Line Input Example

$ commander writemem --patch 0x20000000:0xAB --patch 0x20000010:0xA5A5:2

Writes the byte 0xAB to address 0x20000000 and the two bytes 0xA5A5 to address 0x20000010.

Command Line Output Example

Writing 1 bytes to address 0x20000000...
Writing 2 bytes to address 0x20000010...
DONE