6.3.2 Memory Management

The PIC32WM-BW1 family of devices has enough embedded Flash memory to hold the new upgradable OTA image until the new image is authenticated. The device receives the image in blocks over the Bluetooth® LE link. If the image is encrypted, the device decrypts it and stores it in embedded Flash slot 1. Once the device receives the complete image, it validates the image’s signature. Then, a device reset triggers the bootloader in the boot Flash region to load the image from slot 1 to slot 0. The new firmware then starts executing.

The following figure illustrates the memory split for the PIC32WM-BW1 embedded Flash for OTA DFU:

Figure 6-36. Memory Split for DFU
The following linker script handles the above memory split:
#ifndef PDS_LENGTH
#define PDS_LENGTH 0x4000
#endif
#define ROM_BASE_ADDR 0x01000000
#define METADATA_HEADER_SIZE 0x200
#define SLOT0_BASE_ADDR ROM_BASE_ADDR
#define SLOT1_BASE_ADDR 0x01080000
#ifndef ROM_ORIGIN1
#define ROM_ORIGIN1 SLOT0_BASE_ADDR + METADATA_HEADER_SIZE
#endif
#ifndef ROM_LENGTH1
#define ROM_LENGTH1 (SLOT1_BASE_ADDR - SLOT0_BASE_ADDR - PDS_LENGTH - METADATA_HEADER_SIZE)
#elif (ROM_LENGTH1 > 0x100000)
#error ROM_LENGTH1 is greater than the max size of 0x100000-0x200
#endif
#ifndef PDS_ORIGIN
#define PDS_ORIGIN (ROM_ORIGIN1 + ROM_LENGTH1)
#endif
#ifndef ROM_ORIGIN2
# define ROM_ORIGIN2 SLOT1_BASE_ADDR
#endif
#ifndef ROM_LENGTH2
#define ROM_LENGTH2 0x0080000
#elif (ROM_LENGTH2 > 0x100000)
#error ROM_LENGTH2 is greater than the max size of 0x100000
#endif
#ifndef BOOT_ROM_ORIGIN
# define BOOT_ROM_ORIGIN 0x0
#endif
#ifndef BOOT_ROM_LENGTH
# define BOOT_ROM_LENGTH 0x5e00
#elif (BOOT_ROM_LENGTH > 0x5e00)
# error BOOT_ROM_LENGTH is greater than the max size of 0x5e00
#endif