cancel
Showing results for 
Search instead for 
Did you mean: 

SDRAM and a global struct.

Hector_R
Associate

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.

7 REPLIES 7
GaetanGodart
ST Employee

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,

Gaetan Godart
Software engineer at ST (TouchGFX)
mƎALLEm
ST Employee

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.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.
Hector_R
Associate

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)));

 

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.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

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];

 

You need to specify what do you mean by "it doesn't work". Struct wrongly filled with incorrect values? not accessible? or what?

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.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

Hello.

I have done a debug.

When the first MX_TouchGFX_Process(); is called all is corrupted.

  MX_GPIO_Init();
  MX_DMA_Init();
  MX_QUADSPI_Init();
  MX_FMC_Init();
  MX_CRC_Init();
  MX_LTDC_Init();
  MX_DMA2D_Init();
  MX_TIM2_Init();
  MX_SDMMC1_SD_Init();
  MX_FATFS_Init();
  MX_I2S1_Init();
  MX_USART1_UART_Init();
  MX_I2C1_Init();
  MX_USB_HOST_Init();
  MX_TouchGFX_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
    MX_USB_HOST_Process();

  MX_TouchGFX_Process();
    /* USER CODE BEGIN 3 */
  }

I am not using FreeRTOS.

This image shows the display.

IMG_20250217_094913887.jpg