Skip to content

Commit cba214e

Browse files
committed
Libraries: modernize Portenta_SDRAM and add example
1 parent 3eae8b7 commit cba214e

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
How to interact with external SDRAM on Portenta H7
3+
4+
The board comes with an hefty 8MB of external fast RAM, which can be used:
5+
- as a framebuffer (raw mode)
6+
- as an expansion of on-chip RAM to store "standard" data
7+
8+
This example shows both the usages
9+
*/
10+
11+
#include "SDRAM.h"
12+
13+
REDIRECT_STDOUT_TO(Serial);
14+
15+
void nonFrameBuffer() {
16+
// Initilize SDRAM for non-framebuffer operations
17+
SDRAM.begin(); // is the same as SDRAM.begin(SDRAM_START_ADDRESS);
18+
19+
// Now we can malloc() and free() in the whole RAM space
20+
// For example, let's create a 7MB array
21+
uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024);
22+
23+
// and a small one
24+
uint8_t* mySmallArray = (uint8_t*)SDRAM.malloc(128);
25+
26+
// and use then as usual
27+
for (int i = 0; i<128; i++) {
28+
myVeryBigArray[i] = i;
29+
mySmallArray[i] = i*2;
30+
}
31+
32+
// free the memory when you don't need them anymore
33+
SDRAM.free(myVeryBigArray);
34+
}
35+
36+
void frameBuffer() {
37+
// In case we want a framebuffer-like area at the beginning of the flash,
38+
// simply initialize the memory as
39+
40+
SDRAM.begin(SDRAM_START_ADDRESS + 2 * 1024 * 1024);
41+
// 2MB of contiguous memory available at the beginning
42+
43+
uint32_t* framebuffer = (uint32_t*)SDRAM_START_ADDRESS;
44+
45+
// We can't allocate anymore the huge 7MB array
46+
47+
uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024);
48+
if (myVeryBigArray == NULL) {
49+
Serial.println("Oops, too big :)");
50+
}
51+
52+
}
53+
54+
void setup() {
55+
Serial.begin(115200);
56+
while (!Serial);
57+
58+
frameBuffer();
59+
// Uncomment to test the other functionality
60+
// noFrameBuffer();
61+
62+
// Sort of memtest fo stability, useful for testing when overclocking
63+
if (SDRAM.test()) {
64+
Serial.println("SDRAM completely functional");
65+
}
66+
}
67+
68+
void loop() {
69+
70+
}

Diff for: libraries/Portenta_SDRAM/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Portenta_SDRAM
2+
version=1.0
3+
author=Arduino
4+
maintainer=Arduino <[email protected]>
5+
sentence=Interact with external SDRAM chip on Portenta H7
6+
paragraph=
7+
category=Other
8+
url=https://github.com/arduino/ArduinoCore-mbed/tree/master/libraries/RPC
9+
architectures=mbed,mbed_portenta
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)