Hello All, the following code is generating a HardFault. I'm sure I've missed something stupid:
void Thread_Debug2(void const *argument) { // locals Debug_Struct * pDbgStrct = 0; osStatus Status = osOK; uint32_t Placements2 = 0; // Start while(1) { // disable irq __disable_irq(); // get message, here the hardfault occurs pDbgStrct = (Debug_Struct *)osMessageGet(MsgQueue_Debug1, 0).value.v; // enable irq __enable_irq(); // free memory Status = osPoolFree(MemPool_Debug1, pDbgStrct); // check status if(Status == osOK) { Placements2++; } } }
In my opinion, the osMessageGet should be able to get a message from a message queue even when no interrupt is activated...
Why do you disable the interrupts - because you think that osMessageGet() isn't thread-safe? What if osMessageGet() itself makes use of some interesting critical section?
I don't very much like:
pDbgStrct = (Debug_Struct *)osMessageGet(MsgQueue_Debug1, 0).value.v;
Isn't it good practice to validate the return value before you start making use of it? Shouldn't you always look at the status first?
www.keil.com/.../group___c_m_s_i_s___r_t_o_s___message.html
Next thing is if your queue is valid.
Wouldn't the Hard Fault, and the processor registers point you at exactly what it's objecting too?
If you understand what's faulting, it's a lot easier to determine why it's faulting.
Are you blowing out the stack?