How To read the IAP Flash Memory read on LPC865

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How To read the IAP Flash Memory read on LPC865

跳至解决方案
675 次查看
BerlinRaj
Contributor II

Hi NXP Experts,

I am trying to write and read data to the IAP flash memory on the LPC865M201JHI48 microcontroller. My condition is that I want to write and read data for different pages of one sector.

Case 1:

  • Data = 10
  • Sector = 60
  • Data1 Address = 0x0000F000
  • Page = 960

Case 2:

  • Data = 3999
  • Sector = 60
  • Data2 Address = 0x0000F040
  • Page = 961

Case 3:

  • Data = 200
  • Sector = 60
  • Data3 Address = 0x0000F080
  • Page = 962

Case 4:

  • Data = 1234
  • Sector = 60
  • Data4 Address = 0x0000F0C0
  • Page = 963

I am trying to write the data individually to single pages. In Case 1, I write data to the address 0x0000F000 and read the data using the same address. I get the correct data that I wrote. Later, I use Case 2 with the address 0x0000F040, and I read the data using the same address. I get the correct data perfectly as I wrote before. However, whenever I try to write to both addresses at the same time (0x0000F000 and 0x0000F040), the last written address prints the correct data, but the first written address prints garbage values.

My question is, can I write and read a single page of data at one time? Is this true?

 

#read part :

#define dummy_ADD   0x0000F000

#define dummy_ADD1 0x0000F040

uint32_t dum,dum1;

dum = IAP_ReadFlash(dummy_ADD);

printf(dum)

dum1 = IAP_ReadFlash(dummy_ADD1);

printf(dum1)

 

uint32_t IAP_ReadFlash(uint32_t FLASH_DATA_ADDRESS)
{
uint32_t *flashAddress = (uint32_t *)FLASH_DATA_ADDRESS;
uint32_t data = *flashAddress; // Read the data from the flash memory address
return data;
}
标签 (1)
0 项奖励
回复
1 解答
581 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @BerlinRaj 

There are many errors in your code. So refer to your requirements, I create a project for you.  I have tested on my side, there is no issue when writing two pages and reading.

From the result, we can see write to flash 78 and 190. They are read back correclty.

Alice_Yang_0-1722998175383.png

Alice_Yang_1-1722998368637.png

 

 

I attach my project  for you. 

Hope it helps.

 

BR

Alice

 

 

在原帖中查看解决方案

0 项奖励
回复
8 回复数
648 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @BerlinRaj 

For better help you, please share your project. I will help you check on my side. Thanks.

 

BR

Alice

0 项奖励
回复
636 次查看
BerlinRaj
Contributor II

hi, @Alice_Yang  thank you for your reply. i can write and read each data on a single page,can you tell me can i write and read more data for a single page?

0 项奖励
回复
618 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @BerlinRaj 

Yes, you can write and read more data for a single page. 

I recommend you debug step by step to check. 

If you still have issue, and do not want to publish your code. You can also create a private ticket. 

https://support.nxp.com/s/?language=en_US  

 

BR

Alice

0 项奖励
回复
611 次查看
BerlinRaj
Contributor II

Yes, I have an issue with my code! I can't post the code because of my company's policy. Anyway, I will try to send my issue through a private ticket.. thank you @Alice_Yang 

0 项奖励
回复
608 次查看
BerlinRaj
Contributor II

hii @Alice_Yang , i just try to write the code this console

consider, i have to stored the VERSION and Temperature on the IAP FLASH Memory, and i displayed theVERSION and Temperature value with 1.8 inch TFT DISPLAY.

uint32_t DEMO_IAP_FLASH_SECTOR = 63;//sector number
uint32_t PAGE_SIZE_BYTES = 64;
#define SECTOR_SIZE_BYTES (1024)
static uint32_t s_IapFlashAddress  = 64512;//=>1008(page_num)*64(page size)
static uint32_t s_IapFlashAddress1 = 64576;//=>1009(page_num)*64(page size)
int main()
{
     TFT_Init();
     home_screen();
     while(1)
     {
     }
 }
