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