Nrf52 linker scripts


I am playing with custom boards that feature nRF52832 SoC. I started off with a dev kit nRF52-DK and Adafruit Feather nRF52832 to improve my understanding how developing custom boards in PlatformIO works. And apparently, there are a lot of differences in weather you start off with Adafruit-based product, or a generic nRF52-DK board. The Arduino framework is just different for two systems, and build process as well.

One example is the linker script. Adafruit feather invokes the script “nrf52832_s132_v6.ld”, while the DK invokes the “nrf52_xxaa.ld”. Digging into them, I see they vary in Flash and RAM size, in that, DK containts:

  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000
  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
  CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x10000

While the Adafruit Feather contains:

  FLASH (rx)     : ORIGIN = 0x26000, LENGTH = 0x6D000 - 0x26000

  /* SRAM required by S132 depend on
   * - Attribute Table Size
   * - Vendor UUID count
   * - Max ATT MTU
   * - Concurrent connection peripheral + central + secure links
   * - Event Len, HVN queue, Write CMD queue
  RAM (rwx) :  ORIGIN = 0x20003600, LENGTH = 0x20010000 - 0x20003600

So for some reason Adafruit board has an offset in both RAM and Flash. Why is that so? I assume that S132 SoftDevice requires some special babysitting, but then again, nRF52-DK is also capable of using the SoftDevice, and there are no special changes into the memory map. Could it be the bootloader?

I came across this questions because at first I have based my board on nRF52-DK variant and code build and upload worked well. But when I switched to the Adafruit based board variant, it PIO started complaining a lot. After solving some of the builder issues, such as variant directory and json manifest, I got my build process running just fine. But after the upload, I just noticed that my code is not there on the MCU! It was simply not uploaded - I could see the old code messages coming out of my UART terminal. So, I naturally thought that something’s off in the linking process.