cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 SDRAM Initialization and usage

THIHA KYAW
Associate III
Posted on November 22, 2017 at 04:40

Hi,

I would like to know how to set parameters in SDRAM Initialization. You can refer to document too.

From  FMC_SDRAM example project,

In STM32F769-EVAL, 

hsdram.Init.SDBank = FMC_SDRAM_BANK1;

hsdram.Init.ColumnBitsNumber =

FMC_SDRAM_COLUMN_BITS_NUM_9

;

hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;

hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; //

FMC_SDRAM_MEM_BUS_WIDTH_32

hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;

hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;

hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;

hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD;

hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;

hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;

In STM32F769I_Discovery board,

hsdram.Init.SDBank = FMC_SDRAM_BANK1;

hsdram.Init.ColumnBitsNumber =

FMC_SDRAM_COLUMN_BITS_NUM_8

;

hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;

hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; //

FMC_SDRAM_MEM_BUS_WIDTH_16

hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;

hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_2;

hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;

hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD;

hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;

hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;

Question

: Both evaluation boards uses the same SDRAM chip, why does STM use different configuration? Please explain me.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* Write data to the SDRAM memory */

for (uwIndex = 0; uwIndex < BUFFER_SIZE; uwIndex++)

{

*(__IO uint32_t*) (SDRAM_BANK_ADDR + WRITE_READ_ADDR +

4*uwIndex

) = aTxBuffer[uwIndex];

}

Question

: According to example code, why do we need

4*

?

When I check HAL API, HAL_SDRAM_Write_32b() function doesn't use like above coding.

This means 

HAL_SDRAM_Write_32b() function doesn't work for STM32F7?

Question

can you give me FMC_SDRAM example using HAL_SDRAM_Write_32b() function ?

Regards,

Thiha Kyaw

7 REPLIES 7
Posted on November 22, 2017 at 04:58

Haven't looked at specific boards, in the past ST has used half a memory chip because they can only spare 16 pins for data lines. Look at the data sheets for the specific parts, and review the application of the chip in the schematic for each board.

Multiplies by 4 because a 32-bit word contains 4 bytes and they want all the data to end up in memory and not be overwritten by the next write. On the other hand aTxBuffer[] is an array of 32-bit values. It would really help to understand data representation in memory.

Does

HAL_SDRAM_Write_32b()

cast to a 32-bit pointer? With suitable casting and incrementing of pointers the *4 is done automatically by the compiler, as part of the C Standard implementation.

The SDRAM is within the CPU address space, you can access it like any other memory, I don't see the value in these macros/functions

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 22, 2017 at 05:06

Dear Clive,

HAL_StatusTypeDef HAL_SDRAM_Write_16b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)

{

__IO uint16_t

*pSdramAddress = (uint16_t *)pAddress;

...............

}

//////////////////////////////////////

HAL_StatusTypeDef HAL_SDRAM_Read_32b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)

{

__IO uint32_t

*pSdramAddress = (uint32_t *)pAddress;

................

}

I think I understand what you mean. Let me test it again.

Regards,

Thiha Kyaw

THIHA KYAW
Associate III
Posted on November 29, 2017 at 03:15

Hi,

Please help me to answer the following question.

In STM32F769-EVAL, hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; //

FMC_SDRAM_MEM_BUS_WIDTH_32.

In STM32F769I_Discovery board, hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH; //

FMC_SDRAM_MEM_BUS_WIDTH_16

Which one is correct?  Can you give me any document for FMC configuration.

Thanks.

Regards,

Thiha Kyaw

AVI-crak
Senior
Posted on November 29, 2017 at 04:56

There is a sad experience - to collect all dependent functions in one file to run SDRAM. I got more than a thousand lines !!!, it's very easy to get confused.

The option of direct access to the registers, you'll have to read the documentation a bit - but it's worth it.

http://en.radzio.dxp.pl/stm32f429idiscovery/sdram.html

 
Posted on November 29, 2017 at 04:35

the one that's correct is the one that's correct for your hardware.  the disco board cant access the whole chip.

Posted on November 29, 2017 at 09:49

Dear John,

Let me explain my understanding.

If SDRAM chip is 32 bit SDRAM,  use 

//

FMC_SDRAM_MEM_BUS_WIDTH_32.

If SDRAM chip is 16 bit SDRAM,  use 

//

FMC_SDRAM_MEM_BUS_WIDTH_16.

Am I right?

Regards,

Thiha Kyaw

Posted on November 29, 2017 at 13:34

im not sure where you get that from.  i use the board support package and its all 32 bit

/** @defgroup STM32F769I_DISCOVERY_SDRAM_Exported_Functions SDRAM Exported Functions

  * @{

  */  

uint8_t BSP_SDRAM_Init(void);

uint8_t BSP_SDRAM_DeInit(void);

void    BSP_SDRAM_Initialization_sequence(uint32_t RefreshCount);

uint8_t BSP_SDRAM_ReadData(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize);

uint8_t BSP_SDRAM_ReadData_DMA(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize);

uint8_t BSP_SDRAM_WriteData(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize);

uint8_t BSP_SDRAM_WriteData_DMA(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize);

uint8_t BSP_SDRAM_Sendcmd(FMC_SDRAM_CommandTypeDef *SdramCmd);