How do I use macros in section placement files, and what can I do with them?

Comments

5 comments

  • Avatar
    Michael Johnson

    In the placement file the start attribute is set to a conditional macro value

      <MemorySegment name="FLASH">
        <ProgramSection start="$(FLASH_START:)" alignment="0x100" load="Yes" inputsections="*(.vectors .vectors.*)" name=".vectors"/>

    The Linker Options | Section Placement Macros property can define the macro

    FLASH_START=0x1000

    Which makes the vectors section locate to 0x1000 etc

    0
    Comment actions Permalink
  • Avatar
    Darcy Williams

    Brilliant, that's a nice easy way to reserve space for a bootloader.  Thanks

    0
    Comment actions Permalink
  • Avatar
    Darcy Williams

    Hi Michael, can I then access that same macro definition from within code to allow me to offset vector tables - I didn't seem to be able to - although the method above worked like a charm.  Definining that offset in just one location would be best - although I could create a second definition (pre-processor) if I really had to (although that leads to issues if only one were to be updated).

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    The startup code will map the _vectors for you

      /* Configure vector table offset register */
      ldr r0, =0xE000ED08
      ldr r1, =_vectors
      str r1, [r0]

    You can use the linker symbols that are created for the memory sections for example and also in the startup code

    #ifdef __VECTORS_IN_RAM
      ldr r0, =__vectors_load_start__
      ldr r1, =__vectors_load_end__
      ldr r2, =_vectors
    l0:
      cmp r0, r1
      beq l1
      ldr r3, [r0], #4
      str r3, [r2], #4
      b l0
    l1:
    #endif

    Regards

    Michael

    0
    Comment actions Permalink
  • Avatar
    Darcy Williams

    Thanks Michael,  I'm using the STM32 FWLib but the example above pointed out something really obvious that I wasn't seeing.  I can achieve the same thing by using the section placement macros to offset the start of flash, then use (__vectors_start__ - __FLASH_segment_start__) to pass in to the NVIC_SetVectorTable routine (configures the VTOR register) to achieve the desired offset.  So, that'll be 0 for our devices that don't use the bootloader, and something else for those that do.  Much appreciated

    0
    Comment actions Permalink

Please sign in to leave a comment.