LPC1227 Hard Fault when reading value from pointer with valid address

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC1227 Hard Fault when reading value from pointer with valid address

2,320件の閲覧回数
miloskrizan
Contributor I

Hi all,

I working on project with LPC1227. My application using many of libraries, previously created on linux.
These libraries were previously compiled and used on LPC1768 based project.
Now I have compiled these libraries for LPC1227.
When I run my test application, application will be stopped and stay dead.
I have debug, where is problem.

Problem occure when start condition with reading value of pointer *crc:

if(*crc == crc_calculated)  // Do this, will trigger HardFault_Handler(void) in cr_startup_lpc12xx.c file
{
    ...

All parts of used code are here:

typedef struct _ANB_SESSION_
{
    ...
    uint8_t rx_buff[40];
    ...
}
ANB_SESSION;

ANB_SESSION *anb_session;
uint16_t *crc;

crc = (uint16_t *)&(anb_session -> rx_buff[anb_session -> first_byte_datagram_index + sizeof(ANB_DATAGRAM_HEADER) + anb_datagram_header->Len]);

if(*crc == crc_calculated)  // Do this, will trigger HardFault_Handler(void) in cr_startup_lpc12xx.c file
{
    ...
}

Index of rx_buff in assignment is 28 and rx_buff is 40 bytes long.

Address filled in pointer crc is 0x10000329 and pointed value is 32292 decimal.
Local variable crc_calculated has same value (32292). Type of local variable crc_calculated is uint16_t.

When I click with cursor in debugger on variables in condition, displayed values are correct.
After do condition, then will be triggered HardFault_Handler.

I still using LPCxpresso v7.6.2 [Build 326] [2015-02-02] for LPC1227 and before LPC1768.

All libraries are only precompiled from LPC1768 to LPC1227 and used equaly.

Thank you for your help

Milos

ラベル(1)
0 件の賞賛
返信
5 返答(返信)

1,938件の閲覧回数
miloskrizan
Contributor I

Hi all,

here is my simplest code, which demostrate trigger Hard Fault event.

Hard Fault event is triggered when reading from pointer to array in struct if(*value == 32292).

This code was tested LPC1227, LPC1114 and LPC1769 with code optimalization (None -O0).

Code generate Hard Fault event only LPC1227 and LPC1114, which have Cortex M0 core. On LPC1769 event not triggered.

I would like know, if exist some proper compiler flag that solving this issue.

Milos

Code here:

#define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0]))

typedef struct _TEST_STRUCT_TYPE_
{
    volatile uint8_t some_variable;

    volatile uint8_t rx_buff[40];

} TEST_STRUCT_TYPE;

volatile TEST_STRUCT_TYPE tst_in_main;

void TEST_STRUCT_TYPE_Service(TEST_STRUCT_TYPE *tst);

uint8_t test_uart_put_array[] = { 0x21, 0x23, 0x3C, 0x3E, 0x64, 0x2F, 0x01, 0x00, 0x12, 0x00, 0x53, 0x01, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0xFF, 0x24, 0x7E };
//uint8_t test_uart_put_array[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD };
int main(void)
{
    volatile int size;

    size = sizeof(TEST_STRUCT_TYPE);

    memcpy((void *)&(tst_in_main.rx_buff[0]), (void *)&(test_uart_put_array[0]), 30);

    TEST_STRUCT_TYPE_Service(&tst_in_main);

    //rp6_diag_comm_can_read_data = 0;

    /**********************************************************************************************/

    /* Main Loop forever */
    while (1)
    {
    }

    return 0 ;
}

void TEST_STRUCT_TYPE_Service(TEST_STRUCT_TYPE *tst)
{
    uint16_t *value;
    volatile int counter = 0;

    value = (uint16_t *)&(tst -> rx_buff[28]);

    if(*value == 32292)
    {
        counter++;
    }
}

0 件の賞賛
返信

1,938件の閲覧回数
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

Could you update the LPCXpresso IDE to latest version V8.2.2?

If there still with the same issue, I will report that software issue to LPCXpresso IDE software team.

Please let us know if the latest LPCXpresso IDE software could fix the issue.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信

1,938件の閲覧回数
miloskrizan
Contributor I

I added to project startup code in file cr_startup_lpc12xx.c code according Debugging a Hard Fault.

After, when I track assignment value to stacked_r0 variable, debuger halt with message "No source available for "0xfffffffe"".

When I remove lines with assignment to variables

stacked_r0,

stacked_r1,

stacked_r2,

stacked_r3,

stacked_r12,

stacked_lr,

stacked_pc and stacked_psr all remain variables

_CFSR,

_HFSR,

_DFSR,

_AFSR,

_MMAR,

_BFAR  will be done with zero value.

Milos

0 件の賞賛
返信

1,938件の閲覧回数
miloskrizan
Contributor I

Thank you for your questions Mike Hui_Ma,

excuse me, yesterday I was off..

I'm using Olimex LPC-P1227 development board, that contains LPC1227FBD64/301.

Yes, I can provide SW project.

Milos

0 件の賞賛
返信

1,938件の閲覧回数
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Milos,

Besides of LPCxpresso v7.6.2 [Build 326] [2015-02-02]  IDE, what's the hardware board you are using?

Could you provide the software project?

best regards,

Mike

0 件の賞賛
返信