[SRAM] CubeMX is configured with STM32H743+IS61WV204816 external expansion SRAM

1, Foreword

Although H743 has provided a lot of internal RAM, my friends who read this article must understand that even the most generous internal RAM is useful, so we need to expand ram. At this time, there are two options, SDRAM or SRAM, which can be used. I will use two bloggers to bring their configuration processes respectively!

The configurations of F407 and H743 are similar, and there are no more places for H7.
Let me take the configuration of H743+IS61WV204816BLL as an example:

2, Configuring CubeMX

First of all, the conventional configuration clock and the voltage range of the power regulator are adjusted to 0 (so that the clock can be adjusted very high).

Then set the clock to 480M, and let cubemx configure automatically

Open the serial port as usual

The next step is to configure FMC. SRAM is attached to this interface (this interface is called FSMC on F407. FMC can be regarded as an upgraded version with more functions than FSMC and SDRAM)
First, the configuration of the first part:

These three points need extra attention!!!

① First of all, our SRAM is hung in this area, but it should be noted that there is an easily overlooked "4x64MB" in this area. Originally, this area is divided into four 64MB areas!
NE1 area: 0x6000 0000 ~0x63FF FFFF
NE2 area: 0x6400 0000 ~0x67FF FFFF
NE3 area: 0x6800 0000 ~0x6BFF FFFF
NE4 area: 0x6C00 0000 ~0x6FFF FFFF
The NE to which our SRAM is connected depends on which pin the CS pin of SRAM is connected to on STM32. For example, the CS pin of my SRAM is connected to the PC7 of STM32H743ZIT6. This pin has FMC_ The function of NE1, so I use NE1 here. In CubeMX, I choose NE1.
② Then I see the address bit. Why did I fill in 21bit? Because the SRAM is 204816, the name indicates that it is a 2048K line bit width 16 bit SRAM. How many bits are required for 2048K lines? The 21st power of 2 is 2048K, so the address line of this chip has 21bit(A0-A20). Of course, this can also be seen in the manual. I just want to make this more vivid. (as usual, if it is 102416, it is 20bit(A0-A19);51216 is 19bit(A0-A18))
③ 16 bits wide, so it's 16. Also tick allow 16 bit write below.

Next is the second part of FMC configuration. There is nothing to say.

Open MDK after code generation

3, Configure MDK and Application

Next, configure the MDK and application:
Check the micro library, check the information generation, close the optimization, and check reset and run. It's all basic operation.

For program configuration, I like to configure the serial port first, and then compile it to see if there is a problem.
Serial port redirection:

int fputc(int ch, FILE *f)
//Which serial port can be changed from huart1 to other serial ports
HAL_UART_Transmit(&huart3 , (uint8_t *)&ch, 1 , 0x0f);
return ch;

Don't forget to add:

#include "stdio.h"

Then in FMC C add a program to test SRAM (excerpted from Wildfire routine)

  * @brief  Test whether SRAM is normal 
  * @param  None
  * @retval Normal returns 1 and abnormal returns 0
uint8_t SRAM_Test(void)
  /*Write data counter*/
  uint32_t counter=0;
  /* 8 Bit data */
  uint8_t ubWritedata_8b = 0, ubReaddata_8b = 0;  
  /* 16 Bit data */
  uint16_t uhWritedata_16b = 0, uhReaddata_16b = 0; 
  SRAM_INFO("Detecting SRAM,Read and write in 8-bit and 16 bit mode sram...");

  /*Read and write data in 8-bit format and verify*/
  /* Reset all SRAM data to 0, IS62WV51216_SIZE is in 8 bits */
  for (counter = 0x00; counter < IS62WV51216_SIZE; counter++)
    *(__IO uint8_t*) (Bank1_SRAM4_ADDR + counter) = (uint8_t)0x0;
  /* Write 8 bits of data to the whole SRAM */
  for (counter = 0; counter < IS62WV51216_SIZE; counter++)
    *(__IO uint8_t*) (Bank1_SRAM4_ADDR + counter) = (uint8_t)(ubWritedata_8b + counter);
  /* Read SRAM data and detect*/
  for(counter = 0; counter<IS62WV51216_SIZE;counter++ )
    ubReaddata_8b = *(__IO uint8_t*)(Bank1_SRAM4_ADDR + counter);  //Read data from this address
    if(ubReaddata_8b != (uint8_t)(ubWritedata_8b + counter))      //If the detection data are not equal, the function will jump out and the detection failure result will be returned.
      SRAM_ERROR("8 Bit data read / write error!");
      return 0;
  /*Read and write data in 16 bit format and detect*/
  /* Reset all SRAM data to 0 */
  for (counter = 0x00; counter < IS62WV51216_SIZE/2; counter++)
    *(__IO uint16_t*) (Bank1_SRAM4_ADDR + 2*counter) = (uint16_t)0x00;
  /* Write 16 bits of data to the whole SRAM */
  for (counter = 0; counter < IS62WV51216_SIZE/2; counter++)
    *(__IO uint16_t*) (Bank1_SRAM4_ADDR + 2*counter) = (uint16_t)(uhWritedata_16b + counter);
    /* Read SRAM data and detect*/
  for(counter = 0; counter<IS62WV51216_SIZE/2;counter++ )
    uhReaddata_16b = *(__IO uint16_t*)(Bank1_SRAM4_ADDR + 2*counter);  //Read data from this address
    if(uhReaddata_16b != (uint16_t)(uhWritedata_16b + counter))      //If the detection data are not equal, the function will jump out and the detection failure result will be returned.
      SRAM_ERROR("16 Bit data read / write error!");

      return 0;
  SRAM_INFO("SRAM The reading and writing test is normal!"); 
  /*The test is normal, return 1 */
  return 1;

Then in FMC Add two pieces of code before and after H

Before paragraph:

/* USER CODE BEGIN Includes */
#include "stdio.h"
//The address line range is A0~A19 
#define Bank1_SRAM1_ADDR    ((uint32_t)(0x60000000))
#define IS62WV51216_ 0x1024 bytes, 0x2bits = 200000 bytes
/* USER CODE END Includes */

After paragraph:

/* USER CODE BEGIN Prototypes */
/*Information output*/
#define SRAM_DEBUG_ON         1
#define SRAM_INFO(fmt,arg...)           printf("<<-SRAM-INFO->> "fmt"\n",##arg)
#define SRAM_ERROR(fmt,arg...)          printf("<<-SRAM-ERROR->> "fmt"\n",##arg)
#define SRAM_DEBUG(fmt,arg...)          do{\
                                          printf("<<-SRAM-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
uint8_t SRAM_Test(void);														
/* USER CODE END Prototypes */

In main C add reference SRAM detection function to detect SRAM, and print the detection results with serial port.

printf("SRAM Configuration instance");
printf ( "\r\n extend SRAM write in/Read test start\r\n" );
	printf("Test successful");	  
	printf("Test failed");

Compile and download, the result is successful!

Tags: Single-Chip Microcomputer stm32 ARM SRAM

Posted by sub7av on Wed, 18 May 2022 01:28:58 +0300