Flash memory partitioning using ld script

Hii,
Here i posted the ld file.In this i need page 127 to 128 for the custom partition for the internal flash write and flash read.please verify is it ok for the nrf52840 for 127 to 200 pages for the user need partition.
MEMORY
{
  FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0xd7000
  FLASH_REGS (rx) : ORIGIN = 0xfe000, LENGTH = 0x2000
  RAM (rwx) : ORIGIN = 0x20002b00, LENGTH = 0x33c00
  RAM_SPIM3 (rwx) : ORIGIN = 0x2003df00, LENGTH = 0x2000
  RAM_NOINIT (rwx) : ORIGIN = 0x2003ff00, LENGTH = 0x100
  CUSTOM_MEMORY (rwx) : ORIGIN = 0x7F000, LENGTH = 0x49000
}

SECTIONS
{
  .text :
  {
    *(.text)
  } > FLASH

  .rodata :
  {
    *(.rodata)
  } > FLASH

  .data :
  {
    *(.data)
  } > RAM

  .bss :
  {
    *(.bss)
  } > RAM

  /* Custom section for user data in flash (from page 127 to page 200) */
  .user_flash_data :
  {
    *(.user_flash_data)
  } > CUSTOM_MEMORY = 0x27000 + (127 * 4096) : AT(0x27000 + (200 * 4096)) /* Reserved page 127 to 200 for the user log data */
}

Parents
  • Hi,

     

    > CUSTOM_MEMORY = 0x27000 + (127 * 4096) : AT(0x27000 + (200 * 4096)) /* Reserved page 127 to 200 for the user log data */

    Does this compile properly and show that .user_flash_data is indeed located in that offset in your _build/*.map file? This does not look like accepted syntax.

     

    If you need a section at a specific address offset, then I would recommend that you declare that section with its expected offset/size. You should also explicitly state to the linker that it should keep the region:

    KEEP(*(.user_flash_data*))

     

    Kind regards,

    Håkon

  • can you give the updated ld script.i don't have a detailed knowledge about it

  • Hii,

    The code always rebooting after the below partitioning..is there any mistake in partitioning ?Is there any modification in the softdevice part ?is there any need of modification?below given the partitioning

    MEMORY
    {
      FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0xd7000
      FLASH_REGS (rx) : ORIGIN = 0xfe000, LENGTH = 0x2000
      RAM (rwx) : ORIGIN = 0x20002b00, LENGTH = 0x33c00
      RAM_SPIM3 (rwx) : ORIGIN = 0x2003df00, LENGTH = 0x2000
      RAM_NOINIT (rwx) : ORIGIN = 0x2003ff00, LENGTH = 0x100
      CUSTOM_MEMORY (rwx) : ORIGIN = 0x7F000, LENGTH = 0x49000
    }

    SECTIONS
    {
    }

Reply
  • Hii,

    The code always rebooting after the below partitioning..is there any mistake in partitioning ?Is there any modification in the softdevice part ?is there any need of modification?below given the partitioning

    MEMORY
    {
      FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0xd7000
      FLASH_REGS (rx) : ORIGIN = 0xfe000, LENGTH = 0x2000
      RAM (rwx) : ORIGIN = 0x20002b00, LENGTH = 0x33c00
      RAM_SPIM3 (rwx) : ORIGIN = 0x2003df00, LENGTH = 0x2000
      RAM_NOINIT (rwx) : ORIGIN = 0x2003ff00, LENGTH = 0x100
      CUSTOM_MEMORY (rwx) : ORIGIN = 0x7F000, LENGTH = 0x49000
    }

    SECTIONS
    {
    }

Children
  • Hi,

    Attaching the latest ld file here. We tried flashing using this LD file. But when we are trying to write data into flash memory using the nrf_nvmc_write_word() API, the nRF is kept restarting.

    While reading on nRF forums, we came to know that, the nvmc APIs cannot be used if softdevice is enabled. They are suggesting using the API sd_flash_write() when the softdevice is enabled.

    So we tried with the API sd_flash_write. That API gave a return code of NRF_SUCCESS also. There is no specific API to read the data like a sd_flash_read(). So we tried using memcpy() to read data from that particular address. But it didn't give us the value we wrote.

    The nRF forums say we will get an event also when the sd_flash_write() completes, We are yet to verify thattemplate_gcc_nrf52.ld

    The functions are used for write and read in flash

    uint32_t wridata = 0x12;
    uint32_t ret = sd_flash_write((uint32_t *)0x7F000, &wridata, 4);
    if(ret == NRF_SUCECSS)
    {
    //print some success message
    }
    else
    {
    //print the value of ret
    }

    Try this to read from flash memory

    uint32_t read_value;
    memcpy(&read_value, 0x7F000, 4);
    Then print read_value

    we got read read_value is 0

  • Hi,

     

    Sadiya P said:

    The functions are used for write and read in flash

    uint32_t wridata = 0x12;
    uint32_t ret = sd_flash_write((uint32_t *)0x7F000, &wridata, 4);
    if(ret == NRF_SUCECSS)
    {
    //print some success message
    }
    else
    {
    //print the value of ret
    }

    Try this to read from flash memory

    uint32_t read_value;
    memcpy(&read_value, 0x7F000, 4);
    Then print read_value

    we got read read_value is 0

    You will have to wait for the callback, as the SoftDevice will schedule NVMC operations in between BLE connection events:

    https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/multilink_scheduling/flash_api_timing.html?cp=5_7_3_0_14_7

    See example ble_central/ble_app_hrs_c, main.c::soc_evt_handler for an example implementation.

    Sadiya P said:
    The nRF forums say we will get an event also when the sd_flash_write() completes, We are yet to verify thattemplate_gcc_nrf52.ld

    Your memory regions "FLASH" and "CUSTOM_MEMORY" overlap. You must align the length of "FLASH" to ensure it does not overlap with "CUSTOM_MEMORY" region.

     

    Kind regards,

    Håkon

  • Thanks for your reply.Is there any change  in bootloader section according to this custom flash ?

  • What you have shared is just a linker script, no information on what your firmware is supposed to do.

    Sadiya P said:
    change  in bootloader section according to this custom flash

    Which section are you asking about?

    If you also have the dfu/secure_bootloader in your project, you must ensure that it does not overlap with those address sections as well, mainly the "mbr_params_page" and "bootloader_settings_page".

     

    Kind regards,

    Håkon

  • No we didn't use the dfu/secure_bootloader in my project.

Related