This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

inline assembler not permitted in thumb code

I am working with LPC1768 with Keil realview MDK ARM V4.01.
When iam using "__asm" keyword in my code for IENABLE,IDISABLE macros (to switch between sys mode and irq mode), it is generating a compilation error as "Inline assembler not permitted when generating Thumb code".
these two macros i wish to use.
#define IENABLE __asm { MRS sysreg, SPSR; MSR CPSR_c, #SYS32Mode }//__asm { MRS sysreg, SPSR; MSR CPSR_c, #SYS32Mode }
#define IDISABLE __asm { MSR CPSR_c, #(IRQ32Mode|I_Bit); MSR SPSR_cxsf, sysreg }

please suggest regarding this.

Parents
  • Hi, I'm trying to compile this code on a cortex m3 device.

    /*******************************************************************************
    * Function Name : HardFaultException
    * Description : This function handles Hard Fault exception.
    * Input : None
    * Output : None
    * Return : None
    *******************************************************************************/
    #pragma arm
    void HardFaultException(void)
    {
    //Big thanks to joseph.yiu for this handler. This is simply an adaptation of:
    //www.st.com/.../forums-cat-6778-23.html
    //****************************************************
    //To test this application, you can use this snippet anywhere:
    // //Let's crash the MCU!
    // asm (" MOVS r0, #1 \n"
    // " LDM r0,{r1-r2} \n"
    // " BX LR; \n");
    // Note that this works as-is in IAR 5.20, but could have a different syntax
    // in other compilers.
    //****************************************************
    // hardfault_args is a pointer to your stack. you should change the adress
    // assigned if your compiler places your stack anywhere else!
    
    unsigned int stacked_r0;
    unsigned int stacked_r1;
    unsigned int stacked_r2;
    unsigned int stacked_r3;
    unsigned int stacked_r12;
    unsigned int stacked_lr;
    unsigned int stacked_pc;
    unsigned int stacked_psr;
    u32* hardfault_args = (u32*) 0x20000400;
    
    __asm( "TST LR, #4 \n"
    "ITE EQ \n"
    "MRSEQ R0, MSP \n"
    "MRSNE R0, PSP \n");
    
    stacked_r0 = ((unsigned long) hardfault_args[0]);
    stacked_r1 = ((unsigned long) hardfault_args[1]);
    stacked_r2 = ((unsigned long) hardfault_args[2]);
    stacked_r3 = ((unsigned long) hardfault_args[3]);
    
    stacked_r12 = ((unsigned long) hardfault_args[4]);
    stacked_lr = ((unsigned long) hardfault_args[5]);
    stacked_pc = ((unsigned long) hardfault_args[6]);
    stacked_psr = ((unsigned long) hardfault_args[7]);
    
    printf ("[Hard fault handler]\n");
    printf ("R0 = %x\n", stacked_r0);
    printf ("R1 = %x\n", stacked_r1);
    printf ("R2 = %x\n", stacked_r2);
    printf ("R3 = %x\n", stacked_r3);
    printf ("R12 = %x\n", stacked_r12);
    printf ("LR = %x\n", stacked_lr);
    printf ("PC = %x\n", stacked_pc);
    printf ("PSR = %x\n", stacked_psr);
    printf ("BFAR = %x\n", (*((volatile unsigned long *)(0xE000ED38))));
    printf ("CFSR = %x\n", (*((volatile unsigned long *)(0xE000ED28))));
    printf ("HFSR = %x\n", (*((volatile unsigned long *)(0xE000ED2C))));
    printf ("DFSR = %x\n", (*((volatile unsigned long *)(0xE000ED30))));
    printf ("AFSR = %x\n", (*((volatile unsigned long *)(0xE000ED3C))));
    
    /* Turn on the Alarm KeyLed */
    I2C1_SetKeyLed(KEY_LED_ALL);
    while (1)
    {}
    
    }
    #pragma thumb
    
    

    I've added "--apcs=/interwork" to my compiler option but I gave this error:

    ..\src\stm32f10x_it.c(56): error:  #1114-D: this feature not supported on target architecture/processor
    ..\src\stm32f10x_it.c(83): error:  #1113: Inline assembler not permitted when generating Thumb code
    

    what else should I do?

Reply
  • Hi, I'm trying to compile this code on a cortex m3 device.

    /*******************************************************************************
    * Function Name : HardFaultException
    * Description : This function handles Hard Fault exception.
    * Input : None
    * Output : None
    * Return : None
    *******************************************************************************/
    #pragma arm
    void HardFaultException(void)
    {
    //Big thanks to joseph.yiu for this handler. This is simply an adaptation of:
    //www.st.com/.../forums-cat-6778-23.html
    //****************************************************
    //To test this application, you can use this snippet anywhere:
    // //Let's crash the MCU!
    // asm (" MOVS r0, #1 \n"
    // " LDM r0,{r1-r2} \n"
    // " BX LR; \n");
    // Note that this works as-is in IAR 5.20, but could have a different syntax
    // in other compilers.
    //****************************************************
    // hardfault_args is a pointer to your stack. you should change the adress
    // assigned if your compiler places your stack anywhere else!
    
    unsigned int stacked_r0;
    unsigned int stacked_r1;
    unsigned int stacked_r2;
    unsigned int stacked_r3;
    unsigned int stacked_r12;
    unsigned int stacked_lr;
    unsigned int stacked_pc;
    unsigned int stacked_psr;
    u32* hardfault_args = (u32*) 0x20000400;
    
    __asm( "TST LR, #4 \n"
    "ITE EQ \n"
    "MRSEQ R0, MSP \n"
    "MRSNE R0, PSP \n");
    
    stacked_r0 = ((unsigned long) hardfault_args[0]);
    stacked_r1 = ((unsigned long) hardfault_args[1]);
    stacked_r2 = ((unsigned long) hardfault_args[2]);
    stacked_r3 = ((unsigned long) hardfault_args[3]);
    
    stacked_r12 = ((unsigned long) hardfault_args[4]);
    stacked_lr = ((unsigned long) hardfault_args[5]);
    stacked_pc = ((unsigned long) hardfault_args[6]);
    stacked_psr = ((unsigned long) hardfault_args[7]);
    
    printf ("[Hard fault handler]\n");
    printf ("R0 = %x\n", stacked_r0);
    printf ("R1 = %x\n", stacked_r1);
    printf ("R2 = %x\n", stacked_r2);
    printf ("R3 = %x\n", stacked_r3);
    printf ("R12 = %x\n", stacked_r12);
    printf ("LR = %x\n", stacked_lr);
    printf ("PC = %x\n", stacked_pc);
    printf ("PSR = %x\n", stacked_psr);
    printf ("BFAR = %x\n", (*((volatile unsigned long *)(0xE000ED38))));
    printf ("CFSR = %x\n", (*((volatile unsigned long *)(0xE000ED28))));
    printf ("HFSR = %x\n", (*((volatile unsigned long *)(0xE000ED2C))));
    printf ("DFSR = %x\n", (*((volatile unsigned long *)(0xE000ED30))));
    printf ("AFSR = %x\n", (*((volatile unsigned long *)(0xE000ED3C))));
    
    /* Turn on the Alarm KeyLed */
    I2C1_SetKeyLed(KEY_LED_ALL);
    while (1)
    {}
    
    }
    #pragma thumb
    
    

    I've added "--apcs=/interwork" to my compiler option but I gave this error:

    ..\src\stm32f10x_it.c(56): error:  #1114-D: this feature not supported on target architecture/processor
    ..\src\stm32f10x_it.c(83): error:  #1113: Inline assembler not permitted when generating Thumb code
    

    what else should I do?

Children