global array is altered when CAN API initialization occurs

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

global array is altered when CAN API initialization occurs

4,718 Views
lpcware
NXP Employee
NXP Employee
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.
Labels (1)
0 Kudos
Reply
7 Replies

4,686 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by christianhdz on Mon Aug 17 13:44:04 MST 2015
Indeed! Thanks! This solved the issue.

#include "board.h"
#include "cr_section_macros.h"

/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/

#define TEST_CCAN_BAUD_RATE 500000

//reserve CAN ROM-RAM 0x1000 0050 - 0x1000 00B9
__BSS(RESERVED) char CAN_driver_memory[0xC0];

CCAN_MSG_OBJ_T msg_obj;
...
0 Kudos
Reply

4,686 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Mon Aug 17 11:27:08 MST 2015

Quote: christianhdz
Is there something I am missing?



Yes, section macros 

#include "board.h"
[color=#f00]#include "cr_section_macros.h"[/color]

/*****************************************************************************
 * Private types/enumerations/variables
 ****************************************************************************/

#define TEST_CCAN_BAUD_RATE 500000
[color=#f00]
//reserve CAN ROM-RAM 0x1000 0050 - 0x1000 00B9
__BSS(RESERVED) char CAN_driver_memory[0xC0];
[/color]
CCAN_MSG_OBJ_T msg_obj;
...
0 Kudos
Reply

4,686 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by christianhdz on Mon Aug 17 10:52:26 MST 2015
I am using the CCAN_ROM example included in lpcopen_v2_00a_lpcxpresso_nxp_lpcxpresso_11c24.zip

I tried to use the suggested macro call as follows:

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,
};

//reserve CAN ROM-RAM 0x1000 0050 - 0x1000 00B9
[color=#66f]__BSS(RESERVED) char CAN_driver_memory[0xC0];[/color]

       SystemCoreClockUpdate();
Board_Init();

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

baudrateCalculate(TEST_CCAN_BAUD_RATE, CanApiClkInitTable);

LPC_CCAN_API->init_can(&CanApiClkInitTable[0], TRUE);
/* Configure the CAN callback functions */
LPC_CCAN_API->config_calb(&callbacks);
/* Enable the CAN Interrupt */
NVIC_EnableIRQ(CAN_IRQn);




But I get a bunch of errors with the addition of that line:
[list]
  [*]'RESERVED' undeclared (first use in this function)
  [*]expected ';' before 'char'
  [*]make: *** [example/src/ccan_romIGNSWITCH.o] Error 1
[*]
[/list]

Is there something I am missing?

Thanks for your support
0 Kudos
Reply

4,686 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Aug 13 14:54:41 MST 2015

Quote: christianhdz
I used the "static" modification but the ARRAY is still modified.



I'm not sure which sample you are using in detail, so it could be useful to post it 

Either you didn't reserve CAN RAM as described in:

https://www.lpcware.com/content/forum/how-to-reserve-lpc11cxx-ram

or your linker is removing your unused array as explained in:

https://embeddedfreak.wordpress.com/2009/02/10/removing-unused-functionsdead-codes-with-gccgnu-ld/

Since your array is stored in 0x1000 006B that's the RAM area which should be reserved for CAN API 

So adding a simple:

//reserve CAN ROM-RAM 0x1000 0050 - 0x1000 00B9
__BSS(RESERVED) char CAN_driver_memory[0xC0];


should solve your problem 
0 Kudos
Reply

4,686 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by christianhdz on Thu Aug 13 14:38:42 MST 2015
I used the "static" modification but the ARRAY is still modified.
See the attached pictures before and after the execution of line where CAN is initialized.

[color=#f0f]LPC_CCAN_API->init_can(&CanApiClkInitTable[0], TRUE);[/color]

the attached show the example where crc8table[0x6B]=0x5B, and then it is modified (unintentedly) to  crc8table[0x6B]=0x00 (highlighted in yellow in the expressions window).
0 Kudos
Reply

4,686 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DF9DQ on Wed Aug 12 01:19:45 MST 2015
Could it be that the array occupies the RAM region that should have been reserved for use by the CAN ROM drivers?
Quoting the user manual:

Quote:
On-chip RAM from address 0x1000 0050 to 0x1000 00B8 is used by the CAN API. This address range should not be used by the application. For applications using the on-chip CAN API, the linker control file should be modified appropriately to prevent usage of this area for application’s variable storage.

0 Kudos
Reply

4,686 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Aug 11 16:27:14 MST 2015

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



Use:

static uint8_t crc8table[256] = ...
0 Kudos
Reply