LPC54628 - putting global variables in BOARD_SDRAM

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

LPC54628 - putting global variables in BOARD_SDRAM

Jump to solution
2,544 Views
mateuszkiełbasa
Contributor III

Hi!

I'm trying to figure out how external BOARD_SDRAM works. I have seen the sdram example from SDK but probably it does not show how to solve my problem. In MCUXpresso settings I can choose destination where all global variables will be put. I choose BOARD_SDRAM and everything compile fine. No warnings and BOARD_SDRAM has some usage. When I try to run or debug the program it stucks (In debug mode the breakpoint in first instruction is not set anymore). I modified the sdram example. EMC is configured through BOARD_InitSDRAM(). What have I do? Or maybe it's not as trivial as i think? Thanks for replies!

Labels (1)
Tags (1)
0 Kudos
1 Solution
2,173 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kiełbasa,

Thanks for your reply.

Please try to use the __NOINIT() to place the global Noinit variables in the RAM, like the
// create a 128 byte noinit buffer in RAM2
__NOINIT(RAM2) char noinit_buffer[128];

It will avoid memory overflow risk.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
17 Replies
413 Views
alonbl
Contributor III

Hello,

I am aware this is an old issue, but just for the record, I bump into the same issue and tried to solve it without success as there is egg and chicken, the `SystemInitHook` is called before the idata is copied from flash to RAM, while the entire codegen of the init PIN and clocks is using global variables in idata, so these functions cannot be called during the `SystemInitHook`, and the SDRAM cannot be initialized without these.

It took me a while to figure this out as nothing is properly documented, while there is a simple solution it is just not documented in any place I could find, I will appreciate references.

The solution is to initialize the SEMC without code before the section copy is executed, luckily it is supported as DCD (device configuration data), I I bump into this while trying to understand the sequence and reading all the sources and hints. The DCD can be used to initialize  the SDRAM before the program is initialized, by using field of values and not code.

Step to enable:

1. select "Enable DCD Code" in the SEMC configuration of the peripheral tool

2. define `XIP_BOOT_HEADER_ENABLE=1` and `XIP_BOOT_HEADER_DCD_ENABLE=1` in C pre-processor to enable the DCD header.

3. Use `static __DATA(BOARD_SDRAM) int xxx = 5` as expected.

I hope this will be helpful to someone in future, as after reading this long thread there seems that there is no solution.

Regards,

0 Kudos
2,173 Views
mateuszkiełbasa
Contributor III

HI!

Project exported from MCUXpresso. I cannot find out how to add attachment so I uploaded on zippyshare. 

https://www13.zippyshare.com/v/oHNVAZyy/file.html

0 Kudos
2,173 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

Thanks for your reply.
I think you'd better upload the project by following the below steps, as I fail to download the demo via https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fwww13.zippyshare.com%2Fv%2FoHNVAZyy%2...

pastedImage_2.jpg

Fig 1 Attach steps

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,173 Views
mateuszkiełbasa
Contributor III

Hi!

I've attached the project. Have a nice day!

0 Kudos
2,173 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kiełbasa

Thanks for your reply.

After having a brief review of the project, I'd like to point out that the below functions should be exected prior to jump to main(), otherwise, it will fail to put global variables in SDRAM.

pastedImage_2.png
Hope it helps.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,173 Views
mateuszkiełbasa
Contributor III

I've put the code fragment inside `SystemInitHook` function and now when I type:

__DATA(BOARD_SDRAM) int hugeVar[10000] = {100};

the program runs fine and I can see the memory inside debug view. But I have a few questions :smileyhappy:

With variable in SDRAM like

__DATA(BOARD_SDRAM) int hugeVar[10000] = {100};

when I build the project I observe that not only usage of sdram increase but PROGRAM_FLASH also. For example BOARD_SDRAM usage is 0.48% but flash usage increase from 5% (clear sdram example) to 19.5%. Increasing hugeVar size also increase FLASH_USAGE. Isn't it weird? It's irrational for me.

The second question is: What exactly "Global data placement" option in project settings means? If i choose BOARD_SDRAM option program builds fine but it gets stuck and no breakpoint is available (cannot halt processor error). Can't I set this option instead of putting _DATA(BOARD_SDRAM) in front of the variable?

And the third question is: 

Can I set starting address for variables in sdram? I'd like to have emWin buffer (let's say it's about 8MB) and global data should be placed in second half of sdram.

Really thanks for your time and have a nice day!

0 Kudos
2,173 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kiełbasa,

