Hi there,
We are using cortex M0 uC. We need to recognize at our code whether or not the debugger is attached. We have found after a lot of search and effort that we cannot use CoreDebug->DHCSR with cortex M0.
We have found a different approach using the HardFault exception and software breakpoint that indirect recognize if the debugger is attached.
In this approach using assembly if a hardware exception occurs due to a breakpoint then no debugger is attach and the HardFault exception return to the program skipping the breakpoint instruction.
Below is the assembly code we have found and slightly changed:
__asm("MOVS R0, #4"); __asm("MOV R1, __return_address()"); __asm("TST R0, R1"); __asm("BEQ _MSP"); __asm("MRS R0, PSP"); __asm("B _checkFaultInstruction"); __asm("_MSP: "); __asm("MRS R0, MSP"); __asm("_checkFaultInstruction: "); __asm("LDR R1, [R0,#24]"); __asm("LDRH R2, [R1]"); __asm("LDR R3,=0xBEAB"); __asm("CMP R2, R3"); __asm("BNE HardFault_HandlerC "); __asm("ADDS R1, #2"); __asm("STR R1, [R0,#24]"); __asm("BX __return_address()");
The compiler is throwing the follows errors:
1) __asm("LDR R3,=0xBEAB"); -> error #29: expected an expression We have replaced this instruction with: __asm("MOV R3, 0xBEAB"); Does this instruction has the same effect?
2) __asm("BX __return_address()"); -> error #1084: This instruction not permitted in inline assembler. How can we replace this unsupported instruction?
3) __asm("BNE HardFault_HandlerC "); -> error #114:label "HardFault_HandlerC" was reference but not defined HardFault_HandlerC is a function name 4) __asm("BX __return_address()"); -> error #114:label "..." was reference but not defined
What is wrong with 3 and 4?
Thanks in advance.
According to the following link our replacement to the first error is ok. infocenter.arm.com/.../index.jsp
any ideas for the rest ones?