Hi
I was able to create a very strange bug!
I’m using an ATSAMV71-XULT board with Atmel Studio 7 and FreeRTOS 10.0
I have a function (that I list below) that keeps sending a CAN message.
If I call this function outside a task of FreeRTOS it works fine.
However if I call it from a FreeRTOS task the data that comes out is corrupt, although when I follow the code with the debugger all seems well.
Obviously this is an impossible question, but any ideas what could be wrong or how I can gather more information?
One of the obvious culprits would be the stack of the FreeRTOS stack but that is set to 10000 bytes, so I don’t think that may be the one. Also I don’t see that many usage of the stack.
thanks
static uint8_t Txfinished = false;
void CAN_1_tx_callback_(struct can_async_descriptor *const descr)
{
Txfinished = true;
}
void CAN1test (void)
{
struct can_message msgTx;
can_async_register_callback(&CAN_1, CAN_ASYNC_TX_CB, (FUNC_PTR)CAN_1_tx_callback_);
can_async_enable(&CAN_1);
struct can_filter filter;
filter.id = 0; filter.mask = 0; // accept every CAN id
can_async_set_filter(&CAN_1, 0, CAN_FMT_EXTID, &filter);
msgTx.data = "ola";
msgTx.id = 0x4455;
msgTx.len = strlen(msgTx.data);
msgTx.type = CAN_TYPE_DATA;
msgTx.fmt = CAN_FMT_EXTID;
while(1)
{
Txfinished = false;
can_async_write(&CAN_1, &msgTx);
while (!Txfinished);
for(int i=0; i<10000000; i++);
can_async_enable(&CAN_1);
}
}
int main_CSPv71(void)
{
NVIC_SetPriority ( UART1_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
NVIC_SetPriority ( MCAN1_INT0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
NVIC_SetPriority ( MCAN1_INT1_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
void CAN1test (void);
CAN1test(); **<<== Here it works fine!**
if ( xTaskCreate ( main_CSP_task, "main_CSP_task", TASK_STACK_SIZE, NULL, TASK_PRIORITY, main_CSP_task_TH ) != pdPASS )
while(1);
static void main_CSP_task(void *p)
{
void CAN1test (void);
CAN1test(); **<<== Here it does not work, corrupt data comes out, but the debugger shows valid data**