void home_screen()
{
        static uint32_t s_PageBuf=78;
        static uint32_t s_PageBuf1=190;
        Erace(DEMO_IAP_FLASH_SECTOR);
        Writing_Data _one(s_PageBuf);
        Writing_data_two(s_PageBuf1);
       //read part
	 uint32_t *read_ptr = (uint32_t *)(s_IapFlashAddress);
         uint32_t Version_value = *read_ptr;
	 uint32_t *read_ptr1 = (uint32_t *)(s_IapFlashAddress1);
         uint32_t Temp_value = *read_ptr;
	 print_tft(145, 2,Version_value , YELLOW_COLOR, BLUE_COLOR);
	 print_tft(145, 20,Temp_value , YELLOW_COLOR, BLUE_COLOR);
}
void Write_data_one(uint32_t s_PageBuf)
{
IAP_FLASH_WRITE(DEMO_IAP_FLASH_SECTOR,s_IapFlashAddress,s_PageBuf,PAGE_SIZE_BYTES);
}
void Write_data_two(uint32_t s_PageBuf1)
{
IAP_FLASH_WRITE(DEMO_IAP_FLASH_SECTOR,s_IapFlashAddress1,s_PageBuf1,PAGE_SIZE_BYTES);
}
void IAP_FLASH_WRITE(uint32_t DEMO_IAP_FLASH_SECTOR,uint32_t FlashAddress,uint32_t s_PageBuf,uint32_t PAGE_SIZE_BYTES)
{
//	IAP_PrepareSectorForWriteone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
//	IAP_EraseSectorone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR, SystemCoreClock);
	IAP_PrepareSectorForWriteone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
	IAP_CopyRamToFlashone(FlashAddress, &s_PageBuf,PAGE_SIZE_BYTES, SystemCoreClock);
}
void Erace(uint32_t DEMO_IAP_FLASH_SECTOR)
{
	IAP_PrepareSectorForWriteone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
	IAP_EraseSectorone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR, SystemCoreClock);
}
void IAP_PrepareSectorForWriteone(uint32_t startSector, uint32_t endSector)
{
    uint32_t command[5] = {0x00U};
    uint32_t result[5]  = {0x00U};

    command[0] = (uint32_t)kIapCmd_IAP_PrepareSectorforWrite;//50u
    command[1] = startSector;
    command[2] = endSector;
    iap_entry(command, result);
}
void IAP_EraseSectorone(uint32_t startSector, uint32_t endSector, uint32_t systemCoreClock)
{
   uint32_t command[5] = {0x00U};
   uint32_t result[5]  = {0x00U};

   command[0] = (uint32_t)kIapCmd_IAP_EraseSector;//52u
   command[1] = startSector;
   command[2] = endSector;
  // command[3] = systemCoreClock / HZ_TO_KHZ_DIV;
   iap_entry(command, result);
}
void IAP_CopyRamToFlashone(uint32_t dstAddr, uint32_t *srcAddr, uint32_t numOfBytes, uint32_t systemCoreClock)
{
    uint32_t command[5] = {0x00U};
    uint32_t result[5]  = {0x00U};

    command[0] = (uint32_t)kIapCmd_IAP_CopyRamToFlash;//51u
    command[1] = dstAddr;
    command[2] = (uint32_t)srcAddr;
    command[3] = numOfBytes;
   // command[4] = systemCoreClock / HZ_TO_KHZ_DIV;
    iap_entry(command, result);
}

 

Whenever I write the above program, the FLASH MEMORY writes and reads the data properly.

However, whenever I hide the #Erace(DEMO_IAP_FLASH_SECTOR); function, the first data is not read properly, but the second data is read well. Why?

explain  these below two function if i hide why first data should not printed.

IAP_PrepareSectorForWriteone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
IAP_EraseSectorone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR, SystemCoreClock);

 

 

0 项奖励
回复
582 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @BerlinRaj 

There are many errors in your code. So refer to your requirements, I create a project for you.  I have tested on my side, there is no issue when writing two pages and reading.

From the result, we can see write to flash 78 and 190. They are read back correclty.

Alice_Yang_0-1722998175383.png

Alice_Yang_1-1722998368637.png

 

 

I attach my project  for you. 

Hope it helps.

 

BR

Alice

 

 

0 项奖励
回复
539 次查看
BerlinRaj
Contributor II
Hi, @Alice_Yang you are great! Thank you so much for your wonderful effort.
 

Alice, I am new to NXP controllers. Previously, I had been working on STM32 controllers, where I found it easy to configure the USART peripherals using the IOC configuration tool. We just had to select the UART number, choose synchronous or asynchronous mode, set the baud rate, and data length, and the code would be auto-generated.

In a similar way, if I want to configure the UART in the LPC865, how should I go about it? Could you share a screenshot of the configuration process?

0 项奖励
回复
537 次查看
BerlinRaj
Contributor II

I want to configure USART0 with TX on P0_4 and RX on P0_1.

0 项奖励
回复