Hi Alice,
Thank you very much for your interest and your quick response.
I'm sorry, but I think I don't understand the explanation "the lwsemaphores run quickly" and how can it affect in my case (I am novice developing in this platform).
On the other way, I can show anything when app crashes: how could I see anything? I can confirm the crash using breakpoints and also switching on/off the board's led (using different colors to debug). Could you suggest me any other tools or procedures to help me find what is happening? Any suggestions are welcome!.
The following are the relevant parts of my code for the named process (I can send you the code files you want, or even a zip with the complete project if you wish). These are the lines I have added in fsl_spi_master_driver.c:
// declare reference to callback
spi_transfer_done_cb_t transfer_done_cb = NULL;
// public function to set callback
void SPI_DRV_MasterSetTransferDoneCallback(spi_transfer_done_cb_t transfer_done)
{
transfer_done_cb = transfer_done;
}
static void SPI_DRV_MasterCompleteTransfer(uint32_t instance)
{
...
...
if (spiState->isTransferBlocking)
{
/* Signal the synchronous completion object */
OSA_SemaPost(&spiState->irqSync);
}
// I added the following call to callback function at this point
if (transfer_done_cb)
{
transfer_done_cb();
}
}
And this is the relevant code of my main file:
...
// SW3 button interrupt used to request a SPI write operation
static void MQX_PORTBCDE_IRQHandler(void);
static void npi_app_tl_packet_parser(void);
static void transfer_done_callback(void);
static tl_cbs_t npi_app_tl_cbs = {
npi_app_tl_packet_parser,
};
void Main_task(uint32_t param);
// The lower "Priority" field is, the higher is the actual priority.
const TASK_TEMPLATE_STRUCT MQX_template_list[] = {
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ MAIN_TASK, Main_task, 700, 20, "main", MQX_AUTO_START_TASK, 0, 0 },
{ 0 }
};
void Main_task(uint32_t param) {
hardware_init();
OSA_Init();
// SRDY / SW1 interrupt
switchPins[0].config.interrupt = kPortIntFallingEdge;
// SW3 button interrupt
switchPins[1].config.interrupt = kPortIntFallingEdge;
GPIO_DRV_Init(switchPins, ledPins);
GPIO_DRV_WritePinOutput(kGpioCSn, 1);
configure_spi_pins(SPI0_IDX);
// SW3 button interrupt
OSA_InstallIntHandler(PORTBCDE_IRQn, MQX_PORTBCDE_IRQHandler);
NVIC_SetPriority(PORTBCDE_IRQn, 6);
osa_status_t status = OSA_SemaCreate(&app_main_sem, 0);
if (status != kStatus_OSA_Success) {
printf("Error creating main app semaphore: %d\n", status);
return;
}
tl_init(&npi_app_tl_cbs, TRANSPORT_TX_DONE_EVT,
TRANSPORT_RX_EVT, SPI_SRDY_EVT);
SPI_DRV_MasterSetTransferDoneCallback(&transfer_done_callback);
for(;;) {
do {
status = OSA_SemaWait(&app_main_sem, OSA_WAIT_FOREVER);
} while(status == kStatus_OSA_Idle);
if (status != kStatus_OSA_Success) {
printf("Error: syncStatus: %d\n", status);
}
tl_handle_ISR_event();
if (events & SPI_START_WRITE_EVT) {
events &= ~SPI_START_WRITE_EVT;
npi_app_write();
}
}
}
static void MQX_PORTBCDE_IRQHandler(void) {
PORT_HAL_ClearPortIntFlag(PORTC_BASE_PTR);
events |= SPI_START_WRITE_EVT;
OSA_SemaPost(&app_main_sem);
}
static void transfer_done_callback(void) {
// Post the event to the task thread.
TX_DONE_ISR_EVENT_FLAG = transport_tx_done_event;
// App crashes when calling this function
OSA_SemaPost(&app_main_sem);
}
As you can guess from the code, I start the board, and then I use SW3 button interrupt to force a SPI write. This causes 270 bytes to be writed to the bus, and correctly received in the other side. The, when the SPI transfer is complete the transfer_done_cb() I have added is called.
Regards,
José Antonio Martínez