Demo using extra 16K SRAM banks on LPC1768 for C object storage

Dependencies:   mbed

On-chip LPC1768 SRAM includes:

32 kB of SRAM on the CPU with local code/data bus for high-performance CPU access. Used by compiler for all variables and objects by default.

Two 16 kB SRAM blocks with separate access paths for higher throughput. These SRAM blocks may be used for Ethernet, USB, and DMA memory, as well as for general purpose CPU instruction and data storage. Using any of the SRAM in these banks requires a compiler directive in the object's declaration in the C++ source code.

int buffer_SRAM[3000]; //regular SRAM use by compiler
int buffer_SRAM_Bank0[4000] __attribute__((section("AHBSRAM0"))); //put in extra 16K bank
int buffer_SRAM_Bank1[4000] __attribute__((section("AHBSRAM1"))); //put in other extra 16K bank

Some Ethernet code uses one of the banks to buffer network packets.

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Fri Sep 23 14:09:54 2022 +0000
Commit message:
ver 1.0

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 23 14:09:54 2022 +0000
@@ -0,0 +1,40 @@
+//Demo using additional SRAM Banks on LPC1768
+#include "mbed.h"
+Serial pc(USBTX,USBRX);
+DigitalOut myled(LED1);
+int i=0;
+int buffer_SRAM[3000]; //regular SRAM use by compiler
+int buffer_SRAM_Bank0[4000] __attribute__((section("AHBSRAM0"))); //put in extra 16K bank
+int buffer_SRAM_Bank1[4000] __attribute__((section("AHBSRAM1"))); //put in other extra 16K bank
+int main()
+{
+    pc.printf("Hello Extra SRAM\n\r");
+    pc.printf("size of int %d bytes\n\r",sizeof(buffer_SRAM[0]));
+    pc.printf("address of buffer_SRAM %x\n\r",buffer_SRAM);
+    pc.printf("address of buffer_SRAM_Bank0 %x\n\r",buffer_SRAM_Bank0);
+    pc.printf("address of buffer_SRAM_Bank1 %x\n\r",buffer_SRAM_Bank1);
+    wait(5);
+    while(1) {
+        myled = 1;
+        for(i=0; i<4000; i++) {
+            buffer_SRAM_Bank0[i]=i;
+        }
+        for(i=0; i<4000; i++) {
+            buffer_SRAM_Bank1[i]= -i;
+        }
+        for(i=0; i<3000; i++) {
+            buffer_SRAM[i]= 0;
+        }
+        myled=0;
+        for (i=0; i<4000; i++) {
+            pc.printf("%d\n\r",buffer_SRAM_Bank0[i]);
+        }
+        for (i=0; i<4000; i++) {
+            pc.printf("%d\n\r",buffer_SRAM_Bank1[i]);
+        }
+        for (i=0; i<3000; i++) {
+            pc.printf("%d\n\r",buffer_SRAM[i]);
+        }
+        myled = 1;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Sep 23 14:09:54 2022 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0954ebd79f59
\ No newline at end of file