Thanks for your reply.
1) Isn't it weird?
-- Code and initial values of initialized data items are placed into the first bank of Flash. During startup, MCUXpresso IDE startup code copies the data into the related RAM.
2) What exactly "Global data placement" option in project settings means?
-- Put the global data variable into the specific RAM.
3) Can I set the starting address for variables in SDRAM?
-- It's available, the thread (https://community.nxp.com/thread/389101) illustrates the steps to make it.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,173 Views
mateuszkiełbasa
Contributor III

Hi,

 1. So I'm not unable to create large variables even if it will fit fine into sdram because of the flash? Like 2MB array. It will fit into sdram but the program does not compile with flash overflow error

2. But it's the same as manually writing __DATA() in front of variable? If yes why the program stucks at the initialization?

Have a nice day!

0 Kudos
2,173 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kiełbasa,

Thanks for your reply.
1) So I'm not unable to create large variables even if it will fit fine into SDRAM because of the flash? Like 2MB array. It will fit into SDRAM but the program does not compile with a flash overflow error?
-- You can try to define the global variables which without the initialized value, it can avoid this risk.
2) But it's the same as manually writing __DATA() in front of variable? If yes why the program stucks at the initialization?
- I'm clear with the question, please explain it in details.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,173 Views
mateuszkiełbasa
Contributor III

Hi,

1) You can try to define the global variables which without the initialized value, it can avoid this risk.

-- Even without initialization (code below) this two variables uses about 8% of sdram but the program won't compile with 155% of flash usage

__DATA(RAM4) int hugeVar[100000];
__DATA(RAM5) int hugeVar2[100000];

2) I can manually move global variable using __DATA() in front of the variable. But I'd like to move all the variables into the sdram so I'd like to use Global data placement with SDRAM option choosen (for example all third party global variables (eg. freertos) have to be moved into sdram). The first option with __DATA() works fine. But the second option compile fine and the program can't reach any breakpoint (CPU cannnot be halted error)

Have a nice day!

0 Kudos
2,174 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kiełbasa,

Thanks for your reply.

Please try to use the __NOINIT() to place the global Noinit variables in the RAM, like the
// create a 128 byte noinit buffer in RAM2
__NOINIT(RAM2) char noinit_buffer[128];

It will avoid memory overflow risk.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,173 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kiełbasa

Thanks for your reply.
It seems a bit weird.
Whether you can share the complete compile-able demo which can replicate the issue, as I'd like to do some testing on my site.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,173 Views
mateuszkiełbasa
Contributor III

Also I noticed that sdram example fails. When checking written bytes it fails and when debugging I cannot observe BOARD_SDRAM in Peripheral+ tab. Are there any jumpers or something on this board when using sdram?

0 Kudos
2,173 Views
mateuszkiełbasa
Contributor III

   I've read this tutorial and when compiling it shows some BOARD_SDRAM usage. I've also tryied to move Board_InitSDRAM() into inititlization function. In file system_LPC54629.c there is a init function:

__attribute__ ((weak)) void SystemInitHook (void) {
/* Void implementation of the weak function. */
}

I've put sdram init into this function but the result is same. It still not works...

0 Kudos
2,173 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kiełbasa

Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
Actually, I need more information about the phenomenon, so whether you can introduce what the demo from SDK library you use as template demo, in further, what modification work you did about the demo.
It can help me to figure the issue out.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,173 Views
mateuszkiełbasa
Contributor III

Thanks for your feedback!

In source code there is my sample project based on the sdram example. Other files and settings are from sdram example (except putting global variables in BOARD_SDRAM setting)

#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_emc.h"
#include <stdbool.h>
#include "pin_mux.h"

#define SDRAM_BASE_ADDR 0xa0000000
#define SDRAM_SIZE_BYTES (8 * 1024 * 1024)

/* Global variable */
static int global[10000] = {10, 0};

int main(void)
{
/* Hardware Initialization */
CLOCK_EnableClock(kCLOCK_InputMux);
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

BOARD_InitPins();
BOARD_BootClockFROHF96M();
BOARD_InitDebugConsole();
BOARD_InitSDRAM();

PRINTF("%d", global[0]);

EMC_Deinit(EMC);


while (1)
{
}
}

0 Kudos
2,173 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mateusz Kie&#322;basa

Thanks for your reply.
Firstly, the demo should work well, however, global[10000] won't be placed in the SDRAM, you'd better refer to the thread (Placing data into different RAM blocks ) to make it, besides, the SDRAM should be initialized prior jump to the main().

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos