2025-02-26 11:23 AM
Hello.
I tried to initialize SDRAM (I am using STM32F746 discovery kit), but I try to run it as a separate project just for learning. However I encountered the following problem: when I read data from SDRAM in my case starting from 0xC0000000 address - everything is ok, but writing to the address is shifted, it seems like when I write 16 bit int to 0xC0000002 it actually appears on 0xC0000000 location.
Also when I use Memory tool in STM32CubeIDE and try to change 4 bytes in SDRAM region only lower two bytes are changed on 0xC0000000 addres. When I change the next word (0xC0000004) - the changes appear on 0xC0000003-0xC0000006 bytes. I tried the same with 32 bit int variable in stack region - and I can change all 4 bytes.
I copied hardware settings from the init STM32F746 discovery project. Here is my init code:
FMC_SDRAM_CommandTypeDef Command;
/* Step 1 and Step 2 already done in HAL_SDRAM_Init() */
/* Step 3: Configure a clock configuration enable command */
Command.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; /* Set MODE bits to "001" */
Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; /* configure the Target Bank bits */
Command.AutoRefreshNumber = 1;
Command.ModeRegisterDefinition = 0;
HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
HAL_Delay(1); /* Step 4: Insert 100 us minimum delay - Min HAL Delay is 1ms */
/* Step 5: Configure a PALL (precharge all) command */
Command.CommandMode = FMC_SDRAM_CMD_PALL; /* Set MODE bits to "010" */
HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
/* Step 6: Configure an Auto Refresh command */
Command.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; /* Set MODE bits to "011" */
Command.AutoRefreshNumber = 8;
HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
/* Step 7: Program the external memory mode register */
Command.CommandMode = FMC_SDRAM_CMD_LOAD_MODE;/*set the MODE bits to "100" */
Command.ModeRegisterDefinition = (uint32_t)0 | 0<<3 | 2<<4 | 0<<7 | 1<<9;
Command.AutoRefreshNumber = 1;
HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
/* Step 8: Set the refresh rate counter - refer to section SDRAM refresh timer register in RM0455 */
/* Set the device refresh rate
* COUNT = [(SDRAM self refresh time / number of row) x SDRAM CLK] – 20
= [(64ms/4096) * 100MHz] - 20 = 1562.5 - 20 ~ 1542 */
HAL_SDRAM_ProgramRefreshRate(&hsdram1, 1542);
I also checked this post https://community.st.com/t5/stm32-mcus/how-to-set-up-the-fmc-peripheral-to-interface-with-the-sdram/ta-p/49457 but couldn't find anything relevant to my problem...
Any ideas what maybe the reason of the shift (if this is shift)?