lpcware

global array is altered when CAN API initialization occurs

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by christianhdz on Tue Aug 11 14:50:17 MST 2015
I have an array of 256 bytes that is being modified when LPC_CCAN_API->init_can(&CanApiClkInitTable[0], TRUE) is executed. I don't want this array to be modified, I already initialized it after  the  Private types/enumerations/variables


#define TICKRATE_HZ1 (100) /* 1/TickRate_HZ = PERIOD MS, 20 ms */

#define TEST_CCAN_BAUD_RATE 500000

CCAN_MSG_OBJ_T msg_obj;

[color=#66f]uint8_t crc8table[256] = {
    0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53,
    0xE8, 0xF5, 0xD2, 0xCF, 0x9C, 0x81, 0xA6, 0xBB,
    0xCD, 0xD0, 0xF7, 0xEA, 0xB9, 0xA4, 0x83, 0x9E,
    0x25, 0x38, 0x1F, 0x02, 0x51, 0x4C, 0x6B, 0x76,
...};
[/color]

When I debug the program I observe that some of the values of my array are modified i.e. crc8table[0x6A], it is changed to ZERO. Other array elements are also changed to zero.

I observe that it happens when line LPC_CCAN_API->init_can(&CanApiClkInitTable[0], TRUE); is executed

int main(void)
{

uint32_t CanApiClkInitTable[2];
/* Publish CAN Callback Functions */
CCAN_CALLBACKS_T callbacks = {
CAN_rx,
CAN_tx,
CAN_error,
NULL,
NULL,
NULL,
NULL,
NULL,
};
SystemCoreClockUpdate();
Board_Init();

/* Enable and setup SysTick Timer at a periodic rate */
SysTick_Config(SystemCoreClock/ TICKRATE_HZ1);


baudrateCalculate(TEST_CCAN_BAUD_RATE, CanApiClkInitTable);

[color=#f00]LPC_CCAN_API->init_can(&CanApiClkInitTable[0], TRUE);[/color]
/* Configure the CAN callback functions */
LPC_CCAN_API->config_calb(&callbacks);


If I try restoring the values of the array to the original value, then I get a HARD_FAULT_HANDLER call.

Any idea why this is happening and how to avoid it?

I am using an LPC11C24 board, using lpcxpresso 7.9 and I based my program in the CCAN_ROM example from LPC_OPEN example.

Outcomes