AnsweredAssumed Answered

Strange hard fault

Question asked by Gaurav Banyal on Nov 24, 2016
Latest reply on Nov 28, 2016 by xiangjun.rong

In the code below, I am trying to read the flash memory and store it in a buffer.

When I read and assign to a buffer, I get a hard fault. When I only read and print it to UART, there is no problem and it prints all the addresses with the data I expect to be there.


Can someone please help me? (refer to the in-line comments to understand the problematic statements).

If there is no direct hint, could you please give me a HardFault_Handler implementation which will help me get more information of this problem?


======snip start=======

void read_session_from_flash()
uint32_t read_buffer[(destAdrss - zeroAdrss)/4];
uint32_t *flash_ptr;

PRINTF("\r\nNUMBER OF TIMESTAMPS IN FLASH = %d\r\n",(destAdrss - zeroAdrss)/4);

flash_ptr = (uint32_t*)zeroAdrss;
for (uint8_t i = 0; i < (destAdrss - zeroAdrss)/4; i++)
//read_buffer[i] = *(flash_ptr++); GBA: Something crazy here!! Enable this code and it leads to a hard fault
//PRINTF("FLASH_READ[%d] = 0x%x\r\n", i, read_buffer[i]); // should be enabled when the line above is enabled
PRINTF("FLASH_READ[%d] = 0x%x\r\n", i, *(flash_ptr++)); //This works like a charm!!!

======snip end=======