Undefined Instruction Exception while calling Can_Write()

Hello,

I get the following error while calling Can_Write() in my application:

Exception 'Undefined Instruction' (0x1): Thread-Id=13f4005a(pth=b158a780), Proc-Id=13940046(pprc=b11012a0) 'app.exe', VM-active=13940046(pprc=b11012a0) 'app.exe'
PC=0021a735(app.exe+0x0020a735) RA=800f2be1(kernel.dll+0x0001ebe1) SP=01efe728, BVA=00000000

I initialize my app with these instructions:

#include "can.h"
if ((hCan = Can_Init(L"CAN1")) == NULL)
{
	return SETUP_ERROR;
}

Can_SetConfigInt(hCan, L"ioTx", ca_ioTx.GenericDefinition, StoreVolatile); // 55
Can_SetConfigInt(hCan, L"ioRx", ca_ioRx.GenericDefinition, StoreVolatile); // 63
Can_SetConfigInt(hCan, L"BitRateHz", wBaudrate * 1000, StoreVolatile);
Can_SetConfigInt(hCan, L"IstPriority", 12, StoreVolatile);
Can_SetConfigString(hCan, L"FilterFrameFormat", L"none", StoreVolatile);
Can_SetConfigString(hCan, L"FilterRemote", L"none", StoreVolatile);
Can_SetConfigInt(hCan, L"FilterID", 0x00, StoreVolatile);
Can_SetConfigInt(hCan, L"FilterMask", 0x00, StoreVolatile);
Can_SetConfigInt(hCan, L"Timeout", 1000, StoreVolatile);  

if (!Can_Open(hCan))
{
	hCan = hINVALID;
	Can_Deinit(hCan);
	return SETUP_ERROR;
}

I send a message with this code:

memcpy(s_TxCanMsgBuff.data, pBlock->byData, pBlock->byLen.X.DLC);
s_TxCanMsgBuff.dataLen = pBlock->byLen.X.DLC;
s_TxCanMsgBuff.id = pBlock->cobId.D;
s_TxCanMsgBuff.canMsgFlags = 0;

Can_Write(hCan, &s_TxCanMsgBuff);

Calling Can_Read() works fine. But if I call Can_Write() I get the error above.
The strange thing is, that I don’t get this error, if I use the example CAN project from toradex.
From there, I copied the initialisation part.
Also strange: the message is transmitted, then the error occurs.

Maybe you can help me solving this problem.

Thanks!

Kind regards

kuzco

Dear @Kuzco,

Overall code seems to be proper. Undefined instruction exception would occur due to wrong PC address and leads to correlate invalid instruction. Moreover, this would happen due to stack corruption.
Could you please share complete demo project or your application code with us. We need to verify other parts of the code in your application.

Thank you.

Dear raja,

thanks for your answer.
Giving you the whole project is not that easy, because the software is written by a supplier of us.
We only write extensions.
I have uploaded a example where I copied in as much as possible.
The whole project was already running with CE Libs 2.0.
But we need some features from 2.1.
Here you can download the project.

Dear @Kuzco,

In order to get maximum performance from the library, we haven’t implemented the synchronization object in the FlexCAN library. The Read thread and Write thread simultaneous accessing the CAN library API would be cause for this issue. I have implemented a synchronization object in your can demo application and tested it.
Also, please implement threads self-killing and Can_Deinit. It is missing in the sample code.

Thank you.