Buy Contact NSDSP Home

Devices with Swappable Partitions

Some of the devices have two separate flash panels which can be swapped at run-time. This may be either a permanent condition (for example for PIC32MZ) or the device must be partitioned (for example dsPIC33CK) to be able to swap halves.

When a device has swappable partitions, each partition contains its own application and these applications may be swapped at boot or at run time. Each of these two applications can be debugged.

Getting a HEX file

Usually, both applications are combined into a single HEX file. However, you also may use separate HEX files for the applications, transpose, and combine them on the fly using HEX management functions provided by NSDSP Interface library. For example, for dsPIC33 you can use the following pseudo-code:

  hexMapA = hexMap.read(file_A)
  hexMapB = hexMap.read(file_B)

  for each hexBlock in hexMapB {
    hexBlock.address = hexBlock.address or 0x800000
  }

  hexMap = hexMapA.merge(hexMapB)
  hexMap.partition

  debugSession = Session.programForDebug(hexMap, tcy)

or for PIC32MZ2064:

  hexMapA = hexMap.read(file_A)
  hexMapB = hexMap.read(file_B)

  for each hexBlock in hexMapB {
    switch hexBlock.address and 0xfff00000 {
      case 0x1d000000: hexBlock.address = hexBlock.address or 0x00100000
      case 0x1fc00000: hexBlock.address = hexBlock.address or 0x00020000
    }
  }

  hexMap = hexMapA.merge(hexMapB)

  debugSession = Session.programForDebug(hexMap, tcy)

When you build the HEX file it will contain images of both applications, each built separately. At run time, any one of them may become active. The debugger must be ready to handle either one of the applications. Therefore the debugger configuration must be the same for both applications.

Assisted Setup

If you use assisted debugging, you need to make sure that the location of RAM for the debugger use (if needed) is the same for both partitions. The location of software breakpoint status word also must be the same in both partitions. The easiest way to accomplish this is to allocate them at fixed addresses. This way the addresses are guaranteed to be the same for both partitions.

Look at the memory map and find an unused place (typically at the end of memory) and locate the debugger memory there. Then edit the nsdsp_dbg.S file to specify the addresses. For example change these section headers:

  .section nsdsp_dbg_ram,  NSDSP_DBG_ATTR
  .section nsdsp_dbg_bp,bss,coherent

to this:

  .section nsdsp_dbg_ram,  NSDSP_DBG_ATTR,address(0x8009ffe0)
  .section nsdsp_dbg_bp,bss,coherent,address(0x8009fffc)

Manual Setup

When you do not use assisted debugging, you still may need to reserve RAM for the debugger. Make sure that the reserved RAM is not used by neither of your applications.

Debugging

After every halt, you can call the isSwapped function to find out if partitions are swapped or not. You can use this information to find out which of the partitions is currently executing.

For PIC32, where boot partitions can be swapped independently of the program flash, there is another function - isBootSwapped to find out if boot areas are swapped.

Northern Software Home NSDSP Contact Us Purchase/View Cart

© 2007-2025 Northern Software Inc. All Rights Reserved.