[MQX on K64] post a semaphore during an interrupt creates a hardfault

cancel
Showing results for 
Search instead for 
Did you mean: 

[MQX on K64] post a semaphore during an interrupt creates a hardfault

Jump to solution
781 Views
samuelboivineau
Contributor III

Hello,

 

I have tried to use most of the project sai_demo to test the SAI peripheral, but I have been stuck for a few days by a semaphore posted during an interrupt that creates a hardfault. The target is a K64F120M.

 

In fsl_soundcard.c, the function OSA_SemaPost(&buffer->sem) is used by SND_TxCallback, called by SND_TxDmaCallback, that is called by a DMA interrupt if my understanding is correct :

- EDMA_DRV_InstallCallback(&ctrl->dma_channel, SND_TxDmaCallback, (void *)card);

 

In the MQX documentation, I don't see anything about interrupt context.

And if I follow the post of the semaphore, then the sw goes to _lwsem_post, and sees that the semaphore is at 0, and a task is waiting for it, so the task is set ready and _CHECK_RUN_SCHEDULER is called. Then I jump into my HardFault_Handler, and I got those registers :

 

r0 = 0x1

r1 = 0x2000049c

r2 = 0x1

r3 = 0x1

r12 = 0x1fff0be0

lr = 0x30ab3          => in the code of _lwsem_wait_ticks, after _sched_execute_scheduler_internal and the result.

pc = 0x4b6               => instruction "bx lr"  in _sched_execute_scheduler_internal (defined by macro as _CHECK_RUN_SCHEDULER)

psr = 0x1000000

 

So is it ok to post a semaphore inside an interrupt ?

Maybe I have a missed some configuration ?

Currently I am doing some polling but it's not the aim for a rtos ...

What is also curious is the link register with a value with 3 at the end, there is no alignement required ? It would be some register over-written by someone ? but who ? And which stack or heap would be impacted ?

 

Thanks for your help

Labels (1)
1 Solution
396 Views
keetle
Contributor III

It means that your interrup function name should not be same as the CMSIS startup code file interrupt function name.

capture201511251001251.png

so your function name "DMA0_IRQHandler" etc are illegal.

you can modify the illegal function name like this:

void MQX_DMA0_IRQHandler(void)

{

    EDMA_DRV_IRQHandler(0);

}

after that, register interrupt function

_int_install_isr(DMA0_IRQn, (INT_ISR_FPTR)MQX_DMA0_IRQHandler, NULL);

after all,  it should be OK.:smileyhappy:

View solution in original post

0 Kudos
4 Replies
396 Views
keetle
Contributor III

I think you have met the same doubt I have before

I hope this link page will help you.

https://community.freescale.com/thread/379827

0 Kudos
396 Views
samuelboivineau
Contributor III

Hello,

Thanks for your answer, I've looked at the link, but I am using the irq functions of the example, so it doesn't seem to be an issue. And I don't see how can I change it. They are defined this way :

// DMA (0 to 15)

void DMA0_IRQHandler(void)

{

    EDMA_DRV_IRQHandler(0);

} [...]

// SAI

void I2S0_Tx_IRQHandler(void)

{

    SAI_DRV_TxIRQHandler(0U);

}

void I2S0_Rx_IRQHandler(void)

{

    SAI_DRV_RxIRQHandler(0U);

}

If anyone has an idea, let me know !

Regards

0 Kudos
397 Views
keetle
Contributor III

It means that your interrup function name should not be same as the CMSIS startup code file interrupt function name.

capture201511251001251.png

so your function name "DMA0_IRQHandler" etc are illegal.

you can modify the illegal function name like this:

void MQX_DMA0_IRQHandler(void)

{

    EDMA_DRV_IRQHandler(0);

}

after that, register interrupt function

_int_install_isr(DMA0_IRQn, (INT_ISR_FPTR)MQX_DMA0_IRQHandler, NULL);

after all,  it should be OK.:smileyhappy:

0 Kudos
394 Views
samuelboivineau
Contributor III

Hello,

Your solution solved the issue. Thanks a lot !

0 Kudos