Skip to content

Commit dbc8aab

Browse files
committed
SDRAM: turn SDRAM_START_ADDRESS into variable
SDRAM_START_ADDRESS is being used in various places instead of trusting the APIs. In case the M4 is in standalone mode, no RAM remapping should be used, but if both M7 and M4 want to access the SDRAM, the address they are referring to should be the same. By initializing SDRAM object very early, we can spot is RAM was already initialized (and chenge the user selection accordingly)
1 parent 2da29d8 commit dbc8aab

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

libraries/Arduino_H7_Video/src/dsi.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ int dsi_init(uint8_t bus, struct edid *edid, struct display_timing *dt) {
5151
static const uint32_t DSI_PLLIDF = DSI_PLL_IN_DIV3;
5252
static const uint32_t DSI_PLLODF = DSI_PLL_OUT_DIV1;
5353
static const uint32_t DSI_TXEXCAPECLOCKDIV = 4;
54+
#undef HSE_VALUE
55+
#define HSE_VALUE 16000000
5456
#else
5557
static const uint32_t DSI_PLLNDIV = 40;
5658
static const uint32_t DSI_PLLIDF = DSI_PLL_IN_DIV2;

libraries/Portenta_SDRAM/src/SDRAM.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ extern "C" {
33
#include "ram_internal.h"
44
}
55

6+
uint32_t SDRAM_START_ADDRESS = SDRAM_START_ADDRESS_DEFAULT;
7+
uint32_t SDRAM_END_ADDRESS = SDRAM_END_ADDRESS_DEFAULT;
8+
9+
SDRAMClass::SDRAMClass() {
10+
#ifdef CORE_CM4
11+
if (FMC_SDRAM_DEVICE->SDCMR != 0x00000000U) {
12+
// CM4 not standalone, RAM already remapped to 0x60000000
13+
SDRAM_START_ADDRESS = 0x60000000;
14+
SDRAM_END_ADDRESS = 0x60800000;
15+
}
16+
#endif
17+
}
18+
619
int SDRAMClass::begin(uint32_t start_address) {
720

821
//printf("FMC_SDRAM_DEVICE->SDCMR: %x\n", FMC_SDRAM_DEVICE->SDCMR);
@@ -59,7 +72,11 @@ int SDRAMClass::begin(uint32_t start_address) {
5972
mpu_config_end();
6073
#endif
6174

62-
}
75+
} else {
76+
#ifdef CORE_CM4
77+
start_address = SDRAM_START_ADDRESS | (start_address & 0xFFFFFF);
78+
#endif
79+
}
6380

6481
if (start_address) {
6582
//printf("malloc_addblock: allocate %d bytes\n", SDRAM_END_ADDRESS - start_address);
@@ -126,4 +143,4 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
126143
return true;
127144
}
128145

129-
SDRAMClass SDRAM;
146+
SDRAMClass SDRAM __attribute__ ((init_priority (101)));

libraries/Portenta_SDRAM/src/SDRAM.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
#include "Arduino.h"
66

77
#if !defined(CORE_CM4)
8-
#define SDRAM_END_ADDRESS (0x60800000)
9-
#define SDRAM_START_ADDRESS (0x60000000)
8+
#define SDRAM_END_ADDRESS_DEFAULT (0x60800000)
9+
#define SDRAM_START_ADDRESS_DEFAULT (0x60000000)
1010
#else
11-
#define SDRAM_END_ADDRESS (0xC0800000)
12-
#define SDRAM_START_ADDRESS (0xC0000000)
11+
#define SDRAM_END_ADDRESS_DEFAULT (0xC0800000)
12+
#define SDRAM_START_ADDRESS_DEFAULT (0xC0000000)
1313
#endif
1414

15+
extern uint32_t SDRAM_START_ADDRESS;
16+
extern uint32_t SDRAM_END_ADDRESS;
17+
1518
class SDRAMClass {
1619
public:
17-
SDRAMClass() {}
20+
SDRAMClass();
1821
int begin(uint32_t start_address = SDRAM_START_ADDRESS);
1922
void* malloc(size_t size);
2023
void free(void* ptr);

0 commit comments

Comments
 (0)