Skip to main content
Associate
February 16, 2025
Solved

SDRAM and a global struct.

  • February 16, 2025
  • 4 replies
  • 1309 views

Hi.

I am using TouchGFX and it works fine,

My MCU is STM32H743

 

But when I use the SDRAM for other things the code does not work.

My question is:

Can I use struct in the  SDRAM.?

 

I have this one in my c file.

 

 

SD_CARD SdCard __attribute__((section("\"SDCardSection\""))) __attribute__((aligned(4)));

 

 

In my h file as follows:

 

 

 

typedef struct {
	char Name[256];
	char Path[1000];
	char File[2000];
	uint8_t LogicalDrive;
}SD_CARD;
extern SD_CARD SdCard __attribute__((section("\"SDCardSection\""))) __attribute__((aligned(4)));

 

 

 My Linker file is as follows:

 

 

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x400; /* required amount of heap */
_Min_Stack_Size = 0x800; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
 FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
 DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
 RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
 RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
 RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
 ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
 QUADSPI (r) : ORIGIN = 0x90000000, LENGTH = 16M
 SDRAM (xrw) : ORIGIN = 0xC0000000, LENGTH = 32M 
}

etc
etc
etc
 .ARM.attributes 0 : { *(.ARM.attributes) }
 
 BufferSection (NOLOAD) :
 {
 *(Video_RGB_Buffer Video_RGB_Buffer.*)
 *(.gnu.linkonce.r.*)
 . = ALIGN(0x4);

 *(TouchGFX_Framebuffer TouchGFX_Framebuffer.*)
 *(.gnu.linkonce.r.*)
 . = ALIGN(0x4);
 } >SDRAM
 
 SDCardSection (NOLOAD) :
 {
 *(SDCardSection SDCardSection .*)
 *(.gnu.linkonce.r.*)
 . = ALIGN(0x4);
 } >SDRAM

 

 

 

 Best Regards.

Best answer by mƎALLEm

Hello,

You've already declared and relocated it in SDRAM in the c file:

SD_CARD SdCard __attribute__((section("\"SDCardSection\""))) __attribute__((aligned(4)));

No need to relocate it again in the header file: 

typedef struct {
	char Name[256];
	char Path[1000];
	char File[2000];
	uint8_t LogicalDrive;
}SD_CARD;
extern SD_CARD SdCard;

The linker knows by the key "extern" it's the same variable you've declared in .c file.

4 replies

GaetanGodart
Technical Moderator
February 17, 2025

Hello @Hector_R and welcome to the community!

 

I do not see why you could not use a struct in the SDRAM.

I do not think you need 

extern SD_CARD SdCard __attribute__((section("\"SDCardSection\""))) __attribute__((aligned(4)));

 in your header file. Just declare the type in the source file.

 

Are you able to use your SDRAM when you don't use the structure?

 

Regards,

mƎALLEm
mƎALLEmBest answer
Technical Moderator
February 17, 2025

Hello,

You've already declared and relocated it in SDRAM in the c file:

SD_CARD SdCard __attribute__((section("\"SDCardSection\""))) __attribute__((aligned(4)));

No need to relocate it again in the header file: 

typedef struct {
	char Name[256];
	char Path[1000];
	char File[2000];
	uint8_t LogicalDrive;
}SD_CARD;
extern SD_CARD SdCard;

The linker knows by the key "extern" it's the same variable you've declared in .c file.

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
Hector_RAuthor
Associate
February 17, 2025

Hello Gaetan.

I need to add the structure as an extern because those variables are used in other files. (from TouchGFX)

This works well.

My .c file.

// My structure
SD_CARD SdCard

In my .h file

typedef struct {
	char Name[256];
	char Path[1000];
	char File[2000];
	uint8_t LogicalDrive;
}SD_CARD;
extern SD_CARD SdCard;

 As you can see when

But I would use the SDRAM  because I need to add big buffers to display files (SD CARD file names)

But this way the display does not work.

typedef struct {
	char Name[256];
	char Path[1000];
	char File[2000];
	uint8_t LogicalDrive;
}SD_CARD;
extern SD_CARD SdCard __attribute__((section("\"SDCardSection\""))) __attribute__((aligned(4)));

 

mƎALLEm
Technical Moderator
February 17, 2025

As I said you need to declare and relocate that structure in the c file:

SD_CARD SdCard __attribute__((section("\"SDCardSection\""))) __attribute__((aligned(4)));

Then export it the header file without any relocation:

typedef struct {
	char Name[256];
	char Path[1000];
	char File[2000];
	uint8_t LogicalDrive;
}SD_CARD;
extern SD_CARD SdCard;
"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
Hector_RAuthor
Associate
February 17, 2025

Hello Friend!.

Yes, I have tested it right now.

But the problem is still there.

 

If I use a simple buffer it works, for example:

.c file

char SdCard_Name[256] __attribute__((section("\"SDCardSection\""))) __attribute__((aligned(4)));

 

extern SdCard_Name[256];

 

Hector_RAuthor
Associate
February 25, 2025

Hi there.

The problem was that TouchGFX uses Unicode.

I was using char buffer and pointers to update the buffer of a scrollWheel.

But TouchGFX describes that we should use the Unicode library.

So,  I updated my buffers to datatype uint16_t, and then used the Unicode library.

void CustomContainer2_1::UpdateText(uint16_t value)
{
	Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", &SdCard.File);
...
...
...
...
 textArea1.invalidate();
}