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