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.
(I think that, Cortex-M3 has NVIC.)
Maybe see this:
RealView Compiler User Guide -> Restrictions on inline assembly operations -> Thumb instruction set
http://www.keil.com/support/man/docs/armcc/armcc_Chdgddcj.htm
If you want to include inline assembly in a source file that contains code to be compiled for Thumb, enclose the functions containing inline assembler code between #pragma arm and #pragma thumb statements. For example:
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?
Please make sure that, the code you found from Internet, is written for KEIL Toolchain. I guess that, the inline assembly code you posted is written for IAR or GNU Toolchain.
Ooops.. my fault..
"I guess that, the inline assembly code you posted is written for IAR or GNU Toolchain."
No need to even guess - it is clearly stated:
// Note that this works as-is in IAR 5.20, but could have a different syntax // in other compilers. //****************************************************
When downloading stuff from the net, it is important that you take time to understand what you have got!
Are you sure that this code is for a Cortex-M3?
Is using printf in a Hard Fault handler really a good idea...?
I was just testing a piece of code found on the forum ST's STM32 section. I know that is not good to use printf in hard fault section, but it was only a test. However, I find the code for Keil, who still gives me other errors, but I think I'm going OT.