Example leveraging all the SRAM in NXP LPC5500 devices #73539
-
IntroductionThis example demonstrates and tests application data stored in the different SRAM arrays in the LPC5500 family. This example uses the LPC55S16, but is similar for other MCUs in the LPC5500 family. The example depends on #73533, and modifies the hello_world sample to test the different SRAMs. LPC55S16 SRAM overviewRefer to the LPC55S1x User Manual for details on the SOC and the SRAMs. The LPC55S16 has a total of 96 KB of SRAM divided into 5 separate arrays. These arrays give flexibility for performance and power consumption. The SOC DTS below shows the sizes and address ranges of the 5 arrays:
Applications have flexibility how these SRAM partitions are used. The default setting in the LPCXpresso55S16 board DTS combines SRAMs 0-2 into a single 64 KB segment for the linker. The
SRAM example applicationThe attached example is a simple app that leverages the different SRAM arrays, using nearly all of the total 96 KB. A simple test writes to these arrays and confirms the data written. To test the combined SRAMs 0-2, the main stack size is increased to nearly 64KB. A local variable The SRAMX and USB_RAM arrays are not combined with the other SRAMs. The app declares static variables in these arrays using the macro Enabling SRAM clock in early startup codeSome of these SRAMs have clock gates to reduce power consumption if the array is not used. Most of the clock gates are enabled by default. But in the LPC55S16, the USB_RAM clock is disabled by default. If the USB_RAM is used for app data, this clock gate must be enabled early in the startup code, before the startup code accesses the USB_RAM. This example enables the USB_RAM clock with the function below in main.c.
USB_RAM limitations with ZephyrThe USB_RAM address range is contiguous with SRAM2, and could be combined with SRAMs 0-2 to increase the app data size to 80 KB. However, since the USB_RAM clock is gated off by default, this can cause some complications for a Zephyr app. Zephyr uses the interrupt stack during startup, so the initial stack pointer points to the interrupt stack. This interrupt stack is used before Using Zephyr's linker files, the linker places the interrupt stack in the To avoid this issue, this example app keeps USB_RAM as a separate memory segment for the linker, and specifies the variables placed there. If a Zephyr app combines USB_RAM, this likely requires two options. One is for the app to use a custom linker file, which Zephyr does support. Or the app would need to use modified startup code or a secondary bootloader, which would enable the USB_RAM clock before the interrupt stack is accessed. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Hello, i did the changes that you sugest in this example: Altough this changes, the same error appears, i've tried other things to but without success |
Beta Was this translation helpful? Give feedback.
-
Hi @pmjokas , Best regards |
Beta Was this translation helpful? Give feedback.
-
Well, im new to Zephyr eco-system and i didn´t understood how to use the linker marcos to force variables in USB_ram, i've tried some things but it's not working //static uint32_t sramx_array[SRAMX_WORDS] in my main.c with the respective #includes? |
Beta Was this translation helpful? Give feedback.
-
Do you happen to know how I can allocate a Thread Stack to a specific SRAM section ? By default I think all stacks defined by I see in the final linker and map file that these objects are allocated in Use case: I have some stacks which I would want to allocate in other SRAM regions as I do not have enough space in the main SRAM. I am already using |
Beta Was this translation helpful? Give feedback.
Hi @pmjokas ,
We provided the attached hello_world_SRAM.zip for you to use as a reference. The PR #73533 merged, so this is now supported in the main branch. If you have not already done so, I suggest you update your local Zephyr repo to the latest main branch, copy the attached over the
samples\hello_world
application, and test that app. Since that shows how to use the USB_RAM, you can then apply it to your app.Best regards