lpcware

IAP flash algorithm gives hard fault on LPC5410x board

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Dec 5, 2017 by Daniel Gull
Content originally posted in LPCWare by mbilal on Fri Dec 26 02:38:41 MST 2014
I wrote IAP flash algorithm for LPC5410 512K Flash board.
I always get a hard fault on preparing a single scetor  or any other IAP command.

Below is my code:


#include <stdio.h>

/* Total number of command.  */
#define COMMAND_LENGTH 5
/* Total number of return status.  */
#define RESULT_LENGTH  5

#define COMMAND_PREPARE 50
#define COMMAND_PROGRAM 51
#define COMMAND_ERASE   52
#define COMMAND_PAGE_ERASE  59
#define COMMAND_PART_NUMBER 54


/* Define the IAP location entry point.  */
#define IAP_LOCATION 0x03000204

/* Setting the function pointer that takes IAP command table and result table pointers.  */
typedef void (*iap) (unsigned int *, unsigned int *);

unsigned int lpc5410x_prepare_sector (unsigned int sector)
{
  unsigned int command[COMMAND_LENGTH];
  unsigned int result[RESULT_LENGTH];
  iap iap_entry = (iap) IAP_LOCATION;
  command[0] = COMMAND_PREPARE;
  command[1] = sector;
  command[2] = sector;
  (*iap_entry) (command, result);
  printf("The result of prepared sector number (%d)  is  %d", sector, result[0]);
  return result[0];
}

static __inline__ unsigned int __attribute__ ((always_inline))
lpc5410x_page_erase (unsigned int sector)
{
  unsigned int command[COMMAND_LENGTH];
  unsigned int result[RESULT_LENGTH];
  iap iap_entry = (iap) IAP_LOCATION;
  command[0] = COMMAND_PAGE_ERASE;
  command[1] = sector;
  command[2] = sector;
  iap_entry (command, result);
  printf("The result of page erase number (%d)  is  %d", sector, result[0]);
  return result[0];
}

/* Erase sector SECTOR.  */

static __inline__ unsigned int __attribute__ ((always_inline))
lpc5410x_erase_sector (unsigned int sector)
{
  unsigned int command[COMMAND_LENGTH];
  unsigned int result[RESULT_LENGTH];
  iap iap_entry = (iap) IAP_LOCATION;
  command[0] = COMMAND_ERASE;
  command[1] = sector;
  command[2] = sector;
  iap_entry (command, result);
  printf("The result of erase sector number (%d)  is  %d", sector, result[0]);
  return result[0];
}

static __inline__ unsigned int __attribute__ ((always_inline))
lpc5410x_part_number ()
{
  unsigned int command[COMMAND_LENGTH];
  unsigned int result[RESULT_LENGTH];
  iap iap_entry = (iap) IAP_LOCATION;
  command[0] = COMMAND_PART_NUMBER;
  iap_entry (command, result);
  printf("The result of part identification number is  %d",result[0]);
  return result[0];
}

static __inline__ unsigned int __attribute__ ((always_inline))
lpc5410x_program_sector (unsigned int dest, unsigned int src, unsigned int len)
{
  unsigned int command[COMMAND_LENGTH];
  unsigned int result[RESULT_LENGTH];
  iap iap_entry = (iap) IAP_LOCATION;
  command[0] = COMMAND_PROGRAM;
  command[1] = dest;
  command[2] = src;
  command[3] = len;
  iap_entry (command, result);
  return result[0];
}

int main ()
{
lpc5410x_prepare_sector (1);

// Erase a single sector
lpc5410x_erase_sector(1);
return 0;
}




I also saved top 32 bytes of SRAM space for this and set voltage with Power API command.

I always got Hard fault at line (below) of every command.
iap_entry (command, result);


Is IAP_Location 0x03000204 has been described correct in LPC5410x manual or I'am doing something wrong.
Please help me on this regard.
It will be very appreciated.







Outcomes