spflanze wrote on Sunday, March 13, 2016:
The instruction at SVC_Handler+6 is a psuedo code. Which means there is more going on there than a single opcode.
I have noticed that when the breakpoint at SVC_Handler+0 is hit, and I do not go into Instruction Stepping Mode there as I had in the above code, and do a Step Over (F5), it advances to StartThreadUART_Rx+0, where there is a call to HardFault().
The relevant part of the C source code for StartThreadUART_Rx is pasted below:
void StartThreadUART_Rx(void const * argument)
{ uint8_t rxchar
BaseType_t xQueueReceiveResult;
for(;;)
{ xQueueReceiveResult = xQueueReceive( QueueUART_RxHandle, (void *)&rxchar, portMAX_DELAY );
.....
} }
The statements that creates the thread and the queue elsewhere in the firmware are:
osThreadDef( ThreadUART_Rx, StartThreadUART_Rx, osPriorityNormal, 0, 512);
ThreadUART_RxHandle = osThreadCreate(osThread(ThreadUART_Rx), NULL);
/* definition and creation of QueueUART_Rx */
osMessageQDef(QueueUART_Rx, 10, uint8_t );
QueueUART_RxHandle = osMessageCreate(osMessageQ(QueueUART_Rx), NULL);
When stepping through C source code the HardFault() is called in the statement where xQueueReceive() is called. When stepping through the assembly code pasted below the call to HardFault() is called when the instruction at StartThreadUART_Rx+14 is executed.
StartThreadUART_Rx:
08001ea4: StartThreadUART_Rx+0 push {r4, lr}
08001ea6: StartThreadUART_Rx+2 sub sp, #8
08001ea8: StartThreadUART_Rx+4 sub.w r3, sp, #12224 ; 0x2fc0
08001eac: StartThreadUART_Rx+8 movs r2, #0
08001eae: ...tThreadUART_Rx+10 str.w r2, [r3, #-60]
159 { xQueueReceiveResult = xQueueReceive( QueueUART_RxHandle, (void *)&rxchar, portMAX_DELAY );
08001eb2: ...tThreadUART_Rx+14 ldr r4, [pc, #128] ; (0x8001f34 <StartThreadUART_Rx+144>)
08001eb4: ...tThreadUART_Rx+16 movs r3, #0
08001eb6: ...tThreadUART_Rx+18 mov.w r2, #4294967295
08001eba: ...tThreadUART_Rx+22 add.w r1, sp, #7
08001ebe: ...tThreadUART_Rx+26 ldr r0, [r4, #0]
08001ec0: ...tThreadUART_Rx+28 bl 0x80068d4 <xQueueGenericReceive>
The value at StartThreadUART_Rx+144 is:
08001f34: ...ThreadUART_Rx+144 ; <UNDEFINED> instruction: 0x47ec
When the call to HardFault() happens this message appears in the console:
Info : halted: PC: 0x08001eac
Info : halted: PC: 0x08001eae
Info : halted: PC: 0x08001eb2
Info : halted: PC: 0x08000280
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, GDB will be halted. Polling again in 100ms
Info : Previous state query failed, trying to reconnect
Polling target stm32f3x.cpu succeeded again, trying to reexamine
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
All this is doing is loading the value 0x47ec into r4 and that causes a call to HardFault(). The ST-Link V2 gets disconnected, but it seems it automaically reconnects. How could the instruction at StartThreadUART_Rx+14 create a Hard Fault?