cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault went reading flash

PGood.1
Associate II

This routeen fails on the line

Flash_End_Address() at flash_page.c:87 0x80004e6

where line 87 is

*DATA_64 = *(__IO uint64_t *)StartPageAddress;

_______________________________________________________________________________________

uint32_t Flash_End_Address (uint32_t StartPageAddress)

{

__IO uint64_t* DATA_64;

while (1){

*DATA_64 = *(__IO uint64_t *)StartPageAddress;

if (*DATA_64 == 0xffffffffffffffff)

{

break;

}

StartPageAddress += 8;

}

return StartPageAddress;

}

___________________________________________________________________

This routeen works

___________________________________________________________________

uint32_t Flash_Read_Data (uint32_t StartPageAddress, __IO uint64_t * DATA_64)

{

while (1)

{

*DATA_64 = *(__IO uint64_t *)StartPageAddress;

if (*DATA_64 == 0xffffffffffffffff)

{

*DATA_64 = '\0';

break;

}

StartPageAddress += 8;

DATA_64++;

}

return StartPageAddress;

}

1 REPLY 1
TDK
Guru
__IO uint64_t* DATA_64;
...
*DATA_64 = *(__IO uint64_t *)StartPageAddress;

You're writing a value to the location of an uninitialized pointer. Seems like you want this instead:

uint32_t Flash_End_Address (uint32_t StartPageAddress)
{
  __IO uint64_t DATA_64;
  while (1)
  {
    DATA_64 = *(__IO uint64_t *)StartPageAddress;
    if (DATA_64 == 0xffffffffffffffff)
    {
      break;
    }
  StartPageAddress += 8;
  }
  return StartPageAddress;
}

 or just:

uint32_t Flash_End_Address (uint32_t StartPageAddress)
{
  while (1)
  {
    if (*(__IO uint64_t *)StartPageAddress == 0xffffffffffffffff)
    {
      break;
    }
  StartPageAddress += 8;
  }
  return StartPageAddress;
}

If you feel a post has answered your question, please click "Accept as Solution".