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

osMessageGet causes HardFault when IRQ disabled

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...

Parents
  • Hello Again,

    Thanks to all of your replies. I've updated the thread/function:

    void Thread_Debug2(void const *argument)
    {
            // locals
            Debug_Struct * pDbgStrct = 0;
            osEvent evt;
            uint32_t i = 0;
            volatile uint32_t Dummy = 0;
    
            // Start
            while(1)
            {
                    // check for message
                    evt = osMessageGet(MsgQueue_Debug1, 0);
    
                    // message received?
                    if(evt.status == osEventMessage)
                    {
                            // message received, get data
                            pDbgStrct = (Debug_Struct *)evt.value.p;
    
                            // do something with the data
                            Dummy = pDbgStrct->Temp1 + pDbgStrct->Temp2 + pDbgStrct->Temp3;
    
                            // free the memory block
                            osPoolFree(MemPool_Debug1, pDbgStrct);
                    }
    
                    // do some other things (no os delay)
                    for(i = 0; i < 123456;i++)
                    {
                            __NOP();
                    }
            }
    }
    

    You might noticed, that I've posted another Question the other day about a mailbox overflow

    http://www.keil.com/forum/60328

    This is my main problem so I've started to search otherwise and found the problem above. I thought, that this might be some reason of my problem, but no it isn't...

    Has anyone a Idea what can go wrong when receiving messages like above? Down here is the function where I put the messages:

    void Thread_Debug1(void const *argument)
    {
            // locals
            Debug_Struct * pDbgStrct = 0;
            osStatus Status = osOK;
            uint32_t i = 0;
    
            // Start
            while(1)
            {
                    // allocate memory
                    pDbgStrct = (Debug_Struct *)osPoolCAlloc(MemPool_Debug1);
    
                    // check for memory block
                    if(pDbgStrct != 0)
                    {
                            // fill structure
                            pDbgStrct->Temp1 = 0xAB;
                            pDbgStrct->Temp2 = 0xCDEF;
                            pDbgStrct->Temp3 = 0x01234567;
    
                            // put it in queue
                            Status = osMessagePut(MsgQueue_Debug1, (uint32_t)pDbgStrct, 0);
    
                            // check status
                            if(Status == osOK)
                            {
                                    // message successful placed
                            }
                            else
                            {
                                    // message not placed in queue, free memory
                                    osPoolFree(MemPool_Debug1, pDbgStrct);
                            }
                    }
    
                    // do some other things (no os delay)
                    for(i = 0; i < 123456;i++)
                    {
                            __NOP();
                    }
            }
    }
    

Reply
  • Hello Again,

    Thanks to all of your replies. I've updated the thread/function:

    void Thread_Debug2(void const *argument)
    {
            // locals
            Debug_Struct * pDbgStrct = 0;
            osEvent evt;
            uint32_t i = 0;
            volatile uint32_t Dummy = 0;
    
            // Start
            while(1)
            {
                    // check for message
                    evt = osMessageGet(MsgQueue_Debug1, 0);
    
                    // message received?
                    if(evt.status == osEventMessage)
                    {
                            // message received, get data
                            pDbgStrct = (Debug_Struct *)evt.value.p;
    
                            // do something with the data
                            Dummy = pDbgStrct->Temp1 + pDbgStrct->Temp2 + pDbgStrct->Temp3;
    
                            // free the memory block
                            osPoolFree(MemPool_Debug1, pDbgStrct);
                    }
    
                    // do some other things (no os delay)
                    for(i = 0; i < 123456;i++)
                    {
                            __NOP();
                    }
            }
    }
    

    You might noticed, that I've posted another Question the other day about a mailbox overflow

    http://www.keil.com/forum/60328

    This is my main problem so I've started to search otherwise and found the problem above. I thought, that this might be some reason of my problem, but no it isn't...

    Has anyone a Idea what can go wrong when receiving messages like above? Down here is the function where I put the messages:

    void Thread_Debug1(void const *argument)
    {
            // locals
            Debug_Struct * pDbgStrct = 0;
            osStatus Status = osOK;
            uint32_t i = 0;
    
            // Start
            while(1)
            {
                    // allocate memory
                    pDbgStrct = (Debug_Struct *)osPoolCAlloc(MemPool_Debug1);
    
                    // check for memory block
                    if(pDbgStrct != 0)
                    {
                            // fill structure
                            pDbgStrct->Temp1 = 0xAB;
                            pDbgStrct->Temp2 = 0xCDEF;
                            pDbgStrct->Temp3 = 0x01234567;
    
                            // put it in queue
                            Status = osMessagePut(MsgQueue_Debug1, (uint32_t)pDbgStrct, 0);
    
                            // check status
                            if(Status == osOK)
                            {
                                    // message successful placed
                            }
                            else
                            {
                                    // message not placed in queue, free memory
                                    osPoolFree(MemPool_Debug1, pDbgStrct);
                            }
                    }
    
                    // do some other things (no os delay)
                    for(i = 0; i < 123456;i++)
                    {
                            __NOP();
                    }
            }
    }
    

Children