2022-03-03 02:35 AM
Hello,
I created the project in STM32CubeMX 6.3 with the board name at default settings. The generated code in STM32CubeIDE has many related init functions. The below MX_FMC_init function didn't have any issue and bank2 was set automatically. According to the memory map in RM0455 manual as attached, the start address of SDRAM was set as 0xD0000000 in the code. However, I met an error message that "Cannot access memory at address 0xd0000000". Am I misinterpreting the reference manual? Please help me for this issue. Thanks.
Best Regards,
Jeff
static void MX_FMC_Init(void)
{
/* USER CODE BEGIN FMC_Init 0 */
/* USER CODE END FMC_Init 0 */
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
/* USER CODE BEGIN FMC_Init 1 */
/* USER CODE END FMC_Init 1 */
/** Perform the SDRAM1 memory initialization sequence
*/
hsdram1.Instance = FMC_SDRAM_DEVICE;
/* hsdram1.Init */
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_1;
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_DISABLE;
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
/* SdramTiming */
SdramTiming.LoadToActiveDelay = 16;
SdramTiming.ExitSelfRefreshDelay = 16;
SdramTiming.SelfRefreshTime = 16;
SdramTiming.RowCycleDelay = 16;
SdramTiming.WriteRecoveryTime = 16;
SdramTiming.RPDelay = 16;
SdramTiming.RCDDelay = 16;
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
{
Error_Handler( );
}
/* USER CODE BEGIN FMC_Init 2 */
/* USER CODE END FMC_Init 2 */
}
2022-03-03 11:32 AM
DK boards have ready to go examples and BSP code for init onboard hw.
Try read and compare your code. MX generated projects is clean STM part init, but not generate external hw init commands. SDRAM need some config commands.
2022-03-03 11:55 AM
For example see this
2022-03-03 11:58 AM
Where is it getting the "ERROR" ? The debugger can't touch the memory until the pins, clocks and peripherals are all configured for the board. Prior to that it will be unreadable, and code touching the memory at 0xD0000000 will Hard Fault, as the decoding isn't configured.
This is a problem when you don't initialize until you're already in main(), the memories are supposed to come up in SystemInit() so the startup code can unpack the statics, and run the constructors..
Perhaps look at worked examples of the SDRAM using the BSP
STM32Cube_FW_H7_V1.8.0\Projects\STM32H7B3I-DK\Examples\BSP
STM32Cube_FW_H7_V1.8.0\Drivers\BSP\STM32H7B3I-DK\stm32h7b3i_discovery_sdram.c
2022-03-03 11:23 PM
Thank you for the explanations. I put the memory pointer at the end of main() function. So, all other necessary initializations and configurations were already done I think. Instead, I downloaded and tried STM32Cube_FW_H7_V1.9.0\Projects\STM32H7B3I-DK\Examples\FMC\FMC_SDRAM. It runs well with the SDRAM_BANK_ADDR 0xD0000000. However, when I added UART_HandleTypeDef into the main.c file for serial print, the compiler claims that it's an unknown type. How can I merge the FMC project and UART project?