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.

Thumb instruction set



I would like to use the Thumb instruction set (-mt und --code_state=16). But with these settings I get compiler errors:

"../src/hal/sys_intvecs.asm", ERROR!   at line 30: [E0200] Offset out of range, must be [-255,4095]
              ldr pc,[pc,#-0x1b0] ; [KEEP 32-BIT INS]
"../src/hal/sys_intvecs.asm", ERROR!   at line 31: [E0200] Offset out of range, must be [-255,4095]
              ldr pc,[pc,#-0x1b0] ; [KEEP 32-BIT INS]

If I change the compiler settings for the file sys_intvecs.asm: --code_state=32, then I get linker errors:
"../src/hal/sys_link.cmd", line 45: error #10099-D: placement fails for object
   ".intvecs", size 0x20 (page 0).  Available ranges:
   VECTORS      size: 0x20         unused: 0x20         max hole: 0x20    
    .intvecs : {} > VECTORS

The project only builds with the options -mt and --code_state=32, but according to the documentation these options are in conflict. How can I configure the project to use the Thumb instruction set?

 

  • Hi Daniel,

    We received your post and I will be moving it to our code composer studio support forum.

    I'm curious - do you want to use Thumb (old 16 bit ISA ala ARM7) or the higher performance and better code density Thumb-2 ISA enabled by ARM Cortex(tm) cores?

  • Hi Brian

    I would like to use the thumb 2 instruction set.

    Thanks, Daniel

  • Daniel,

    you got this Error because this instruction can't be assembled as an Thumb instruction.

    The Cortex-R4F as it is used on the Hercules devices is always in ARM mode if an exception occurs (Reset, IRQ, FIQ, ...).

    This means that all instructions in the interrupt vector table, have to be coded as an ARM instruction.

    So it is mandatory that this file is assembled with the ARM instruction set. You can achieve this with in two ways, you can either specify different build options for this file or you can add " .arm" in front of the instructions in the asm file (e.g. after the .sect statement).

    You also should use the ARM instruction set for all system files (c and asm), as otherwise the CPU has to perform an switch of the instruction set and this might lead into problems if the CPU registers are not initialized. For C function you can do this with the help of the CODE_STATE pragma, e.g.:

    #pragma CODE_STATE(_c_int00, 32)

    I’m pretty sure that the second error you reported occurs, because the Linker has to introduce a small part of code which does the switch from ARM to Thumb2 mode. Now this code has to be placed somewhere, but there is no space left in the .intvecs section.

     

    Best Regards,

    Christian

  • Daniel,

    I checked this again and figured out, that also every IRQ and FIQ has to be coded in ARM instruction set. This is because the Cortex-R4F core will be in ARM state after any exception.

    This means that you need to add at least the CODE_STAE pragma in front of every interrupt routine, for example:

    /* USER CODE BEGIN (38) */
    #pragma CODE_STATE(rtiCompare0Interrupt, 32)
    /* USER CODE END */
    #pragma INTERRUPT(rtiCompare0Interrupt, IRQ)
    void rtiCompare0Interrupt(void)
    {
        /* USER CODE BEGIN (39) */
        /* USER CODE END */
        rtiREG1->INTFLAG = 1U;
        rtiNotification(rtiNOTIFICATION_COMPARE0);
        /* USER CODE BEGIN (40) */
        /* USER CODE END */
    }

    But a function called in a interrupt routine like rtiNotification here can be coded in Thumb2, as the linker can add the necessary code for instruction set switching here.

     

    Best Regards,

    Christian