Difference between revisions of "Read-Modify-Write Flash"

From SEGGER Wiki
Jump to: navigation, search
Line 1: Line 1:
  +
This article describes how to use the '''Read-Modify-Write (RMW)''' function in the J-Link software. This article assumes that there is already a basic knowledge about flash programming in general.
  +
By default the Read-Modify-Write threshold is set to 1 KiB in order to allow read-modify-write of single bytes in flash (e.g. when editing bytes in memory windows of IDEs).
  +
To increase or decrease the threshold J-Link offers the following command string: [[J-Link_Command_Strings#SetFlashDLNoRMWThreshold | ''SetFlashDLNoRMWThreshold = <value>'']]
  +
{{Note|RMW will only be executed if the memory to be written is smaller than the RMW value. This also means:
  +
* Setting the RMW to <tt>0x0</tt>, will disable read modify write entirely
  +
* Setting it to <tt>0xFFFFFFFF</tt> will result in RMW to be always used}}
 
__TOC__
 
__TOC__
   
  +
== Theoretical example ==
This article describes how to use the '''Read-Modify-Write (RMW)''' function in the J-Link software. This article assumes that there is already a basic knowledge about flash programming in general.
 
  +
This example assumes that a bootloader is already present in the sector in which the sample application is to be downloaded.
  +
The memory of bootloader and application is not overlapping so the application can be added to the same sector as the bootloader, without overwriting the bootloader, assuming the correct RMW value is set.
   
  +
=== Assumptions ===
The following example project will be shown for a Infineon XMC4500 MCU but can be applied to any other MCU. This can for example be used to split physical memory sectors into smaller logical ones.
 
  +
{|
  +
|-
  +
| Sector size || 0x10000
  +
|-
  +
| Bootloader location || 0x0000_0000 to 0x0000_3FFF || already in flash (size: 0x4000 bytes)
  +
|-
  +
| Application location || 0x0000_4000 to 0x0000_FFFF || to be downloaded (size: 0xC000 bytes)
  +
|-
  +
|}
   
  +
=== Determining the correct value for RMW ===
By default the Read-Modify-Write threshold is set to 1 KiB in order to allow read-modify-write of single bytes in flash (e.g. when editing bytes in memory windows of IDEs).
 
  +
To make sure RMW will be used, the value for <tt>SetFlashDLNoRMWThreshold</tt> has to be ApplicationSize + 1 '''or higher'''.
  +
  +
For our example, this means, everything between
  +
"SetFlashDLNoRMWThreshold = 0xC001"
  +
and
  +
"SetFlashDLNoRMWThreshold = 0xFFFFFFFF"
  +
will result in read modify write to be executed, and thus the bootloader and application will both be present in flash after downloading.
  +
  +
=== RMW in J-Link Commander ===
  +
For this example, we assume that
  +
* the name of the data file with the application is "App.hex".
  +
* the bootloader is already present in the device flash.
  +
* the J-Link commander is already connected to the device
  +
exec SetFlashDLNoRMWThreshold = 0xFFFFFFFF // Always do read modify write.
  +
loadfile App.hex
  +
  +
== Sample projects ==
  +
In this section the RMW is explained with a couple of practical examples.
   
  +
=== XMC4xxx ===
To increase the threshold J-Link offers the following command string: ''SetFlashDLNoRMWThreshold = <value>''
 
  +
The following project was designed for an Infineon XMC4500 MCU, but the procedure can be applied to any other MCU, too.
  +
In case of the XMC4xxx MCUs, the physical memory sectors are split into smaller logical ones.
  +
The J-Link owever J-Link will always flash the phy
   
A more detailed description is available [[J-Link_Command_Strings#SetFlashDLNoRMWThreshold | here]].
 
   
= Sample project =
 
 
The sample project is designed to be used with J-Link and a Infineon XMC4500 MCU. It will we automatically executed when starting the .bat file.
 
The sample project is designed to be used with J-Link and a Infineon XMC4500 MCU. It will we automatically executed when starting the .bat file.
   
Line 18: Line 54:
 
[[Media:Wiki_J-LinkCommander_RMW_Example.zip | Wiki_J-LinkCommander_RMW_Example.zip]]
 
[[Media:Wiki_J-LinkCommander_RMW_Example.zip | Wiki_J-LinkCommander_RMW_Example.zip]]
   
= How to =
+
== How to ==
   
 
For the example project the ''SetFlashDLNoRMWThreshold'' value is set to ''0xFFFF'' (64 KiB RMW threshold). This means that the J-Link DLL will perform a read-modify-write of flash memory regions <= 64 KiB. Make sure you adjust this value depending on the device and sector you are trying to modify.
 
For the example project the ''SetFlashDLNoRMWThreshold'' value is set to ''0xFFFF'' (64 KiB RMW threshold). This means that the J-Link DLL will perform a read-modify-write of flash memory regions <= 64 KiB. Make sure you adjust this value depending on the device and sector you are trying to modify.

Revision as of 13:07, 18 January 2022

This article describes how to use the Read-Modify-Write (RMW) function in the J-Link software. This article assumes that there is already a basic knowledge about flash programming in general. By default the Read-Modify-Write threshold is set to 1 KiB in order to allow read-modify-write of single bytes in flash (e.g. when editing bytes in memory windows of IDEs). To increase or decrease the threshold J-Link offers the following command string: SetFlashDLNoRMWThreshold = <value>

Note:

RMW will only be executed if the memory to be written is smaller than the RMW value. This also means:

  • Setting the RMW to 0x0, will disable read modify write entirely
  • Setting it to 0xFFFFFFFF will result in RMW to be always used

Theoretical example

This example assumes that a bootloader is already present in the sector in which the sample application is to be downloaded. The memory of bootloader and application is not overlapping so the application can be added to the same sector as the bootloader, without overwriting the bootloader, assuming the correct RMW value is set.

Assumptions

Sector size 0x10000
Bootloader location 0x0000_0000 to 0x0000_3FFF already in flash (size: 0x4000 bytes)
Application location 0x0000_4000 to 0x0000_FFFF to be downloaded (size: 0xC000 bytes)

Determining the correct value for RMW

To make sure RMW will be used, the value for SetFlashDLNoRMWThreshold has to be ApplicationSize + 1 or higher.

For our example, this means, everything between

"SetFlashDLNoRMWThreshold = 0xC001"

and

"SetFlashDLNoRMWThreshold = 0xFFFFFFFF"

will result in read modify write to be executed, and thus the bootloader and application will both be present in flash after downloading.

RMW in J-Link Commander

For this example, we assume that

  • the name of the data file with the application is "App.hex".
  • the bootloader is already present in the device flash.
  • the J-Link commander is already connected to the device
exec SetFlashDLNoRMWThreshold = 0xFFFFFFFF // Always do read modify write.
loadfile App.hex

Sample projects

In this section the RMW is explained with a couple of practical examples.

XMC4xxx

The following project was designed for an Infineon XMC4500 MCU, but the procedure can be applied to any other MCU, too. In case of the XMC4xxx MCUs, the physical memory sectors are split into smaller logical ones. The J-Link owever J-Link will always flash the phy


The sample project is designed to be used with J-Link and a Infineon XMC4500 MCU. It will we automatically executed when starting the .bat file.

The .bat and .jlink file can be used as a reference for your own RMW flash projects.

Wiki_J-LinkCommander_RMW_Example.zip

How to

For the example project the SetFlashDLNoRMWThreshold value is set to 0xFFFF (64 KiB RMW threshold). This means that the J-Link DLL will perform a read-modify-write of flash memory regions <= 64 KiB. Make sure you adjust this value depending on the device and sector you are trying to modify.

To use the example project follow these steps:

  • Unzip the contents of the Wiki_J-LinkCommander_RMW_Example.zip to a example folder
  • execute StartTest.bat
  • The J-Link commander will open and you should see the following output
Flash Success.PNG
  • If your output matches the screenshot, the RMW was successful (this applies only to the example project, the output on your own project might vary)