SDRAM interface issue with LPC4367 Controller using __Data attribute and __BSS Attribute

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SDRAM interface issue with LPC4367 Controller using __Data attribute and __BSS Attribute

1,561 Views
gauravmore
Contributor III

Hi,

I am using LPC4367 controller. I have interfaced SDRAM with the controller. I have verified the interface using the test code , refer the attached code for the same. 

It is working with 16bit mode (2Byte). The test code use pointer functionality and writes 0XA5A5 and 0x5A5A and write the same in the SDRAM location. I verified it for 4 MB size. 

But when I used __BSS attribute and allocate the array variable to the SDRAM location, then the data stored is fail. Means it stores 0xFFFF instead. so with the same configuration it works using pointer functionality then what would be the reason for not working in  __DATA or __BSS mode.

Refer the attached code and please comment on the same. also raised the ticket for the same. The attached code is implemented using the pointer functionality.

BR,

Gaurav More

 

Labels (3)
0 Kudos
6 Replies

1,552 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Gaurav,

As you know that the external SDRAM can save data only after the EMC module is initialized, I suppose that you initialize the EMC in your application  code, so you can access the SDRAM with pointer successfully , because at this time when you access SDRAM with pointer, the EMC has been initialized. But when you use .bss section, or __DATA section, cpu access the SDRAM address before the EMC is initialized, of course, you can not write/read successfully.

Hope it can help you

BR

XiangJun Rong

 

 

Tags (1)
0 Kudos

1,546 Views
gauravmore
Contributor III

Hi  xiangjun_rong,

Thanks for the quick response, But in my case i am initializing the EMC lines at the Chip_SystemInit() function itself  where the CPU will come first before it goes to main function routine. 

Regarding the data access it will only be done when i will call and assign the data to the variable. So the EMC line will only be active when we access the actual address allocated to that EMC CS line.

Also i will try with different code and confirm you by writing the same patterns, 0xA5A5, 0x5555, 0x5A5A. It should work accordingly.

Also check the modified code which i will now download and check. i created the RAM8 in MCU setting option in the properties. You can refer the code and check the EMC init function called in Chip_SystemInit() in sysinit.c file. do you think calling this EMC init function in the above mentioned Chip_SystemInit function will also reflect the same behavior?

Refer the attached code for reference and review so that i can proceed further with the development.

BR, 

Gaurav More

0 Kudos

1,539 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

As the following screenshot, in the cr_startup_lpc43xx.c file, the bss section is initialized as 0.

BTW, as you know the SDRAM is RAM, volatile memory, it can not save constant data, the constant must be saved in flash, and copy to RAM as the following code.

Hope it can help you

BR

XiangJun Rong

 

xiangjun_rong_0-1642670660573.png

 

0 Kudos

1,528 Views
frank_m
Senior Contributor III

> As the following screenshot, in the cr_startup_lpc43xx.c file, the bss section is initialized as 0.

> BTW, as you know the SDRAM is RAM, volatile memory, it can not save constant data, the constant must be saved in flash, and copy to RAM as the following code.

 

It shouldn't be too difficult to modify the startup code, and initialize the EMC before the constants (Flash data) are copied.

0 Kudos

1,497 Views
gauravmore
Contributor III

Hi Frank,

It is already done in the attached code in the thread. The initialization of EMI lines are done in the startup function inside SystemInit() - >Chip_SystemInit()->EMC_SetPinMux() & EMC_SetupSDRAMMemmory()

Also I verified it by using below code modification in the attached reference code.

 

#define SDRAM_SIZE_BYTES       (2* 1024 * 1024)
#define	SDRAM_SIZE		SDRAM_SIZE_BYTES
__BSS(RAM8)	uint16_t	Buffer[SDRAM_SIZE_BYTES ];
__BSS(RAM9)	uint16_t	Buffer1[SDRAM_SIZE_BYTES ];

void main(void)
{
 uint32_t l_ui_Count = 0;
 uint8_t l_ui8_status = 0, l_ui8_status1 = 0;
/* Writing the data in SDRAM RAM*/
for(l_ui_Count = 0; l_ui_Count < SDRAM_SIZE; l_ui_Count++ )
{
  Buffer[l_ui_Count] = 0x5555;
  Buffer1[l_ui_Count] = 0xA5A5;
}

/* Reading the data from SDRAM and verification of the same */ 
for(l_ui_Count = 0; l_ui_Count < SDRAM_SIZE; l_ui_Count++ )
{
  if(Buffer[l_ui_Count] != 0x5555)
  {
    l_ui8_status = 1;
  }

  if(Buffer1[l_ui_Count] != 0xA5A5)
  {
    l_ui8_status1 = 1;
   }
}

while(1)
{
  if(l_ui8_status == 0 && l_ui8_status1 == 0)
  {
    Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 5, 5);
    for (i=0; i<0xFFFFF;i++ );
    Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 5, 19);
    for (i=0; i<0xFFFFF;i++ );
  }
  else
  {
   Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 19, (bool) false);
  }
}
   return 0 ;
}/* Main()*/

Refer the attached code in the thread and revert. after doing this it is working properly but same modification is done in the main code there it is not working. the only difference is instead of Buffer array I am assigning Structure array to it. 

Also the variables of different data types are there uint8_t, uint16_t, uint32_t son checking the same issue also I am using memcpy function for copying the data to it.

Just suggest if have pointers mean while I will check at my side.

BR,

Gaurav More

 

 

 

0 Kudos

1,486 Views
frank_m
Senior Contributor III

> Refer the attached code in the thread and revert. after doing this it is working properly but same modification is done in the main code there it is not working. the only difference is instead of Buffer array I am assigning Structure array to it. 

> Also the variables of different data types are there uint8_t, uint16_t, uint32_t son checking the same issue also I am using memcpy function for copying the data to it.

I am not sure either.

I would first check the addresses of said variables/structs in the map file, if they are correctly located. And then check in the debugger how actual access works out.

I did not need any pre-main initialisation, so initialisation of the EMC interface and the RAM itself is done in main. For my project I used the pointer method as well. Writing is done in an interrupt handler, and I kept it as short as possible.

0 Kudos