2021-06-07 03:00 PM
I'm having trouble making use of SDRAM (external device memory) on the STM32H743 EVAL2 board. Specifically, I'm trying to make use of FMC SDRAM Bank 2 (Region: External Devices) to store a large array.
Here are code snippets that I have added/modified
< STM32H743XIHX_FLASH.ld >
...
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
RAM (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
SDRAM (xrw) : ORIGIN = 0xD0000000, LENGTH = 64K
}
...
/* Define output sections */
SECTIONS
{
...
/* SDRAM Section, store some application variables */
.sdram :
{
. = ALIGN(4);
_ssdram = .;
*(.sdram)
*(.sdram*)
. = ALIGN(4);
_esdram = .;
} >SDRAM
...
}
...
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_DFSDM1_Init();
MX_FMC_Init();
MX_I2C1_Init();
MX_LTDC_Init();
MX_QUADSPI_Init();
MX_SAI1_Init();
MX_USART1_UART_Init();
MX_USB_OTG_FS_PCD_Init();
MX_USB_OTG_HS_PCD_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
int value;
srand(time(NULL));
while (1)
{
value = rand() % BUF_LEN;
buf[value] = (uint8_t)rand();
if (buf[value] % 2 == 0) {
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_10);
}
else {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_4);
}
HAL_Delay(2000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
...
.ioc file has all default configurations
When trying to RUN/DEBUG, I receive this error:
Error in final launch sequence:
Failed to execute MI command:
load /home/<user_name>/<user_project>/use_sdram_example/Debug/use_sdram_example.elf
Error message from debugger back end:
Load failed
Failed to execute MI command:
load /home/<user_name>/<user_project>/use_sdram_example/Debug/use_sdram_example.elf
Error message from debugger back end:
Load failed
Failed to execute MI command:
load /home/<user_name>/<user_project>/use_sdram_example/Debug/use_sdram_example.elf
Error message from debugger back end:
Load failed
Load failed
The paths are correct
2021-06-07 03:18 PM
Try marking the SDRAM section as NOLOAD.
/* SDRAM Section, store some application variables */
.sdram (NOLOAD) :
{
2021-06-07 03:23 PM
In terms of having it come up early and be able to copy data to it the CMSIS model really needs for the clocks, pins, peripheral and SDRAM to be brought up in SystemInit() and statics copied or zeroed in the startup.s code.
I'm not sure CubeMX handles this, and if so badly.
NOLOAD / NOINIT type functionality can be used to mask deficiencies, and allow the memory and chip to be brought up later.
2021-06-07 03:37 PM
Thanks! With this addition, I can now launch the program. However, if I try to access/read/write to buf, I get a hard-fault error. In the debugger, when I try to view an entry in buf, I am shown this error (specifically, this is me checking buf[2] explicitly)
Failed to execute MI command:
-data-evaluate-expression buf[2]
Error message from debugger back end:
Cannot access memory at address 0xd0000002
2021-06-07 03:37 PM
When I use NOINIT, I receive linker error:
non constant or forward reference address expression for section .sdram
See my response to TDK (above)
2021-06-07 03:52 PM
Recheck your SDRAM parameters. Yours do not match those found in the examples for that board.
Also, you need to do more than just call HAL_SDRAM_Init. Again, see the example.
2021-06-07 04:52 PM
Thanks for linking that example, it does appear very useful.
However, the issue I'm facing on my application is that there are very large, uninitialized variables that cannot fit on RAM. I want to use RAM for .bss section, but specifically set certain large variables (think, array of size 200,000) to use SDRAM, specifically address 0xD0000000+. The linked example uses RAM for .bss (uninitialized variables).
Does my issue make sense?
2021-06-07 04:56 PM