SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By armsistem
#155921
Hi , I want to writing flash memory data for lpc2368 mcu. Then read flash memory adress , send to uart but the data coming ff

Please help
Code: Select all
#include <lpc23xx.h>
#include "uart.h"
#include "irq.h"
#include "timer.h"
#include "protocol.h"
#define IAP_LOCATION 0x7FFFFFF1
char Ram_Array[] = "abcdefgh";
unsigned long command[5]; // For Command Table
unsigned long result[2]; // For Result Table
typedef void (*IAP)(unsigned long [], unsigned long []);
IAP iap_entry;
void Write_to_Flash()
{ 
//******************************************
command[0] = 50;
command[1] = 0x00007000;
command[2] = 0x00008000;
command[3] = 48000; // PCLK == 48000 KHz	
iap_entry(command,result);
//******************************************	
command[0] = 51;
command[1] = 0x40000100;
command[2] = 0x00007000;
command[3] = 256;	
command[4] = 48000; // PCLK == 48000 KHz	
iap_entry(command,result);
//******************************************	
command[0] = 50;
command[1] = 0x00007000;
command[2] = 0x00008000;
command[3] = 48000; // PCLK == 48000 KHz	
iap_entry(command,result);
//******************************************		
command[0] = 52;
command[1] = 0x00007000;
command[2] = 0x00008000;
command[3] = 48000; // PCLK == 48000 KHz	
iap_entry(command,result);
//******************************************		
}

void
u1_karakter_gonder (unsigned char ch){
while (!(U0LSR & 0x20)); 
U0THR=ch;
}

   void
u1_string_gonder(const char *ch){ 
while(*ch) //
u1_karakter_gonder(*ch++);
}


int main(void)
{
unsigned long i;

char *Ram_Pointer;
 	char *Flash_Pointer;	
	
	UART0Init(57600);

      Ram_Pointer = (char*)0x40000100; // Set pointer to RAM
    	Flash_Pointer = (char*)0x00007000; // Set pointer to RAM
	    iap_entry = (IAP)IAP_LOCATION;// Set Function Pointer
	
	for (i=0;i<256;i++)
{if(i<=8) {*Ram_Pointer = Ram_Array[i];}
else {*Ram_Pointer = '1';}
Ram_Pointer++;}
//Ram_Pointer=&Ram_Array[0];
Write_to_Flash();
u1_string_gonder(Ram_Pointer);
u1_string_gonder(Flash_Pointer);
while(1);
}

By cfb
#155995
The parameters you are using for the IAP commands are incorrect. e.g.

1. 'Prepare Sectors' and 'Erase Sectors' needs sector numbers not absolute addresses.

2. 'Prepare Sectors' doesn't have the clock frequency as a parameter.

3. The first parameter of Copy RAM to flash is the destination flash address not the source RAM address.

etc. etc.

You should also check the return codes from the IAP functions to be informed of any errors and tidy up the layout of your code so it is easier to read and comprehend (Google for 'beautify C' if you don't know what I'm talking about).

Before you attempt to write any more code study Chapter 29: "LPC23XX Flash memory programming firmware" in LPC23XX User Manual UM10211 carefully to gain a better understanding of what it is you are trying to do.