This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432E401Y: Assembly code ORG directive

Part Number: MSP432E401Y

I'm trying to place some ARM assembly code in a particular location in memory.  I've always been able to do this with an ORG directive when I was coding in non-ARM assembly.  When I do a google search it looks like I should also be able to use this directive in ARM assembly, but when I try either of these:

   org 0x0000800

   .org 0x0000800

I get compilation errors.

Can anyone tell me what I need to do in order to place my ARM assembly instructions at a particular place in memory?

Thank you.

  • I think a typical solution would be to use a section directive in your assembler file, then in the linker .cmd file, place that section where you want it.
    e.g. In the gpiointerrupt_MSP_EXP432E401Y_nortos_ccs, example, the MSP_EXP432E401Y_NoRTOS.cmd file has:

    ...
    MEMORY
    {
        FLASH (RX) : origin = 0x00000000, length = 0x00100000
        SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    }
    
    /* Section allocation in memory */
    
    SECTIONS
    {
        .text   :   > FLASH
        .const  :   > FLASH
        .rodata :   > FLASH
        .cinit  :   > FLASH
        .pinit  :   > FLASH
        .init_array : > FLASH
    
        .vtable :   > RAM_BASE
        .TI.ramfunc : {} load=FLASH, run=SRAM, table(BINIT)
        .data   :   > SRAM
        .bss    :   > SRAM
        .sysmem :   > SRAM
        .stack  :   > SRAM (HIGH)
    
        .intvecs :  > 0x00000000
    }
    ...

    Here, most code is in the .text section and .cinit is another code section, but they are all located in the FLASH area.

    You could define a special MYFLASH at the required location, the place .mysection in it.

  • I found the .cmd file in my project and it looks similar to the one you show, but it's not clear to me at all how I can define a special MYFLASH at the required location and/or how to place .mysection in it.

    Could you show an example of what you are suggesting?  What command would I put in the .cmd file and where would it be located.  Also, what command should I put the assembly file to tell it I want it loaded at that particular location.

    Thank you

  • Hi,

    I think you just enter the memory blocks you need. e.g. In the gpiointerrupt sample project, I moved .const and .rodata to MYFLASH like this:

    ...
    MEMORY
    {
        FLASH (RX)   : origin = 0x00000000, length = 0x00003000
        MYFLASH (RX) : origin = 0x00003000, length = 0x00001000
        SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    }
    
    /* Section allocation in memory */
    
    SECTIONS
    {
        .text   :   > FLASH
        .const  :   > MYFLASH
        .rodata :   > MYFLASH
        .cinit  :   > FLASH
        .pinit  :   > FLASH
        .init_array : > FLASH
    
        .vtable :   > RAM_BASE
        .TI.ramfunc : {} load=FLASH, run=SRAM, table(BINIT)
        .data   :   > SRAM
        .bss    :   > SRAM
        .sysmem :   > SRAM
        .stack  :   > SRAM (HIGH)
    
        .intvecs :  > 0x00000000
    }
    ...

    It still seems to work Slight smile

    To put some assembler in its own section - the bootloader example includes bl_startup_ccs.s which has:

    ...
    ;;*****************************************************************************
    ;;
    ;; This portion of the file goes into interrupt vectors section
    ;;
    ;;*****************************************************************************
        .sect ".intvecs"
    
    ;;*****************************************************************************
    ;;
    ;; The minimal vector table for a Cortex-M3 processor.
    ;;
    ;;*****************************************************************************
    Vectors:
        .ref    __STACK_TOP
        .word   __STACK_TOP                   ;; Offset 000: Initial stack pointer
        .word   ResetISR - 0x20000000         ;; Offset 004: Reset handler
        .word   NmiSR - 0x20000000            ;; Offset 008: NMI handler
        .word   FaultISR - 0x20000000         ;; Offset 00C: Hard fault handler
        .word   IntDefaultHandler             ;; Offset 010: MPU fault handler
        .word   IntDefaultHandler             ;; Offset 014: Bus fault handler
        .word   IntDefaultHandler             ;; Offset 018: Usage fault handler
        .word   0                             ;; Offset 01C: Reserved
        .word   0                             ;; Offset 020: Reserved
    ...

    so the 

    .sect "section_name" seems to be the magic!

    (You may guess that I'm no expert - done this on other platforms and adding some guesswork for TI)

    Hope this helps.

    Jim

  • I tried various values for the border of FLASH and MYFLASH and got compilation errors each time.  There either wasn't enough memory allocated for FLASH or, if I did allocate enough memory for flash my assembly code had errors because it had been pushed too high in memory.

    What I really need is some way of placing my code in a specific location in FLASH.  There is plenty of room for it there and I'm hoping I can find a way to put it in a specific there.

  • I think you have a few options Slight smile

    You could divide the flash into as many pieces as you need. You could even have one for for every section if you really need, but that would be hard work because you would have to manually adjust all the boundaries and sizes every time you made a change - much easier to let the linker do it! So, you could have:

    LOW_FLASH

    SPECIAL_FLASH

    REST_OF_FLASH

    Or

    In the gpiointerrupt example, you will see that that interrupt vectors section is specifically placed at address zero as it needs to be there and not just anywhere in FLASH:-

    ...

    .stack : > SRAM (HIGH)

    .intvecs : > 0x00000000
    }

    It should be possible to do the same with your special section - in which case, you just need the one FLASH memory definition you started with.

    The linker should see a big chunk of space called FLASH, where it has to place most sections, but also special requirements to place intvecs at 0 and BradsSection at xyz, then it will just jiggle the remaining sections into the gaps.

    Hope that helps

    Jim

  • I think I got it working.  I defined my own flash at 00000000 to 0000FFFF and put the system flash at 00010000 to 00100000.

    I was concerned there would be a problem because execution will start at 00000000, but when I ran my project it ran ok.  I put a breakpoint at the beginning of my code and it was located at 00000208 so it looks like the system put the necessary instructions below that point.  I'm ok with my code starting at 00000208 as long as it starts at the same place each time.

    Thank you for your assistance and your patience.